Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / buffers / buffer-data-and-buffer-sub-data-sub-source.html
blobed9a131f777f737e11ebf15b3d97721f103bf112
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 ArrayBufferView sub source input");
23 var wtu = WebGLTestUtils;
24 var gl = wtu.create3DContext(undefined, undefined, 2);
26 function verifyBufferData(testCase, sourceByteOffset, size, data) {
27 var readbackBuffer = new ArrayBuffer(testCase.size * size);
28 var readbackView = new window[testCase.type](readbackBuffer);
29 gl.getBufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, readbackView);
30 var pass = true;
31 var offset = sourceByteOffset / testCase.size;
32 for (var ii = 0; ii < size; ++ii) {
33 if (readbackView[ii] != data[ii]) {
34 testFailed("expected data at " + ii + ": " + data[ii] + ", got " + readbackView[ii]);
35 pass = false;
38 if (pass) {
39 testPassed("buffer data uploaded correctly");
43 function bufferDataTest(testCases) {
44 for (var idx = 0; idx < testCases.length; ++idx) {
45 var test = testCases[idx];
46 debug("");
47 debug("Test bufferData with " + test.type);
49 var buf = gl.createBuffer();
50 shouldBeNonNull(buf);
52 gl.bindBuffer(gl.ARRAY_BUFFER, buf);
53 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
55 var count = 4;
56 var arrayBuffer = new ArrayBuffer(test.size * count);
57 var view = new window[test.type](arrayBuffer);
58 for (var ii = 0; ii < count; ++ii) {
59 view[ii] = ii;
62 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, 0, count + 1);
63 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
64 "calling bufferData when srcOffset + length is larger than source size");
66 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, count + 1);
67 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
68 "calling bufferData when srcOffset + length is larger than source size");
70 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, count - 1, 2);
71 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
72 "calling bufferData when srcOffset + length is larger than source size");
74 var offset = 2;
75 var size = count - offset;
76 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset);
77 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
78 "calling bufferData with valid sub source should succeed");
79 verifyBufferData(test, 0, size, view.slice(offset, offset + size));
81 offset = 1;
82 size = 1;
83 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, offset, size);
84 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
85 "calling bufferData with valid sub source should succeed");
86 verifyBufferData(test, 0, size, view.slice(offset, offset + size));
88 gl.bufferData(gl.ARRAY_BUFFER, view, gl.STATIC_DRAW, count);
89 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
90 "calling bufferData with valid sub source of size 0 should succeed");
92 gl.deleteBuffer(buf);
93 gl.bindBuffer(gl.ARRAY_BUFFER, null);
95 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no GL error");
99 function bufferSubDataTest(testCases) {
100 for (var idx = 0; idx < testCases.length; ++idx) {
101 var test = testCases[idx];
102 debug("");
103 debug("Test bufferSubData with " + test.type);
105 var count = 4;
106 var totalBufferBytes = test.size * count * 2;
107 var buf = gl.createBuffer();
108 shouldBeNonNull(buf);
109 gl.bindBuffer(gl.ARRAY_BUFFER, buf);
110 gl.bufferData(gl.ARRAY_BUFFER, totalBufferBytes, gl.STATIC_DRAW);
111 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
113 var arrayBuffer = new ArrayBuffer(test.size * count);
114 var view = new window[test.type](arrayBuffer);
115 for (var ii = 0; ii < count; ++ii) {
116 view[ii] = ii;
119 var sourceByteOffset = test.size * 2;
121 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, 0, count + 1);
122 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
123 "calling bufferSubData when srcOffset + length is larger than source size");
125 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, count + 1);
126 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
127 "calling bufferSubData when srcOffset + length is larger than source size");
129 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, count - 1, 2);
130 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
131 "calling bufferSubData when srcOffset + length is larger than source size");
133 var offset = 2;
134 var size = count - offset;
135 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, offset);
136 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
137 "calling bufferSubData with valid sub source should succeed");
138 verifyBufferData(test, sourceByteOffset, size, view.slice(offset, offset + size));
140 offset = 1;
141 size = 1;
142 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, offset, size);
143 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
144 "calling bufferSubData with valid sub source should succeed");
145 verifyBufferData(test, sourceByteOffset, size, view.slice(offset, offset + size));
147 gl.bufferSubData(gl.ARRAY_BUFFER, sourceByteOffset, view, count);
148 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
149 "calling bufferSubData with valid sub source of size 0 should succeed");
151 gl.deleteBuffer(buf);
152 gl.bindBuffer(gl.ARRAY_BUFFER, null);
154 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no GL error");
158 if (!gl) {
159 testFailed("WebGL context does not exist");
160 } else {
161 testPassed("WebGL context exists");
163 var testCases = [
164 {type: "Uint8Array", size: 1},
165 {type: "Int8Array", size: 1},
166 {type: "Int16Array", size: 2},
167 {type: "Uint16Array", size: 2},
168 {type: "Uint32Array", size: 4},
169 {type: "Int32Array", size: 4},
170 {type: "Float32Array", size: 4},
171 {type: "Float64Array", size: 8}
174 bufferDataTest(testCases);
175 bufferSubDataTest(testCases);
178 var successfullyParsed = true;
179 </script>
181 <script src="../../js/js-test-post.js"></script>
182 </body>
183 </html>