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>-
1 Index Rendering 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);
40 description(document
.title
);
42 var wtu
= WebGLTestUtils
;
43 var gl
= wtu
.create3DContext("example");
44 var contextVersion
= wtu
.getDefault3DContextVersion();
45 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ["vPosition"]);
47 var vertexObject
= gl
.createBuffer();
48 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
49 var vertexData
= new Float32Array(65536 * 3);
50 vertexData
[0 * 3 + 0] = 0.0;
51 vertexData
[0 * 3 + 1] = 0.5;
52 vertexData
[0 * 3 + 2] = 0.0;
53 vertexData
[1 * 3 + 0] = -0.5;
54 vertexData
[1 * 3 + 1] = -0.5;
55 vertexData
[1 * 3 + 2] = 0.0;
56 vertexData
[65535 * 3 + 0] = 0.5;
57 vertexData
[65535 * 3 + 1] = -0.5;
58 vertexData
[65535 * 3 + 2] = 0.0;
59 gl
.bufferData(gl
.ARRAY_BUFFER
, vertexData
, gl
.STATIC_DRAW
);
60 gl
.enableVertexAttribArray(0);
61 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
63 var indices
= new Uint16Array([0, 1, -1]);
64 var indexBuffer
= gl
.createBuffer();
65 gl
.bindBuffer(gl
.ELEMENT_ARRAY_BUFFER
, indexBuffer
);
66 gl
.bufferData(gl
.ELEMENT_ARRAY_BUFFER
, indices
, gl
.STATIC_DRAW
);
68 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
69 gl
.drawElements(gl
.TRIANGLES
, 3, gl
.UNSIGNED_SHORT
, 0);
71 if (contextVersion
<= 1) {
72 // This should render a green triangle in the middle of the canvas.
73 // Some implementations may incorrectly interpret the -1 index as
74 // a primitive restart and not render anything.
76 // Test several locations
77 // First line should be all black
78 wtu
.checkCanvasRect(gl
, 0, 0, 50, 1, [0, 0, 0, 0]);
80 // Line 15 should be green for at least 10 pixels starting from row 20
81 wtu
.checkCanvasRect(gl
, 20, 15, 10, 1, [0, 255, 0, 255]);
83 // Last line should be all black
84 wtu
.checkCanvasRect(gl
, 0, 49, 50, 1, [0, 0, 0, 0]);
86 // For WebGL 2, PRIMITIVE_RESTART_FIXED_INDEX is always enabled.
87 // Nothing should be drawn on the canvas.
88 wtu
.checkCanvasRect(gl
, 0, 0, 50, 50, [0, 0, 0, 0]);
93 var successfullyParsed
= true;
95 <script src=
"../../js/js-test-post.js"></script>