blob: 4ebafb73738e05f879ffb7cbbb1beac8107cc257 [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;
Geoff Langcab92ee2017-07-19 17:32:07 -0400895 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -0400896 frag +=
897 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -0400898 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -0400899 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -0400900 "{/*\n"
901 " ` @ $\n"
902 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -0400903 "}\n";
904
905 ANGLE_GL_PROGRAM(program, vert, frag);
906 EXPECT_GL_NO_ERROR();
907
908 for (char invalidChar : invalidSet)
909 {
910 std::string invalidName = validAttribName + invalidChar;
911 glGetAttribLocation(program, invalidName.c_str());
912 EXPECT_GL_ERROR(GL_INVALID_VALUE)
913 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
914
915 glBindAttribLocation(program, 0, invalidName.c_str());
916 EXPECT_GL_ERROR(GL_INVALID_VALUE)
917 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
918 }
919
920 for (char invalidChar : invalidSet)
921 {
922 std::string invalidName = validUniformName + invalidChar;
923 glGetUniformLocation(program, invalidName.c_str());
924 EXPECT_GL_ERROR(GL_INVALID_VALUE)
925 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
926 }
927
928 for (char invalidChar : invalidSet)
929 {
930 std::string invalidAttribName = validAttribName + invalidChar;
931 const char *invalidVert[] = {
932 "attribute float ",
933 invalidAttribName.c_str(),
934 ";\n",
935 "void main()\n",
936 "{\n",
937 " gl_Position = vec4(1.0);\n",
938 "}\n",
939 };
940
941 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
942 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
943 EXPECT_GL_ERROR(GL_INVALID_VALUE);
944 glDeleteShader(shader);
945 }
946}
947
Geoff Langcab92ee2017-07-19 17:32:07 -0400948// Test that line continuation is handled correctly when valdiating shader source
949TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
950{
951 const char *validVert =
952 "#version 300 es\n"
953 "precision mediump float;\n"
954 "\n"
955 "void main ()\n"
956 "{\n"
957 " float f\\\n"
958 "oo = 1.0;\n"
959 " gl_Position = vec4(foo);\n"
960 "}\n";
961
962 const char *invalidVert =
963 "#version 300 es\n"
964 "precision mediump float;\n"
965 "\n"
966 "void main ()\n"
967 "{\n"
968 " float f\\$\n"
969 "oo = 1.0;\n"
970 " gl_Position = vec4(foo);\n"
971 "}\n";
972
973 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
974 glShaderSource(shader, 1, &validVert, nullptr);
975 EXPECT_GL_NO_ERROR();
976 glShaderSource(shader, 1, &invalidVert, nullptr);
977 EXPECT_GL_ERROR(GL_INVALID_VALUE);
978 glDeleteShader(shader);
979}
980
Corentin Wallezfd456442016-12-21 17:57:00 -0500981// Test the checks for OOB reads in the vertex buffers, instanced version
982TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
983{
984 const std::string &vert =
985 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400986 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500987 "void main()\n"
988 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400989 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500990 "}\n";
991
992 const std::string &frag =
993 "precision highp float;\n"
994 "void main()\n"
995 "{\n"
996 " gl_FragColor = vec4(1.0);\n"
997 "}\n";
998
999 ANGLE_GL_PROGRAM(program, vert, frag);
1000
1001 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1002 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -04001003
1004 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1005 ASSERT_NE(-1, wLocation);
1006
Corentin Wallezfd456442016-12-21 17:57:00 -05001007 glUseProgram(program.get());
1008
1009 GLBuffer buffer;
1010 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1011 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1012
1013 glEnableVertexAttribArray(posLocation);
1014 glVertexAttribDivisor(posLocation, 1);
1015
Geoff Lang407d4e72017-04-12 14:54:11 -04001016 glEnableVertexAttribArray(wLocation);
1017 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1018 glVertexAttribDivisor(wLocation, 0);
1019
Corentin Wallezfd456442016-12-21 17:57:00 -05001020 const uint8_t* zeroOffset = nullptr;
1021
1022 // Test touching the last element is valid.
1023 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1024 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1025 ASSERT_GL_NO_ERROR();
1026
1027 // Test touching the last element + 1 is invalid.
1028 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1029 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1030 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1031
1032 // Test touching the last element is valid, using a stride.
1033 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1034 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1035 ASSERT_GL_NO_ERROR();
1036
1037 // Test touching the last element + 1 is invalid, using a stride.
1038 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1039 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1040 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1041
1042 // Test any offset is valid if no vertices are drawn.
1043 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1044 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1045 ASSERT_GL_NO_ERROR();
1046}
1047
Corentin Wallez0dc97812017-06-22 14:38:44 -04001048// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001049TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1050{
1051 const std::string &vert =
1052 "attribute float a_pos;\n"
1053 "void main()\n"
1054 "{\n"
1055 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1056 "}\n";
1057
1058 const std::string &frag =
1059 "precision highp float;\n"
1060 "void main()\n"
1061 "{\n"
1062 " gl_FragColor = vec4(1.0);\n"
1063 "}\n";
1064
1065 ANGLE_GL_PROGRAM(program, vert, frag);
1066
1067 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1068 ASSERT_NE(-1, posLocation);
1069
1070 glUseProgram(program.get());
1071
1072 GLBuffer buffer;
1073 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1074 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1075
1076 glEnableVertexAttribArray(posLocation);
1077 glVertexAttribDivisor(posLocation, 1);
1078
Geoff Lang407d4e72017-04-12 14:54:11 -04001079 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1080 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001081 ASSERT_GL_NO_ERROR();
1082}
1083
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001084// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1085TEST_P(WebGLCompatibilityTest, NPOT)
1086{
1087 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1088
1089 // Create a texture and set an NPOT mip 0, should always be acceptable.
1090 GLTexture texture;
1091 glBindTexture(GL_TEXTURE_2D, texture.get());
1092 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1093 ASSERT_GL_NO_ERROR();
1094
1095 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1096 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1097 if (getClientMajorVersion() < 3)
1098 {
1099 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1100 }
1101 else
1102 {
1103 ASSERT_GL_NO_ERROR();
1104 }
1105
1106 if (extensionRequestable("GL_OES_texture_npot"))
1107 {
1108 glRequestExtensionANGLE("GL_OES_texture_npot");
1109 ASSERT_GL_NO_ERROR();
1110
1111 // Try again to set NPOT mip 1
1112 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1113 ASSERT_GL_NO_ERROR();
1114 }
1115}
1116
Jamie Madillcad97ee2017-02-02 18:52:44 -05001117template <typename T>
1118void FillTexture2D(GLuint texture,
1119 GLsizei width,
1120 GLsizei height,
1121 const T &onePixelData,
1122 GLint level,
1123 GLint internalFormat,
1124 GLenum format,
1125 GLenum type)
1126{
1127 std::vector<T> allPixelsData(width * height, onePixelData);
1128
1129 glBindTexture(GL_TEXTURE_2D, texture);
1130 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1131 allPixelsData.data());
1132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1134 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1136}
1137
Frank Henigman875bbba2017-02-08 16:38:17 -05001138// Test that unset gl_Position defaults to (0,0,0,0).
1139TEST_P(WebGLCompatibilityTest, DefaultPosition)
1140{
1141 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1142 // and green otherwise. The center of each quadrant will be red if and only if all
1143 // four corners are red.
1144 const std::string vertexShader =
1145 "attribute vec3 pos;\n"
1146 "varying vec4 color;\n"
1147 "void main() {\n"
1148 " if (gl_Position == vec4(0,0,0,0)) {\n"
1149 " color = vec4(1,0,0,1);\n"
1150 " } else {\n"
1151 " color = vec4(0,1,0,1);\n"
1152 " }\n"
1153 " gl_Position = vec4(pos,1);\n"
1154 "}\n";
1155
1156 const std::string fragmentShader =
1157 "precision mediump float;\n"
1158 "varying vec4 color;\n"
1159 "void main() {\n"
1160 " gl_FragColor = color;\n"
1161 "}\n";
1162
1163 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1164 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1165 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1166 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1167 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1168 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1169}
1170
Jamie Madilla4595b82017-01-11 17:36:34 -05001171// Tests that a rendering feedback loop triggers a GL error under WebGL.
1172// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1173TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1174{
1175 const std::string vertexShader =
1176 "attribute vec4 a_position;\n"
1177 "varying vec2 v_texCoord;\n"
1178 "void main() {\n"
1179 " gl_Position = a_position;\n"
1180 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1181 "}\n";
1182
1183 const std::string fragmentShader =
1184 "precision mediump float;\n"
1185 "varying vec2 v_texCoord;\n"
1186 "uniform sampler2D u_texture;\n"
1187 "void main() {\n"
1188 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1189 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1190 "}\n";
1191
1192 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001193 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001194
1195 ASSERT_GL_NO_ERROR();
1196
1197 GLFramebuffer framebuffer;
1198 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1199 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1200
1201 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1202
1203 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1204
1205 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1206 ASSERT_NE(-1, uniformLoc);
1207
1208 glUseProgram(program.get());
1209 glUniform1i(uniformLoc, 0);
1210 glDisable(GL_BLEND);
1211 glDisable(GL_DEPTH_TEST);
1212 ASSERT_GL_NO_ERROR();
1213
1214 // Drawing with a texture that is also bound to the current framebuffer should fail
1215 glBindTexture(GL_TEXTURE_2D, texture.get());
1216 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1217 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1218
1219 // Ensure that the texture contents did not change after the previous render
1220 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1221 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1222 ASSERT_GL_NO_ERROR();
1223 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1224
1225 // Drawing when texture is bound to an inactive uniform should succeed
1226 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001227 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001228
1229 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1230 glActiveTexture(GL_TEXTURE1);
1231 glBindTexture(GL_TEXTURE_2D, texture.get());
1232 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1233 ASSERT_GL_NO_ERROR();
1234 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1235}
1236
Bryan Bernhart58806562017-01-05 13:09:31 -08001237// Test for the max draw buffers and color attachments.
1238TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1239{
1240 // This test only applies to ES2.
1241 if (getClientMajorVersion() != 2)
1242 {
1243 return;
1244 }
1245
1246 GLFramebuffer fbo[2];
1247 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1248
1249 // Test that is valid when we bind with a single attachment point.
1250 GLTexture texture;
1251 glBindTexture(GL_TEXTURE_2D, texture.get());
1252 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1253 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1254 ASSERT_GL_NO_ERROR();
1255
1256 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1257 // attachment point.
1258 if (extensionRequestable("GL_EXT_draw_buffers"))
1259 {
1260 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1261 EXPECT_GL_NO_ERROR();
1262 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1263
1264 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1265
1266 GLTexture texture2;
1267 glBindTexture(GL_TEXTURE_2D, texture2.get());
1268 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1269 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1270 0);
1271 ASSERT_GL_NO_ERROR();
1272 }
1273}
1274
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001275// Test that the offset in the index buffer is forced to be a multiple of the element size
1276TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1277{
1278 const std::string &vert =
1279 "attribute vec3 a_pos;\n"
1280 "void main()\n"
1281 "{\n"
1282 " gl_Position = vec4(a_pos, 1.0);\n"
1283 "}\n";
1284
1285 const std::string &frag =
1286 "precision highp float;\n"
1287 "void main()\n"
1288 "{\n"
1289 " gl_FragColor = vec4(1.0);\n"
1290 "}\n";
1291
1292 ANGLE_GL_PROGRAM(program, vert, frag);
1293
1294 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1295 ASSERT_NE(-1, posLocation);
1296 glUseProgram(program.get());
1297
1298 const auto &vertices = GetQuadVertices();
1299
1300 GLBuffer vertexBuffer;
1301 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1302 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1303 GL_STATIC_DRAW);
1304
1305 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1306 glEnableVertexAttribArray(posLocation);
1307
1308 GLBuffer indexBuffer;
1309 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
1310 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1311 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1312
1313 ASSERT_GL_NO_ERROR();
1314
1315 const char *zeroIndices = nullptr;
1316
1317 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1318 ASSERT_GL_NO_ERROR();
1319
1320 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
1321 ASSERT_GL_NO_ERROR();
1322
1323 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
1324 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1325}
1326
1327// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1328// size
1329TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1330{
1331 const char *zeroOffset = nullptr;
1332
1333 // Base case, vector of two floats
1334 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1335 ASSERT_GL_NO_ERROR();
1336
1337 // Test setting a non-multiple offset
1338 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1339 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1340 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1341 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1342 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1343 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1344
1345 // Test setting a non-multiple stride
1346 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1347 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1348 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1349 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1350 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1351 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1352}
1353
Jamie Madillcad97ee2017-02-02 18:52:44 -05001354void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1355 const std::array<GLenum, 2> &drawBuffers,
1356 GLenum expectedError)
1357{
1358 glDrawBuffersEXT(2, drawBuffers.data());
1359
1360 // Make sure framebuffer is complete before feedback loop detection
1361 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1362
1363 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1364
1365 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1366 // it should be NO_ERROR"
1367 EXPECT_GL_ERROR(expectedError);
1368}
1369
1370// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1371// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1372TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1373{
1374 const std::string vertexShader =
1375 "attribute vec4 aPosition;\n"
1376 "varying vec2 texCoord;\n"
1377 "void main() {\n"
1378 " gl_Position = aPosition;\n"
1379 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1380 "}\n";
1381
1382 const std::string fragmentShader =
1383 "#extension GL_EXT_draw_buffers : require\n"
1384 "precision mediump float;\n"
1385 "uniform sampler2D tex;\n"
1386 "varying vec2 texCoord;\n"
1387 "void main() {\n"
1388 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1389 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1390 "}\n";
1391
1392 GLsizei width = 8;
1393 GLsizei height = 8;
1394
1395 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1396 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1397 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1398 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1399 {
1400 // No WEBGL_draw_buffers support -- this is legal.
1401 return;
1402 }
1403
1404 GLint maxDrawBuffers = 0;
1405 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1406
1407 if (maxDrawBuffers < 2)
1408 {
1409 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1410 return;
1411 }
1412
1413 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1414 glUseProgram(program.get());
1415 glViewport(0, 0, width, height);
1416
1417 GLTexture tex0;
1418 GLTexture tex1;
1419 GLFramebuffer fbo;
1420 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1421 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1422 ASSERT_GL_NO_ERROR();
1423
1424 glBindTexture(GL_TEXTURE_2D, tex1.get());
1425 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1426 ASSERT_NE(-1, texLoc);
1427 glUniform1i(texLoc, 0);
1428 ASSERT_GL_NO_ERROR();
1429
1430 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1431 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1432 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1433 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1434
1435 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1436 GL_INVALID_OPERATION);
1437 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1438 GL_INVALID_OPERATION);
1439 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1440}
1441
Jamie Madill07be8bf2017-02-02 19:59:57 -05001442// Test tests that texture copying feedback loops are properly rejected in WebGL.
1443// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1444TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1445{
1446 GLTexture texture;
1447 glBindTexture(GL_TEXTURE_2D, texture.get());
1448 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1451 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1452 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1453
1454 GLTexture texture2;
1455 glBindTexture(GL_TEXTURE_2D, texture2.get());
1456 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1457 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1458 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1461
1462 GLFramebuffer framebuffer;
1463 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1464 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1465
1466 // framebuffer should be FRAMEBUFFER_COMPLETE.
1467 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1468 ASSERT_GL_NO_ERROR();
1469
1470 // testing copyTexImage2D
1471
1472 // copyTexImage2D to same texture but different level
1473 glBindTexture(GL_TEXTURE_2D, texture.get());
1474 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1475 EXPECT_GL_NO_ERROR();
1476
1477 // copyTexImage2D to same texture same level, invalid feedback loop
1478 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1479 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1480
1481 // copyTexImage2D to different texture
1482 glBindTexture(GL_TEXTURE_2D, texture2.get());
1483 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1484 EXPECT_GL_NO_ERROR();
1485
1486 // testing copyTexSubImage2D
1487
1488 // copyTexSubImage2D to same texture but different level
1489 glBindTexture(GL_TEXTURE_2D, texture.get());
1490 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1491 EXPECT_GL_NO_ERROR();
1492
1493 // copyTexSubImage2D to same texture same level, invalid feedback loop
1494 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1495 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1496
1497 // copyTexSubImage2D to different texture
1498 glBindTexture(GL_TEXTURE_2D, texture2.get());
1499 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1500 EXPECT_GL_NO_ERROR();
1501}
1502
1503void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1504 const std::array<GLenum, 2> &drawBuffers,
1505 GLenum expectedError)
1506{
1507 glDrawBuffers(2, drawBuffers.data());
1508
1509 // Make sure framebuffer is complete before feedback loop detection
1510 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1511
1512 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1513
1514 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1515 // it should be NO_ERROR"
1516 EXPECT_GL_ERROR(expectedError);
1517}
1518
Yuly Novikov817232e2017-02-22 18:36:10 -05001519// Tests invariance matching rules between built in varyings.
1520// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1521TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1522{
1523 const std::string vertexShaderVariant =
1524 "varying vec4 v_varying;\n"
1525 "void main()\n"
1526 "{\n"
1527 " gl_PointSize = 1.0;\n"
1528 " gl_Position = v_varying;\n"
1529 "}";
1530 const std::string fragmentShaderInvariantGlFragCoord =
1531 "invariant gl_FragCoord;\n"
1532 "void main()\n"
1533 "{\n"
1534 " gl_FragColor = gl_FragCoord;\n"
1535 "}";
1536 const std::string fragmentShaderInvariantGlPointCoord =
1537 "invariant gl_PointCoord;\n"
1538 "void main()\n"
1539 "{\n"
1540 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1541 "}";
1542
1543 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1544 EXPECT_EQ(0u, program);
1545
1546 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1547 EXPECT_EQ(0u, program);
1548}
1549
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04001550// Tests global namespace conflicts between uniforms and attributes.
1551// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
1552TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
1553{
1554 const std::string vertexShader =
1555 "attribute vec4 foo;\n"
1556 "void main()\n"
1557 "{\n"
1558 " gl_Position = foo;\n"
1559 "}";
1560 const std::string fragmentShader =
1561 "precision mediump float;\n"
1562 "uniform vec4 foo;\n"
1563 "void main()\n"
1564 "{\n"
1565 " gl_FragColor = foo;\n"
1566 "}";
1567
1568 GLuint program = CompileProgram(vertexShader, fragmentShader);
1569 EXPECT_EQ(0u, program);
1570}
1571
Geoff Lang966c9402017-04-18 12:38:27 -04001572// Test dimension and image size validation of compressed textures
1573TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1574{
1575 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1576 {
1577 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1578 }
1579
1580 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1581 {
1582 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1583 << std::endl;
1584 return;
1585 }
1586
1587 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1588
1589 GLTexture texture;
1590 glBindTexture(GL_TEXTURE_2D, texture);
1591
1592 // Regular case, verify that it works
1593 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1594 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1595 ASSERT_GL_NO_ERROR();
1596
1597 // Test various dimensions that are not valid
1598 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1599 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1600 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1601
1602 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1603 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1604 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1605
1606 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1607 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1608 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1609
1610 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1611 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1612 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1613
1614 // Test various image sizes that are not valid
1615 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1616 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1617 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1618
1619 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1620 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1621 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1622
1623 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1624 CompressedImageDXT1);
1625 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1626
1627 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1628 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1629 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1630
1631 // Fill a full mip chain and verify that it works
1632 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1633 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1634 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1635 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1636 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1637 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1638 ASSERT_GL_NO_ERROR();
1639
1640 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1641 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1642 ASSERT_GL_NO_ERROR();
1643
1644 // Test that non-block size sub-uploads are not valid for the 0 mip
1645 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1646 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1647 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1648
1649 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1650 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1651 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1652 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1653 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1654 ASSERT_GL_NO_ERROR();
1655
1656 // Test that if the format miss-matches the texture, an error is generated
1657 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1658 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1659 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1660}
1661
Geoff Lang677bb6f2017-04-05 12:40:40 -04001662TEST_P(WebGLCompatibilityTest, L32FTextures)
1663{
1664 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1665 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1666
1667 for (auto extension : FloatingPointTextureExtensions)
1668 {
1669 if (strlen(extension) > 0 && extensionRequestable(extension))
1670 {
1671 glRequestExtensionANGLE(extension);
1672 ASSERT_GL_NO_ERROR();
1673 }
1674
1675 // Unsized L 32F
1676 {
1677 bool texture = extensionEnabled("GL_OES_texture_float");
1678 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1679 bool render = false;
1680 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1681 textureData, readPixelData);
1682 }
1683
1684 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1685 {
1686 // Sized L 32F
1687 bool texture = extensionEnabled("GL_OES_texture_float") &&
1688 extensionEnabled("GL_EXT_texture_storage");
1689 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1690 bool render = false;
1691 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1692 render, textureData, readPixelData);
1693 }
1694 }
1695}
1696
1697TEST_P(WebGLCompatibilityTest, A32FTextures)
1698{
1699 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1700 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1701
1702 for (auto extension : FloatingPointTextureExtensions)
1703 {
1704 if (strlen(extension) > 0 && extensionRequestable(extension))
1705 {
1706 glRequestExtensionANGLE(extension);
1707 ASSERT_GL_NO_ERROR();
1708 }
1709
1710 // Unsized A 32F
1711 {
1712 bool texture = extensionEnabled("GL_OES_texture_float");
1713 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1714 bool render = false;
1715 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1716 textureData, readPixelData);
1717 }
1718
1719 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1720 {
1721 // Sized A 32F
1722 bool texture = extensionEnabled("GL_OES_texture_float") &&
1723 extensionEnabled("GL_EXT_texture_storage");
1724 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1725 bool render = false;
1726 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1727 textureData, readPixelData);
1728 }
1729 }
1730}
1731
1732TEST_P(WebGLCompatibilityTest, LA32FTextures)
1733{
1734 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1735 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1736 textureData[1]};
1737
1738 for (auto extension : FloatingPointTextureExtensions)
1739 {
1740 if (strlen(extension) > 0 && extensionRequestable(extension))
1741 {
1742 glRequestExtensionANGLE(extension);
1743 ASSERT_GL_NO_ERROR();
1744 }
1745
1746 // Unsized LA 32F
1747 {
1748 bool texture = extensionEnabled("GL_OES_texture_float");
1749 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1750 bool render = false;
1751 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1752 filter, render, textureData, readPixelData);
1753 }
1754
1755 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1756 {
1757 // Sized LA 32F
1758 bool texture = extensionEnabled("GL_OES_texture_float") &&
1759 extensionEnabled("GL_EXT_texture_storage");
1760 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1761 bool render = false;
1762 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1763 filter, render, textureData, readPixelData);
1764 }
1765 }
1766}
1767
1768TEST_P(WebGLCompatibilityTest, R32FTextures)
1769{
1770 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1771
1772 for (auto extension : FloatingPointTextureExtensions)
1773 {
1774 if (strlen(extension) > 0 && extensionRequestable(extension))
1775 {
1776 glRequestExtensionANGLE(extension);
1777 ASSERT_GL_NO_ERROR();
1778 }
1779
1780 // Unsized R 32F
1781 {
1782 bool texture =
1783 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1784 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1785 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1786 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1787 }
1788
1789 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1790 {
1791 // Sized R 32F
1792 bool texture =
1793 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1794 extensionEnabled("GL_EXT_texture_rg") &&
1795 extensionEnabled("GL_EXT_texture_storage"));
1796 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1797 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1798 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1799 }
1800 }
1801}
1802
1803TEST_P(WebGLCompatibilityTest, RG32FTextures)
1804{
1805 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1806
1807 for (auto extension : FloatingPointTextureExtensions)
1808 {
1809 if (strlen(extension) > 0 && extensionRequestable(extension))
1810 {
1811 glRequestExtensionANGLE(extension);
1812 ASSERT_GL_NO_ERROR();
1813 }
1814
1815 // Unsized RG 32F
1816 {
1817 bool texture =
1818 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1819 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1820 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1821 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1822 }
1823
1824 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1825 {
1826 // Sized RG 32F
1827 bool texture =
1828 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1829 extensionEnabled("GL_EXT_texture_rg") &&
1830 extensionEnabled("GL_EXT_texture_storage"));
1831 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1832 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1833 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1834 }
1835 }
1836}
1837
1838TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1839{
Geoff Lang40762ef2017-05-08 13:47:03 -04001840 if (IsLinux() && IsIntel())
1841 {
1842 std::cout << "Test skipped on Linux Intel." << std::endl;
1843 return;
1844 }
1845
Geoff Lang677bb6f2017-04-05 12:40:40 -04001846 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1847
1848 for (auto extension : FloatingPointTextureExtensions)
1849 {
1850 if (strlen(extension) > 0 && extensionRequestable(extension))
1851 {
1852 glRequestExtensionANGLE(extension);
1853 ASSERT_GL_NO_ERROR();
1854 }
1855
1856 // Unsized RGB 32F
1857 {
1858 bool texture = extensionEnabled("GL_OES_texture_float");
1859 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1860 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1861 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
1862 }
1863
1864 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1865 {
1866 // Sized RGBA 32F
1867 bool texture =
1868 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1869 extensionEnabled("GL_EXT_texture_storage"));
1870 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1871 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1872 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
1873 data);
1874 }
1875 }
1876}
1877
1878TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
1879{
1880 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1881
1882 for (auto extension : FloatingPointTextureExtensions)
1883 {
1884 if (strlen(extension) > 0 && extensionRequestable(extension))
1885 {
1886 glRequestExtensionANGLE(extension);
1887 ASSERT_GL_NO_ERROR();
1888 }
1889
1890 // Unsized RGBA 32F
1891 {
1892 bool texture = extensionEnabled("GL_OES_texture_float");
1893 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1894 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1895 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1896 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
1897 }
1898
1899 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1900 {
1901 // Sized RGBA 32F
1902 bool texture =
1903 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1904 extensionEnabled("GL_EXT_texture_storage"));
1905 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1906 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1907 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1908 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
1909 data);
1910 }
1911 }
1912}
1913
1914TEST_P(WebGLCompatibilityTest, R16FTextures)
1915{
1916 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
1917 const GLushort textureData[] = {
1918 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1919 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1920
1921 for (auto extension : FloatingPointTextureExtensions)
1922 {
1923 if (strlen(extension) > 0 && extensionRequestable(extension))
1924 {
1925 glRequestExtensionANGLE(extension);
1926 ASSERT_GL_NO_ERROR();
1927 }
1928
1929 // Unsized R 16F (OES)
1930 {
1931 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1932 extensionEnabled("GL_EXT_texture_rg");
1933 bool filter = getClientMajorVersion() >= 3 ||
1934 extensionEnabled("GL_OES_texture_half_float_linear");
1935 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1936 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
1937 textureData, readPixelsData);
1938 }
1939
1940 // Unsized R 16F
1941 {
1942 bool texture = false;
1943 bool filter = false;
1944 bool render = false;
1945 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1946 textureData, readPixelsData);
1947 }
1948
1949 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1950 {
1951 // Sized R 16F
1952 bool texture = getClientMajorVersion() >= 3;
1953 bool filter = getClientMajorVersion() >= 3 ||
1954 extensionEnabled("GL_OES_texture_half_float_linear");
1955 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1956 extensionEnabled("GL_EXT_color_buffer_float");
1957 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1958 textureData, readPixelsData);
1959 }
1960 }
1961}
1962
1963TEST_P(WebGLCompatibilityTest, RG16FTextures)
1964{
1965 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
1966 const GLushort textureData[] = {
1967 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1968 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1969
1970 for (auto extension : FloatingPointTextureExtensions)
1971 {
1972 if (strlen(extension) > 0 && extensionRequestable(extension))
1973 {
1974 glRequestExtensionANGLE(extension);
1975 ASSERT_GL_NO_ERROR();
1976 }
1977
1978 // Unsized RG 16F (OES)
1979 {
1980 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1981 extensionEnabled("GL_EXT_texture_rg");
1982 bool filter = getClientMajorVersion() >= 3 ||
1983 extensionEnabled("GL_OES_texture_half_float_linear");
1984 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
1985 extensionEnabled("GL_EXT_texture_rg");
1986 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
1987 textureData, readPixelsData);
1988 }
1989
1990 // Unsized RG 16F
1991 {
1992 bool texture = false;
1993 bool filter = false;
1994 bool render = false;
1995 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1996 textureData, readPixelsData);
1997 }
1998
1999 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2000 {
2001 // Sized RG 16F
2002 bool texture = getClientMajorVersion() >= 3;
2003 bool filter = getClientMajorVersion() >= 3 ||
2004 extensionEnabled("GL_OES_texture_half_float_linear");
2005 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2006 extensionEnabled("GL_EXT_color_buffer_float");
2007 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2008 textureData, readPixelsData);
2009 }
2010 }
2011}
2012
2013TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2014{
Geoff Lang40762ef2017-05-08 13:47:03 -04002015 if (IsOzone() && IsIntel())
2016 {
2017 std::cout << "Test skipped on Intel Ozone." << std::endl;
2018 return;
2019 }
2020
Geoff Lang677bb6f2017-04-05 12:40:40 -04002021 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2022 const GLushort textureData[] = {
2023 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2024 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2025
2026 for (auto extension : FloatingPointTextureExtensions)
2027 {
2028 if (strlen(extension) > 0 && extensionRequestable(extension))
2029 {
2030 glRequestExtensionANGLE(extension);
2031 ASSERT_GL_NO_ERROR();
2032 }
2033
2034 // Unsized RGB 16F (OES)
2035 {
2036 bool texture = extensionEnabled("GL_OES_texture_half_float");
2037 bool filter = getClientMajorVersion() >= 3 ||
2038 extensionEnabled("GL_OES_texture_half_float_linear");
2039 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2040 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2041 textureData, readPixelsData);
2042 }
2043
2044 // Unsized RGB 16F
2045 {
2046 bool texture = false;
2047 bool filter = false;
2048 bool render = false;
2049 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2050 textureData, readPixelsData);
2051 }
2052
2053 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2054 {
2055 // Sized RGB 16F
2056 bool texture = getClientMajorVersion() >= 3;
2057 bool filter = getClientMajorVersion() >= 3 ||
2058 extensionEnabled("GL_OES_texture_half_float_linear");
2059 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2060 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2061 textureData, readPixelsData);
2062 }
2063 }
2064}
2065
2066TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2067{
Geoff Lang40762ef2017-05-08 13:47:03 -04002068 if (IsOzone() && IsIntel())
2069 {
2070 std::cout << "Test skipped on Intel Ozone." << std::endl;
2071 return;
2072 }
2073
Geoff Lang677bb6f2017-04-05 12:40:40 -04002074 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2075 const GLushort textureData[] = {
2076 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2077 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2078
2079 for (auto extension : FloatingPointTextureExtensions)
2080 {
2081 if (strlen(extension) > 0 && extensionRequestable(extension))
2082 {
2083 glRequestExtensionANGLE(extension);
2084 ASSERT_GL_NO_ERROR();
2085 }
2086
2087 // Unsized RGBA 16F (OES)
2088 {
2089 bool texture = extensionEnabled("GL_OES_texture_half_float");
2090 bool filter = getClientMajorVersion() >= 3 ||
2091 extensionEnabled("GL_OES_texture_half_float_linear");
2092 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2093 extensionEnabled("GL_EXT_color_buffer_float");
2094 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2095 textureData, readPixelsData);
2096 }
2097
2098 // Unsized RGBA 16F
2099 {
2100 bool texture = false;
2101 bool filter = false;
2102 bool render = false;
2103 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2104 textureData, readPixelsData);
2105 }
2106
2107 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2108 {
2109 // Sized RGBA 16F
2110 bool texture = getClientMajorVersion() >= 3;
2111 bool filter = getClientMajorVersion() >= 3 ||
2112 extensionEnabled("GL_OES_texture_half_float_linear");
2113 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2114 extensionEnabled("GL_EXT_color_buffer_float");
2115 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2116 textureData, readPixelsData);
2117 }
2118 }
2119}
2120
Geoff Lang6e898aa2017-06-02 11:17:26 -04002121// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2122// accepted by glTexImage2D
2123TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2124{
2125 if (getClientMajorVersion() != 2)
2126 {
2127 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2128 return;
2129 }
2130
2131 if (!extensionRequestable("GL_OES_texture_float"))
2132 {
2133 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2134 return;
2135 }
2136 glRequestExtensionANGLE("GL_OES_texture_float");
2137 ASSERT_GL_NO_ERROR();
2138
2139 GLTexture texture;
2140 glBindTexture(GL_TEXTURE_2D, texture);
2141
2142 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2143 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2144
2145 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2146 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2147
2148 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2149 {
2150 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2151 ASSERT_GL_NO_ERROR();
2152
2153 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2154 EXPECT_GL_NO_ERROR();
2155 }
2156
2157 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2158 {
2159 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2160 ASSERT_GL_NO_ERROR();
2161
2162 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2163 EXPECT_GL_NO_ERROR();
2164 }
2165}
2166
Jamie Madill07be8bf2017-02-02 19:59:57 -05002167// This tests that rendering feedback loops works as expected with WebGL 2.
2168// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2169TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2170{
2171 const std::string vertexShader =
2172 "#version 300 es\n"
2173 "in vec4 aPosition;\n"
2174 "out vec2 texCoord;\n"
2175 "void main() {\n"
2176 " gl_Position = aPosition;\n"
2177 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2178 "}\n";
2179
2180 const std::string fragmentShader =
2181 "#version 300 es\n"
2182 "precision mediump float;\n"
2183 "uniform sampler2D tex;\n"
2184 "in vec2 texCoord;\n"
2185 "out vec4 oColor;\n"
2186 "void main() {\n"
2187 " oColor = texture(tex, texCoord);\n"
2188 "}\n";
2189
2190 GLsizei width = 8;
2191 GLsizei height = 8;
2192
2193 GLint maxDrawBuffers = 0;
2194 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2195 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2196 ASSERT_GE(maxDrawBuffers, 2);
2197
2198 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2199 glUseProgram(program.get());
2200 glViewport(0, 0, width, height);
2201
2202 GLTexture tex0;
2203 GLTexture tex1;
2204 GLFramebuffer fbo;
2205 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2206 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2207 ASSERT_GL_NO_ERROR();
2208
2209 glBindTexture(GL_TEXTURE_2D, tex1.get());
2210 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2211 ASSERT_NE(-1, texLoc);
2212 glUniform1i(texLoc, 0);
2213
2214 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2215 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2216 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2217 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2218 ASSERT_GL_NO_ERROR();
2219
2220 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2221 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2222 GL_INVALID_OPERATION);
2223 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2224}
2225
Jamie Madill1d37bc52017-02-02 19:59:58 -05002226// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2227// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2228TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2229{
2230 const std::string vertexShader =
2231 "#version 300 es\n"
2232 "in vec4 aPosition;\n"
2233 "out vec2 texCoord;\n"
2234 "void main() {\n"
2235 " gl_Position = aPosition;\n"
2236 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2237 "}\n";
2238
2239 const std::string fragmentShader =
2240 "#version 300 es\n"
2241 "precision mediump float;\n"
2242 "uniform sampler2D tex;\n"
2243 "in vec2 texCoord;\n"
2244 "out vec4 oColor;\n"
2245 "void main() {\n"
2246 " oColor = texture(tex, texCoord);\n"
2247 "}\n";
2248
2249 GLsizei width = 8;
2250 GLsizei height = 8;
2251
2252 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2253 glUseProgram(program.get());
2254
2255 glViewport(0, 0, width, height);
2256
2257 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2258 glUniform1i(texLoc, 0);
2259
2260 // Create textures and allocate storage
2261 GLTexture tex0;
2262 GLTexture tex1;
2263 GLRenderbuffer rb;
2264 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2265 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2266 GL_UNSIGNED_INT);
2267 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2268 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2269 ASSERT_GL_NO_ERROR();
2270
2271 GLFramebuffer fbo;
2272 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2273 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2274
2275 // Test rendering and sampling feedback loop for depth buffer
2276 glBindTexture(GL_TEXTURE_2D, tex1.get());
2277 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2278 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2279
2280 // The same image is used as depth buffer during rendering.
2281 glEnable(GL_DEPTH_TEST);
2282 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2283 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2284
2285 // The same image is used as depth buffer. But depth mask is false.
2286 glDepthMask(GL_FALSE);
2287 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2288 EXPECT_GL_NO_ERROR();
2289
2290 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2291 glDepthMask(GL_TRUE);
2292 glDisable(GL_DEPTH_TEST);
2293 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2294 EXPECT_GL_NO_ERROR();
2295
2296 // Test rendering and sampling feedback loop for stencil buffer
2297 glBindTexture(GL_RENDERBUFFER, rb.get());
2298 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2299 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2300 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2301 constexpr GLint stencilClearValue = 0x40;
2302 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2303
2304 // The same image is used as stencil buffer during rendering.
2305 glEnable(GL_STENCIL_TEST);
2306 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2307 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2308
2309 // The same image is used as stencil buffer. But stencil mask is zero.
2310 glStencilMask(0x0);
2311 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2312 EXPECT_GL_NO_ERROR();
2313
2314 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2315 glStencilMask(0xffff);
2316 glDisable(GL_STENCIL_TEST);
2317 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2318 EXPECT_GL_NO_ERROR();
2319}
2320
Jamie Madillfd3dd432017-02-02 19:59:59 -05002321// The source and the target for CopyTexSubImage3D are the same 3D texture.
2322// But the level of the 3D texture != the level of the read attachment.
2323TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2324{
2325 GLTexture texture;
2326 GLFramebuffer framebuffer;
2327
2328 glBindTexture(GL_TEXTURE_3D, texture.get());
2329 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2330
2331 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2332 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2333 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2334 ASSERT_GL_NO_ERROR();
2335
2336 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2337 EXPECT_GL_NO_ERROR();
2338}
2339
2340// The source and the target for CopyTexSubImage3D are the same 3D texture.
2341// But the zoffset of the 3D texture != the layer of the read attachment.
2342TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2343{
2344 GLTexture texture;
2345 GLFramebuffer framebuffer;
2346
2347 glBindTexture(GL_TEXTURE_3D, texture.get());
2348 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2349
2350 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2351 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2352 ASSERT_GL_NO_ERROR();
2353
2354 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2355 EXPECT_GL_NO_ERROR();
2356}
2357
2358// The source and the target for CopyTexSubImage3D are the same 3D texture.
2359// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2360TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2361{
2362 GLTexture texture;
2363 GLFramebuffer framebuffer;
2364
2365 glBindTexture(GL_TEXTURE_3D, texture.get());
2366 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2367
2368 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2369 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2370 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2371 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2372 ASSERT_GL_NO_ERROR();
2373
2374 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2375 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2376}
2377
Corentin Wallez59c41592017-07-11 13:19:54 -04002378// Verify that errors are generated when there isn't a defined conversion between the clear type and
2379// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04002380TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2381{
2382 if (IsD3D11())
2383 {
2384 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2385 return;
2386 }
2387
2388 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2389 constexpr int clearInt[] = {0, 0, 0, 0};
2390 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2391
2392 GLTexture texture;
2393 GLFramebuffer framebuffer;
2394
2395 glBindTexture(GL_TEXTURE_2D, texture.get());
2396 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2397
2398 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2399 ASSERT_GL_NO_ERROR();
2400
2401 // Unsigned integer buffer
2402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2403 ASSERT_GL_NO_ERROR();
2404
2405 glClearBufferfv(GL_COLOR, 0, clearFloat);
2406 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2407
2408 glClearBufferiv(GL_COLOR, 0, clearInt);
2409 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2410
2411 glClearBufferuiv(GL_COLOR, 0, clearUint);
2412 EXPECT_GL_NO_ERROR();
2413
2414 glClear(GL_COLOR_BUFFER_BIT);
2415 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2416
2417 // Integer buffer
2418 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2419 ASSERT_GL_NO_ERROR();
2420
2421 glClearBufferfv(GL_COLOR, 0, clearFloat);
2422 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2423
2424 glClearBufferiv(GL_COLOR, 0, clearInt);
2425 EXPECT_GL_NO_ERROR();
2426
2427 glClearBufferuiv(GL_COLOR, 0, clearUint);
2428 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2429
2430 glClear(GL_COLOR_BUFFER_BIT);
2431 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2432
2433 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002434 if (extensionRequestable("GL_EXT_color_buffer_float"))
2435 {
2436 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2437 }
Geoff Lang76e65652017-03-27 14:58:02 -04002438
Geoff Lang677bb6f2017-04-05 12:40:40 -04002439 if (extensionEnabled("GL_EXT_color_buffer_float"))
2440 {
2441 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2442 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002443
Geoff Lang677bb6f2017-04-05 12:40:40 -04002444 glClearBufferfv(GL_COLOR, 0, clearFloat);
2445 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002446
Geoff Lang677bb6f2017-04-05 12:40:40 -04002447 glClearBufferiv(GL_COLOR, 0, clearInt);
2448 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002449
Geoff Lang677bb6f2017-04-05 12:40:40 -04002450 glClearBufferuiv(GL_COLOR, 0, clearUint);
2451 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2452
2453 glClear(GL_COLOR_BUFFER_BIT);
2454 EXPECT_GL_NO_ERROR();
2455 }
Geoff Lang76e65652017-03-27 14:58:02 -04002456
2457 // Normalized uint buffer
2458 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2459 ASSERT_GL_NO_ERROR();
2460
2461 glClearBufferfv(GL_COLOR, 0, clearFloat);
2462 EXPECT_GL_NO_ERROR();
2463
2464 glClearBufferiv(GL_COLOR, 0, clearInt);
2465 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2466
2467 glClearBufferuiv(GL_COLOR, 0, clearUint);
2468 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2469
2470 glClear(GL_COLOR_BUFFER_BIT);
2471 EXPECT_GL_NO_ERROR();
2472}
2473
Corentin Wallez59c41592017-07-11 13:19:54 -04002474// Test the interaction of WebGL compatibility clears with default framebuffers
2475TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
2476{
2477 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2478 constexpr int clearInt[] = {0, 0, 0, 0};
2479 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2480
2481 // glClear works as usual, this is also a regression test for a bug where we
2482 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
2483 glClear(GL_COLOR_BUFFER_BIT);
2484 EXPECT_GL_NO_ERROR();
2485
2486 // Default framebuffers are normalized uints, so only glClearBufferfv works.
2487 glClearBufferfv(GL_COLOR, 0, clearFloat);
2488 EXPECT_GL_NO_ERROR();
2489
2490 glClearBufferiv(GL_COLOR, 0, clearInt);
2491 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2492
2493 glClearBufferuiv(GL_COLOR, 0, clearUint);
2494 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2495}
2496
Geoff Lange4915782017-04-12 15:19:07 -04002497// Verify that errors are generate when trying to blit from an image to itself
2498TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2499{
2500 GLTexture textures[2];
2501 glBindTexture(GL_TEXTURE_2D, textures[0]);
2502 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2503 glBindTexture(GL_TEXTURE_2D, textures[1]);
2504 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2505
2506 GLRenderbuffer renderbuffers[2];
2507 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2508 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2509 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2510 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2511
2512 GLFramebuffer framebuffers[2];
2513 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2514 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2515
2516 ASSERT_GL_NO_ERROR();
2517
2518 // Same texture
2519 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2520 0);
2521 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2522 0);
2523 ASSERT_GL_NO_ERROR();
2524 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2525 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2526
2527 // Same textures but different renderbuffers
2528 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2529 renderbuffers[0]);
2530 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2531 renderbuffers[1]);
2532 ASSERT_GL_NO_ERROR();
2533 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2534 ASSERT_GL_NO_ERROR();
2535 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2536 GL_NEAREST);
2537 ASSERT_GL_NO_ERROR();
2538 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2539 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2540 GL_NEAREST);
2541 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2542
2543 // Same renderbuffers but different textures
2544 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2545 0);
2546 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2547 0);
2548 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2549 renderbuffers[0]);
2550 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2551 renderbuffers[0]);
2552 ASSERT_GL_NO_ERROR();
2553 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2554 ASSERT_GL_NO_ERROR();
2555 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2556 GL_NEAREST);
2557 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2558 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2559 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2560 GL_NEAREST);
2561 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2562}
2563
Geoff Lange0cff192017-05-30 13:04:56 -04002564// Verify that errors are generated when the fragment shader output doesn't match the bound color
2565// buffer types
2566TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2567{
2568 const std::string vertexShader =
2569 "#version 300 es\n"
2570 "void main() {\n"
2571 " gl_Position = vec4(0, 0, 0, 1);\n"
2572 "}\n";
2573
2574 const std::string fragmentShader =
2575 "#version 300 es\n"
2576 "precision mediump float;\n"
2577 "layout(location = 0) out vec4 floatOutput;\n"
2578 "layout(location = 1) out uvec4 uintOutput;\n"
2579 "layout(location = 2) out ivec4 intOutput;\n"
2580 "void main() {\n"
2581 " floatOutput = vec4(0, 0, 0, 1);\n"
2582 " uintOutput = uvec4(0, 0, 0, 1);\n"
2583 " intOutput = ivec4(0, 0, 0, 1);\n"
2584 "}\n";
2585
2586 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2587 glUseProgram(program.get());
2588
2589 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2590 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2591 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2592
2593 GLFramebuffer fbo;
2594 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2595
2596 GLRenderbuffer floatRenderbuffer;
2597 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2598 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2599 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2600 floatRenderbuffer);
2601
2602 GLRenderbuffer uintRenderbuffer;
2603 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2604 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2605 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2606 uintRenderbuffer);
2607
2608 GLRenderbuffer intRenderbuffer;
2609 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2610 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2611 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2612 intRenderbuffer);
2613
2614 ASSERT_GL_NO_ERROR();
2615
2616 GLint maxDrawBuffers = 0;
2617 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2618 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2619 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2620 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2621 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2622
2623 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2624
2625 // Check that the correct case generates no errors
2626 glDrawArrays(GL_TRIANGLES, 0, 6);
2627 EXPECT_GL_NO_ERROR();
2628
2629 // Unbind some buffers and verify that there are still no errors
2630 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2631 0);
2632 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2633 0);
2634 glDrawArrays(GL_TRIANGLES, 0, 6);
2635 EXPECT_GL_NO_ERROR();
2636
2637 // Swap the int and uint buffers to and verify that an error is generated
2638 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2639 intRenderbuffer);
2640 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2641 uintRenderbuffer);
2642 glDrawArrays(GL_TRIANGLES, 0, 6);
2643 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2644
2645 // Swap the float and uint buffers to and verify that an error is generated
2646 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2647 floatRenderbuffer);
2648 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2649 uintRenderbuffer);
2650 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2651 intRenderbuffer);
2652 glDrawArrays(GL_TRIANGLES, 0, 6);
2653 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2654}
2655
Geoff Lang9ab5b822017-05-30 16:19:23 -04002656// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2657// types
2658TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2659{
2660 const std::string vertexShader =
2661 "#version 300 es\n"
2662 "in vec4 floatInput;\n"
2663 "in uvec4 uintInput;\n"
2664 "in ivec4 intInput;\n"
2665 "void main() {\n"
2666 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2667 "}\n";
2668
2669 const std::string fragmentShader =
2670 "#version 300 es\n"
2671 "precision mediump float;\n"
2672 "out vec4 outputColor;\n"
2673 "void main() {\n"
2674 " outputColor = vec4(0, 0, 0, 1);"
2675 "}\n";
2676
2677 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2678 glUseProgram(program.get());
2679
2680 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2681 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2682 GLint intLocation = glGetAttribLocation(program, "intInput");
2683
2684 // Default attributes are of float types
2685 glDrawArrays(GL_TRIANGLES, 0, 6);
2686 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2687
2688 // Set the default attributes to the correct types, should succeed
2689 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2690 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2691 glDrawArrays(GL_TRIANGLES, 0, 6);
2692 EXPECT_GL_NO_ERROR();
2693
2694 // Change the default float attribute to an integer, should fail
2695 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2696 glDrawArrays(GL_TRIANGLES, 0, 6);
2697 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2698
2699 // Use a buffer for some attributes
2700 GLBuffer buffer;
2701 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2702 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2703 glEnableVertexAttribArray(floatLocation);
2704 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2705 glDrawArrays(GL_TRIANGLES, 0, 6);
2706 EXPECT_GL_NO_ERROR();
2707
2708 // Use a float pointer attrib for a uint input
2709 glEnableVertexAttribArray(uintLocation);
2710 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2711 glDrawArrays(GL_TRIANGLES, 0, 6);
2712 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2713
2714 // Use a uint pointer for the uint input
2715 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2716 glDrawArrays(GL_TRIANGLES, 0, 6);
2717 EXPECT_GL_NO_ERROR();
2718}
2719
Corentin Walleze7557742017-06-01 13:09:57 -04002720// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2721TEST_P(WebGLCompatibilityTest, DrawBuffers)
2722{
Corentin Walleze7557742017-06-01 13:09:57 -04002723 // Make sure we can use at least 4 attachments for the tests.
2724 bool useEXT = false;
2725 if (getClientMajorVersion() < 3)
2726 {
2727 if (!extensionRequestable("GL_EXT_draw_buffers"))
2728 {
2729 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2730 return;
2731 }
2732
2733 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2734 useEXT = true;
2735 EXPECT_GL_NO_ERROR();
2736 }
2737
2738 GLint maxDrawBuffers = 0;
2739 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2740 if (maxDrawBuffers < 4)
2741 {
2742 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2743 return;
2744 }
2745
2746 // Clears all the renderbuffers to red.
2747 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2748 GLFramebuffer clearFBO;
2749 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2750
2751 glClearColor(1, 0, 0, 1);
2752 for (int i = 0; i < 4; ++i)
2753 {
2754 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2755 renderbuffers[i]);
2756 glClear(GL_COLOR_BUFFER_BIT);
2757 }
2758 ASSERT_GL_NO_ERROR();
2759 };
2760
2761 // Checks that the renderbuffers specified by mask have the correct color
2762 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2763 GLFramebuffer readFBO;
2764 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2765
2766 for (int i = 0; i < 4; ++i)
2767 {
2768 if (mask & (1 << i))
2769 {
2770 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2771 GL_RENDERBUFFER, renderbuffers[i]);
2772 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2773 }
2774 }
2775 ASSERT_GL_NO_ERROR();
2776 };
2777
2778 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2779 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2780 if (useEXT)
2781 {
2782 glDrawBuffersEXT(numBuffers, buffers);
2783 }
2784 else
2785 {
2786 glDrawBuffers(numBuffers, buffers);
2787 }
2788 };
2789
2790 // Initialized the test framebuffer
2791 GLFramebuffer drawFBO;
2792 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2793
2794 GLRenderbuffer renderbuffers[4];
2795 for (int i = 0; i < 4; ++i)
2796 {
2797 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2798 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2799 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2800 renderbuffers[i]);
2801 }
2802
2803 ASSERT_GL_NO_ERROR();
2804
2805 const char *vertESSL1 =
2806 "attribute vec4 a_pos;\n"
2807 "void main()\n"
2808 "{\n"
2809 " gl_Position = a_pos;\n"
2810 "}\n";
2811 const char *vertESSL3 =
2812 "#version 300 es\n"
2813 "in vec4 a_pos;\n"
2814 "void main()\n"
2815 "{\n"
2816 " gl_Position = a_pos;\n"
2817 "}\n";
2818
2819 GLenum allDrawBuffers[] = {
2820 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2821 };
2822
2823 GLenum halfDrawBuffers[] = {
2824 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2825 };
2826
2827 // Test that when using gl_FragColor, only the first attachment is written to.
2828 const char *fragESSL1 =
2829 "precision highp float;\n"
2830 "void main()\n"
2831 "{\n"
2832 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2833 "}\n";
2834 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2835
2836 {
2837 ClearEverythingToRed(renderbuffers);
2838
2839 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2840 DrawBuffers(useEXT, 4, allDrawBuffers);
2841 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2842 ASSERT_GL_NO_ERROR();
2843
2844 CheckColors(renderbuffers, 0b0001, GLColor::green);
2845 CheckColors(renderbuffers, 0b1110, GLColor::red);
2846 }
2847
2848 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2849 // written to.
2850 {
2851 ClearEverythingToRed(renderbuffers);
2852
2853 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2854 DrawBuffers(useEXT, 4, halfDrawBuffers);
2855 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2856 ASSERT_GL_NO_ERROR();
2857
2858 CheckColors(renderbuffers, 0b1111, GLColor::red);
2859 }
2860
2861 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
2862 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
2863 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
2864 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
2865 // attachments not declared in the shader should not be written to.
2866 const char *writeOddOutputsVert;
2867 const char *writeOddOutputsFrag;
2868 GLColor unwrittenColor;
2869 if (useEXT)
2870 {
2871 // In the extension, when an attachment isn't written to, it should get 0's
2872 unwrittenColor = GLColor(0, 0, 0, 0);
2873 writeOddOutputsVert = vertESSL1;
2874 writeOddOutputsFrag =
2875 "#extension GL_EXT_draw_buffers : require\n"
2876 "precision highp float;\n"
2877 "void main()\n"
2878 "{\n"
2879 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2880 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2881 "}\n";
2882 }
2883 else
2884 {
2885 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
2886 // because of the preceding clears.
2887 unwrittenColor = GLColor::red;
2888 writeOddOutputsVert = vertESSL3;
2889 writeOddOutputsFrag =
2890 "#version 300 es\n"
2891 "precision highp float;\n"
2892 "layout(location = 1) out vec4 output1;"
2893 "layout(location = 3) out vec4 output2;"
2894 "void main()\n"
2895 "{\n"
2896 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2897 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2898 "}\n";
2899 }
2900 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
2901
2902 // Test that attachments not written to get the "unwritten" color
2903 {
2904 ClearEverythingToRed(renderbuffers);
2905
2906 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2907 DrawBuffers(useEXT, 4, allDrawBuffers);
2908 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2909 ASSERT_GL_NO_ERROR();
2910
2911 CheckColors(renderbuffers, 0b1010, GLColor::green);
2912 CheckColors(renderbuffers, 0b0101, unwrittenColor);
2913 }
2914
2915 // Test that attachments not written to get the "unwritten" color but that even when the
2916 // extension is used, disabled attachments are not written at all and stay red.
2917 {
2918 ClearEverythingToRed(renderbuffers);
2919
2920 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2921 DrawBuffers(useEXT, 4, halfDrawBuffers);
2922 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2923 ASSERT_GL_NO_ERROR();
2924
2925 CheckColors(renderbuffers, 0b1000, GLColor::green);
2926 CheckColors(renderbuffers, 0b0100, unwrittenColor);
2927 CheckColors(renderbuffers, 0b0011, GLColor::red);
2928 }
2929}
2930
Frank Henigmanfccbac22017-05-28 17:29:26 -04002931// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
2932// qualifiers.
2933TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
2934{
2935 const std::string vertexShader =
2936 "#version 300 es\n"
2937 "uniform Block { mediump vec4 val; };\n"
2938 "void main() { gl_Position = val; }\n";
2939 const std::string fragmentShader =
2940 "#version 300 es\n"
2941 "uniform Block { highp vec4 val; };\n"
2942 "out highp vec4 out_FragColor;\n"
2943 "void main() { out_FragColor = val; }\n";
2944
2945 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
2946 ASSERT_NE(0u, vs);
2947 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
2948 ASSERT_NE(0u, fs);
2949
2950 GLuint program = glCreateProgram();
2951
2952 glAttachShader(program, vs);
2953 glDeleteShader(vs);
2954 glAttachShader(program, fs);
2955 glDeleteShader(fs);
2956
2957 glLinkProgram(program);
2958 GLint linkStatus;
2959 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
2960 ASSERT_EQ(0, linkStatus);
2961
2962 glDeleteProgram(program);
2963}
2964
Geoff Lang69df2422017-07-05 12:42:31 -04002965// Test no attribute vertex shaders
2966TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
2967{
2968 const std::string vertexShader =
2969 "#version 300 es\n"
2970 "void main()\n"
2971 "{\n"
2972 "\n"
2973 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
2974 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
2975 "}";
2976 const std::string fragmentShader =
2977 "#version 300 es\n"
2978 "precision mediump float;\n"
2979 "out vec4 result;\n"
2980 "void main()\n"
2981 "{\n"
2982 " result = vec4(0, 1, 0, 1);\n"
2983 "}";
2984
2985 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2986 glUseProgram(program);
2987
2988 glDrawArrays(GL_TRIANGLES, 0, 6);
2989 ASSERT_GL_NO_ERROR();
2990 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2991}
2992
Geoff Langc287ea62016-09-16 14:46:51 -04002993// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2994// tests should be run against.
2995ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2996 ES2_D3D9(),
2997 ES2_D3D11(),
2998 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002999 ES2_OPENGL(),
3000 ES3_OPENGL(),
3001 ES2_OPENGLES(),
3002 ES3_OPENGLES());
3003
Jamie Madill07be8bf2017-02-02 19:59:57 -05003004ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04003005} // namespace