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 <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>
16 <canvas id=
"example" width=
"1" height=
"1"></canvas>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
20 <script id=
"vs" type=
"x-shader/x-vertex">
21 attribute vec4 vPosition;
22 attribute vec4 vColor;
25 gl_Position = vPosition;
29 <script id=
"fs" type=
"x-shader/x-fragment">
30 precision mediump float;
38 description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
40 var wtu
= WebGLTestUtils
;
41 var gl
= wtu
.create3DContext("example");
42 var program
= wtu
.setupProgram(gl
, ["vs", "fs"], ["vPosition", "vColor"]);
43 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after initialization");
45 var vertexObject
= gl
.createBuffer();
46 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
47 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(
48 [-1,1,0, 1,1,0, -1,-1,0,
49 -1,-1,0, 1,1,0, 1,-1,0]), gl
.STATIC_DRAW
);
50 gl
.enableVertexAttribArray(0);
51 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
52 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after vertex setup");
54 var texCoordObject
= gl
.createBuffer();
55 gl
.bindBuffer(gl
.ARRAY_BUFFER
, texCoordObject
);
56 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(
58 0,1, 1,0, 1,1]), gl
.STATIC_DRAW
);
59 gl
.enableVertexAttribArray(1);
60 gl
.vertexAttribPointer(1, 2, gl
.FLOAT
, false, 0, 0);
61 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after texture coord setup");
63 // Now resize these buffers because we want to change what we're drawing.
64 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
65 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
66 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0,
67 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl
.STATIC_DRAW
);
68 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after vertex redefinition");
69 gl
.bindBuffer(gl
.ARRAY_BUFFER
, texCoordObject
);
70 gl
.bufferData(gl
.ARRAY_BUFFER
, new Uint8Array([
78 0, 255, 0, 255]), gl
.STATIC_DRAW
);
79 gl
.vertexAttribPointer(1, 4, gl
.UNSIGNED_BYTE
, false, 0, 0);
80 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after texture coordinate / color redefinition");
83 var indices
= new Uint8Array(numQuads
* 6);
84 for (var ii
= 0; ii
< numQuads
; ++ii
) {
86 var quad
= (ii
== (numQuads
- 1)) ? 4 : 0;
87 indices
[offset
+ 0] = quad
+ 0;
88 indices
[offset
+ 1] = quad
+ 1;
89 indices
[offset
+ 2] = quad
+ 2;
90 indices
[offset
+ 3] = quad
+ 2;
91 indices
[offset
+ 4] = quad
+ 1;
92 indices
[offset
+ 5] = quad
+ 3;
94 var indexObject
= gl
.createBuffer();
95 gl
.bindBuffer(gl
.ELEMENT_ARRAY_BUFFER
, indexObject
);
96 gl
.bufferData(gl
.ELEMENT_ARRAY_BUFFER
, indices
, gl
.STATIC_DRAW
);
97 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after setting up indices");
98 gl
.drawElements(gl
.TRIANGLES
, numQuads
* 6, gl
.UNSIGNED_BYTE
, 0);
99 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after drawing");
102 var successfullyParsed
= true;
105 <script src=
"../../js/js-test-post.js"></script>