blob: eea95531c2cbb2ba2063fd86f2cbac4b7c324aa2 [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
Jamie Madille7b96342017-06-23 15:06:08 -0400297 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400298 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
Jamie Madille7b96342017-06-23 15:06:08 -0400306 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400307 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";
Geoff Langa71a98e2017-06-19 15:15:00 -0400876 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
877 if (getClientMajorVersion() < 3)
878 {
879 invalidSet.push_back('\\');
880 }
Geoff Langfc32e8b2017-05-31 14:16:59 -0400881
882 std::string vert = "attribute float ";
883 vert += validAttribName;
884 vert +=
885 ";\n"
886 "void main()\n"
887 "{\n"
888 " gl_Position = vec4(1.0);\n"
889 "}\n";
890
891 std::string frag =
892 "precision highp float;\n"
893 "uniform vec4 ";
894 frag += validUniformName;
895 frag +=
896 ";\n"
897 "void main()\n"
898 "{\n"
899 " gl_FragColor = vec4(1.0);\n"
900 "}\n";
901
902 ANGLE_GL_PROGRAM(program, vert, frag);
903 EXPECT_GL_NO_ERROR();
904
905 for (char invalidChar : invalidSet)
906 {
907 std::string invalidName = validAttribName + invalidChar;
908 glGetAttribLocation(program, invalidName.c_str());
909 EXPECT_GL_ERROR(GL_INVALID_VALUE)
910 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
911
912 glBindAttribLocation(program, 0, invalidName.c_str());
913 EXPECT_GL_ERROR(GL_INVALID_VALUE)
914 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
915 }
916
917 for (char invalidChar : invalidSet)
918 {
919 std::string invalidName = validUniformName + invalidChar;
920 glGetUniformLocation(program, invalidName.c_str());
921 EXPECT_GL_ERROR(GL_INVALID_VALUE)
922 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
923 }
924
925 for (char invalidChar : invalidSet)
926 {
927 std::string invalidAttribName = validAttribName + invalidChar;
928 const char *invalidVert[] = {
929 "attribute float ",
930 invalidAttribName.c_str(),
931 ";\n",
932 "void main()\n",
933 "{\n",
934 " gl_Position = vec4(1.0);\n",
935 "}\n",
936 };
937
938 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
939 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
940 EXPECT_GL_ERROR(GL_INVALID_VALUE);
941 glDeleteShader(shader);
942 }
943}
944
Corentin Wallezfd456442016-12-21 17:57:00 -0500945// Test the checks for OOB reads in the vertex buffers, instanced version
946TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
947{
948 const std::string &vert =
949 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400950 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500951 "void main()\n"
952 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400953 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500954 "}\n";
955
956 const std::string &frag =
957 "precision highp float;\n"
958 "void main()\n"
959 "{\n"
960 " gl_FragColor = vec4(1.0);\n"
961 "}\n";
962
963 ANGLE_GL_PROGRAM(program, vert, frag);
964
965 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
966 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -0400967
968 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
969 ASSERT_NE(-1, wLocation);
970
Corentin Wallezfd456442016-12-21 17:57:00 -0500971 glUseProgram(program.get());
972
973 GLBuffer buffer;
974 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
975 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
976
977 glEnableVertexAttribArray(posLocation);
978 glVertexAttribDivisor(posLocation, 1);
979
Geoff Lang407d4e72017-04-12 14:54:11 -0400980 glEnableVertexAttribArray(wLocation);
981 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
982 glVertexAttribDivisor(wLocation, 0);
983
Corentin Wallezfd456442016-12-21 17:57:00 -0500984 const uint8_t* zeroOffset = nullptr;
985
986 // Test touching the last element is valid.
987 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
988 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
989 ASSERT_GL_NO_ERROR();
990
991 // Test touching the last element + 1 is invalid.
992 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
993 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
994 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
995
996 // Test touching the last element is valid, using a stride.
997 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
998 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
999 ASSERT_GL_NO_ERROR();
1000
1001 // Test touching the last element + 1 is invalid, using a stride.
1002 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1003 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1004 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1005
1006 // Test any offset is valid if no vertices are drawn.
1007 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1008 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1009 ASSERT_GL_NO_ERROR();
1010}
1011
Corentin Wallez0dc97812017-06-22 14:38:44 -04001012// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001013TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1014{
1015 const std::string &vert =
1016 "attribute float a_pos;\n"
1017 "void main()\n"
1018 "{\n"
1019 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1020 "}\n";
1021
1022 const std::string &frag =
1023 "precision highp float;\n"
1024 "void main()\n"
1025 "{\n"
1026 " gl_FragColor = vec4(1.0);\n"
1027 "}\n";
1028
1029 ANGLE_GL_PROGRAM(program, vert, frag);
1030
1031 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1032 ASSERT_NE(-1, posLocation);
1033
1034 glUseProgram(program.get());
1035
1036 GLBuffer buffer;
1037 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1038 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1039
1040 glEnableVertexAttribArray(posLocation);
1041 glVertexAttribDivisor(posLocation, 1);
1042
Geoff Lang407d4e72017-04-12 14:54:11 -04001043 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1044 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001045 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
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04001514// Tests global namespace conflicts between uniforms and attributes.
1515// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
1516TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
1517{
1518 const std::string vertexShader =
1519 "attribute vec4 foo;\n"
1520 "void main()\n"
1521 "{\n"
1522 " gl_Position = foo;\n"
1523 "}";
1524 const std::string fragmentShader =
1525 "precision mediump float;\n"
1526 "uniform vec4 foo;\n"
1527 "void main()\n"
1528 "{\n"
1529 " gl_FragColor = foo;\n"
1530 "}";
1531
1532 GLuint program = CompileProgram(vertexShader, fragmentShader);
1533 EXPECT_EQ(0u, program);
1534}
1535
Geoff Lang966c9402017-04-18 12:38:27 -04001536// Test dimension and image size validation of compressed textures
1537TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1538{
1539 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1540 {
1541 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1542 }
1543
1544 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1545 {
1546 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1547 << std::endl;
1548 return;
1549 }
1550
1551 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1552
1553 GLTexture texture;
1554 glBindTexture(GL_TEXTURE_2D, texture);
1555
1556 // Regular case, verify that it works
1557 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1558 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1559 ASSERT_GL_NO_ERROR();
1560
1561 // Test various dimensions that are not valid
1562 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1563 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1564 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1565
1566 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1567 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1568 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1569
1570 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1571 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1572 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1573
1574 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1575 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1576 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1577
1578 // Test various image sizes that are not valid
1579 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1580 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1581 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1582
1583 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1584 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1585 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1586
1587 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1588 CompressedImageDXT1);
1589 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1590
1591 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1592 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1593 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1594
1595 // Fill a full mip chain and verify that it works
1596 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1597 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1598 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1599 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1600 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1601 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1602 ASSERT_GL_NO_ERROR();
1603
1604 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1605 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1606 ASSERT_GL_NO_ERROR();
1607
1608 // Test that non-block size sub-uploads are not valid for the 0 mip
1609 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1610 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1611 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1612
1613 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1614 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1615 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1616 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1617 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1618 ASSERT_GL_NO_ERROR();
1619
1620 // Test that if the format miss-matches the texture, an error is generated
1621 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1622 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1623 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1624}
1625
Geoff Lang677bb6f2017-04-05 12:40:40 -04001626TEST_P(WebGLCompatibilityTest, L32FTextures)
1627{
1628 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1629 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1630
1631 for (auto extension : FloatingPointTextureExtensions)
1632 {
1633 if (strlen(extension) > 0 && extensionRequestable(extension))
1634 {
1635 glRequestExtensionANGLE(extension);
1636 ASSERT_GL_NO_ERROR();
1637 }
1638
1639 // Unsized L 32F
1640 {
1641 bool texture = extensionEnabled("GL_OES_texture_float");
1642 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1643 bool render = false;
1644 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1645 textureData, readPixelData);
1646 }
1647
1648 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1649 {
1650 // Sized L 32F
1651 bool texture = extensionEnabled("GL_OES_texture_float") &&
1652 extensionEnabled("GL_EXT_texture_storage");
1653 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1654 bool render = false;
1655 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1656 render, textureData, readPixelData);
1657 }
1658 }
1659}
1660
1661TEST_P(WebGLCompatibilityTest, A32FTextures)
1662{
1663 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1664 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1665
1666 for (auto extension : FloatingPointTextureExtensions)
1667 {
1668 if (strlen(extension) > 0 && extensionRequestable(extension))
1669 {
1670 glRequestExtensionANGLE(extension);
1671 ASSERT_GL_NO_ERROR();
1672 }
1673
1674 // Unsized A 32F
1675 {
1676 bool texture = extensionEnabled("GL_OES_texture_float");
1677 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1678 bool render = false;
1679 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1680 textureData, readPixelData);
1681 }
1682
1683 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1684 {
1685 // Sized A 32F
1686 bool texture = extensionEnabled("GL_OES_texture_float") &&
1687 extensionEnabled("GL_EXT_texture_storage");
1688 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1689 bool render = false;
1690 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1691 textureData, readPixelData);
1692 }
1693 }
1694}
1695
1696TEST_P(WebGLCompatibilityTest, LA32FTextures)
1697{
1698 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1699 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1700 textureData[1]};
1701
1702 for (auto extension : FloatingPointTextureExtensions)
1703 {
1704 if (strlen(extension) > 0 && extensionRequestable(extension))
1705 {
1706 glRequestExtensionANGLE(extension);
1707 ASSERT_GL_NO_ERROR();
1708 }
1709
1710 // Unsized LA 32F
1711 {
1712 bool texture = extensionEnabled("GL_OES_texture_float");
1713 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1714 bool render = false;
1715 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1716 filter, render, textureData, readPixelData);
1717 }
1718
1719 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1720 {
1721 // Sized LA 32F
1722 bool texture = extensionEnabled("GL_OES_texture_float") &&
1723 extensionEnabled("GL_EXT_texture_storage");
1724 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1725 bool render = false;
1726 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1727 filter, render, textureData, readPixelData);
1728 }
1729 }
1730}
1731
1732TEST_P(WebGLCompatibilityTest, R32FTextures)
1733{
1734 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1735
1736 for (auto extension : FloatingPointTextureExtensions)
1737 {
1738 if (strlen(extension) > 0 && extensionRequestable(extension))
1739 {
1740 glRequestExtensionANGLE(extension);
1741 ASSERT_GL_NO_ERROR();
1742 }
1743
1744 // Unsized R 32F
1745 {
1746 bool texture =
1747 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1748 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1749 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1750 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1751 }
1752
1753 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1754 {
1755 // Sized R 32F
1756 bool texture =
1757 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1758 extensionEnabled("GL_EXT_texture_rg") &&
1759 extensionEnabled("GL_EXT_texture_storage"));
1760 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1761 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1762 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1763 }
1764 }
1765}
1766
1767TEST_P(WebGLCompatibilityTest, RG32FTextures)
1768{
1769 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1770
1771 for (auto extension : FloatingPointTextureExtensions)
1772 {
1773 if (strlen(extension) > 0 && extensionRequestable(extension))
1774 {
1775 glRequestExtensionANGLE(extension);
1776 ASSERT_GL_NO_ERROR();
1777 }
1778
1779 // Unsized RG 32F
1780 {
1781 bool texture =
1782 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1783 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1784 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1785 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1786 }
1787
1788 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1789 {
1790 // Sized RG 32F
1791 bool texture =
1792 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1793 extensionEnabled("GL_EXT_texture_rg") &&
1794 extensionEnabled("GL_EXT_texture_storage"));
1795 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1796 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1797 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1798 }
1799 }
1800}
1801
1802TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1803{
Geoff Lang40762ef2017-05-08 13:47:03 -04001804 if (IsLinux() && IsIntel())
1805 {
1806 std::cout << "Test skipped on Linux Intel." << std::endl;
1807 return;
1808 }
1809
Geoff Lang677bb6f2017-04-05 12:40:40 -04001810 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1811
1812 for (auto extension : FloatingPointTextureExtensions)
1813 {
1814 if (strlen(extension) > 0 && extensionRequestable(extension))
1815 {
1816 glRequestExtensionANGLE(extension);
1817 ASSERT_GL_NO_ERROR();
1818 }
1819
1820 // Unsized RGB 32F
1821 {
1822 bool texture = extensionEnabled("GL_OES_texture_float");
1823 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1824 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1825 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
1826 }
1827
1828 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1829 {
1830 // Sized RGBA 32F
1831 bool texture =
1832 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1833 extensionEnabled("GL_EXT_texture_storage"));
1834 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1835 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1836 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
1837 data);
1838 }
1839 }
1840}
1841
1842TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
1843{
1844 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1845
1846 for (auto extension : FloatingPointTextureExtensions)
1847 {
1848 if (strlen(extension) > 0 && extensionRequestable(extension))
1849 {
1850 glRequestExtensionANGLE(extension);
1851 ASSERT_GL_NO_ERROR();
1852 }
1853
1854 // Unsized RGBA 32F
1855 {
1856 bool texture = extensionEnabled("GL_OES_texture_float");
1857 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1858 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1859 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1860 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
1861 }
1862
1863 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1864 {
1865 // Sized RGBA 32F
1866 bool texture =
1867 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1868 extensionEnabled("GL_EXT_texture_storage"));
1869 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1870 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1871 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1872 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
1873 data);
1874 }
1875 }
1876}
1877
1878TEST_P(WebGLCompatibilityTest, R16FTextures)
1879{
1880 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
1881 const GLushort textureData[] = {
1882 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1883 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1884
1885 for (auto extension : FloatingPointTextureExtensions)
1886 {
1887 if (strlen(extension) > 0 && extensionRequestable(extension))
1888 {
1889 glRequestExtensionANGLE(extension);
1890 ASSERT_GL_NO_ERROR();
1891 }
1892
1893 // Unsized R 16F (OES)
1894 {
1895 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1896 extensionEnabled("GL_EXT_texture_rg");
1897 bool filter = getClientMajorVersion() >= 3 ||
1898 extensionEnabled("GL_OES_texture_half_float_linear");
1899 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1900 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
1901 textureData, readPixelsData);
1902 }
1903
1904 // Unsized R 16F
1905 {
1906 bool texture = false;
1907 bool filter = false;
1908 bool render = false;
1909 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1910 textureData, readPixelsData);
1911 }
1912
1913 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1914 {
1915 // Sized R 16F
1916 bool texture = getClientMajorVersion() >= 3;
1917 bool filter = getClientMajorVersion() >= 3 ||
1918 extensionEnabled("GL_OES_texture_half_float_linear");
1919 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1920 extensionEnabled("GL_EXT_color_buffer_float");
1921 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1922 textureData, readPixelsData);
1923 }
1924 }
1925}
1926
1927TEST_P(WebGLCompatibilityTest, RG16FTextures)
1928{
1929 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
1930 const GLushort textureData[] = {
1931 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1932 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1933
1934 for (auto extension : FloatingPointTextureExtensions)
1935 {
1936 if (strlen(extension) > 0 && extensionRequestable(extension))
1937 {
1938 glRequestExtensionANGLE(extension);
1939 ASSERT_GL_NO_ERROR();
1940 }
1941
1942 // Unsized RG 16F (OES)
1943 {
1944 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1945 extensionEnabled("GL_EXT_texture_rg");
1946 bool filter = getClientMajorVersion() >= 3 ||
1947 extensionEnabled("GL_OES_texture_half_float_linear");
1948 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
1949 extensionEnabled("GL_EXT_texture_rg");
1950 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
1951 textureData, readPixelsData);
1952 }
1953
1954 // Unsized RG 16F
1955 {
1956 bool texture = false;
1957 bool filter = false;
1958 bool render = false;
1959 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1960 textureData, readPixelsData);
1961 }
1962
1963 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1964 {
1965 // Sized RG 16F
1966 bool texture = getClientMajorVersion() >= 3;
1967 bool filter = getClientMajorVersion() >= 3 ||
1968 extensionEnabled("GL_OES_texture_half_float_linear");
1969 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1970 extensionEnabled("GL_EXT_color_buffer_float");
1971 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1972 textureData, readPixelsData);
1973 }
1974 }
1975}
1976
1977TEST_P(WebGLCompatibilityTest, RGB16FTextures)
1978{
Geoff Lang40762ef2017-05-08 13:47:03 -04001979 if (IsOzone() && IsIntel())
1980 {
1981 std::cout << "Test skipped on Intel Ozone." << std::endl;
1982 return;
1983 }
1984
Geoff Lang677bb6f2017-04-05 12:40:40 -04001985 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
1986 const GLushort textureData[] = {
1987 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1988 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1989
1990 for (auto extension : FloatingPointTextureExtensions)
1991 {
1992 if (strlen(extension) > 0 && extensionRequestable(extension))
1993 {
1994 glRequestExtensionANGLE(extension);
1995 ASSERT_GL_NO_ERROR();
1996 }
1997
1998 // Unsized RGB 16F (OES)
1999 {
2000 bool texture = extensionEnabled("GL_OES_texture_half_float");
2001 bool filter = getClientMajorVersion() >= 3 ||
2002 extensionEnabled("GL_OES_texture_half_float_linear");
2003 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2004 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2005 textureData, readPixelsData);
2006 }
2007
2008 // Unsized RGB 16F
2009 {
2010 bool texture = false;
2011 bool filter = false;
2012 bool render = false;
2013 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2014 textureData, readPixelsData);
2015 }
2016
2017 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2018 {
2019 // Sized RGB 16F
2020 bool texture = getClientMajorVersion() >= 3;
2021 bool filter = getClientMajorVersion() >= 3 ||
2022 extensionEnabled("GL_OES_texture_half_float_linear");
2023 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2024 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2025 textureData, readPixelsData);
2026 }
2027 }
2028}
2029
2030TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2031{
Geoff Lang40762ef2017-05-08 13:47:03 -04002032 if (IsOzone() && IsIntel())
2033 {
2034 std::cout << "Test skipped on Intel Ozone." << std::endl;
2035 return;
2036 }
2037
Geoff Lang677bb6f2017-04-05 12:40:40 -04002038 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2039 const GLushort textureData[] = {
2040 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2041 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2042
2043 for (auto extension : FloatingPointTextureExtensions)
2044 {
2045 if (strlen(extension) > 0 && extensionRequestable(extension))
2046 {
2047 glRequestExtensionANGLE(extension);
2048 ASSERT_GL_NO_ERROR();
2049 }
2050
2051 // Unsized RGBA 16F (OES)
2052 {
2053 bool texture = extensionEnabled("GL_OES_texture_half_float");
2054 bool filter = getClientMajorVersion() >= 3 ||
2055 extensionEnabled("GL_OES_texture_half_float_linear");
2056 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2057 extensionEnabled("GL_EXT_color_buffer_float");
2058 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2059 textureData, readPixelsData);
2060 }
2061
2062 // Unsized RGBA 16F
2063 {
2064 bool texture = false;
2065 bool filter = false;
2066 bool render = false;
2067 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2068 textureData, readPixelsData);
2069 }
2070
2071 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2072 {
2073 // Sized RGBA 16F
2074 bool texture = getClientMajorVersion() >= 3;
2075 bool filter = getClientMajorVersion() >= 3 ||
2076 extensionEnabled("GL_OES_texture_half_float_linear");
2077 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2078 extensionEnabled("GL_EXT_color_buffer_float");
2079 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2080 textureData, readPixelsData);
2081 }
2082 }
2083}
2084
Geoff Lang6e898aa2017-06-02 11:17:26 -04002085// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2086// accepted by glTexImage2D
2087TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2088{
2089 if (getClientMajorVersion() != 2)
2090 {
2091 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2092 return;
2093 }
2094
2095 if (!extensionRequestable("GL_OES_texture_float"))
2096 {
2097 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2098 return;
2099 }
2100 glRequestExtensionANGLE("GL_OES_texture_float");
2101 ASSERT_GL_NO_ERROR();
2102
2103 GLTexture texture;
2104 glBindTexture(GL_TEXTURE_2D, texture);
2105
2106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2107 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2108
2109 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2110 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2111
2112 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2113 {
2114 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2115 ASSERT_GL_NO_ERROR();
2116
2117 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2118 EXPECT_GL_NO_ERROR();
2119 }
2120
2121 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2122 {
2123 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2124 ASSERT_GL_NO_ERROR();
2125
2126 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2127 EXPECT_GL_NO_ERROR();
2128 }
2129}
2130
Jamie Madill07be8bf2017-02-02 19:59:57 -05002131// This tests that rendering feedback loops works as expected with WebGL 2.
2132// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2133TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2134{
2135 const std::string vertexShader =
2136 "#version 300 es\n"
2137 "in vec4 aPosition;\n"
2138 "out vec2 texCoord;\n"
2139 "void main() {\n"
2140 " gl_Position = aPosition;\n"
2141 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2142 "}\n";
2143
2144 const std::string fragmentShader =
2145 "#version 300 es\n"
2146 "precision mediump float;\n"
2147 "uniform sampler2D tex;\n"
2148 "in vec2 texCoord;\n"
2149 "out vec4 oColor;\n"
2150 "void main() {\n"
2151 " oColor = texture(tex, texCoord);\n"
2152 "}\n";
2153
2154 GLsizei width = 8;
2155 GLsizei height = 8;
2156
2157 GLint maxDrawBuffers = 0;
2158 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2159 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2160 ASSERT_GE(maxDrawBuffers, 2);
2161
2162 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2163 glUseProgram(program.get());
2164 glViewport(0, 0, width, height);
2165
2166 GLTexture tex0;
2167 GLTexture tex1;
2168 GLFramebuffer fbo;
2169 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2170 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2171 ASSERT_GL_NO_ERROR();
2172
2173 glBindTexture(GL_TEXTURE_2D, tex1.get());
2174 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2175 ASSERT_NE(-1, texLoc);
2176 glUniform1i(texLoc, 0);
2177
2178 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2179 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2180 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2181 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2182 ASSERT_GL_NO_ERROR();
2183
2184 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2185 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2186 GL_INVALID_OPERATION);
2187 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2188}
2189
Jamie Madill1d37bc52017-02-02 19:59:58 -05002190// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2191// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2192TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2193{
2194 const std::string vertexShader =
2195 "#version 300 es\n"
2196 "in vec4 aPosition;\n"
2197 "out vec2 texCoord;\n"
2198 "void main() {\n"
2199 " gl_Position = aPosition;\n"
2200 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2201 "}\n";
2202
2203 const std::string fragmentShader =
2204 "#version 300 es\n"
2205 "precision mediump float;\n"
2206 "uniform sampler2D tex;\n"
2207 "in vec2 texCoord;\n"
2208 "out vec4 oColor;\n"
2209 "void main() {\n"
2210 " oColor = texture(tex, texCoord);\n"
2211 "}\n";
2212
2213 GLsizei width = 8;
2214 GLsizei height = 8;
2215
2216 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2217 glUseProgram(program.get());
2218
2219 glViewport(0, 0, width, height);
2220
2221 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2222 glUniform1i(texLoc, 0);
2223
2224 // Create textures and allocate storage
2225 GLTexture tex0;
2226 GLTexture tex1;
2227 GLRenderbuffer rb;
2228 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2229 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2230 GL_UNSIGNED_INT);
2231 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2232 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2233 ASSERT_GL_NO_ERROR();
2234
2235 GLFramebuffer fbo;
2236 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2237 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2238
2239 // Test rendering and sampling feedback loop for depth buffer
2240 glBindTexture(GL_TEXTURE_2D, tex1.get());
2241 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2242 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2243
2244 // The same image is used as depth buffer during rendering.
2245 glEnable(GL_DEPTH_TEST);
2246 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2247 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2248
2249 // The same image is used as depth buffer. But depth mask is false.
2250 glDepthMask(GL_FALSE);
2251 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2252 EXPECT_GL_NO_ERROR();
2253
2254 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2255 glDepthMask(GL_TRUE);
2256 glDisable(GL_DEPTH_TEST);
2257 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2258 EXPECT_GL_NO_ERROR();
2259
2260 // Test rendering and sampling feedback loop for stencil buffer
2261 glBindTexture(GL_RENDERBUFFER, rb.get());
2262 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2263 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2264 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2265 constexpr GLint stencilClearValue = 0x40;
2266 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2267
2268 // The same image is used as stencil buffer during rendering.
2269 glEnable(GL_STENCIL_TEST);
2270 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2271 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2272
2273 // The same image is used as stencil buffer. But stencil mask is zero.
2274 glStencilMask(0x0);
2275 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2276 EXPECT_GL_NO_ERROR();
2277
2278 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2279 glStencilMask(0xffff);
2280 glDisable(GL_STENCIL_TEST);
2281 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2282 EXPECT_GL_NO_ERROR();
2283}
2284
Jamie Madillfd3dd432017-02-02 19:59:59 -05002285// The source and the target for CopyTexSubImage3D are the same 3D texture.
2286// But the level of the 3D texture != the level of the read attachment.
2287TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2288{
2289 GLTexture texture;
2290 GLFramebuffer framebuffer;
2291
2292 glBindTexture(GL_TEXTURE_3D, texture.get());
2293 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2294
2295 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2296 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2297 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2298 ASSERT_GL_NO_ERROR();
2299
2300 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2301 EXPECT_GL_NO_ERROR();
2302}
2303
2304// The source and the target for CopyTexSubImage3D are the same 3D texture.
2305// But the zoffset of the 3D texture != the layer of the read attachment.
2306TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2307{
2308 GLTexture texture;
2309 GLFramebuffer framebuffer;
2310
2311 glBindTexture(GL_TEXTURE_3D, texture.get());
2312 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2313
2314 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2315 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2316 ASSERT_GL_NO_ERROR();
2317
2318 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2319 EXPECT_GL_NO_ERROR();
2320}
2321
2322// The source and the target for CopyTexSubImage3D are the same 3D texture.
2323// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2324TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2325{
2326 GLTexture texture;
2327 GLFramebuffer framebuffer;
2328
2329 glBindTexture(GL_TEXTURE_3D, texture.get());
2330 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2331
2332 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2333 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2334 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2335 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2336 ASSERT_GL_NO_ERROR();
2337
2338 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2339 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2340}
2341
Corentin Wallez59c41592017-07-11 13:19:54 -04002342// Verify that errors are generated when there isn't a defined conversion between the clear type and
2343// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04002344TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2345{
2346 if (IsD3D11())
2347 {
2348 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2349 return;
2350 }
2351
2352 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2353 constexpr int clearInt[] = {0, 0, 0, 0};
2354 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2355
2356 GLTexture texture;
2357 GLFramebuffer framebuffer;
2358
2359 glBindTexture(GL_TEXTURE_2D, texture.get());
2360 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2361
2362 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2363 ASSERT_GL_NO_ERROR();
2364
2365 // Unsigned integer buffer
2366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2367 ASSERT_GL_NO_ERROR();
2368
2369 glClearBufferfv(GL_COLOR, 0, clearFloat);
2370 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2371
2372 glClearBufferiv(GL_COLOR, 0, clearInt);
2373 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2374
2375 glClearBufferuiv(GL_COLOR, 0, clearUint);
2376 EXPECT_GL_NO_ERROR();
2377
2378 glClear(GL_COLOR_BUFFER_BIT);
2379 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2380
2381 // Integer buffer
2382 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2383 ASSERT_GL_NO_ERROR();
2384
2385 glClearBufferfv(GL_COLOR, 0, clearFloat);
2386 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2387
2388 glClearBufferiv(GL_COLOR, 0, clearInt);
2389 EXPECT_GL_NO_ERROR();
2390
2391 glClearBufferuiv(GL_COLOR, 0, clearUint);
2392 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2393
2394 glClear(GL_COLOR_BUFFER_BIT);
2395 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2396
2397 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002398 if (extensionRequestable("GL_EXT_color_buffer_float"))
2399 {
2400 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2401 }
Geoff Lang76e65652017-03-27 14:58:02 -04002402
Geoff Lang677bb6f2017-04-05 12:40:40 -04002403 if (extensionEnabled("GL_EXT_color_buffer_float"))
2404 {
2405 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2406 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002407
Geoff Lang677bb6f2017-04-05 12:40:40 -04002408 glClearBufferfv(GL_COLOR, 0, clearFloat);
2409 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002410
Geoff Lang677bb6f2017-04-05 12:40:40 -04002411 glClearBufferiv(GL_COLOR, 0, clearInt);
2412 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002413
Geoff Lang677bb6f2017-04-05 12:40:40 -04002414 glClearBufferuiv(GL_COLOR, 0, clearUint);
2415 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2416
2417 glClear(GL_COLOR_BUFFER_BIT);
2418 EXPECT_GL_NO_ERROR();
2419 }
Geoff Lang76e65652017-03-27 14:58:02 -04002420
2421 // Normalized uint buffer
2422 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2423 ASSERT_GL_NO_ERROR();
2424
2425 glClearBufferfv(GL_COLOR, 0, clearFloat);
2426 EXPECT_GL_NO_ERROR();
2427
2428 glClearBufferiv(GL_COLOR, 0, clearInt);
2429 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2430
2431 glClearBufferuiv(GL_COLOR, 0, clearUint);
2432 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2433
2434 glClear(GL_COLOR_BUFFER_BIT);
2435 EXPECT_GL_NO_ERROR();
2436}
2437
Corentin Wallez59c41592017-07-11 13:19:54 -04002438// Test the interaction of WebGL compatibility clears with default framebuffers
2439TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
2440{
2441 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2442 constexpr int clearInt[] = {0, 0, 0, 0};
2443 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2444
2445 // glClear works as usual, this is also a regression test for a bug where we
2446 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
2447 glClear(GL_COLOR_BUFFER_BIT);
2448 EXPECT_GL_NO_ERROR();
2449
2450 // Default framebuffers are normalized uints, so only glClearBufferfv works.
2451 glClearBufferfv(GL_COLOR, 0, clearFloat);
2452 EXPECT_GL_NO_ERROR();
2453
2454 glClearBufferiv(GL_COLOR, 0, clearInt);
2455 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2456
2457 glClearBufferuiv(GL_COLOR, 0, clearUint);
2458 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2459}
2460
Geoff Lange4915782017-04-12 15:19:07 -04002461// Verify that errors are generate when trying to blit from an image to itself
2462TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2463{
2464 GLTexture textures[2];
2465 glBindTexture(GL_TEXTURE_2D, textures[0]);
2466 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2467 glBindTexture(GL_TEXTURE_2D, textures[1]);
2468 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2469
2470 GLRenderbuffer renderbuffers[2];
2471 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2472 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2473 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2474 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2475
2476 GLFramebuffer framebuffers[2];
2477 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2478 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2479
2480 ASSERT_GL_NO_ERROR();
2481
2482 // Same texture
2483 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2484 0);
2485 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2486 0);
2487 ASSERT_GL_NO_ERROR();
2488 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2489 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2490
2491 // Same textures but different renderbuffers
2492 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2493 renderbuffers[0]);
2494 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2495 renderbuffers[1]);
2496 ASSERT_GL_NO_ERROR();
2497 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2498 ASSERT_GL_NO_ERROR();
2499 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2500 GL_NEAREST);
2501 ASSERT_GL_NO_ERROR();
2502 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2503 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2504 GL_NEAREST);
2505 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2506
2507 // Same renderbuffers but different textures
2508 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2509 0);
2510 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2511 0);
2512 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2513 renderbuffers[0]);
2514 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2515 renderbuffers[0]);
2516 ASSERT_GL_NO_ERROR();
2517 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2518 ASSERT_GL_NO_ERROR();
2519 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2520 GL_NEAREST);
2521 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2522 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2523 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2524 GL_NEAREST);
2525 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2526}
2527
Geoff Lange0cff192017-05-30 13:04:56 -04002528// Verify that errors are generated when the fragment shader output doesn't match the bound color
2529// buffer types
2530TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2531{
2532 const std::string vertexShader =
2533 "#version 300 es\n"
2534 "void main() {\n"
2535 " gl_Position = vec4(0, 0, 0, 1);\n"
2536 "}\n";
2537
2538 const std::string fragmentShader =
2539 "#version 300 es\n"
2540 "precision mediump float;\n"
2541 "layout(location = 0) out vec4 floatOutput;\n"
2542 "layout(location = 1) out uvec4 uintOutput;\n"
2543 "layout(location = 2) out ivec4 intOutput;\n"
2544 "void main() {\n"
2545 " floatOutput = vec4(0, 0, 0, 1);\n"
2546 " uintOutput = uvec4(0, 0, 0, 1);\n"
2547 " intOutput = ivec4(0, 0, 0, 1);\n"
2548 "}\n";
2549
2550 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2551 glUseProgram(program.get());
2552
2553 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2554 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2555 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2556
2557 GLFramebuffer fbo;
2558 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2559
2560 GLRenderbuffer floatRenderbuffer;
2561 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2562 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2563 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2564 floatRenderbuffer);
2565
2566 GLRenderbuffer uintRenderbuffer;
2567 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2568 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2569 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2570 uintRenderbuffer);
2571
2572 GLRenderbuffer intRenderbuffer;
2573 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2574 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2575 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2576 intRenderbuffer);
2577
2578 ASSERT_GL_NO_ERROR();
2579
2580 GLint maxDrawBuffers = 0;
2581 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2582 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2583 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2584 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2585 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2586
2587 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2588
2589 // Check that the correct case generates no errors
2590 glDrawArrays(GL_TRIANGLES, 0, 6);
2591 EXPECT_GL_NO_ERROR();
2592
2593 // Unbind some buffers and verify that there are still no errors
2594 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2595 0);
2596 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2597 0);
2598 glDrawArrays(GL_TRIANGLES, 0, 6);
2599 EXPECT_GL_NO_ERROR();
2600
2601 // Swap the int and uint buffers to and verify that an error is generated
2602 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2603 intRenderbuffer);
2604 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2605 uintRenderbuffer);
2606 glDrawArrays(GL_TRIANGLES, 0, 6);
2607 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2608
2609 // Swap the float and uint buffers to and verify that an error is generated
2610 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2611 floatRenderbuffer);
2612 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2613 uintRenderbuffer);
2614 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2615 intRenderbuffer);
2616 glDrawArrays(GL_TRIANGLES, 0, 6);
2617 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2618}
2619
Geoff Lang9ab5b822017-05-30 16:19:23 -04002620// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2621// types
2622TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2623{
2624 const std::string vertexShader =
2625 "#version 300 es\n"
2626 "in vec4 floatInput;\n"
2627 "in uvec4 uintInput;\n"
2628 "in ivec4 intInput;\n"
2629 "void main() {\n"
2630 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2631 "}\n";
2632
2633 const std::string fragmentShader =
2634 "#version 300 es\n"
2635 "precision mediump float;\n"
2636 "out vec4 outputColor;\n"
2637 "void main() {\n"
2638 " outputColor = vec4(0, 0, 0, 1);"
2639 "}\n";
2640
2641 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2642 glUseProgram(program.get());
2643
2644 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2645 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2646 GLint intLocation = glGetAttribLocation(program, "intInput");
2647
2648 // Default attributes are of float types
2649 glDrawArrays(GL_TRIANGLES, 0, 6);
2650 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2651
2652 // Set the default attributes to the correct types, should succeed
2653 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2654 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2655 glDrawArrays(GL_TRIANGLES, 0, 6);
2656 EXPECT_GL_NO_ERROR();
2657
2658 // Change the default float attribute to an integer, should fail
2659 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2660 glDrawArrays(GL_TRIANGLES, 0, 6);
2661 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2662
2663 // Use a buffer for some attributes
2664 GLBuffer buffer;
2665 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2666 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2667 glEnableVertexAttribArray(floatLocation);
2668 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2669 glDrawArrays(GL_TRIANGLES, 0, 6);
2670 EXPECT_GL_NO_ERROR();
2671
2672 // Use a float pointer attrib for a uint input
2673 glEnableVertexAttribArray(uintLocation);
2674 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2675 glDrawArrays(GL_TRIANGLES, 0, 6);
2676 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2677
2678 // Use a uint pointer for the uint input
2679 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2680 glDrawArrays(GL_TRIANGLES, 0, 6);
2681 EXPECT_GL_NO_ERROR();
2682}
2683
Corentin Walleze7557742017-06-01 13:09:57 -04002684// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2685TEST_P(WebGLCompatibilityTest, DrawBuffers)
2686{
Corentin Walleze7557742017-06-01 13:09:57 -04002687 // Make sure we can use at least 4 attachments for the tests.
2688 bool useEXT = false;
2689 if (getClientMajorVersion() < 3)
2690 {
2691 if (!extensionRequestable("GL_EXT_draw_buffers"))
2692 {
2693 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2694 return;
2695 }
2696
2697 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2698 useEXT = true;
2699 EXPECT_GL_NO_ERROR();
2700 }
2701
2702 GLint maxDrawBuffers = 0;
2703 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2704 if (maxDrawBuffers < 4)
2705 {
2706 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2707 return;
2708 }
2709
2710 // Clears all the renderbuffers to red.
2711 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2712 GLFramebuffer clearFBO;
2713 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2714
2715 glClearColor(1, 0, 0, 1);
2716 for (int i = 0; i < 4; ++i)
2717 {
2718 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2719 renderbuffers[i]);
2720 glClear(GL_COLOR_BUFFER_BIT);
2721 }
2722 ASSERT_GL_NO_ERROR();
2723 };
2724
2725 // Checks that the renderbuffers specified by mask have the correct color
2726 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2727 GLFramebuffer readFBO;
2728 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2729
2730 for (int i = 0; i < 4; ++i)
2731 {
2732 if (mask & (1 << i))
2733 {
2734 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2735 GL_RENDERBUFFER, renderbuffers[i]);
2736 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2737 }
2738 }
2739 ASSERT_GL_NO_ERROR();
2740 };
2741
2742 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2743 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2744 if (useEXT)
2745 {
2746 glDrawBuffersEXT(numBuffers, buffers);
2747 }
2748 else
2749 {
2750 glDrawBuffers(numBuffers, buffers);
2751 }
2752 };
2753
2754 // Initialized the test framebuffer
2755 GLFramebuffer drawFBO;
2756 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2757
2758 GLRenderbuffer renderbuffers[4];
2759 for (int i = 0; i < 4; ++i)
2760 {
2761 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2762 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2763 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2764 renderbuffers[i]);
2765 }
2766
2767 ASSERT_GL_NO_ERROR();
2768
2769 const char *vertESSL1 =
2770 "attribute vec4 a_pos;\n"
2771 "void main()\n"
2772 "{\n"
2773 " gl_Position = a_pos;\n"
2774 "}\n";
2775 const char *vertESSL3 =
2776 "#version 300 es\n"
2777 "in vec4 a_pos;\n"
2778 "void main()\n"
2779 "{\n"
2780 " gl_Position = a_pos;\n"
2781 "}\n";
2782
2783 GLenum allDrawBuffers[] = {
2784 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2785 };
2786
2787 GLenum halfDrawBuffers[] = {
2788 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2789 };
2790
2791 // Test that when using gl_FragColor, only the first attachment is written to.
2792 const char *fragESSL1 =
2793 "precision highp float;\n"
2794 "void main()\n"
2795 "{\n"
2796 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2797 "}\n";
2798 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2799
2800 {
2801 ClearEverythingToRed(renderbuffers);
2802
2803 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2804 DrawBuffers(useEXT, 4, allDrawBuffers);
2805 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2806 ASSERT_GL_NO_ERROR();
2807
2808 CheckColors(renderbuffers, 0b0001, GLColor::green);
2809 CheckColors(renderbuffers, 0b1110, GLColor::red);
2810 }
2811
2812 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2813 // written to.
2814 {
2815 ClearEverythingToRed(renderbuffers);
2816
2817 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2818 DrawBuffers(useEXT, 4, halfDrawBuffers);
2819 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2820 ASSERT_GL_NO_ERROR();
2821
2822 CheckColors(renderbuffers, 0b1111, GLColor::red);
2823 }
2824
2825 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
2826 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
2827 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
2828 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
2829 // attachments not declared in the shader should not be written to.
2830 const char *writeOddOutputsVert;
2831 const char *writeOddOutputsFrag;
2832 GLColor unwrittenColor;
2833 if (useEXT)
2834 {
2835 // In the extension, when an attachment isn't written to, it should get 0's
2836 unwrittenColor = GLColor(0, 0, 0, 0);
2837 writeOddOutputsVert = vertESSL1;
2838 writeOddOutputsFrag =
2839 "#extension GL_EXT_draw_buffers : require\n"
2840 "precision highp float;\n"
2841 "void main()\n"
2842 "{\n"
2843 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2844 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2845 "}\n";
2846 }
2847 else
2848 {
2849 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
2850 // because of the preceding clears.
2851 unwrittenColor = GLColor::red;
2852 writeOddOutputsVert = vertESSL3;
2853 writeOddOutputsFrag =
2854 "#version 300 es\n"
2855 "precision highp float;\n"
2856 "layout(location = 1) out vec4 output1;"
2857 "layout(location = 3) out vec4 output2;"
2858 "void main()\n"
2859 "{\n"
2860 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2861 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2862 "}\n";
2863 }
2864 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
2865
2866 // Test that attachments not written to get the "unwritten" color
2867 {
2868 ClearEverythingToRed(renderbuffers);
2869
2870 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2871 DrawBuffers(useEXT, 4, allDrawBuffers);
2872 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2873 ASSERT_GL_NO_ERROR();
2874
2875 CheckColors(renderbuffers, 0b1010, GLColor::green);
2876 CheckColors(renderbuffers, 0b0101, unwrittenColor);
2877 }
2878
2879 // Test that attachments not written to get the "unwritten" color but that even when the
2880 // extension is used, disabled attachments are not written at all and stay red.
2881 {
2882 ClearEverythingToRed(renderbuffers);
2883
2884 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2885 DrawBuffers(useEXT, 4, halfDrawBuffers);
2886 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2887 ASSERT_GL_NO_ERROR();
2888
2889 CheckColors(renderbuffers, 0b1000, GLColor::green);
2890 CheckColors(renderbuffers, 0b0100, unwrittenColor);
2891 CheckColors(renderbuffers, 0b0011, GLColor::red);
2892 }
2893}
2894
Frank Henigmanfccbac22017-05-28 17:29:26 -04002895// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
2896// qualifiers.
2897TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
2898{
2899 const std::string vertexShader =
2900 "#version 300 es\n"
2901 "uniform Block { mediump vec4 val; };\n"
2902 "void main() { gl_Position = val; }\n";
2903 const std::string fragmentShader =
2904 "#version 300 es\n"
2905 "uniform Block { highp vec4 val; };\n"
2906 "out highp vec4 out_FragColor;\n"
2907 "void main() { out_FragColor = val; }\n";
2908
2909 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
2910 ASSERT_NE(0u, vs);
2911 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
2912 ASSERT_NE(0u, fs);
2913
2914 GLuint program = glCreateProgram();
2915
2916 glAttachShader(program, vs);
2917 glDeleteShader(vs);
2918 glAttachShader(program, fs);
2919 glDeleteShader(fs);
2920
2921 glLinkProgram(program);
2922 GLint linkStatus;
2923 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
2924 ASSERT_EQ(0, linkStatus);
2925
2926 glDeleteProgram(program);
2927}
2928
Geoff Lang69df2422017-07-05 12:42:31 -04002929// Test no attribute vertex shaders
2930TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
2931{
2932 const std::string vertexShader =
2933 "#version 300 es\n"
2934 "void main()\n"
2935 "{\n"
2936 "\n"
2937 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
2938 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
2939 "}";
2940 const std::string fragmentShader =
2941 "#version 300 es\n"
2942 "precision mediump float;\n"
2943 "out vec4 result;\n"
2944 "void main()\n"
2945 "{\n"
2946 " result = vec4(0, 1, 0, 1);\n"
2947 "}";
2948
2949 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2950 glUseProgram(program);
2951
2952 glDrawArrays(GL_TRIANGLES, 0, 6);
2953 ASSERT_GL_NO_ERROR();
2954 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2955}
2956
Geoff Langc287ea62016-09-16 14:46:51 -04002957// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2958// tests should be run against.
2959ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2960 ES2_D3D9(),
2961 ES2_D3D11(),
2962 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002963 ES2_OPENGL(),
2964 ES3_OPENGL(),
2965 ES2_OPENGLES(),
2966 ES3_OPENGLES());
2967
Jamie Madill07be8bf2017-02-02 19:59:57 -05002968ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04002969} // namespace