4 ** Copyright (c) 2014 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>Float32Array garbage collection test</title>
33 <link rel="stylesheet" href="../resources/js-test-style.css"/>
34 <script src="../resources/js-test-pre.js"></script>
35 <script src="../conformance/resources/webgl-test-utils.js"> </script>
38 <canvas id="canvas" width="40" height="40"></canvas>
39 <div id="description"></div>
40 <div id="console"></div>
41 <script id="vshader" type="x-shader/x-vertex">
42 attribute vec2 inPosition;
43 attribute vec4 inColor;
51 gl_Position = vec4(inPosition, 0.0, 1.0);
54 <script id="fshader" type="x-shader/x-fragment">
55 precision mediump float;
61 if (color == vec4(0.0))
71 description("Allocates a buffer object and then updates it repeatedly using throw-away Float32Array objects. " +
72 "Ideally, this should not result in a browser crash or instability, since GC should be able to collect all Float32Arrays.");
73 var wtu = WebGLTestUtils;
77 for (var x = -1; x < 1; x += w) {
78 for (var y = -1; y < 1; y += w) {
79 vertices.push(x + w, y + w);
80 vertices.push(x, y + w);
83 vertices.push(x + w, y + w);
85 vertices.push(x + w, y );
88 var numVertices = (vertices.length / 2);
94 var drawIterationsPerTest = 100;
97 gl = wtu.create3DContext("canvas");
98 var attribs = ["inPosition", "inColor"];
99 wtu.setupProgram(gl, ["vshader", "fshader"], attribs);
100 gl.disable(gl.DEPTH_TEST);
101 gl.disable(gl.BLEND);
103 squareBuffer = gl.createBuffer();
104 gl.enableVertexAttribArray(0);
105 gl.bindBuffer(gl.ARRAY_BUFFER, squareBuffer);
106 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
107 gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
109 buffer = gl.createBuffer();
110 gl.enableVertexAttribArray(1);
111 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
112 gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0);
116 var drawIterations = 0;
118 function runNextTest() {
121 size = Math.pow(2, testIndex) * numVertices * 16;
123 if (size > 2 * 1024 * 1024 && prevSize <= 2 * 1024 * 1024) {
124 if (!confirm("The following tests can cause unresponsiveness or instability. Press OK to continue.")) {
125 testFailed("Tests aborted");
130 if (size > 64 * 1024 * 1024) {
131 gl.deleteBuffer(buffer);
132 testPassed("Tests finished");
136 debug('Initializing buffer with size: ' + size);
137 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
138 gl.bufferData(gl.ARRAY_BUFFER, size, gl.DYNAMIC_DRAW);
139 updateBufferData = new Float32Array(size / 4);
141 debug("Drawing " + drawIterationsPerTest + " times, each time creating a new throw-away Float32Array of size " + size + " and using it to update the buffer");
146 var doDraw = function() {
147 gl.clearColor(0, 255, 0, 255);
148 gl.clear(gl.COLOR_BUFFER_BIT);
150 // Update the array buffer with a throw-away Float32Array
151 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
152 gl.bufferSubData(gl.ARRAY_BUFFER, 0, new Float32Array(updateBufferData));
154 gl.drawArrays(gl.TRIANGLES, 0, numVertices);
155 var error = gl.getError();
156 if (error !== gl.NO_ERROR) {
157 testFailed("drawArrays failed with error " + wtu.glEnumToString(gl, error));
160 if (drawIterations < drawIterationsPerTest) {
162 requestAnimationFrame(doDraw);
171 var successfullyParsed = true;