|
1 <!-- |
|
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
3 Use of this source code is governed by a BSD-style license that can be |
|
4 found in the LICENSE file. |
|
5 --> |
|
6 <!DOCTYPE html> |
|
7 <html> |
|
8 <head> |
|
9 <meta charset="utf-8"> |
|
10 <title>WebGL drawElements Test</title> |
|
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
|
12 <script src="../../resources/js-test-pre.js"></script> |
|
13 <script src="../resources/webgl-test.js"> </script> |
|
14 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> |
|
15 </head> |
|
16 <body> |
|
17 <canvas id="example" width="50" height="50"></canvas> |
|
18 <div id="description"></div> |
|
19 <div id="console"></div> |
|
20 <script id="vshader" type="x-shader/x-vertex"> |
|
21 attribute vec4 vPosition; |
|
22 void main() |
|
23 { |
|
24 gl_Position = vPosition; |
|
25 } |
|
26 </script> |
|
27 |
|
28 <script id="fshader" type="x-shader/x-fragment"> |
|
29 void main() |
|
30 { |
|
31 gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
|
32 } |
|
33 </script> |
|
34 |
|
35 <script> |
|
36 function init() |
|
37 { |
|
38 if (window.initNonKhronosFramework) { |
|
39 window.initNonKhronosFramework(false); |
|
40 } |
|
41 |
|
42 description(document.title); |
|
43 |
|
44 function checkDrawElements(mode, count, type, expect, msg) { |
|
45 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
46 gl.drawElements(mode, count, type, 0); |
|
47 glErrorShouldBe(gl, expect, msg); |
|
48 } |
|
49 |
|
50 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1); |
|
51 |
|
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); |
|
56 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
|
57 |
|
58 var vertexObject = gl.createBuffer(); |
|
59 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject); |
|
60 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([ 0, 1, 2]), gl.STATIC_DRAW); |
|
61 |
|
62 checkDrawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, |
|
63 gl.NO_ERROR, "can call gl.DrawElements with UNSIGNED_SHORT"); |
|
64 |
|
65 var vertexObject = gl.createBuffer(); |
|
66 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject); |
|
67 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array([ 0, 1, 2, 0]), gl.STATIC_DRAW); |
|
68 |
|
69 checkDrawElements( |
|
70 gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, |
|
71 gl.NO_ERROR, "can call gl.DrawElements with UNSIGNED_BYTE"); |
|
72 checkDrawElements( |
|
73 desktopGL['QUAD_STRIP'], 4, gl.UNSIGNED_BYTE, |
|
74 gl.INVALID_ENUM, "gl.DrawElements with QUAD_STRIP should return INVALID_ENUM"); |
|
75 checkDrawElements( |
|
76 desktopGL['QUADS'], 4, gl.UNSIGNED_BYTE, |
|
77 gl.INVALID_ENUM, "gl.DrawElements with QUADS should return INVALID_ENUM"); |
|
78 checkDrawElements( |
|
79 desktopGL['POLYGON'], 4, gl.UNSIGNED_BYTE, |
|
80 gl.INVALID_ENUM, "gl.DrawElements with POLYGON should return INVALID_ENUM"); |
|
81 |
|
82 var vertexObject = gl.createBuffer(); |
|
83 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexObject); |
|
84 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array([ 0, 1, 2]), gl.STATIC_DRAW); |
|
85 |
|
86 checkDrawElements( |
|
87 gl.TRIANGLES, 3, gl.UNSIGNED_INT, |
|
88 gl.INVALID_ENUM, "gl.DrawElements should return INVALID_ENUM with UNSIGNED_INT"); |
|
89 |
|
90 } |
|
91 |
|
92 init(); |
|
93 successfullyParsed = true; |
|
94 </script> |
|
95 <script>finishTest();</script> |
|
96 |
|
97 </body> |
|
98 </html> |