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.
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>
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;
24 gl_Position = a_vertex ==
0.0 ? vec4(
9,
9,
9,
1) : vec4(
0.5,
0.5,
0.5,
1);
28 <script id=
"fshader" type=
"x-shader/x-fragment">
31 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
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
++) {
53 gl
.clearColor(0, 1, 0, 1);
55 function test(initFunction
) {
56 var uninitializedBuffer
= gl
.createBuffer();
57 gl
.bindBuffer(gl
.ARRAY_BUFFER
, uninitializedBuffer
);
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
);
82 debug("testing bufferData(..., size, ...)");
83 for (j
= 0; j
< REPETITIONS
; j
++) {
85 gl
.bufferData(gl
.ARRAY_BUFFER
, TEST_BUFSIZE
, gl
.STATIC_DRAW
);
90 debug("testing bufferSubData(..., offset, data) of uninitialized buffer");
91 for (j
= 0; j
< REPETITIONS
; j
++) {
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
);
99 var successfullyParsed
= true;
102 <script src=
"../../js/js-test-post.js"></script>