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>WebGL Enable Vertex Attrib Zero Test
</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=
"example" width=
"50" height=
"50">
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"vshader" type=
"x-shader/x-vertex">
22 attribute vec4 vPosition;
25 gl_Position = vPosition;
29 <script id=
"fshader" type=
"x-shader/x-fragment">
32 gl_FragColor = vec4(
0.0,
1.0,
0.0,
1.0);
38 description("Test some of the issues of the difference between attrib 0 on OpenGL vs WebGL");
40 var wtu
= WebGLTestUtils
;
41 var gl
= wtu
.create3DContext("example");
44 function setup(attribIndex
) {
45 var program
= wtu
.setupProgram(
46 gl
, ['vshader', 'fshader'], ['vPosition'], [attribIndex
]);
48 g_attribLocation
= attribIndex
;
49 shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')");
53 function setupVerts(numVerts
) {
62 var positions
= new Float32Array(numVerts
* 3);
63 var indices
= new Uint16Array(numVerts
);
64 for (var ii
= 0; ii
< numVerts
; ++ii
) {
68 for (var jj
= 0; jj
< 3; ++jj
) {
69 positions
[dst
+ jj
] = verts
[src
+ jj
];
73 var vertexObject
= gl
.createBuffer();
74 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
75 gl
.bufferData(gl
.ARRAY_BUFFER
, positions
, gl
.STATIC_DRAW
);
76 var indexBuffer
= gl
.createBuffer();
77 gl
.bindBuffer(gl
.ELEMENT_ARRAY_BUFFER
, indexBuffer
);
78 gl
.bufferData(gl
.ELEMENT_ARRAY_BUFFER
, indices
, gl
.STATIC_DRAW
);
85 for (var ii
= 0; ii
< 5; ++ii
) {
86 // test drawing with attrib 0
88 gl
.enableVertexAttribArray(0);
89 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
90 gl
.clear(gl
.COLOR_BUFFER_BIT
);
91 gl
.drawElements(gl
.TRIANGLES
, 60000, gl
.UNSIGNED_SHORT
, 0);
94 "drawing using attrib 0 with 6 verts");
95 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "canvas should be green");
96 gl
.disableVertexAttribArray(0);
98 // test drawing without attrib 0
100 gl
.enableVertexAttribArray(3);
101 gl
.vertexAttribPointer(3, 3, gl
.FLOAT
, false, 0, 0);
102 gl
.clear(gl
.COLOR_BUFFER_BIT
);
103 gl
.drawArrays(gl
.TRIANGLES
, 0, 60000);
106 "drawing using attrib 3 with 60000 verts");
107 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "canvas should be green");
108 gl
.disableVertexAttribArray(3);
110 // This second test of drawing without attrib0 uncovered a bug in chrome
111 // where after the draw without attrib0 the attrib 0 emulation code disabled
112 // attrib 0 and it was never re-enabled so this next draw failed.
114 gl
.enableVertexAttribArray(3);
115 gl
.clear(gl
.COLOR_BUFFER_BIT
);
116 gl
.drawElements(gl
.TRIANGLES
, 60000, gl
.UNSIGNED_SHORT
, 0);
119 "drawing using attrib 3 with 60000 verts");
120 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "canvas should be green");
121 gl
.disableVertexAttribArray(3);
125 var successfullyParsed
= true;
127 <script src=
"../../js/js-test-post.js"></script>