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 <meta charset=
"utf-8">
11 <title>bufferData with DYNAMIC_DRAW and delay between updating data
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"> </script>
17 <canvas id=
"canvas" width=
"50" height=
"50"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
21 <script id=
"vshader" type=
"x-shader/x-vertex">
22 attribute vec2 a_position;
23 attribute vec2 a_color;
27 gl_Position = vec4(a_position,
0.0,
1.0);
31 <script id=
"fshader" type=
"x-shader/x-fragment">
32 precision mediump float;
36 gl_FragColor = vec4(v_color,
0.0,
1.0);
42 description("Verifies that bufferData with DYNAMIC_DRAW updates the vertex attribute when there is a significant delay between updating the buffer.");
43 var wtu
= WebGLTestUtils
;
44 var gl
= wtu
.create3DContext("canvas");
45 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ["a_position", "a_color"]);
47 // Initialize position vertex attribute to draw a square covering the entire canvas.
48 var positionBuffer
= gl
.createBuffer();
49 gl
.bindBuffer(gl
.ARRAY_BUFFER
, positionBuffer
);
50 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
56 gl
.enableVertexAttribArray(0);
57 gl
.vertexAttribPointer(0, 2, gl
.FLOAT
, false, 0, 0);
59 // Initialize color vertex attribute to red.
60 var colorBuffer
= gl
.createBuffer();
61 gl
.bindBuffer(gl
.ARRAY_BUFFER
, colorBuffer
);
62 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
68 gl
.enableVertexAttribArray(1);
69 gl
.vertexAttribPointer(1, 2, gl
.FLOAT
, false, 0, 0);
71 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No error after setup");
73 // Fill the canvas with red
74 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 4);
75 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No error after first drawArrays");
77 wtu
.checkCanvasRect(gl
, 0, 0, 50, 50, [255, 0, 0, 255], "Canvas should be red after the first drawArrays");
79 // With the buffer set to DYNAMIC_DRAW, Angle internally changes the storage type of the vertex attribute from DYNAMIC to DIRECT
80 // if the buffer has not been updated after ~4-5 draw calls. When the buffer is eventually updated, the vertex attribute
81 // is updated back to DYNAMIC, but there was a bug in Angle where the data is not marked as dirty. The result is that the
82 // vertex data is not updated with the new buffer data. This test verifies that the vertex data is updated.
85 // Draw 10 times to ensure that the vertex attribute storage type is changed.
87 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 2);
88 requestAnimationFrame(draw
);
91 // Update the buffer bound to the color vertex attribute to green and draw.
92 gl
.bindBuffer(gl
.ARRAY_BUFFER
, colorBuffer
);
93 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
99 gl
.drawArrays(gl
.TRIANGLE_STRIP
, 0, 4);
100 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No error after last drawArrays");
102 wtu
.checkCanvasRect(gl
, 0, 0, 50, 50, [0, 255, 0, 255], "Canvas should be green after 10 frames");
110 requestAnimationFrame(draw
);