blob: a5fa997048006776bbe1b9267e8ae8907415e416 [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 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400211
212 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
213 {
214 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
215 << std::endl;
216 return;
217 }
218
219 if (destImageChannels == 4 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"))
220 {
221 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
222 << std::endl;
223 return;
224 }
225
226 if (destImageChannels <= 2)
227 {
228 std::cout << "Test skipped because no extensions grant renderability to 1 and 2 "
229 "channel floating point textures."
230 << std::endl;
231 return;
232 }
233 }
234 else
235 {
236 if (!extensionEnabled("GL_color_buffer_float"))
237 {
238 std::cout << "Test skipped due to missing GL_color_buffer_float." << std::endl;
239 return;
240 }
241
242 if (destImageChannels == 3 && !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"))
243 {
244 std::cout << "Test skipped due to missing GL_CHROMIUM_color_buffer_float_rgb."
245 << std::endl;
246 return;
247 }
Geoff Langfbfa47c2015-03-31 11:26:00 -0400248 }
249
Jamie Madillbc393df2015-01-29 13:46:07 -0500250 GLfloat sourceImageData[4][16] =
251 {
252 { // R
253 1.0f,
254 0.0f,
255 0.0f,
256 1.0f
257 },
258 { // RG
259 1.0f, 0.0f,
260 0.0f, 1.0f,
261 0.0f, 0.0f,
262 1.0f, 1.0f
263 },
264 { // RGB
265 1.0f, 0.0f, 0.0f,
266 0.0f, 1.0f, 0.0f,
267 0.0f, 0.0f, 1.0f,
268 1.0f, 1.0f, 0.0f
269 },
270 { // RGBA
271 1.0f, 0.0f, 0.0f, 1.0f,
272 0.0f, 1.0f, 0.0f, 1.0f,
273 0.0f, 0.0f, 1.0f, 1.0f,
274 1.0f, 1.0f, 0.0f, 1.0f
275 },
276 };
277
278 GLenum imageFormats[] =
279 {
280 GL_R32F,
281 GL_RG32F,
282 GL_RGB32F,
283 GL_RGBA32F,
284 };
285
286 GLenum sourceUnsizedFormats[] =
287 {
288 GL_RED,
289 GL_RG,
290 GL_RGB,
291 GL_RGBA,
292 };
293
294 GLuint textures[2];
295
296 glGenTextures(2, textures);
297
298 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
299 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
300 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
301 GLenum destImageFormat = imageFormats[destImageChannels - 1];
302
303 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400304 if (getClientMajorVersion() >= 3)
305 {
306 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
307 }
308 else
309 {
310 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
311 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
315
hendrikwb27f79a2015-03-04 11:26:46 -0800316 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500317 {
318 // This is not supported
319 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
320 }
321 else
322 {
323 ASSERT_GL_NO_ERROR();
324 }
325
326 GLuint fbo;
327 glGenFramebuffers(1, &fbo);
328 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
329 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
330
331 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400332 if (getClientMajorVersion() >= 3)
333 {
334 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
335 }
336 else
337 {
338 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
339 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
342
343 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
344 ASSERT_GL_NO_ERROR();
345
346 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200347 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500348
349 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
350
Olli Etuahoa314b612016-03-10 16:43:00 +0200351 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500352 if (testImageChannels > 1)
353 {
354 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
355 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
356 if (testImageChannels > 2)
357 {
358 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
359 }
360 }
361
362 glDeleteFramebuffers(1, &fbo);
363 glDeleteTextures(2, textures);
364
365 ASSERT_GL_NO_ERROR();
366 }
367
Jamie Madilld4cfa572014-07-08 10:00:32 -0400368 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400369 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400370};
371
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200372class Texture2DTestES3 : public Texture2DTest
373{
374 protected:
375 Texture2DTestES3() : Texture2DTest() {}
376
377 std::string getVertexShaderSource() override
378 {
379 return std::string(
380 "#version 300 es\n"
381 "out vec2 texcoord;\n"
382 "in vec4 position;\n"
383 "void main()\n"
384 "{\n"
385 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
386 " texcoord = (position.xy * 0.5) + 0.5;\n"
387 "}\n");
388 }
389
390 std::string getFragmentShaderSource() override
391 {
392 return std::string(
393 "#version 300 es\n"
394 "precision highp float;\n"
395 "uniform highp sampler2D tex;\n"
396 "in vec2 texcoord;\n"
397 "out vec4 fragColor;\n"
398 "void main()\n"
399 "{\n"
400 " fragColor = texture(tex, texcoord);\n"
401 "}\n");
402 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300403
404 void SetUp() override
405 {
406 Texture2DTest::SetUp();
407 setUpProgram();
408 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200409};
410
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200411class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
412{
413 protected:
414 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
415
416 std::string getVertexShaderSource() override
417 {
418 return std::string(
419 "#version 300 es\n"
420 "out vec2 texcoord;\n"
421 "in vec4 position;\n"
422 "void main()\n"
423 "{\n"
424 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
425 " texcoord = (position.xy * 0.5) + 0.5;\n"
426 "}\n");
427 }
428
429 std::string getFragmentShaderSource() override
430 {
431 return std::string(
432 "#version 300 es\n"
433 "precision highp float;\n"
434 "uniform highp isampler2D tex;\n"
435 "in vec2 texcoord;\n"
436 "out vec4 fragColor;\n"
437 "void main()\n"
438 "{\n"
439 " vec4 green = vec4(0, 1, 0, 1);\n"
440 " vec4 black = vec4(0, 0, 0, 0);\n"
441 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
442 "}\n");
443 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300444
445 void SetUp() override
446 {
447 Texture2DTest::SetUp();
448 setUpProgram();
449 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200450};
451
452class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
453{
454 protected:
455 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
456
457 std::string getVertexShaderSource() override
458 {
459 return std::string(
460 "#version 300 es\n"
461 "out vec2 texcoord;\n"
462 "in vec4 position;\n"
463 "void main()\n"
464 "{\n"
465 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
466 " texcoord = (position.xy * 0.5) + 0.5;\n"
467 "}\n");
468 }
469
470 std::string getFragmentShaderSource() override
471 {
472 return std::string(
473 "#version 300 es\n"
474 "precision highp float;\n"
475 "uniform highp usampler2D tex;\n"
476 "in vec2 texcoord;\n"
477 "out vec4 fragColor;\n"
478 "void main()\n"
479 "{\n"
480 " vec4 green = vec4(0, 1, 0, 1);\n"
481 " vec4 black = vec4(0, 0, 0, 0);\n"
482 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
483 "}\n");
484 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300485
486 void SetUp() override
487 {
488 Texture2DTest::SetUp();
489 setUpProgram();
490 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200491};
492
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200493class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400494{
495 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200496 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
497
498 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400499 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200500 return std::string(SHADER_SOURCE
501 (
502 precision highp float;
503 attribute vec4 position;
504 varying vec2 texcoord;
505
506 uniform vec2 drawScale;
507
508 void main()
509 {
510 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
511 texcoord = (position.xy * 0.5) + 0.5;
512 }
513 )
514 );
Jamie Madill2453dbc2015-07-14 11:35:42 -0400515 }
516
517 void SetUp() override
518 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200519 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300520
521 setUpProgram();
522
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200523 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
524 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400525
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200526 glUseProgram(mProgram);
527 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
528 glUseProgram(0);
529 ASSERT_GL_NO_ERROR();
530 }
531
532 GLint mDrawScaleUniformLocation;
533};
534
Olli Etuaho4644a202016-01-12 15:12:53 +0200535class Sampler2DAsFunctionParameterTest : public Texture2DTest
536{
537 protected:
538 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
539
540 std::string getFragmentShaderSource() override
541 {
542 return std::string(SHADER_SOURCE
543 (
544 precision highp float;
545 uniform sampler2D tex;
546 varying vec2 texcoord;
547
548 vec4 computeFragColor(sampler2D aTex)
549 {
550 return texture2D(aTex, texcoord);
551 }
552
553 void main()
554 {
555 gl_FragColor = computeFragColor(tex);
556 }
557 )
558 );
559 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300560
561 void SetUp() override
562 {
563 Texture2DTest::SetUp();
564 setUpProgram();
565 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200566};
567
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200568class TextureCubeTest : public TexCoordDrawTest
569{
570 protected:
571 TextureCubeTest()
572 : TexCoordDrawTest(),
573 mTexture2D(0),
574 mTextureCube(0),
575 mTexture2DUniformLocation(-1),
576 mTextureCubeUniformLocation(-1)
577 {
578 }
579
580 std::string getFragmentShaderSource() override
581 {
582 return std::string(SHADER_SOURCE
583 (
584 precision highp float;
585 uniform sampler2D tex2D;
586 uniform samplerCube texCube;
587 varying vec2 texcoord;
588
589 void main()
590 {
591 gl_FragColor = texture2D(tex2D, texcoord);
592 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
593 }
594 )
595 );
596 }
597
598 void SetUp() override
599 {
600 TexCoordDrawTest::SetUp();
601
602 glGenTextures(1, &mTextureCube);
603 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400604 for (GLenum face = 0; face < 6; face++)
605 {
606 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
607 GL_UNSIGNED_BYTE, nullptr);
608 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200609 EXPECT_GL_NO_ERROR();
610
611 mTexture2D = create2DTexture();
612
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300613 setUpProgram();
614
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200615 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
616 ASSERT_NE(-1, mTexture2DUniformLocation);
617 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
618 ASSERT_NE(-1, mTextureCubeUniformLocation);
619 }
620
621 void TearDown() override
622 {
623 glDeleteTextures(1, &mTextureCube);
624 TexCoordDrawTest::TearDown();
625 }
626
627 GLuint mTexture2D;
628 GLuint mTextureCube;
629 GLint mTexture2DUniformLocation;
630 GLint mTextureCubeUniformLocation;
631};
632
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200633class SamplerArrayTest : public TexCoordDrawTest
634{
635 protected:
636 SamplerArrayTest()
637 : TexCoordDrawTest(),
638 mTexture2DA(0),
639 mTexture2DB(0),
640 mTexture0UniformLocation(-1),
641 mTexture1UniformLocation(-1)
642 {
643 }
644
645 std::string getFragmentShaderSource() override
646 {
647 return std::string(SHADER_SOURCE
648 (
649 precision mediump float;
650 uniform highp sampler2D tex2DArray[2];
651 varying vec2 texcoord;
652 void main()
653 {
654 gl_FragColor = texture2D(tex2DArray[0], texcoord);
655 gl_FragColor += texture2D(tex2DArray[1], texcoord);
656 }
657 )
658 );
659 }
660
661 void SetUp() override
662 {
663 TexCoordDrawTest::SetUp();
664
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300665 setUpProgram();
666
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200667 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
668 ASSERT_NE(-1, mTexture0UniformLocation);
669 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
670 ASSERT_NE(-1, mTexture1UniformLocation);
671
672 mTexture2DA = create2DTexture();
673 mTexture2DB = create2DTexture();
674 ASSERT_GL_NO_ERROR();
675 }
676
677 void TearDown() override
678 {
679 glDeleteTextures(1, &mTexture2DA);
680 glDeleteTextures(1, &mTexture2DB);
681 TexCoordDrawTest::TearDown();
682 }
683
684 void testSamplerArrayDraw()
685 {
686 GLubyte texData[4];
687 texData[0] = 0;
688 texData[1] = 60;
689 texData[2] = 0;
690 texData[3] = 255;
691
692 glActiveTexture(GL_TEXTURE0);
693 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
694 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
695
696 texData[1] = 120;
697 glActiveTexture(GL_TEXTURE1);
698 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
699 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
700 EXPECT_GL_ERROR(GL_NO_ERROR);
701
702 glUseProgram(mProgram);
703 glUniform1i(mTexture0UniformLocation, 0);
704 glUniform1i(mTexture1UniformLocation, 1);
705 drawQuad(mProgram, "position", 0.5f);
706 EXPECT_GL_NO_ERROR();
707
708 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
709 }
710
711 GLuint mTexture2DA;
712 GLuint mTexture2DB;
713 GLint mTexture0UniformLocation;
714 GLint mTexture1UniformLocation;
715};
716
717
718class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
719{
720 protected:
721 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
722
723 std::string getFragmentShaderSource() override
724 {
725 return std::string(SHADER_SOURCE
726 (
727 precision mediump float;
728 uniform highp sampler2D tex2DArray[2];
729 varying vec2 texcoord;
730
731 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
732 {
733 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
734 }
735
736 void main()
737 {
738 gl_FragColor = computeFragColor(tex2DArray);
739 }
740 )
741 );
742 }
743};
744
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200745class Texture2DArrayTestES3 : public TexCoordDrawTest
746{
747 protected:
748 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
749
750 std::string getVertexShaderSource() override
751 {
752 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400753 "#version 300 es\n"
754 "out vec2 texcoord;\n"
755 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200756 "void main()\n"
757 "{\n"
758 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
759 " texcoord = (position.xy * 0.5) + 0.5;\n"
760 "}\n");
761 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400762
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200763 std::string getFragmentShaderSource() override
764 {
765 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400766 "#version 300 es\n"
767 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200768 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400769 "in vec2 texcoord;\n"
770 "out vec4 fragColor;\n"
771 "void main()\n"
772 "{\n"
773 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200774 "}\n");
775 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400776
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200777 void SetUp() override
778 {
779 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400780
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300781 setUpProgram();
782
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200783 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400784 ASSERT_NE(-1, mTextureArrayLocation);
785
786 glGenTextures(1, &m2DArrayTexture);
787 ASSERT_GL_NO_ERROR();
788 }
789
790 void TearDown() override
791 {
792 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200793 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400794 }
795
796 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400797 GLint mTextureArrayLocation;
798};
799
Olli Etuahobce743a2016-01-15 17:18:28 +0200800class TextureSizeTextureArrayTest : public TexCoordDrawTest
801{
802 protected:
803 TextureSizeTextureArrayTest()
804 : TexCoordDrawTest(),
805 mTexture2DA(0),
806 mTexture2DB(0),
807 mTexture0Location(-1),
808 mTexture1Location(-1)
809 {
810 }
811
812 std::string getVertexShaderSource() override
813 {
814 return std::string(
815 "#version 300 es\n"
816 "in vec4 position;\n"
817 "void main()\n"
818 "{\n"
819 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
820 "}\n");
821 }
822
823 std::string getFragmentShaderSource() override
824 {
825 return std::string(
826 "#version 300 es\n"
827 "precision highp float;\n"
828 "uniform highp sampler2D tex2DArray[2];\n"
829 "out vec4 fragColor;\n"
830 "void main()\n"
831 "{\n"
832 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
833 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
834 " fragColor = vec4(red, green, 0.0, 1.0);\n"
835 "}\n");
836 }
837
838 void SetUp() override
839 {
840 TexCoordDrawTest::SetUp();
841
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300842 setUpProgram();
843
Olli Etuahobce743a2016-01-15 17:18:28 +0200844 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
845 ASSERT_NE(-1, mTexture0Location);
846 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
847 ASSERT_NE(-1, mTexture1Location);
848
849 mTexture2DA = create2DTexture();
850 mTexture2DB = create2DTexture();
851 ASSERT_GL_NO_ERROR();
852 }
853
854 void TearDown() override
855 {
856 glDeleteTextures(1, &mTexture2DA);
857 glDeleteTextures(1, &mTexture2DB);
858 TexCoordDrawTest::TearDown();
859 }
860
861 GLuint mTexture2DA;
862 GLuint mTexture2DB;
863 GLint mTexture0Location;
864 GLint mTexture1Location;
865};
866
Olli Etuahoa314b612016-03-10 16:43:00 +0200867class Texture3DTestES3 : public TexCoordDrawTest
868{
869 protected:
870 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
871
872 std::string getVertexShaderSource() override
873 {
874 return std::string(
875 "#version 300 es\n"
876 "out vec2 texcoord;\n"
877 "in vec4 position;\n"
878 "void main()\n"
879 "{\n"
880 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
881 " texcoord = (position.xy * 0.5) + 0.5;\n"
882 "}\n");
883 }
884
885 std::string getFragmentShaderSource() override
886 {
887 return std::string(
888 "#version 300 es\n"
889 "precision highp float;\n"
890 "uniform highp sampler3D tex3D;\n"
891 "in vec2 texcoord;\n"
892 "out vec4 fragColor;\n"
893 "void main()\n"
894 "{\n"
895 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
896 "}\n");
897 }
898
899 void SetUp() override
900 {
901 TexCoordDrawTest::SetUp();
902
903 glGenTextures(1, &mTexture3D);
904
905 setUpProgram();
906
907 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
908 ASSERT_NE(-1, mTexture3DUniformLocation);
909 }
910
911 void TearDown() override
912 {
913 glDeleteTextures(1, &mTexture3D);
914 TexCoordDrawTest::TearDown();
915 }
916
917 GLuint mTexture3D;
918 GLint mTexture3DUniformLocation;
919};
920
Olli Etuaho1a679902016-01-14 12:21:47 +0200921class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
922{
923 protected:
924 ShadowSamplerPlusSampler3DTestES3()
925 : TexCoordDrawTest(),
926 mTextureShadow(0),
927 mTexture3D(0),
928 mTextureShadowUniformLocation(-1),
929 mTexture3DUniformLocation(-1),
930 mDepthRefUniformLocation(-1)
931 {
932 }
933
934 std::string getVertexShaderSource() override
935 {
936 return std::string(
937 "#version 300 es\n"
938 "out vec2 texcoord;\n"
939 "in vec4 position;\n"
940 "void main()\n"
941 "{\n"
942 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
943 " texcoord = (position.xy * 0.5) + 0.5;\n"
944 "}\n");
945 }
946
947 std::string getFragmentShaderSource() override
948 {
949 return std::string(
950 "#version 300 es\n"
951 "precision highp float;\n"
952 "uniform highp sampler2DShadow tex2DShadow;\n"
953 "uniform highp sampler3D tex3D;\n"
954 "in vec2 texcoord;\n"
955 "uniform float depthRef;\n"
956 "out vec4 fragColor;\n"
957 "void main()\n"
958 "{\n"
959 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
960 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
961 "}\n");
962 }
963
964 void SetUp() override
965 {
966 TexCoordDrawTest::SetUp();
967
968 glGenTextures(1, &mTexture3D);
969
970 glGenTextures(1, &mTextureShadow);
971 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
973
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300974 setUpProgram();
975
Olli Etuaho1a679902016-01-14 12:21:47 +0200976 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
977 ASSERT_NE(-1, mTextureShadowUniformLocation);
978 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
979 ASSERT_NE(-1, mTexture3DUniformLocation);
980 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
981 ASSERT_NE(-1, mDepthRefUniformLocation);
982 }
983
984 void TearDown() override
985 {
986 glDeleteTextures(1, &mTextureShadow);
987 glDeleteTextures(1, &mTexture3D);
988 TexCoordDrawTest::TearDown();
989 }
990
991 GLuint mTextureShadow;
992 GLuint mTexture3D;
993 GLint mTextureShadowUniformLocation;
994 GLint mTexture3DUniformLocation;
995 GLint mDepthRefUniformLocation;
996};
997
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200998class SamplerTypeMixTestES3 : public TexCoordDrawTest
999{
1000 protected:
1001 SamplerTypeMixTestES3()
1002 : TexCoordDrawTest(),
1003 mTexture2D(0),
1004 mTextureCube(0),
1005 mTexture2DShadow(0),
1006 mTextureCubeShadow(0),
1007 mTexture2DUniformLocation(-1),
1008 mTextureCubeUniformLocation(-1),
1009 mTexture2DShadowUniformLocation(-1),
1010 mTextureCubeShadowUniformLocation(-1),
1011 mDepthRefUniformLocation(-1)
1012 {
1013 }
1014
1015 std::string getVertexShaderSource() override
1016 {
1017 return std::string(
1018 "#version 300 es\n"
1019 "out vec2 texcoord;\n"
1020 "in vec4 position;\n"
1021 "void main()\n"
1022 "{\n"
1023 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
1024 " texcoord = (position.xy * 0.5) + 0.5;\n"
1025 "}\n");
1026 }
1027
1028 std::string getFragmentShaderSource() override
1029 {
1030 return std::string(
1031 "#version 300 es\n"
1032 "precision highp float;\n"
1033 "uniform highp sampler2D tex2D;\n"
1034 "uniform highp samplerCube texCube;\n"
1035 "uniform highp sampler2DShadow tex2DShadow;\n"
1036 "uniform highp samplerCubeShadow texCubeShadow;\n"
1037 "in vec2 texcoord;\n"
1038 "uniform float depthRef;\n"
1039 "out vec4 fragColor;\n"
1040 "void main()\n"
1041 "{\n"
1042 " fragColor = texture(tex2D, texcoord);\n"
1043 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
1044 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
1045 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
1046 "0.125);\n"
1047 "}\n");
1048 }
1049
1050 void SetUp() override
1051 {
1052 TexCoordDrawTest::SetUp();
1053
1054 glGenTextures(1, &mTexture2D);
1055 glGenTextures(1, &mTextureCube);
1056
1057 glGenTextures(1, &mTexture2DShadow);
1058 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
1059 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1060
1061 glGenTextures(1, &mTextureCubeShadow);
1062 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
1063 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
1064
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001065 setUpProgram();
1066
Olli Etuahoc8c99a02016-01-14 16:47:22 +02001067 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
1068 ASSERT_NE(-1, mTexture2DUniformLocation);
1069 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1070 ASSERT_NE(-1, mTextureCubeUniformLocation);
1071 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1072 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1073 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1074 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1075 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1076 ASSERT_NE(-1, mDepthRefUniformLocation);
1077
1078 ASSERT_GL_NO_ERROR();
1079 }
1080
1081 void TearDown() override
1082 {
1083 glDeleteTextures(1, &mTexture2D);
1084 glDeleteTextures(1, &mTextureCube);
1085 glDeleteTextures(1, &mTexture2DShadow);
1086 glDeleteTextures(1, &mTextureCubeShadow);
1087 TexCoordDrawTest::TearDown();
1088 }
1089
1090 GLuint mTexture2D;
1091 GLuint mTextureCube;
1092 GLuint mTexture2DShadow;
1093 GLuint mTextureCubeShadow;
1094 GLint mTexture2DUniformLocation;
1095 GLint mTextureCubeUniformLocation;
1096 GLint mTexture2DShadowUniformLocation;
1097 GLint mTextureCubeShadowUniformLocation;
1098 GLint mDepthRefUniformLocation;
1099};
1100
Olli Etuaho96963162016-03-21 11:54:33 +02001101class SamplerInStructTest : public Texture2DTest
1102{
1103 protected:
1104 SamplerInStructTest() : Texture2DTest() {}
1105
1106 const char *getTextureUniformName() override { return "us.tex"; }
1107
1108 std::string getFragmentShaderSource() override
1109 {
1110 return std::string(
1111 "precision highp float;\n"
1112 "struct S\n"
1113 "{\n"
1114 " vec4 a;\n"
1115 " highp sampler2D tex;\n"
1116 "};\n"
1117 "uniform S us;\n"
1118 "varying vec2 texcoord;\n"
1119 "void main()\n"
1120 "{\n"
1121 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1122 "}\n");
1123 }
1124
1125 void runSamplerInStructTest()
1126 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001127 setUpProgram();
1128
Olli Etuaho96963162016-03-21 11:54:33 +02001129 glActiveTexture(GL_TEXTURE0);
1130 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1132 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001133 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001134 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001135 }
1136};
1137
1138class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1139{
1140 protected:
1141 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1142
1143 std::string getFragmentShaderSource() override
1144 {
1145 return std::string(
1146 "precision highp float;\n"
1147 "struct S\n"
1148 "{\n"
1149 " vec4 a;\n"
1150 " highp sampler2D tex;\n"
1151 "};\n"
1152 "uniform S us;\n"
1153 "varying vec2 texcoord;\n"
1154 "vec4 sampleFrom(S s) {\n"
1155 " return texture2D(s.tex, texcoord + s.a.x);\n"
1156 "}\n"
1157 "void main()\n"
1158 "{\n"
1159 " gl_FragColor = sampleFrom(us);\n"
1160 "}\n");
1161 }
1162};
1163
1164class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1165{
1166 protected:
1167 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1168
1169 const char *getTextureUniformName() override { return "us[0].tex"; }
1170
1171 std::string getFragmentShaderSource() override
1172 {
1173 return std::string(
1174 "precision highp float;\n"
1175 "struct S\n"
1176 "{\n"
1177 " vec4 a;\n"
1178 " highp sampler2D tex;\n"
1179 "};\n"
1180 "uniform S us[1];\n"
1181 "varying vec2 texcoord;\n"
1182 "vec4 sampleFrom(S s) {\n"
1183 " return texture2D(s.tex, texcoord + s.a.x);\n"
1184 "}\n"
1185 "void main()\n"
1186 "{\n"
1187 " gl_FragColor = sampleFrom(us[0]);\n"
1188 "}\n");
1189 }
1190};
1191
1192class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1193{
1194 protected:
1195 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1196
1197 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1198
1199 std::string getFragmentShaderSource() override
1200 {
1201 return std::string(
1202 "precision highp float;\n"
1203 "struct SUB\n"
1204 "{\n"
1205 " vec4 a;\n"
1206 " highp sampler2D tex;\n"
1207 "};\n"
1208 "struct S\n"
1209 "{\n"
1210 " SUB sub;\n"
1211 "};\n"
1212 "uniform S us[1];\n"
1213 "varying vec2 texcoord;\n"
1214 "vec4 sampleFrom(SUB s) {\n"
1215 " return texture2D(s.tex, texcoord + s.a.x);\n"
1216 "}\n"
1217 "void main()\n"
1218 "{\n"
1219 " gl_FragColor = sampleFrom(us[0].sub);\n"
1220 "}\n");
1221 }
1222};
1223
1224class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1225{
1226 protected:
1227 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1228
1229 std::string getFragmentShaderSource() override
1230 {
1231 return std::string(
1232 "precision highp float;\n"
1233 "struct S\n"
1234 "{\n"
1235 " vec4 a;\n"
1236 " highp sampler2D tex;\n"
1237 "};\n"
1238 "uniform S us;\n"
1239 "uniform float us_tex;\n"
1240 "varying vec2 texcoord;\n"
1241 "void main()\n"
1242 "{\n"
1243 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1244 "}\n");
1245 }
1246};
1247
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001248TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001249{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001250 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001251 EXPECT_GL_ERROR(GL_NO_ERROR);
1252
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001253 setUpProgram();
1254
Jamie Madillf67115c2014-04-22 13:14:05 -04001255 const GLubyte *pixels[20] = { 0 };
1256 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1257 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001258
1259 if (extensionEnabled("GL_EXT_texture_storage"))
1260 {
1261 // Create a 1-level immutable texture.
1262 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1263
1264 // Try calling sub image on the second level.
1265 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1266 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1267 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001268}
Geoff Langc41e42d2014-04-28 10:58:16 -04001269
John Bauman18319182016-09-28 14:22:27 -07001270// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1271TEST_P(Texture2DTest, QueryBinding)
1272{
1273 glBindTexture(GL_TEXTURE_2D, 0);
1274 EXPECT_GL_ERROR(GL_NO_ERROR);
1275
1276 GLint textureBinding;
1277 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1278 EXPECT_GL_NO_ERROR();
1279 EXPECT_EQ(0, textureBinding);
1280
1281 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1282 if (extensionEnabled("GL_OES_EGL_image_external") ||
1283 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1284 {
1285 EXPECT_GL_NO_ERROR();
1286 EXPECT_EQ(0, textureBinding);
1287 }
1288 else
1289 {
1290 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1291 }
1292}
1293
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001294TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001295{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001296 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001297 EXPECT_GL_ERROR(GL_NO_ERROR);
1298
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001299 setUpProgram();
1300
Geoff Langc41e42d2014-04-28 10:58:16 -04001301 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001302 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001303 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001304 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001305
1306 const GLubyte *pixel[4] = { 0 };
1307
1308 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1309 EXPECT_GL_NO_ERROR();
1310
1311 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1312 EXPECT_GL_NO_ERROR();
1313
1314 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1315 EXPECT_GL_NO_ERROR();
1316}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001317
1318// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001319TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001320{
1321 glActiveTexture(GL_TEXTURE0);
1322 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1323 glActiveTexture(GL_TEXTURE1);
1324 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1325 EXPECT_GL_ERROR(GL_NO_ERROR);
1326
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001327 glUseProgram(mProgram);
1328 glUniform1i(mTexture2DUniformLocation, 0);
1329 glUniform1i(mTextureCubeUniformLocation, 1);
1330 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001331 EXPECT_GL_NO_ERROR();
1332}
Jamie Madill9aca0592014-10-06 16:26:59 -04001333
Olli Etuaho53a2da12016-01-11 15:43:32 +02001334// Test drawing with two texture types accessed from the same shader and check that the result of
1335// drawing is correct.
1336TEST_P(TextureCubeTest, CubeMapDraw)
1337{
1338 GLubyte texData[4];
1339 texData[0] = 0;
1340 texData[1] = 60;
1341 texData[2] = 0;
1342 texData[3] = 255;
1343
1344 glActiveTexture(GL_TEXTURE0);
1345 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1346 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1347
1348 glActiveTexture(GL_TEXTURE1);
1349 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1350 texData[1] = 120;
1351 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1352 texData);
1353 EXPECT_GL_ERROR(GL_NO_ERROR);
1354
1355 glUseProgram(mProgram);
1356 glUniform1i(mTexture2DUniformLocation, 0);
1357 glUniform1i(mTextureCubeUniformLocation, 1);
1358 drawQuad(mProgram, "position", 0.5f);
1359 EXPECT_GL_NO_ERROR();
1360
1361 int px = getWindowWidth() - 1;
1362 int py = 0;
1363 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1364}
1365
Olli Etuaho4644a202016-01-12 15:12:53 +02001366TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1367{
1368 glActiveTexture(GL_TEXTURE0);
1369 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1370 GLubyte texData[4];
1371 texData[0] = 0;
1372 texData[1] = 128;
1373 texData[2] = 0;
1374 texData[3] = 255;
1375 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1376 glUseProgram(mProgram);
1377 glUniform1i(mTexture2DUniformLocation, 0);
1378 drawQuad(mProgram, "position", 0.5f);
1379 EXPECT_GL_NO_ERROR();
1380
1381 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1382}
1383
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001384// Test drawing with two textures passed to the shader in a sampler array.
1385TEST_P(SamplerArrayTest, SamplerArrayDraw)
1386{
1387 testSamplerArrayDraw();
1388}
1389
1390// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1391// user-defined function in the shader.
1392TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1393{
1394 testSamplerArrayDraw();
1395}
1396
Jamie Madill9aca0592014-10-06 16:26:59 -04001397// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001398TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001399{
1400 int px = getWindowWidth() / 2;
1401 int py = getWindowHeight() / 2;
1402
1403 glActiveTexture(GL_TEXTURE0);
1404 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1405
Olli Etuahoa314b612016-03-10 16:43:00 +02001406 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001407
Olli Etuahoa314b612016-03-10 16:43:00 +02001408 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1410 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1411 glGenerateMipmap(GL_TEXTURE_2D);
1412
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001413 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001414 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001415 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1416 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001417 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001418 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001419
Olli Etuahoa314b612016-03-10 16:43:00 +02001420 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001421
Olli Etuahoa314b612016-03-10 16:43:00 +02001422 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1423 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001424 glGenerateMipmap(GL_TEXTURE_2D);
1425
Olli Etuahoa314b612016-03-10 16:43:00 +02001426 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001427
Olli Etuahoa314b612016-03-10 16:43:00 +02001428 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1429 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001430 glGenerateMipmap(GL_TEXTURE_2D);
1431
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001432 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001433
1434 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001435 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001436}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001437
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001438// Test creating a FBO with a cube map render target, to test an ANGLE bug
1439// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001440TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001441{
1442 GLuint fbo;
1443 glGenFramebuffers(1, &fbo);
1444 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1445
1446 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1447 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mTextureCube, 0);
1448
Corentin Wallez322653b2015-06-17 18:33:56 +02001449 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001450
1451 glDeleteFramebuffers(1, &fbo);
1452
1453 EXPECT_GL_NO_ERROR();
1454}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001455
1456// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001457TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001458{
Geoff Langc4e93662017-05-01 10:45:59 -04001459 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
1460 {
1461 std::cout << "Test skipped because ES3 or GL_EXT_texture_storage not available."
1462 << std::endl;
1463 return;
1464 }
1465
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001466 int width = getWindowWidth();
1467 int height = getWindowHeight();
1468
1469 GLuint tex2D;
1470 glGenTextures(1, &tex2D);
1471 glActiveTexture(GL_TEXTURE0);
1472 glBindTexture(GL_TEXTURE_2D, tex2D);
1473
1474 // Fill with red
1475 std::vector<GLubyte> pixels(3 * 16 * 16);
1476 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1477 {
1478 pixels[pixelId * 3 + 0] = 255;
1479 pixels[pixelId * 3 + 1] = 0;
1480 pixels[pixelId * 3 + 2] = 0;
1481 }
1482
1483 // ANGLE internally uses RGBA as the DirectX format for RGB images
1484 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1485 // The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001486 if (getClientMajorVersion() >= 3)
1487 {
1488 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1489 }
1490 else
1491 {
1492 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1493 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001494
1495 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1496 // glTexSubImage2D should take into account that the image is dirty.
1497 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1498 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1499 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1500
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001501 setUpProgram();
1502
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001503 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001504 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001505 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001506 glDeleteTextures(1, &tex2D);
1507 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001508 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001509
1510 // Validate that the region of the texture without data has an alpha of 1.0
1511 GLubyte pixel[4];
1512 glReadPixels(3 * width / 4, 3 * height / 4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1513 EXPECT_EQ(pixel[3], 255);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001514}
1515
1516// 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 +02001517TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001518{
1519 if (extensionEnabled("NV_pixel_buffer_object"))
1520 {
1521 int width = getWindowWidth();
1522 int height = getWindowHeight();
1523
1524 GLuint tex2D;
1525 glGenTextures(1, &tex2D);
1526 glActiveTexture(GL_TEXTURE0);
1527 glBindTexture(GL_TEXTURE_2D, tex2D);
1528
1529 // Fill with red
1530 std::vector<GLubyte> pixels(3 * 16 * 16);
1531 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1532 {
1533 pixels[pixelId * 3 + 0] = 255;
1534 pixels[pixelId * 3 + 1] = 0;
1535 pixels[pixelId * 3 + 2] = 0;
1536 }
1537
1538 // Read 16x16 region from red backbuffer to PBO
1539 GLuint pbo;
1540 glGenBuffers(1, &pbo);
1541 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1542 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1543
1544 // ANGLE internally uses RGBA as the DirectX format for RGB images
1545 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent alpha color.
1546 // The data is kept in a CPU-side image and the image is marked as dirty.
1547 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1548
1549 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1550 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001551 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 +00001552 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1553 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1554
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001555 setUpProgram();
1556
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001557 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001558 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001559 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001560 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001561 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001562 EXPECT_GL_NO_ERROR();
1563 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1564 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1565 }
1566}
Jamie Madillbc393df2015-01-29 13:46:07 -05001567
1568// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001569TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001570{
1571 testFloatCopySubImage(1, 1);
1572}
1573
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001574TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001575{
1576 testFloatCopySubImage(2, 1);
1577}
1578
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001579TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001580{
1581 testFloatCopySubImage(2, 2);
1582}
1583
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001584TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001585{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001586 if (IsIntel() && IsLinux())
1587 {
1588 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1589 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1590 return;
1591 }
1592
Jamie Madillbc393df2015-01-29 13:46:07 -05001593 testFloatCopySubImage(3, 1);
1594}
1595
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001596TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001597{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001598 if (IsIntel() && IsLinux())
1599 {
1600 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1601 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1602 return;
1603 }
1604
Jamie Madillbc393df2015-01-29 13:46:07 -05001605 testFloatCopySubImage(3, 2);
1606}
1607
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001608TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001609{
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001610 if (IsIntel() && IsLinux())
1611 {
1612 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1613 std::cout << "Test disabled on Linux Intel OpenGL." << std::endl;
1614 return;
1615 }
1616
Austin Kinrossd544cc92016-01-11 15:26:42 -08001617 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001618 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001619 {
1620 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1621 return;
1622 }
1623
Jamie Madillbc393df2015-01-29 13:46:07 -05001624 testFloatCopySubImage(3, 3);
1625}
1626
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001627TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001628{
1629 testFloatCopySubImage(4, 1);
1630}
1631
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001632TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001633{
1634 testFloatCopySubImage(4, 2);
1635}
1636
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001637TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001638{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001639 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001640 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001641 {
1642 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1643 return;
1644 }
1645
Jamie Madillbc393df2015-01-29 13:46:07 -05001646 testFloatCopySubImage(4, 3);
1647}
1648
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001649TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001650{
Austin Kinrossd544cc92016-01-11 15:26:42 -08001651 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -05001652 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -08001653 {
1654 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
1655 return;
1656 }
1657
Jamie Madillbc393df2015-01-29 13:46:07 -05001658 testFloatCopySubImage(4, 4);
1659}
Austin Kinross07285142015-03-26 11:36:16 -07001660
1661// Port of https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1662// 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 +02001663TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001664{
1665 const int npotTexSize = 5;
1666 const int potTexSize = 4; // Should be less than npotTexSize
1667 GLuint tex2D;
1668
1669 if (extensionEnabled("GL_OES_texture_npot"))
1670 {
1671 // This test isn't applicable if texture_npot is enabled
1672 return;
1673 }
1674
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001675 setUpProgram();
1676
Austin Kinross07285142015-03-26 11:36:16 -07001677 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1678
Austin Kinross5faa15b2016-01-11 13:32:48 -08001679 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1680 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1681
Austin Kinross07285142015-03-26 11:36:16 -07001682 glActiveTexture(GL_TEXTURE0);
1683 glGenTextures(1, &tex2D);
1684 glBindTexture(GL_TEXTURE_2D, tex2D);
1685
1686 std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize);
1687 for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId)
1688 {
1689 pixels[pixelId] = 64;
1690 }
1691
1692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1694
1695 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
1696 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1697 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1698
1699 // Check that an NPOT texture on level 0 succeeds
1700 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1701 EXPECT_GL_NO_ERROR();
1702
1703 // Check that generateMipmap fails on NPOT
1704 glGenerateMipmap(GL_TEXTURE_2D);
1705 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1706
1707 // Check that nothing is drawn if filtering is not correct for NPOT
1708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1709 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1710 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1711 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1712 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001713 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001714 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1715
1716 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1720 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001721 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001722 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1723
1724 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1726 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001727 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001728 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1729
1730 // Check that glTexImage2D for POT texture succeeds
1731 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels.data());
1732 EXPECT_GL_NO_ERROR();
1733
1734 // Check that generateMipmap for an POT texture succeeds
1735 glGenerateMipmap(GL_TEXTURE_2D);
1736 EXPECT_GL_NO_ERROR();
1737
1738 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1739 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1743 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001744 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001745 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1746 EXPECT_GL_NO_ERROR();
1747}
Jamie Madillfa05f602015-05-07 13:47:11 -04001748
Austin Kinross08528e12015-10-07 16:24:40 -07001749// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1750// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001751TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001752{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001753 // TODO(geofflang): Allow the GL backend to accept SubImage calls with a null data ptr. (bug
1754 // 1278)
1755 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1756 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1757 {
1758 std::cout << "Test disabled on OpenGL." << std::endl;
1759 return;
1760 }
1761
Austin Kinross08528e12015-10-07 16:24:40 -07001762 glActiveTexture(GL_TEXTURE0);
1763 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1764
1765 // Create an 8x8 (i.e. power-of-two) texture.
1766 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1768 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1769 glGenerateMipmap(GL_TEXTURE_2D);
1770
1771 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1772 // This should always work, even if GL_OES_texture_npot isn't active.
1773 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1774
1775 EXPECT_GL_NO_ERROR();
1776}
1777
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001778// Test to check that texture completeness is determined correctly when the texture base level is
1779// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1780TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1781{
1782 glActiveTexture(GL_TEXTURE0);
1783 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001784
1785 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1786 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1787 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1788 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1789 texDataGreen.data());
1790 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1791 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001792 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1793 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1795
1796 EXPECT_GL_NO_ERROR();
1797
1798 drawQuad(mProgram, "position", 0.5f);
1799
Olli Etuahoa314b612016-03-10 16:43:00 +02001800 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1801}
1802
1803// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1804// have images defined.
1805TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1806{
1807 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1808 {
1809 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1810 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1811 return;
1812 }
1813 if (IsOSX())
1814 {
1815 // Observed incorrect rendering on OSX.
1816 std::cout << "Test skipped on OSX." << std::endl;
1817 return;
1818 }
1819 glActiveTexture(GL_TEXTURE0);
1820 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1821 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1822 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1823 texDataGreen.data());
1824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1826 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1827 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1828
1829 EXPECT_GL_NO_ERROR();
1830
1831 drawQuad(mProgram, "position", 0.5f);
1832
1833 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1834}
1835
Olli Etuahoe8528d82016-05-16 17:50:52 +03001836// Test that drawing works correctly when level 0 is undefined and base level is 1.
1837TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1838{
1839 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1840 {
1841 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1842 std::cout << "Test skipped on AMD OpenGL." << std::endl;
1843 return;
1844 }
1845 if (IsOSX())
1846 {
1847 // Observed incorrect rendering on OSX.
1848 std::cout << "Test skipped on OSX." << std::endl;
1849 return;
1850 }
1851 glActiveTexture(GL_TEXTURE0);
1852 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1853 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1854 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1855 texDataGreen.data());
1856 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1857 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1858 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1859 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1860
1861 EXPECT_GL_NO_ERROR();
1862
1863 // Texture is incomplete.
1864 drawQuad(mProgram, "position", 0.5f);
1865 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1866
1867 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1868 texDataGreen.data());
1869
1870 // Texture is now complete.
1871 drawQuad(mProgram, "position", 0.5f);
1872 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1873}
1874
Olli Etuahoa314b612016-03-10 16:43:00 +02001875// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1876// dimensions that don't fit the images inside the range.
1877// GLES 3.0.4 section 3.8.13 Texture completeness
1878TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1879{
1880 if (IsOSX())
1881 {
1882 // Observed incorrect rendering on OSX.
1883 std::cout << "Test skipped on OSX." << std::endl;
1884 return;
1885 }
1886 glActiveTexture(GL_TEXTURE0);
1887 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1888 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1889 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1890 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1891
1892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1893 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1894
1895 // Two levels that are initially unused.
1896 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1897 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1898 texDataCyan.data());
1899
1900 // One level that is used - only this level should affect completeness.
1901 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1902 texDataGreen.data());
1903
1904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1905 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1906
1907 EXPECT_GL_NO_ERROR();
1908
1909 drawQuad(mProgram, "position", 0.5f);
1910
1911 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1912
1913 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1914 {
1915 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
1916 // level was changed.
1917 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
1918 return;
1919 }
1920
1921 // Switch the level that is being used to the cyan level 2.
1922 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1923 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1924
1925 EXPECT_GL_NO_ERROR();
1926
1927 drawQuad(mProgram, "position", 0.5f);
1928
1929 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1930}
1931
1932// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1933// have images defined.
1934TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1935{
1936 if (IsOSX())
1937 {
1938 // Observed incorrect rendering on OSX.
1939 std::cout << "Test skipped on OSX." << std::endl;
1940 return;
1941 }
1942 glActiveTexture(GL_TEXTURE0);
1943 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1944 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1945 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1946 texDataGreen.data());
1947 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1948 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1949 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1950 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1951
1952 EXPECT_GL_NO_ERROR();
1953
1954 drawQuad(mProgram, "position", 0.5f);
1955
1956 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1957}
1958
1959// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1960// dimensions that don't fit the images inside the range.
1961// GLES 3.0.4 section 3.8.13 Texture completeness
1962TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1963{
1964 if (IsOSX())
1965 {
1966 // Observed incorrect rendering on OSX.
1967 std::cout << "Test skipped on OSX." << std::endl;
1968 return;
1969 }
1970 glActiveTexture(GL_TEXTURE0);
1971 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1972 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1973 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1974 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1975
1976 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1977 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1978
1979 // Two levels that are initially unused.
1980 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1981 texDataRed.data());
1982 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1983 texDataCyan.data());
1984
1985 // One level that is used - only this level should affect completeness.
1986 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1987 texDataGreen.data());
1988
1989 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1990 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1991
1992 EXPECT_GL_NO_ERROR();
1993
1994 drawQuad(mProgram, "position", 0.5f);
1995
1996 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1997
1998 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
1999 {
2000 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2001 // level was changed.
2002 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2003 return;
2004 }
2005
2006 // Switch the level that is being used to the cyan level 2.
2007 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
2008 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
2009
2010 EXPECT_GL_NO_ERROR();
2011
2012 drawQuad(mProgram, "position", 0.5f);
2013
2014 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2015}
2016
2017// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
2018// have images defined.
2019TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
2020{
2021 if (IsOSX())
2022 {
2023 // Observed incorrect rendering on OSX.
2024 std::cout << "Test skipped on OSX." << std::endl;
2025 return;
2026 }
2027 glActiveTexture(GL_TEXTURE0);
2028 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
2029 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2030 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2031 texDataGreen.data());
2032 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2033 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2034 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2035 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2036
2037 EXPECT_GL_NO_ERROR();
2038
2039 drawQuad(mProgram, "position", 0.5f);
2040
2041 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2042}
2043
2044// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
2045// dimensions that don't fit the images inside the range.
2046// GLES 3.0.4 section 3.8.13 Texture completeness
2047TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
2048{
2049 if (IsOSX())
2050 {
2051 // Observed incorrect rendering on OSX.
2052 std::cout << "Test skipped on OSX." << std::endl;
2053 return;
2054 }
2055 glActiveTexture(GL_TEXTURE0);
2056 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
2057 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
2058 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2059 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
2060
2061 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2062 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2063
2064 // Two levels that are initially unused.
2065 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2066 texDataRed.data());
2067 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2068 texDataCyan.data());
2069
2070 // One level that is used - only this level should affect completeness.
2071 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2072 texDataGreen.data());
2073
2074 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
2075 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
2076
2077 EXPECT_GL_NO_ERROR();
2078
2079 drawQuad(mProgram, "position", 0.5f);
2080
2081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2082
2083 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2084 {
2085 // Intel was observed drawing color 0,0,0,0 instead of the texture color after the base
2086 // level was changed.
2087 std::cout << "Test partially skipped on Intel OpenGL." << std::endl;
2088 return;
2089 }
2090 if (IsNVIDIA() && (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
2091 getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE))
2092 {
2093 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
2094 // level was changed.
2095 std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl;
2096 return;
2097 }
2098
2099 // Switch the level that is being used to the cyan level 2.
2100 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
2101 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
2102
2103 EXPECT_GL_NO_ERROR();
2104
2105 drawQuad(mProgram, "position", 0.5f);
2106
2107 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2108}
2109
2110// Test that texture completeness is updated if texture max level changes.
2111// GLES 3.0.4 section 3.8.13 Texture completeness
2112TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
2113{
2114 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2115 {
2116 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2117 // the base level.
2118 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2119 return;
2120 }
2121 if (IsOSX())
2122 {
2123 // Observed incorrect rendering on OSX.
2124 std::cout << "Test skipped on OSX." << std::endl;
2125 return;
2126 }
2127
2128 glActiveTexture(GL_TEXTURE0);
2129 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2130 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2131
2132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2134
2135 // A level that is initially unused.
2136 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2137 texDataGreen.data());
2138
2139 // One level that is initially used - only this level should affect completeness.
2140 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2141 texDataGreen.data());
2142
2143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2145
2146 EXPECT_GL_NO_ERROR();
2147
2148 drawQuad(mProgram, "position", 0.5f);
2149
2150 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2151
2152 // Switch the max level to level 1. The levels within the used range now have inconsistent
2153 // dimensions and the texture should be incomplete.
2154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2155
2156 EXPECT_GL_NO_ERROR();
2157
2158 drawQuad(mProgram, "position", 0.5f);
2159
2160 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2161}
2162
2163// Test that 3D texture completeness is updated if texture max level changes.
2164// GLES 3.0.4 section 3.8.13 Texture completeness
2165TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
2166{
2167 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2168 {
2169 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2170 // the base level.
2171 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2172 return;
2173 }
2174 if (IsOSX())
2175 {
2176 // Observed incorrect rendering on OSX.
2177 std::cout << "Test skipped on OSX." << std::endl;
2178 return;
2179 }
2180
2181 glActiveTexture(GL_TEXTURE0);
2182 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2183 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
2184
2185 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2186 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2187
2188 // A level that is initially unused.
2189 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2190 texDataGreen.data());
2191
2192 // One level that is initially used - only this level should affect completeness.
2193 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2194 texDataGreen.data());
2195
2196 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2197 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2198
2199 EXPECT_GL_NO_ERROR();
2200
2201 drawQuad(mProgram, "position", 0.5f);
2202
2203 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2204
2205 // Switch the max level to level 1. The levels within the used range now have inconsistent
2206 // dimensions and the texture should be incomplete.
2207 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2208
2209 EXPECT_GL_NO_ERROR();
2210
2211 drawQuad(mProgram, "position", 0.5f);
2212
2213 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2214}
2215
2216// Test that texture completeness is updated if texture base level changes.
2217// GLES 3.0.4 section 3.8.13 Texture completeness
2218TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2219{
2220 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2221 {
2222 // Intel was observed having wrong behavior after the texture is made incomplete by changing
2223 // the base level.
2224 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2225 return;
2226 }
2227
2228 glActiveTexture(GL_TEXTURE0);
2229 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2230 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2231
2232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2234
2235 // Two levels that are initially unused.
2236 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2237 texDataGreen.data());
2238 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2239 texDataGreen.data());
2240
2241 // One level that is initially used - only this level should affect completeness.
2242 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2243 texDataGreen.data());
2244
2245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2247
2248 EXPECT_GL_NO_ERROR();
2249
2250 drawQuad(mProgram, "position", 0.5f);
2251
2252 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2253
2254 // Switch the base level to level 1. The levels within the used range now have inconsistent
2255 // dimensions and the texture should be incomplete.
2256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2257
2258 EXPECT_GL_NO_ERROR();
2259
2260 drawQuad(mProgram, "position", 0.5f);
2261
2262 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2263}
2264
2265// Test that texture is not complete if base level is greater than max level.
2266// GLES 3.0.4 section 3.8.13 Texture completeness
2267TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2268{
2269 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2270 {
2271 // Intel Windows OpenGL driver crashes if the base level of a non-immutable texture is out
2272 // of range.
2273 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2274 return;
2275 }
2276
2277 glActiveTexture(GL_TEXTURE0);
2278 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2279
2280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2281 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2282
2283 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2284
2285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2287
2288 EXPECT_GL_NO_ERROR();
2289
2290 drawQuad(mProgram, "position", 0.5f);
2291
2292 // Texture should be incomplete.
2293 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2294}
2295
2296// Test that immutable texture base level and max level are clamped.
2297// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2298TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2299{
Olli Etuahoa314b612016-03-10 16:43:00 +02002300 glActiveTexture(GL_TEXTURE0);
2301 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2302
2303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2305
2306 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2307
2308 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2309
2310 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2311 // should be clamped to [base_level, levels - 1].
2312 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2313 // In the case of this test, those rules make the effective base level and max level 0.
2314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2316
2317 EXPECT_GL_NO_ERROR();
2318
2319 drawQuad(mProgram, "position", 0.5f);
2320
2321 // Texture should be complete.
2322 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2323}
2324
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002325// Test that changing base level works when it affects the format of the texture.
2326TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2327{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002328 if (IsNVIDIA() && IsOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002329 {
2330 // Observed rendering corruption on NVIDIA OpenGL.
2331 std::cout << "Test skipped on NVIDIA OpenGL." << std::endl;
2332 return;
2333 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002334 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002335 {
2336 // Observed incorrect rendering on Intel OpenGL.
2337 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2338 return;
2339 }
Corentin Wallezc7f59d02016-06-20 10:12:08 -04002340 if (IsAMD() && IsDesktopOpenGL())
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002341 {
2342 // Observed incorrect rendering on AMD OpenGL.
2343 std::cout << "Test skipped on AMD OpenGL." << std::endl;
2344 return;
2345 }
2346
2347 glActiveTexture(GL_TEXTURE0);
2348 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2349 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2350 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2351
2352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2354
2355 // RGBA8 level that's initially unused.
2356 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2357 texDataCyan.data());
2358
2359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2361
2362 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2363 // format. It reads green channel data from the green and alpha channels of texDataGreen
2364 // (this is a bit hacky but works).
2365 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2366
2367 EXPECT_GL_NO_ERROR();
2368
2369 drawQuad(mProgram, "position", 0.5f);
2370
2371 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2372
2373 // Switch the texture to use the cyan level 0 with the RGBA format.
2374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2376
2377 EXPECT_GL_NO_ERROR();
2378
2379 drawQuad(mProgram, "position", 0.5f);
2380
2381 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2382}
2383
Olli Etuahoa314b612016-03-10 16:43:00 +02002384// Test that setting a texture image works when base level is out of range.
2385TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2386{
2387 glActiveTexture(GL_TEXTURE0);
2388 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2389
2390 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2392
2393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2395
2396 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2397
2398 EXPECT_GL_NO_ERROR();
2399
2400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2401
2402 drawQuad(mProgram, "position", 0.5f);
2403
2404 // Texture should be complete.
2405 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002406}
2407
Jamie Madill2453dbc2015-07-14 11:35:42 -04002408// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG RBA->RGBA8, with 1.0
2409// in the alpha channel. This test covers a bug where redefining array textures with these formats does not work as
2410// expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002411TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002412{
2413 std::vector<GLubyte> pixelData;
2414 for (size_t count = 0; count < 5000; count++)
2415 {
2416 pixelData.push_back(0u);
2417 pixelData.push_back(255u);
2418 pixelData.push_back(0u);
2419 }
2420
2421 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002422 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002423 glUniform1i(mTextureArrayLocation, 0);
2424
2425 // The first draw worked correctly.
2426 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);
2427
2428 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2429 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2430 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2431 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002432 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002433 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002434
2435 // The dimension of the respecification must match the original exactly to trigger the bug.
2436 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 +02002437 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002438 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002439
2440 ASSERT_GL_NO_ERROR();
2441}
2442
Olli Etuaho1a679902016-01-14 12:21:47 +02002443// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2444// This test is needed especially to confirm that sampler registers get assigned correctly on
2445// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2446TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2447{
2448 glActiveTexture(GL_TEXTURE0);
2449 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2450 GLubyte texData[4];
2451 texData[0] = 0;
2452 texData[1] = 60;
2453 texData[2] = 0;
2454 texData[3] = 255;
2455 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2456
2457 glActiveTexture(GL_TEXTURE1);
2458 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2459 GLfloat depthTexData[1];
2460 depthTexData[0] = 0.5f;
2461 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2462 depthTexData);
2463
2464 glUseProgram(mProgram);
2465 glUniform1f(mDepthRefUniformLocation, 0.3f);
2466 glUniform1i(mTexture3DUniformLocation, 0);
2467 glUniform1i(mTextureShadowUniformLocation, 1);
2468
2469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2470 drawQuad(mProgram, "position", 0.5f);
2471 EXPECT_GL_NO_ERROR();
2472 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2473 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2474
2475 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2476 drawQuad(mProgram, "position", 0.5f);
2477 EXPECT_GL_NO_ERROR();
2478 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2479 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2480}
2481
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002482// Test multiple different sampler types in the same shader.
2483// This test makes sure that even if sampler / texture registers get grouped together based on type
2484// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2485// still has the right register index information for each ESSL sampler.
2486// The tested ESSL samplers have the following types in D3D11 HLSL:
2487// sampler2D: Texture2D + SamplerState
2488// samplerCube: TextureCube + SamplerState
2489// sampler2DShadow: Texture2D + SamplerComparisonState
2490// samplerCubeShadow: TextureCube + SamplerComparisonState
2491TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2492{
2493 glActiveTexture(GL_TEXTURE0);
2494 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2495 GLubyte texData[4];
2496 texData[0] = 0;
2497 texData[1] = 0;
2498 texData[2] = 120;
2499 texData[3] = 255;
2500 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2501
2502 glActiveTexture(GL_TEXTURE1);
2503 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2504 texData[0] = 0;
2505 texData[1] = 90;
2506 texData[2] = 0;
2507 texData[3] = 255;
2508 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2509 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2510 texData);
2511
2512 glActiveTexture(GL_TEXTURE2);
2513 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2515 GLfloat depthTexData[1];
2516 depthTexData[0] = 0.5f;
2517 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2518 depthTexData);
2519
2520 glActiveTexture(GL_TEXTURE3);
2521 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2522 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2523 depthTexData[0] = 0.2f;
2524 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2525 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2526 depthTexData);
2527
2528 EXPECT_GL_NO_ERROR();
2529
2530 glUseProgram(mProgram);
2531 glUniform1f(mDepthRefUniformLocation, 0.3f);
2532 glUniform1i(mTexture2DUniformLocation, 0);
2533 glUniform1i(mTextureCubeUniformLocation, 1);
2534 glUniform1i(mTexture2DShadowUniformLocation, 2);
2535 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2536
2537 drawQuad(mProgram, "position", 0.5f);
2538 EXPECT_GL_NO_ERROR();
2539 // The shader writes:
2540 // <texture 2d color> +
2541 // <cube map color> +
2542 // 0.25 * <comparison result (1.0)> +
2543 // 0.125 * <comparison result (0.0)>
2544 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2545}
2546
Olli Etuahobce743a2016-01-15 17:18:28 +02002547// Test different base levels on textures accessed through the same sampler array.
2548// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2549TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2550{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002551 if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
Olli Etuahobce743a2016-01-15 17:18:28 +02002552 {
2553 std::cout << "Test skipped on Intel and AMD D3D." << std::endl;
2554 return;
2555 }
2556 glActiveTexture(GL_TEXTURE0);
2557 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2558 GLsizei size = 64;
2559 for (GLint level = 0; level < 7; ++level)
2560 {
2561 ASSERT_LT(0, size);
2562 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2563 nullptr);
2564 size = size / 2;
2565 }
2566 ASSERT_EQ(0, size);
2567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2568
2569 glActiveTexture(GL_TEXTURE1);
2570 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2571 size = 128;
2572 for (GLint level = 0; level < 8; ++level)
2573 {
2574 ASSERT_LT(0, size);
2575 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2576 nullptr);
2577 size = size / 2;
2578 }
2579 ASSERT_EQ(0, size);
2580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2581 EXPECT_GL_NO_ERROR();
2582
2583 glUseProgram(mProgram);
2584 glUniform1i(mTexture0Location, 0);
2585 glUniform1i(mTexture1Location, 1);
2586
2587 drawQuad(mProgram, "position", 0.5f);
2588 EXPECT_GL_NO_ERROR();
2589 // Red channel: width of level 1 of texture A: 32.
2590 // Green channel: width of level 3 of texture B: 16.
2591 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2592}
2593
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002594// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2595// ES 3.0.4 table 3.24
2596TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2597{
2598 glActiveTexture(GL_TEXTURE0);
2599 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2600 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2601 EXPECT_GL_NO_ERROR();
2602
2603 drawQuad(mProgram, "position", 0.5f);
2604
2605 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2606}
2607
2608// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2609// ES 3.0.4 table 3.24
2610TEST_P(Texture2DTestES3, TextureLuminanceImplicitAlpha1)
2611{
2612 glActiveTexture(GL_TEXTURE0);
2613 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2615 EXPECT_GL_NO_ERROR();
2616
2617 drawQuad(mProgram, "position", 0.5f);
2618
2619 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2620}
2621
2622// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2623// ES 3.0.4 table 3.24
2624TEST_P(Texture2DTestES3, TextureLuminance32ImplicitAlpha1)
2625{
2626 if (extensionEnabled("GL_OES_texture_float"))
2627 {
2628 glActiveTexture(GL_TEXTURE0);
2629 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2630 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2631 EXPECT_GL_NO_ERROR();
2632
2633 drawQuad(mProgram, "position", 0.5f);
2634
2635 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2636 }
2637}
2638
2639// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2640// ES 3.0.4 table 3.24
2641TEST_P(Texture2DTestES3, TextureLuminance16ImplicitAlpha1)
2642{
2643 if (extensionEnabled("GL_OES_texture_half_float"))
2644 {
Yuly Novikovafcec832016-06-21 22:19:51 -04002645 if (IsNVIDIA() && IsOpenGLES())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002646 {
2647 std::cout << "Test skipped on NVIDIA" << std::endl;
2648 return;
2649 }
Yuly Novikovafcec832016-06-21 22:19:51 -04002650 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2651 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2652 {
2653 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2654 return;
2655 }
2656
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002657 glActiveTexture(GL_TEXTURE0);
2658 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2659 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES,
2660 nullptr);
2661 EXPECT_GL_NO_ERROR();
2662
2663 drawQuad(mProgram, "position", 0.5f);
2664
2665 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2666 }
2667}
2668
2669// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2670// ES 3.0.4 table 3.24
2671TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2672{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002673 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002674 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002675 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002676 return;
2677 }
2678 glActiveTexture(GL_TEXTURE0);
2679 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2680 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2683 EXPECT_GL_NO_ERROR();
2684
2685 drawQuad(mProgram, "position", 0.5f);
2686
2687 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2688}
2689
2690// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2691// ES 3.0.4 table 3.24
2692TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2693{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002694 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002695 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002696 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002697 return;
2698 }
2699 glActiveTexture(GL_TEXTURE0);
2700 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2701
2702 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2703 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2704 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2705 EXPECT_GL_NO_ERROR();
2706
2707 drawQuad(mProgram, "position", 0.5f);
2708
2709 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2710}
2711
2712// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2713// ES 3.0.4 table 3.24
2714TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2715{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002716 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002717 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002718 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002719 return;
2720 }
2721 glActiveTexture(GL_TEXTURE0);
2722 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2723 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2724 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2725 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2726 EXPECT_GL_NO_ERROR();
2727
2728 drawQuad(mProgram, "position", 0.5f);
2729
2730 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2731}
2732
2733// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2734// ES 3.0.4 table 3.24
2735TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2736{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002737 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002738 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002739 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002740 return;
2741 }
2742 glActiveTexture(GL_TEXTURE0);
2743 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2744 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2745 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2747 EXPECT_GL_NO_ERROR();
2748
2749 drawQuad(mProgram, "position", 0.5f);
2750
2751 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2752}
2753
2754// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2755// ES 3.0.4 table 3.24
2756TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2757{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002758 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002759 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002760 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002761 return;
2762 }
2763 glActiveTexture(GL_TEXTURE0);
2764 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2765 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2766 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2767 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2768 EXPECT_GL_NO_ERROR();
2769
2770 drawQuad(mProgram, "position", 0.5f);
2771
2772 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2773}
2774
2775// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2776// ES 3.0.4 table 3.24
2777TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2778{
Jamie Madill518b9fa2016-03-02 11:26:02 -05002779 if (IsIntel())
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002780 {
Jamie Madill518b9fa2016-03-02 11:26:02 -05002781 std::cout << "Test disabled on Intel." << std::endl;
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002782 return;
2783 }
2784 glActiveTexture(GL_TEXTURE0);
2785 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2786 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2788 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2789 EXPECT_GL_NO_ERROR();
2790
2791 drawQuad(mProgram, "position", 0.5f);
2792
2793 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2794}
2795
2796// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2797// ES 3.0.4 table 3.24
2798TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2799{
2800 glActiveTexture(GL_TEXTURE0);
2801 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2802 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2803 EXPECT_GL_NO_ERROR();
2804
2805 drawQuad(mProgram, "position", 0.5f);
2806
2807 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2808}
2809
2810// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2811// ES 3.0.4 table 3.24
2812TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2813{
2814 glActiveTexture(GL_TEXTURE0);
2815 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2816 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2817 nullptr);
2818 EXPECT_GL_NO_ERROR();
2819
2820 drawQuad(mProgram, "position", 0.5f);
2821
2822 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2823}
2824
2825// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2826// ES 3.0.4 table 3.24
2827TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2828{
Jamie Madillbb1db482017-01-10 10:48:32 -05002829 if (IsOSX() && IsIntel() && IsOpenGL())
2830 {
2831 // Seems to fail on OSX 10.12 Intel.
2832 std::cout << "Test skipped on OSX Intel." << std::endl;
2833 return;
2834 }
2835
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002836 glActiveTexture(GL_TEXTURE0);
2837 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2838 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2839 EXPECT_GL_NO_ERROR();
2840
2841 drawQuad(mProgram, "position", 0.5f);
2842
2843 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2844}
2845
2846// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2847// ES 3.0.4 table 3.24
2848TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2849{
Jamie Madillbb1db482017-01-10 10:48:32 -05002850 if (IsIntel() && IsOpenGL() && (IsLinux() || IsOSX()))
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002851 {
2852 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
Jamie Madillbb1db482017-01-10 10:48:32 -05002853 // Also seems to fail on OSX 10.12 Intel.
2854 std::cout << "Test disabled on Linux and OSX Intel OpenGL." << std::endl;
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002855 return;
2856 }
2857
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002858 glActiveTexture(GL_TEXTURE0);
2859 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2860 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2861 EXPECT_GL_NO_ERROR();
2862
2863 drawQuad(mProgram, "position", 0.5f);
2864
2865 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2866}
2867
Olli Etuaho96963162016-03-21 11:54:33 +02002868// Use a sampler in a uniform struct.
2869TEST_P(SamplerInStructTest, SamplerInStruct)
2870{
2871 runSamplerInStructTest();
2872}
2873
2874// Use a sampler in a uniform struct that's passed as a function parameter.
2875TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2876{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002877 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2878 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2879 {
2880 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2881 return;
2882 }
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002883
2884 if (IsWindows() && IsIntel() && IsOpenGL())
2885 {
2886 std::cout << "Test skipped on Windows OpenGL on Intel." << std::endl;
2887 return;
2888 }
2889
Olli Etuaho96963162016-03-21 11:54:33 +02002890 runSamplerInStructTest();
2891}
2892
2893// Use a sampler in a uniform struct array with a struct from the array passed as a function
2894// parameter.
2895TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2896{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002897 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2898 {
2899 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2900 return;
2901 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002902 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2903 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2904 {
2905 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2906 return;
2907 }
Olli Etuaho96963162016-03-21 11:54:33 +02002908 runSamplerInStructTest();
2909}
2910
2911// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2912// parameter.
2913TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2914{
Olli Etuahoa1c917f2016-04-06 13:50:03 +03002915 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
2916 {
2917 std::cout << "Test skipped on Intel OpenGL." << std::endl;
2918 return;
2919 }
Yuly Novikovad6c0452016-06-24 22:24:37 -04002920 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
2921 if (IsAndroid() && IsAdreno() && IsOpenGLES())
2922 {
2923 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
2924 return;
2925 }
Olli Etuaho96963162016-03-21 11:54:33 +02002926 runSamplerInStructTest();
2927}
2928
2929// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2930// similarly named uniform.
2931TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2932{
2933 runSamplerInStructTest();
2934}
2935
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002936class TextureLimitsTest : public ANGLETest
2937{
2938 protected:
2939 struct RGBA8
2940 {
2941 uint8_t R, G, B, A;
2942 };
2943
2944 TextureLimitsTest()
2945 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2946 {
2947 setWindowWidth(128);
2948 setWindowHeight(128);
2949 setConfigRedBits(8);
2950 setConfigGreenBits(8);
2951 setConfigBlueBits(8);
2952 setConfigAlphaBits(8);
2953 }
2954
2955 ~TextureLimitsTest()
2956 {
2957 if (mProgram != 0)
2958 {
2959 glDeleteProgram(mProgram);
2960 mProgram = 0;
2961
2962 if (!mTextures.empty())
2963 {
2964 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2965 }
2966 }
2967 }
2968
2969 void SetUp() override
2970 {
2971 ANGLETest::SetUp();
2972
2973 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2974 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2975 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2976
2977 ASSERT_GL_NO_ERROR();
2978 }
2979
2980 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2981 GLint vertexTextureCount,
2982 GLint vertexActiveTextureCount,
2983 const std::string &fragPrefix,
2984 GLint fragmentTextureCount,
2985 GLint fragmentActiveTextureCount)
2986 {
2987 std::stringstream vertexShaderStr;
2988 vertexShaderStr << "attribute vec2 position;\n"
2989 << "varying vec4 color;\n"
2990 << "varying vec2 texCoord;\n";
2991
2992 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2993 {
2994 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2995 }
2996
2997 vertexShaderStr << "void main() {\n"
2998 << " gl_Position = vec4(position, 0, 1);\n"
2999 << " texCoord = (position * 0.5) + 0.5;\n"
3000 << " color = vec4(0);\n";
3001
3002 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
3003 {
3004 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
3005 << ", texCoord);\n";
3006 }
3007
3008 vertexShaderStr << "}";
3009
3010 std::stringstream fragmentShaderStr;
3011 fragmentShaderStr << "varying mediump vec4 color;\n"
3012 << "varying mediump vec2 texCoord;\n";
3013
3014 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
3015 {
3016 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
3017 }
3018
3019 fragmentShaderStr << "void main() {\n"
3020 << " gl_FragColor = color;\n";
3021
3022 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
3023 {
3024 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
3025 << ", texCoord);\n";
3026 }
3027
3028 fragmentShaderStr << "}";
3029
3030 const std::string &vertexShaderSource = vertexShaderStr.str();
3031 const std::string &fragmentShaderSource = fragmentShaderStr.str();
3032
3033 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
3034 }
3035
3036 RGBA8 getPixel(GLint texIndex)
3037 {
3038 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
3039 0, 255u};
3040 return pixel;
3041 }
3042
3043 void initTextures(GLint tex2DCount, GLint texCubeCount)
3044 {
3045 GLint totalCount = tex2DCount + texCubeCount;
3046 mTextures.assign(totalCount, 0);
3047 glGenTextures(totalCount, &mTextures[0]);
3048 ASSERT_GL_NO_ERROR();
3049
3050 std::vector<RGBA8> texData(16 * 16);
3051
3052 GLint texIndex = 0;
3053 for (; texIndex < tex2DCount; ++texIndex)
3054 {
3055 texData.assign(texData.size(), getPixel(texIndex));
3056 glActiveTexture(GL_TEXTURE0 + texIndex);
3057 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
3058 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3059 &texData[0]);
3060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3063 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3064 }
3065
3066 ASSERT_GL_NO_ERROR();
3067
3068 for (; texIndex < texCubeCount; ++texIndex)
3069 {
3070 texData.assign(texData.size(), getPixel(texIndex));
3071 glActiveTexture(GL_TEXTURE0 + texIndex);
3072 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
3073 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3074 GL_UNSIGNED_BYTE, &texData[0]);
3075 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3076 GL_UNSIGNED_BYTE, &texData[0]);
3077 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3078 GL_UNSIGNED_BYTE, &texData[0]);
3079 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3080 GL_UNSIGNED_BYTE, &texData[0]);
3081 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3082 GL_UNSIGNED_BYTE, &texData[0]);
3083 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
3084 GL_UNSIGNED_BYTE, &texData[0]);
3085 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3086 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3087 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3088 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3089 }
3090
3091 ASSERT_GL_NO_ERROR();
3092 }
3093
3094 void testWithTextures(GLint vertexTextureCount,
3095 const std::string &vertexTexturePrefix,
3096 GLint fragmentTextureCount,
3097 const std::string &fragmentTexturePrefix)
3098 {
3099 // Generate textures
3100 initTextures(vertexTextureCount + fragmentTextureCount, 0);
3101
3102 glUseProgram(mProgram);
3103 RGBA8 expectedSum = {0};
3104 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
3105 {
3106 std::stringstream uniformNameStr;
3107 uniformNameStr << vertexTexturePrefix << texIndex;
3108 const std::string &uniformName = uniformNameStr.str();
3109 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3110 ASSERT_NE(-1, location);
3111
3112 glUniform1i(location, texIndex);
3113 RGBA8 contribution = getPixel(texIndex);
3114 expectedSum.R += contribution.R;
3115 expectedSum.G += contribution.G;
3116 }
3117
3118 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
3119 {
3120 std::stringstream uniformNameStr;
3121 uniformNameStr << fragmentTexturePrefix << texIndex;
3122 const std::string &uniformName = uniformNameStr.str();
3123 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
3124 ASSERT_NE(-1, location);
3125
3126 glUniform1i(location, texIndex + vertexTextureCount);
3127 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
3128 expectedSum.R += contribution.R;
3129 expectedSum.G += contribution.G;
3130 }
3131
3132 ASSERT_GE(256u, expectedSum.G);
3133
3134 drawQuad(mProgram, "position", 0.5f);
3135 ASSERT_GL_NO_ERROR();
3136 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
3137 }
3138
3139 GLuint mProgram;
3140 std::vector<GLuint> mTextures;
3141 GLint mMaxVertexTextures;
3142 GLint mMaxFragmentTextures;
3143 GLint mMaxCombinedTextures;
3144};
3145
3146// Test rendering with the maximum vertex texture units.
3147TEST_P(TextureLimitsTest, MaxVertexTextures)
3148{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003149 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003150 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003151 {
3152 std::cout << "Test skipped on Intel." << std::endl;
3153 return;
3154 }
3155
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003156 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
3157 ASSERT_NE(0u, mProgram);
3158 ASSERT_GL_NO_ERROR();
3159
3160 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3161}
3162
3163// Test rendering with the maximum fragment texture units.
3164TEST_P(TextureLimitsTest, MaxFragmentTextures)
3165{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003166 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003167 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003168 {
3169 std::cout << "Test skipped on Intel." << std::endl;
3170 return;
3171 }
3172
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003173 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
3174 ASSERT_NE(0u, mProgram);
3175 ASSERT_GL_NO_ERROR();
3176
3177 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
3178}
3179
3180// Test rendering with maximum combined texture units.
3181TEST_P(TextureLimitsTest, MaxCombinedTextures)
3182{
Jamie Madill412f17d2015-09-25 08:43:54 -04003183 // TODO(jmadill): Investigate workaround.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003184 if (IsIntel() && GetParam() == ES2_OPENGL())
Jamie Madill412f17d2015-09-25 08:43:54 -04003185 {
3186 std::cout << "Test skipped on Intel." << std::endl;
3187 return;
3188 }
3189
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003190 GLint vertexTextures = mMaxVertexTextures;
3191
3192 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
3193 {
3194 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
3195 }
3196
3197 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
3198 mMaxFragmentTextures, mMaxFragmentTextures);
3199 ASSERT_NE(0u, mProgram);
3200 ASSERT_GL_NO_ERROR();
3201
3202 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
3203}
3204
3205// Negative test for exceeding the number of vertex textures
3206TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
3207{
3208 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
3209 0);
3210 ASSERT_EQ(0u, mProgram);
3211}
3212
3213// Negative test for exceeding the number of fragment textures
3214TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
3215{
3216 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
3217 mMaxFragmentTextures + 1);
3218 ASSERT_EQ(0u, mProgram);
3219}
3220
3221// Test active vertex textures under the limit, but excessive textures specified.
3222TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
3223{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003224 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003225 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003226 {
3227 std::cout << "Test skipped on Intel." << std::endl;
3228 return;
3229 }
3230
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003231 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
3232 ASSERT_NE(0u, mProgram);
3233 ASSERT_GL_NO_ERROR();
3234
3235 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
3236}
3237
3238// Test active fragment textures under the limit, but excessive textures specified.
3239TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
3240{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003241 // TODO(jmadill): Figure out why this fails on Intel.
Jamie Madill518b9fa2016-03-02 11:26:02 -05003242 if (IsIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Jamie Madill1ea9aaa2015-10-07 11:13:55 -04003243 {
3244 std::cout << "Test skipped on Intel." << std::endl;
3245 return;
3246 }
3247
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003248 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
3249 mMaxFragmentTextures);
3250 ASSERT_NE(0u, mProgram);
3251 ASSERT_GL_NO_ERROR();
3252
3253 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
3254}
3255
3256// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02003257// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04003258TEST_P(TextureLimitsTest, TextureTypeConflict)
3259{
3260 const std::string &vertexShader =
3261 "attribute vec2 position;\n"
3262 "varying float color;\n"
3263 "uniform sampler2D tex2D;\n"
3264 "uniform samplerCube texCube;\n"
3265 "void main() {\n"
3266 " gl_Position = vec4(position, 0, 1);\n"
3267 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3268 " color = texture2D(tex2D, texCoord).x;\n"
3269 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3270 "}";
3271 const std::string &fragmentShader =
3272 "varying mediump float color;\n"
3273 "void main() {\n"
3274 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3275 "}";
3276
3277 mProgram = CompileProgram(vertexShader, fragmentShader);
3278 ASSERT_NE(0u, mProgram);
3279
3280 initTextures(1, 0);
3281
3282 glUseProgram(mProgram);
3283 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3284 ASSERT_NE(-1, tex2DLocation);
3285 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3286 ASSERT_NE(-1, texCubeLocation);
3287
3288 glUniform1i(tex2DLocation, 0);
3289 glUniform1i(texCubeLocation, 0);
3290 ASSERT_GL_NO_ERROR();
3291
3292 drawQuad(mProgram, "position", 0.5f);
3293 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3294}
3295
Vincent Lang25ab4512016-05-13 18:13:59 +02003296class Texture2DNorm16TestES3 : public Texture2DTestES3
3297{
3298 protected:
3299 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3300
3301 void SetUp() override
3302 {
3303 Texture2DTestES3::SetUp();
3304
3305 glActiveTexture(GL_TEXTURE0);
3306 glGenTextures(3, mTextures);
3307 glGenFramebuffers(1, &mFBO);
3308 glGenRenderbuffers(1, &mRenderbuffer);
3309
3310 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3311 {
3312 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3315 }
3316
3317 glBindTexture(GL_TEXTURE_2D, 0);
3318
3319 ASSERT_GL_NO_ERROR();
3320 }
3321
3322 void TearDown() override
3323 {
3324 glDeleteTextures(3, mTextures);
3325 glDeleteFramebuffers(1, &mFBO);
3326 glDeleteRenderbuffers(1, &mRenderbuffer);
3327
3328 Texture2DTestES3::TearDown();
3329 }
3330
3331 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3332 {
Geoff Langf607c602016-09-21 11:46:48 -04003333 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3334 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003335
3336 setUpProgram();
3337
3338 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3339 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3340 0);
3341
3342 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3343 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3344
3345 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003346 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003347
3348 EXPECT_GL_NO_ERROR();
3349
3350 drawQuad(mProgram, "position", 0.5f);
3351
Geoff Langf607c602016-09-21 11:46:48 -04003352 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003353
Geoff Langf607c602016-09-21 11:46:48 -04003354 EXPECT_PIXEL_COLOR_EQ(
3355 0, 0, SliceFormatColor(
3356 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003357
3358 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3359
3360 ASSERT_GL_NO_ERROR();
3361 }
3362
3363 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3364 {
3365 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003366 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003367
3368 setUpProgram();
3369
3370 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3371 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3372
3373 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3374 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3375 0);
3376
3377 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003378 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003379
3380 EXPECT_GL_NO_ERROR();
3381
3382 drawQuad(mProgram, "position", 0.5f);
3383
Geoff Langf607c602016-09-21 11:46:48 -04003384 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
3385 EXPECT_PIXEL_COLOR_EQ(
3386 0, 0, SliceFormatColor(
3387 format, GLColor(expectedValue, expectedValue, expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003388
3389 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3390 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3391 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3392 mRenderbuffer);
3393 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3394 EXPECT_GL_NO_ERROR();
3395
3396 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3397 glClear(GL_COLOR_BUFFER_BIT);
3398
3399 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3400
Geoff Langf607c602016-09-21 11:46:48 -04003401 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003402
3403 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3404
3405 ASSERT_GL_NO_ERROR();
3406 }
3407
3408 GLuint mTextures[3];
3409 GLuint mFBO;
3410 GLuint mRenderbuffer;
3411};
3412
3413// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3414TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3415{
3416 if (!extensionEnabled("GL_EXT_texture_norm16"))
3417 {
3418 std::cout << "Test skipped due to missing GL_EXT_texture_norm16." << std::endl;
3419 return;
3420 }
3421
3422 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3423 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3424 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3425 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3426 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3427 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3428 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3429 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3430
3431 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3432 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3433 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3434}
3435
Olli Etuaho95faa232016-06-07 14:01:53 -07003436// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3437// GLES 3.0.4 section 3.8.3.
3438TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3439{
Corentin Wallezc7f59d02016-06-20 10:12:08 -04003440 if (IsIntel() && IsDesktopOpenGL())
Olli Etuaho95faa232016-06-07 14:01:53 -07003441 {
3442 std::cout << "Test skipped on Intel OpenGL." << std::endl;
3443 return;
3444 }
Yuly Novikov3c754192016-06-27 19:36:41 -04003445 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
3446 if (IsAndroid() && IsAdreno() && IsOpenGLES())
3447 {
3448 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
3449 return;
3450 }
Olli Etuaho95faa232016-06-07 14:01:53 -07003451
3452 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3454 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3455 ASSERT_GL_NO_ERROR();
3456
3457 // SKIP_IMAGES should not have an effect on uploading 2D textures
3458 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3459 ASSERT_GL_NO_ERROR();
3460
3461 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3462
3463 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3464 pixelsGreen.data());
3465 ASSERT_GL_NO_ERROR();
3466
3467 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3468 pixelsGreen.data());
3469 ASSERT_GL_NO_ERROR();
3470
3471 glUseProgram(mProgram);
3472 drawQuad(mProgram, "position", 0.5f);
3473 ASSERT_GL_NO_ERROR();
3474
3475 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3476}
3477
Olli Etuaho989cac32016-06-08 16:18:49 -07003478// Test that skip defined in unpack parameters is taken into account when determining whether
3479// unpacking source extends outside unpack buffer bounds.
3480TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3481{
3482 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3483 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3485 ASSERT_GL_NO_ERROR();
3486
3487 GLBuffer buf;
3488 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3489 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3490 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3491 GL_DYNAMIC_COPY);
3492 ASSERT_GL_NO_ERROR();
3493
3494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3495 ASSERT_GL_NO_ERROR();
3496
3497 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3498 ASSERT_GL_NO_ERROR();
3499
3500 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3501 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3502
3503 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3504 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3505 ASSERT_GL_NO_ERROR();
3506
3507 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3508 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3509}
3510
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003511// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3512TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3513{
3514 if (IsD3D11())
3515 {
3516 std::cout << "Test skipped on D3D." << std::endl;
3517 return;
3518 }
3519 if (IsOSX() && IsAMD())
3520 {
3521 // Incorrect rendering results seen on OSX AMD.
3522 std::cout << "Test skipped on OSX AMD." << std::endl;
3523 return;
3524 }
3525
3526 const GLuint width = 8u;
3527 const GLuint height = 8u;
3528 const GLuint unpackRowLength = 5u;
3529 const GLuint unpackSkipPixels = 1u;
3530
3531 setWindowWidth(width);
3532 setWindowHeight(height);
3533
3534 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3537 ASSERT_GL_NO_ERROR();
3538
3539 GLBuffer buf;
3540 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3541 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3542 GLColor::green);
3543
3544 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3545 {
3546 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3547 }
3548
3549 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3550 GL_DYNAMIC_COPY);
3551 ASSERT_GL_NO_ERROR();
3552
3553 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3554 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3555 ASSERT_GL_NO_ERROR();
3556
3557 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3558 ASSERT_GL_NO_ERROR();
3559
3560 glUseProgram(mProgram);
3561 drawQuad(mProgram, "position", 0.5f);
3562 ASSERT_GL_NO_ERROR();
3563
3564 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3565 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3566 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3567 actual.data());
3568 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3569 EXPECT_EQ(expected, actual);
3570}
3571
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003572template <typename T>
3573T UNorm(double value)
3574{
3575 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3576}
3577
3578// Test rendering a depth texture with mipmaps.
3579TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3580{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003581 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3582 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3583 // http://anglebugs.com/1706
3584 if (IsIntel() && IsWindows())
Corentin Walleze731d8a2016-09-07 10:56:25 -04003585 {
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003586 std::cout << "Test skipped on Win Intel." << std::endl;
Corentin Walleze731d8a2016-09-07 10:56:25 -04003587 return;
3588 }
3589
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003590 const int size = getWindowWidth();
3591
3592 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003593 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003594
3595 glActiveTexture(GL_TEXTURE0);
3596 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3597 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3601 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3602 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3603 ASSERT_GL_NO_ERROR();
3604
3605 glUseProgram(mProgram);
3606 glUniform1i(mTexture2DUniformLocation, 0);
3607
3608 std::vector<unsigned char> expected;
3609
3610 for (int level = 0; level < levels; ++level)
3611 {
3612 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3613 expected.push_back(UNorm<unsigned char>(value));
3614
3615 int levelDim = dim(level);
3616
3617 ASSERT_GT(levelDim, 0);
3618
3619 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3620 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3621 GL_UNSIGNED_INT, initData.data());
3622 }
3623 ASSERT_GL_NO_ERROR();
3624
3625 for (int level = 0; level < levels; ++level)
3626 {
3627 glViewport(0, 0, dim(level), dim(level));
3628 drawQuad(mProgram, "position", 0.5f);
3629 GLColor actual = ReadColor(0, 0);
3630 EXPECT_NEAR(expected[level], actual.R, 10u);
3631 }
3632
3633 ASSERT_GL_NO_ERROR();
3634}
3635
Jamie Madill7ffdda92016-09-08 13:26:51 -04003636// Tests unpacking into the unsized GL_ALPHA format.
3637TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3638{
3639 // TODO(jmadill): Figure out why this fails on OSX.
3640 ANGLE_SKIP_TEST_IF(IsOSX());
3641
3642 // Initialize the texure.
3643 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3644 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3645 GL_UNSIGNED_BYTE, nullptr);
3646 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3647 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3648
3649 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3650
3651 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003652 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003653 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3654 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3655 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3656 GL_STATIC_DRAW);
3657
3658 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3659 GL_UNSIGNED_BYTE, nullptr);
3660
3661 // Clear to a weird color to make sure we're drawing something.
3662 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3663 glClear(GL_COLOR_BUFFER_BIT);
3664
3665 // Draw with the alpha texture and verify.
3666 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003667
3668 ASSERT_GL_NO_ERROR();
3669 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3670}
3671
Jamie Madill2e600342016-09-19 13:56:40 -04003672// Ensure stale unpack data doesn't propagate in D3D11.
3673TEST_P(Texture2DTestES3, StaleUnpackData)
3674{
3675 // Init unpack buffer.
3676 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3677 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3678
3679 GLBuffer unpackBuffer;
3680 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3681 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3682 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3683 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3684
3685 // Create from unpack buffer.
3686 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3687 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3688 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3691
3692 drawQuad(mProgram, "position", 0.5f);
3693
3694 ASSERT_GL_NO_ERROR();
3695 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3696
3697 // Fill unpack with green, recreating buffer.
3698 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3699 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3700 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3701
3702 // Reinit texture with green.
3703 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3704 GL_UNSIGNED_BYTE, nullptr);
3705
3706 drawQuad(mProgram, "position", 0.5f);
3707
3708 ASSERT_GL_NO_ERROR();
3709 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3710}
3711
Jamie Madillf097e232016-11-05 00:44:15 -04003712// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3713// being properly checked, and the texture storage of the previous texture format was persisting.
3714// This would result in an ASSERT in debug and incorrect rendering in release.
3715// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3716TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3717{
3718 GLTexture tex;
3719 glBindTexture(GL_TEXTURE_3D, tex.get());
3720 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3721
3722 GLFramebuffer framebuffer;
3723 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3724 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3725
3726 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3727
3728 std::vector<uint8_t> pixelData(100, 0);
3729
3730 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3731 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3732 pixelData.data());
3733
3734 ASSERT_GL_NO_ERROR();
3735}
3736
Corentin Wallezd2627992017-04-28 17:17:03 -04003737// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3738TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3739{
3740 // 2D tests
3741 {
3742 GLTexture tex;
3743 glBindTexture(GL_TEXTURE_2D, tex.get());
3744
3745 GLBuffer pbo;
3746 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3747
3748 // Test OOB
3749 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3751 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3752
3753 // Test OOB
3754 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3755 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3756 ASSERT_GL_NO_ERROR();
3757 }
3758
3759 // 3D tests
3760 {
3761 GLTexture tex;
3762 glBindTexture(GL_TEXTURE_3D, tex.get());
3763
3764 GLBuffer pbo;
3765 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3766
3767 // Test OOB
3768 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3769 GL_STATIC_DRAW);
3770 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3771 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3772
3773 // Test OOB
3774 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3775 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3776 ASSERT_GL_NO_ERROR();
3777 }
3778}
3779
Jamie Madill3ed60422017-09-07 11:32:52 -04003780// Tests behaviour with a single texture and multiple sampler objects.
3781TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3782{
3783 GLint maxTextureUnits = 0;
3784 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3785 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3786
3787 constexpr int kSize = 16;
3788
3789 // Make a single-level texture, fill it with red.
3790 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3791 GLTexture tex;
3792 glBindTexture(GL_TEXTURE_2D, tex);
3793 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3794 redColors.data());
3795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3796 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3797
3798 // Simple sanity check.
3799 draw2DTexturedQuad(0.5f, 1.0f, true);
3800 ASSERT_GL_NO_ERROR();
3801 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3802
3803 // Bind texture to unit 1 with a sampler object making it incomplete.
3804 GLSampler sampler;
3805 glBindSampler(0, sampler);
3806 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3807 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3808
3809 // Make a mipmap texture, fill it with blue.
3810 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3811 GLTexture mipmapTex;
3812 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3813 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3814 blueColors.data());
3815 glGenerateMipmap(GL_TEXTURE_2D);
3816
3817 // Draw with the sampler, expect blue.
3818 draw2DTexturedQuad(0.5f, 1.0f, true);
3819 ASSERT_GL_NO_ERROR();
3820 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3821
3822 // Simple multitexturing program.
3823 const std::string vs =
3824 "#version 300 es\n"
3825 "in vec2 position;\n"
3826 "out vec2 texCoord;\n"
3827 "void main()\n"
3828 "{\n"
3829 " gl_Position = vec4(position, 0, 1);\n"
3830 " texCoord = position * 0.5 + vec2(0.5);\n"
3831 "}";
3832 const std::string fs =
3833 "#version 300 es\n"
3834 "precision mediump float;\n"
3835 "in vec2 texCoord;\n"
3836 "uniform sampler2D tex1;\n"
3837 "uniform sampler2D tex2;\n"
3838 "uniform sampler2D tex3;\n"
3839 "uniform sampler2D tex4;\n"
3840 "out vec4 color;\n"
3841 "void main()\n"
3842 "{\n"
3843 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3844 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3845 "}";
3846
3847 ANGLE_GL_PROGRAM(program, vs, fs);
3848
3849 std::array<GLint, 4> texLocations = {
3850 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3851 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3852 for (GLint location : texLocations)
3853 {
3854 ASSERT_NE(-1, location);
3855 }
3856
3857 // Init the uniform data.
3858 glUseProgram(program);
3859 for (GLint location = 0; location < 4; ++location)
3860 {
3861 glUniform1i(texLocations[location], location);
3862 }
3863
3864 // Initialize four samplers
3865 GLSampler samplers[4];
3866
3867 // 0: non-mipped.
3868 glBindSampler(0, samplers[0]);
3869 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3870 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3871
3872 // 1: mipped.
3873 glBindSampler(1, samplers[1]);
3874 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3875 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3876
3877 // 2: non-mipped.
3878 glBindSampler(2, samplers[2]);
3879 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3880 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3881
3882 // 3: mipped.
3883 glBindSampler(3, samplers[3]);
3884 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3885 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3886
3887 // Bind two blue mipped textures and two single layer textures, should all draw.
3888 glActiveTexture(GL_TEXTURE0);
3889 glBindTexture(GL_TEXTURE_2D, tex);
3890
3891 glActiveTexture(GL_TEXTURE1);
3892 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3893
3894 glActiveTexture(GL_TEXTURE2);
3895 glBindTexture(GL_TEXTURE_2D, tex);
3896
3897 glActiveTexture(GL_TEXTURE3);
3898 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3899
3900 ASSERT_GL_NO_ERROR();
3901
3902 drawQuad(program, "position", 0.5f);
3903 ASSERT_GL_NO_ERROR();
3904 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3905
3906 // Bind four single layer textures, two should be incomplete.
3907 glActiveTexture(GL_TEXTURE1);
3908 glBindTexture(GL_TEXTURE_2D, tex);
3909
3910 glActiveTexture(GL_TEXTURE3);
3911 glBindTexture(GL_TEXTURE_2D, tex);
3912
3913 drawQuad(program, "position", 0.5f);
3914 ASSERT_GL_NO_ERROR();
3915 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3916}
3917
Jamie Madillfa05f602015-05-07 13:47:11 -04003918// 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 +02003919// TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003920ANGLE_INSTANTIATE_TEST(Texture2DTest,
3921 ES2_D3D9(),
3922 ES2_D3D11(),
3923 ES2_D3D11_FL9_3(),
3924 ES2_OPENGL(),
3925 ES2_OPENGLES());
3926ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3927 ES2_D3D9(),
3928 ES2_D3D11(),
3929 ES2_D3D11_FL9_3(),
3930 ES2_OPENGL(),
3931 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003932ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3933 ES2_D3D9(),
3934 ES2_D3D11(),
3935 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003936 ES2_OPENGL(),
3937 ES2_OPENGLES());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003938ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3939 ES2_D3D9(),
3940 ES2_D3D11(),
3941 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003942 ES2_OPENGL(),
3943 ES2_OPENGLES());
3944ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3945 ES2_D3D9(),
3946 ES2_D3D11(),
3947 ES2_D3D11_FL9_3(),
3948 ES2_OPENGL(),
3949 ES2_OPENGLES());
3950ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3951 ES2_D3D9(),
3952 ES2_D3D11(),
3953 ES2_D3D11_FL9_3(),
3954 ES2_OPENGL(),
3955 ES2_OPENGLES());
3956ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003957ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003958ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3959ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3960 ES3_D3D11(),
3961 ES3_OPENGL(),
3962 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003963ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3964 ES3_D3D11(),
3965 ES3_OPENGL(),
3966 ES3_OPENGLES());
3967ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3968ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003969ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003970ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3971 ES2_D3D11(),
3972 ES2_D3D11_FL9_3(),
3973 ES2_D3D9(),
3974 ES2_OPENGL(),
3975 ES2_OPENGLES());
3976ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3977 ES2_D3D11(),
3978 ES2_D3D11_FL9_3(),
3979 ES2_D3D9(),
3980 ES2_OPENGL(),
3981 ES2_OPENGLES());
3982ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3983 ES2_D3D11(),
3984 ES2_D3D11_FL9_3(),
3985 ES2_D3D9(),
3986 ES2_OPENGL(),
3987 ES2_OPENGLES());
3988ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3989 ES2_D3D11(),
3990 ES2_D3D11_FL9_3(),
3991 ES2_D3D9(),
3992 ES2_OPENGL(),
3993 ES2_OPENGLES());
3994ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3995 ES2_D3D11(),
3996 ES2_D3D11_FL9_3(),
3997 ES2_D3D9(),
3998 ES2_OPENGL(),
3999 ES2_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05004000ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());
Vincent Lang25ab4512016-05-13 18:13:59 +02004001ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04004002
Jamie Madill7ffdda92016-09-08 13:26:51 -04004003} // anonymous namespace