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