blob: 8f3f71c90ac49216ef44f2a38430105a45f26532 [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
13namespace angle
14{
15
16class WebGLCompatibilityTest : public ANGLETest
17{
18 protected:
19 WebGLCompatibilityTest()
20 {
21 setWindowWidth(128);
22 setWindowHeight(128);
23 setConfigRedBits(8);
24 setConfigGreenBits(8);
25 setConfigBlueBits(8);
26 setConfigAlphaBits(8);
27 setWebGLCompatibilityEnabled(true);
28 }
29
30 void SetUp() override
31 {
32 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050033 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
34 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040035 }
36
37 void TearDown() override { ANGLETest::TearDown(); }
38
Geoff Langc339c4e2016-11-29 10:37:36 -050039 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -040040};
41
Corentin Wallezfd456442016-12-21 17:57:00 -050042class WebGL2CompatibilityTest : public WebGLCompatibilityTest
43{
44};
45
Geoff Langc287ea62016-09-16 14:46:51 -040046// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
47// the GL extension should always be present
48TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
49{
50 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
51}
52
53// Verify that all extension entry points are available
54TEST_P(WebGLCompatibilityTest, EntryPoints)
55{
Geoff Langc339c4e2016-11-29 10:37:36 -050056 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -040057 {
Geoff Langc339c4e2016-11-29 10:37:36 -050058 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040059 }
60}
61
62// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
63// even in ES2 contexts.
64TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
65{
66 GLRenderbuffer renderbuffer;
67 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
68 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
69
70 GLFramebuffer framebuffer;
71 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
72 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
73 renderbuffer.get());
74
75 EXPECT_GL_NO_ERROR();
76}
77
78// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
79TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
80{
Geoff Langc339c4e2016-11-29 10:37:36 -050081 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -040082 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
83}
84
85// Test enabling the GL_OES_element_index_uint extension
86TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
87{
88 if (getClientMajorVersion() != 2)
89 {
90 // This test only works on ES2 where uint indices are not available by default
91 return;
92 }
93
94 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
95
96 GLBuffer indexBuffer;
97 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
98
99 GLuint data[] = {0, 1, 2, 1, 3, 2};
100 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
101
102 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
103 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
104 glUseProgram(program.get());
105
106 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
107 EXPECT_GL_ERROR(GL_INVALID_ENUM);
108
Geoff Langc339c4e2016-11-29 10:37:36 -0500109 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400110 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500111 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400112 EXPECT_GL_NO_ERROR();
113 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
114
115 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
116 EXPECT_GL_NO_ERROR();
117 }
118}
119
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700120// Verify that shaders are of a compatible spec when the extension is enabled.
121TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
122{
123 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
124
125 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
126 const std::string &vert =
127 "struct Foo {\n"
128 " int _webgl_bar;\n"
129 "};\n"
130 "void main()\n"
131 "{\n"
132 " Foo foo = Foo(1);\n"
133 "}";
134
135 // Default fragement shader.
136 const std::string &frag =
137 "void main()\n"
138 "{\n"
139 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
140 "}";
141
142 GLuint program = CompileProgram(vert, frag);
143 EXPECT_EQ(0u, program);
144 glDeleteProgram(program);
145}
146
Corentin Wallez327411e2016-12-09 11:09:17 -0500147// Test that client-side array buffers are forbidden in WebGL mode
148TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
149{
150 const std::string &vert =
151 "attribute vec3 a_pos;\n"
152 "void main()\n"
153 "{\n"
154 " gl_Position = vec4(a_pos, 1.0);\n"
155 "}\n";
156
157 const std::string &frag =
158 "precision highp float;\n"
159 "void main()\n"
160 "{\n"
161 " gl_FragColor = vec4(1.0);\n"
162 "}\n";
163
164 ANGLE_GL_PROGRAM(program, vert, frag);
165
166 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
167 ASSERT_NE(-1, posLocation);
168 glUseProgram(program.get());
169
170 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500171 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500172 glEnableVertexAttribArray(posLocation);
173
174 ASSERT_GL_NO_ERROR();
175 glDrawArrays(GL_TRIANGLES, 0, 6);
176 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
177}
178
179// Test that client-side element array buffers are forbidden in WebGL mode
180TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
181{
182 const std::string &vert =
183 "attribute vec3 a_pos;\n"
184 "void main()\n"
185 "{\n"
186 " gl_Position = vec4(a_pos, 1.0);\n"
187 "}\n";
188
189 const std::string &frag =
190 "precision highp float;\n"
191 "void main()\n"
192 "{\n"
193 " gl_FragColor = vec4(1.0);\n"
194 "}\n";
195
196 ANGLE_GL_PROGRAM(program, vert, frag);
197
198 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
199 ASSERT_NE(-1, posLocation);
200 glUseProgram(program.get());
201
202 const auto &vertices = GetQuadVertices();
203
204 GLBuffer vertexBuffer;
205 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
206 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
207 GL_STATIC_DRAW);
208
209 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
210 glEnableVertexAttribArray(posLocation);
211
212 const GLubyte indices[] = {0, 1, 2, 3, 4, 5};
213
214 ASSERT_GL_NO_ERROR();
215 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
216 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
217}
218
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500219// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
220TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
221{
222 // Run the test in an FBO to make sure we have some stencil bits.
223 GLRenderbuffer renderbuffer;
224 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
225 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
226
227 GLFramebuffer framebuffer;
228 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
229 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
230 renderbuffer.get());
231
232 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
233 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
234 glUseProgram(program.get());
235 ASSERT_GL_NO_ERROR();
236
237 // Having ref and mask the same for front and back is valid.
238 glStencilMask(255);
239 glStencilFunc(GL_ALWAYS, 0, 255);
240 glDrawArrays(GL_TRIANGLES, 0, 6);
241 ASSERT_GL_NO_ERROR();
242
243 // Having a different front - back write mask generates an error.
244 glStencilMaskSeparate(GL_FRONT, 1);
245 glDrawArrays(GL_TRIANGLES, 0, 6);
246 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
247
248 // Setting both write masks separately to the same value is valid.
249 glStencilMaskSeparate(GL_BACK, 1);
250 glDrawArrays(GL_TRIANGLES, 0, 6);
251 ASSERT_GL_NO_ERROR();
252
253 // Having a different stencil front - back mask generates an error
254 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
255 glDrawArrays(GL_TRIANGLES, 0, 6);
256 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
257
258 // Setting both masks separately to the same value is valid.
259 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
260 glDrawArrays(GL_TRIANGLES, 0, 6);
261 ASSERT_GL_NO_ERROR();
262
263 // Having a different stencil front - back reference generates an error
264 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
265 glDrawArrays(GL_TRIANGLES, 0, 6);
266 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
267
268 // Setting both references separately to the same value is valid.
269 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
270 glDrawArrays(GL_TRIANGLES, 0, 6);
271 ASSERT_GL_NO_ERROR();
272
273 // Using different stencil funcs, everything being equal is valid.
274 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
275 glDrawArrays(GL_TRIANGLES, 0, 6);
276 ASSERT_GL_NO_ERROR();
277}
278
Corentin Wallez506fc9c2016-12-21 16:53:33 -0500279// Test that GL_FIXED is forbidden
280TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
281{
282 GLBuffer buffer;
283 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
284 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
285
286 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
287 ASSERT_GL_NO_ERROR();
288
289 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
290 EXPECT_GL_ERROR(GL_INVALID_ENUM);
291}
292
293// Test the WebGL limit of 255 for the attribute stride
294TEST_P(WebGLCompatibilityTest, MaxStride)
295{
296 GLBuffer buffer;
297 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
298 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
299
300 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
301 ASSERT_GL_NO_ERROR();
302
303 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
304 EXPECT_GL_ERROR(GL_INVALID_VALUE);
305}
306
Corentin Wallezfd456442016-12-21 17:57:00 -0500307// Test the checks for OOB reads in the vertex buffers, non-instanced version
308TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
309{
310 const std::string &vert =
311 "attribute float a_pos;\n"
312 "void main()\n"
313 "{\n"
314 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
315 "}\n";
316
317 const std::string &frag =
318 "precision highp float;\n"
319 "void main()\n"
320 "{\n"
321 " gl_FragColor = vec4(1.0);\n"
322 "}\n";
323
324 ANGLE_GL_PROGRAM(program, vert, frag);
325
326 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
327 ASSERT_NE(-1, posLocation);
328 glUseProgram(program.get());
329
330 GLBuffer buffer;
331 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
332 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
333
334 glEnableVertexAttribArray(posLocation);
335
336 const uint8_t* zeroOffset = nullptr;
337
338 // Test touching the last element is valid.
339 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
340 glDrawArrays(GL_POINTS, 0, 4);
341 ASSERT_GL_NO_ERROR();
342
343 // Test touching the last element + 1 is invalid.
344 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
345 glDrawArrays(GL_POINTS, 0, 4);
346 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
347
348 // Test touching the last element is valid, using a stride.
349 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
350 glDrawArrays(GL_POINTS, 0, 4);
351 ASSERT_GL_NO_ERROR();
352
353 // Test touching the last element + 1 is invalid, using a stride.
354 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
355 glDrawArrays(GL_POINTS, 0, 4);
356 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
357
358 // Test any offset is valid if no vertices are drawn.
359 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
360 glDrawArrays(GL_POINTS, 0, 0);
361 ASSERT_GL_NO_ERROR();
362}
363
Geoff Lang5f319a42017-01-09 16:49:19 -0500364// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
365TEST_P(WebGLCompatibilityTest, NPOT)
366{
367 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
368
369 // Create a texture and set an NPOT mip 0, should always be acceptable.
370 GLTexture texture;
371 glBindTexture(GL_TEXTURE_2D, texture.get());
372 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
373 ASSERT_GL_NO_ERROR();
374
375 // Try setting an NPOT mip 1 and verify the error if WebGL 1
376 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
377 if (getClientMajorVersion() < 3)
378 {
379 ASSERT_GL_ERROR(GL_INVALID_VALUE);
380 }
381 else
382 {
383 ASSERT_GL_NO_ERROR();
384 }
385
386 if (extensionRequestable("GL_OES_texture_npot"))
387 {
388 glRequestExtensionANGLE("GL_OES_texture_npot");
389 ASSERT_GL_NO_ERROR();
390
391 // Try again to set NPOT mip 1
392 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
393 ASSERT_GL_NO_ERROR();
394 }
395}
396
Corentin Wallezfd456442016-12-21 17:57:00 -0500397// Test the checks for OOB reads in the vertex buffers, instanced version
398TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
399{
400 const std::string &vert =
401 "attribute float a_pos;\n"
402 "void main()\n"
403 "{\n"
404 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
405 "}\n";
406
407 const std::string &frag =
408 "precision highp float;\n"
409 "void main()\n"
410 "{\n"
411 " gl_FragColor = vec4(1.0);\n"
412 "}\n";
413
414 ANGLE_GL_PROGRAM(program, vert, frag);
415
416 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
417 ASSERT_NE(-1, posLocation);
418 glUseProgram(program.get());
419
420 GLBuffer buffer;
421 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
422 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
423
424 glEnableVertexAttribArray(posLocation);
425 glVertexAttribDivisor(posLocation, 1);
426
427 const uint8_t* zeroOffset = nullptr;
428
429 // Test touching the last element is valid.
430 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
431 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
432 ASSERT_GL_NO_ERROR();
433
434 // Test touching the last element + 1 is invalid.
435 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
436 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
437 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
438
439 // Test touching the last element is valid, using a stride.
440 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
441 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
442 ASSERT_GL_NO_ERROR();
443
444 // Test touching the last element + 1 is invalid, using a stride.
445 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
446 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
447 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
448
449 // Test any offset is valid if no vertices are drawn.
450 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
451 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
452 ASSERT_GL_NO_ERROR();
453}
454
Jamie Madilla4595b82017-01-11 17:36:34 -0500455// Tests that a rendering feedback loop triggers a GL error under WebGL.
456// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
457TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
458{
459 const std::string vertexShader =
460 "attribute vec4 a_position;\n"
461 "varying vec2 v_texCoord;\n"
462 "void main() {\n"
463 " gl_Position = a_position;\n"
464 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
465 "}\n";
466
467 const std::string fragmentShader =
468 "precision mediump float;\n"
469 "varying vec2 v_texCoord;\n"
470 "uniform sampler2D u_texture;\n"
471 "void main() {\n"
472 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
473 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
474 "}\n";
475
476 GLTexture texture;
477 glBindTexture(GL_TEXTURE_2D, texture.get());
478 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::red);
479 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
483
484 ASSERT_GL_NO_ERROR();
485
486 GLFramebuffer framebuffer;
487 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
488 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
489
490 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
491
492 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
493
494 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
495 ASSERT_NE(-1, uniformLoc);
496
497 glUseProgram(program.get());
498 glUniform1i(uniformLoc, 0);
499 glDisable(GL_BLEND);
500 glDisable(GL_DEPTH_TEST);
501 ASSERT_GL_NO_ERROR();
502
503 // Drawing with a texture that is also bound to the current framebuffer should fail
504 glBindTexture(GL_TEXTURE_2D, texture.get());
505 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
506 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
507
508 // Ensure that the texture contents did not change after the previous render
509 glBindFramebuffer(GL_FRAMEBUFFER, 0);
510 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
511 ASSERT_GL_NO_ERROR();
512 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
513
514 // Drawing when texture is bound to an inactive uniform should succeed
515 GLTexture texture2;
516 glBindTexture(GL_TEXTURE_2D, texture2.get());
517 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
522
523 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
524 glActiveTexture(GL_TEXTURE1);
525 glBindTexture(GL_TEXTURE_2D, texture.get());
526 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
527 ASSERT_GL_NO_ERROR();
528 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
529}
530
Jamie Madillf695a3a2017-01-11 17:36:35 -0500531// Test tests that texture copying feedback loops are properly rejected in WebGL.
532// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
533TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
534{
535 GLTexture texture;
536 glBindTexture(GL_TEXTURE_2D, texture.get());
537 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
540 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
542
543 GLTexture texture2;
544 glBindTexture(GL_TEXTURE_2D, texture2.get());
545 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
546 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
548 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
549 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
550
551 GLFramebuffer framebuffer;
552 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
553 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
554
555 // framebuffer should be FRAMEBUFFER_COMPLETE.
556 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
557 ASSERT_GL_NO_ERROR();
558
559 // testing copyTexImage2D
560
561 // copyTexImage2D to same texture but different level
562 glBindTexture(GL_TEXTURE_2D, texture.get());
563 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
564 EXPECT_GL_NO_ERROR();
565
566 // copyTexImage2D to same texture same level, invalid feedback loop
567 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
568 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
569
570 // copyTexImage2D to different texture
571 glBindTexture(GL_TEXTURE_2D, texture2.get());
572 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
573 EXPECT_GL_NO_ERROR();
574
575 // testing copyTexSubImage2D
576
577 // copyTexSubImage2D to same texture but different level
578 glBindTexture(GL_TEXTURE_2D, texture.get());
579 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
580 EXPECT_GL_NO_ERROR();
581
582 // copyTexSubImage2D to same texture same level, invalid feedback loop
583 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
584 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
585
586 // copyTexSubImage2D to different texture
587 glBindTexture(GL_TEXTURE_2D, texture2.get());
588 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
589 EXPECT_GL_NO_ERROR();
590}
591
Bryan Bernhart58806562017-01-05 13:09:31 -0800592// Test for the max draw buffers and color attachments.
593TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
594{
595 // This test only applies to ES2.
596 if (getClientMajorVersion() != 2)
597 {
598 return;
599 }
600
601 GLFramebuffer fbo[2];
602 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
603
604 // Test that is valid when we bind with a single attachment point.
605 GLTexture texture;
606 glBindTexture(GL_TEXTURE_2D, texture.get());
607 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
608 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
609 ASSERT_GL_NO_ERROR();
610
611 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
612 // attachment point.
613 if (extensionRequestable("GL_EXT_draw_buffers"))
614 {
615 glRequestExtensionANGLE("GL_EXT_draw_buffers");
616 EXPECT_GL_NO_ERROR();
617 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
618
619 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
620
621 GLTexture texture2;
622 glBindTexture(GL_TEXTURE_2D, texture2.get());
623 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
624 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
625 0);
626 ASSERT_GL_NO_ERROR();
627 }
628}
629
Corentin Wallez3f6d4df2017-01-30 18:04:36 -0500630// Test that the offset in the index buffer is forced to be a multiple of the element size
631TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
632{
633 const std::string &vert =
634 "attribute vec3 a_pos;\n"
635 "void main()\n"
636 "{\n"
637 " gl_Position = vec4(a_pos, 1.0);\n"
638 "}\n";
639
640 const std::string &frag =
641 "precision highp float;\n"
642 "void main()\n"
643 "{\n"
644 " gl_FragColor = vec4(1.0);\n"
645 "}\n";
646
647 ANGLE_GL_PROGRAM(program, vert, frag);
648
649 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
650 ASSERT_NE(-1, posLocation);
651 glUseProgram(program.get());
652
653 const auto &vertices = GetQuadVertices();
654
655 GLBuffer vertexBuffer;
656 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
657 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
658 GL_STATIC_DRAW);
659
660 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
661 glEnableVertexAttribArray(posLocation);
662
663 GLBuffer indexBuffer;
664 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
665 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
666 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
667
668 ASSERT_GL_NO_ERROR();
669
670 const char *zeroIndices = nullptr;
671
672 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
673 ASSERT_GL_NO_ERROR();
674
675 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
676 ASSERT_GL_NO_ERROR();
677
678 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
679 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
680}
681
682// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
683// size
684TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
685{
686 const char *zeroOffset = nullptr;
687
688 // Base case, vector of two floats
689 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
690 ASSERT_GL_NO_ERROR();
691
692 // Test setting a non-multiple offset
693 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
694 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
695 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
696 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
697 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
698 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
699
700 // Test setting a non-multiple stride
701 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
702 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
703 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
704 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
705 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
706 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
707}
708
Geoff Langc287ea62016-09-16 14:46:51 -0400709// Use this to select which configurations (e.g. which renderer, which GLES major version) these
710// tests should be run against.
711ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
712 ES2_D3D9(),
713 ES2_D3D11(),
714 ES3_D3D11(),
715 ES2_D3D11_FL9_3(),
716 ES2_OPENGL(),
717 ES3_OPENGL(),
718 ES2_OPENGLES(),
719 ES3_OPENGLES());
720
Corentin Wallezfd456442016-12-21 17:57:00 -0500721ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest,
722 ES3_D3D11(),
723 ES3_OPENGL(),
724 ES3_OPENGLES());
725
Geoff Langc287ea62016-09-16 14:46:51 -0400726} // namespace