blob: 773350027aea7cd3583dea6f91cd3f89d573f0b4 [file] [log] [blame]
kbr@google.comae73e942010-06-28 17:41:40 +00001<html>
2<head>
ap@apple.comfab549e2014-12-27 23:22:02 +00003<script src="../../../resources/js-test.js"></script>
kbr@google.comae73e942010-06-28 17:41:40 +00004<script src="resources/webgl-test.js"></script>
kbr@google.comae73e942010-06-28 17:41:40 +00005</head>
6<body>
7<canvas id="example" width="1px" height="1px"></canvas>
8<div id="description"></div>
9<div id="console"></div>
10
11<script id="vs" type="x-shader/x-vertex">
12attribute vec4 vPosition;
13attribute vec4 vColor;
14varying vec4 color;
15void main() {
16 gl_Position = vPosition;
17 color = vColor;
18}
19</script>
20<script id="fs" type="x-shader/x-fragment">
21#if defined(GL_ES)
22precision mediump float;
23#endif
24varying vec4 color;
25void main() {
26 gl_FragColor = color;
27}
28</script>
29<script>
30description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
31
kbr@google.comae73e942010-06-28 17:41:40 +000032var gl = initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1], 1);
33glErrorShouldBe(gl, gl.NO_ERROR, "after initialization");
34
35gl.useProgram(gl.program);
36var vertexObject = gl.createBuffer();
37gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
38gl.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);
41gl.enableVertexAttribArray(0);
42gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
43glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup");
44
45var texCoordObject = gl.createBuffer();
46gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
47gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
48 [0,0, 1,0, 0,1,
49 0,1, 1,0, 1,1]), gl.STATIC_DRAW);
50gl.enableVertexAttribArray(1);
51gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
52glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup");
53
54// Now resize these buffers because we want to change what we're drawing.
55gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
56gl.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);
59glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition");
60gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
61gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([
62 255, 0, 0, 255,
63 255, 0, 0, 255,
64 255, 0, 0, 255,
65 255, 0, 0, 255,
66 0, 255, 0, 255,
67 0, 255, 0, 255,
68 0, 255, 0, 255,
69 0, 255, 0, 255]), gl.STATIC_DRAW);
70gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0);
71glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition");
72
73var numQuads = 2;
74var indices = new Uint8Array(numQuads * 6);
75for (var ii = 0; ii < numQuads; ++ii) {
76 var offset = ii * 6;
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;
84}
85var indexObject = gl.createBuffer();
86gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
87gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
88glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");
89gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0);
90glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
91
92debug("")
kbr@google.comae73e942010-06-28 17:41:40 +000093</script>
kbr@google.comae73e942010-06-28 17:41:40 +000094</body>
95</html>