Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / rendering / negative-one-index.html
blob69a59940a8e382184bae6c6031312cfd741109f2
1 <!--
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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
15 </head>
16 <body>
17 <canvas id="example" width="50" height="50">
18 </canvas>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="vshader" type="x-shader/x-vertex">
22 attribute vec4 vPosition;
23 void main()
25 gl_Position = vPosition;
27 </script>
29 <script id="fshader" type="x-shader/x-fragment">
30 void main()
32 gl_FragColor = vec4(0.0,1.0,0.0,1.0);
34 </script>
36 <script>
37 "use strict";
38 function init()
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]);
85 } else {
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]);
92 init();
93 var successfullyParsed = true;
94 </script>
95 <script src="../../js/js-test-post.js"></script>
97 </body>
98 </html>