Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / buffers / buffer-uninitialized.html
blob75282f36744386a550e66f42b480568fea767562
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 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
11 <script src="../../js/js-test-pre.js"></script>
12 <script src="../../js/webgl-test-utils.js"></script>
13 </head>
14 <body>
15 <div id="description"></div>
16 <div id="console"></div>
18 <canvas id="canvas" width="1" height="1"></canvas>
20 <script id="vshader" type="x-shader/x-vertex">
21 attribute float a_vertex;
22 void main()
24 gl_Position = a_vertex == 0.0 ? vec4(9, 9, 9, 1) : vec4(0.5, 0.5, 0.5, 1);
26 </script>
28 <script id="fshader" type="x-shader/x-fragment">
29 void main()
31 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
33 </script>
35 <script>
36 "use strict";
37 description("Tests that uninitialized WebGLBuffers are zeroed out");
39 var wtu = WebGLTestUtils;
40 var gl = wtu.create3DContext(document.getElementById("canvas"));
41 var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_vertex"]);
42 shouldBeTrue("program != null");
44 var TEST_LENGTH = 1024;
45 var TEST_BUFSIZE = TEST_LENGTH * 4;
46 var data = new Float32Array(TEST_LENGTH / 4); // this array is zeroed
48 var indices = new Uint16Array(TEST_LENGTH);
49 for (var i = 0; i < TEST_LENGTH; i++) {
50 indices[i] = i;
53 gl.clearColor(0, 1, 0, 1);
55 function test(initFunction) {
56 var uninitializedBuffer = gl.createBuffer();
57 gl.bindBuffer(gl.ARRAY_BUFFER, uninitializedBuffer);
58 initFunction();
60 var elements = gl.createBuffer();
61 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
62 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
64 gl.useProgram(program);
65 var vertexLoc = gl.getAttribLocation(program, "a_vertex");
66 gl.vertexAttribPointer(vertexLoc, 1, gl.FLOAT, gl.FALSE, 0, 0);
67 gl.enableVertexAttribArray(vertexLoc);
69 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no error should result from setup");
71 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
72 gl.drawElements(gl.POINTS, TEST_LENGTH, gl.UNSIGNED_SHORT, 0);
73 wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 255, 0, 255], "buffer should be initialized to zero");
75 gl.deleteBuffer(uninitializedBuffer);
78 var REPETITIONS = 50;
80 var j;
81 debug("");
82 debug("testing bufferData(..., size, ...)");
83 for (j = 0; j < REPETITIONS; j++) {
84 test(function() {
85 gl.bufferData(gl.ARRAY_BUFFER, TEST_BUFSIZE, gl.STATIC_DRAW);
86 });
89 debug("");
90 debug("testing bufferSubData(..., offset, data) of uninitialized buffer");
91 for (j = 0; j < REPETITIONS; j++) {
92 test(function() {
93 gl.bufferData(gl.ARRAY_BUFFER, TEST_BUFSIZE, gl.STATIC_DRAW);
94 // bufferSubData the second quarter of the buffer
95 gl.bufferSubData(gl.ARRAY_BUFFER, TEST_BUFSIZE / 4, data);
96 });
99 var successfullyParsed = true;
100 </script>
102 <script src="../../js/js-test-post.js"></script>
103 </body>
104 </html>