blob: 6d5b12f5af900673f36ab339f5675a4b17617bb3 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020052 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040053 (
54 precision highp float;
55 attribute vec4 position;
56 varying vec2 texcoord;
57
58 void main()
59 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020060 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040061 texcoord = (position.xy * 0.5) + 0.5;
62 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 )
Geoff Langc41e42d2014-04-28 10:58:16 -040064 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020065 }
Geoff Langc41e42d2014-04-28 10:58:16 -040066
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 virtual std::string getFragmentShaderSource() = 0;
68
Olli Etuahoa1c917f2016-04-06 13:50:03 +030069 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020070 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020071 const std::string vertexShaderSource = getVertexShaderSource();
72 const std::string fragmentShaderSource = getFragmentShaderSource();
73
74 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
75 ASSERT_NE(0u, mProgram);
76 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030077 }
78
79 void SetUp() override
80 {
81 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020082
83 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020084 }
85
86 void TearDown() override
87 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020088 glBindFramebuffer(GL_FRAMEBUFFER, 0);
89 glDeleteFramebuffers(1, &mFramebuffer);
90 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020091 glDeleteProgram(mProgram);
92 ANGLETest::TearDown();
93 }
94
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020095 void setUpFramebuffer()
96 {
97 // We use an FBO to work around an issue where the default framebuffer applies SRGB
98 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
99 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
100 // section 4.4 says that the format of the default framebuffer is entirely up to the window
101 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
102 // SRGB conversion like desktop GL does.
103 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
104 glGenFramebuffers(1, &mFramebuffer);
105 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
106
107 glGenTextures(1, &mFramebufferColorTexture);
108 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
110 GL_UNSIGNED_BYTE, nullptr);
111 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
112 mFramebufferColorTexture, 0);
113 ASSERT_GL_NO_ERROR();
114 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
115 glBindTexture(GL_TEXTURE_2D, 0);
116 }
117
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200118 // Returns the created texture ID.
119 GLuint create2DTexture()
120 {
121 GLuint texture2D;
122 glGenTextures(1, &texture2D);
123 glBindTexture(GL_TEXTURE_2D, texture2D);
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);
Geoff Langc51642b2016-11-14 16:18:26 -05001197
1198 if (extensionEnabled("GL_EXT_texture_storage"))
1199 {
1200 // Create a 1-level immutable texture.
1201 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1202
1203 // Try calling sub image on the second level.
1204 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1205 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1206 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001207}
Geoff Langc41e42d2014-04-28 10:58:16 -04001208
John Bauman18319182016-09-28 14:22:27 -07001209// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1210TEST_P(Texture2DTest, QueryBinding)
1211{
1212 glBindTexture(GL_TEXTURE_2D, 0);
1213 EXPECT_GL_ERROR(GL_NO_ERROR);
1214
1215 GLint textureBinding;
1216 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1217 EXPECT_GL_NO_ERROR();
1218 EXPECT_EQ(0, textureBinding);
1219
1220 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1221 if (extensionEnabled("GL_OES_EGL_image_external") ||
1222 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1223 {
1224 EXPECT_GL_NO_ERROR();
1225 EXPECT_EQ(0, textureBinding);
1226 }
1227 else
1228 {
1229 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1230 }
1231}
1232
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001234{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001235 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001236 EXPECT_GL_ERROR(GL_NO_ERROR);
1237
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001238 setUpProgram();
1239
Geoff Langc41e42d2014-04-28 10:58:16 -04001240 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001241 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001242 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001243 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001244
1245 const GLubyte *pixel[4] = { 0 };
1246
1247 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1248 EXPECT_GL_NO_ERROR();
1249
1250 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1251 EXPECT_GL_NO_ERROR();
1252
1253 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1254 EXPECT_GL_NO_ERROR();
1255}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001256
1257// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001258TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001259{
1260 glActiveTexture(GL_TEXTURE0);
1261 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1262 glActiveTexture(GL_TEXTURE1);
1263 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1264 EXPECT_GL_ERROR(GL_NO_ERROR);
1265
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001266 glUseProgram(mProgram);
1267 glUniform1i(mTexture2DUniformLocation, 0);
1268 glUniform1i(mTextureCubeUniformLocation, 1);
1269 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001270 EXPECT_GL_NO_ERROR();
1271}
Jamie Madill9aca0592014-10-06 16:26:59 -04001272
Olli Etuaho53a2da12016-01-11 15:43:32 +02001273// Test drawing with two texture types accessed from the same shader and check that the result of
1274// drawing is correct.
1275TEST_P(TextureCubeTest, CubeMapDraw)
1276{
1277 GLubyte texData[4];
1278 texData[0] = 0;
1279 texData[1] = 60;
1280 texData[2] = 0;
1281 texData[3] = 255;
1282
1283 glActiveTexture(GL_TEXTURE0);
1284 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1285 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1286
1287 glActiveTexture(GL_TEXTURE1);
1288 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1289 texData[1] = 120;
1290 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1291 texData);
1292 EXPECT_GL_ERROR(GL_NO_ERROR);
1293
1294 glUseProgram(mProgram);
1295 glUniform1i(mTexture2DUniformLocation, 0);
1296 glUniform1i(mTextureCubeUniformLocation, 1);
1297 drawQuad(mProgram, "position", 0.5f);
1298 EXPECT_GL_NO_ERROR();
1299
1300 int px = getWindowWidth() - 1;
1301 int py = 0;
1302 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1303}
1304
Olli Etuaho4644a202016-01-12 15:12:53 +02001305TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1306{
1307 glActiveTexture(GL_TEXTURE0);
1308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1309 GLubyte texData[4];
1310 texData[0] = 0;
1311 texData[1] = 128;
1312 texData[2] = 0;
1313 texData[3] = 255;
1314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1315 glUseProgram(mProgram);
1316 glUniform1i(mTexture2DUniformLocation, 0);
1317 drawQuad(mProgram, "position", 0.5f);
1318 EXPECT_GL_NO_ERROR();
1319
1320 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1321}
1322
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001323// Test drawing with two textures passed to the shader in a sampler array.
1324TEST_P(SamplerArrayTest, SamplerArrayDraw)
1325{
1326 testSamplerArrayDraw();
1327}
1328
1329// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1330// user-defined function in the shader.
1331TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1332{
1333 testSamplerArrayDraw();
1334}
1335
Jamie Madill9aca0592014-10-06 16:26:59 -04001336// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001337TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001338{
1339 int px = getWindowWidth() / 2;
1340 int py = getWindowHeight() / 2;
1341
1342 glActiveTexture(GL_TEXTURE0);
1343 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1344
Olli Etuahoa314b612016-03-10 16:43:00 +02001345 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001346
Olli Etuahoa314b612016-03-10 16:43:00 +02001347 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1350 glGenerateMipmap(GL_TEXTURE_2D);
1351
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001352 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001353 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001354 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1355 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001358
Olli Etuahoa314b612016-03-10 16:43:00 +02001359 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001360
Olli Etuahoa314b612016-03-10 16:43:00 +02001361 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1362 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001363 glGenerateMipmap(GL_TEXTURE_2D);
1364
Olli Etuahoa314b612016-03-10 16:43:00 +02001365 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001366
Olli Etuahoa314b612016-03-10 16:43:00 +02001367 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1368 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001369 glGenerateMipmap(GL_TEXTURE_2D);
1370
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001371 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001372
1373 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001374 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001375}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001376
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001377// Test creating a FBO with a cube map render target, to test an ANGLE bug
1378// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001379TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001380{
1381 GLuint fbo;
1382 glGenFramebuffers(1, &fbo);
1383 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1384
1385 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1386 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1387
Corentin Wallez322653b2015-06-17 18:33:56 +02001388 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001389
1390 glDeleteFramebuffers(1, &fbo);
1391
1392 EXPECT_GL_NO_ERROR();
1393}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001394
1395// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001396TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001397{
1398 int width = getWindowWidth();
1399 int height = getWindowHeight();
1400
1401 GLuint tex2D;
1402 glGenTextures(1, &tex2D);
1403 glActiveTexture(GL_TEXTURE0);
1404 glBindTexture(GL_TEXTURE_2D, tex2D);
1405
1406 // Fill with red
1407 std::vector<GLubyte> pixels(3 * 16 * 16);
1408 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1409 {
1410 pixels[pixelId * 3 + 0] = 255;
1411 pixels[pixelId * 3 + 1] = 0;
1412 pixels[pixelId * 3 + 2] = 0;
1413 }
1414
1415 // ANGLE internally uses RGBA as the DirectX format for RGB images
1416 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1417 // The data is kept in a CPU-side image and the image is marked as dirty.
1418 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1419
1420 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1421 // glTexSubImage2D should take into account that the image is dirty.
1422 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1425
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001426 setUpProgram();
1427
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001428 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001429 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001430 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001431 glDeleteTextures(1, &tex2D);
1432 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001433 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001434
1435 // Validate that the region of the texture without data has an alpha of 1.0
1436 GLubyte pixel[4];
1437 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1438 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001439}
1440
1441// 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 +02001442TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443{
1444 if (extensionEnabled("NV_pixel_buffer_object"))
1445 {
1446 int width = getWindowWidth();
1447 int height = getWindowHeight();
1448
1449 GLuint tex2D;
1450 glGenTextures(1, &tex2D);
1451 glActiveTexture(GL_TEXTURE0);
1452 glBindTexture(GL_TEXTURE_2D, tex2D);
1453
1454 // Fill with red
1455 std::vector<GLubyte> pixels(3 * 16 * 16);
1456 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1457 {
1458 pixels[pixelId * 3 + 0] = 255;
1459 pixels[pixelId * 3 + 1] = 0;
1460 pixels[pixelId * 3 + 2] = 0;
1461 }
1462
1463 // Read 16x16 region from red backbuffer to PBO
1464 GLuint pbo;
1465 glGenBuffers(1, &pbo);
1466 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1467 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1468
1469 // ANGLE internally uses RGBA as the DirectX format for RGB images
1470 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1471 // The data is kept in a CPU-side image and the image is marked as dirty.
1472 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1473
1474 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1475 // glTexSubImage2D should take into account that the image is dirty.
1476 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, NULL);
1477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1479
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001480 setUpProgram();
1481
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001482 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001483 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001484 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001485 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001486 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001487 EXPECT_GL_NO_ERROR();
1488 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1489 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1490 }
1491}
Jamie Madillbc393df2015-01-29 13:46:07 -05001492
1493// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001494TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001495{
1496 testFloatCopySubImage(1, 1);
1497}
1498
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001499TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001500{
1501 testFloatCopySubImage(2, 1);
1502}
1503
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001504TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001505{
1506 testFloatCopySubImage(2, 2);
1507}
1508
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001509TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001510{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001511 if (IsIntel() && IsLinux())
1512 {
1513 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1514 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1515 return;
1516 }
1517
Jamie Madillbc393df2015-01-29 13:46:07 -05001518 testFloatCopySubImage(3, 1);
1519}
1520
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001521TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001522{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001523 if (IsIntel() && IsLinux())
1524 {
1525 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1526 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1527 return;
1528 }
1529
Jamie Madillbc393df2015-01-29 13:46:07 -05001530 testFloatCopySubImage(3, 2);
1531}
1532
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001533TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001534{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001535 if (IsIntel() && IsLinux())
1536 {
1537 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1538 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1539 return;
1540 }
1541
Austin Kinrossd544cc92016-01-11 15:26:42 -08001542 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001543 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001544 {
1545 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1546 return;
1547 }
1548
Jamie Madillbc393df2015-01-29 13:46:07 -05001549 testFloatCopySubImage(3, 3);
1550}
1551
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001552TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001553{
1554 testFloatCopySubImage(4, 1);
1555}
1556
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001557TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001558{
1559 testFloatCopySubImage(4, 2);
1560}
1561
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001562TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001563{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001564 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001565 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001566 {
1567 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1568 return;
1569 }
1570
Jamie Madillbc393df2015-01-29 13:46:07 -05001571 testFloatCopySubImage(4, 3);
1572}
1573
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001574TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001575{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001576 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001577 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001578 {
1579 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1580 return;
1581 }
1582
Jamie Madillbc393df2015-01-29 13:46:07 -05001583 testFloatCopySubImage(4, 4);
1584}
Austin Kinross07285142015-03-26 11:36:16 -07001585
1586// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1587// 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 +02001588TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001589{
1590 const int npotTexSize = 5;
1591 const int potTexSize = 4; // Should be less than npotTexSize
1592 GLuint tex2D;
1593
1594 if (extensionEnabled("GL_OES_texture_npot"))
1595 {
1596 // This test isn't applicable if texture_npot is enabled
1597 return;
1598 }
1599
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001600 setUpProgram();
1601
Austin Kinross07285142015-03-26 11:36:16 -07001602 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1603
Austin Kinross5faa15b2016-01-11 13:32:48 -08001604 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1605 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1606
Austin Kinross07285142015-03-26 11:36:16 -07001607 glActiveTexture(GL_TEXTURE0);
1608 glGenTextures(1, &tex2D);
1609 glBindTexture(GL_TEXTURE_2D, tex2D);
1610
1611 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1612 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1613 {
1614 pixels[pixelId] = 64;
1615 }
1616
1617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1619
1620 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1621 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1622 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1623
1624 // Check that an NPOT texture on level 0 succeeds
1625 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1626 EXPECT_GL_NO_ERROR();
1627
1628 // Check that generateMipmap fails on NPOT
1629 glGenerateMipmap(GL_TEXTURE_2D);
1630 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1631
1632 // Check that nothing is drawn if filtering is not correct for NPOT
1633 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1635 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1636 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1637 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001638 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001639 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1640
1641 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1642 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1643 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1644 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1645 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001646 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001647 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1648
1649 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1651 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001652 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001653 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1654
1655 // Check that glTexImage2D for POT texture succeeds
1656 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1657 EXPECT_GL_NO_ERROR();
1658
1659 // Check that generateMipmap for an POT texture succeeds
1660 glGenerateMipmap(GL_TEXTURE_2D);
1661 EXPECT_GL_NO_ERROR();
1662
1663 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1668 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001669 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001670 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1671 EXPECT_GL_NO_ERROR();
1672}
Jamie Madillfa05f602015-05-07 13:47:11 -04001673
Austin Kinross08528e12015-10-07 16:24:40 -07001674// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1675// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001676TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001677{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001678 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1679 // 1278)
1680 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1681 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1682 {
1683 std::cout << "Test disabled on OpenGL." << std::endl;
1684 return;
1685 }
1686
Austin Kinross08528e12015-10-07 16:24:40 -07001687 glActiveTexture(GL_TEXTURE0);
1688 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1689
1690 // Create an 8x8 (i.e. power-of-two) texture.
1691 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1694 glGenerateMipmap(GL_TEXTURE_2D);
1695
1696 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1697 // This should always work, even if GL_OES_texture_npot isn't active.
1698 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1699
1700 EXPECT_GL_NO_ERROR();
1701}
1702
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001703// Test to check that texture completeness is determined correctly when the texture base level is
1704// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1705TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1706{
1707 glActiveTexture(GL_TEXTURE0);
1708 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001709
1710 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1712 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1713 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1714 texDataGreen.data());
1715 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1716 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1720
1721 EXPECT_GL_NO_ERROR();
1722
1723 drawQuad(mProgram, "position", 0.5f);
1724
Olli Etuahoa314b612016-03-10 16:43:00 +02001725 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1726}
1727
1728// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1729// have images defined.
1730TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1731{
1732 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1733 {
1734 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1735 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1736 return;
1737 }
1738 if (IsOSX())
1739 {
1740 // Observed incorrect rendering on OSX.
1741 std::cout << "Test skipped on OSX." << std::endl;
1742 return;
1743 }
1744 glActiveTexture(GL_TEXTURE0);
1745 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1746 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1747 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1748 texDataGreen.data());
1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1753
1754 EXPECT_GL_NO_ERROR();
1755
1756 drawQuad(mProgram, "position", 0.5f);
1757
1758 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1759}
1760
Olli Etuahoe8528d82016-05-16 17:50:52 +03001761// Test that drawing works correctly when level 0 is undefined and base level is 1.
1762TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1763{
1764 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1765 {
1766 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1767 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1768 return;
1769 }
1770 if (IsOSX())
1771 {
1772 // Observed incorrect rendering on OSX.
1773 std::cout << "Test skipped on OSX." << std::endl;
1774 return;
1775 }
1776 glActiveTexture(GL_TEXTURE0);
1777 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1778 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1779 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1780 texDataGreen.data());
1781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1783 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1784 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1785
1786 EXPECT_GL_NO_ERROR();
1787
1788 // Texture is incomplete.
1789 drawQuad(mProgram, "position", 0.5f);
1790 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1791
1792 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1793 texDataGreen.data());
1794
1795 // Texture is now complete.
1796 drawQuad(mProgram, "position", 0.5f);
1797 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1798}
1799
Olli Etuahoa314b612016-03-10 16:43:00 +02001800// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1801// dimensions that don't fit the images inside the range.
1802// GLES 3.0.4 section 3.8.13 Texture completeness
1803TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1804{
1805 if (IsOSX())
1806 {
1807 // Observed incorrect rendering on OSX.
1808 std::cout << "Test skipped on OSX." << std::endl;
1809 return;
1810 }
1811 glActiveTexture(GL_TEXTURE0);
1812 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1813 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1814 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1815 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1816
1817 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1818 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1819
1820 // Two levels that are initially unused.
1821 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1822 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1823 texDataCyan.data());
1824
1825 // One level that is used - only this level should affect completeness.
1826 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1827 texDataGreen.data());
1828
1829 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1831
1832 EXPECT_GL_NO_ERROR();
1833
1834 drawQuad(mProgram, "position", 0.5f);
1835
1836 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1837
1838 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1839 {
1840 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1841 // level was changed.
1842 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1843 return;
1844 }
1845
1846 // Switch the level that is being used to the cyan level 2.
1847 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1848 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1849
1850 EXPECT_GL_NO_ERROR();
1851
1852 drawQuad(mProgram, "position", 0.5f);
1853
1854 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1855}
1856
1857// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1858// have images defined.
1859TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1860{
1861 if (IsOSX())
1862 {
1863 // Observed incorrect rendering on OSX.
1864 std::cout << "Test skipped on OSX." << std::endl;
1865 return;
1866 }
1867 glActiveTexture(GL_TEXTURE0);
1868 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1869 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1870 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1871 texDataGreen.data());
1872 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1873 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1874 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1875 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1876
1877 EXPECT_GL_NO_ERROR();
1878
1879 drawQuad(mProgram, "position", 0.5f);
1880
1881 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1882}
1883
1884// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1885// dimensions that don't fit the images inside the range.
1886// GLES 3.0.4 section 3.8.13 Texture completeness
1887TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1888{
1889 if (IsOSX())
1890 {
1891 // Observed incorrect rendering on OSX.
1892 std::cout << "Test skipped on OSX." << std::endl;
1893 return;
1894 }
1895 glActiveTexture(GL_TEXTURE0);
1896 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1897 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1898 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1899 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1900
1901 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1902 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1903
1904 // Two levels that are initially unused.
1905 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1906 texDataRed.data());
1907 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1908 texDataCyan.data());
1909
1910 // One level that is used - only this level should affect completeness.
1911 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1912 texDataGreen.data());
1913
1914 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1915 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1916
1917 EXPECT_GL_NO_ERROR();
1918
1919 drawQuad(mProgram, "position", 0.5f);
1920
1921 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1922
1923 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1924 {
1925 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1926 // level was changed.
1927 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1928 return;
1929 }
1930
1931 // Switch the level that is being used to the cyan level 2.
1932 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1933 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1934
1935 EXPECT_GL_NO_ERROR();
1936
1937 drawQuad(mProgram, "position", 0.5f);
1938
1939 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1940}
1941
1942// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1943// have images defined.
1944TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1945{
1946 if (IsOSX())
1947 {
1948 // Observed incorrect rendering on OSX.
1949 std::cout << "Test skipped on OSX." << std::endl;
1950 return;
1951 }
1952 glActiveTexture(GL_TEXTURE0);
1953 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1954 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1955 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1956 texDataGreen.data());
1957 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1958 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1959 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1960 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1961
1962 EXPECT_GL_NO_ERROR();
1963
1964 drawQuad(mProgram, "position", 0.5f);
1965
1966 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1967}
1968
1969// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1970// dimensions that don't fit the images inside the range.
1971// GLES 3.0.4 section 3.8.13 Texture completeness
1972TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1973{
1974 if (IsOSX())
1975 {
1976 // Observed incorrect rendering on OSX.
1977 std::cout << "Test skipped on OSX." << std::endl;
1978 return;
1979 }
1980 glActiveTexture(GL_TEXTURE0);
1981 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1982 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1983 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1984 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1985
1986 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1987 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1988
1989 // Two levels that are initially unused.
1990 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1991 texDataRed.data());
1992 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1993 texDataCyan.data());
1994
1995 // One level that is used - only this level should affect completeness.
1996 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1997 texDataGreen.data());
1998
1999 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2000 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2001
2002 EXPECT_GL_NO_ERROR();
2003
2004 drawQuad(mProgram, "position", 0.5f);
2005
2006 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2007
2008 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2009 {
2010 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2011 // level was changed.
2012 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2013 return;
2014 }
2015 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2016 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2017 {
2018 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2019 // level was changed.
2020 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2021 return;
2022 }
2023
2024 // Switch the level that is being used to the cyan level 2.
2025 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2026 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2027
2028 EXPECT_GL_NO_ERROR();
2029
2030 drawQuad(mProgram, "position", 0.5f);
2031
2032 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2033}
2034
2035// Test that texture completeness is updated if texture max level changes.
2036// GLES 3.0.4 section 3.8.13 Texture completeness
2037TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2038{
2039 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2040 {
2041 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2042 // the base level.
2043 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2044 return;
2045 }
2046 if (IsOSX())
2047 {
2048 // Observed incorrect rendering on OSX.
2049 std::cout << "Test skipped on OSX." << std::endl;
2050 return;
2051 }
2052
2053 glActiveTexture(GL_TEXTURE0);
2054 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2055 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2056
2057 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2058 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2059
2060 // A level that is initially unused.
2061 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2062 texDataGreen.data());
2063
2064 // One level that is initially used - only this level should affect completeness.
2065 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2066 texDataGreen.data());
2067
2068 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2069 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2070
2071 EXPECT_GL_NO_ERROR();
2072
2073 drawQuad(mProgram, "position", 0.5f);
2074
2075 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2076
2077 // Switch the max level to level 1. The levels within the used range now have inconsistent
2078 // dimensions and the texture should be incomplete.
2079 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2080
2081 EXPECT_GL_NO_ERROR();
2082
2083 drawQuad(mProgram, "position", 0.5f);
2084
2085 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2086}
2087
2088// Test that 3D texture completeness is updated if texture max level changes.
2089// GLES 3.0.4 section 3.8.13 Texture completeness
2090TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2091{
2092 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2093 {
2094 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2095 // the base level.
2096 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2097 return;
2098 }
2099 if (IsOSX())
2100 {
2101 // Observed incorrect rendering on OSX.
2102 std::cout << "Test skipped on OSX." << std::endl;
2103 return;
2104 }
2105
2106 glActiveTexture(GL_TEXTURE0);
2107 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2108 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2109
2110 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2111 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2112
2113 // A level that is initially unused.
2114 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2115 texDataGreen.data());
2116
2117 // One level that is initially used - only this level should affect completeness.
2118 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2119 texDataGreen.data());
2120
2121 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2122 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2123
2124 EXPECT_GL_NO_ERROR();
2125
2126 drawQuad(mProgram, "position", 0.5f);
2127
2128 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2129
2130 // Switch the max level to level 1. The levels within the used range now have inconsistent
2131 // dimensions and the texture should be incomplete.
2132 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2133
2134 EXPECT_GL_NO_ERROR();
2135
2136 drawQuad(mProgram, "position", 0.5f);
2137
2138 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2139}
2140
2141// Test that texture completeness is updated if texture base level changes.
2142// GLES 3.0.4 section 3.8.13 Texture completeness
2143TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2144{
2145 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2146 {
2147 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2148 // the base level.
2149 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2150 return;
2151 }
2152
2153 glActiveTexture(GL_TEXTURE0);
2154 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2155 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2156
2157 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2158 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2159
2160 // Two levels that are initially unused.
2161 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2162 texDataGreen.data());
2163 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2164 texDataGreen.data());
2165
2166 // One level that is initially used - only this level should affect completeness.
2167 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2168 texDataGreen.data());
2169
2170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2172
2173 EXPECT_GL_NO_ERROR();
2174
2175 drawQuad(mProgram, "position", 0.5f);
2176
2177 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2178
2179 // Switch the base level to level 1. The levels within the used range now have inconsistent
2180 // dimensions and the texture should be incomplete.
2181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2182
2183 EXPECT_GL_NO_ERROR();
2184
2185 drawQuad(mProgram, "position", 0.5f);
2186
2187 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2188}
2189
2190// Test that texture is not complete if base level is greater than max level.
2191// GLES 3.0.4 section 3.8.13 Texture completeness
2192TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2193{
2194 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2195 {
2196 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2197 // of range.
2198 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2199 return;
2200 }
2201
2202 glActiveTexture(GL_TEXTURE0);
2203 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2204
2205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2207
2208 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2209
2210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2212
2213 EXPECT_GL_NO_ERROR();
2214
2215 drawQuad(mProgram, "position", 0.5f);
2216
2217 // Texture should be incomplete.
2218 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2219}
2220
2221// Test that immutable texture base level and max level are clamped.
2222// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2223TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2224{
Olli Etuahoa314b612016-03-10 16:43:00 +02002225 glActiveTexture(GL_TEXTURE0);
2226 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2227
2228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2230
2231 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2232
2233 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2234
2235 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2236 // should be clamped to [base_level, levels - 1].
2237 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2238 // In the case of this test, those rules make the effective base level and max level 0.
2239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2240 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2241
2242 EXPECT_GL_NO_ERROR();
2243
2244 drawQuad(mProgram, "position", 0.5f);
2245
2246 // Texture should be complete.
2247 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2248}
2249
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002250// Test that changing base level works when it affects the format of the texture.
2251TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2252{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002253 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002254 {
2255 // Observed rendering corruption on NVIDIA OpenGL.
2256 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2257 return;
2258 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002259 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002260 {
2261 // Observed incorrect rendering on Intel OpenGL.
2262 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2263 return;
2264 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002265 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002266 {
2267 // Observed incorrect rendering on AMD OpenGL.
2268 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2269 return;
2270 }
2271
2272 glActiveTexture(GL_TEXTURE0);
2273 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2274 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2275 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2276
2277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2279
2280 // RGBA8 level that's initially unused.
2281 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2282 texDataCyan.data());
2283
2284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2286
2287 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2288 // format. It reads green channel data from the green and alpha channels of texDataGreen
2289 // (this is a bit hacky but works).
2290 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2291
2292 EXPECT_GL_NO_ERROR();
2293
2294 drawQuad(mProgram, "position", 0.5f);
2295
2296 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2297
2298 // Switch the texture to use the cyan level 0 with the RGBA format.
2299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2301
2302 EXPECT_GL_NO_ERROR();
2303
2304 drawQuad(mProgram, "position", 0.5f);
2305
2306 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2307}
2308
Olli Etuahoa314b612016-03-10 16:43:00 +02002309// Test that setting a texture image works when base level is out of range.
2310TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2311{
2312 glActiveTexture(GL_TEXTURE0);
2313 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2314
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2317
2318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2320
2321 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2322
2323 EXPECT_GL_NO_ERROR();
2324
2325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2326
2327 drawQuad(mProgram, "position", 0.5f);
2328
2329 // Texture should be complete.
2330 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002331}
2332
Jamie Madill2453dbc2015-07-14 11:35:42 -04002333// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2334// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2335// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002336TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002337{
2338 std::vector<GLubyte> pixelData;
2339 for (size_t count = 0; count < 5000; count++)
2340 {
2341 pixelData.push_back(0u);
2342 pixelData.push_back(255u);
2343 pixelData.push_back(0u);
2344 }
2345
2346 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002347 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002348 glUniform1i(mTextureArrayLocation, 0);
2349
2350 // The first draw worked correctly.
2351 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2352
2353 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2354 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2355 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2356 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002357 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002358 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002359
2360 // The dimension of the respecification must match the original exactly to trigger the bug.
2361 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 +02002362 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002363 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002364
2365 ASSERT_GL_NO_ERROR();
2366}
2367
Olli Etuaho1a679902016-01-14 12:21:47 +02002368// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2369// This test is needed especially to confirm that sampler registers get assigned correctly on
2370// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2371TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2372{
2373 glActiveTexture(GL_TEXTURE0);
2374 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2375 GLubyte texData[4];
2376 texData[0] = 0;
2377 texData[1] = 60;
2378 texData[2] = 0;
2379 texData[3] = 255;
2380 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2381
2382 glActiveTexture(GL_TEXTURE1);
2383 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2384 GLfloat depthTexData[1];
2385 depthTexData[0] = 0.5f;
2386 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2387 depthTexData);
2388
2389 glUseProgram(mProgram);
2390 glUniform1f(mDepthRefUniformLocation, 0.3f);
2391 glUniform1i(mTexture3DUniformLocation, 0);
2392 glUniform1i(mTextureShadowUniformLocation, 1);
2393
2394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2395 drawQuad(mProgram, "position", 0.5f);
2396 EXPECT_GL_NO_ERROR();
2397 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2398 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2399
2400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2401 drawQuad(mProgram, "position", 0.5f);
2402 EXPECT_GL_NO_ERROR();
2403 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2404 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2405}
2406
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002407// Test multiple different sampler types in the same shader.
2408// This test makes sure that even if sampler / texture registers get grouped together based on type
2409// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2410// still has the right register index information for each ESSL sampler.
2411// The tested ESSL samplers have the following types in D3D11 HLSL:
2412// sampler2D: Texture2D + SamplerState
2413// samplerCube: TextureCube + SamplerState
2414// sampler2DShadow: Texture2D + SamplerComparisonState
2415// samplerCubeShadow: TextureCube + SamplerComparisonState
2416TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2417{
2418 glActiveTexture(GL_TEXTURE0);
2419 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2420 GLubyte texData[4];
2421 texData[0] = 0;
2422 texData[1] = 0;
2423 texData[2] = 120;
2424 texData[3] = 255;
2425 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2426
2427 glActiveTexture(GL_TEXTURE1);
2428 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2429 texData[0] = 0;
2430 texData[1] = 90;
2431 texData[2] = 0;
2432 texData[3] = 255;
2433 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2434 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2435 texData);
2436
2437 glActiveTexture(GL_TEXTURE2);
2438 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2440 GLfloat depthTexData[1];
2441 depthTexData[0] = 0.5f;
2442 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2443 depthTexData);
2444
2445 glActiveTexture(GL_TEXTURE3);
2446 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2447 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2448 depthTexData[0] = 0.2f;
2449 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2450 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2451 depthTexData);
2452
2453 EXPECT_GL_NO_ERROR();
2454
2455 glUseProgram(mProgram);
2456 glUniform1f(mDepthRefUniformLocation, 0.3f);
2457 glUniform1i(mTexture2DUniformLocation, 0);
2458 glUniform1i(mTextureCubeUniformLocation, 1);
2459 glUniform1i(mTexture2DShadowUniformLocation, 2);
2460 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2461
2462 drawQuad(mProgram, "position", 0.5f);
2463 EXPECT_GL_NO_ERROR();
2464 // The shader writes:
2465 // <texture 2d color> +
2466 // <cube map color> +
2467 // 0.25 * <comparison result (1.0)> +
2468 // 0.125 * <comparison result (0.0)>
2469 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2470}
2471
Olli Etuahobce743a2016-01-15 17:18:28 +02002472// Test different base levels on textures accessed through the same sampler array.
2473// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2474TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2475{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002476 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002477 {
2478 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2479 return;
2480 }
2481 glActiveTexture(GL_TEXTURE0);
2482 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2483 GLsizei size = 64;
2484 for (GLint level = 0; level < 7; ++level)
2485 {
2486 ASSERT_LT(0, size);
2487 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2488 nullptr);
2489 size = size / 2;
2490 }
2491 ASSERT_EQ(0, size);
2492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2493
2494 glActiveTexture(GL_TEXTURE1);
2495 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2496 size = 128;
2497 for (GLint level = 0; level < 8; ++level)
2498 {
2499 ASSERT_LT(0, size);
2500 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2501 nullptr);
2502 size = size / 2;
2503 }
2504 ASSERT_EQ(0, size);
2505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2506 EXPECT_GL_NO_ERROR();
2507
2508 glUseProgram(mProgram);
2509 glUniform1i(mTexture0Location, 0);
2510 glUniform1i(mTexture1Location, 1);
2511
2512 drawQuad(mProgram, "position", 0.5f);
2513 EXPECT_GL_NO_ERROR();
2514 // Red channel: width of level 1 of texture A: 32.
2515 // Green channel: width of level 3 of texture B: 16.
2516 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2517}
2518
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002519// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2520// ES 3.0.4 table 3.24
2521TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2522{
2523 glActiveTexture(GL_TEXTURE0);
2524 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2525 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2526 EXPECT_GL_NO_ERROR();
2527
2528 drawQuad(mProgram, "position", 0.5f);
2529
2530 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2531}
2532
2533// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2534// ES 3.0.4 table 3.24
2535TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2536{
2537 glActiveTexture(GL_TEXTURE0);
2538 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2539 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2540 EXPECT_GL_NO_ERROR();
2541
2542 drawQuad(mProgram, "position", 0.5f);
2543
2544 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2545}
2546
2547// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2548// ES 3.0.4 table 3.24
2549TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2550{
2551 if (extensionEnabled("GL_OES_texture_float"))
2552 {
2553 glActiveTexture(GL_TEXTURE0);
2554 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2555 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2556 EXPECT_GL_NO_ERROR();
2557
2558 drawQuad(mProgram, "position", 0.5f);
2559
2560 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2561 }
2562}
2563
2564// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2565// ES 3.0.4 table 3.24
2566TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2567{
2568 if (extensionEnabled("GL_OES_texture_half_float"))
2569 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002570 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002571 {
2572 std::cout << "Test skipped on NVIDIA" << std::endl;
2573 return;
2574 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002575 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2576 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2577 {
2578 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2579 return;
2580 }
2581
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002582 glActiveTexture(GL_TEXTURE0);
2583 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2584 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2585 nullptr);
2586 EXPECT_GL_NO_ERROR();
2587
2588 drawQuad(mProgram, "position", 0.5f);
2589
2590 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2591 }
2592}
2593
2594// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2595// ES 3.0.4 table 3.24
2596TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2597{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002598 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002599 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002600 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002601 return;
2602 }
2603 glActiveTexture(GL_TEXTURE0);
2604 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2608 EXPECT_GL_NO_ERROR();
2609
2610 drawQuad(mProgram, "position", 0.5f);
2611
2612 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2613}
2614
2615// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2616// ES 3.0.4 table 3.24
2617TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2618{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002619 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002620 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002621 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002622 return;
2623 }
2624 glActiveTexture(GL_TEXTURE0);
2625 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2626
2627 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2629 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2630 EXPECT_GL_NO_ERROR();
2631
2632 drawQuad(mProgram, "position", 0.5f);
2633
2634 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2635}
2636
2637// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2638// ES 3.0.4 table 3.24
2639TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2640{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002641 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002642 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002643 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002644 return;
2645 }
2646 glActiveTexture(GL_TEXTURE0);
2647 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2648 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2651 EXPECT_GL_NO_ERROR();
2652
2653 drawQuad(mProgram, "position", 0.5f);
2654
2655 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2656}
2657
2658// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2659// ES 3.0.4 table 3.24
2660TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2661{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002662 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002663 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002664 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002665 return;
2666 }
2667 glActiveTexture(GL_TEXTURE0);
2668 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2669 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2672 EXPECT_GL_NO_ERROR();
2673
2674 drawQuad(mProgram, "position", 0.5f);
2675
2676 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2677}
2678
2679// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2680// ES 3.0.4 table 3.24
2681TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2682{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002683 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002684 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002685 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002686 return;
2687 }
2688 glActiveTexture(GL_TEXTURE0);
2689 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2690 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2691 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2693 EXPECT_GL_NO_ERROR();
2694
2695 drawQuad(mProgram, "position", 0.5f);
2696
2697 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2698}
2699
2700// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2701// ES 3.0.4 table 3.24
2702TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2703{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002704 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002705 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002706 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002707 return;
2708 }
2709 glActiveTexture(GL_TEXTURE0);
2710 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2714 EXPECT_GL_NO_ERROR();
2715
2716 drawQuad(mProgram, "position", 0.5f);
2717
2718 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2719}
2720
2721// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2722// ES 3.0.4 table 3.24
2723TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2724{
2725 glActiveTexture(GL_TEXTURE0);
2726 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2727 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2728 EXPECT_GL_NO_ERROR();
2729
2730 drawQuad(mProgram, "position", 0.5f);
2731
2732 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2733}
2734
2735// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2736// ES 3.0.4 table 3.24
2737TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2738{
2739 glActiveTexture(GL_TEXTURE0);
2740 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2741 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2742 nullptr);
2743 EXPECT_GL_NO_ERROR();
2744
2745 drawQuad(mProgram, "position", 0.5f);
2746
2747 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2748}
2749
2750// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2751// ES 3.0.4 table 3.24
2752TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2753{
Jamie Madillbb1db482017-01-10 10:48:32 -05002754 if (IsOSX() && IsIntel() && IsOpenGL())
2755 {
2756 // Seems to fail on OSX 10.12 Intel.
2757 std::cout << "Test skipped on OSX Intel." << std::endl;
2758 return;
2759 }
2760
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002761 glActiveTexture(GL_TEXTURE0);
2762 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2763 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2764 EXPECT_GL_NO_ERROR();
2765
2766 drawQuad(mProgram, "position", 0.5f);
2767
2768 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2769}
2770
2771// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2772// ES 3.0.4 table 3.24
2773TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2774{
Jamie Madillbb1db482017-01-10 10:48:32 -05002775 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002776 {
2777 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002778 // Also seems to fail on OSX 10.12 Intel.
2779 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002780 return;
2781 }
2782
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002783 glActiveTexture(GL_TEXTURE0);
2784 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2785 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2786 EXPECT_GL_NO_ERROR();
2787
2788 drawQuad(mProgram, "position", 0.5f);
2789
2790 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2791}
2792
Olli Etuaho96963162016-03-21 11:54:33 +02002793// Use a sampler in a uniform struct.
2794TEST_P(SamplerInStructTest, SamplerInStruct)
2795{
2796 runSamplerInStructTest();
2797}
2798
2799// Use a sampler in a uniform struct that's passed as a function parameter.
2800TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2801{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002802 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2803 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2804 {
2805 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2806 return;
2807 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002808
2809 if (IsWindows() && IsIntel() && IsOpenGL())
2810 {
2811 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2812 return;
2813 }
2814
Olli Etuaho96963162016-03-21 11:54:33 +02002815 runSamplerInStructTest();
2816}
2817
2818// Use a sampler in a uniform struct array with a struct from the array passed as a function
2819// parameter.
2820TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
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// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2837// parameter.
2838TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2839{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002840 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2841 {
2842 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2843 return;
2844 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002845 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2846 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2847 {
2848 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2849 return;
2850 }
Olli Etuaho96963162016-03-21 11:54:33 +02002851 runSamplerInStructTest();
2852}
2853
2854// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2855// similarly named uniform.
2856TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2857{
2858 runSamplerInStructTest();
2859}
2860
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002861class TextureLimitsTest : public ANGLETest
2862{
2863 protected:
2864 struct RGBA8
2865 {
2866 uint8_t R, G, B, A;
2867 };
2868
2869 TextureLimitsTest()
2870 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2871 {
2872 setWindowWidth(128);
2873 setWindowHeight(128);
2874 setConfigRedBits(8);
2875 setConfigGreenBits(8);
2876 setConfigBlueBits(8);
2877 setConfigAlphaBits(8);
2878 }
2879
2880 ~TextureLimitsTest()
2881 {
2882 if (mProgram != 0)
2883 {
2884 glDeleteProgram(mProgram);
2885 mProgram = 0;
2886
2887 if (!mTextures.empty())
2888 {
2889 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2890 }
2891 }
2892 }
2893
2894 void SetUp() override
2895 {
2896 ANGLETest::SetUp();
2897
2898 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2899 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2900 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2901
2902 ASSERT_GL_NO_ERROR();
2903 }
2904
2905 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2906 GLint vertexTextureCount,
2907 GLint vertexActiveTextureCount,
2908 const std::string &fragPrefix,
2909 GLint fragmentTextureCount,
2910 GLint fragmentActiveTextureCount)
2911 {
2912 std::stringstream vertexShaderStr;
2913 vertexShaderStr << "attribute vec2 position;\n"
2914 << "varying vec4 color;\n"
2915 << "varying vec2 texCoord;\n";
2916
2917 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2918 {
2919 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2920 }
2921
2922 vertexShaderStr << "void main() {\n"
2923 << " gl_Position = vec4(position, 0, 1);\n"
2924 << " texCoord = (position * 0.5) + 0.5;\n"
2925 << " color = vec4(0);\n";
2926
2927 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2928 {
2929 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2930 << ", texCoord);\n";
2931 }
2932
2933 vertexShaderStr << "}";
2934
2935 std::stringstream fragmentShaderStr;
2936 fragmentShaderStr << "varying mediump vec4 color;\n"
2937 << "varying mediump vec2 texCoord;\n";
2938
2939 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2940 {
2941 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2942 }
2943
2944 fragmentShaderStr << "void main() {\n"
2945 << " gl_FragColor = color;\n";
2946
2947 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2948 {
2949 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2950 << ", texCoord);\n";
2951 }
2952
2953 fragmentShaderStr << "}";
2954
2955 const std::string &vertexShaderSource = vertexShaderStr.str();
2956 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2957
2958 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2959 }
2960
2961 RGBA8 getPixel(GLint texIndex)
2962 {
2963 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2964 0, 255u};
2965 return pixel;
2966 }
2967
2968 void initTextures(GLint tex2DCount, GLint texCubeCount)
2969 {
2970 GLint totalCount = tex2DCount + texCubeCount;
2971 mTextures.assign(totalCount, 0);
2972 glGenTextures(totalCount, &mTextures[0]);
2973 ASSERT_GL_NO_ERROR();
2974
2975 std::vector<RGBA8> texData(16 * 16);
2976
2977 GLint texIndex = 0;
2978 for (; texIndex < tex2DCount; ++texIndex)
2979 {
2980 texData.assign(texData.size(), getPixel(texIndex));
2981 glActiveTexture(GL_TEXTURE0 + texIndex);
2982 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2983 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2984 &texData[0]);
2985 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2987 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2988 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2989 }
2990
2991 ASSERT_GL_NO_ERROR();
2992
2993 for (; texIndex < texCubeCount; ++texIndex)
2994 {
2995 texData.assign(texData.size(), getPixel(texIndex));
2996 glActiveTexture(GL_TEXTURE0 + texIndex);
2997 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2998 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2999 GL_UNSIGNED_BYTE, &texData[0]);
3000 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3001 GL_UNSIGNED_BYTE, &texData[0]);
3002 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3003 GL_UNSIGNED_BYTE, &texData[0]);
3004 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3005 GL_UNSIGNED_BYTE, &texData[0]);
3006 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3007 GL_UNSIGNED_BYTE, &texData[0]);
3008 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3009 GL_UNSIGNED_BYTE, &texData[0]);
3010 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3011 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3012 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3013 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3014 }
3015
3016 ASSERT_GL_NO_ERROR();
3017 }
3018
3019 void testWithTextures(GLint vertexTextureCount,
3020 const std::string &vertexTexturePrefix,
3021 GLint fragmentTextureCount,
3022 const std::string &fragmentTexturePrefix)
3023 {
3024 // Generate textures
3025 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3026
3027 glUseProgram(mProgram);
3028 RGBA8 expectedSum = {0};
3029 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3030 {
3031 std::stringstream uniformNameStr;
3032 uniformNameStr << vertexTexturePrefix << texIndex;
3033 const std::string &uniformName = uniformNameStr.str();
3034 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3035 ASSERT_NE(-1, location);
3036
3037 glUniform1i(location, texIndex);
3038 RGBA8 contribution = getPixel(texIndex);
3039 expectedSum.R += contribution.R;
3040 expectedSum.G += contribution.G;
3041 }
3042
3043 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3044 {
3045 std::stringstream uniformNameStr;
3046 uniformNameStr << fragmentTexturePrefix << texIndex;
3047 const std::string &uniformName = uniformNameStr.str();
3048 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3049 ASSERT_NE(-1, location);
3050
3051 glUniform1i(location, texIndex + vertexTextureCount);
3052 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3053 expectedSum.R += contribution.R;
3054 expectedSum.G += contribution.G;
3055 }
3056
3057 ASSERT_GE(256u, expectedSum.G);
3058
3059 drawQuad(mProgram, "position", 0.5f);
3060 ASSERT_GL_NO_ERROR();
3061 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3062 }
3063
3064 GLuint mProgram;
3065 std::vector<GLuint> mTextures;
3066 GLint mMaxVertexTextures;
3067 GLint mMaxFragmentTextures;
3068 GLint mMaxCombinedTextures;
3069};
3070
3071// Test rendering with the maximum vertex texture units.
3072TEST_P(TextureLimitsTest, MaxVertexTextures)
3073{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003074 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003075 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003076 {
3077 std::cout << "Test skipped on Intel." << std::endl;
3078 return;
3079 }
3080
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003081 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3082 ASSERT_NE(0u, mProgram);
3083 ASSERT_GL_NO_ERROR();
3084
3085 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3086}
3087
3088// Test rendering with the maximum fragment texture units.
3089TEST_P(TextureLimitsTest, MaxFragmentTextures)
3090{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003091 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003092 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003093 {
3094 std::cout << "Test skipped on Intel." << std::endl;
3095 return;
3096 }
3097
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003098 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3099 ASSERT_NE(0u, mProgram);
3100 ASSERT_GL_NO_ERROR();
3101
3102 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3103}
3104
3105// Test rendering with maximum combined texture units.
3106TEST_P(TextureLimitsTest, MaxCombinedTextures)
3107{
Jamie Madill412f17d2015-09-25 08:43:54 -04003108 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003109 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003110 {
3111 std::cout << "Test skipped on Intel." << std::endl;
3112 return;
3113 }
3114
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003115 GLint vertexTextures = mMaxVertexTextures;
3116
3117 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3118 {
3119 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3120 }
3121
3122 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3123 mMaxFragmentTextures, mMaxFragmentTextures);
3124 ASSERT_NE(0u, mProgram);
3125 ASSERT_GL_NO_ERROR();
3126
3127 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3128}
3129
3130// Negative test for exceeding the number of vertex textures
3131TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3132{
3133 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3134 0);
3135 ASSERT_EQ(0u, mProgram);
3136}
3137
3138// Negative test for exceeding the number of fragment textures
3139TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3140{
3141 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3142 mMaxFragmentTextures + 1);
3143 ASSERT_EQ(0u, mProgram);
3144}
3145
3146// Test active vertex textures under the limit, but excessive textures specified.
3147TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3148{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003149 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003150 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003151 {
3152 std::cout << "Test skipped on Intel." << std::endl;
3153 return;
3154 }
3155
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003156 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3157 ASSERT_NE(0u, mProgram);
3158 ASSERT_GL_NO_ERROR();
3159
3160 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3161}
3162
3163// Test active fragment textures under the limit, but excessive textures specified.
3164TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3165{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003166 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003167 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003168 {
3169 std::cout << "Test skipped on Intel." << std::endl;
3170 return;
3171 }
3172
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003173 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3174 mMaxFragmentTextures);
3175 ASSERT_NE(0u, mProgram);
3176 ASSERT_GL_NO_ERROR();
3177
3178 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3179}
3180
3181// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003182// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003183TEST_P(TextureLimitsTest, TextureTypeConflict)
3184{
3185 const std::string &vertexShader =
3186 "attribute vec2 position;\n"
3187 "varying float color;\n"
3188 "uniform sampler2D tex2D;\n"
3189 "uniform samplerCube texCube;\n"
3190 "void main() {\n"
3191 " gl_Position = vec4(position, 0, 1);\n"
3192 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3193 " color = texture2D(tex2D, texCoord).x;\n"
3194 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3195 "}";
3196 const std::string &fragmentShader =
3197 "varying mediump float color;\n"
3198 "void main() {\n"
3199 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3200 "}";
3201
3202 mProgram = CompileProgram(vertexShader, fragmentShader);
3203 ASSERT_NE(0u, mProgram);
3204
3205 initTextures(1, 0);
3206
3207 glUseProgram(mProgram);
3208 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3209 ASSERT_NE(-1, tex2DLocation);
3210 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3211 ASSERT_NE(-1, texCubeLocation);
3212
3213 glUniform1i(tex2DLocation, 0);
3214 glUniform1i(texCubeLocation, 0);
3215 ASSERT_GL_NO_ERROR();
3216
3217 drawQuad(mProgram, "position", 0.5f);
3218 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3219}
3220
Vincent Lang25ab4512016-05-13 18:13:59 +02003221class Texture2DNorm16TestES3 : public Texture2DTestES3
3222{
3223 protected:
3224 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3225
3226 void SetUp() override
3227 {
3228 Texture2DTestES3::SetUp();
3229
3230 glActiveTexture(GL_TEXTURE0);
3231 glGenTextures(3, mTextures);
3232 glGenFramebuffers(1, &mFBO);
3233 glGenRenderbuffers(1, &mRenderbuffer);
3234
3235 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3236 {
3237 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3240 }
3241
3242 glBindTexture(GL_TEXTURE_2D, 0);
3243
3244 ASSERT_GL_NO_ERROR();
3245 }
3246
3247 void TearDown() override
3248 {
3249 glDeleteTextures(3, mTextures);
3250 glDeleteFramebuffers(1, &mFBO);
3251 glDeleteRenderbuffers(1, &mRenderbuffer);
3252
3253 Texture2DTestES3::TearDown();
3254 }
3255
3256 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3257 {
Geoff Langf607c602016-09-21 11:46:48 -04003258 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3259 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003260
3261 setUpProgram();
3262
3263 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3264 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3265 0);
3266
3267 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3268 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3269
3270 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003271 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003272
3273 EXPECT_GL_NO_ERROR();
3274
3275 drawQuad(mProgram, "position", 0.5f);
3276
Geoff Langf607c602016-09-21 11:46:48 -04003277 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003278
Geoff Langf607c602016-09-21 11:46:48 -04003279 EXPECT_PIXEL_COLOR_EQ(
3280 0, 0, SliceFormatColor(
3281 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003282
3283 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3284
3285 ASSERT_GL_NO_ERROR();
3286 }
3287
3288 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3289 {
3290 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003291 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003292
3293 setUpProgram();
3294
3295 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3296 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3297
3298 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3299 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3300 0);
3301
3302 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003303 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003304
3305 EXPECT_GL_NO_ERROR();
3306
3307 drawQuad(mProgram, "position", 0.5f);
3308
Geoff Langf607c602016-09-21 11:46:48 -04003309 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3310 EXPECT_PIXEL_COLOR_EQ(
3311 0, 0, SliceFormatColor(
3312 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003313
3314 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3315 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3316 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3317 mRenderbuffer);
3318 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3319 EXPECT_GL_NO_ERROR();
3320
3321 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3322 glClear(GL_COLOR_BUFFER_BIT);
3323
3324 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3325
Geoff Langf607c602016-09-21 11:46:48 -04003326 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003327
3328 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3329
3330 ASSERT_GL_NO_ERROR();
3331 }
3332
3333 GLuint mTextures[3];
3334 GLuint mFBO;
3335 GLuint mRenderbuffer;
3336};
3337
3338// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3339TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3340{
3341 if (!extensionEnabled("GL_EXT_texture_norm16"))
3342 {
3343 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3344 return;
3345 }
3346
3347 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3348 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3349 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3350 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3351 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3352 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3353 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3354 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3355
3356 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3357 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3358 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3359}
3360
Olli Etuaho95faa232016-06-07 14:01:53 -07003361// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3362// GLES 3.0.4 section 3.8.3.
3363TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3364{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003365 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003366 {
3367 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3368 return;
3369 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003370 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3371 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3372 {
3373 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3374 return;
3375 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003376
3377 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3380 ASSERT_GL_NO_ERROR();
3381
3382 // SKIP_IMAGES should not have an effect on uploading 2D textures
3383 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3384 ASSERT_GL_NO_ERROR();
3385
3386 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3387
3388 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3389 pixelsGreen.data());
3390 ASSERT_GL_NO_ERROR();
3391
3392 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3393 pixelsGreen.data());
3394 ASSERT_GL_NO_ERROR();
3395
3396 glUseProgram(mProgram);
3397 drawQuad(mProgram, "position", 0.5f);
3398 ASSERT_GL_NO_ERROR();
3399
3400 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3401}
3402
Olli Etuaho989cac32016-06-08 16:18:49 -07003403// Test that skip defined in unpack parameters is taken into account when determining whether
3404// unpacking source extends outside unpack buffer bounds.
3405TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3406{
3407 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3410 ASSERT_GL_NO_ERROR();
3411
3412 GLBuffer buf;
3413 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3414 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3415 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3416 GL_DYNAMIC_COPY);
3417 ASSERT_GL_NO_ERROR();
3418
3419 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3420 ASSERT_GL_NO_ERROR();
3421
3422 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3423 ASSERT_GL_NO_ERROR();
3424
3425 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3426 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3427
3428 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3429 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3430 ASSERT_GL_NO_ERROR();
3431
3432 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3433 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3434}
3435
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003436// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3437TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3438{
3439 if (IsD3D11())
3440 {
3441 std::cout << "Test skipped on D3D." << std::endl;
3442 return;
3443 }
3444 if (IsOSX() && IsAMD())
3445 {
3446 // Incorrect rendering results seen on OSX AMD.
3447 std::cout << "Test skipped on OSX AMD." << std::endl;
3448 return;
3449 }
3450
3451 const GLuint width = 8u;
3452 const GLuint height = 8u;
3453 const GLuint unpackRowLength = 5u;
3454 const GLuint unpackSkipPixels = 1u;
3455
3456 setWindowWidth(width);
3457 setWindowHeight(height);
3458
3459 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3462 ASSERT_GL_NO_ERROR();
3463
3464 GLBuffer buf;
3465 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3466 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3467 GLColor::green);
3468
3469 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3470 {
3471 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3472 }
3473
3474 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3475 GL_DYNAMIC_COPY);
3476 ASSERT_GL_NO_ERROR();
3477
3478 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3479 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3480 ASSERT_GL_NO_ERROR();
3481
3482 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3483 ASSERT_GL_NO_ERROR();
3484
3485 glUseProgram(mProgram);
3486 drawQuad(mProgram, "position", 0.5f);
3487 ASSERT_GL_NO_ERROR();
3488
3489 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3490 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3491 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3492 actual.data());
3493 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3494 EXPECT_EQ(expected, actual);
3495}
3496
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003497template <typename T>
3498T UNorm(double value)
3499{
3500 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3501}
3502
3503// Test rendering a depth texture with mipmaps.
3504TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3505{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003506 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3507 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3508 // http://anglebugs.com/1706
3509 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003510 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003511 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003512 return;
3513 }
3514
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003515 const int size = getWindowWidth();
3516
3517 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003518 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003519
3520 glActiveTexture(GL_TEXTURE0);
3521 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3522 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3523 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3526 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3527 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3528 ASSERT_GL_NO_ERROR();
3529
3530 glUseProgram(mProgram);
3531 glUniform1i(mTexture2DUniformLocation, 0);
3532
3533 std::vector<unsigned char> expected;
3534
3535 for (int level = 0; level < levels; ++level)
3536 {
3537 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3538 expected.push_back(UNorm<unsigned char>(value));
3539
3540 int levelDim = dim(level);
3541
3542 ASSERT_GT(levelDim, 0);
3543
3544 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3545 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3546 GL_UNSIGNED_INT, initData.data());
3547 }
3548 ASSERT_GL_NO_ERROR();
3549
3550 for (int level = 0; level < levels; ++level)
3551 {
3552 glViewport(0, 0, dim(level), dim(level));
3553 drawQuad(mProgram, "position", 0.5f);
3554 GLColor actual = ReadColor(0, 0);
3555 EXPECT_NEAR(expected[level], actual.R, 10u);
3556 }
3557
3558 ASSERT_GL_NO_ERROR();
3559}
3560
Jamie Madill7ffdda92016-09-08 13:26:51 -04003561// Tests unpacking into the unsized GL_ALPHA format.
3562TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3563{
3564 // TODO(jmadill): Figure out why this fails on OSX.
3565 ANGLE_SKIP_TEST_IF(IsOSX());
3566
3567 // Initialize the texure.
3568 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3569 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3570 GL_UNSIGNED_BYTE, nullptr);
3571 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3572 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3573
3574 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3575
3576 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003577 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003578 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3579 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3580 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3581 GL_STATIC_DRAW);
3582
3583 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3584 GL_UNSIGNED_BYTE, nullptr);
3585
3586 // Clear to a weird color to make sure we're drawing something.
3587 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3588 glClear(GL_COLOR_BUFFER_BIT);
3589
3590 // Draw with the alpha texture and verify.
3591 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003592
3593 ASSERT_GL_NO_ERROR();
3594 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3595}
3596
Jamie Madill2e600342016-09-19 13:56:40 -04003597// Ensure stale unpack data doesn't propagate in D3D11.
3598TEST_P(Texture2DTestES3, StaleUnpackData)
3599{
3600 // Init unpack buffer.
3601 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3602 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3603
3604 GLBuffer unpackBuffer;
3605 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3606 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3607 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3608 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3609
3610 // Create from unpack buffer.
3611 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3612 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3613 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3614 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3616
3617 drawQuad(mProgram, "position", 0.5f);
3618
3619 ASSERT_GL_NO_ERROR();
3620 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3621
3622 // Fill unpack with green, recreating buffer.
3623 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3624 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3625 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3626
3627 // Reinit texture with green.
3628 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3629 GL_UNSIGNED_BYTE, nullptr);
3630
3631 drawQuad(mProgram, "position", 0.5f);
3632
3633 ASSERT_GL_NO_ERROR();
3634 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3635}
3636
Jamie Madillf097e232016-11-05 00:44:15 -04003637// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3638// being properly checked, and the texture storage of the previous texture format was persisting.
3639// This would result in an ASSERT in debug and incorrect rendering in release.
3640// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3641TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3642{
3643 GLTexture tex;
3644 glBindTexture(GL_TEXTURE_3D, tex.get());
3645 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3646
3647 GLFramebuffer framebuffer;
3648 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3649 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3650
3651 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3652
3653 std::vector<uint8_t> pixelData(100, 0);
3654
3655 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3656 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3657 pixelData.data());
3658
3659 ASSERT_GL_NO_ERROR();
3660}
3661
Jamie Madillfa05f602015-05-07 13:47:11 -04003662// 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 +02003663// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003664ANGLE_INSTANTIATE_TEST(Texture2DTest,
3665 ES2_D3D9(),
3666 ES2_D3D11(),
3667 ES2_D3D11_FL9_3(),
3668 ES2_OPENGL(),
3669 ES2_OPENGLES());
3670ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3671 ES2_D3D9(),
3672 ES2_D3D11(),
3673 ES2_D3D11_FL9_3(),
3674 ES2_OPENGL(),
3675 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003676ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3677 ES2_D3D9(),
3678 ES2_D3D11(),
3679 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003680 ES2_OPENGL(),
3681 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003682ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3683 ES2_D3D9(),
3684 ES2_D3D11(),
3685 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003686 ES2_OPENGL(),
3687 ES2_OPENGLES());
3688ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3689 ES2_D3D9(),
3690 ES2_D3D11(),
3691 ES2_D3D11_FL9_3(),
3692 ES2_OPENGL(),
3693 ES2_OPENGLES());
3694ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3695 ES2_D3D9(),
3696 ES2_D3D11(),
3697 ES2_D3D11_FL9_3(),
3698 ES2_OPENGL(),
3699 ES2_OPENGLES());
3700ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003701ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003702ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3703ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3704 ES3_D3D11(),
3705 ES3_OPENGL(),
3706 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003707ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3708 ES3_D3D11(),
3709 ES3_OPENGL(),
3710 ES3_OPENGLES());
3711ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3712ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003713ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003714ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3715 ES2_D3D11(),
3716 ES2_D3D11_FL9_3(),
3717 ES2_D3D9(),
3718 ES2_OPENGL(),
3719 ES2_OPENGLES());
3720ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3721 ES2_D3D11(),
3722 ES2_D3D11_FL9_3(),
3723 ES2_D3D9(),
3724 ES2_OPENGL(),
3725 ES2_OPENGLES());
3726ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3727 ES2_D3D11(),
3728 ES2_D3D11_FL9_3(),
3729 ES2_D3D9(),
3730 ES2_OPENGL(),
3731 ES2_OPENGLES());
3732ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3733 ES2_D3D11(),
3734 ES2_D3D11_FL9_3(),
3735 ES2_D3D9(),
3736 ES2_OPENGL(),
3737 ES2_OPENGLES());
3738ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3739 ES2_D3D11(),
3740 ES2_D3D11_FL9_3(),
3741 ES2_D3D9(),
3742 ES2_OPENGL(),
3743 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003744ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003745ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003746
Jamie Madill7ffdda92016-09-08 13:26:51 -04003747} // anonymous namespace