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 drawArrays Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/desktop-gl-constants.js"></script>
14 <script src=
"../../js/js-test-pre.js"></script>
15 <script src=
"../../js/webgl-test-utils.js"> </script>
18 <canvas id=
"example" width=
"50" height=
"50"></canvas>
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(
1.0,
0.0,
0.0,
1.0);
40 description(document
.title
);
42 function checkDrawArrays(mode
, count
, expect
, msg
) {
43 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
44 gl
.drawArrays(mode
, 0, count
);
45 wtu
.glErrorShouldBe(gl
, expect
, msg
);
48 var wtu
= WebGLTestUtils
;
49 var gl
= wtu
.create3DContext("example");
50 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ["vPosition"]);
52 var vertexObject
= gl
.createBuffer();
53 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
54 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl
.STATIC_DRAW
);
55 gl
.enableVertexAttribArray(0);
57 checkDrawArrays(gl
.TRIANGLES
, 3,
58 gl
.INVALID_OPERATION
, "gl.DrawArrays with no buffer attached to VAO should return INVALID_OPERATION");
60 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
62 checkDrawArrays(gl
.TRIANGLES
, 3,
63 gl
.NO_ERROR
, "can call gl.DrawArrays with gl.TRIANGLES");
66 desktopGL
['QUAD_STRIP'], 4,
67 gl
.INVALID_ENUM
, "gl.DrawArrays with QUAD_STRIP should return INVALID_ENUM");
69 desktopGL
['QUADS'], 4,
70 gl
.INVALID_ENUM
, "gl.DrawArrays with QUADS should return INVALID_ENUM");
72 desktopGL
['POLYGON'], 4,
73 gl
.INVALID_ENUM
, "gl.DrawArrays with POLYGON should return INVALID_ENUM");
77 var successfullyParsed
= true;
79 <script src=
"../../js/js-test-post.js"></script>