blob: 3fa6a149fac7971709ff0ffebb635e493ff7f42d [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020052 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040053 (
54 precision highp float;
55 attribute vec4 position;
56 varying vec2 texcoord;
57
58 void main()
59 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020060 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040061 texcoord = (position.xy * 0.5) + 0.5;
62 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +020063 )
Geoff Langc41e42d2014-04-28 10:58:16 -040064 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +020065 }
Geoff Langc41e42d2014-04-28 10:58:16 -040066
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 virtual std::string getFragmentShaderSource() = 0;
68
Olli Etuahoa1c917f2016-04-06 13:50:03 +030069 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020070 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020071 const std::string vertexShaderSource = getVertexShaderSource();
72 const std::string fragmentShaderSource = getFragmentShaderSource();
73
74 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
75 ASSERT_NE(0u, mProgram);
76 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030077 }
78
79 void SetUp() override
80 {
81 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020082
83 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020084 }
85
86 void TearDown() override
87 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020088 glBindFramebuffer(GL_FRAMEBUFFER, 0);
89 glDeleteFramebuffers(1, &mFramebuffer);
90 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020091 glDeleteProgram(mProgram);
92 ANGLETest::TearDown();
93 }
94
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020095 void setUpFramebuffer()
96 {
97 // We use an FBO to work around an issue where the default framebuffer applies SRGB
98 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
99 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
100 // section 4.4 says that the format of the default framebuffer is entirely up to the window
101 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
102 // SRGB conversion like desktop GL does.
103 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
104 glGenFramebuffers(1, &mFramebuffer);
105 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
106
107 glGenTextures(1, &mFramebufferColorTexture);
108 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
110 GL_UNSIGNED_BYTE, nullptr);
111 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
112 mFramebufferColorTexture, 0);
113 ASSERT_GL_NO_ERROR();
114 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
115 glBindTexture(GL_TEXTURE_2D, 0);
116 }
117
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200118 // Returns the created texture ID.
119 GLuint create2DTexture()
120 {
121 GLuint texture2D;
122 glGenTextures(1, &texture2D);
123 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800124 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200125 EXPECT_GL_NO_ERROR();
126 return texture2D;
127 }
128
129 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200130 GLuint mFramebuffer;
131
132 private:
133 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200134};
135
136class Texture2DTest : public TexCoordDrawTest
137{
138 protected:
139 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
140
141 std::string getFragmentShaderSource() override
142 {
143 return std::string(SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -0400144 (
145 precision highp float;
146 uniform sampler2D tex;
147 varying vec2 texcoord;
148
149 void main()
150 {
151 gl_FragColor = texture2D(tex, texcoord);
152 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200153 )
Geoff Langc41e42d2014-04-28 10:58:16 -0400154 );
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200155 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400156
Olli Etuaho96963162016-03-21 11:54:33 +0200157 virtual const char *getTextureUniformName() { return "tex"; }
158
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300159 void setUpProgram() override
160 {
161 TexCoordDrawTest::setUpProgram();
162 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
163 ASSERT_NE(-1, mTexture2DUniformLocation);
164 }
165
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200166 void SetUp() override
167 {
168 TexCoordDrawTest::SetUp();
169 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170
Jamie Madill9aca0592014-10-06 16:26:59 -0400171 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400175 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400176 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200177 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400178 }
179
Jamie Madillbc393df2015-01-29 13:46:07 -0500180 // Tests CopyTexSubImage with floating point textures of various formats.
181 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
182 {
Geoff Langbde666a2015-04-07 17:17:08 -0400183 // TODO(jmadill): Figure out why this is broken on Intel D3D11
Jamie Madill518b9fa2016-03-02 11:26:02 -0500184 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Geoff Langbde666a2015-04-07 17:17:08 -0400185 {
186 std::cout << "Test skipped on Intel D3D11." << std::endl;
187 return;
188 }
189
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300190 setUpProgram();
191
Martin Radev1be913c2016-07-11 17:59:16 +0300192 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400193 {
Geoff Langc4e93662017-05-01 10:45:59 -0400194 if (!extensionEnabled("GL_EXT_texture_storage"))
195 {
196 std::cout << "Test skipped due to missing GL_EXT_texture_storage." << std::endl;
197 return;
198 }
199
Geoff Langfbfa47c2015-03-31 11:26:00 -0400200 if (!extensionEnabled("GL_OES_texture_float"))
201 {
202 std::cout << "Test skipped due to missing GL_OES_texture_float." << std::endl;
203 return;
204 }
205
206 if ((sourceImageChannels < 3 || destImageChannels < 3) && !extensionEnabled("GL_EXT_texture_rg"))
207 {
208 std::cout << "Test skipped due to missing GL_EXT_texture_rg." << std::endl;
209 return;
210 }
211 }
212
Jamie Madillbc393df2015-01-29 13:46:07 -0500213 GLfloat sourceImageData[4][16] =
214 {
215 { // R
216 1.0f,
217 0.0f,
218 0.0f,
219 1.0f
220 },
221 { // RG
222 1.0f, 0.0f,
223 0.0f, 1.0f,
224 0.0f, 0.0f,
225 1.0f, 1.0f
226 },
227 { // RGB
228 1.0f, 0.0f, 0.0f,
229 0.0f, 1.0f, 0.0f,
230 0.0f, 0.0f, 1.0f,
231 1.0f, 1.0f, 0.0f
232 },
233 { // RGBA
234 1.0f, 0.0f, 0.0f, 1.0f,
235 0.0f, 1.0f, 0.0f, 1.0f,
236 0.0f, 0.0f, 1.0f, 1.0f,
237 1.0f, 1.0f, 0.0f, 1.0f
238 },
239 };
240
241 GLenum imageFormats[] =
242 {
243 GL_R32F,
244 GL_RG32F,
245 GL_RGB32F,
246 GL_RGBA32F,
247 };
248
249 GLenum sourceUnsizedFormats[] =
250 {
251 GL_RED,
252 GL_RG,
253 GL_RGB,
254 GL_RGBA,
255 };
256
257 GLuint textures[2];
258
259 glGenTextures(2, textures);
260
261 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
262 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
263 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
264 GLenum destImageFormat = imageFormats[destImageChannels - 1];
265
266 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400267 if (getClientMajorVersion() >= 3)
268 {
269 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
270 }
271 else
272 {
273 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
274 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500275 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
276 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
278
hendrikwb27f79a2015-03-04 11:26:46 -0800279 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500280 {
281 // This is not supported
282 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
283 }
284 else
285 {
286 ASSERT_GL_NO_ERROR();
287 }
288
289 GLuint fbo;
290 glGenFramebuffers(1, &fbo);
291 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
292 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
293
294 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400295 if (getClientMajorVersion() >= 3)
296 {
297 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
298 }
299 else
300 {
301 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
302 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
305
306 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
307 ASSERT_GL_NO_ERROR();
308
309 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200310 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500311
312 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
313
Olli Etuahoa314b612016-03-10 16:43:00 +0200314 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500315 if (testImageChannels > 1)
316 {
317 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
318 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
319 if (testImageChannels > 2)
320 {
321 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
322 }
323 }
324
325 glDeleteFramebuffers(1, &fbo);
326 glDeleteTextures(2, textures);
327
328 ASSERT_GL_NO_ERROR();
329 }
330
Jamie Madilld4cfa572014-07-08 10:00:32 -0400331 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400332 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400333};
334
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200335class Texture2DTestES3 : public Texture2DTest
336{
337 protected:
338 Texture2DTestES3() : Texture2DTest() {}
339
340 std::string getVertexShaderSource() override
341 {
342 return std::string(
343 "#version 300 es\n"
344 "out vec2 texcoord;\n"
345 "in vec4 position;\n"
346 "void main()\n"
347 "{\n"
348 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
349 " texcoord = (position.xy * 0.5) + 0.5;\n"
350 "}\n");
351 }
352
353 std::string getFragmentShaderSource() override
354 {
355 return std::string(
356 "#version 300 es\n"
357 "precision highp float;\n"
358 "uniform highp sampler2D tex;\n"
359 "in vec2 texcoord;\n"
360 "out vec4 fragColor;\n"
361 "void main()\n"
362 "{\n"
363 " fragColor = texture(tex, texcoord);\n"
364 "}\n");
365 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300366
367 void SetUp() override
368 {
369 Texture2DTest::SetUp();
370 setUpProgram();
371 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200372};
373
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200374class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
375{
376 protected:
377 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
378
379 std::string getVertexShaderSource() override
380 {
381 return std::string(
382 "#version 300 es\n"
383 "out vec2 texcoord;\n"
384 "in vec4 position;\n"
385 "void main()\n"
386 "{\n"
387 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
388 " texcoord = (position.xy * 0.5) + 0.5;\n"
389 "}\n");
390 }
391
392 std::string getFragmentShaderSource() override
393 {
394 return std::string(
395 "#version 300 es\n"
396 "precision highp float;\n"
397 "uniform highp isampler2D tex;\n"
398 "in vec2 texcoord;\n"
399 "out vec4 fragColor;\n"
400 "void main()\n"
401 "{\n"
402 " vec4 green = vec4(0, 1, 0, 1);\n"
403 " vec4 black = vec4(0, 0, 0, 0);\n"
404 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
405 "}\n");
406 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300407
408 void SetUp() override
409 {
410 Texture2DTest::SetUp();
411 setUpProgram();
412 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200413};
414
415class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
416{
417 protected:
418 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
419
420 std::string getVertexShaderSource() override
421 {
422 return std::string(
423 "#version 300 es\n"
424 "out vec2 texcoord;\n"
425 "in vec4 position;\n"
426 "void main()\n"
427 "{\n"
428 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
429 " texcoord = (position.xy * 0.5) + 0.5;\n"
430 "}\n");
431 }
432
433 std::string getFragmentShaderSource() override
434 {
435 return std::string(
436 "#version 300 es\n"
437 "precision highp float;\n"
438 "uniform highp usampler2D tex;\n"
439 "in vec2 texcoord;\n"
440 "out vec4 fragColor;\n"
441 "void main()\n"
442 "{\n"
443 " vec4 green = vec4(0, 1, 0, 1);\n"
444 " vec4 black = vec4(0, 0, 0, 0);\n"
445 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
446 "}\n");
447 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300448
449 void SetUp() override
450 {
451 Texture2DTest::SetUp();
452 setUpProgram();
453 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200454};
455
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200456class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400457{
458 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200459 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
460
461 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400462 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200463 return std::string(SHADER_SOURCE
464 (
465 precision highp float;
466 attribute vec4 position;
467 varying vec2 texcoord;
468
469 uniform vec2 drawScale;
470
471 void main()
472 {
473 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
474 texcoord = (position.xy * 0.5) + 0.5;
475 }
476 )
477 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400478 }
479
480 void SetUp() override
481 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200482 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300483
484 setUpProgram();
485
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200486 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
487 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400488
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200489 glUseProgram(mProgram);
490 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
491 glUseProgram(0);
492 ASSERT_GL_NO_ERROR();
493 }
494
495 GLint mDrawScaleUniformLocation;
496};
497
Olli Etuaho4644a202016-01-12 15:12:53 +0200498class Sampler2DAsFunctionParameterTest : public Texture2DTest
499{
500 protected:
501 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
502
503 std::string getFragmentShaderSource() override
504 {
505 return std::string(SHADER_SOURCE
506 (
507 precision highp float;
508 uniform sampler2D tex;
509 varying vec2 texcoord;
510
511 vec4 computeFragColor(sampler2D aTex)
512 {
513 return texture2D(aTex, texcoord);
514 }
515
516 void main()
517 {
518 gl_FragColor = computeFragColor(tex);
519 }
520 )
521 );
522 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300523
524 void SetUp() override
525 {
526 Texture2DTest::SetUp();
527 setUpProgram();
528 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200529};
530
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200531class TextureCubeTest : public TexCoordDrawTest
532{
533 protected:
534 TextureCubeTest()
535 : TexCoordDrawTest(),
536 mTexture2D(0),
537 mTextureCube(0),
538 mTexture2DUniformLocation(-1),
539 mTextureCubeUniformLocation(-1)
540 {
541 }
542
543 std::string getFragmentShaderSource() override
544 {
545 return std::string(SHADER_SOURCE
546 (
547 precision highp float;
548 uniform sampler2D tex2D;
549 uniform samplerCube texCube;
550 varying vec2 texcoord;
551
552 void main()
553 {
554 gl_FragColor = texture2D(tex2D, texcoord);
555 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
556 }
557 )
558 );
559 }
560
561 void SetUp() override
562 {
563 TexCoordDrawTest::SetUp();
564
565 glGenTextures(1, &mTextureCube);
566 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400567 for (GLenum face = 0; face < 6; face++)
568 {
569 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
570 GL_UNSIGNED_BYTE, nullptr);
571 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200572 EXPECT_GL_NO_ERROR();
573
574 mTexture2D = create2DTexture();
575
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300576 setUpProgram();
577
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200578 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
579 ASSERT_NE(-1, mTexture2DUniformLocation);
580 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
581 ASSERT_NE(-1, mTextureCubeUniformLocation);
582 }
583
584 void TearDown() override
585 {
586 glDeleteTextures(1, &mTextureCube);
587 TexCoordDrawTest::TearDown();
588 }
589
590 GLuint mTexture2D;
591 GLuint mTextureCube;
592 GLint mTexture2DUniformLocation;
593 GLint mTextureCubeUniformLocation;
594};
595
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200596class SamplerArrayTest : public TexCoordDrawTest
597{
598 protected:
599 SamplerArrayTest()
600 : TexCoordDrawTest(),
601 mTexture2DA(0),
602 mTexture2DB(0),
603 mTexture0UniformLocation(-1),
604 mTexture1UniformLocation(-1)
605 {
606 }
607
608 std::string getFragmentShaderSource() override
609 {
610 return std::string(SHADER_SOURCE
611 (
612 precision mediump float;
613 uniform highp sampler2D tex2DArray[2];
614 varying vec2 texcoord;
615 void main()
616 {
617 gl_FragColor = texture2D(tex2DArray[0], texcoord);
618 gl_FragColor += texture2D(tex2DArray[1], texcoord);
619 }
620 )
621 );
622 }
623
624 void SetUp() override
625 {
626 TexCoordDrawTest::SetUp();
627
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300628 setUpProgram();
629
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200630 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
631 ASSERT_NE(-1, mTexture0UniformLocation);
632 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
633 ASSERT_NE(-1, mTexture1UniformLocation);
634
635 mTexture2DA = create2DTexture();
636 mTexture2DB = create2DTexture();
637 ASSERT_GL_NO_ERROR();
638 }
639
640 void TearDown() override
641 {
642 glDeleteTextures(1, &mTexture2DA);
643 glDeleteTextures(1, &mTexture2DB);
644 TexCoordDrawTest::TearDown();
645 }
646
647 void testSamplerArrayDraw()
648 {
649 GLubyte texData[4];
650 texData[0] = 0;
651 texData[1] = 60;
652 texData[2] = 0;
653 texData[3] = 255;
654
655 glActiveTexture(GL_TEXTURE0);
656 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
657 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
658
659 texData[1] = 120;
660 glActiveTexture(GL_TEXTURE1);
661 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
662 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
663 EXPECT_GL_ERROR(GL_NO_ERROR);
664
665 glUseProgram(mProgram);
666 glUniform1i(mTexture0UniformLocation, 0);
667 glUniform1i(mTexture1UniformLocation, 1);
668 drawQuad(mProgram, "position", 0.5f);
669 EXPECT_GL_NO_ERROR();
670
671 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
672 }
673
674 GLuint mTexture2DA;
675 GLuint mTexture2DB;
676 GLint mTexture0UniformLocation;
677 GLint mTexture1UniformLocation;
678};
679
680
681class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
682{
683 protected:
684 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
685
686 std::string getFragmentShaderSource() override
687 {
688 return std::string(SHADER_SOURCE
689 (
690 precision mediump float;
691 uniform highp sampler2D tex2DArray[2];
692 varying vec2 texcoord;
693
694 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
695 {
696 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
697 }
698
699 void main()
700 {
701 gl_FragColor = computeFragColor(tex2DArray);
702 }
703 )
704 );
705 }
706};
707
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200708class Texture2DArrayTestES3 : public TexCoordDrawTest
709{
710 protected:
711 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
712
713 std::string getVertexShaderSource() override
714 {
715 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400716 "#version 300 es\n"
717 "out vec2 texcoord;\n"
718 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200719 "void main()\n"
720 "{\n"
721 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
722 " texcoord = (position.xy * 0.5) + 0.5;\n"
723 "}\n");
724 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400725
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200726 std::string getFragmentShaderSource() override
727 {
728 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400729 "#version 300 es\n"
730 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200731 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400732 "in vec2 texcoord;\n"
733 "out vec4 fragColor;\n"
734 "void main()\n"
735 "{\n"
736 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200737 "}\n");
738 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400739
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200740 void SetUp() override
741 {
742 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400743
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300744 setUpProgram();
745
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200746 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400747 ASSERT_NE(-1, mTextureArrayLocation);
748
749 glGenTextures(1, &m2DArrayTexture);
750 ASSERT_GL_NO_ERROR();
751 }
752
753 void TearDown() override
754 {
755 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200756 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400757 }
758
759 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400760 GLint mTextureArrayLocation;
761};
762
Olli Etuahobce743a2016-01-15 17:18:28 +0200763class TextureSizeTextureArrayTest : public TexCoordDrawTest
764{
765 protected:
766 TextureSizeTextureArrayTest()
767 : TexCoordDrawTest(),
768 mTexture2DA(0),
769 mTexture2DB(0),
770 mTexture0Location(-1),
771 mTexture1Location(-1)
772 {
773 }
774
775 std::string getVertexShaderSource() override
776 {
777 return std::string(
778 "#version 300 es\n"
779 "in vec4 position;\n"
780 "void main()\n"
781 "{\n"
782 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
783 "}\n");
784 }
785
786 std::string getFragmentShaderSource() override
787 {
788 return std::string(
789 "#version 300 es\n"
790 "precision highp float;\n"
791 "uniform highp sampler2D tex2DArray[2];\n"
792 "out vec4 fragColor;\n"
793 "void main()\n"
794 "{\n"
795 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
796 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
797 " fragColor = vec4(red, green, 0.0, 1.0);\n"
798 "}\n");
799 }
800
801 void SetUp() override
802 {
803 TexCoordDrawTest::SetUp();
804
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300805 setUpProgram();
806
Olli Etuahobce743a2016-01-15 17:18:28 +0200807 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
808 ASSERT_NE(-1, mTexture0Location);
809 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
810 ASSERT_NE(-1, mTexture1Location);
811
812 mTexture2DA = create2DTexture();
813 mTexture2DB = create2DTexture();
814 ASSERT_GL_NO_ERROR();
815 }
816
817 void TearDown() override
818 {
819 glDeleteTextures(1, &mTexture2DA);
820 glDeleteTextures(1, &mTexture2DB);
821 TexCoordDrawTest::TearDown();
822 }
823
824 GLuint mTexture2DA;
825 GLuint mTexture2DB;
826 GLint mTexture0Location;
827 GLint mTexture1Location;
828};
829
Olli Etuahoa314b612016-03-10 16:43:00 +0200830class Texture3DTestES3 : public TexCoordDrawTest
831{
832 protected:
833 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
834
835 std::string getVertexShaderSource() override
836 {
837 return std::string(
838 "#version 300 es\n"
839 "out vec2 texcoord;\n"
840 "in vec4 position;\n"
841 "void main()\n"
842 "{\n"
843 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
844 " texcoord = (position.xy * 0.5) + 0.5;\n"
845 "}\n");
846 }
847
848 std::string getFragmentShaderSource() override
849 {
850 return std::string(
851 "#version 300 es\n"
852 "precision highp float;\n"
853 "uniform highp sampler3D tex3D;\n"
854 "in vec2 texcoord;\n"
855 "out vec4 fragColor;\n"
856 "void main()\n"
857 "{\n"
858 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
859 "}\n");
860 }
861
862 void SetUp() override
863 {
864 TexCoordDrawTest::SetUp();
865
866 glGenTextures(1, &mTexture3D);
867
868 setUpProgram();
869
870 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
871 ASSERT_NE(-1, mTexture3DUniformLocation);
872 }
873
874 void TearDown() override
875 {
876 glDeleteTextures(1, &mTexture3D);
877 TexCoordDrawTest::TearDown();
878 }
879
880 GLuint mTexture3D;
881 GLint mTexture3DUniformLocation;
882};
883
Olli Etuaho1a679902016-01-14 12:21:47 +0200884class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
885{
886 protected:
887 ShadowSamplerPlusSampler3DTestES3()
888 : TexCoordDrawTest(),
889 mTextureShadow(0),
890 mTexture3D(0),
891 mTextureShadowUniformLocation(-1),
892 mTexture3DUniformLocation(-1),
893 mDepthRefUniformLocation(-1)
894 {
895 }
896
897 std::string getVertexShaderSource() override
898 {
899 return std::string(
900 "#version 300 es\n"
901 "out vec2 texcoord;\n"
902 "in vec4 position;\n"
903 "void main()\n"
904 "{\n"
905 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
906 " texcoord = (position.xy * 0.5) + 0.5;\n"
907 "}\n");
908 }
909
910 std::string getFragmentShaderSource() override
911 {
912 return std::string(
913 "#version 300 es\n"
914 "precision highp float;\n"
915 "uniform highp sampler2DShadow tex2DShadow;\n"
916 "uniform highp sampler3D tex3D;\n"
917 "in vec2 texcoord;\n"
918 "uniform float depthRef;\n"
919 "out vec4 fragColor;\n"
920 "void main()\n"
921 "{\n"
922 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
923 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
924 "}\n");
925 }
926
927 void SetUp() override
928 {
929 TexCoordDrawTest::SetUp();
930
931 glGenTextures(1, &mTexture3D);
932
933 glGenTextures(1, &mTextureShadow);
934 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
936
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300937 setUpProgram();
938
Olli Etuaho1a679902016-01-14 12:21:47 +0200939 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
940 ASSERT_NE(-1, mTextureShadowUniformLocation);
941 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
942 ASSERT_NE(-1, mTexture3DUniformLocation);
943 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
944 ASSERT_NE(-1, mDepthRefUniformLocation);
945 }
946
947 void TearDown() override
948 {
949 glDeleteTextures(1, &mTextureShadow);
950 glDeleteTextures(1, &mTexture3D);
951 TexCoordDrawTest::TearDown();
952 }
953
954 GLuint mTextureShadow;
955 GLuint mTexture3D;
956 GLint mTextureShadowUniformLocation;
957 GLint mTexture3DUniformLocation;
958 GLint mDepthRefUniformLocation;
959};
960
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200961class SamplerTypeMixTestES3 : public TexCoordDrawTest
962{
963 protected:
964 SamplerTypeMixTestES3()
965 : TexCoordDrawTest(),
966 mTexture2D(0),
967 mTextureCube(0),
968 mTexture2DShadow(0),
969 mTextureCubeShadow(0),
970 mTexture2DUniformLocation(-1),
971 mTextureCubeUniformLocation(-1),
972 mTexture2DShadowUniformLocation(-1),
973 mTextureCubeShadowUniformLocation(-1),
974 mDepthRefUniformLocation(-1)
975 {
976 }
977
978 std::string getVertexShaderSource() override
979 {
980 return std::string(
981 "#version 300 es\n"
982 "out vec2 texcoord;\n"
983 "in vec4 position;\n"
984 "void main()\n"
985 "{\n"
986 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
987 " texcoord = (position.xy * 0.5) + 0.5;\n"
988 "}\n");
989 }
990
991 std::string getFragmentShaderSource() override
992 {
993 return std::string(
994 "#version 300 es\n"
995 "precision highp float;\n"
996 "uniform highp sampler2D tex2D;\n"
997 "uniform highp samplerCube texCube;\n"
998 "uniform highp sampler2DShadow tex2DShadow;\n"
999 "uniform highp samplerCubeShadow texCubeShadow;\n"
1000 "in vec2 texcoord;\n"
1001 "uniform float depthRef;\n"
1002 "out vec4 fragColor;\n"
1003 "void main()\n"
1004 "{\n"
1005 " fragColor = texture(tex2D, texcoord);\n"
1006 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1007 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1008 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1009 "0.125);\n"
1010 "}\n");
1011 }
1012
1013 void SetUp() override
1014 {
1015 TexCoordDrawTest::SetUp();
1016
1017 glGenTextures(1, &mTexture2D);
1018 glGenTextures(1, &mTextureCube);
1019
1020 glGenTextures(1, &mTexture2DShadow);
1021 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1022 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1023
1024 glGenTextures(1, &mTextureCubeShadow);
1025 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1026 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1027
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001028 setUpProgram();
1029
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001030 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1031 ASSERT_NE(-1, mTexture2DUniformLocation);
1032 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1033 ASSERT_NE(-1, mTextureCubeUniformLocation);
1034 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1035 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1036 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1037 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1038 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1039 ASSERT_NE(-1, mDepthRefUniformLocation);
1040
1041 ASSERT_GL_NO_ERROR();
1042 }
1043
1044 void TearDown() override
1045 {
1046 glDeleteTextures(1, &mTexture2D);
1047 glDeleteTextures(1, &mTextureCube);
1048 glDeleteTextures(1, &mTexture2DShadow);
1049 glDeleteTextures(1, &mTextureCubeShadow);
1050 TexCoordDrawTest::TearDown();
1051 }
1052
1053 GLuint mTexture2D;
1054 GLuint mTextureCube;
1055 GLuint mTexture2DShadow;
1056 GLuint mTextureCubeShadow;
1057 GLint mTexture2DUniformLocation;
1058 GLint mTextureCubeUniformLocation;
1059 GLint mTexture2DShadowUniformLocation;
1060 GLint mTextureCubeShadowUniformLocation;
1061 GLint mDepthRefUniformLocation;
1062};
1063
Olli Etuaho96963162016-03-21 11:54:33 +02001064class SamplerInStructTest : public Texture2DTest
1065{
1066 protected:
1067 SamplerInStructTest() : Texture2DTest() {}
1068
1069 const char *getTextureUniformName() override { return "us.tex"; }
1070
1071 std::string getFragmentShaderSource() override
1072 {
1073 return std::string(
1074 "precision highp float;\n"
1075 "struct S\n"
1076 "{\n"
1077 " vec4 a;\n"
1078 " highp sampler2D tex;\n"
1079 "};\n"
1080 "uniform S us;\n"
1081 "varying vec2 texcoord;\n"
1082 "void main()\n"
1083 "{\n"
1084 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1085 "}\n");
1086 }
1087
1088 void runSamplerInStructTest()
1089 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001090 setUpProgram();
1091
Olli Etuaho96963162016-03-21 11:54:33 +02001092 glActiveTexture(GL_TEXTURE0);
1093 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001094 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1095 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001096 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001097 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001098 }
1099};
1100
1101class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1102{
1103 protected:
1104 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1105
1106 std::string getFragmentShaderSource() override
1107 {
1108 return std::string(
1109 "precision highp float;\n"
1110 "struct S\n"
1111 "{\n"
1112 " vec4 a;\n"
1113 " highp sampler2D tex;\n"
1114 "};\n"
1115 "uniform S us;\n"
1116 "varying vec2 texcoord;\n"
1117 "vec4 sampleFrom(S s) {\n"
1118 " return texture2D(s.tex, texcoord + s.a.x);\n"
1119 "}\n"
1120 "void main()\n"
1121 "{\n"
1122 " gl_FragColor = sampleFrom(us);\n"
1123 "}\n");
1124 }
1125};
1126
1127class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1128{
1129 protected:
1130 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1131
1132 const char *getTextureUniformName() override { return "us[0].tex"; }
1133
1134 std::string getFragmentShaderSource() override
1135 {
1136 return std::string(
1137 "precision highp float;\n"
1138 "struct S\n"
1139 "{\n"
1140 " vec4 a;\n"
1141 " highp sampler2D tex;\n"
1142 "};\n"
1143 "uniform S us[1];\n"
1144 "varying vec2 texcoord;\n"
1145 "vec4 sampleFrom(S s) {\n"
1146 " return texture2D(s.tex, texcoord + s.a.x);\n"
1147 "}\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = sampleFrom(us[0]);\n"
1151 "}\n");
1152 }
1153};
1154
1155class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1156{
1157 protected:
1158 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1159
1160 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1161
1162 std::string getFragmentShaderSource() override
1163 {
1164 return std::string(
1165 "precision highp float;\n"
1166 "struct SUB\n"
1167 "{\n"
1168 " vec4 a;\n"
1169 " highp sampler2D tex;\n"
1170 "};\n"
1171 "struct S\n"
1172 "{\n"
1173 " SUB sub;\n"
1174 "};\n"
1175 "uniform S us[1];\n"
1176 "varying vec2 texcoord;\n"
1177 "vec4 sampleFrom(SUB s) {\n"
1178 " return texture2D(s.tex, texcoord + s.a.x);\n"
1179 "}\n"
1180 "void main()\n"
1181 "{\n"
1182 " gl_FragColor = sampleFrom(us[0].sub);\n"
1183 "}\n");
1184 }
1185};
1186
1187class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1188{
1189 protected:
1190 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1191
1192 std::string getFragmentShaderSource() override
1193 {
1194 return std::string(
1195 "precision highp float;\n"
1196 "struct S\n"
1197 "{\n"
1198 " vec4 a;\n"
1199 " highp sampler2D tex;\n"
1200 "};\n"
1201 "uniform S us;\n"
1202 "uniform float us_tex;\n"
1203 "varying vec2 texcoord;\n"
1204 "void main()\n"
1205 "{\n"
1206 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1207 "}\n");
1208 }
1209};
1210
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001211TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001212{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001213 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001214 EXPECT_GL_ERROR(GL_NO_ERROR);
1215
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001216 setUpProgram();
1217
Jamie Madillf67115c2014-04-22 13:14:05 -04001218 const GLubyte *pixels[20] = { 0 };
1219 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1220 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001221
1222 if (extensionEnabled("GL_EXT_texture_storage"))
1223 {
1224 // Create a 1-level immutable texture.
1225 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1226
1227 // Try calling sub image on the second level.
1228 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1229 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1230 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001231}
Geoff Langc41e42d2014-04-28 10:58:16 -04001232
John Bauman18319182016-09-28 14:22:27 -07001233// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1234TEST_P(Texture2DTest, QueryBinding)
1235{
1236 glBindTexture(GL_TEXTURE_2D, 0);
1237 EXPECT_GL_ERROR(GL_NO_ERROR);
1238
1239 GLint textureBinding;
1240 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1241 EXPECT_GL_NO_ERROR();
1242 EXPECT_EQ(0, textureBinding);
1243
1244 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1245 if (extensionEnabled("GL_OES_EGL_image_external") ||
1246 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1247 {
1248 EXPECT_GL_NO_ERROR();
1249 EXPECT_EQ(0, textureBinding);
1250 }
1251 else
1252 {
1253 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1254 }
1255}
1256
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001257TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001258{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001259 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001260 EXPECT_GL_ERROR(GL_NO_ERROR);
1261
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001262 setUpProgram();
1263
Geoff Langc41e42d2014-04-28 10:58:16 -04001264 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001265 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001266 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001267 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001268
1269 const GLubyte *pixel[4] = { 0 };
1270
1271 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1272 EXPECT_GL_NO_ERROR();
1273
1274 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1275 EXPECT_GL_NO_ERROR();
1276
1277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1278 EXPECT_GL_NO_ERROR();
1279}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001280
1281// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001282TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001283{
1284 glActiveTexture(GL_TEXTURE0);
1285 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1286 glActiveTexture(GL_TEXTURE1);
1287 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1288 EXPECT_GL_ERROR(GL_NO_ERROR);
1289
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001290 glUseProgram(mProgram);
1291 glUniform1i(mTexture2DUniformLocation, 0);
1292 glUniform1i(mTextureCubeUniformLocation, 1);
1293 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001294 EXPECT_GL_NO_ERROR();
1295}
Jamie Madill9aca0592014-10-06 16:26:59 -04001296
Olli Etuaho53a2da12016-01-11 15:43:32 +02001297// Test drawing with two texture types accessed from the same shader and check that the result of
1298// drawing is correct.
1299TEST_P(TextureCubeTest, CubeMapDraw)
1300{
1301 GLubyte texData[4];
1302 texData[0] = 0;
1303 texData[1] = 60;
1304 texData[2] = 0;
1305 texData[3] = 255;
1306
1307 glActiveTexture(GL_TEXTURE0);
1308 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1309 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1310
1311 glActiveTexture(GL_TEXTURE1);
1312 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1313 texData[1] = 120;
1314 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1315 texData);
1316 EXPECT_GL_ERROR(GL_NO_ERROR);
1317
1318 glUseProgram(mProgram);
1319 glUniform1i(mTexture2DUniformLocation, 0);
1320 glUniform1i(mTextureCubeUniformLocation, 1);
1321 drawQuad(mProgram, "position", 0.5f);
1322 EXPECT_GL_NO_ERROR();
1323
1324 int px = getWindowWidth() - 1;
1325 int py = 0;
1326 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1327}
1328
Olli Etuaho4644a202016-01-12 15:12:53 +02001329TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1330{
1331 glActiveTexture(GL_TEXTURE0);
1332 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1333 GLubyte texData[4];
1334 texData[0] = 0;
1335 texData[1] = 128;
1336 texData[2] = 0;
1337 texData[3] = 255;
1338 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1339 glUseProgram(mProgram);
1340 glUniform1i(mTexture2DUniformLocation, 0);
1341 drawQuad(mProgram, "position", 0.5f);
1342 EXPECT_GL_NO_ERROR();
1343
1344 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1345}
1346
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001347// Test drawing with two textures passed to the shader in a sampler array.
1348TEST_P(SamplerArrayTest, SamplerArrayDraw)
1349{
1350 testSamplerArrayDraw();
1351}
1352
1353// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1354// user-defined function in the shader.
1355TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1356{
1357 testSamplerArrayDraw();
1358}
1359
Jamie Madill9aca0592014-10-06 16:26:59 -04001360// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001361TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001362{
1363 int px = getWindowWidth() / 2;
1364 int py = getWindowHeight() / 2;
1365
1366 glActiveTexture(GL_TEXTURE0);
1367 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1368
Olli Etuahoa314b612016-03-10 16:43:00 +02001369 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001370
Olli Etuahoa314b612016-03-10 16:43:00 +02001371 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1374 glGenerateMipmap(GL_TEXTURE_2D);
1375
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001376 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001377 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001378 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1379 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001380 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001381 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001382
Olli Etuahoa314b612016-03-10 16:43:00 +02001383 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001384
Olli Etuahoa314b612016-03-10 16:43:00 +02001385 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1386 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001387 glGenerateMipmap(GL_TEXTURE_2D);
1388
Olli Etuahoa314b612016-03-10 16:43:00 +02001389 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001390
Olli Etuahoa314b612016-03-10 16:43:00 +02001391 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1392 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001393 glGenerateMipmap(GL_TEXTURE_2D);
1394
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001395 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001396
1397 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001398 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001399}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001400
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001401// Test creating a FBO with a cube map render target, to test an ANGLE bug
1402// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001403TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001404{
1405 GLuint fbo;
1406 glGenFramebuffers(1, &fbo);
1407 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1408
1409 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1410 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1411
Corentin Wallez322653b2015-06-17 18:33:56 +02001412 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001413
1414 glDeleteFramebuffers(1, &fbo);
1415
1416 EXPECT_GL_NO_ERROR();
1417}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001418
1419// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001420TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001421{
Geoff Langc4e93662017-05-01 10:45:59 -04001422 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1423 {
1424 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1425 << std::endl;
1426 return;
1427 }
1428
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001429 int width = getWindowWidth();
1430 int height = getWindowHeight();
1431
1432 GLuint tex2D;
1433 glGenTextures(1, &tex2D);
1434 glActiveTexture(GL_TEXTURE0);
1435 glBindTexture(GL_TEXTURE_2D, tex2D);
1436
1437 // Fill with red
1438 std::vector<GLubyte> pixels(3 * 16 * 16);
1439 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1440 {
1441 pixels[pixelId * 3 + 0] = 255;
1442 pixels[pixelId * 3 + 1] = 0;
1443 pixels[pixelId * 3 + 2] = 0;
1444 }
1445
1446 // ANGLE internally uses RGBA as the DirectX format for RGB images
1447 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1448 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001449 if (getClientMajorVersion() >= 3)
1450 {
1451 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1452 }
1453 else
1454 {
1455 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1456 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001457
1458 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1459 // glTexSubImage2D should take into account that the image is dirty.
1460 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1463
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001464 setUpProgram();
1465
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001466 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001467 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001468 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001469 glDeleteTextures(1, &tex2D);
1470 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001471 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001472
1473 // Validate that the region of the texture without data has an alpha of 1.0
1474 GLubyte pixel[4];
1475 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1476 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001477}
1478
1479// 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 +02001480TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001481{
1482 if (extensionEnabled("NV_pixel_buffer_object"))
1483 {
1484 int width = getWindowWidth();
1485 int height = getWindowHeight();
1486
1487 GLuint tex2D;
1488 glGenTextures(1, &tex2D);
1489 glActiveTexture(GL_TEXTURE0);
1490 glBindTexture(GL_TEXTURE_2D, tex2D);
1491
1492 // Fill with red
1493 std::vector<GLubyte> pixels(3 * 16 * 16);
1494 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1495 {
1496 pixels[pixelId * 3 + 0] = 255;
1497 pixels[pixelId * 3 + 1] = 0;
1498 pixels[pixelId * 3 + 2] = 0;
1499 }
1500
1501 // Read 16x16 region from red backbuffer to PBO
1502 GLuint pbo;
1503 glGenBuffers(1, &pbo);
1504 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1505 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1506
1507 // ANGLE internally uses RGBA as the DirectX format for RGB images
1508 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1509 // The data is kept in a CPU-side image and the image is marked as dirty.
1510 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1511
1512 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1513 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001514 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1517
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001518 setUpProgram();
1519
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001520 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001521 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001522 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001523 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001524 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001525 EXPECT_GL_NO_ERROR();
1526 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1527 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1528 }
1529}
Jamie Madillbc393df2015-01-29 13:46:07 -05001530
1531// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001532TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001533{
1534 testFloatCopySubImage(1, 1);
1535}
1536
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001537TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001538{
1539 testFloatCopySubImage(2, 1);
1540}
1541
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001542TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001543{
1544 testFloatCopySubImage(2, 2);
1545}
1546
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001547TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001548{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001549 if (IsIntel() && IsLinux())
1550 {
1551 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1552 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1553 return;
1554 }
1555
Jamie Madillbc393df2015-01-29 13:46:07 -05001556 testFloatCopySubImage(3, 1);
1557}
1558
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001560{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001561 if (IsIntel() && IsLinux())
1562 {
1563 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1564 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1565 return;
1566 }
1567
Jamie Madillbc393df2015-01-29 13:46:07 -05001568 testFloatCopySubImage(3, 2);
1569}
1570
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001571TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001572{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001573 if (IsIntel() && IsLinux())
1574 {
1575 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1576 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1577 return;
1578 }
1579
Austin Kinrossd544cc92016-01-11 15:26:42 -08001580 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001581 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001582 {
1583 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1584 return;
1585 }
1586
Jamie Madillbc393df2015-01-29 13:46:07 -05001587 testFloatCopySubImage(3, 3);
1588}
1589
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001590TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001591{
1592 testFloatCopySubImage(4, 1);
1593}
1594
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001595TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001596{
1597 testFloatCopySubImage(4, 2);
1598}
1599
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001600TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001601{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001602 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001603 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001604 {
1605 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1606 return;
1607 }
1608
Jamie Madillbc393df2015-01-29 13:46:07 -05001609 testFloatCopySubImage(4, 3);
1610}
1611
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001612TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001613{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001614 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001615 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001616 {
1617 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1618 return;
1619 }
1620
Jamie Madillbc393df2015-01-29 13:46:07 -05001621 testFloatCopySubImage(4, 4);
1622}
Austin Kinross07285142015-03-26 11:36:16 -07001623
1624// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1625// 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 +02001626TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001627{
1628 const int npotTexSize = 5;
1629 const int potTexSize = 4; // Should be less than npotTexSize
1630 GLuint tex2D;
1631
1632 if (extensionEnabled("GL_OES_texture_npot"))
1633 {
1634 // This test isn't applicable if texture_npot is enabled
1635 return;
1636 }
1637
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001638 setUpProgram();
1639
Austin Kinross07285142015-03-26 11:36:16 -07001640 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1641
Austin Kinross5faa15b2016-01-11 13:32:48 -08001642 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1643 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1644
Austin Kinross07285142015-03-26 11:36:16 -07001645 glActiveTexture(GL_TEXTURE0);
1646 glGenTextures(1, &tex2D);
1647 glBindTexture(GL_TEXTURE_2D, tex2D);
1648
1649 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1650 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1651 {
1652 pixels[pixelId] = 64;
1653 }
1654
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1656 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1657
1658 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1659 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1660 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1661
1662 // Check that an NPOT texture on level 0 succeeds
1663 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1664 EXPECT_GL_NO_ERROR();
1665
1666 // Check that generateMipmap fails on NPOT
1667 glGenerateMipmap(GL_TEXTURE_2D);
1668 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1669
1670 // Check that nothing is drawn if filtering is not correct for NPOT
1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1672 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1673 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1674 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1675 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001676 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001677 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1678
1679 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1683 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001684 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001685 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1686
1687 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1689 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001690 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001691 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1692
1693 // Check that glTexImage2D for POT texture succeeds
1694 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1695 EXPECT_GL_NO_ERROR();
1696
1697 // Check that generateMipmap for an POT texture succeeds
1698 glGenerateMipmap(GL_TEXTURE_2D);
1699 EXPECT_GL_NO_ERROR();
1700
1701 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1702 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1705 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1706 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001707 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001708 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1709 EXPECT_GL_NO_ERROR();
1710}
Jamie Madillfa05f602015-05-07 13:47:11 -04001711
Austin Kinross08528e12015-10-07 16:24:40 -07001712// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1713// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001714TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001715{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001716 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1717 // 1278)
1718 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1719 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1720 {
1721 std::cout << "Test disabled on OpenGL." << std::endl;
1722 return;
1723 }
1724
Austin Kinross08528e12015-10-07 16:24:40 -07001725 glActiveTexture(GL_TEXTURE0);
1726 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1727
1728 // Create an 8x8 (i.e. power-of-two) texture.
1729 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1731 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1732 glGenerateMipmap(GL_TEXTURE_2D);
1733
1734 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1735 // This should always work, even if GL_OES_texture_npot isn't active.
1736 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1737
1738 EXPECT_GL_NO_ERROR();
1739}
1740
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001741// Test to check that texture completeness is determined correctly when the texture base level is
1742// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1743TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1744{
1745 glActiveTexture(GL_TEXTURE0);
1746 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001747
1748 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1749 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1750 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1751 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1752 texDataGreen.data());
1753 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1754 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1758
1759 EXPECT_GL_NO_ERROR();
1760
1761 drawQuad(mProgram, "position", 0.5f);
1762
Olli Etuahoa314b612016-03-10 16:43:00 +02001763 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1764}
1765
1766// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1767// have images defined.
1768TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1769{
1770 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1771 {
1772 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1773 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1774 return;
1775 }
1776 if (IsOSX())
1777 {
1778 // Observed incorrect rendering on OSX.
1779 std::cout << "Test skipped on OSX." << std::endl;
1780 return;
1781 }
1782 glActiveTexture(GL_TEXTURE0);
1783 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1784 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1785 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1786 texDataGreen.data());
1787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1788 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1791
1792 EXPECT_GL_NO_ERROR();
1793
1794 drawQuad(mProgram, "position", 0.5f);
1795
1796 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1797}
1798
Olli Etuahoe8528d82016-05-16 17:50:52 +03001799// Test that drawing works correctly when level 0 is undefined and base level is 1.
1800TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1801{
1802 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1803 {
1804 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1805 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1806 return;
1807 }
1808 if (IsOSX())
1809 {
1810 // Observed incorrect rendering on OSX.
1811 std::cout << "Test skipped on OSX." << std::endl;
1812 return;
1813 }
1814 glActiveTexture(GL_TEXTURE0);
1815 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1816 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1817 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1818 texDataGreen.data());
1819 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1820 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1821 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1822 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1823
1824 EXPECT_GL_NO_ERROR();
1825
1826 // Texture is incomplete.
1827 drawQuad(mProgram, "position", 0.5f);
1828 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1829
1830 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1831 texDataGreen.data());
1832
1833 // Texture is now complete.
1834 drawQuad(mProgram, "position", 0.5f);
1835 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1836}
1837
Olli Etuahoa314b612016-03-10 16:43:00 +02001838// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1839// dimensions that don't fit the images inside the range.
1840// GLES 3.0.4 section 3.8.13 Texture completeness
1841TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1842{
1843 if (IsOSX())
1844 {
1845 // Observed incorrect rendering on OSX.
1846 std::cout << "Test skipped on OSX." << std::endl;
1847 return;
1848 }
1849 glActiveTexture(GL_TEXTURE0);
1850 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1851 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1852 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1853 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1854
1855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1856 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1857
1858 // Two levels that are initially unused.
1859 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1860 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1861 texDataCyan.data());
1862
1863 // One level that is used - only this level should affect completeness.
1864 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1865 texDataGreen.data());
1866
1867 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1868 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1869
1870 EXPECT_GL_NO_ERROR();
1871
1872 drawQuad(mProgram, "position", 0.5f);
1873
1874 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1875
1876 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1877 {
1878 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1879 // level was changed.
1880 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1881 return;
1882 }
1883
1884 // Switch the level that is being used to the cyan level 2.
1885 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1886 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1887
1888 EXPECT_GL_NO_ERROR();
1889
1890 drawQuad(mProgram, "position", 0.5f);
1891
1892 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1893}
1894
1895// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1896// have images defined.
1897TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1898{
1899 if (IsOSX())
1900 {
1901 // Observed incorrect rendering on OSX.
1902 std::cout << "Test skipped on OSX." << std::endl;
1903 return;
1904 }
1905 glActiveTexture(GL_TEXTURE0);
1906 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1907 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1908 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1909 texDataGreen.data());
1910 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1911 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1912 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1913 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1914
1915 EXPECT_GL_NO_ERROR();
1916
1917 drawQuad(mProgram, "position", 0.5f);
1918
1919 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1920}
1921
1922// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1923// dimensions that don't fit the images inside the range.
1924// GLES 3.0.4 section 3.8.13 Texture completeness
1925TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1926{
1927 if (IsOSX())
1928 {
1929 // Observed incorrect rendering on OSX.
1930 std::cout << "Test skipped on OSX." << std::endl;
1931 return;
1932 }
1933 glActiveTexture(GL_TEXTURE0);
1934 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1935 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1936 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1937 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1938
1939 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1940 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1941
1942 // Two levels that are initially unused.
1943 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1944 texDataRed.data());
1945 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1946 texDataCyan.data());
1947
1948 // One level that is used - only this level should affect completeness.
1949 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1950 texDataGreen.data());
1951
1952 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1953 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1954
1955 EXPECT_GL_NO_ERROR();
1956
1957 drawQuad(mProgram, "position", 0.5f);
1958
1959 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1960
1961 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1962 {
1963 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1964 // level was changed.
1965 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1966 return;
1967 }
1968
1969 // Switch the level that is being used to the cyan level 2.
1970 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1971 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1972
1973 EXPECT_GL_NO_ERROR();
1974
1975 drawQuad(mProgram, "position", 0.5f);
1976
1977 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1978}
1979
1980// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1981// have images defined.
1982TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1983{
1984 if (IsOSX())
1985 {
1986 // Observed incorrect rendering on OSX.
1987 std::cout << "Test skipped on OSX." << std::endl;
1988 return;
1989 }
1990 glActiveTexture(GL_TEXTURE0);
1991 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1992 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1993 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1994 texDataGreen.data());
1995 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1996 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1997 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1998 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1999
2000 EXPECT_GL_NO_ERROR();
2001
2002 drawQuad(mProgram, "position", 0.5f);
2003
2004 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2005}
2006
2007// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2008// dimensions that don't fit the images inside the range.
2009// GLES 3.0.4 section 3.8.13 Texture completeness
2010TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2011{
2012 if (IsOSX())
2013 {
2014 // Observed incorrect rendering on OSX.
2015 std::cout << "Test skipped on OSX." << std::endl;
2016 return;
2017 }
2018 glActiveTexture(GL_TEXTURE0);
2019 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2020 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2021 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2022 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2023
2024 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2025 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2026
2027 // Two levels that are initially unused.
2028 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2029 texDataRed.data());
2030 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2031 texDataCyan.data());
2032
2033 // One level that is used - only this level should affect completeness.
2034 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2035 texDataGreen.data());
2036
2037 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2038 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2039
2040 EXPECT_GL_NO_ERROR();
2041
2042 drawQuad(mProgram, "position", 0.5f);
2043
2044 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2045
2046 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2047 {
2048 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2049 // level was changed.
2050 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2051 return;
2052 }
2053 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2054 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2055 {
2056 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2057 // level was changed.
2058 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2059 return;
2060 }
2061
2062 // Switch the level that is being used to the cyan level 2.
2063 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2064 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2065
2066 EXPECT_GL_NO_ERROR();
2067
2068 drawQuad(mProgram, "position", 0.5f);
2069
2070 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2071}
2072
2073// Test that texture completeness is updated if texture max level changes.
2074// GLES 3.0.4 section 3.8.13 Texture completeness
2075TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2076{
2077 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2078 {
2079 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2080 // the base level.
2081 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2082 return;
2083 }
2084 if (IsOSX())
2085 {
2086 // Observed incorrect rendering on OSX.
2087 std::cout << "Test skipped on OSX." << std::endl;
2088 return;
2089 }
2090
2091 glActiveTexture(GL_TEXTURE0);
2092 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2093 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2094
2095 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2096 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2097
2098 // A level that is initially unused.
2099 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2100 texDataGreen.data());
2101
2102 // One level that is initially used - only this level should affect completeness.
2103 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2104 texDataGreen.data());
2105
2106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2108
2109 EXPECT_GL_NO_ERROR();
2110
2111 drawQuad(mProgram, "position", 0.5f);
2112
2113 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2114
2115 // Switch the max level to level 1. The levels within the used range now have inconsistent
2116 // dimensions and the texture should be incomplete.
2117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2118
2119 EXPECT_GL_NO_ERROR();
2120
2121 drawQuad(mProgram, "position", 0.5f);
2122
2123 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2124}
2125
2126// Test that 3D texture completeness is updated if texture max level changes.
2127// GLES 3.0.4 section 3.8.13 Texture completeness
2128TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2129{
2130 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2131 {
2132 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2133 // the base level.
2134 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2135 return;
2136 }
2137 if (IsOSX())
2138 {
2139 // Observed incorrect rendering on OSX.
2140 std::cout << "Test skipped on OSX." << std::endl;
2141 return;
2142 }
2143
2144 glActiveTexture(GL_TEXTURE0);
2145 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2146 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2147
2148 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2149 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2150
2151 // A level that is initially unused.
2152 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2153 texDataGreen.data());
2154
2155 // One level that is initially used - only this level should affect completeness.
2156 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2157 texDataGreen.data());
2158
2159 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2160 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2161
2162 EXPECT_GL_NO_ERROR();
2163
2164 drawQuad(mProgram, "position", 0.5f);
2165
2166 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2167
2168 // Switch the max level to level 1. The levels within the used range now have inconsistent
2169 // dimensions and the texture should be incomplete.
2170 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2171
2172 EXPECT_GL_NO_ERROR();
2173
2174 drawQuad(mProgram, "position", 0.5f);
2175
2176 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2177}
2178
2179// Test that texture completeness is updated if texture base level changes.
2180// GLES 3.0.4 section 3.8.13 Texture completeness
2181TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2182{
2183 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2184 {
2185 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2186 // the base level.
2187 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2188 return;
2189 }
2190
2191 glActiveTexture(GL_TEXTURE0);
2192 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2193 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2194
2195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2197
2198 // Two levels that are initially unused.
2199 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2200 texDataGreen.data());
2201 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2202 texDataGreen.data());
2203
2204 // One level that is initially used - only this level should affect completeness.
2205 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2206 texDataGreen.data());
2207
2208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2210
2211 EXPECT_GL_NO_ERROR();
2212
2213 drawQuad(mProgram, "position", 0.5f);
2214
2215 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2216
2217 // Switch the base level to level 1. The levels within the used range now have inconsistent
2218 // dimensions and the texture should be incomplete.
2219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2220
2221 EXPECT_GL_NO_ERROR();
2222
2223 drawQuad(mProgram, "position", 0.5f);
2224
2225 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2226}
2227
2228// Test that texture is not complete if base level is greater than max level.
2229// GLES 3.0.4 section 3.8.13 Texture completeness
2230TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2231{
2232 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2233 {
2234 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2235 // of range.
2236 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2237 return;
2238 }
2239
2240 glActiveTexture(GL_TEXTURE0);
2241 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2242
2243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2245
2246 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2247
2248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2250
2251 EXPECT_GL_NO_ERROR();
2252
2253 drawQuad(mProgram, "position", 0.5f);
2254
2255 // Texture should be incomplete.
2256 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2257}
2258
2259// Test that immutable texture base level and max level are clamped.
2260// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2261TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2262{
Olli Etuahoa314b612016-03-10 16:43:00 +02002263 glActiveTexture(GL_TEXTURE0);
2264 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2265
2266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2268
2269 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2270
2271 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2272
2273 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2274 // should be clamped to [base_level, levels - 1].
2275 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2276 // In the case of this test, those rules make the effective base level and max level 0.
2277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2279
2280 EXPECT_GL_NO_ERROR();
2281
2282 drawQuad(mProgram, "position", 0.5f);
2283
2284 // Texture should be complete.
2285 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2286}
2287
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002288// Test that changing base level works when it affects the format of the texture.
2289TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2290{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002291 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002292 {
2293 // Observed rendering corruption on NVIDIA OpenGL.
2294 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2295 return;
2296 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002297 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002298 {
2299 // Observed incorrect rendering on Intel OpenGL.
2300 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2301 return;
2302 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002303 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002304 {
2305 // Observed incorrect rendering on AMD OpenGL.
2306 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2307 return;
2308 }
2309
2310 glActiveTexture(GL_TEXTURE0);
2311 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2312 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2313 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2314
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2317
2318 // RGBA8 level that's initially unused.
2319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2320 texDataCyan.data());
2321
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2324
2325 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2326 // format. It reads green channel data from the green and alpha channels of texDataGreen
2327 // (this is a bit hacky but works).
2328 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2329
2330 EXPECT_GL_NO_ERROR();
2331
2332 drawQuad(mProgram, "position", 0.5f);
2333
2334 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2335
2336 // Switch the texture to use the cyan level 0 with the RGBA format.
2337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2338 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2339
2340 EXPECT_GL_NO_ERROR();
2341
2342 drawQuad(mProgram, "position", 0.5f);
2343
2344 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2345}
2346
Olli Etuahoa314b612016-03-10 16:43:00 +02002347// Test that setting a texture image works when base level is out of range.
2348TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2349{
2350 glActiveTexture(GL_TEXTURE0);
2351 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2352
2353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2355
2356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2358
2359 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2360
2361 EXPECT_GL_NO_ERROR();
2362
2363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2364
2365 drawQuad(mProgram, "position", 0.5f);
2366
2367 // Texture should be complete.
2368 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002369}
2370
Jamie Madill2453dbc2015-07-14 11:35:42 -04002371// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2372// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2373// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002374TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002375{
2376 std::vector<GLubyte> pixelData;
2377 for (size_t count = 0; count < 5000; count++)
2378 {
2379 pixelData.push_back(0u);
2380 pixelData.push_back(255u);
2381 pixelData.push_back(0u);
2382 }
2383
2384 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002385 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002386 glUniform1i(mTextureArrayLocation, 0);
2387
2388 // The first draw worked correctly.
2389 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2390
2391 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2392 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2393 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2394 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002395 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002396 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002397
2398 // The dimension of the respecification must match the original exactly to trigger the bug.
2399 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 +02002400 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002401 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002402
2403 ASSERT_GL_NO_ERROR();
2404}
2405
Olli Etuaho1a679902016-01-14 12:21:47 +02002406// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2407// This test is needed especially to confirm that sampler registers get assigned correctly on
2408// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2409TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2410{
2411 glActiveTexture(GL_TEXTURE0);
2412 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2413 GLubyte texData[4];
2414 texData[0] = 0;
2415 texData[1] = 60;
2416 texData[2] = 0;
2417 texData[3] = 255;
2418 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2419
2420 glActiveTexture(GL_TEXTURE1);
2421 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2422 GLfloat depthTexData[1];
2423 depthTexData[0] = 0.5f;
2424 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2425 depthTexData);
2426
2427 glUseProgram(mProgram);
2428 glUniform1f(mDepthRefUniformLocation, 0.3f);
2429 glUniform1i(mTexture3DUniformLocation, 0);
2430 glUniform1i(mTextureShadowUniformLocation, 1);
2431
2432 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2433 drawQuad(mProgram, "position", 0.5f);
2434 EXPECT_GL_NO_ERROR();
2435 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2436 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2437
2438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2439 drawQuad(mProgram, "position", 0.5f);
2440 EXPECT_GL_NO_ERROR();
2441 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2442 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2443}
2444
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002445// Test multiple different sampler types in the same shader.
2446// This test makes sure that even if sampler / texture registers get grouped together based on type
2447// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2448// still has the right register index information for each ESSL sampler.
2449// The tested ESSL samplers have the following types in D3D11 HLSL:
2450// sampler2D: Texture2D + SamplerState
2451// samplerCube: TextureCube + SamplerState
2452// sampler2DShadow: Texture2D + SamplerComparisonState
2453// samplerCubeShadow: TextureCube + SamplerComparisonState
2454TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2455{
2456 glActiveTexture(GL_TEXTURE0);
2457 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2458 GLubyte texData[4];
2459 texData[0] = 0;
2460 texData[1] = 0;
2461 texData[2] = 120;
2462 texData[3] = 255;
2463 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2464
2465 glActiveTexture(GL_TEXTURE1);
2466 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2467 texData[0] = 0;
2468 texData[1] = 90;
2469 texData[2] = 0;
2470 texData[3] = 255;
2471 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2472 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2473 texData);
2474
2475 glActiveTexture(GL_TEXTURE2);
2476 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2478 GLfloat depthTexData[1];
2479 depthTexData[0] = 0.5f;
2480 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2481 depthTexData);
2482
2483 glActiveTexture(GL_TEXTURE3);
2484 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2485 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2486 depthTexData[0] = 0.2f;
2487 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2488 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2489 depthTexData);
2490
2491 EXPECT_GL_NO_ERROR();
2492
2493 glUseProgram(mProgram);
2494 glUniform1f(mDepthRefUniformLocation, 0.3f);
2495 glUniform1i(mTexture2DUniformLocation, 0);
2496 glUniform1i(mTextureCubeUniformLocation, 1);
2497 glUniform1i(mTexture2DShadowUniformLocation, 2);
2498 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2499
2500 drawQuad(mProgram, "position", 0.5f);
2501 EXPECT_GL_NO_ERROR();
2502 // The shader writes:
2503 // <texture 2d color> +
2504 // <cube map color> +
2505 // 0.25 * <comparison result (1.0)> +
2506 // 0.125 * <comparison result (0.0)>
2507 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2508}
2509
Olli Etuahobce743a2016-01-15 17:18:28 +02002510// Test different base levels on textures accessed through the same sampler array.
2511// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2512TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2513{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002514 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002515 {
2516 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2517 return;
2518 }
2519 glActiveTexture(GL_TEXTURE0);
2520 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2521 GLsizei size = 64;
2522 for (GLint level = 0; level < 7; ++level)
2523 {
2524 ASSERT_LT(0, size);
2525 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2526 nullptr);
2527 size = size / 2;
2528 }
2529 ASSERT_EQ(0, size);
2530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2531
2532 glActiveTexture(GL_TEXTURE1);
2533 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2534 size = 128;
2535 for (GLint level = 0; level < 8; ++level)
2536 {
2537 ASSERT_LT(0, size);
2538 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2539 nullptr);
2540 size = size / 2;
2541 }
2542 ASSERT_EQ(0, size);
2543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2544 EXPECT_GL_NO_ERROR();
2545
2546 glUseProgram(mProgram);
2547 glUniform1i(mTexture0Location, 0);
2548 glUniform1i(mTexture1Location, 1);
2549
2550 drawQuad(mProgram, "position", 0.5f);
2551 EXPECT_GL_NO_ERROR();
2552 // Red channel: width of level 1 of texture A: 32.
2553 // Green channel: width of level 3 of texture B: 16.
2554 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2555}
2556
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002557// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2558// ES 3.0.4 table 3.24
2559TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2560{
2561 glActiveTexture(GL_TEXTURE0);
2562 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2563 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2564 EXPECT_GL_NO_ERROR();
2565
2566 drawQuad(mProgram, "position", 0.5f);
2567
2568 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2569}
2570
2571// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2572// ES 3.0.4 table 3.24
2573TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2574{
2575 glActiveTexture(GL_TEXTURE0);
2576 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2577 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2578 EXPECT_GL_NO_ERROR();
2579
2580 drawQuad(mProgram, "position", 0.5f);
2581
2582 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2583}
2584
2585// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2586// ES 3.0.4 table 3.24
2587TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2588{
2589 if (extensionEnabled("GL_OES_texture_float"))
2590 {
2591 glActiveTexture(GL_TEXTURE0);
2592 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2593 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2594 EXPECT_GL_NO_ERROR();
2595
2596 drawQuad(mProgram, "position", 0.5f);
2597
2598 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2599 }
2600}
2601
2602// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2603// ES 3.0.4 table 3.24
2604TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2605{
2606 if (extensionEnabled("GL_OES_texture_half_float"))
2607 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002608 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002609 {
2610 std::cout << "Test skipped on NVIDIA" << std::endl;
2611 return;
2612 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002613 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2614 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2615 {
2616 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2617 return;
2618 }
2619
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002620 glActiveTexture(GL_TEXTURE0);
2621 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2622 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2623 nullptr);
2624 EXPECT_GL_NO_ERROR();
2625
2626 drawQuad(mProgram, "position", 0.5f);
2627
2628 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2629 }
2630}
2631
2632// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2633// ES 3.0.4 table 3.24
2634TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2635{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002636 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002637 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002638 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002639 return;
2640 }
2641 glActiveTexture(GL_TEXTURE0);
2642 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2643 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2644 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2645 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2646 EXPECT_GL_NO_ERROR();
2647
2648 drawQuad(mProgram, "position", 0.5f);
2649
2650 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2651}
2652
2653// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2654// ES 3.0.4 table 3.24
2655TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2656{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002657 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002658 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002659 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002660 return;
2661 }
2662 glActiveTexture(GL_TEXTURE0);
2663 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2664
2665 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2668 EXPECT_GL_NO_ERROR();
2669
2670 drawQuad(mProgram, "position", 0.5f);
2671
2672 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2673}
2674
2675// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2676// ES 3.0.4 table 3.24
2677TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2678{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002679 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002680 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002681 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002682 return;
2683 }
2684 glActiveTexture(GL_TEXTURE0);
2685 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2686 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2687 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2689 EXPECT_GL_NO_ERROR();
2690
2691 drawQuad(mProgram, "position", 0.5f);
2692
2693 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2694}
2695
2696// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2697// ES 3.0.4 table 3.24
2698TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2699{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002700 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002701 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002702 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002703 return;
2704 }
2705 glActiveTexture(GL_TEXTURE0);
2706 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2707 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2710 EXPECT_GL_NO_ERROR();
2711
2712 drawQuad(mProgram, "position", 0.5f);
2713
2714 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2715}
2716
2717// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2718// ES 3.0.4 table 3.24
2719TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2720{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002721 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002722 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002723 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002724 return;
2725 }
2726 glActiveTexture(GL_TEXTURE0);
2727 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2728 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2729 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2730 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2731 EXPECT_GL_NO_ERROR();
2732
2733 drawQuad(mProgram, "position", 0.5f);
2734
2735 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2736}
2737
2738// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2739// ES 3.0.4 table 3.24
2740TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2741{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002742 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002743 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002744 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002745 return;
2746 }
2747 glActiveTexture(GL_TEXTURE0);
2748 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2749 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2752 EXPECT_GL_NO_ERROR();
2753
2754 drawQuad(mProgram, "position", 0.5f);
2755
2756 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2757}
2758
2759// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2760// ES 3.0.4 table 3.24
2761TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2762{
2763 glActiveTexture(GL_TEXTURE0);
2764 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2765 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2766 EXPECT_GL_NO_ERROR();
2767
2768 drawQuad(mProgram, "position", 0.5f);
2769
2770 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2771}
2772
2773// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2774// ES 3.0.4 table 3.24
2775TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2776{
2777 glActiveTexture(GL_TEXTURE0);
2778 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2779 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2780 nullptr);
2781 EXPECT_GL_NO_ERROR();
2782
2783 drawQuad(mProgram, "position", 0.5f);
2784
2785 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2786}
2787
2788// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2789// ES 3.0.4 table 3.24
2790TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2791{
Jamie Madillbb1db482017-01-10 10:48:32 -05002792 if (IsOSX() && IsIntel() && IsOpenGL())
2793 {
2794 // Seems to fail on OSX 10.12 Intel.
2795 std::cout << "Test skipped on OSX Intel." << std::endl;
2796 return;
2797 }
2798
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002799 glActiveTexture(GL_TEXTURE0);
2800 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2801 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2802 EXPECT_GL_NO_ERROR();
2803
2804 drawQuad(mProgram, "position", 0.5f);
2805
2806 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2807}
2808
2809// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2810// ES 3.0.4 table 3.24
2811TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2812{
Jamie Madillbb1db482017-01-10 10:48:32 -05002813 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002814 {
2815 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002816 // Also seems to fail on OSX 10.12 Intel.
2817 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002818 return;
2819 }
2820
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002821 glActiveTexture(GL_TEXTURE0);
2822 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2823 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2824 EXPECT_GL_NO_ERROR();
2825
2826 drawQuad(mProgram, "position", 0.5f);
2827
2828 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2829}
2830
Olli Etuaho96963162016-03-21 11:54:33 +02002831// Use a sampler in a uniform struct.
2832TEST_P(SamplerInStructTest, SamplerInStruct)
2833{
2834 runSamplerInStructTest();
2835}
2836
2837// Use a sampler in a uniform struct that's passed as a function parameter.
2838TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2839{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002840 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2841 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2842 {
2843 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2844 return;
2845 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002846
2847 if (IsWindows() && IsIntel() && IsOpenGL())
2848 {
2849 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2850 return;
2851 }
2852
Olli Etuaho96963162016-03-21 11:54:33 +02002853 runSamplerInStructTest();
2854}
2855
2856// Use a sampler in a uniform struct array with a struct from the array passed as a function
2857// parameter.
2858TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2859{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002860 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2861 {
2862 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2863 return;
2864 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002865 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2866 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2867 {
2868 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2869 return;
2870 }
Olli Etuaho96963162016-03-21 11:54:33 +02002871 runSamplerInStructTest();
2872}
2873
2874// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2875// parameter.
2876TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2877{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002878 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2879 {
2880 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2881 return;
2882 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002883 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2884 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2885 {
2886 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2887 return;
2888 }
Olli Etuaho96963162016-03-21 11:54:33 +02002889 runSamplerInStructTest();
2890}
2891
2892// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2893// similarly named uniform.
2894TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2895{
2896 runSamplerInStructTest();
2897}
2898
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002899class TextureLimitsTest : public ANGLETest
2900{
2901 protected:
2902 struct RGBA8
2903 {
2904 uint8_t R, G, B, A;
2905 };
2906
2907 TextureLimitsTest()
2908 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2909 {
2910 setWindowWidth(128);
2911 setWindowHeight(128);
2912 setConfigRedBits(8);
2913 setConfigGreenBits(8);
2914 setConfigBlueBits(8);
2915 setConfigAlphaBits(8);
2916 }
2917
2918 ~TextureLimitsTest()
2919 {
2920 if (mProgram != 0)
2921 {
2922 glDeleteProgram(mProgram);
2923 mProgram = 0;
2924
2925 if (!mTextures.empty())
2926 {
2927 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2928 }
2929 }
2930 }
2931
2932 void SetUp() override
2933 {
2934 ANGLETest::SetUp();
2935
2936 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2937 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2938 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2939
2940 ASSERT_GL_NO_ERROR();
2941 }
2942
2943 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2944 GLint vertexTextureCount,
2945 GLint vertexActiveTextureCount,
2946 const std::string &fragPrefix,
2947 GLint fragmentTextureCount,
2948 GLint fragmentActiveTextureCount)
2949 {
2950 std::stringstream vertexShaderStr;
2951 vertexShaderStr << "attribute vec2 position;\n"
2952 << "varying vec4 color;\n"
2953 << "varying vec2 texCoord;\n";
2954
2955 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2956 {
2957 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2958 }
2959
2960 vertexShaderStr << "void main() {\n"
2961 << " gl_Position = vec4(position, 0, 1);\n"
2962 << " texCoord = (position * 0.5) + 0.5;\n"
2963 << " color = vec4(0);\n";
2964
2965 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2966 {
2967 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2968 << ", texCoord);\n";
2969 }
2970
2971 vertexShaderStr << "}";
2972
2973 std::stringstream fragmentShaderStr;
2974 fragmentShaderStr << "varying mediump vec4 color;\n"
2975 << "varying mediump vec2 texCoord;\n";
2976
2977 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2978 {
2979 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2980 }
2981
2982 fragmentShaderStr << "void main() {\n"
2983 << " gl_FragColor = color;\n";
2984
2985 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2986 {
2987 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2988 << ", texCoord);\n";
2989 }
2990
2991 fragmentShaderStr << "}";
2992
2993 const std::string &vertexShaderSource = vertexShaderStr.str();
2994 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2995
2996 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2997 }
2998
2999 RGBA8 getPixel(GLint texIndex)
3000 {
3001 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3002 0, 255u};
3003 return pixel;
3004 }
3005
3006 void initTextures(GLint tex2DCount, GLint texCubeCount)
3007 {
3008 GLint totalCount = tex2DCount + texCubeCount;
3009 mTextures.assign(totalCount, 0);
3010 glGenTextures(totalCount, &mTextures[0]);
3011 ASSERT_GL_NO_ERROR();
3012
3013 std::vector<RGBA8> texData(16 * 16);
3014
3015 GLint texIndex = 0;
3016 for (; texIndex < tex2DCount; ++texIndex)
3017 {
3018 texData.assign(texData.size(), getPixel(texIndex));
3019 glActiveTexture(GL_TEXTURE0 + texIndex);
3020 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3021 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3022 &texData[0]);
3023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3024 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3025 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3026 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3027 }
3028
3029 ASSERT_GL_NO_ERROR();
3030
3031 for (; texIndex < texCubeCount; ++texIndex)
3032 {
3033 texData.assign(texData.size(), getPixel(texIndex));
3034 glActiveTexture(GL_TEXTURE0 + texIndex);
3035 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3036 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3037 GL_UNSIGNED_BYTE, &texData[0]);
3038 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3039 GL_UNSIGNED_BYTE, &texData[0]);
3040 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3041 GL_UNSIGNED_BYTE, &texData[0]);
3042 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3043 GL_UNSIGNED_BYTE, &texData[0]);
3044 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3045 GL_UNSIGNED_BYTE, &texData[0]);
3046 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3047 GL_UNSIGNED_BYTE, &texData[0]);
3048 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3049 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3050 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3051 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3052 }
3053
3054 ASSERT_GL_NO_ERROR();
3055 }
3056
3057 void testWithTextures(GLint vertexTextureCount,
3058 const std::string &vertexTexturePrefix,
3059 GLint fragmentTextureCount,
3060 const std::string &fragmentTexturePrefix)
3061 {
3062 // Generate textures
3063 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3064
3065 glUseProgram(mProgram);
3066 RGBA8 expectedSum = {0};
3067 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3068 {
3069 std::stringstream uniformNameStr;
3070 uniformNameStr << vertexTexturePrefix << texIndex;
3071 const std::string &uniformName = uniformNameStr.str();
3072 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3073 ASSERT_NE(-1, location);
3074
3075 glUniform1i(location, texIndex);
3076 RGBA8 contribution = getPixel(texIndex);
3077 expectedSum.R += contribution.R;
3078 expectedSum.G += contribution.G;
3079 }
3080
3081 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3082 {
3083 std::stringstream uniformNameStr;
3084 uniformNameStr << fragmentTexturePrefix << texIndex;
3085 const std::string &uniformName = uniformNameStr.str();
3086 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3087 ASSERT_NE(-1, location);
3088
3089 glUniform1i(location, texIndex + vertexTextureCount);
3090 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3091 expectedSum.R += contribution.R;
3092 expectedSum.G += contribution.G;
3093 }
3094
3095 ASSERT_GE(256u, expectedSum.G);
3096
3097 drawQuad(mProgram, "position", 0.5f);
3098 ASSERT_GL_NO_ERROR();
3099 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3100 }
3101
3102 GLuint mProgram;
3103 std::vector<GLuint> mTextures;
3104 GLint mMaxVertexTextures;
3105 GLint mMaxFragmentTextures;
3106 GLint mMaxCombinedTextures;
3107};
3108
3109// Test rendering with the maximum vertex texture units.
3110TEST_P(TextureLimitsTest, MaxVertexTextures)
3111{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003112 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003113 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003114 {
3115 std::cout << "Test skipped on Intel." << std::endl;
3116 return;
3117 }
3118
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003119 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3120 ASSERT_NE(0u, mProgram);
3121 ASSERT_GL_NO_ERROR();
3122
3123 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3124}
3125
3126// Test rendering with the maximum fragment texture units.
3127TEST_P(TextureLimitsTest, MaxFragmentTextures)
3128{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003129 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003130 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003131 {
3132 std::cout << "Test skipped on Intel." << std::endl;
3133 return;
3134 }
3135
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003136 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3137 ASSERT_NE(0u, mProgram);
3138 ASSERT_GL_NO_ERROR();
3139
3140 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3141}
3142
3143// Test rendering with maximum combined texture units.
3144TEST_P(TextureLimitsTest, MaxCombinedTextures)
3145{
Jamie Madill412f17d2015-09-25 08:43:54 -04003146 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003147 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003148 {
3149 std::cout << "Test skipped on Intel." << std::endl;
3150 return;
3151 }
3152
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003153 GLint vertexTextures = mMaxVertexTextures;
3154
3155 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3156 {
3157 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3158 }
3159
3160 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3161 mMaxFragmentTextures, mMaxFragmentTextures);
3162 ASSERT_NE(0u, mProgram);
3163 ASSERT_GL_NO_ERROR();
3164
3165 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3166}
3167
3168// Negative test for exceeding the number of vertex textures
3169TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3170{
3171 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3172 0);
3173 ASSERT_EQ(0u, mProgram);
3174}
3175
3176// Negative test for exceeding the number of fragment textures
3177TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3178{
3179 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3180 mMaxFragmentTextures + 1);
3181 ASSERT_EQ(0u, mProgram);
3182}
3183
3184// Test active vertex textures under the limit, but excessive textures specified.
3185TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3186{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003187 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003188 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003189 {
3190 std::cout << "Test skipped on Intel." << std::endl;
3191 return;
3192 }
3193
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003194 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3195 ASSERT_NE(0u, mProgram);
3196 ASSERT_GL_NO_ERROR();
3197
3198 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3199}
3200
3201// Test active fragment textures under the limit, but excessive textures specified.
3202TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3203{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003204 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003205 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003206 {
3207 std::cout << "Test skipped on Intel." << std::endl;
3208 return;
3209 }
3210
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003211 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3212 mMaxFragmentTextures);
3213 ASSERT_NE(0u, mProgram);
3214 ASSERT_GL_NO_ERROR();
3215
3216 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3217}
3218
3219// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003220// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003221TEST_P(TextureLimitsTest, TextureTypeConflict)
3222{
3223 const std::string &vertexShader =
3224 "attribute vec2 position;\n"
3225 "varying float color;\n"
3226 "uniform sampler2D tex2D;\n"
3227 "uniform samplerCube texCube;\n"
3228 "void main() {\n"
3229 " gl_Position = vec4(position, 0, 1);\n"
3230 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3231 " color = texture2D(tex2D, texCoord).x;\n"
3232 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3233 "}";
3234 const std::string &fragmentShader =
3235 "varying mediump float color;\n"
3236 "void main() {\n"
3237 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3238 "}";
3239
3240 mProgram = CompileProgram(vertexShader, fragmentShader);
3241 ASSERT_NE(0u, mProgram);
3242
3243 initTextures(1, 0);
3244
3245 glUseProgram(mProgram);
3246 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3247 ASSERT_NE(-1, tex2DLocation);
3248 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3249 ASSERT_NE(-1, texCubeLocation);
3250
3251 glUniform1i(tex2DLocation, 0);
3252 glUniform1i(texCubeLocation, 0);
3253 ASSERT_GL_NO_ERROR();
3254
3255 drawQuad(mProgram, "position", 0.5f);
3256 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3257}
3258
Vincent Lang25ab4512016-05-13 18:13:59 +02003259class Texture2DNorm16TestES3 : public Texture2DTestES3
3260{
3261 protected:
3262 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3263
3264 void SetUp() override
3265 {
3266 Texture2DTestES3::SetUp();
3267
3268 glActiveTexture(GL_TEXTURE0);
3269 glGenTextures(3, mTextures);
3270 glGenFramebuffers(1, &mFBO);
3271 glGenRenderbuffers(1, &mRenderbuffer);
3272
3273 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3274 {
3275 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3276 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3278 }
3279
3280 glBindTexture(GL_TEXTURE_2D, 0);
3281
3282 ASSERT_GL_NO_ERROR();
3283 }
3284
3285 void TearDown() override
3286 {
3287 glDeleteTextures(3, mTextures);
3288 glDeleteFramebuffers(1, &mFBO);
3289 glDeleteRenderbuffers(1, &mRenderbuffer);
3290
3291 Texture2DTestES3::TearDown();
3292 }
3293
3294 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3295 {
Geoff Langf607c602016-09-21 11:46:48 -04003296 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3297 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003298
3299 setUpProgram();
3300
3301 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3302 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3303 0);
3304
3305 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3306 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3307
3308 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003309 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003310
3311 EXPECT_GL_NO_ERROR();
3312
3313 drawQuad(mProgram, "position", 0.5f);
3314
Geoff Langf607c602016-09-21 11:46:48 -04003315 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003316
Geoff Langf607c602016-09-21 11:46:48 -04003317 EXPECT_PIXEL_COLOR_EQ(
3318 0, 0, SliceFormatColor(
3319 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003320
3321 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3322
3323 ASSERT_GL_NO_ERROR();
3324 }
3325
3326 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3327 {
3328 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003329 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003330
3331 setUpProgram();
3332
3333 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3334 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3335
3336 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3337 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3338 0);
3339
3340 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003341 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003342
3343 EXPECT_GL_NO_ERROR();
3344
3345 drawQuad(mProgram, "position", 0.5f);
3346
Geoff Langf607c602016-09-21 11:46:48 -04003347 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3348 EXPECT_PIXEL_COLOR_EQ(
3349 0, 0, SliceFormatColor(
3350 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003351
3352 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3353 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3354 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3355 mRenderbuffer);
3356 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3357 EXPECT_GL_NO_ERROR();
3358
3359 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3360 glClear(GL_COLOR_BUFFER_BIT);
3361
3362 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3363
Geoff Langf607c602016-09-21 11:46:48 -04003364 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003365
3366 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3367
3368 ASSERT_GL_NO_ERROR();
3369 }
3370
3371 GLuint mTextures[3];
3372 GLuint mFBO;
3373 GLuint mRenderbuffer;
3374};
3375
3376// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3377TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3378{
3379 if (!extensionEnabled("GL_EXT_texture_norm16"))
3380 {
3381 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3382 return;
3383 }
3384
3385 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3386 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3387 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3388 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3389 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3390 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3391 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3392 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3393
3394 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3395 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3396 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3397}
3398
Olli Etuaho95faa232016-06-07 14:01:53 -07003399// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3400// GLES 3.0.4 section 3.8.3.
3401TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3402{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003403 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003404 {
3405 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3406 return;
3407 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003408 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3409 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3410 {
3411 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3412 return;
3413 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003414
3415 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3417 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3418 ASSERT_GL_NO_ERROR();
3419
3420 // SKIP_IMAGES should not have an effect on uploading 2D textures
3421 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3422 ASSERT_GL_NO_ERROR();
3423
3424 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3425
3426 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3427 pixelsGreen.data());
3428 ASSERT_GL_NO_ERROR();
3429
3430 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3431 pixelsGreen.data());
3432 ASSERT_GL_NO_ERROR();
3433
3434 glUseProgram(mProgram);
3435 drawQuad(mProgram, "position", 0.5f);
3436 ASSERT_GL_NO_ERROR();
3437
3438 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3439}
3440
Olli Etuaho989cac32016-06-08 16:18:49 -07003441// Test that skip defined in unpack parameters is taken into account when determining whether
3442// unpacking source extends outside unpack buffer bounds.
3443TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3444{
3445 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3448 ASSERT_GL_NO_ERROR();
3449
3450 GLBuffer buf;
3451 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3452 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3453 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3454 GL_DYNAMIC_COPY);
3455 ASSERT_GL_NO_ERROR();
3456
3457 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3458 ASSERT_GL_NO_ERROR();
3459
3460 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3461 ASSERT_GL_NO_ERROR();
3462
3463 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3464 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3465
3466 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3467 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3468 ASSERT_GL_NO_ERROR();
3469
3470 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3471 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3472}
3473
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003474// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3475TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3476{
3477 if (IsD3D11())
3478 {
3479 std::cout << "Test skipped on D3D." << std::endl;
3480 return;
3481 }
3482 if (IsOSX() && IsAMD())
3483 {
3484 // Incorrect rendering results seen on OSX AMD.
3485 std::cout << "Test skipped on OSX AMD." << std::endl;
3486 return;
3487 }
3488
3489 const GLuint width = 8u;
3490 const GLuint height = 8u;
3491 const GLuint unpackRowLength = 5u;
3492 const GLuint unpackSkipPixels = 1u;
3493
3494 setWindowWidth(width);
3495 setWindowHeight(height);
3496
3497 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3500 ASSERT_GL_NO_ERROR();
3501
3502 GLBuffer buf;
3503 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3504 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3505 GLColor::green);
3506
3507 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3508 {
3509 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3510 }
3511
3512 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3513 GL_DYNAMIC_COPY);
3514 ASSERT_GL_NO_ERROR();
3515
3516 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3517 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3518 ASSERT_GL_NO_ERROR();
3519
3520 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3521 ASSERT_GL_NO_ERROR();
3522
3523 glUseProgram(mProgram);
3524 drawQuad(mProgram, "position", 0.5f);
3525 ASSERT_GL_NO_ERROR();
3526
3527 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3528 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3529 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3530 actual.data());
3531 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3532 EXPECT_EQ(expected, actual);
3533}
3534
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003535template <typename T>
3536T UNorm(double value)
3537{
3538 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3539}
3540
3541// Test rendering a depth texture with mipmaps.
3542TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3543{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003544 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3545 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3546 // http://anglebugs.com/1706
3547 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003548 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003549 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003550 return;
3551 }
3552
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003553 const int size = getWindowWidth();
3554
3555 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003556 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003557
3558 glActiveTexture(GL_TEXTURE0);
3559 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3560 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3565 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3566 ASSERT_GL_NO_ERROR();
3567
3568 glUseProgram(mProgram);
3569 glUniform1i(mTexture2DUniformLocation, 0);
3570
3571 std::vector<unsigned char> expected;
3572
3573 for (int level = 0; level < levels; ++level)
3574 {
3575 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3576 expected.push_back(UNorm<unsigned char>(value));
3577
3578 int levelDim = dim(level);
3579
3580 ASSERT_GT(levelDim, 0);
3581
3582 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3583 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3584 GL_UNSIGNED_INT, initData.data());
3585 }
3586 ASSERT_GL_NO_ERROR();
3587
3588 for (int level = 0; level < levels; ++level)
3589 {
3590 glViewport(0, 0, dim(level), dim(level));
3591 drawQuad(mProgram, "position", 0.5f);
3592 GLColor actual = ReadColor(0, 0);
3593 EXPECT_NEAR(expected[level], actual.R, 10u);
3594 }
3595
3596 ASSERT_GL_NO_ERROR();
3597}
3598
Jamie Madill7ffdda92016-09-08 13:26:51 -04003599// Tests unpacking into the unsized GL_ALPHA format.
3600TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3601{
3602 // TODO(jmadill): Figure out why this fails on OSX.
3603 ANGLE_SKIP_TEST_IF(IsOSX());
3604
3605 // Initialize the texure.
3606 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3607 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3608 GL_UNSIGNED_BYTE, nullptr);
3609 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3610 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3611
3612 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3613
3614 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003615 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003616 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3617 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3618 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3619 GL_STATIC_DRAW);
3620
3621 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3622 GL_UNSIGNED_BYTE, nullptr);
3623
3624 // Clear to a weird color to make sure we're drawing something.
3625 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3626 glClear(GL_COLOR_BUFFER_BIT);
3627
3628 // Draw with the alpha texture and verify.
3629 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003630
3631 ASSERT_GL_NO_ERROR();
3632 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3633}
3634
Jamie Madill2e600342016-09-19 13:56:40 -04003635// Ensure stale unpack data doesn't propagate in D3D11.
3636TEST_P(Texture2DTestES3, StaleUnpackData)
3637{
3638 // Init unpack buffer.
3639 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3640 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3641
3642 GLBuffer unpackBuffer;
3643 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3644 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3645 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3646 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3647
3648 // Create from unpack buffer.
3649 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3650 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3651 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3653 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3654
3655 drawQuad(mProgram, "position", 0.5f);
3656
3657 ASSERT_GL_NO_ERROR();
3658 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3659
3660 // Fill unpack with green, recreating buffer.
3661 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3662 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3663 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3664
3665 // Reinit texture with green.
3666 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3667 GL_UNSIGNED_BYTE, nullptr);
3668
3669 drawQuad(mProgram, "position", 0.5f);
3670
3671 ASSERT_GL_NO_ERROR();
3672 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3673}
3674
Jamie Madillf097e232016-11-05 00:44:15 -04003675// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3676// being properly checked, and the texture storage of the previous texture format was persisting.
3677// This would result in an ASSERT in debug and incorrect rendering in release.
3678// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3679TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3680{
3681 GLTexture tex;
3682 glBindTexture(GL_TEXTURE_3D, tex.get());
3683 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3684
3685 GLFramebuffer framebuffer;
3686 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3687 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3688
3689 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3690
3691 std::vector<uint8_t> pixelData(100, 0);
3692
3693 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3694 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3695 pixelData.data());
3696
3697 ASSERT_GL_NO_ERROR();
3698}
3699
Corentin Wallezd2627992017-04-28 17:17:03 -04003700// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3701TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3702{
3703 // 2D tests
3704 {
3705 GLTexture tex;
3706 glBindTexture(GL_TEXTURE_2D, tex.get());
3707
3708 GLBuffer pbo;
3709 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3710
3711 // Test OOB
3712 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3713 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3714 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3715
3716 // Test OOB
3717 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3718 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3719 ASSERT_GL_NO_ERROR();
3720 }
3721
3722 // 3D tests
3723 {
3724 GLTexture tex;
3725 glBindTexture(GL_TEXTURE_3D, tex.get());
3726
3727 GLBuffer pbo;
3728 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3729
3730 // Test OOB
3731 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3732 GL_STATIC_DRAW);
3733 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3734 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3735
3736 // Test OOB
3737 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3738 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3739 ASSERT_GL_NO_ERROR();
3740 }
3741}
3742
Jamie Madillfa05f602015-05-07 13:47:11 -04003743// 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 +02003744// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003745ANGLE_INSTANTIATE_TEST(Texture2DTest,
3746 ES2_D3D9(),
3747 ES2_D3D11(),
3748 ES2_D3D11_FL9_3(),
3749 ES2_OPENGL(),
3750 ES2_OPENGLES());
3751ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3752 ES2_D3D9(),
3753 ES2_D3D11(),
3754 ES2_D3D11_FL9_3(),
3755 ES2_OPENGL(),
3756 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003757ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3758 ES2_D3D9(),
3759 ES2_D3D11(),
3760 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003761 ES2_OPENGL(),
3762 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003763ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3764 ES2_D3D9(),
3765 ES2_D3D11(),
3766 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003767 ES2_OPENGL(),
3768 ES2_OPENGLES());
3769ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3770 ES2_D3D9(),
3771 ES2_D3D11(),
3772 ES2_D3D11_FL9_3(),
3773 ES2_OPENGL(),
3774 ES2_OPENGLES());
3775ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3776 ES2_D3D9(),
3777 ES2_D3D11(),
3778 ES2_D3D11_FL9_3(),
3779 ES2_OPENGL(),
3780 ES2_OPENGLES());
3781ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003782ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003783ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3784ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3785 ES3_D3D11(),
3786 ES3_OPENGL(),
3787 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003788ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3789 ES3_D3D11(),
3790 ES3_OPENGL(),
3791 ES3_OPENGLES());
3792ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3793ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003794ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003795ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3796 ES2_D3D11(),
3797 ES2_D3D11_FL9_3(),
3798 ES2_D3D9(),
3799 ES2_OPENGL(),
3800 ES2_OPENGLES());
3801ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3802 ES2_D3D11(),
3803 ES2_D3D11_FL9_3(),
3804 ES2_D3D9(),
3805 ES2_OPENGL(),
3806 ES2_OPENGLES());
3807ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3808 ES2_D3D11(),
3809 ES2_D3D11_FL9_3(),
3810 ES2_D3D9(),
3811 ES2_OPENGL(),
3812 ES2_OPENGLES());
3813ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3814 ES2_D3D11(),
3815 ES2_D3D11_FL9_3(),
3816 ES2_D3D9(),
3817 ES2_OPENGL(),
3818 ES2_OPENGLES());
3819ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3820 ES2_D3D11(),
3821 ES2_D3D11_FL9_3(),
3822 ES2_D3D9(),
3823 ES2_OPENGL(),
3824 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003825ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02003826ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003827
Jamie Madill7ffdda92016-09-08 13:26:51 -04003828} // anonymous namespace