Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / rendering / vertex-id.html
blobec4bd05ad45ac4331671475e6564bc302389dd29
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>WebGL 2 gl_VertexID Tests</title>
6 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
7 <script src="../../js/desktop-gl-constants.js"></script>
8 <script src="../../js/js-test-pre.js"></script>
9 <script src="../../js/webgl-test-utils.js"></script>
10 </head>
11 <body>
12 <div id="description"></div>
13 <div id="console"></div>
14 <!-- Shaders for testing instanced draws -->
15 <script id="vs" type="text/plain">
16 #version 300 es
17 flat out highp int vVertexID;
19 void main() {
20 vVertexID = gl_VertexID;
21 gl_PointSize = 1.0;
22 gl_Position = vec4(0,0,0,1);
24 </script>
25 <script id="fs" type="text/plain">
26 #version 300 es
27 flat in highp int vVertexID;
28 out highp int oVertexID;
29 void main() {
30 oVertexID = vVertexID;
32 </script>
34 <script>
35 "use strict";
36 description("Test gl_VertexID");
38 debug("");
40 const wtu = WebGLTestUtils;
41 const canvas = document.createElement("canvas");
42 canvas.width = 1;
43 canvas.height = 1;
44 const gl = wtu.create3DContext(canvas, null, 2);
46 (function() {
47 if (!gl) {
48 testFailed("WebGL context does not exist");
49 return;
51 testPassed("WebGL context exists");
53 const vs = document.getElementById("vs").innerHTML.trim();
54 const fs = document.getElementById("fs").innerHTML.trim();
55 const prog = wtu.loadProgram(gl, vs, fs);
56 gl.useProgram(prog);
58 const tex = gl.createTexture();
59 gl.bindTexture(gl.TEXTURE_2D, tex);
60 gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R32I, 1, 1);
61 const fb = gl.createFramebuffer();
62 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
63 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
64 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
65 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors after setup");
67 function shouldBeVal(prefix, expected, was) {
68 let text = prefix + "Should be " + expected;
69 let func = testPassed;
70 if (was != expected) {
71 text = text + ", was " + was;
72 func = testFailed;
74 func(text);
77 const readValData = new Int32Array(10000);
78 function ensureVal(prefix, expected) {
79 gl.readPixels(0, 0, 1, 1, gl.RGBA_INTEGER, gl.INT, readValData);
80 const was = readValData[0];
81 shouldBeVal(prefix, expected, was);
84 gl.clearBufferiv(gl.COLOR, 0, new Int32Array([42, 0, 0, 0]));
85 ensureVal("After clear", 42);
87 // -
89 debug("");
90 debug("----------------");
91 debug("drawArrays");
93 let test = function(first, count) {
94 debug("");
95 debug(`drawArrays(first: ${first}, count: ${count})`);
96 gl.drawArrays(gl.POINTS, first, count);
97 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
98 ensureVal("", first+count-1);
101 test(0, 1);
102 test(1, 1);
103 test(10000, 1);
104 test(100000, 1);
105 test(1000000, 1);
107 test(0, 2);
108 test(1, 2);
109 test(10000, 2);
110 test(100000, 2);
111 test(1000000, 2);
113 const INT32_MAX = 0x7fffffff;
115 test = function(first, count) {
116 debug("");
117 debug(`drawArrays(first: ${first}, count: ${count})`);
118 gl.drawArrays(gl.POINTS, first, count);
119 if (!wtu.glErrorShouldBe(gl, [gl.NO_ERROR, gl.OUT_OF_MEMORY])) {
120 ensureVal("", first+count-1);
124 test(INT32_MAX-2, 1);
125 test(INT32_MAX-1, 1);
126 test(INT32_MAX, 1);
128 // -
130 debug("");
131 debug("----------------");
132 debug("drawElements");
134 const indexBuffer = gl.createBuffer();
135 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
136 const indexData = new Uint16Array([1, 2, 5, 3, 10000]);
137 debug("indexData: " + indexData);
138 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indexData, gl.STATIC_DRAW);
140 test = function(first, count) {
141 debug("");
142 debug(`drawElements(first: ${first}, count: ${count})`);
143 gl.drawElements(gl.POINTS, count, gl.UNSIGNED_SHORT, first*2);
144 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
145 ensureVal("", indexData[first+count-1]);
148 for (let f = 0; f < indexData.length; ++f) {
149 for (let c = 1; f + c <= indexData.length; ++c) {
150 test(f, c);
154 // -
156 debug("");
157 debug("----------------");
158 debug("Via transform feedback");
160 gl.transformFeedbackVaryings(prog, ["vVertexID"], gl.INTERLEAVED_ATTRIBS);
161 wtu.linkProgram(gl, prog);
162 gl.useProgram(prog);
164 const tfBuffer = gl.createBuffer();
165 gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, tfBuffer);
166 gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, 4*10000, gl.DYNAMIC_READ);
168 test = function(offset, count) {
169 debug("");
170 debug("drawArrays(" + offset + ", " + count + ")");
171 gl.beginTransformFeedback(gl.POINTS);
172 gl.drawArrays(gl.POINTS, offset, count);
173 gl.endTransformFeedback();
174 gl.getBufferSubData(gl.TRANSFORM_FEEDBACK_BUFFER, 0, readValData);
175 let ok = true;
176 for (let i = 0; i < readValData.length; i++) {
177 if (i >= count)
178 break;
179 const expected = offset + i;
180 const was = readValData[i];
181 if (was != expected) {
182 testFailed("[" + i + "] expected " + expected + ", was " + was);
183 ok = false;
184 break;
187 if (ok) {
188 testPassed("ok");
192 test(0, 1);
193 test(1, 1);
194 test(10000, 1);
196 test(0, 2);
197 test(1, 2);
198 test(10000, 2);
200 test(10000, 10000);
202 // -
204 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "There should be no remaining errors");
205 })();
207 debug("");
208 var successfullyParsed = true;
209 </script>
210 <script src="../../js/js-test-post.js"></script>
212 </body>
213 </html>
215 <!--
216 Copyright (c) 2019 The Khronos Group Inc.
217 Use of this source code is governed by an MIT-style license that can be
218 found in the LICENSE.txt file.