blob: 71f124ec919e6fd05c407ffc2c13251c234f1269 [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
11#include "test_utils/gl_raii.h"
12
Frank Henigman146e8a12017-03-02 23:22:37 -050013namespace
14{
15
16bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second)
17{
18 return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) &&
19 (second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA);
20}
21
22void CheckBlendFunctions(GLenum src, GLenum dst)
23{
24 if (ConstantColorAndAlphaBlendFunctions(src, dst) ||
25 ConstantColorAndAlphaBlendFunctions(dst, src))
26 {
27 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
28 }
29 else
30 {
31 ASSERT_GL_NO_ERROR();
32 }
33}
34
35} // namespace
36
Geoff Langc287ea62016-09-16 14:46:51 -040037namespace angle
38{
39
40class WebGLCompatibilityTest : public ANGLETest
41{
42 protected:
43 WebGLCompatibilityTest()
44 {
45 setWindowWidth(128);
46 setWindowHeight(128);
47 setConfigRedBits(8);
48 setConfigGreenBits(8);
49 setConfigBlueBits(8);
50 setConfigAlphaBits(8);
51 setWebGLCompatibilityEnabled(true);
52 }
53
54 void SetUp() override
55 {
56 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050057 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
58 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040059 }
60
Jamie Madillcad97ee2017-02-02 18:52:44 -050061 // Called from RenderingFeedbackLoopWithDrawBuffersEXT.
62 void drawBuffersEXTFeedbackLoop(GLuint program,
63 const std::array<GLenum, 2> &drawBuffers,
64 GLenum expectedError);
65
Jamie Madill07be8bf2017-02-02 19:59:57 -050066 // Called from RenderingFeedbackLoopWithDrawBuffers.
67 void drawBuffersFeedbackLoop(GLuint program,
68 const std::array<GLenum, 2> &drawBuffers,
69 GLenum expectedError);
70
Geoff Langc339c4e2016-11-29 10:37:36 -050071 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -040072};
73
Corentin Wallezfd456442016-12-21 17:57:00 -050074class WebGL2CompatibilityTest : public WebGLCompatibilityTest
75{
76};
77
Geoff Langc287ea62016-09-16 14:46:51 -040078// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
79// the GL extension should always be present
80TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
81{
82 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
83}
84
85// Verify that all extension entry points are available
86TEST_P(WebGLCompatibilityTest, EntryPoints)
87{
Geoff Langc339c4e2016-11-29 10:37:36 -050088 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -040089 {
Geoff Langc339c4e2016-11-29 10:37:36 -050090 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040091 }
92}
93
94// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
95// even in ES2 contexts.
96TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
97{
98 GLRenderbuffer renderbuffer;
99 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
100 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
101
102 GLFramebuffer framebuffer;
103 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
104 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
105 renderbuffer.get());
106
107 EXPECT_GL_NO_ERROR();
108}
109
110// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
111TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
112{
Geoff Langc339c4e2016-11-29 10:37:36 -0500113 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -0400114 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
115}
116
117// Test enabling the GL_OES_element_index_uint extension
118TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
119{
120 if (getClientMajorVersion() != 2)
121 {
122 // This test only works on ES2 where uint indices are not available by default
123 return;
124 }
125
126 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
127
128 GLBuffer indexBuffer;
129 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
130
131 GLuint data[] = {0, 1, 2, 1, 3, 2};
132 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
133
134 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
135 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
136 glUseProgram(program.get());
137
138 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
139 EXPECT_GL_ERROR(GL_INVALID_ENUM);
140
Geoff Langc339c4e2016-11-29 10:37:36 -0500141 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400142 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500143 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400144 EXPECT_GL_NO_ERROR();
145 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
146
147 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
148 EXPECT_GL_NO_ERROR();
149 }
150}
151
Geoff Langff5c63e2017-04-12 15:26:54 -0400152// Test enabling the GL_OES_standard_derivatives extension
153TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives)
154{
155 EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives"));
156
157 const std::string source =
158 "#extension GL_OES_standard_derivatives : require\n"
159 "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n";
160 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
161
162 if (extensionRequestable("GL_OES_standard_derivatives"))
163 {
164 glRequestExtensionANGLE("GL_OES_standard_derivatives");
165 EXPECT_GL_NO_ERROR();
166 EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives"));
167
168 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
169 ASSERT_NE(0u, shader);
170 glDeleteShader(shader);
171 }
172}
173
174// Test enabling the GL_EXT_shader_texture_lod extension
175TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD)
176{
177 EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod"));
178
179 const std::string source =
180 "#extension GL_EXT_shader_texture_lod : require\n"
181 "uniform sampler2D u_texture;\n"
182 "void main() {\n"
183 " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, "
184 "0.0));\n"
185 "}\n";
186 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
187
188 if (extensionRequestable("GL_EXT_shader_texture_lod"))
189 {
190 glRequestExtensionANGLE("GL_EXT_shader_texture_lod");
191 EXPECT_GL_NO_ERROR();
192 EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod"));
193
194 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
195 ASSERT_NE(0u, shader);
196 glDeleteShader(shader);
197 }
198}
199
200// Test enabling the GL_EXT_frag_depth extension
201TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth)
202{
203 EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth"));
204
205 const std::string source =
206 "#extension GL_EXT_frag_depth : require\n"
207 "void main() {\n"
208 " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
209 " gl_FragDepthEXT = 1.0;\n"
210 "}\n";
211 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
212
213 if (extensionRequestable("GL_EXT_frag_depth"))
214 {
215 glRequestExtensionANGLE("GL_EXT_frag_depth");
216 EXPECT_GL_NO_ERROR();
217 EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth"));
218
219 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
220 ASSERT_NE(0u, shader);
221 glDeleteShader(shader);
222 }
223}
224
Geoff Langd7d526a2017-02-21 16:48:43 -0500225// Test enabling the GL_EXT_texture_filter_anisotropic extension
226TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic)
227{
228 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
229
230 GLfloat maxAnisotropy = 0.0f;
231 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
232 EXPECT_GL_ERROR(GL_INVALID_ENUM);
233
234 GLTexture texture;
235 glBindTexture(GL_TEXTURE_2D, texture.get());
236 ASSERT_GL_NO_ERROR();
237
238 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
239 EXPECT_GL_ERROR(GL_INVALID_ENUM);
240
241 GLfloat currentAnisotropy = 0.0f;
242 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
243 EXPECT_GL_ERROR(GL_INVALID_ENUM);
244
245 if (extensionRequestable("GL_EXT_texture_filter_anisotropic"))
246 {
247 glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic");
248 EXPECT_GL_NO_ERROR();
249 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
250
251 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
252 ASSERT_GL_NO_ERROR();
253 EXPECT_GE(maxAnisotropy, 2.0f);
254
255 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
256 ASSERT_GL_NO_ERROR();
257 EXPECT_EQ(1.0f, currentAnisotropy);
258
259 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
260 ASSERT_GL_NO_ERROR();
261 }
262}
263
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700264// Verify that shaders are of a compatible spec when the extension is enabled.
265TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
266{
267 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
268
269 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
270 const std::string &vert =
271 "struct Foo {\n"
272 " int _webgl_bar;\n"
273 "};\n"
274 "void main()\n"
275 "{\n"
276 " Foo foo = Foo(1);\n"
277 "}";
278
279 // Default fragement shader.
280 const std::string &frag =
281 "void main()\n"
282 "{\n"
283 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
284 "}";
285
286 GLuint program = CompileProgram(vert, frag);
287 EXPECT_EQ(0u, program);
288 glDeleteProgram(program);
289}
290
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400291// Verify that the context generates the correct error when the framebuffer attachments are
292// different sizes
293TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch)
294{
295 GLFramebuffer fbo;
296 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
297
298 GLTexture textures[2];
299 glBindTexture(GL_TEXTURE_2D, textures[0]);
300 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
301 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
302
303 ASSERT_GL_NO_ERROR();
304 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
305
306 GLRenderbuffer renderbuffer;
307 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
308 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
309 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
310
311 ASSERT_GL_NO_ERROR();
312 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
313 glCheckFramebufferStatus(GL_FRAMEBUFFER));
314
315 if (extensionRequestable("GL_EXT_draw_buffers"))
316 {
317 glRequestExtensionANGLE("GL_EXT_draw_buffers");
318 EXPECT_GL_NO_ERROR();
319 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
320
321 glBindTexture(GL_TEXTURE_2D, textures[1]);
322 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
323 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
324 ASSERT_GL_NO_ERROR();
325
326 ASSERT_GL_NO_ERROR();
327 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
328 glCheckFramebufferStatus(GL_FRAMEBUFFER));
329
330 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
331
332 ASSERT_GL_NO_ERROR();
333 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
334
335 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
336
337 ASSERT_GL_NO_ERROR();
338 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
339 glCheckFramebufferStatus(GL_FRAMEBUFFER));
340 }
341}
342
Corentin Wallez327411e2016-12-09 11:09:17 -0500343// Test that client-side array buffers are forbidden in WebGL mode
344TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
345{
346 const std::string &vert =
347 "attribute vec3 a_pos;\n"
348 "void main()\n"
349 "{\n"
350 " gl_Position = vec4(a_pos, 1.0);\n"
351 "}\n";
352
353 const std::string &frag =
354 "precision highp float;\n"
355 "void main()\n"
356 "{\n"
357 " gl_FragColor = vec4(1.0);\n"
358 "}\n";
359
360 ANGLE_GL_PROGRAM(program, vert, frag);
361
362 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
363 ASSERT_NE(-1, posLocation);
364 glUseProgram(program.get());
365
366 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500367 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500368 glEnableVertexAttribArray(posLocation);
369
370 ASSERT_GL_NO_ERROR();
371 glDrawArrays(GL_TRIANGLES, 0, 6);
372 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
373}
374
375// Test that client-side element array buffers are forbidden in WebGL mode
376TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
377{
378 const std::string &vert =
379 "attribute vec3 a_pos;\n"
380 "void main()\n"
381 "{\n"
382 " gl_Position = vec4(a_pos, 1.0);\n"
383 "}\n";
384
385 const std::string &frag =
386 "precision highp float;\n"
387 "void main()\n"
388 "{\n"
389 " gl_FragColor = vec4(1.0);\n"
390 "}\n";
391
392 ANGLE_GL_PROGRAM(program, vert, frag);
393
394 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
395 ASSERT_NE(-1, posLocation);
396 glUseProgram(program.get());
397
398 const auto &vertices = GetQuadVertices();
399
400 GLBuffer vertexBuffer;
401 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
402 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
403 GL_STATIC_DRAW);
404
405 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
406 glEnableVertexAttribArray(posLocation);
407
Corentin Wallez327411e2016-12-09 11:09:17 -0500408 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500409
410 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
411 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
412 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
413 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500414 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
415}
416
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500417// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
418TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
419{
420 // Run the test in an FBO to make sure we have some stencil bits.
421 GLRenderbuffer renderbuffer;
422 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
423 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
424
425 GLFramebuffer framebuffer;
426 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
427 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
428 renderbuffer.get());
429
430 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
431 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
432 glUseProgram(program.get());
433 ASSERT_GL_NO_ERROR();
434
435 // Having ref and mask the same for front and back is valid.
436 glStencilMask(255);
437 glStencilFunc(GL_ALWAYS, 0, 255);
438 glDrawArrays(GL_TRIANGLES, 0, 6);
439 ASSERT_GL_NO_ERROR();
440
441 // Having a different front - back write mask generates an error.
442 glStencilMaskSeparate(GL_FRONT, 1);
443 glDrawArrays(GL_TRIANGLES, 0, 6);
444 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
445
446 // Setting both write masks separately to the same value is valid.
447 glStencilMaskSeparate(GL_BACK, 1);
448 glDrawArrays(GL_TRIANGLES, 0, 6);
449 ASSERT_GL_NO_ERROR();
450
451 // Having a different stencil front - back mask generates an error
452 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
453 glDrawArrays(GL_TRIANGLES, 0, 6);
454 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
455
456 // Setting both masks separately to the same value is valid.
457 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
458 glDrawArrays(GL_TRIANGLES, 0, 6);
459 ASSERT_GL_NO_ERROR();
460
461 // Having a different stencil front - back reference generates an error
462 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
463 glDrawArrays(GL_TRIANGLES, 0, 6);
464 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
465
466 // Setting both references separately to the same value is valid.
467 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
468 glDrawArrays(GL_TRIANGLES, 0, 6);
469 ASSERT_GL_NO_ERROR();
470
471 // Using different stencil funcs, everything being equal is valid.
472 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
473 glDrawArrays(GL_TRIANGLES, 0, 6);
474 ASSERT_GL_NO_ERROR();
475}
476
Corentin Wallez506fc9c2016-12-21 16:53:33 -0500477// Test that GL_FIXED is forbidden
478TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
479{
480 GLBuffer buffer;
481 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
482 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
483
484 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
485 ASSERT_GL_NO_ERROR();
486
487 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
488 EXPECT_GL_ERROR(GL_INVALID_ENUM);
489}
490
491// Test the WebGL limit of 255 for the attribute stride
492TEST_P(WebGLCompatibilityTest, MaxStride)
493{
494 GLBuffer buffer;
495 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
496 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
497
498 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
499 ASSERT_GL_NO_ERROR();
500
501 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
502 EXPECT_GL_ERROR(GL_INVALID_VALUE);
503}
504
Corentin Wallezfd456442016-12-21 17:57:00 -0500505// Test the checks for OOB reads in the vertex buffers, non-instanced version
506TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
507{
508 const std::string &vert =
509 "attribute float a_pos;\n"
510 "void main()\n"
511 "{\n"
512 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
513 "}\n";
514
515 const std::string &frag =
516 "precision highp float;\n"
517 "void main()\n"
518 "{\n"
519 " gl_FragColor = vec4(1.0);\n"
520 "}\n";
521
522 ANGLE_GL_PROGRAM(program, vert, frag);
523
524 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
525 ASSERT_NE(-1, posLocation);
526 glUseProgram(program.get());
527
528 GLBuffer buffer;
529 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
530 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
531
532 glEnableVertexAttribArray(posLocation);
533
534 const uint8_t* zeroOffset = nullptr;
535
536 // Test touching the last element is valid.
537 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
538 glDrawArrays(GL_POINTS, 0, 4);
539 ASSERT_GL_NO_ERROR();
540
541 // Test touching the last element + 1 is invalid.
542 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
543 glDrawArrays(GL_POINTS, 0, 4);
544 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
545
546 // Test touching the last element is valid, using a stride.
547 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
548 glDrawArrays(GL_POINTS, 0, 4);
549 ASSERT_GL_NO_ERROR();
550
551 // Test touching the last element + 1 is invalid, using a stride.
552 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
553 glDrawArrays(GL_POINTS, 0, 4);
554 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
555
556 // Test any offset is valid if no vertices are drawn.
557 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
558 glDrawArrays(GL_POINTS, 0, 0);
559 ASSERT_GL_NO_ERROR();
560}
561
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500562// Test the checks for OOB reads in the index buffer
563TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -0500564{
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500565 const std::string &vert =
566 "attribute float a_pos;\n"
567 "void main()\n"
568 "{\n"
569 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
570 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -0500571
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500572 const std::string &frag =
573 "precision highp float;\n"
574 "void main()\n"
575 "{\n"
576 " gl_FragColor = vec4(1.0);\n"
577 "}\n";
578
579 ANGLE_GL_PROGRAM(program, vert, frag);
580
581 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
582 ASSERT_NE(-1, posLocation);
583 glUseProgram(program.get());
584
585 GLBuffer vertexBuffer;
586 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
587 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
588
589 glEnableVertexAttribArray(posLocation);
590
591 const uint8_t *zeroOffset = nullptr;
592 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
593
594 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset);
595
596 GLBuffer indexBuffer;
597 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
598 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -0500599 ASSERT_GL_NO_ERROR();
600
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500601 // Test touching the last index is valid
602 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
603 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -0500604
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500605 // Test touching the last + 1 element is invalid
606 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
607 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -0500608
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500609 // Test any offset if valid if count is zero
610 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
611 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -0500612
613 // Test touching the first index is valid
614 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
615 ASSERT_GL_NO_ERROR();
616
617 // Test touching the first - 1 index is invalid
618 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
619 // the historic behavior of WebGL implementations
620 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
621 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -0500622}
623
Frank Henigman6137ddc2017-02-10 18:55:07 -0500624// Test depth range with 'near' more or less than 'far.'
625TEST_P(WebGLCompatibilityTest, DepthRange)
626{
627 glDepthRangef(0, 1);
628 ASSERT_GL_NO_ERROR();
629
630 glDepthRangef(.5, .5);
631 ASSERT_GL_NO_ERROR();
632
633 glDepthRangef(1, 0);
634 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
635}
636
Frank Henigman146e8a12017-03-02 23:22:37 -0500637// Test all blend function combinations.
638// In WebGL it is invalid to combine constant color with constant alpha.
639TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
640{
641 constexpr GLenum srcFunc[] = {
642 GL_ZERO,
643 GL_ONE,
644 GL_SRC_COLOR,
645 GL_ONE_MINUS_SRC_COLOR,
646 GL_DST_COLOR,
647 GL_ONE_MINUS_DST_COLOR,
648 GL_SRC_ALPHA,
649 GL_ONE_MINUS_SRC_ALPHA,
650 GL_DST_ALPHA,
651 GL_ONE_MINUS_DST_ALPHA,
652 GL_CONSTANT_COLOR,
653 GL_ONE_MINUS_CONSTANT_COLOR,
654 GL_CONSTANT_ALPHA,
655 GL_ONE_MINUS_CONSTANT_ALPHA,
656 GL_SRC_ALPHA_SATURATE,
657 };
658
659 constexpr GLenum dstFunc[] = {
660 GL_ZERO, GL_ONE,
661 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
662 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
663 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
664 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
665 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
666 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
667 };
668
669 for (GLenum src : srcFunc)
670 {
671 for (GLenum dst : dstFunc)
672 {
673 glBlendFunc(src, dst);
674 CheckBlendFunctions(src, dst);
675 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
676 CheckBlendFunctions(src, dst);
677 }
678 }
679}
680
Corentin Wallezfd456442016-12-21 17:57:00 -0500681// Test the checks for OOB reads in the vertex buffers, instanced version
682TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
683{
684 const std::string &vert =
685 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400686 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500687 "void main()\n"
688 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400689 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500690 "}\n";
691
692 const std::string &frag =
693 "precision highp float;\n"
694 "void main()\n"
695 "{\n"
696 " gl_FragColor = vec4(1.0);\n"
697 "}\n";
698
699 ANGLE_GL_PROGRAM(program, vert, frag);
700
701 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
702 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -0400703
704 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
705 ASSERT_NE(-1, wLocation);
706
Corentin Wallezfd456442016-12-21 17:57:00 -0500707 glUseProgram(program.get());
708
709 GLBuffer buffer;
710 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
711 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
712
713 glEnableVertexAttribArray(posLocation);
714 glVertexAttribDivisor(posLocation, 1);
715
Geoff Lang407d4e72017-04-12 14:54:11 -0400716 glEnableVertexAttribArray(wLocation);
717 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
718 glVertexAttribDivisor(wLocation, 0);
719
Corentin Wallezfd456442016-12-21 17:57:00 -0500720 const uint8_t* zeroOffset = nullptr;
721
722 // Test touching the last element is valid.
723 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
724 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
725 ASSERT_GL_NO_ERROR();
726
727 // Test touching the last element + 1 is invalid.
728 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
729 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
730 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
731
732 // Test touching the last element is valid, using a stride.
733 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
734 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
735 ASSERT_GL_NO_ERROR();
736
737 // Test touching the last element + 1 is invalid, using a stride.
738 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
739 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
740 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
741
742 // Test any offset is valid if no vertices are drawn.
743 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
744 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
745 ASSERT_GL_NO_ERROR();
746}
747
Geoff Lang407d4e72017-04-12 14:54:11 -0400748// Test that at least one attribute has a zero divisor for WebGL
749TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
750{
751 const std::string &vert =
752 "attribute float a_pos;\n"
753 "void main()\n"
754 "{\n"
755 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
756 "}\n";
757
758 const std::string &frag =
759 "precision highp float;\n"
760 "void main()\n"
761 "{\n"
762 " gl_FragColor = vec4(1.0);\n"
763 "}\n";
764
765 ANGLE_GL_PROGRAM(program, vert, frag);
766
767 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
768 ASSERT_NE(-1, posLocation);
769
770 glUseProgram(program.get());
771
772 GLBuffer buffer;
773 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
774 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
775
776 glEnableVertexAttribArray(posLocation);
777 glVertexAttribDivisor(posLocation, 1);
778
779 // Test touching the last element is valid.
780 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
781 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
782 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
783
784 glVertexAttribDivisor(posLocation, 0);
785 ASSERT_GL_NO_ERROR();
786}
787
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500788// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
789TEST_P(WebGLCompatibilityTest, NPOT)
790{
791 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
792
793 // Create a texture and set an NPOT mip 0, should always be acceptable.
794 GLTexture texture;
795 glBindTexture(GL_TEXTURE_2D, texture.get());
796 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
797 ASSERT_GL_NO_ERROR();
798
799 // Try setting an NPOT mip 1 and verify the error if WebGL 1
800 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
801 if (getClientMajorVersion() < 3)
802 {
803 ASSERT_GL_ERROR(GL_INVALID_VALUE);
804 }
805 else
806 {
807 ASSERT_GL_NO_ERROR();
808 }
809
810 if (extensionRequestable("GL_OES_texture_npot"))
811 {
812 glRequestExtensionANGLE("GL_OES_texture_npot");
813 ASSERT_GL_NO_ERROR();
814
815 // Try again to set NPOT mip 1
816 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
817 ASSERT_GL_NO_ERROR();
818 }
819}
820
Jamie Madillcad97ee2017-02-02 18:52:44 -0500821template <typename T>
822void FillTexture2D(GLuint texture,
823 GLsizei width,
824 GLsizei height,
825 const T &onePixelData,
826 GLint level,
827 GLint internalFormat,
828 GLenum format,
829 GLenum type)
830{
831 std::vector<T> allPixelsData(width * height, onePixelData);
832
833 glBindTexture(GL_TEXTURE_2D, texture);
834 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
835 allPixelsData.data());
836 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
837 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
840}
841
Frank Henigman875bbba2017-02-08 16:38:17 -0500842// Test that unset gl_Position defaults to (0,0,0,0).
843TEST_P(WebGLCompatibilityTest, DefaultPosition)
844{
845 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
846 // and green otherwise. The center of each quadrant will be red if and only if all
847 // four corners are red.
848 const std::string vertexShader =
849 "attribute vec3 pos;\n"
850 "varying vec4 color;\n"
851 "void main() {\n"
852 " if (gl_Position == vec4(0,0,0,0)) {\n"
853 " color = vec4(1,0,0,1);\n"
854 " } else {\n"
855 " color = vec4(0,1,0,1);\n"
856 " }\n"
857 " gl_Position = vec4(pos,1);\n"
858 "}\n";
859
860 const std::string fragmentShader =
861 "precision mediump float;\n"
862 "varying vec4 color;\n"
863 "void main() {\n"
864 " gl_FragColor = color;\n"
865 "}\n";
866
867 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
868 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
869 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
870 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
871 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
872 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
873}
874
Jamie Madilla4595b82017-01-11 17:36:34 -0500875// Tests that a rendering feedback loop triggers a GL error under WebGL.
876// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
877TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
878{
879 const std::string vertexShader =
880 "attribute vec4 a_position;\n"
881 "varying vec2 v_texCoord;\n"
882 "void main() {\n"
883 " gl_Position = a_position;\n"
884 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
885 "}\n";
886
887 const std::string fragmentShader =
888 "precision mediump float;\n"
889 "varying vec2 v_texCoord;\n"
890 "uniform sampler2D u_texture;\n"
891 "void main() {\n"
892 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
893 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
894 "}\n";
895
896 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -0500897 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -0500898
899 ASSERT_GL_NO_ERROR();
900
901 GLFramebuffer framebuffer;
902 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
903 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
904
905 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
906
907 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
908
909 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
910 ASSERT_NE(-1, uniformLoc);
911
912 glUseProgram(program.get());
913 glUniform1i(uniformLoc, 0);
914 glDisable(GL_BLEND);
915 glDisable(GL_DEPTH_TEST);
916 ASSERT_GL_NO_ERROR();
917
918 // Drawing with a texture that is also bound to the current framebuffer should fail
919 glBindTexture(GL_TEXTURE_2D, texture.get());
920 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
921 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
922
923 // Ensure that the texture contents did not change after the previous render
924 glBindFramebuffer(GL_FRAMEBUFFER, 0);
925 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
926 ASSERT_GL_NO_ERROR();
927 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
928
929 // Drawing when texture is bound to an inactive uniform should succeed
930 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -0500931 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -0500932
933 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
934 glActiveTexture(GL_TEXTURE1);
935 glBindTexture(GL_TEXTURE_2D, texture.get());
936 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
937 ASSERT_GL_NO_ERROR();
938 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
939}
940
Bryan Bernhart58806562017-01-05 13:09:31 -0800941// Test for the max draw buffers and color attachments.
942TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
943{
944 // This test only applies to ES2.
945 if (getClientMajorVersion() != 2)
946 {
947 return;
948 }
949
950 GLFramebuffer fbo[2];
951 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
952
953 // Test that is valid when we bind with a single attachment point.
954 GLTexture texture;
955 glBindTexture(GL_TEXTURE_2D, texture.get());
956 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
957 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
958 ASSERT_GL_NO_ERROR();
959
960 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
961 // attachment point.
962 if (extensionRequestable("GL_EXT_draw_buffers"))
963 {
964 glRequestExtensionANGLE("GL_EXT_draw_buffers");
965 EXPECT_GL_NO_ERROR();
966 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
967
968 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
969
970 GLTexture texture2;
971 glBindTexture(GL_TEXTURE_2D, texture2.get());
972 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
973 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
974 0);
975 ASSERT_GL_NO_ERROR();
976 }
977}
978
Corentin Wallez3f6d4df2017-01-30 18:04:36 -0500979// Test that the offset in the index buffer is forced to be a multiple of the element size
980TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
981{
982 const std::string &vert =
983 "attribute vec3 a_pos;\n"
984 "void main()\n"
985 "{\n"
986 " gl_Position = vec4(a_pos, 1.0);\n"
987 "}\n";
988
989 const std::string &frag =
990 "precision highp float;\n"
991 "void main()\n"
992 "{\n"
993 " gl_FragColor = vec4(1.0);\n"
994 "}\n";
995
996 ANGLE_GL_PROGRAM(program, vert, frag);
997
998 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
999 ASSERT_NE(-1, posLocation);
1000 glUseProgram(program.get());
1001
1002 const auto &vertices = GetQuadVertices();
1003
1004 GLBuffer vertexBuffer;
1005 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1006 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1007 GL_STATIC_DRAW);
1008
1009 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1010 glEnableVertexAttribArray(posLocation);
1011
1012 GLBuffer indexBuffer;
1013 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
1014 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1015 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1016
1017 ASSERT_GL_NO_ERROR();
1018
1019 const char *zeroIndices = nullptr;
1020
1021 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1022 ASSERT_GL_NO_ERROR();
1023
1024 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
1025 ASSERT_GL_NO_ERROR();
1026
1027 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
1028 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1029}
1030
1031// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1032// size
1033TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1034{
1035 const char *zeroOffset = nullptr;
1036
1037 // Base case, vector of two floats
1038 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1039 ASSERT_GL_NO_ERROR();
1040
1041 // Test setting a non-multiple offset
1042 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1043 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1044 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1045 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1046 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1047 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1048
1049 // Test setting a non-multiple stride
1050 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1051 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1052 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1053 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1054 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1055 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1056}
1057
Jamie Madillcad97ee2017-02-02 18:52:44 -05001058void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1059 const std::array<GLenum, 2> &drawBuffers,
1060 GLenum expectedError)
1061{
1062 glDrawBuffersEXT(2, drawBuffers.data());
1063
1064 // Make sure framebuffer is complete before feedback loop detection
1065 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1066
1067 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1068
1069 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1070 // it should be NO_ERROR"
1071 EXPECT_GL_ERROR(expectedError);
1072}
1073
1074// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1075// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1076TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1077{
1078 const std::string vertexShader =
1079 "attribute vec4 aPosition;\n"
1080 "varying vec2 texCoord;\n"
1081 "void main() {\n"
1082 " gl_Position = aPosition;\n"
1083 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1084 "}\n";
1085
1086 const std::string fragmentShader =
1087 "#extension GL_EXT_draw_buffers : require\n"
1088 "precision mediump float;\n"
1089 "uniform sampler2D tex;\n"
1090 "varying vec2 texCoord;\n"
1091 "void main() {\n"
1092 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1093 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1094 "}\n";
1095
1096 GLsizei width = 8;
1097 GLsizei height = 8;
1098
1099 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1100 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1101 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1102 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1103 {
1104 // No WEBGL_draw_buffers support -- this is legal.
1105 return;
1106 }
1107
1108 GLint maxDrawBuffers = 0;
1109 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1110
1111 if (maxDrawBuffers < 2)
1112 {
1113 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1114 return;
1115 }
1116
1117 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1118 glUseProgram(program.get());
1119 glViewport(0, 0, width, height);
1120
1121 GLTexture tex0;
1122 GLTexture tex1;
1123 GLFramebuffer fbo;
1124 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1125 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1126 ASSERT_GL_NO_ERROR();
1127
1128 glBindTexture(GL_TEXTURE_2D, tex1.get());
1129 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1130 ASSERT_NE(-1, texLoc);
1131 glUniform1i(texLoc, 0);
1132 ASSERT_GL_NO_ERROR();
1133
1134 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1135 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1136 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1138
1139 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1140 GL_INVALID_OPERATION);
1141 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1142 GL_INVALID_OPERATION);
1143 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1144}
1145
Jamie Madill07be8bf2017-02-02 19:59:57 -05001146// Test tests that texture copying feedback loops are properly rejected in WebGL.
1147// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1148TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1149{
1150 GLTexture texture;
1151 glBindTexture(GL_TEXTURE_2D, texture.get());
1152 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1155 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1156 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1157
1158 GLTexture texture2;
1159 glBindTexture(GL_TEXTURE_2D, texture2.get());
1160 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1165
1166 GLFramebuffer framebuffer;
1167 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1168 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1169
1170 // framebuffer should be FRAMEBUFFER_COMPLETE.
1171 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1172 ASSERT_GL_NO_ERROR();
1173
1174 // testing copyTexImage2D
1175
1176 // copyTexImage2D to same texture but different level
1177 glBindTexture(GL_TEXTURE_2D, texture.get());
1178 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1179 EXPECT_GL_NO_ERROR();
1180
1181 // copyTexImage2D to same texture same level, invalid feedback loop
1182 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1183 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1184
1185 // copyTexImage2D to different texture
1186 glBindTexture(GL_TEXTURE_2D, texture2.get());
1187 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1188 EXPECT_GL_NO_ERROR();
1189
1190 // testing copyTexSubImage2D
1191
1192 // copyTexSubImage2D to same texture but different level
1193 glBindTexture(GL_TEXTURE_2D, texture.get());
1194 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1195 EXPECT_GL_NO_ERROR();
1196
1197 // copyTexSubImage2D to same texture same level, invalid feedback loop
1198 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1199 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1200
1201 // copyTexSubImage2D to different texture
1202 glBindTexture(GL_TEXTURE_2D, texture2.get());
1203 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1204 EXPECT_GL_NO_ERROR();
1205}
1206
1207void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1208 const std::array<GLenum, 2> &drawBuffers,
1209 GLenum expectedError)
1210{
1211 glDrawBuffers(2, drawBuffers.data());
1212
1213 // Make sure framebuffer is complete before feedback loop detection
1214 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1215
1216 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1217
1218 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1219 // it should be NO_ERROR"
1220 EXPECT_GL_ERROR(expectedError);
1221}
1222
Yuly Novikov817232e2017-02-22 18:36:10 -05001223// Tests invariance matching rules between built in varyings.
1224// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1225TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1226{
1227 const std::string vertexShaderVariant =
1228 "varying vec4 v_varying;\n"
1229 "void main()\n"
1230 "{\n"
1231 " gl_PointSize = 1.0;\n"
1232 " gl_Position = v_varying;\n"
1233 "}";
1234 const std::string fragmentShaderInvariantGlFragCoord =
1235 "invariant gl_FragCoord;\n"
1236 "void main()\n"
1237 "{\n"
1238 " gl_FragColor = gl_FragCoord;\n"
1239 "}";
1240 const std::string fragmentShaderInvariantGlPointCoord =
1241 "invariant gl_PointCoord;\n"
1242 "void main()\n"
1243 "{\n"
1244 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1245 "}";
1246
1247 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1248 EXPECT_EQ(0u, program);
1249
1250 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1251 EXPECT_EQ(0u, program);
1252}
1253
Jamie Madill07be8bf2017-02-02 19:59:57 -05001254// This tests that rendering feedback loops works as expected with WebGL 2.
1255// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
1256TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
1257{
1258 const std::string vertexShader =
1259 "#version 300 es\n"
1260 "in vec4 aPosition;\n"
1261 "out vec2 texCoord;\n"
1262 "void main() {\n"
1263 " gl_Position = aPosition;\n"
1264 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1265 "}\n";
1266
1267 const std::string fragmentShader =
1268 "#version 300 es\n"
1269 "precision mediump float;\n"
1270 "uniform sampler2D tex;\n"
1271 "in vec2 texCoord;\n"
1272 "out vec4 oColor;\n"
1273 "void main() {\n"
1274 " oColor = texture(tex, texCoord);\n"
1275 "}\n";
1276
1277 GLsizei width = 8;
1278 GLsizei height = 8;
1279
1280 GLint maxDrawBuffers = 0;
1281 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1282 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
1283 ASSERT_GE(maxDrawBuffers, 2);
1284
1285 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1286 glUseProgram(program.get());
1287 glViewport(0, 0, width, height);
1288
1289 GLTexture tex0;
1290 GLTexture tex1;
1291 GLFramebuffer fbo;
1292 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1293 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1294 ASSERT_GL_NO_ERROR();
1295
1296 glBindTexture(GL_TEXTURE_2D, tex1.get());
1297 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1298 ASSERT_NE(-1, texLoc);
1299 glUniform1i(texLoc, 0);
1300
1301 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1302 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1303 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1304 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1305 ASSERT_GL_NO_ERROR();
1306
1307 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
1308 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1309 GL_INVALID_OPERATION);
1310 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1311}
1312
Jamie Madill1d37bc52017-02-02 19:59:58 -05001313// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
1314// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
1315TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
1316{
1317 const std::string vertexShader =
1318 "#version 300 es\n"
1319 "in vec4 aPosition;\n"
1320 "out vec2 texCoord;\n"
1321 "void main() {\n"
1322 " gl_Position = aPosition;\n"
1323 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1324 "}\n";
1325
1326 const std::string fragmentShader =
1327 "#version 300 es\n"
1328 "precision mediump float;\n"
1329 "uniform sampler2D tex;\n"
1330 "in vec2 texCoord;\n"
1331 "out vec4 oColor;\n"
1332 "void main() {\n"
1333 " oColor = texture(tex, texCoord);\n"
1334 "}\n";
1335
1336 GLsizei width = 8;
1337 GLsizei height = 8;
1338
1339 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1340 glUseProgram(program.get());
1341
1342 glViewport(0, 0, width, height);
1343
1344 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1345 glUniform1i(texLoc, 0);
1346
1347 // Create textures and allocate storage
1348 GLTexture tex0;
1349 GLTexture tex1;
1350 GLRenderbuffer rb;
1351 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1352 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
1353 GL_UNSIGNED_INT);
1354 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
1355 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
1356 ASSERT_GL_NO_ERROR();
1357
1358 GLFramebuffer fbo;
1359 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1360 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1361
1362 // Test rendering and sampling feedback loop for depth buffer
1363 glBindTexture(GL_TEXTURE_2D, tex1.get());
1364 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
1365 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1366
1367 // The same image is used as depth buffer during rendering.
1368 glEnable(GL_DEPTH_TEST);
1369 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1370 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1371
1372 // The same image is used as depth buffer. But depth mask is false.
1373 glDepthMask(GL_FALSE);
1374 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1375 EXPECT_GL_NO_ERROR();
1376
1377 // The same image is used as depth buffer. But depth test is not enabled during rendering.
1378 glDepthMask(GL_TRUE);
1379 glDisable(GL_DEPTH_TEST);
1380 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1381 EXPECT_GL_NO_ERROR();
1382
1383 // Test rendering and sampling feedback loop for stencil buffer
1384 glBindTexture(GL_RENDERBUFFER, rb.get());
1385 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
1386 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
1387 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1388 constexpr GLint stencilClearValue = 0x40;
1389 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
1390
1391 // The same image is used as stencil buffer during rendering.
1392 glEnable(GL_STENCIL_TEST);
1393 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1394 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1395
1396 // The same image is used as stencil buffer. But stencil mask is zero.
1397 glStencilMask(0x0);
1398 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1399 EXPECT_GL_NO_ERROR();
1400
1401 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
1402 glStencilMask(0xffff);
1403 glDisable(GL_STENCIL_TEST);
1404 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1405 EXPECT_GL_NO_ERROR();
1406}
1407
Jamie Madillfd3dd432017-02-02 19:59:59 -05001408// The source and the target for CopyTexSubImage3D are the same 3D texture.
1409// But the level of the 3D texture != the level of the read attachment.
1410TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
1411{
1412 GLTexture texture;
1413 GLFramebuffer framebuffer;
1414
1415 glBindTexture(GL_TEXTURE_3D, texture.get());
1416 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1417
1418 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1419 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1420 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
1421 ASSERT_GL_NO_ERROR();
1422
1423 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
1424 EXPECT_GL_NO_ERROR();
1425}
1426
1427// The source and the target for CopyTexSubImage3D are the same 3D texture.
1428// But the zoffset of the 3D texture != the layer of the read attachment.
1429TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
1430{
1431 GLTexture texture;
1432 GLFramebuffer framebuffer;
1433
1434 glBindTexture(GL_TEXTURE_3D, texture.get());
1435 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1436
1437 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1438 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
1439 ASSERT_GL_NO_ERROR();
1440
1441 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
1442 EXPECT_GL_NO_ERROR();
1443}
1444
1445// The source and the target for CopyTexSubImage3D are the same 3D texture.
1446// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
1447TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
1448{
1449 GLTexture texture;
1450 GLFramebuffer framebuffer;
1451
1452 glBindTexture(GL_TEXTURE_3D, texture.get());
1453 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1454
1455 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1456 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1457 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1458 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
1459 ASSERT_GL_NO_ERROR();
1460
1461 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
1462 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1463}
1464
Geoff Lang76e65652017-03-27 14:58:02 -04001465// Verify that errors are generated when there isn not a defined conversion between the clear type
1466// and the buffer type.
1467TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
1468{
1469 if (IsD3D11())
1470 {
1471 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
1472 return;
1473 }
1474
1475 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
1476 constexpr int clearInt[] = {0, 0, 0, 0};
1477 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
1478
1479 GLTexture texture;
1480 GLFramebuffer framebuffer;
1481
1482 glBindTexture(GL_TEXTURE_2D, texture.get());
1483 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1484
1485 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1486 ASSERT_GL_NO_ERROR();
1487
1488 // Unsigned integer buffer
1489 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
1490 ASSERT_GL_NO_ERROR();
1491
1492 glClearBufferfv(GL_COLOR, 0, clearFloat);
1493 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1494
1495 glClearBufferiv(GL_COLOR, 0, clearInt);
1496 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1497
1498 glClearBufferuiv(GL_COLOR, 0, clearUint);
1499 EXPECT_GL_NO_ERROR();
1500
1501 glClear(GL_COLOR_BUFFER_BIT);
1502 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1503
1504 // Integer buffer
1505 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
1506 ASSERT_GL_NO_ERROR();
1507
1508 glClearBufferfv(GL_COLOR, 0, clearFloat);
1509 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1510
1511 glClearBufferiv(GL_COLOR, 0, clearInt);
1512 EXPECT_GL_NO_ERROR();
1513
1514 glClearBufferuiv(GL_COLOR, 0, clearUint);
1515 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1516
1517 glClear(GL_COLOR_BUFFER_BIT);
1518 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1519
1520 // Float buffer
1521 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
1522 ASSERT_GL_NO_ERROR();
1523
1524 glClearBufferfv(GL_COLOR, 0, clearFloat);
1525 EXPECT_GL_NO_ERROR();
1526
1527 glClearBufferiv(GL_COLOR, 0, clearInt);
1528 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1529
1530 glClearBufferuiv(GL_COLOR, 0, clearUint);
1531 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1532
1533 glClear(GL_COLOR_BUFFER_BIT);
1534 EXPECT_GL_NO_ERROR();
1535
1536 // Normalized uint buffer
1537 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1538 ASSERT_GL_NO_ERROR();
1539
1540 glClearBufferfv(GL_COLOR, 0, clearFloat);
1541 EXPECT_GL_NO_ERROR();
1542
1543 glClearBufferiv(GL_COLOR, 0, clearInt);
1544 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1545
1546 glClearBufferuiv(GL_COLOR, 0, clearUint);
1547 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1548
1549 glClear(GL_COLOR_BUFFER_BIT);
1550 EXPECT_GL_NO_ERROR();
1551}
1552
Geoff Lange4915782017-04-12 15:19:07 -04001553// Verify that errors are generate when trying to blit from an image to itself
1554TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
1555{
1556 GLTexture textures[2];
1557 glBindTexture(GL_TEXTURE_2D, textures[0]);
1558 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
1559 glBindTexture(GL_TEXTURE_2D, textures[1]);
1560 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
1561
1562 GLRenderbuffer renderbuffers[2];
1563 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
1564 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
1565 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
1566 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
1567
1568 GLFramebuffer framebuffers[2];
1569 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
1570 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
1571
1572 ASSERT_GL_NO_ERROR();
1573
1574 // Same texture
1575 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
1576 0);
1577 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
1578 0);
1579 ASSERT_GL_NO_ERROR();
1580 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1581 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1582
1583 // Same textures but different renderbuffers
1584 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1585 renderbuffers[0]);
1586 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1587 renderbuffers[1]);
1588 ASSERT_GL_NO_ERROR();
1589 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
1590 ASSERT_GL_NO_ERROR();
1591 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1592 GL_NEAREST);
1593 ASSERT_GL_NO_ERROR();
1594 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
1595 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1596 GL_NEAREST);
1597 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1598
1599 // Same renderbuffers but different textures
1600 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
1601 0);
1602 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
1603 0);
1604 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1605 renderbuffers[0]);
1606 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1607 renderbuffers[0]);
1608 ASSERT_GL_NO_ERROR();
1609 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1610 ASSERT_GL_NO_ERROR();
1611 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1612 GL_NEAREST);
1613 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1614 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
1615 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
1616 GL_NEAREST);
1617 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1618}
1619
Geoff Langc287ea62016-09-16 14:46:51 -04001620// Use this to select which configurations (e.g. which renderer, which GLES major version) these
1621// tests should be run against.
1622ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
1623 ES2_D3D9(),
1624 ES2_D3D11(),
1625 ES3_D3D11(),
1626 ES2_D3D11_FL9_3(),
1627 ES2_OPENGL(),
1628 ES3_OPENGL(),
1629 ES2_OPENGLES(),
1630 ES3_OPENGLES());
1631
Jamie Madill07be8bf2017-02-02 19:59:57 -05001632ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04001633} // namespace