3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
7 <canvas id=
"example" width=
"1px" height=
"1px"></canvas>
8 <div id=
"description"></div>
9 <div id=
"console"></div>
11 <script id=
"vs" type=
"x-shader/x-vertex">
12 attribute vec4 vPosition;
13 attribute vec4 vColor;
16 gl_Position = vPosition;
20 <script id=
"fs" type=
"x-shader/x-fragment">
22 precision mediump float;
30 description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
32 var gl
= initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1], 1);
33 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after initialization");
35 gl
.useProgram(gl
.program
);
36 var vertexObject
= gl
.createBuffer();
37 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
38 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(
39 [-1,1,0, 1,1,0, -1,-1,0,
40 -1,-1,0, 1,1,0, 1,-1,0]), gl
.STATIC_DRAW
);
41 gl
.enableVertexAttribArray(0);
42 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
43 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after vertex setup");
45 var texCoordObject
= gl
.createBuffer();
46 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
47 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(
49 0,1, 1,0, 1,1]), gl
.STATIC_DRAW
);
50 gl
.enableVertexAttribArray(1);
51 gl
.vertexAttribPointer(1, 2, gl
.FLOAT
, false, 0, 0);
52 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after texture coord setup");
54 // Now resize these buffers because we want to change what we're drawing.
55 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
56 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
57 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0,
58 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl
.STATIC_DRAW
);
59 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after vertex redefinition");
60 gl
.bindBuffer(gl
.ARRAY_BUFFER
, texCoordObject
);
61 gl
.bufferData(gl
.ARRAY_BUFFER
, new Uint8Array([
69 0, 255, 0, 255]), gl
.STATIC_DRAW
);
70 gl
.vertexAttribPointer(1, 4, gl
.UNSIGNED_BYTE
, false, 0, 0);
71 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after texture coordinate / color redefinition");
74 var indices
= new Uint8Array(numQuads
* 6);
75 for (var ii
= 0; ii
< numQuads
; ++ii
) {
77 var quad
= (ii
== (numQuads
- 1)) ? 4 : 0;
78 indices
[offset
+ 0] = quad
+ 0;
79 indices
[offset
+ 1] = quad
+ 1;
80 indices
[offset
+ 2] = quad
+ 2;
81 indices
[offset
+ 3] = quad
+ 2;
82 indices
[offset
+ 4] = quad
+ 1;
83 indices
[offset
+ 5] = quad
+ 3;
85 var indexObject
= gl
.createBuffer();
86 gl
.bindBuffer(gl
.ELEMENT_ARRAY_BUFFER
, indexObject
);
87 gl
.bufferData(gl
.ELEMENT_ARRAY_BUFFER
, indices
, gl
.STATIC_DRAW
);
88 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after setting up indices");
89 gl
.drawElements(gl
.TRIANGLES
, numQuads
* 6, gl
.UNSIGNED_BYTE
, 0);
90 glErrorShouldBe(gl
, gl
.NO_ERROR
, "after drawing");