Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / buffers / buffer-data-and-buffer-sub-data.html
blobf3c2658a22b9ccd0553bc8e034c2b42f5fb69b96
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"></script>
14 </head>
15 <body>
16 <div id="description"></div>
17 <div id="console"></div>
19 <script>
20 "use strict";
21 description("Test bufferData/bufferSubData with or without ArrayBuffer input");
23 debug('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=41884">https://bugs.webkit.org/show_bug.cgi?id=41884</a> : <code>Implement bufferData and bufferSubData with ArrayBuffer as input</code>');
25 var wtu = WebGLTestUtils;
26 var gl = wtu.create3DContext();
27 if (!gl) {
28 testFailed("WebGL context does not exist");
29 } else {
30 testPassed("WebGL context exists");
32 bufferDataTest();
33 bufferDataSizesTest();
35 bufferSubDataTest();
38 function bufferDataTest() {
39 debug("");
40 debug("Test bufferData without ArrayBuffer input");
42 var buf = gl.createBuffer();
43 shouldBeNonNull(buf);
45 gl.bufferData(gl.ARRAY_BUFFER, 4, gl.STATIC_DRAW);
46 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "no buffer bound");
48 gl.bindBuffer(gl.ARRAY_BUFFER, buf);
49 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
51 gl.bufferData(gl.ARRAY_BUFFER, -4, gl.STATIC_DRAW);
52 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
53 "calling bufferData when buffer size is negative should generate INVALID_VALUE");
55 gl.bufferData(gl.ARRAY_BUFFER, null, gl.STATIC_DRAW);
56 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
57 "calling bufferData when BufferDataSource is null should generate INVALID_VALUE");
59 gl.bufferData(gl.ARRAY_BUFFER, undefined, gl.STATIC_DRAW);
60 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
61 "calling bufferData when BufferDataSource is undefined should generate INVALID_VALUE");
63 gl.bindBuffer(gl.ARRAY_BUFFER, null);
66 function bufferDataSizesTest() {
67 debug("");
68 debug("Test bufferData overloads");
70 // bufferData has an integer overload and an ArrayBuffer overload.
71 // Per the WebIDL spec, the overload resolution algorithm should resolve types as follows:
72 // - If the argument is null or undefined, pick the nullable type, which is ArrayBuffer.
73 // Per the WebGL spec, null should flag INVALID_VALUE.
74 // - If the argument is an ArrayBuffer, then pick the ArrayBuffer overload
75 // - Everything else should pick the numeric overload. This means things like objects, strings,
76 // floating point numbers, arrays of numbers and strings, etc should convert themselves to a number.
77 var bufferDataParams = [
78 { parameter: 0, expectedBufferSize: 0 },
79 { parameter: 4, expectedBufferSize: 4 },
80 { parameter: 5.1, expectedBufferSize: 5 },
81 { parameter: 5.8, expectedBufferSize: 5 },
82 { parameter: 5.5, expectedBufferSize: 5 },
84 { parameter: "4", expectedBufferSize: 4 },
85 { parameter: "5.1", expectedBufferSize: 5 },
86 { parameter: "5.8", expectedBufferSize: 5 },
87 { parameter: "5.5", expectedBufferSize: 5 },
88 { parameter: "0", expectedBufferSize: 0 },
90 { parameter: [42, 64], expectedBufferSize: 0 },
91 { parameter: [42], expectedBufferSize: 42 },
92 { parameter: ["42"], expectedBufferSize: 42 },
93 { parameter: ["42", "64"], expectedBufferSize: 0 },
95 { parameter: new ArrayBuffer(0), expectedBufferSize: 0 },
96 { parameter: new ArrayBuffer(4), expectedBufferSize: 4 },
97 { parameter: new Uint8Array(new ArrayBuffer(5)), expectedBufferSize: 5 },
98 { parameter: new DataView(new ArrayBuffer(7)), expectedBufferSize: 7 },
100 { parameter: "WebGL Rocks!", expectedBufferSize: 0 },
101 { parameter: { mystring: "WebGL Rocks!" }, expectedBufferSize: 0 },
104 if (window.SharedArrayBuffer) {
105 bufferDataParams.push(
106 { parameter: new SharedArrayBuffer(3), expectedBufferSize: 3 },
107 { parameter: new Uint8Array(new SharedArrayBuffer(6)), expectedBufferSize: 6 },
108 { parameter: new DataView(new SharedArrayBuffer(8)), expectedBufferSize: 8 }
112 bufferDataParams.forEach(function (bufferDataParam) {
113 var buffer = gl.createBuffer();
114 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
115 gl.bufferData(gl.ARRAY_BUFFER, bufferDataParam.parameter, gl.STATIC_DRAW);
116 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Passing " + bufferDataParam.parameter + " to bufferData");
118 shouldEvaluateTo("gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)", bufferDataParam.expectedBufferSize);
121 gl.bindBuffer(gl.ARRAY_BUFFER, null);
124 function bufferSubDataTest() {
125 debug("");
126 debug("Test bufferSubData");
128 var buf = gl.createBuffer();
129 gl.bindBuffer(gl.ARRAY_BUFFER, buf);
131 gl.bufferSubData(gl.ARRAY_BUFFER, 0, new ArrayBuffer(1));
132 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Calling bufferSubData before bufferData should fail");
134 gl.bufferData(gl.ARRAY_BUFFER, 128, gl.STATIC_DRAW);
135 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
137 var array = new ArrayBuffer(64);
139 gl.bufferSubData(gl.ARRAY_BUFFER, -10, array);
140 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
141 "calling bufferSubData with ArrayBuffer when offset is negative should INVALID_VALUE");
143 gl.bufferSubData(gl.ARRAY_BUFFER, 65, array);
144 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "buffer overflow");
146 gl.bufferSubData(gl.ARRAY_BUFFER, -10, new Float32Array(8));
147 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
148 "calling bufferSubData with ArrayBufferView when offset is negative should generate INVALID_VALUE");
150 gl.bufferSubData(gl.ARRAY_BUFFER, 10, array);
151 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
152 "calling bufferSubData with ArrayBuffer should succeed");
154 gl.bufferSubData(gl.ARRAY_BUFFER, 10, new Float32Array(0));
155 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
156 "calling bufferSubData with zero-sized ArrayBufferView should succeed");
158 // Arguments that are not ArrayBuffers, null or undefined should throw a TypeError exception
159 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 42);");
160 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, 5.5);");
161 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, \"5.5\");");
162 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, [4]);");
163 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, { mynumber: 42});");
164 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, null)");
165 shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, undefined)");
167 if (window.SharedArrayBuffer) {
168 const validDatas = [
169 'new SharedArrayBuffer(3)',
170 'new Uint8Array(new SharedArrayBuffer(3))',
171 'new DataView(new SharedArrayBuffer(3))',
173 for (const x of validDatas) {
174 shouldNotThrow(`gl.bufferSubData(gl.ARRAY_BUFFER, 0, ${x})`);
178 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should generate no GL error");
180 // -
181 // Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1611837
183 gl.bindBuffer(gl.ARRAY_BUFFER, null);
184 gl.bufferSubData(gl.ARRAY_BUFFER, 0, new ArrayBuffer(0));
185 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
186 "Calling bufferSubData with empty ArrayBuffer and null WebGLBuffer should fail");
188 gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
189 gl.bufferSubData(gl.ARRAY_BUFFER, 0, new ArrayBuffer(0));
190 wtu.glErrorShouldBe(gl, 0,
191 "Calling bufferSubData with empty ArrayBuffer and non-null WebGLBuffer should succeed");
193 // -
195 gl.bindBuffer(gl.ARRAY_BUFFER, null);
198 var successfullyParsed = true;
199 </script>
201 <script src="../../js/js-test-post.js"></script>
202 </body>
203 </html>