blob: 9f4b423fca5dbcc36564f33ccbcf605a837d5310 [file] [log] [blame]
Geoff Langc287ea62016-09-16 14:46:51 -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
7// WebGLCompatibilityTest.cpp : Tests of the GL_ANGLE_webgl_compatibility extension.
8
9#include "test_utils/ANGLETest.h"
10
Geoff Lang677bb6f2017-04-05 12:40:40 -040011#include "common/mathutil.h"
Geoff Langc287ea62016-09-16 14:46:51 -040012#include "test_utils/gl_raii.h"
13
Frank Henigman146e8a12017-03-02 23:22:37 -050014namespace
15{
16
17bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second)
18{
19 return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) &&
20 (second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA);
21}
22
23void CheckBlendFunctions(GLenum src, GLenum dst)
24{
25 if (ConstantColorAndAlphaBlendFunctions(src, dst) ||
26 ConstantColorAndAlphaBlendFunctions(dst, src))
27 {
28 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
29 }
30 else
31 {
32 ASSERT_GL_NO_ERROR();
33 }
34}
35
Geoff Lang677bb6f2017-04-05 12:40:40 -040036// Extensions that affect the ability to use floating point textures
37constexpr const char *FloatingPointTextureExtensions[] = {
38 "",
39 "GL_EXT_texture_storage",
40 "GL_OES_texture_float",
41 "GL_OES_texture_float_linear",
42 "GL_OES_texture_half_float",
43 "GL_OES_texture_half_float_linear",
44 "GL_EXT_color_buffer_half_float",
45 "GL_EXT_color_buffer_float",
46 "GL_CHROMIUM_color_buffer_float_rgba",
47 "GL_CHROMIUM_color_buffer_float_rgb",
48};
49
Frank Henigman146e8a12017-03-02 23:22:37 -050050} // namespace
51
Geoff Langc287ea62016-09-16 14:46:51 -040052namespace angle
53{
54
55class WebGLCompatibilityTest : public ANGLETest
56{
57 protected:
58 WebGLCompatibilityTest()
59 {
60 setWindowWidth(128);
61 setWindowHeight(128);
62 setConfigRedBits(8);
63 setConfigGreenBits(8);
64 setConfigBlueBits(8);
65 setConfigAlphaBits(8);
66 setWebGLCompatibilityEnabled(true);
67 }
68
69 void SetUp() override
70 {
71 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050072 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
73 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040074 }
75
Geoff Lang677bb6f2017-04-05 12:40:40 -040076 template <typename T>
77 void TestFloatTextureFormat(GLenum internalFormat,
78 GLenum format,
79 GLenum type,
80 bool texturingEnabled,
81 bool linearSamplingEnabled,
82 bool renderingEnabled,
83 const T textureData[4],
84 const float floatData[4])
85 {
86 ASSERT_GL_NO_ERROR();
87
88 const std::string samplingVs =
89 "attribute vec4 position;\n"
90 "varying vec2 texcoord;\n"
91 "void main()\n"
92 "{\n"
93 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
94 " texcoord = (position.xy * 0.5) + 0.5;\n"
95 "}\n";
96
97 const std::string samplingFs =
98 "precision mediump float;\n"
99 "uniform sampler2D tex;\n"
100 "uniform vec4 subtractor;\n"
101 "varying vec2 texcoord;\n"
102 "void main()\n"
103 "{\n"
104 " vec4 color = texture2D(tex, texcoord);\n"
105 " if (abs(color.r - subtractor.r) +\n"
106 " abs(color.g - subtractor.g) +\n"
107 " abs(color.b - subtractor.b) +\n"
108 " abs(color.a - subtractor.a) < 8.0)\n"
109 " {\n"
110 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
111 " }\n"
112 " else\n"
113 " {\n"
114 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
115 " }\n"
116 "}\n";
117
118 ANGLE_GL_PROGRAM(samplingProgram, samplingVs, samplingFs);
119 glUseProgram(samplingProgram.get());
120
121 GLRenderbuffer rbo;
122 glBindRenderbuffer(GL_RENDERBUFFER, rbo.get());
123 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
124
125 GLFramebuffer fbo;
126 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
127 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo.get());
128
129 GLTexture texture;
130 glBindTexture(GL_TEXTURE_2D, texture.get());
131
132 if (internalFormat == format)
133 {
134 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, textureData);
135 }
136 else
137 {
138 if (getClientMajorVersion() >= 3)
139 {
140 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
141 }
142 else
143 {
144 ASSERT_TRUE(extensionEnabled("GL_EXT_texture_storage"));
145 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
146 }
147 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, format, type, textureData);
148 }
149
150 if (!texturingEnabled)
151 {
152 // Depending on the entry point and client version, different errors may be generated
153 ASSERT_GLENUM_NE(GL_NO_ERROR, glGetError());
154
155 // Two errors may be generated in the glTexStorage + glTexSubImage case, clear the
156 // second error
157 glGetError();
158
159 return;
160 }
161 ASSERT_GL_NO_ERROR();
162
163 glUniform1i(glGetUniformLocation(samplingProgram.get(), "tex"), 0);
164 glUniform4fv(glGetUniformLocation(samplingProgram.get(), "subtractor"), 1, floatData);
165
166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
168 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
170
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
172 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
173
174 if (linearSamplingEnabled)
175 {
176 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
177 }
178 else
179 {
180 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
181 }
182
183 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(),
184 0);
185 glBindTexture(GL_TEXTURE_2D, 0);
186 if (!renderingEnabled)
187 {
188 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
189 glCheckFramebufferStatus(GL_FRAMEBUFFER));
190 return;
191 }
192 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
193
194 const std::string renderingVs =
195 "attribute vec4 position;\n"
196 "void main()\n"
197 "{\n"
198 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
199 "}\n";
200
201 const std::string renderingFs =
202 "precision mediump float;\n"
203 "uniform vec4 writeValue;\n"
204 "void main()\n"
205 "{\n"
206 " gl_FragColor = writeValue;\n"
207 "}\n";
208
209 ANGLE_GL_PROGRAM(renderingProgram, renderingVs, renderingFs);
210 glUseProgram(renderingProgram.get());
211
212 glUniform4fv(glGetUniformLocation(renderingProgram.get(), "writeValue"), 1, floatData);
213
214 drawQuad(renderingProgram.get(), "position", 0.5f, 1.0f, true);
215
216 EXPECT_PIXEL_COLOR32F_NEAR(
217 0, 0, GLColor32F(floatData[0], floatData[1], floatData[2], floatData[3]), 1.0f);
218 }
219
Jamie Madillcad97ee2017-02-02 18:52:44 -0500220 // Called from RenderingFeedbackLoopWithDrawBuffersEXT.
221 void drawBuffersEXTFeedbackLoop(GLuint program,
222 const std::array<GLenum, 2> &drawBuffers,
223 GLenum expectedError);
224
Jamie Madill07be8bf2017-02-02 19:59:57 -0500225 // Called from RenderingFeedbackLoopWithDrawBuffers.
226 void drawBuffersFeedbackLoop(GLuint program,
227 const std::array<GLenum, 2> &drawBuffers,
228 GLenum expectedError);
229
Geoff Langc339c4e2016-11-29 10:37:36 -0500230 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -0400231};
232
Corentin Wallezfd456442016-12-21 17:57:00 -0500233class WebGL2CompatibilityTest : public WebGLCompatibilityTest
234{
235};
236
Geoff Langc287ea62016-09-16 14:46:51 -0400237// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
238// the GL extension should always be present
239TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
240{
241 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
242}
243
244// Verify that all extension entry points are available
245TEST_P(WebGLCompatibilityTest, EntryPoints)
246{
Geoff Langc339c4e2016-11-29 10:37:36 -0500247 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -0400248 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500249 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -0400250 }
251}
252
253// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
254// even in ES2 contexts.
255TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
256{
257 GLRenderbuffer renderbuffer;
258 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
259 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
260
261 GLFramebuffer framebuffer;
262 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
263 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
264 renderbuffer.get());
265
266 EXPECT_GL_NO_ERROR();
267}
268
269// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
270TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
271{
Geoff Langc339c4e2016-11-29 10:37:36 -0500272 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -0400273 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
274}
275
276// Test enabling the GL_OES_element_index_uint extension
277TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
278{
279 if (getClientMajorVersion() != 2)
280 {
281 // This test only works on ES2 where uint indices are not available by default
282 return;
283 }
284
285 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
286
287 GLBuffer indexBuffer;
288 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
289
290 GLuint data[] = {0, 1, 2, 1, 3, 2};
291 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
292
293 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
294 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
295 glUseProgram(program.get());
296
297 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
298 EXPECT_GL_ERROR(GL_INVALID_ENUM);
299
Geoff Langc339c4e2016-11-29 10:37:36 -0500300 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400301 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500302 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400303 EXPECT_GL_NO_ERROR();
304 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
305
306 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
307 EXPECT_GL_NO_ERROR();
308 }
309}
310
Geoff Langff5c63e2017-04-12 15:26:54 -0400311// Test enabling the GL_OES_standard_derivatives extension
312TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives)
313{
314 EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives"));
315
316 const std::string source =
317 "#extension GL_OES_standard_derivatives : require\n"
318 "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n";
319 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
320
321 if (extensionRequestable("GL_OES_standard_derivatives"))
322 {
323 glRequestExtensionANGLE("GL_OES_standard_derivatives");
324 EXPECT_GL_NO_ERROR();
325 EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives"));
326
327 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
328 ASSERT_NE(0u, shader);
329 glDeleteShader(shader);
330 }
331}
332
333// Test enabling the GL_EXT_shader_texture_lod extension
334TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD)
335{
336 EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod"));
337
338 const std::string source =
339 "#extension GL_EXT_shader_texture_lod : require\n"
340 "uniform sampler2D u_texture;\n"
341 "void main() {\n"
342 " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, "
343 "0.0));\n"
344 "}\n";
345 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
346
347 if (extensionRequestable("GL_EXT_shader_texture_lod"))
348 {
349 glRequestExtensionANGLE("GL_EXT_shader_texture_lod");
350 EXPECT_GL_NO_ERROR();
351 EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod"));
352
353 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
354 ASSERT_NE(0u, shader);
355 glDeleteShader(shader);
356 }
357}
358
359// Test enabling the GL_EXT_frag_depth extension
360TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth)
361{
362 EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth"));
363
364 const std::string source =
365 "#extension GL_EXT_frag_depth : require\n"
366 "void main() {\n"
367 " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
368 " gl_FragDepthEXT = 1.0;\n"
369 "}\n";
370 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
371
372 if (extensionRequestable("GL_EXT_frag_depth"))
373 {
374 glRequestExtensionANGLE("GL_EXT_frag_depth");
375 EXPECT_GL_NO_ERROR();
376 EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth"));
377
378 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
379 ASSERT_NE(0u, shader);
380 glDeleteShader(shader);
381 }
382}
383
Geoff Langd7d526a2017-02-21 16:48:43 -0500384// Test enabling the GL_EXT_texture_filter_anisotropic extension
385TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic)
386{
387 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
388
389 GLfloat maxAnisotropy = 0.0f;
390 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
391 EXPECT_GL_ERROR(GL_INVALID_ENUM);
392
393 GLTexture texture;
394 glBindTexture(GL_TEXTURE_2D, texture.get());
395 ASSERT_GL_NO_ERROR();
396
397 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
398 EXPECT_GL_ERROR(GL_INVALID_ENUM);
399
400 GLfloat currentAnisotropy = 0.0f;
401 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
402 EXPECT_GL_ERROR(GL_INVALID_ENUM);
403
404 if (extensionRequestable("GL_EXT_texture_filter_anisotropic"))
405 {
406 glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic");
407 EXPECT_GL_NO_ERROR();
408 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
409
410 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
411 ASSERT_GL_NO_ERROR();
412 EXPECT_GE(maxAnisotropy, 2.0f);
413
414 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
415 ASSERT_GL_NO_ERROR();
416 EXPECT_EQ(1.0f, currentAnisotropy);
417
418 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
419 ASSERT_GL_NO_ERROR();
420 }
421}
422
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700423// Verify that shaders are of a compatible spec when the extension is enabled.
424TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
425{
426 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
427
428 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
429 const std::string &vert =
430 "struct Foo {\n"
431 " int _webgl_bar;\n"
432 "};\n"
433 "void main()\n"
434 "{\n"
435 " Foo foo = Foo(1);\n"
436 "}";
437
438 // Default fragement shader.
439 const std::string &frag =
440 "void main()\n"
441 "{\n"
442 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
443 "}";
444
445 GLuint program = CompileProgram(vert, frag);
446 EXPECT_EQ(0u, program);
447 glDeleteProgram(program);
448}
449
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400450// Verify that the context generates the correct error when the framebuffer attachments are
451// different sizes
452TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch)
453{
454 GLFramebuffer fbo;
455 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
456
457 GLTexture textures[2];
458 glBindTexture(GL_TEXTURE_2D, textures[0]);
459 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
460 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
461
462 ASSERT_GL_NO_ERROR();
463 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
464
465 GLRenderbuffer renderbuffer;
466 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
467 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
468 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
469
470 ASSERT_GL_NO_ERROR();
471 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
472 glCheckFramebufferStatus(GL_FRAMEBUFFER));
473
474 if (extensionRequestable("GL_EXT_draw_buffers"))
475 {
476 glRequestExtensionANGLE("GL_EXT_draw_buffers");
477 EXPECT_GL_NO_ERROR();
478 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
479
480 glBindTexture(GL_TEXTURE_2D, textures[1]);
481 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
482 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
483 ASSERT_GL_NO_ERROR();
484
485 ASSERT_GL_NO_ERROR();
486 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
487 glCheckFramebufferStatus(GL_FRAMEBUFFER));
488
489 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
490
491 ASSERT_GL_NO_ERROR();
492 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
493
494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
495
496 ASSERT_GL_NO_ERROR();
497 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
498 glCheckFramebufferStatus(GL_FRAMEBUFFER));
499 }
500}
501
Corentin Wallez327411e2016-12-09 11:09:17 -0500502// Test that client-side array buffers are forbidden in WebGL mode
503TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
504{
505 const std::string &vert =
506 "attribute vec3 a_pos;\n"
507 "void main()\n"
508 "{\n"
509 " gl_Position = vec4(a_pos, 1.0);\n"
510 "}\n";
511
512 const std::string &frag =
513 "precision highp float;\n"
514 "void main()\n"
515 "{\n"
516 " gl_FragColor = vec4(1.0);\n"
517 "}\n";
518
519 ANGLE_GL_PROGRAM(program, vert, frag);
520
521 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
522 ASSERT_NE(-1, posLocation);
523 glUseProgram(program.get());
524
525 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500526 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500527 glEnableVertexAttribArray(posLocation);
528
529 ASSERT_GL_NO_ERROR();
530 glDrawArrays(GL_TRIANGLES, 0, 6);
531 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
532}
533
534// Test that client-side element array buffers are forbidden in WebGL mode
535TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
536{
537 const std::string &vert =
538 "attribute vec3 a_pos;\n"
539 "void main()\n"
540 "{\n"
541 " gl_Position = vec4(a_pos, 1.0);\n"
542 "}\n";
543
544 const std::string &frag =
545 "precision highp float;\n"
546 "void main()\n"
547 "{\n"
548 " gl_FragColor = vec4(1.0);\n"
549 "}\n";
550
551 ANGLE_GL_PROGRAM(program, vert, frag);
552
553 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
554 ASSERT_NE(-1, posLocation);
555 glUseProgram(program.get());
556
557 const auto &vertices = GetQuadVertices();
558
559 GLBuffer vertexBuffer;
560 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
561 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
562 GL_STATIC_DRAW);
563
564 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
565 glEnableVertexAttribArray(posLocation);
566
Corentin Wallez327411e2016-12-09 11:09:17 -0500567 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500568
569 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
570 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
571 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
572 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500573 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
574}
575
Corentin Wallez672f7f32017-06-15 17:42:17 -0400576// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
577TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
578{
579 const std::string &vert =
580 "void main()\n"
581 "{\n"
582 " gl_Position = vec4(1.0);\n"
583 "}\n";
584
585 const std::string &frag =
586 "precision highp float;\n"
587 "void main()\n"
588 "{\n"
589 " gl_FragColor = vec4(1.0);\n"
590 "}\n";
591
592 ANGLE_GL_PROGRAM(program, vert, frag);
593
594 glUseProgram(program.get());
595
596 const auto &vertices = GetQuadVertices();
597 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
598 glEnableVertexAttribArray(0);
599
600 ASSERT_GL_NO_ERROR();
601 glDrawArrays(GL_TRIANGLES, 0, 6);
602 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
603}
604
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500605// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
606TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
607{
608 // Run the test in an FBO to make sure we have some stencil bits.
609 GLRenderbuffer renderbuffer;
610 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
611 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
612
613 GLFramebuffer framebuffer;
614 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
615 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
616 renderbuffer.get());
617
618 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
619 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
620 glUseProgram(program.get());
621 ASSERT_GL_NO_ERROR();
622
623 // Having ref and mask the same for front and back is valid.
624 glStencilMask(255);
625 glStencilFunc(GL_ALWAYS, 0, 255);
626 glDrawArrays(GL_TRIANGLES, 0, 6);
627 ASSERT_GL_NO_ERROR();
628
629 // Having a different front - back write mask generates an error.
630 glStencilMaskSeparate(GL_FRONT, 1);
631 glDrawArrays(GL_TRIANGLES, 0, 6);
632 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
633
634 // Setting both write masks separately to the same value is valid.
635 glStencilMaskSeparate(GL_BACK, 1);
636 glDrawArrays(GL_TRIANGLES, 0, 6);
637 ASSERT_GL_NO_ERROR();
638
639 // Having a different stencil front - back mask generates an error
640 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
641 glDrawArrays(GL_TRIANGLES, 0, 6);
642 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
643
644 // Setting both masks separately to the same value is valid.
645 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
646 glDrawArrays(GL_TRIANGLES, 0, 6);
647 ASSERT_GL_NO_ERROR();
648
649 // Having a different stencil front - back reference generates an error
650 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
651 glDrawArrays(GL_TRIANGLES, 0, 6);
652 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
653
654 // Setting both references separately to the same value is valid.
655 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
656 glDrawArrays(GL_TRIANGLES, 0, 6);
657 ASSERT_GL_NO_ERROR();
658
659 // Using different stencil funcs, everything being equal is valid.
660 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
661 glDrawArrays(GL_TRIANGLES, 0, 6);
662 ASSERT_GL_NO_ERROR();
663}
664
Corentin Wallez506fc9c2016-12-21 16:53:33 -0500665// Test that GL_FIXED is forbidden
666TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
667{
668 GLBuffer buffer;
669 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
670 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
671
672 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
673 ASSERT_GL_NO_ERROR();
674
675 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
676 EXPECT_GL_ERROR(GL_INVALID_ENUM);
677}
678
679// Test the WebGL limit of 255 for the attribute stride
680TEST_P(WebGLCompatibilityTest, MaxStride)
681{
682 GLBuffer buffer;
683 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
684 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
685
686 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
687 ASSERT_GL_NO_ERROR();
688
689 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
690 EXPECT_GL_ERROR(GL_INVALID_VALUE);
691}
692
Corentin Wallezfd456442016-12-21 17:57:00 -0500693// Test the checks for OOB reads in the vertex buffers, non-instanced version
694TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
695{
696 const std::string &vert =
697 "attribute float a_pos;\n"
698 "void main()\n"
699 "{\n"
700 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
701 "}\n";
702
703 const std::string &frag =
704 "precision highp float;\n"
705 "void main()\n"
706 "{\n"
707 " gl_FragColor = vec4(1.0);\n"
708 "}\n";
709
710 ANGLE_GL_PROGRAM(program, vert, frag);
711
712 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
713 ASSERT_NE(-1, posLocation);
714 glUseProgram(program.get());
715
716 GLBuffer buffer;
717 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
718 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
719
720 glEnableVertexAttribArray(posLocation);
721
722 const uint8_t* zeroOffset = nullptr;
723
724 // Test touching the last element is valid.
725 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
726 glDrawArrays(GL_POINTS, 0, 4);
727 ASSERT_GL_NO_ERROR();
728
729 // Test touching the last element + 1 is invalid.
730 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
731 glDrawArrays(GL_POINTS, 0, 4);
732 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
733
734 // Test touching the last element is valid, using a stride.
735 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
736 glDrawArrays(GL_POINTS, 0, 4);
737 ASSERT_GL_NO_ERROR();
738
739 // Test touching the last element + 1 is invalid, using a stride.
740 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
741 glDrawArrays(GL_POINTS, 0, 4);
742 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
743
744 // Test any offset is valid if no vertices are drawn.
745 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
746 glDrawArrays(GL_POINTS, 0, 0);
747 ASSERT_GL_NO_ERROR();
748}
749
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500750// Test the checks for OOB reads in the index buffer
751TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -0500752{
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500753 const std::string &vert =
754 "attribute float a_pos;\n"
755 "void main()\n"
756 "{\n"
757 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
758 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -0500759
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500760 const std::string &frag =
761 "precision highp float;\n"
762 "void main()\n"
763 "{\n"
764 " gl_FragColor = vec4(1.0);\n"
765 "}\n";
766
767 ANGLE_GL_PROGRAM(program, vert, frag);
768
769 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
770 ASSERT_NE(-1, posLocation);
771 glUseProgram(program.get());
772
773 GLBuffer vertexBuffer;
774 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
775 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
776
777 glEnableVertexAttribArray(posLocation);
778
779 const uint8_t *zeroOffset = nullptr;
780 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
781
782 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset);
783
784 GLBuffer indexBuffer;
785 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
786 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -0500787 ASSERT_GL_NO_ERROR();
788
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500789 // Test touching the last index is valid
790 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
791 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -0500792
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500793 // Test touching the last + 1 element is invalid
794 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
795 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -0500796
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500797 // Test any offset if valid if count is zero
798 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
799 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -0500800
801 // Test touching the first index is valid
802 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
803 ASSERT_GL_NO_ERROR();
804
805 // Test touching the first - 1 index is invalid
806 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
807 // the historic behavior of WebGL implementations
808 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
809 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -0500810}
811
Frank Henigman6137ddc2017-02-10 18:55:07 -0500812// Test depth range with 'near' more or less than 'far.'
813TEST_P(WebGLCompatibilityTest, DepthRange)
814{
815 glDepthRangef(0, 1);
816 ASSERT_GL_NO_ERROR();
817
818 glDepthRangef(.5, .5);
819 ASSERT_GL_NO_ERROR();
820
821 glDepthRangef(1, 0);
822 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
823}
824
Frank Henigman146e8a12017-03-02 23:22:37 -0500825// Test all blend function combinations.
826// In WebGL it is invalid to combine constant color with constant alpha.
827TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
828{
829 constexpr GLenum srcFunc[] = {
830 GL_ZERO,
831 GL_ONE,
832 GL_SRC_COLOR,
833 GL_ONE_MINUS_SRC_COLOR,
834 GL_DST_COLOR,
835 GL_ONE_MINUS_DST_COLOR,
836 GL_SRC_ALPHA,
837 GL_ONE_MINUS_SRC_ALPHA,
838 GL_DST_ALPHA,
839 GL_ONE_MINUS_DST_ALPHA,
840 GL_CONSTANT_COLOR,
841 GL_ONE_MINUS_CONSTANT_COLOR,
842 GL_CONSTANT_ALPHA,
843 GL_ONE_MINUS_CONSTANT_ALPHA,
844 GL_SRC_ALPHA_SATURATE,
845 };
846
847 constexpr GLenum dstFunc[] = {
848 GL_ZERO, GL_ONE,
849 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
850 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
851 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
852 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
853 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
854 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
855 };
856
857 for (GLenum src : srcFunc)
858 {
859 for (GLenum dst : dstFunc)
860 {
861 glBlendFunc(src, dst);
862 CheckBlendFunctions(src, dst);
863 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
864 CheckBlendFunctions(src, dst);
865 }
866 }
867}
868
Geoff Langfc32e8b2017-05-31 14:16:59 -0400869// Test that binding/querying uniforms and attributes with invalid names generates errors
870TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
871{
872 const std::string validAttribName =
873 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
874 const std::string validUniformName =
875 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
876 const char invalidSet[] = {'"', '$', '`', '@', '\\', '\''};
877
878 std::string vert = "attribute float ";
879 vert += validAttribName;
880 vert +=
881 ";\n"
882 "void main()\n"
883 "{\n"
884 " gl_Position = vec4(1.0);\n"
885 "}\n";
886
887 std::string frag =
888 "precision highp float;\n"
889 "uniform vec4 ";
890 frag += validUniformName;
891 frag +=
892 ";\n"
893 "void main()\n"
894 "{\n"
895 " gl_FragColor = vec4(1.0);\n"
896 "}\n";
897
898 ANGLE_GL_PROGRAM(program, vert, frag);
899 EXPECT_GL_NO_ERROR();
900
901 for (char invalidChar : invalidSet)
902 {
903 std::string invalidName = validAttribName + invalidChar;
904 glGetAttribLocation(program, invalidName.c_str());
905 EXPECT_GL_ERROR(GL_INVALID_VALUE)
906 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
907
908 glBindAttribLocation(program, 0, invalidName.c_str());
909 EXPECT_GL_ERROR(GL_INVALID_VALUE)
910 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
911 }
912
913 for (char invalidChar : invalidSet)
914 {
915 std::string invalidName = validUniformName + invalidChar;
916 glGetUniformLocation(program, invalidName.c_str());
917 EXPECT_GL_ERROR(GL_INVALID_VALUE)
918 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
919 }
920
921 for (char invalidChar : invalidSet)
922 {
923 std::string invalidAttribName = validAttribName + invalidChar;
924 const char *invalidVert[] = {
925 "attribute float ",
926 invalidAttribName.c_str(),
927 ";\n",
928 "void main()\n",
929 "{\n",
930 " gl_Position = vec4(1.0);\n",
931 "}\n",
932 };
933
934 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
935 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
936 EXPECT_GL_ERROR(GL_INVALID_VALUE);
937 glDeleteShader(shader);
938 }
939}
940
Corentin Wallezfd456442016-12-21 17:57:00 -0500941// Test the checks for OOB reads in the vertex buffers, instanced version
942TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
943{
944 const std::string &vert =
945 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400946 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500947 "void main()\n"
948 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400949 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500950 "}\n";
951
952 const std::string &frag =
953 "precision highp float;\n"
954 "void main()\n"
955 "{\n"
956 " gl_FragColor = vec4(1.0);\n"
957 "}\n";
958
959 ANGLE_GL_PROGRAM(program, vert, frag);
960
961 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
962 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -0400963
964 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
965 ASSERT_NE(-1, wLocation);
966
Corentin Wallezfd456442016-12-21 17:57:00 -0500967 glUseProgram(program.get());
968
969 GLBuffer buffer;
970 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
971 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
972
973 glEnableVertexAttribArray(posLocation);
974 glVertexAttribDivisor(posLocation, 1);
975
Geoff Lang407d4e72017-04-12 14:54:11 -0400976 glEnableVertexAttribArray(wLocation);
977 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
978 glVertexAttribDivisor(wLocation, 0);
979
Corentin Wallezfd456442016-12-21 17:57:00 -0500980 const uint8_t* zeroOffset = nullptr;
981
982 // Test touching the last element is valid.
983 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
984 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
985 ASSERT_GL_NO_ERROR();
986
987 // Test touching the last element + 1 is invalid.
988 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
989 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
990 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
991
992 // Test touching the last element is valid, using a stride.
993 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
994 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
995 ASSERT_GL_NO_ERROR();
996
997 // Test touching the last element + 1 is invalid, using a stride.
998 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
999 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1000 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1001
1002 // Test any offset is valid if no vertices are drawn.
1003 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1004 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1005 ASSERT_GL_NO_ERROR();
1006}
1007
Geoff Lang407d4e72017-04-12 14:54:11 -04001008// Test that at least one attribute has a zero divisor for WebGL
1009TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1010{
1011 const std::string &vert =
1012 "attribute float a_pos;\n"
1013 "void main()\n"
1014 "{\n"
1015 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1016 "}\n";
1017
1018 const std::string &frag =
1019 "precision highp float;\n"
1020 "void main()\n"
1021 "{\n"
1022 " gl_FragColor = vec4(1.0);\n"
1023 "}\n";
1024
1025 ANGLE_GL_PROGRAM(program, vert, frag);
1026
1027 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1028 ASSERT_NE(-1, posLocation);
1029
1030 glUseProgram(program.get());
1031
1032 GLBuffer buffer;
1033 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1034 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1035
1036 glEnableVertexAttribArray(posLocation);
1037 glVertexAttribDivisor(posLocation, 1);
1038
1039 // Test touching the last element is valid.
1040 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1041 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1042 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1043
1044 glVertexAttribDivisor(posLocation, 0);
1045 ASSERT_GL_NO_ERROR();
1046}
1047
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001048// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1049TEST_P(WebGLCompatibilityTest, NPOT)
1050{
1051 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1052
1053 // Create a texture and set an NPOT mip 0, should always be acceptable.
1054 GLTexture texture;
1055 glBindTexture(GL_TEXTURE_2D, texture.get());
1056 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1057 ASSERT_GL_NO_ERROR();
1058
1059 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1060 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1061 if (getClientMajorVersion() < 3)
1062 {
1063 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1064 }
1065 else
1066 {
1067 ASSERT_GL_NO_ERROR();
1068 }
1069
1070 if (extensionRequestable("GL_OES_texture_npot"))
1071 {
1072 glRequestExtensionANGLE("GL_OES_texture_npot");
1073 ASSERT_GL_NO_ERROR();
1074
1075 // Try again to set NPOT mip 1
1076 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1077 ASSERT_GL_NO_ERROR();
1078 }
1079}
1080
Jamie Madillcad97ee2017-02-02 18:52:44 -05001081template <typename T>
1082void FillTexture2D(GLuint texture,
1083 GLsizei width,
1084 GLsizei height,
1085 const T &onePixelData,
1086 GLint level,
1087 GLint internalFormat,
1088 GLenum format,
1089 GLenum type)
1090{
1091 std::vector<T> allPixelsData(width * height, onePixelData);
1092
1093 glBindTexture(GL_TEXTURE_2D, texture);
1094 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1095 allPixelsData.data());
1096 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1097 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1098 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1100}
1101
Frank Henigman875bbba2017-02-08 16:38:17 -05001102// Test that unset gl_Position defaults to (0,0,0,0).
1103TEST_P(WebGLCompatibilityTest, DefaultPosition)
1104{
1105 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1106 // and green otherwise. The center of each quadrant will be red if and only if all
1107 // four corners are red.
1108 const std::string vertexShader =
1109 "attribute vec3 pos;\n"
1110 "varying vec4 color;\n"
1111 "void main() {\n"
1112 " if (gl_Position == vec4(0,0,0,0)) {\n"
1113 " color = vec4(1,0,0,1);\n"
1114 " } else {\n"
1115 " color = vec4(0,1,0,1);\n"
1116 " }\n"
1117 " gl_Position = vec4(pos,1);\n"
1118 "}\n";
1119
1120 const std::string fragmentShader =
1121 "precision mediump float;\n"
1122 "varying vec4 color;\n"
1123 "void main() {\n"
1124 " gl_FragColor = color;\n"
1125 "}\n";
1126
1127 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1128 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1129 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1130 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1131 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1132 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1133}
1134
Jamie Madilla4595b82017-01-11 17:36:34 -05001135// Tests that a rendering feedback loop triggers a GL error under WebGL.
1136// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1137TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1138{
1139 const std::string vertexShader =
1140 "attribute vec4 a_position;\n"
1141 "varying vec2 v_texCoord;\n"
1142 "void main() {\n"
1143 " gl_Position = a_position;\n"
1144 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1145 "}\n";
1146
1147 const std::string fragmentShader =
1148 "precision mediump float;\n"
1149 "varying vec2 v_texCoord;\n"
1150 "uniform sampler2D u_texture;\n"
1151 "void main() {\n"
1152 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1153 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1154 "}\n";
1155
1156 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001157 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001158
1159 ASSERT_GL_NO_ERROR();
1160
1161 GLFramebuffer framebuffer;
1162 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1163 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1164
1165 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1166
1167 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1168
1169 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1170 ASSERT_NE(-1, uniformLoc);
1171
1172 glUseProgram(program.get());
1173 glUniform1i(uniformLoc, 0);
1174 glDisable(GL_BLEND);
1175 glDisable(GL_DEPTH_TEST);
1176 ASSERT_GL_NO_ERROR();
1177
1178 // Drawing with a texture that is also bound to the current framebuffer should fail
1179 glBindTexture(GL_TEXTURE_2D, texture.get());
1180 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1181 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1182
1183 // Ensure that the texture contents did not change after the previous render
1184 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1185 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1186 ASSERT_GL_NO_ERROR();
1187 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1188
1189 // Drawing when texture is bound to an inactive uniform should succeed
1190 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001191 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001192
1193 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1194 glActiveTexture(GL_TEXTURE1);
1195 glBindTexture(GL_TEXTURE_2D, texture.get());
1196 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1197 ASSERT_GL_NO_ERROR();
1198 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1199}
1200
Bryan Bernhart58806562017-01-05 13:09:31 -08001201// Test for the max draw buffers and color attachments.
1202TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1203{
1204 // This test only applies to ES2.
1205 if (getClientMajorVersion() != 2)
1206 {
1207 return;
1208 }
1209
1210 GLFramebuffer fbo[2];
1211 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1212
1213 // Test that is valid when we bind with a single attachment point.
1214 GLTexture texture;
1215 glBindTexture(GL_TEXTURE_2D, texture.get());
1216 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1217 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1218 ASSERT_GL_NO_ERROR();
1219
1220 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1221 // attachment point.
1222 if (extensionRequestable("GL_EXT_draw_buffers"))
1223 {
1224 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1225 EXPECT_GL_NO_ERROR();
1226 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1227
1228 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1229
1230 GLTexture texture2;
1231 glBindTexture(GL_TEXTURE_2D, texture2.get());
1232 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1233 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1234 0);
1235 ASSERT_GL_NO_ERROR();
1236 }
1237}
1238
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001239// Test that the offset in the index buffer is forced to be a multiple of the element size
1240TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1241{
1242 const std::string &vert =
1243 "attribute vec3 a_pos;\n"
1244 "void main()\n"
1245 "{\n"
1246 " gl_Position = vec4(a_pos, 1.0);\n"
1247 "}\n";
1248
1249 const std::string &frag =
1250 "precision highp float;\n"
1251 "void main()\n"
1252 "{\n"
1253 " gl_FragColor = vec4(1.0);\n"
1254 "}\n";
1255
1256 ANGLE_GL_PROGRAM(program, vert, frag);
1257
1258 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1259 ASSERT_NE(-1, posLocation);
1260 glUseProgram(program.get());
1261
1262 const auto &vertices = GetQuadVertices();
1263
1264 GLBuffer vertexBuffer;
1265 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1266 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1267 GL_STATIC_DRAW);
1268
1269 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1270 glEnableVertexAttribArray(posLocation);
1271
1272 GLBuffer indexBuffer;
1273 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
1274 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1275 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1276
1277 ASSERT_GL_NO_ERROR();
1278
1279 const char *zeroIndices = nullptr;
1280
1281 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1282 ASSERT_GL_NO_ERROR();
1283
1284 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
1285 ASSERT_GL_NO_ERROR();
1286
1287 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
1288 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1289}
1290
1291// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1292// size
1293TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1294{
1295 const char *zeroOffset = nullptr;
1296
1297 // Base case, vector of two floats
1298 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1299 ASSERT_GL_NO_ERROR();
1300
1301 // Test setting a non-multiple offset
1302 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1303 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1304 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1305 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1306 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1307 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1308
1309 // Test setting a non-multiple stride
1310 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1311 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1312 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1313 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1314 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1315 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1316}
1317
Jamie Madillcad97ee2017-02-02 18:52:44 -05001318void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1319 const std::array<GLenum, 2> &drawBuffers,
1320 GLenum expectedError)
1321{
1322 glDrawBuffersEXT(2, drawBuffers.data());
1323
1324 // Make sure framebuffer is complete before feedback loop detection
1325 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1326
1327 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1328
1329 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1330 // it should be NO_ERROR"
1331 EXPECT_GL_ERROR(expectedError);
1332}
1333
1334// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1335// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1336TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1337{
1338 const std::string vertexShader =
1339 "attribute vec4 aPosition;\n"
1340 "varying vec2 texCoord;\n"
1341 "void main() {\n"
1342 " gl_Position = aPosition;\n"
1343 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1344 "}\n";
1345
1346 const std::string fragmentShader =
1347 "#extension GL_EXT_draw_buffers : require\n"
1348 "precision mediump float;\n"
1349 "uniform sampler2D tex;\n"
1350 "varying vec2 texCoord;\n"
1351 "void main() {\n"
1352 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1353 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1354 "}\n";
1355
1356 GLsizei width = 8;
1357 GLsizei height = 8;
1358
1359 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1360 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1361 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1362 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1363 {
1364 // No WEBGL_draw_buffers support -- this is legal.
1365 return;
1366 }
1367
1368 GLint maxDrawBuffers = 0;
1369 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1370
1371 if (maxDrawBuffers < 2)
1372 {
1373 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1374 return;
1375 }
1376
1377 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1378 glUseProgram(program.get());
1379 glViewport(0, 0, width, height);
1380
1381 GLTexture tex0;
1382 GLTexture tex1;
1383 GLFramebuffer fbo;
1384 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1385 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1386 ASSERT_GL_NO_ERROR();
1387
1388 glBindTexture(GL_TEXTURE_2D, tex1.get());
1389 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1390 ASSERT_NE(-1, texLoc);
1391 glUniform1i(texLoc, 0);
1392 ASSERT_GL_NO_ERROR();
1393
1394 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1395 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1396 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1397 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1398
1399 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1400 GL_INVALID_OPERATION);
1401 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1402 GL_INVALID_OPERATION);
1403 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1404}
1405
Jamie Madill07be8bf2017-02-02 19:59:57 -05001406// Test tests that texture copying feedback loops are properly rejected in WebGL.
1407// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1408TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1409{
1410 GLTexture texture;
1411 glBindTexture(GL_TEXTURE_2D, texture.get());
1412 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1415 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1416 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1417
1418 GLTexture texture2;
1419 glBindTexture(GL_TEXTURE_2D, texture2.get());
1420 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1421 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1425
1426 GLFramebuffer framebuffer;
1427 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1428 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1429
1430 // framebuffer should be FRAMEBUFFER_COMPLETE.
1431 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1432 ASSERT_GL_NO_ERROR();
1433
1434 // testing copyTexImage2D
1435
1436 // copyTexImage2D to same texture but different level
1437 glBindTexture(GL_TEXTURE_2D, texture.get());
1438 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1439 EXPECT_GL_NO_ERROR();
1440
1441 // copyTexImage2D to same texture same level, invalid feedback loop
1442 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1443 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1444
1445 // copyTexImage2D to different texture
1446 glBindTexture(GL_TEXTURE_2D, texture2.get());
1447 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1448 EXPECT_GL_NO_ERROR();
1449
1450 // testing copyTexSubImage2D
1451
1452 // copyTexSubImage2D to same texture but different level
1453 glBindTexture(GL_TEXTURE_2D, texture.get());
1454 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1455 EXPECT_GL_NO_ERROR();
1456
1457 // copyTexSubImage2D to same texture same level, invalid feedback loop
1458 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1459 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1460
1461 // copyTexSubImage2D to different texture
1462 glBindTexture(GL_TEXTURE_2D, texture2.get());
1463 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1464 EXPECT_GL_NO_ERROR();
1465}
1466
1467void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1468 const std::array<GLenum, 2> &drawBuffers,
1469 GLenum expectedError)
1470{
1471 glDrawBuffers(2, drawBuffers.data());
1472
1473 // Make sure framebuffer is complete before feedback loop detection
1474 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1475
1476 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1477
1478 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1479 // it should be NO_ERROR"
1480 EXPECT_GL_ERROR(expectedError);
1481}
1482
Yuly Novikov817232e2017-02-22 18:36:10 -05001483// Tests invariance matching rules between built in varyings.
1484// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1485TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1486{
1487 const std::string vertexShaderVariant =
1488 "varying vec4 v_varying;\n"
1489 "void main()\n"
1490 "{\n"
1491 " gl_PointSize = 1.0;\n"
1492 " gl_Position = v_varying;\n"
1493 "}";
1494 const std::string fragmentShaderInvariantGlFragCoord =
1495 "invariant gl_FragCoord;\n"
1496 "void main()\n"
1497 "{\n"
1498 " gl_FragColor = gl_FragCoord;\n"
1499 "}";
1500 const std::string fragmentShaderInvariantGlPointCoord =
1501 "invariant gl_PointCoord;\n"
1502 "void main()\n"
1503 "{\n"
1504 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1505 "}";
1506
1507 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1508 EXPECT_EQ(0u, program);
1509
1510 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1511 EXPECT_EQ(0u, program);
1512}
1513
Geoff Lang966c9402017-04-18 12:38:27 -04001514// Test dimension and image size validation of compressed textures
1515TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1516{
1517 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1518 {
1519 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1520 }
1521
1522 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1523 {
1524 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1525 << std::endl;
1526 return;
1527 }
1528
1529 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1530
1531 GLTexture texture;
1532 glBindTexture(GL_TEXTURE_2D, texture);
1533
1534 // Regular case, verify that it works
1535 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1536 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1537 ASSERT_GL_NO_ERROR();
1538
1539 // Test various dimensions that are not valid
1540 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1541 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1542 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1543
1544 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1545 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1546 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1547
1548 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1549 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1550 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1551
1552 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1553 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1554 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1555
1556 // Test various image sizes that are not valid
1557 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1558 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1559 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1560
1561 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1562 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1563 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1564
1565 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1566 CompressedImageDXT1);
1567 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1568
1569 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1570 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1571 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1572
1573 // Fill a full mip chain and verify that it works
1574 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1575 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1576 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1577 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1578 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1579 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1580 ASSERT_GL_NO_ERROR();
1581
1582 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1583 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1584 ASSERT_GL_NO_ERROR();
1585
1586 // Test that non-block size sub-uploads are not valid for the 0 mip
1587 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1588 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1589 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1590
1591 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1592 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1593 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1594 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1595 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1596 ASSERT_GL_NO_ERROR();
1597
1598 // Test that if the format miss-matches the texture, an error is generated
1599 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1600 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1601 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1602}
1603
Geoff Lang677bb6f2017-04-05 12:40:40 -04001604TEST_P(WebGLCompatibilityTest, L32FTextures)
1605{
1606 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1607 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1608
1609 for (auto extension : FloatingPointTextureExtensions)
1610 {
1611 if (strlen(extension) > 0 && extensionRequestable(extension))
1612 {
1613 glRequestExtensionANGLE(extension);
1614 ASSERT_GL_NO_ERROR();
1615 }
1616
1617 // Unsized L 32F
1618 {
1619 bool texture = extensionEnabled("GL_OES_texture_float");
1620 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1621 bool render = false;
1622 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1623 textureData, readPixelData);
1624 }
1625
1626 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1627 {
1628 // Sized L 32F
1629 bool texture = extensionEnabled("GL_OES_texture_float") &&
1630 extensionEnabled("GL_EXT_texture_storage");
1631 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1632 bool render = false;
1633 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1634 render, textureData, readPixelData);
1635 }
1636 }
1637}
1638
1639TEST_P(WebGLCompatibilityTest, A32FTextures)
1640{
1641 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1642 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1643
1644 for (auto extension : FloatingPointTextureExtensions)
1645 {
1646 if (strlen(extension) > 0 && extensionRequestable(extension))
1647 {
1648 glRequestExtensionANGLE(extension);
1649 ASSERT_GL_NO_ERROR();
1650 }
1651
1652 // Unsized A 32F
1653 {
1654 bool texture = extensionEnabled("GL_OES_texture_float");
1655 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1656 bool render = false;
1657 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1658 textureData, readPixelData);
1659 }
1660
1661 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1662 {
1663 // Sized A 32F
1664 bool texture = extensionEnabled("GL_OES_texture_float") &&
1665 extensionEnabled("GL_EXT_texture_storage");
1666 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1667 bool render = false;
1668 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1669 textureData, readPixelData);
1670 }
1671 }
1672}
1673
1674TEST_P(WebGLCompatibilityTest, LA32FTextures)
1675{
1676 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1677 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1678 textureData[1]};
1679
1680 for (auto extension : FloatingPointTextureExtensions)
1681 {
1682 if (strlen(extension) > 0 && extensionRequestable(extension))
1683 {
1684 glRequestExtensionANGLE(extension);
1685 ASSERT_GL_NO_ERROR();
1686 }
1687
1688 // Unsized LA 32F
1689 {
1690 bool texture = extensionEnabled("GL_OES_texture_float");
1691 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1692 bool render = false;
1693 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1694 filter, render, textureData, readPixelData);
1695 }
1696
1697 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1698 {
1699 // Sized LA 32F
1700 bool texture = extensionEnabled("GL_OES_texture_float") &&
1701 extensionEnabled("GL_EXT_texture_storage");
1702 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1703 bool render = false;
1704 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1705 filter, render, textureData, readPixelData);
1706 }
1707 }
1708}
1709
1710TEST_P(WebGLCompatibilityTest, R32FTextures)
1711{
1712 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1713
1714 for (auto extension : FloatingPointTextureExtensions)
1715 {
1716 if (strlen(extension) > 0 && extensionRequestable(extension))
1717 {
1718 glRequestExtensionANGLE(extension);
1719 ASSERT_GL_NO_ERROR();
1720 }
1721
1722 // Unsized R 32F
1723 {
1724 bool texture =
1725 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1726 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1727 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1728 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1729 }
1730
1731 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1732 {
1733 // Sized R 32F
1734 bool texture =
1735 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1736 extensionEnabled("GL_EXT_texture_rg") &&
1737 extensionEnabled("GL_EXT_texture_storage"));
1738 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1739 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1740 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1741 }
1742 }
1743}
1744
1745TEST_P(WebGLCompatibilityTest, RG32FTextures)
1746{
1747 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1748
1749 for (auto extension : FloatingPointTextureExtensions)
1750 {
1751 if (strlen(extension) > 0 && extensionRequestable(extension))
1752 {
1753 glRequestExtensionANGLE(extension);
1754 ASSERT_GL_NO_ERROR();
1755 }
1756
1757 // Unsized RG 32F
1758 {
1759 bool texture =
1760 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1761 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1762 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1763 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1764 }
1765
1766 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1767 {
1768 // Sized RG 32F
1769 bool texture =
1770 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1771 extensionEnabled("GL_EXT_texture_rg") &&
1772 extensionEnabled("GL_EXT_texture_storage"));
1773 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1774 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1775 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1776 }
1777 }
1778}
1779
1780TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1781{
Geoff Lang40762ef2017-05-08 13:47:03 -04001782 if (IsLinux() && IsIntel())
1783 {
1784 std::cout << "Test skipped on Linux Intel." << std::endl;
1785 return;
1786 }
1787
Geoff Lang677bb6f2017-04-05 12:40:40 -04001788 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1789
1790 for (auto extension : FloatingPointTextureExtensions)
1791 {
1792 if (strlen(extension) > 0 && extensionRequestable(extension))
1793 {
1794 glRequestExtensionANGLE(extension);
1795 ASSERT_GL_NO_ERROR();
1796 }
1797
1798 // Unsized RGB 32F
1799 {
1800 bool texture = extensionEnabled("GL_OES_texture_float");
1801 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1802 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1803 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
1804 }
1805
1806 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1807 {
1808 // Sized RGBA 32F
1809 bool texture =
1810 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1811 extensionEnabled("GL_EXT_texture_storage"));
1812 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1813 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1814 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
1815 data);
1816 }
1817 }
1818}
1819
1820TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
1821{
1822 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1823
1824 for (auto extension : FloatingPointTextureExtensions)
1825 {
1826 if (strlen(extension) > 0 && extensionRequestable(extension))
1827 {
1828 glRequestExtensionANGLE(extension);
1829 ASSERT_GL_NO_ERROR();
1830 }
1831
1832 // Unsized RGBA 32F
1833 {
1834 bool texture = extensionEnabled("GL_OES_texture_float");
1835 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1836 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1837 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1838 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
1839 }
1840
1841 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1842 {
1843 // Sized RGBA 32F
1844 bool texture =
1845 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1846 extensionEnabled("GL_EXT_texture_storage"));
1847 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1848 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1849 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1850 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
1851 data);
1852 }
1853 }
1854}
1855
1856TEST_P(WebGLCompatibilityTest, R16FTextures)
1857{
1858 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
1859 const GLushort textureData[] = {
1860 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1861 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1862
1863 for (auto extension : FloatingPointTextureExtensions)
1864 {
1865 if (strlen(extension) > 0 && extensionRequestable(extension))
1866 {
1867 glRequestExtensionANGLE(extension);
1868 ASSERT_GL_NO_ERROR();
1869 }
1870
1871 // Unsized R 16F (OES)
1872 {
1873 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1874 extensionEnabled("GL_EXT_texture_rg");
1875 bool filter = getClientMajorVersion() >= 3 ||
1876 extensionEnabled("GL_OES_texture_half_float_linear");
1877 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1878 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
1879 textureData, readPixelsData);
1880 }
1881
1882 // Unsized R 16F
1883 {
1884 bool texture = false;
1885 bool filter = false;
1886 bool render = false;
1887 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1888 textureData, readPixelsData);
1889 }
1890
1891 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1892 {
1893 // Sized R 16F
1894 bool texture = getClientMajorVersion() >= 3;
1895 bool filter = getClientMajorVersion() >= 3 ||
1896 extensionEnabled("GL_OES_texture_half_float_linear");
1897 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1898 extensionEnabled("GL_EXT_color_buffer_float");
1899 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1900 textureData, readPixelsData);
1901 }
1902 }
1903}
1904
1905TEST_P(WebGLCompatibilityTest, RG16FTextures)
1906{
1907 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
1908 const GLushort textureData[] = {
1909 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1910 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1911
1912 for (auto extension : FloatingPointTextureExtensions)
1913 {
1914 if (strlen(extension) > 0 && extensionRequestable(extension))
1915 {
1916 glRequestExtensionANGLE(extension);
1917 ASSERT_GL_NO_ERROR();
1918 }
1919
1920 // Unsized RG 16F (OES)
1921 {
1922 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1923 extensionEnabled("GL_EXT_texture_rg");
1924 bool filter = getClientMajorVersion() >= 3 ||
1925 extensionEnabled("GL_OES_texture_half_float_linear");
1926 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
1927 extensionEnabled("GL_EXT_texture_rg");
1928 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
1929 textureData, readPixelsData);
1930 }
1931
1932 // Unsized RG 16F
1933 {
1934 bool texture = false;
1935 bool filter = false;
1936 bool render = false;
1937 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1938 textureData, readPixelsData);
1939 }
1940
1941 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1942 {
1943 // Sized RG 16F
1944 bool texture = getClientMajorVersion() >= 3;
1945 bool filter = getClientMajorVersion() >= 3 ||
1946 extensionEnabled("GL_OES_texture_half_float_linear");
1947 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1948 extensionEnabled("GL_EXT_color_buffer_float");
1949 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1950 textureData, readPixelsData);
1951 }
1952 }
1953}
1954
1955TEST_P(WebGLCompatibilityTest, RGB16FTextures)
1956{
Geoff Lang40762ef2017-05-08 13:47:03 -04001957 if (IsOzone() && IsIntel())
1958 {
1959 std::cout << "Test skipped on Intel Ozone." << std::endl;
1960 return;
1961 }
1962
Geoff Lang677bb6f2017-04-05 12:40:40 -04001963 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
1964 const GLushort textureData[] = {
1965 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1966 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1967
1968 for (auto extension : FloatingPointTextureExtensions)
1969 {
1970 if (strlen(extension) > 0 && extensionRequestable(extension))
1971 {
1972 glRequestExtensionANGLE(extension);
1973 ASSERT_GL_NO_ERROR();
1974 }
1975
1976 // Unsized RGB 16F (OES)
1977 {
1978 bool texture = extensionEnabled("GL_OES_texture_half_float");
1979 bool filter = getClientMajorVersion() >= 3 ||
1980 extensionEnabled("GL_OES_texture_half_float_linear");
1981 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1982 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
1983 textureData, readPixelsData);
1984 }
1985
1986 // Unsized RGB 16F
1987 {
1988 bool texture = false;
1989 bool filter = false;
1990 bool render = false;
1991 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
1992 textureData, readPixelsData);
1993 }
1994
1995 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1996 {
1997 // Sized RGB 16F
1998 bool texture = getClientMajorVersion() >= 3;
1999 bool filter = getClientMajorVersion() >= 3 ||
2000 extensionEnabled("GL_OES_texture_half_float_linear");
2001 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2002 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2003 textureData, readPixelsData);
2004 }
2005 }
2006}
2007
2008TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2009{
Geoff Lang40762ef2017-05-08 13:47:03 -04002010 if (IsOzone() && IsIntel())
2011 {
2012 std::cout << "Test skipped on Intel Ozone." << std::endl;
2013 return;
2014 }
2015
Geoff Lang677bb6f2017-04-05 12:40:40 -04002016 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2017 const GLushort textureData[] = {
2018 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2019 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2020
2021 for (auto extension : FloatingPointTextureExtensions)
2022 {
2023 if (strlen(extension) > 0 && extensionRequestable(extension))
2024 {
2025 glRequestExtensionANGLE(extension);
2026 ASSERT_GL_NO_ERROR();
2027 }
2028
2029 // Unsized RGBA 16F (OES)
2030 {
2031 bool texture = extensionEnabled("GL_OES_texture_half_float");
2032 bool filter = getClientMajorVersion() >= 3 ||
2033 extensionEnabled("GL_OES_texture_half_float_linear");
2034 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2035 extensionEnabled("GL_EXT_color_buffer_float");
2036 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2037 textureData, readPixelsData);
2038 }
2039
2040 // Unsized RGBA 16F
2041 {
2042 bool texture = false;
2043 bool filter = false;
2044 bool render = false;
2045 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2046 textureData, readPixelsData);
2047 }
2048
2049 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2050 {
2051 // Sized RGBA 16F
2052 bool texture = getClientMajorVersion() >= 3;
2053 bool filter = getClientMajorVersion() >= 3 ||
2054 extensionEnabled("GL_OES_texture_half_float_linear");
2055 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2056 extensionEnabled("GL_EXT_color_buffer_float");
2057 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2058 textureData, readPixelsData);
2059 }
2060 }
2061}
2062
Geoff Lang6e898aa2017-06-02 11:17:26 -04002063// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2064// accepted by glTexImage2D
2065TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2066{
2067 if (getClientMajorVersion() != 2)
2068 {
2069 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2070 return;
2071 }
2072
2073 if (!extensionRequestable("GL_OES_texture_float"))
2074 {
2075 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2076 return;
2077 }
2078 glRequestExtensionANGLE("GL_OES_texture_float");
2079 ASSERT_GL_NO_ERROR();
2080
2081 GLTexture texture;
2082 glBindTexture(GL_TEXTURE_2D, texture);
2083
2084 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2085 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2086
2087 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2088 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2089
2090 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2091 {
2092 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2093 ASSERT_GL_NO_ERROR();
2094
2095 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2096 EXPECT_GL_NO_ERROR();
2097 }
2098
2099 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2100 {
2101 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2102 ASSERT_GL_NO_ERROR();
2103
2104 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2105 EXPECT_GL_NO_ERROR();
2106 }
2107}
2108
Jamie Madill07be8bf2017-02-02 19:59:57 -05002109// This tests that rendering feedback loops works as expected with WebGL 2.
2110// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2111TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2112{
2113 const std::string vertexShader =
2114 "#version 300 es\n"
2115 "in vec4 aPosition;\n"
2116 "out vec2 texCoord;\n"
2117 "void main() {\n"
2118 " gl_Position = aPosition;\n"
2119 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2120 "}\n";
2121
2122 const std::string fragmentShader =
2123 "#version 300 es\n"
2124 "precision mediump float;\n"
2125 "uniform sampler2D tex;\n"
2126 "in vec2 texCoord;\n"
2127 "out vec4 oColor;\n"
2128 "void main() {\n"
2129 " oColor = texture(tex, texCoord);\n"
2130 "}\n";
2131
2132 GLsizei width = 8;
2133 GLsizei height = 8;
2134
2135 GLint maxDrawBuffers = 0;
2136 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2137 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2138 ASSERT_GE(maxDrawBuffers, 2);
2139
2140 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2141 glUseProgram(program.get());
2142 glViewport(0, 0, width, height);
2143
2144 GLTexture tex0;
2145 GLTexture tex1;
2146 GLFramebuffer fbo;
2147 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2148 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2149 ASSERT_GL_NO_ERROR();
2150
2151 glBindTexture(GL_TEXTURE_2D, tex1.get());
2152 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2153 ASSERT_NE(-1, texLoc);
2154 glUniform1i(texLoc, 0);
2155
2156 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2157 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2158 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2159 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2160 ASSERT_GL_NO_ERROR();
2161
2162 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2163 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2164 GL_INVALID_OPERATION);
2165 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2166}
2167
Jamie Madill1d37bc52017-02-02 19:59:58 -05002168// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2169// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2170TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2171{
2172 const std::string vertexShader =
2173 "#version 300 es\n"
2174 "in vec4 aPosition;\n"
2175 "out vec2 texCoord;\n"
2176 "void main() {\n"
2177 " gl_Position = aPosition;\n"
2178 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2179 "}\n";
2180
2181 const std::string fragmentShader =
2182 "#version 300 es\n"
2183 "precision mediump float;\n"
2184 "uniform sampler2D tex;\n"
2185 "in vec2 texCoord;\n"
2186 "out vec4 oColor;\n"
2187 "void main() {\n"
2188 " oColor = texture(tex, texCoord);\n"
2189 "}\n";
2190
2191 GLsizei width = 8;
2192 GLsizei height = 8;
2193
2194 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2195 glUseProgram(program.get());
2196
2197 glViewport(0, 0, width, height);
2198
2199 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2200 glUniform1i(texLoc, 0);
2201
2202 // Create textures and allocate storage
2203 GLTexture tex0;
2204 GLTexture tex1;
2205 GLRenderbuffer rb;
2206 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2207 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2208 GL_UNSIGNED_INT);
2209 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2210 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2211 ASSERT_GL_NO_ERROR();
2212
2213 GLFramebuffer fbo;
2214 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2215 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2216
2217 // Test rendering and sampling feedback loop for depth buffer
2218 glBindTexture(GL_TEXTURE_2D, tex1.get());
2219 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2220 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2221
2222 // The same image is used as depth buffer during rendering.
2223 glEnable(GL_DEPTH_TEST);
2224 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2226
2227 // The same image is used as depth buffer. But depth mask is false.
2228 glDepthMask(GL_FALSE);
2229 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2230 EXPECT_GL_NO_ERROR();
2231
2232 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2233 glDepthMask(GL_TRUE);
2234 glDisable(GL_DEPTH_TEST);
2235 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2236 EXPECT_GL_NO_ERROR();
2237
2238 // Test rendering and sampling feedback loop for stencil buffer
2239 glBindTexture(GL_RENDERBUFFER, rb.get());
2240 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2241 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2242 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2243 constexpr GLint stencilClearValue = 0x40;
2244 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2245
2246 // The same image is used as stencil buffer during rendering.
2247 glEnable(GL_STENCIL_TEST);
2248 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2249 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2250
2251 // The same image is used as stencil buffer. But stencil mask is zero.
2252 glStencilMask(0x0);
2253 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2254 EXPECT_GL_NO_ERROR();
2255
2256 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2257 glStencilMask(0xffff);
2258 glDisable(GL_STENCIL_TEST);
2259 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2260 EXPECT_GL_NO_ERROR();
2261}
2262
Jamie Madillfd3dd432017-02-02 19:59:59 -05002263// The source and the target for CopyTexSubImage3D are the same 3D texture.
2264// But the level of the 3D texture != the level of the read attachment.
2265TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2266{
2267 GLTexture texture;
2268 GLFramebuffer framebuffer;
2269
2270 glBindTexture(GL_TEXTURE_3D, texture.get());
2271 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2272
2273 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2274 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2275 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2276 ASSERT_GL_NO_ERROR();
2277
2278 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2279 EXPECT_GL_NO_ERROR();
2280}
2281
2282// The source and the target for CopyTexSubImage3D are the same 3D texture.
2283// But the zoffset of the 3D texture != the layer of the read attachment.
2284TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2285{
2286 GLTexture texture;
2287 GLFramebuffer framebuffer;
2288
2289 glBindTexture(GL_TEXTURE_3D, texture.get());
2290 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2291
2292 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2293 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2294 ASSERT_GL_NO_ERROR();
2295
2296 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2297 EXPECT_GL_NO_ERROR();
2298}
2299
2300// The source and the target for CopyTexSubImage3D are the same 3D texture.
2301// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2302TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2303{
2304 GLTexture texture;
2305 GLFramebuffer framebuffer;
2306
2307 glBindTexture(GL_TEXTURE_3D, texture.get());
2308 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2309
2310 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2311 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2312 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2313 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2314 ASSERT_GL_NO_ERROR();
2315
2316 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2317 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2318}
2319
Geoff Lang76e65652017-03-27 14:58:02 -04002320// Verify that errors are generated when there isn not a defined conversion between the clear type
2321// and the buffer type.
2322TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2323{
2324 if (IsD3D11())
2325 {
2326 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2327 return;
2328 }
2329
2330 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2331 constexpr int clearInt[] = {0, 0, 0, 0};
2332 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2333
2334 GLTexture texture;
2335 GLFramebuffer framebuffer;
2336
2337 glBindTexture(GL_TEXTURE_2D, texture.get());
2338 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2339
2340 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2341 ASSERT_GL_NO_ERROR();
2342
2343 // Unsigned integer buffer
2344 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2345 ASSERT_GL_NO_ERROR();
2346
2347 glClearBufferfv(GL_COLOR, 0, clearFloat);
2348 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2349
2350 glClearBufferiv(GL_COLOR, 0, clearInt);
2351 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2352
2353 glClearBufferuiv(GL_COLOR, 0, clearUint);
2354 EXPECT_GL_NO_ERROR();
2355
2356 glClear(GL_COLOR_BUFFER_BIT);
2357 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2358
2359 // Integer buffer
2360 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2361 ASSERT_GL_NO_ERROR();
2362
2363 glClearBufferfv(GL_COLOR, 0, clearFloat);
2364 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2365
2366 glClearBufferiv(GL_COLOR, 0, clearInt);
2367 EXPECT_GL_NO_ERROR();
2368
2369 glClearBufferuiv(GL_COLOR, 0, clearUint);
2370 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2371
2372 glClear(GL_COLOR_BUFFER_BIT);
2373 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2374
2375 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002376 if (extensionRequestable("GL_EXT_color_buffer_float"))
2377 {
2378 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2379 }
Geoff Lang76e65652017-03-27 14:58:02 -04002380
Geoff Lang677bb6f2017-04-05 12:40:40 -04002381 if (extensionEnabled("GL_EXT_color_buffer_float"))
2382 {
2383 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2384 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002385
Geoff Lang677bb6f2017-04-05 12:40:40 -04002386 glClearBufferfv(GL_COLOR, 0, clearFloat);
2387 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002388
Geoff Lang677bb6f2017-04-05 12:40:40 -04002389 glClearBufferiv(GL_COLOR, 0, clearInt);
2390 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002391
Geoff Lang677bb6f2017-04-05 12:40:40 -04002392 glClearBufferuiv(GL_COLOR, 0, clearUint);
2393 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2394
2395 glClear(GL_COLOR_BUFFER_BIT);
2396 EXPECT_GL_NO_ERROR();
2397 }
Geoff Lang76e65652017-03-27 14:58:02 -04002398
2399 // Normalized uint buffer
2400 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2401 ASSERT_GL_NO_ERROR();
2402
2403 glClearBufferfv(GL_COLOR, 0, clearFloat);
2404 EXPECT_GL_NO_ERROR();
2405
2406 glClearBufferiv(GL_COLOR, 0, clearInt);
2407 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2408
2409 glClearBufferuiv(GL_COLOR, 0, clearUint);
2410 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2411
2412 glClear(GL_COLOR_BUFFER_BIT);
2413 EXPECT_GL_NO_ERROR();
2414}
2415
Geoff Lange4915782017-04-12 15:19:07 -04002416// Verify that errors are generate when trying to blit from an image to itself
2417TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2418{
2419 GLTexture textures[2];
2420 glBindTexture(GL_TEXTURE_2D, textures[0]);
2421 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2422 glBindTexture(GL_TEXTURE_2D, textures[1]);
2423 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2424
2425 GLRenderbuffer renderbuffers[2];
2426 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2427 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2428 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2429 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2430
2431 GLFramebuffer framebuffers[2];
2432 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2433 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2434
2435 ASSERT_GL_NO_ERROR();
2436
2437 // Same texture
2438 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2439 0);
2440 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2441 0);
2442 ASSERT_GL_NO_ERROR();
2443 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2444 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2445
2446 // Same textures but different renderbuffers
2447 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2448 renderbuffers[0]);
2449 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2450 renderbuffers[1]);
2451 ASSERT_GL_NO_ERROR();
2452 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2453 ASSERT_GL_NO_ERROR();
2454 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2455 GL_NEAREST);
2456 ASSERT_GL_NO_ERROR();
2457 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2458 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2459 GL_NEAREST);
2460 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2461
2462 // Same renderbuffers but different textures
2463 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2464 0);
2465 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2466 0);
2467 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2468 renderbuffers[0]);
2469 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2470 renderbuffers[0]);
2471 ASSERT_GL_NO_ERROR();
2472 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2473 ASSERT_GL_NO_ERROR();
2474 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2475 GL_NEAREST);
2476 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2477 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2478 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2479 GL_NEAREST);
2480 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2481}
2482
Geoff Lange0cff192017-05-30 13:04:56 -04002483// Verify that errors are generated when the fragment shader output doesn't match the bound color
2484// buffer types
2485TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2486{
2487 const std::string vertexShader =
2488 "#version 300 es\n"
2489 "void main() {\n"
2490 " gl_Position = vec4(0, 0, 0, 1);\n"
2491 "}\n";
2492
2493 const std::string fragmentShader =
2494 "#version 300 es\n"
2495 "precision mediump float;\n"
2496 "layout(location = 0) out vec4 floatOutput;\n"
2497 "layout(location = 1) out uvec4 uintOutput;\n"
2498 "layout(location = 2) out ivec4 intOutput;\n"
2499 "void main() {\n"
2500 " floatOutput = vec4(0, 0, 0, 1);\n"
2501 " uintOutput = uvec4(0, 0, 0, 1);\n"
2502 " intOutput = ivec4(0, 0, 0, 1);\n"
2503 "}\n";
2504
2505 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2506 glUseProgram(program.get());
2507
2508 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2509 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2510 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2511
2512 GLFramebuffer fbo;
2513 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2514
2515 GLRenderbuffer floatRenderbuffer;
2516 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2517 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2518 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2519 floatRenderbuffer);
2520
2521 GLRenderbuffer uintRenderbuffer;
2522 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2523 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2524 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2525 uintRenderbuffer);
2526
2527 GLRenderbuffer intRenderbuffer;
2528 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2529 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2530 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2531 intRenderbuffer);
2532
2533 ASSERT_GL_NO_ERROR();
2534
2535 GLint maxDrawBuffers = 0;
2536 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2537 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2538 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2539 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2540 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2541
2542 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2543
2544 // Check that the correct case generates no errors
2545 glDrawArrays(GL_TRIANGLES, 0, 6);
2546 EXPECT_GL_NO_ERROR();
2547
2548 // Unbind some buffers and verify that there are still no errors
2549 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2550 0);
2551 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2552 0);
2553 glDrawArrays(GL_TRIANGLES, 0, 6);
2554 EXPECT_GL_NO_ERROR();
2555
2556 // Swap the int and uint buffers to and verify that an error is generated
2557 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2558 intRenderbuffer);
2559 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2560 uintRenderbuffer);
2561 glDrawArrays(GL_TRIANGLES, 0, 6);
2562 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2563
2564 // Swap the float and uint buffers to and verify that an error is generated
2565 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2566 floatRenderbuffer);
2567 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2568 uintRenderbuffer);
2569 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2570 intRenderbuffer);
2571 glDrawArrays(GL_TRIANGLES, 0, 6);
2572 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2573}
2574
Geoff Lang9ab5b822017-05-30 16:19:23 -04002575// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2576// types
2577TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2578{
2579 const std::string vertexShader =
2580 "#version 300 es\n"
2581 "in vec4 floatInput;\n"
2582 "in uvec4 uintInput;\n"
2583 "in ivec4 intInput;\n"
2584 "void main() {\n"
2585 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2586 "}\n";
2587
2588 const std::string fragmentShader =
2589 "#version 300 es\n"
2590 "precision mediump float;\n"
2591 "out vec4 outputColor;\n"
2592 "void main() {\n"
2593 " outputColor = vec4(0, 0, 0, 1);"
2594 "}\n";
2595
2596 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2597 glUseProgram(program.get());
2598
2599 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2600 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2601 GLint intLocation = glGetAttribLocation(program, "intInput");
2602
2603 // Default attributes are of float types
2604 glDrawArrays(GL_TRIANGLES, 0, 6);
2605 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2606
2607 // Set the default attributes to the correct types, should succeed
2608 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2609 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2610 glDrawArrays(GL_TRIANGLES, 0, 6);
2611 EXPECT_GL_NO_ERROR();
2612
2613 // Change the default float attribute to an integer, should fail
2614 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2615 glDrawArrays(GL_TRIANGLES, 0, 6);
2616 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2617
2618 // Use a buffer for some attributes
2619 GLBuffer buffer;
2620 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2621 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2622 glEnableVertexAttribArray(floatLocation);
2623 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2624 glDrawArrays(GL_TRIANGLES, 0, 6);
2625 EXPECT_GL_NO_ERROR();
2626
2627 // Use a float pointer attrib for a uint input
2628 glEnableVertexAttribArray(uintLocation);
2629 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2630 glDrawArrays(GL_TRIANGLES, 0, 6);
2631 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2632
2633 // Use a uint pointer for the uint input
2634 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2635 glDrawArrays(GL_TRIANGLES, 0, 6);
2636 EXPECT_GL_NO_ERROR();
2637}
2638
Corentin Walleze7557742017-06-01 13:09:57 -04002639// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2640TEST_P(WebGLCompatibilityTest, DrawBuffers)
2641{
Corentin Wallezc084de12017-06-05 14:28:52 -07002642 // TODO(cwallez) AMD incorrectly write black to the first render target when the HLSL pixel
2643 // shader doesn't write anything to the ouput.
2644 if (IsD3D11() && IsAMD())
Corentin Walleze7557742017-06-01 13:09:57 -04002645 {
Corentin Wallezc084de12017-06-05 14:28:52 -07002646 std::cout << "Test skipped on AMD " << GetParam() << std::endl;
Corentin Walleze7557742017-06-01 13:09:57 -04002647 return;
2648 }
2649
2650 // Make sure we can use at least 4 attachments for the tests.
2651 bool useEXT = false;
2652 if (getClientMajorVersion() < 3)
2653 {
2654 if (!extensionRequestable("GL_EXT_draw_buffers"))
2655 {
2656 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2657 return;
2658 }
2659
2660 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2661 useEXT = true;
2662 EXPECT_GL_NO_ERROR();
2663 }
2664
2665 GLint maxDrawBuffers = 0;
2666 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2667 if (maxDrawBuffers < 4)
2668 {
2669 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2670 return;
2671 }
2672
2673 // Clears all the renderbuffers to red.
2674 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2675 GLFramebuffer clearFBO;
2676 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2677
2678 glClearColor(1, 0, 0, 1);
2679 for (int i = 0; i < 4; ++i)
2680 {
2681 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2682 renderbuffers[i]);
2683 glClear(GL_COLOR_BUFFER_BIT);
2684 }
2685 ASSERT_GL_NO_ERROR();
2686 };
2687
2688 // Checks that the renderbuffers specified by mask have the correct color
2689 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2690 GLFramebuffer readFBO;
2691 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2692
2693 for (int i = 0; i < 4; ++i)
2694 {
2695 if (mask & (1 << i))
2696 {
2697 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2698 GL_RENDERBUFFER, renderbuffers[i]);
2699 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2700 }
2701 }
2702 ASSERT_GL_NO_ERROR();
2703 };
2704
2705 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2706 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2707 if (useEXT)
2708 {
2709 glDrawBuffersEXT(numBuffers, buffers);
2710 }
2711 else
2712 {
2713 glDrawBuffers(numBuffers, buffers);
2714 }
2715 };
2716
2717 // Initialized the test framebuffer
2718 GLFramebuffer drawFBO;
2719 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2720
2721 GLRenderbuffer renderbuffers[4];
2722 for (int i = 0; i < 4; ++i)
2723 {
2724 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2725 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2726 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2727 renderbuffers[i]);
2728 }
2729
2730 ASSERT_GL_NO_ERROR();
2731
2732 const char *vertESSL1 =
2733 "attribute vec4 a_pos;\n"
2734 "void main()\n"
2735 "{\n"
2736 " gl_Position = a_pos;\n"
2737 "}\n";
2738 const char *vertESSL3 =
2739 "#version 300 es\n"
2740 "in vec4 a_pos;\n"
2741 "void main()\n"
2742 "{\n"
2743 " gl_Position = a_pos;\n"
2744 "}\n";
2745
2746 GLenum allDrawBuffers[] = {
2747 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2748 };
2749
2750 GLenum halfDrawBuffers[] = {
2751 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2752 };
2753
2754 // Test that when using gl_FragColor, only the first attachment is written to.
2755 const char *fragESSL1 =
2756 "precision highp float;\n"
2757 "void main()\n"
2758 "{\n"
2759 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2760 "}\n";
2761 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2762
2763 {
2764 ClearEverythingToRed(renderbuffers);
2765
2766 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2767 DrawBuffers(useEXT, 4, allDrawBuffers);
2768 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2769 ASSERT_GL_NO_ERROR();
2770
2771 CheckColors(renderbuffers, 0b0001, GLColor::green);
2772 CheckColors(renderbuffers, 0b1110, GLColor::red);
2773 }
2774
2775 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2776 // written to.
2777 {
2778 ClearEverythingToRed(renderbuffers);
2779
2780 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2781 DrawBuffers(useEXT, 4, halfDrawBuffers);
2782 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2783 ASSERT_GL_NO_ERROR();
2784
2785 CheckColors(renderbuffers, 0b1111, GLColor::red);
2786 }
2787
2788 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
2789 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
2790 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
2791 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
2792 // attachments not declared in the shader should not be written to.
2793 const char *writeOddOutputsVert;
2794 const char *writeOddOutputsFrag;
2795 GLColor unwrittenColor;
2796 if (useEXT)
2797 {
2798 // In the extension, when an attachment isn't written to, it should get 0's
2799 unwrittenColor = GLColor(0, 0, 0, 0);
2800 writeOddOutputsVert = vertESSL1;
2801 writeOddOutputsFrag =
2802 "#extension GL_EXT_draw_buffers : require\n"
2803 "precision highp float;\n"
2804 "void main()\n"
2805 "{\n"
2806 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2807 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2808 "}\n";
2809 }
2810 else
2811 {
2812 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
2813 // because of the preceding clears.
2814 unwrittenColor = GLColor::red;
2815 writeOddOutputsVert = vertESSL3;
2816 writeOddOutputsFrag =
2817 "#version 300 es\n"
2818 "precision highp float;\n"
2819 "layout(location = 1) out vec4 output1;"
2820 "layout(location = 3) out vec4 output2;"
2821 "void main()\n"
2822 "{\n"
2823 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2824 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2825 "}\n";
2826 }
2827 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
2828
2829 // Test that attachments not written to get the "unwritten" color
2830 {
2831 ClearEverythingToRed(renderbuffers);
2832
2833 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2834 DrawBuffers(useEXT, 4, allDrawBuffers);
2835 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2836 ASSERT_GL_NO_ERROR();
2837
2838 CheckColors(renderbuffers, 0b1010, GLColor::green);
2839 CheckColors(renderbuffers, 0b0101, unwrittenColor);
2840 }
2841
2842 // Test that attachments not written to get the "unwritten" color but that even when the
2843 // extension is used, disabled attachments are not written at all and stay red.
2844 {
2845 ClearEverythingToRed(renderbuffers);
2846
2847 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2848 DrawBuffers(useEXT, 4, halfDrawBuffers);
2849 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2850 ASSERT_GL_NO_ERROR();
2851
2852 CheckColors(renderbuffers, 0b1000, GLColor::green);
2853 CheckColors(renderbuffers, 0b0100, unwrittenColor);
2854 CheckColors(renderbuffers, 0b0011, GLColor::red);
2855 }
2856}
2857
Frank Henigmanfccbac22017-05-28 17:29:26 -04002858// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
2859// qualifiers.
2860TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
2861{
2862 const std::string vertexShader =
2863 "#version 300 es\n"
2864 "uniform Block { mediump vec4 val; };\n"
2865 "void main() { gl_Position = val; }\n";
2866 const std::string fragmentShader =
2867 "#version 300 es\n"
2868 "uniform Block { highp vec4 val; };\n"
2869 "out highp vec4 out_FragColor;\n"
2870 "void main() { out_FragColor = val; }\n";
2871
2872 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
2873 ASSERT_NE(0u, vs);
2874 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
2875 ASSERT_NE(0u, fs);
2876
2877 GLuint program = glCreateProgram();
2878
2879 glAttachShader(program, vs);
2880 glDeleteShader(vs);
2881 glAttachShader(program, fs);
2882 glDeleteShader(fs);
2883
2884 glLinkProgram(program);
2885 GLint linkStatus;
2886 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
2887 ASSERT_EQ(0, linkStatus);
2888
2889 glDeleteProgram(program);
2890}
2891
Geoff Langc287ea62016-09-16 14:46:51 -04002892// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2893// tests should be run against.
2894ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2895 ES2_D3D9(),
2896 ES2_D3D11(),
2897 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002898 ES2_OPENGL(),
2899 ES3_OPENGL(),
2900 ES2_OPENGLES(),
2901 ES3_OPENGLES());
2902
Jamie Madill07be8bf2017-02-02 19:59:57 -05002903ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04002904} // namespace