4 <title>WebGL Enable Vertex Attrib Zero Test
</title>
5 <script src=
"../../../resources/js-test.js"></script>
6 <script src=
"resources/webgl-test.js"> </script>
7 <script src=
"resources/webgl-test-utils.js"> </script>
10 <canvas id=
"example" width=
"50" height=
"50">
12 <div id=
"description"></div>
13 <div id=
"console"></div>
14 <script id=
"vshader" type=
"x-shader/x-vertex">
15 attribute vec4 vPosition;
18 gl_Position = vPosition;
22 <script id=
"fshader" type=
"x-shader/x-fragment">
25 gl_FragColor = vec4(
0.0,
0.0,
0.0,
0.0);
30 description("Test some of the issues of the difference between attrib 0 on OpenGL vs WebGL");
32 var wtu
= WebGLTestUtils
;
33 var canvas
= document
.getElementById("example");
34 var gl
= wtu
.create3DContext(canvas
);
36 function setup(numVerts
, attribIndex
) {
37 var program
= wtu
.setupProgram(
39 [wtu
.loadShaderFromScript(gl
, 'vshader', gl
.VERTEX_SHADER
),
40 wtu
.loadShaderFromScript(gl
, 'fshader', gl
.FRAGMENT_SHADER
)],
41 ['vPosition'], [attribIndex
]);
42 // draw with something on attrib zero with a small number of vertices
43 var vertexObject
= gl
.createBuffer();
45 g_attribLocation
= attribIndex
;
46 shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')");
47 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
49 gl
.ARRAY_BUFFER
, new Float32Array(numVerts
* 3), gl
.STATIC_DRAW
);
50 gl
.vertexAttribPointer(attribIndex
, 3, gl
.FLOAT
, false, 0, 0);
51 var indices
= new Uint16Array(numVerts
);
52 for (var ii
= 0; ii
< numVerts
; ++ii
) {
55 var indexBuffer
= gl
.createBuffer();
56 gl
.bindBuffer(gl
.ELEMENT_ARRAY_BUFFER
, indexBuffer
);
57 gl
.bufferData(gl
.ELEMENT_ARRAY_BUFFER
, indices
, gl
.STATIC_DRAW
);
62 var p2
= setup(60000, 3);
64 for (var ii
= 0; ii
< 5; ++ii
) {
66 gl
.enableVertexAttribArray(0);
67 gl
.drawElements(gl
.TRIANGLES
, 3, gl
.UNSIGNED_SHORT
, 0);
70 "drawing using attrib 0 with 3 verts");
73 gl
.enableVertexAttribArray(3);
74 gl
.drawArrays(gl
.LINES
, 0, 60000);
77 "drawing using attrib 3 with 60000 verts");
80 wtu
.checkCanvas(gl
, [0, 0, 0, 0], "canvas should be 0, 0, 0, 0");