blob: 0be2b647de230a26a047c828995405281ebb6dda [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"
686 "void main()\n"
687 "{\n"
688 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
689 "}\n";
690
691 const std::string &frag =
692 "precision highp float;\n"
693 "void main()\n"
694 "{\n"
695 " gl_FragColor = vec4(1.0);\n"
696 "}\n";
697
698 ANGLE_GL_PROGRAM(program, vert, frag);
699
700 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
701 ASSERT_NE(-1, posLocation);
702 glUseProgram(program.get());
703
704 GLBuffer buffer;
705 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
706 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
707
708 glEnableVertexAttribArray(posLocation);
709 glVertexAttribDivisor(posLocation, 1);
710
711 const uint8_t* zeroOffset = nullptr;
712
713 // Test touching the last element is valid.
714 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
715 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
716 ASSERT_GL_NO_ERROR();
717
718 // Test touching the last element + 1 is invalid.
719 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
720 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
721 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
722
723 // Test touching the last element is valid, using a stride.
724 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
725 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
726 ASSERT_GL_NO_ERROR();
727
728 // Test touching the last element + 1 is invalid, using a stride.
729 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
730 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
731 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
732
733 // Test any offset is valid if no vertices are drawn.
734 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
735 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
736 ASSERT_GL_NO_ERROR();
737}
738
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500739// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
740TEST_P(WebGLCompatibilityTest, NPOT)
741{
742 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
743
744 // Create a texture and set an NPOT mip 0, should always be acceptable.
745 GLTexture texture;
746 glBindTexture(GL_TEXTURE_2D, texture.get());
747 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
748 ASSERT_GL_NO_ERROR();
749
750 // Try setting an NPOT mip 1 and verify the error if WebGL 1
751 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
752 if (getClientMajorVersion() < 3)
753 {
754 ASSERT_GL_ERROR(GL_INVALID_VALUE);
755 }
756 else
757 {
758 ASSERT_GL_NO_ERROR();
759 }
760
761 if (extensionRequestable("GL_OES_texture_npot"))
762 {
763 glRequestExtensionANGLE("GL_OES_texture_npot");
764 ASSERT_GL_NO_ERROR();
765
766 // Try again to set NPOT mip 1
767 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
768 ASSERT_GL_NO_ERROR();
769 }
770}
771
Jamie Madillcad97ee2017-02-02 18:52:44 -0500772template <typename T>
773void FillTexture2D(GLuint texture,
774 GLsizei width,
775 GLsizei height,
776 const T &onePixelData,
777 GLint level,
778 GLint internalFormat,
779 GLenum format,
780 GLenum type)
781{
782 std::vector<T> allPixelsData(width * height, onePixelData);
783
784 glBindTexture(GL_TEXTURE_2D, texture);
785 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
786 allPixelsData.data());
787 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
788 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
789 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
790 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
791}
792
Frank Henigman875bbba2017-02-08 16:38:17 -0500793// Test that unset gl_Position defaults to (0,0,0,0).
794TEST_P(WebGLCompatibilityTest, DefaultPosition)
795{
796 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
797 // and green otherwise. The center of each quadrant will be red if and only if all
798 // four corners are red.
799 const std::string vertexShader =
800 "attribute vec3 pos;\n"
801 "varying vec4 color;\n"
802 "void main() {\n"
803 " if (gl_Position == vec4(0,0,0,0)) {\n"
804 " color = vec4(1,0,0,1);\n"
805 " } else {\n"
806 " color = vec4(0,1,0,1);\n"
807 " }\n"
808 " gl_Position = vec4(pos,1);\n"
809 "}\n";
810
811 const std::string fragmentShader =
812 "precision mediump float;\n"
813 "varying vec4 color;\n"
814 "void main() {\n"
815 " gl_FragColor = color;\n"
816 "}\n";
817
818 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
819 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
820 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
821 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
822 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
823 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
824}
825
Jamie Madilla4595b82017-01-11 17:36:34 -0500826// Tests that a rendering feedback loop triggers a GL error under WebGL.
827// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
828TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
829{
830 const std::string vertexShader =
831 "attribute vec4 a_position;\n"
832 "varying vec2 v_texCoord;\n"
833 "void main() {\n"
834 " gl_Position = a_position;\n"
835 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
836 "}\n";
837
838 const std::string fragmentShader =
839 "precision mediump float;\n"
840 "varying vec2 v_texCoord;\n"
841 "uniform sampler2D u_texture;\n"
842 "void main() {\n"
843 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
844 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
845 "}\n";
846
847 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -0500848 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -0500849
850 ASSERT_GL_NO_ERROR();
851
852 GLFramebuffer framebuffer;
853 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
854 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
855
856 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
857
858 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
859
860 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
861 ASSERT_NE(-1, uniformLoc);
862
863 glUseProgram(program.get());
864 glUniform1i(uniformLoc, 0);
865 glDisable(GL_BLEND);
866 glDisable(GL_DEPTH_TEST);
867 ASSERT_GL_NO_ERROR();
868
869 // Drawing with a texture that is also bound to the current framebuffer should fail
870 glBindTexture(GL_TEXTURE_2D, texture.get());
871 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
872 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
873
874 // Ensure that the texture contents did not change after the previous render
875 glBindFramebuffer(GL_FRAMEBUFFER, 0);
876 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
877 ASSERT_GL_NO_ERROR();
878 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
879
880 // Drawing when texture is bound to an inactive uniform should succeed
881 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -0500882 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -0500883
884 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
885 glActiveTexture(GL_TEXTURE1);
886 glBindTexture(GL_TEXTURE_2D, texture.get());
887 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
888 ASSERT_GL_NO_ERROR();
889 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
890}
891
Bryan Bernhart58806562017-01-05 13:09:31 -0800892// Test for the max draw buffers and color attachments.
893TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
894{
895 // This test only applies to ES2.
896 if (getClientMajorVersion() != 2)
897 {
898 return;
899 }
900
901 GLFramebuffer fbo[2];
902 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
903
904 // Test that is valid when we bind with a single attachment point.
905 GLTexture texture;
906 glBindTexture(GL_TEXTURE_2D, texture.get());
907 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
908 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
909 ASSERT_GL_NO_ERROR();
910
911 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
912 // attachment point.
913 if (extensionRequestable("GL_EXT_draw_buffers"))
914 {
915 glRequestExtensionANGLE("GL_EXT_draw_buffers");
916 EXPECT_GL_NO_ERROR();
917 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
918
919 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
920
921 GLTexture texture2;
922 glBindTexture(GL_TEXTURE_2D, texture2.get());
923 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
924 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
925 0);
926 ASSERT_GL_NO_ERROR();
927 }
928}
929
Corentin Wallez3f6d4df2017-01-30 18:04:36 -0500930// Test that the offset in the index buffer is forced to be a multiple of the element size
931TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
932{
933 const std::string &vert =
934 "attribute vec3 a_pos;\n"
935 "void main()\n"
936 "{\n"
937 " gl_Position = vec4(a_pos, 1.0);\n"
938 "}\n";
939
940 const std::string &frag =
941 "precision highp float;\n"
942 "void main()\n"
943 "{\n"
944 " gl_FragColor = vec4(1.0);\n"
945 "}\n";
946
947 ANGLE_GL_PROGRAM(program, vert, frag);
948
949 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
950 ASSERT_NE(-1, posLocation);
951 glUseProgram(program.get());
952
953 const auto &vertices = GetQuadVertices();
954
955 GLBuffer vertexBuffer;
956 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
957 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
958 GL_STATIC_DRAW);
959
960 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
961 glEnableVertexAttribArray(posLocation);
962
963 GLBuffer indexBuffer;
964 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
965 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
966 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
967
968 ASSERT_GL_NO_ERROR();
969
970 const char *zeroIndices = nullptr;
971
972 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
973 ASSERT_GL_NO_ERROR();
974
975 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
976 ASSERT_GL_NO_ERROR();
977
978 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
979 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
980}
981
982// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
983// size
984TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
985{
986 const char *zeroOffset = nullptr;
987
988 // Base case, vector of two floats
989 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
990 ASSERT_GL_NO_ERROR();
991
992 // Test setting a non-multiple offset
993 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
994 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
995 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
996 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
997 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
998 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
999
1000 // Test setting a non-multiple stride
1001 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1002 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1003 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1004 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1005 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1006 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1007}
1008
Jamie Madillcad97ee2017-02-02 18:52:44 -05001009void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1010 const std::array<GLenum, 2> &drawBuffers,
1011 GLenum expectedError)
1012{
1013 glDrawBuffersEXT(2, drawBuffers.data());
1014
1015 // Make sure framebuffer is complete before feedback loop detection
1016 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1017
1018 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1019
1020 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1021 // it should be NO_ERROR"
1022 EXPECT_GL_ERROR(expectedError);
1023}
1024
1025// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1026// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1027TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1028{
1029 const std::string vertexShader =
1030 "attribute vec4 aPosition;\n"
1031 "varying vec2 texCoord;\n"
1032 "void main() {\n"
1033 " gl_Position = aPosition;\n"
1034 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1035 "}\n";
1036
1037 const std::string fragmentShader =
1038 "#extension GL_EXT_draw_buffers : require\n"
1039 "precision mediump float;\n"
1040 "uniform sampler2D tex;\n"
1041 "varying vec2 texCoord;\n"
1042 "void main() {\n"
1043 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1044 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1045 "}\n";
1046
1047 GLsizei width = 8;
1048 GLsizei height = 8;
1049
1050 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1051 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1052 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1053 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1054 {
1055 // No WEBGL_draw_buffers support -- this is legal.
1056 return;
1057 }
1058
1059 GLint maxDrawBuffers = 0;
1060 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1061
1062 if (maxDrawBuffers < 2)
1063 {
1064 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1065 return;
1066 }
1067
1068 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1069 glUseProgram(program.get());
1070 glViewport(0, 0, width, height);
1071
1072 GLTexture tex0;
1073 GLTexture tex1;
1074 GLFramebuffer fbo;
1075 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1076 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1077 ASSERT_GL_NO_ERROR();
1078
1079 glBindTexture(GL_TEXTURE_2D, tex1.get());
1080 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1081 ASSERT_NE(-1, texLoc);
1082 glUniform1i(texLoc, 0);
1083 ASSERT_GL_NO_ERROR();
1084
1085 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1086 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1087 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1088 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1089
1090 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1091 GL_INVALID_OPERATION);
1092 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1093 GL_INVALID_OPERATION);
1094 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1095}
1096
Jamie Madill07be8bf2017-02-02 19:59:57 -05001097// Test tests that texture copying feedback loops are properly rejected in WebGL.
1098// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1099TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1100{
1101 GLTexture texture;
1102 glBindTexture(GL_TEXTURE_2D, texture.get());
1103 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1108
1109 GLTexture texture2;
1110 glBindTexture(GL_TEXTURE_2D, texture2.get());
1111 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1116
1117 GLFramebuffer framebuffer;
1118 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1119 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1120
1121 // framebuffer should be FRAMEBUFFER_COMPLETE.
1122 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1123 ASSERT_GL_NO_ERROR();
1124
1125 // testing copyTexImage2D
1126
1127 // copyTexImage2D to same texture but different level
1128 glBindTexture(GL_TEXTURE_2D, texture.get());
1129 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1130 EXPECT_GL_NO_ERROR();
1131
1132 // copyTexImage2D to same texture same level, invalid feedback loop
1133 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1134 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1135
1136 // copyTexImage2D to different texture
1137 glBindTexture(GL_TEXTURE_2D, texture2.get());
1138 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1139 EXPECT_GL_NO_ERROR();
1140
1141 // testing copyTexSubImage2D
1142
1143 // copyTexSubImage2D to same texture but different level
1144 glBindTexture(GL_TEXTURE_2D, texture.get());
1145 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1146 EXPECT_GL_NO_ERROR();
1147
1148 // copyTexSubImage2D to same texture same level, invalid feedback loop
1149 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1150 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1151
1152 // copyTexSubImage2D to different texture
1153 glBindTexture(GL_TEXTURE_2D, texture2.get());
1154 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1155 EXPECT_GL_NO_ERROR();
1156}
1157
1158void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1159 const std::array<GLenum, 2> &drawBuffers,
1160 GLenum expectedError)
1161{
1162 glDrawBuffers(2, drawBuffers.data());
1163
1164 // Make sure framebuffer is complete before feedback loop detection
1165 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1166
1167 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1168
1169 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1170 // it should be NO_ERROR"
1171 EXPECT_GL_ERROR(expectedError);
1172}
1173
Yuly Novikov817232e2017-02-22 18:36:10 -05001174// Tests invariance matching rules between built in varyings.
1175// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1176TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1177{
1178 const std::string vertexShaderVariant =
1179 "varying vec4 v_varying;\n"
1180 "void main()\n"
1181 "{\n"
1182 " gl_PointSize = 1.0;\n"
1183 " gl_Position = v_varying;\n"
1184 "}";
1185 const std::string fragmentShaderInvariantGlFragCoord =
1186 "invariant gl_FragCoord;\n"
1187 "void main()\n"
1188 "{\n"
1189 " gl_FragColor = gl_FragCoord;\n"
1190 "}";
1191 const std::string fragmentShaderInvariantGlPointCoord =
1192 "invariant gl_PointCoord;\n"
1193 "void main()\n"
1194 "{\n"
1195 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1196 "}";
1197
1198 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1199 EXPECT_EQ(0u, program);
1200
1201 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1202 EXPECT_EQ(0u, program);
1203}
1204
Jamie Madill07be8bf2017-02-02 19:59:57 -05001205// This tests that rendering feedback loops works as expected with WebGL 2.
1206// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
1207TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
1208{
1209 const std::string vertexShader =
1210 "#version 300 es\n"
1211 "in vec4 aPosition;\n"
1212 "out vec2 texCoord;\n"
1213 "void main() {\n"
1214 " gl_Position = aPosition;\n"
1215 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1216 "}\n";
1217
1218 const std::string fragmentShader =
1219 "#version 300 es\n"
1220 "precision mediump float;\n"
1221 "uniform sampler2D tex;\n"
1222 "in vec2 texCoord;\n"
1223 "out vec4 oColor;\n"
1224 "void main() {\n"
1225 " oColor = texture(tex, texCoord);\n"
1226 "}\n";
1227
1228 GLsizei width = 8;
1229 GLsizei height = 8;
1230
1231 GLint maxDrawBuffers = 0;
1232 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1233 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
1234 ASSERT_GE(maxDrawBuffers, 2);
1235
1236 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1237 glUseProgram(program.get());
1238 glViewport(0, 0, width, height);
1239
1240 GLTexture tex0;
1241 GLTexture tex1;
1242 GLFramebuffer fbo;
1243 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1244 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1245 ASSERT_GL_NO_ERROR();
1246
1247 glBindTexture(GL_TEXTURE_2D, tex1.get());
1248 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1249 ASSERT_NE(-1, texLoc);
1250 glUniform1i(texLoc, 0);
1251
1252 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1253 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1254 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1255 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1256 ASSERT_GL_NO_ERROR();
1257
1258 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
1259 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1260 GL_INVALID_OPERATION);
1261 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1262}
1263
Jamie Madill1d37bc52017-02-02 19:59:58 -05001264// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
1265// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
1266TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
1267{
1268 const std::string vertexShader =
1269 "#version 300 es\n"
1270 "in vec4 aPosition;\n"
1271 "out vec2 texCoord;\n"
1272 "void main() {\n"
1273 " gl_Position = aPosition;\n"
1274 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1275 "}\n";
1276
1277 const std::string fragmentShader =
1278 "#version 300 es\n"
1279 "precision mediump float;\n"
1280 "uniform sampler2D tex;\n"
1281 "in vec2 texCoord;\n"
1282 "out vec4 oColor;\n"
1283 "void main() {\n"
1284 " oColor = texture(tex, texCoord);\n"
1285 "}\n";
1286
1287 GLsizei width = 8;
1288 GLsizei height = 8;
1289
1290 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1291 glUseProgram(program.get());
1292
1293 glViewport(0, 0, width, height);
1294
1295 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1296 glUniform1i(texLoc, 0);
1297
1298 // Create textures and allocate storage
1299 GLTexture tex0;
1300 GLTexture tex1;
1301 GLRenderbuffer rb;
1302 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1303 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
1304 GL_UNSIGNED_INT);
1305 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
1306 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
1307 ASSERT_GL_NO_ERROR();
1308
1309 GLFramebuffer fbo;
1310 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1311 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1312
1313 // Test rendering and sampling feedback loop for depth buffer
1314 glBindTexture(GL_TEXTURE_2D, tex1.get());
1315 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
1316 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1317
1318 // The same image is used as depth buffer during rendering.
1319 glEnable(GL_DEPTH_TEST);
1320 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1321 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1322
1323 // The same image is used as depth buffer. But depth mask is false.
1324 glDepthMask(GL_FALSE);
1325 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1326 EXPECT_GL_NO_ERROR();
1327
1328 // The same image is used as depth buffer. But depth test is not enabled during rendering.
1329 glDepthMask(GL_TRUE);
1330 glDisable(GL_DEPTH_TEST);
1331 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1332 EXPECT_GL_NO_ERROR();
1333
1334 // Test rendering and sampling feedback loop for stencil buffer
1335 glBindTexture(GL_RENDERBUFFER, rb.get());
1336 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
1337 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
1338 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1339 constexpr GLint stencilClearValue = 0x40;
1340 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
1341
1342 // The same image is used as stencil buffer during rendering.
1343 glEnable(GL_STENCIL_TEST);
1344 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1345 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1346
1347 // The same image is used as stencil buffer. But stencil mask is zero.
1348 glStencilMask(0x0);
1349 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1350 EXPECT_GL_NO_ERROR();
1351
1352 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
1353 glStencilMask(0xffff);
1354 glDisable(GL_STENCIL_TEST);
1355 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
1356 EXPECT_GL_NO_ERROR();
1357}
1358
Jamie Madillfd3dd432017-02-02 19:59:59 -05001359// The source and the target for CopyTexSubImage3D are the same 3D texture.
1360// But the level of the 3D texture != the level of the read attachment.
1361TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
1362{
1363 GLTexture texture;
1364 GLFramebuffer framebuffer;
1365
1366 glBindTexture(GL_TEXTURE_3D, texture.get());
1367 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1368
1369 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1370 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1371 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
1372 ASSERT_GL_NO_ERROR();
1373
1374 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
1375 EXPECT_GL_NO_ERROR();
1376}
1377
1378// The source and the target for CopyTexSubImage3D are the same 3D texture.
1379// But the zoffset of the 3D texture != the layer of the read attachment.
1380TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
1381{
1382 GLTexture texture;
1383 GLFramebuffer framebuffer;
1384
1385 glBindTexture(GL_TEXTURE_3D, texture.get());
1386 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1387
1388 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1389 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
1390 ASSERT_GL_NO_ERROR();
1391
1392 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
1393 EXPECT_GL_NO_ERROR();
1394}
1395
1396// The source and the target for CopyTexSubImage3D are the same 3D texture.
1397// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
1398TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
1399{
1400 GLTexture texture;
1401 GLFramebuffer framebuffer;
1402
1403 glBindTexture(GL_TEXTURE_3D, texture.get());
1404 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1405
1406 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1407 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1408 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1409 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
1410 ASSERT_GL_NO_ERROR();
1411
1412 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
1413 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1414}
1415
Geoff Lang76e65652017-03-27 14:58:02 -04001416// Verify that errors are generated when there isn not a defined conversion between the clear type
1417// and the buffer type.
1418TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
1419{
1420 if (IsD3D11())
1421 {
1422 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
1423 return;
1424 }
1425
1426 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
1427 constexpr int clearInt[] = {0, 0, 0, 0};
1428 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
1429
1430 GLTexture texture;
1431 GLFramebuffer framebuffer;
1432
1433 glBindTexture(GL_TEXTURE_2D, texture.get());
1434 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1435
1436 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1437 ASSERT_GL_NO_ERROR();
1438
1439 // Unsigned integer buffer
1440 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
1441 ASSERT_GL_NO_ERROR();
1442
1443 glClearBufferfv(GL_COLOR, 0, clearFloat);
1444 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1445
1446 glClearBufferiv(GL_COLOR, 0, clearInt);
1447 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1448
1449 glClearBufferuiv(GL_COLOR, 0, clearUint);
1450 EXPECT_GL_NO_ERROR();
1451
1452 glClear(GL_COLOR_BUFFER_BIT);
1453 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1454
1455 // Integer buffer
1456 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
1457 ASSERT_GL_NO_ERROR();
1458
1459 glClearBufferfv(GL_COLOR, 0, clearFloat);
1460 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1461
1462 glClearBufferiv(GL_COLOR, 0, clearInt);
1463 EXPECT_GL_NO_ERROR();
1464
1465 glClearBufferuiv(GL_COLOR, 0, clearUint);
1466 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1467
1468 glClear(GL_COLOR_BUFFER_BIT);
1469 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1470
1471 // Float buffer
1472 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
1473 ASSERT_GL_NO_ERROR();
1474
1475 glClearBufferfv(GL_COLOR, 0, clearFloat);
1476 EXPECT_GL_NO_ERROR();
1477
1478 glClearBufferiv(GL_COLOR, 0, clearInt);
1479 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1480
1481 glClearBufferuiv(GL_COLOR, 0, clearUint);
1482 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1483
1484 glClear(GL_COLOR_BUFFER_BIT);
1485 EXPECT_GL_NO_ERROR();
1486
1487 // Normalized uint buffer
1488 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1489 ASSERT_GL_NO_ERROR();
1490
1491 glClearBufferfv(GL_COLOR, 0, clearFloat);
1492 EXPECT_GL_NO_ERROR();
1493
1494 glClearBufferiv(GL_COLOR, 0, clearInt);
1495 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1496
1497 glClearBufferuiv(GL_COLOR, 0, clearUint);
1498 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1499
1500 glClear(GL_COLOR_BUFFER_BIT);
1501 EXPECT_GL_NO_ERROR();
1502}
1503
Geoff Langc287ea62016-09-16 14:46:51 -04001504// Use this to select which configurations (e.g. which renderer, which GLES major version) these
1505// tests should be run against.
1506ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
1507 ES2_D3D9(),
1508 ES2_D3D11(),
1509 ES3_D3D11(),
1510 ES2_D3D11_FL9_3(),
1511 ES2_OPENGL(),
1512 ES3_OPENGL(),
1513 ES2_OPENGLES(),
1514 ES3_OPENGLES());
1515
Jamie Madill07be8bf2017-02-02 19:59:57 -05001516ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04001517} // namespace