Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / attribs / gl-vertex-attrib-i-render.html
blob5fcbc786fee075ca843b82fcd2211b84e502a1a9
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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"></script>
14 <script id='vshader' type='x-shader/x-vertex'>#version 300 es
15 layout(location=0) in ivec2 p;
16 layout(location=1) in ivec4 a;
17 void main()
19 gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y, 0.0, 10.0);
21 </script>
22 <script id='vshader_unsigned' type='x-shader/x-vertex'>#version 300 es
23 layout(location=0) in ivec2 p;
24 layout(location=1) in uvec4 a;
25 void main()
27 gl_Position = vec4(p.x + int(a.x + a.y + a.z + a.w), p.y, 0.0, 10.0);
29 </script>
30 <script id='fshader' type='x-shader/x-fragment'>#version 300 es
31 precision mediump float;
32 layout(location=0) out vec4 oColor;
33 void main()
35 oColor = vec4(1.0, 0.0, 0.0, 1.0);
37 </script>
38 <script>
39 "use strict";
40 function checkRedPortion(gl, w, low, high) {
41 var buf = new Uint8Array(w * w * 4);
42 gl.readPixels(0, 0, w, w, gl.RGBA, gl.UNSIGNED_BYTE, buf);
43 var i = 0;
44 for (; i < w; ++i) {
45 if (buf[i * 4 + 0] == 255 && buf[i * 4 + 1] == 0 && buf[i * 4 + 2] == 0 && buf[i * 4 + 3] == 255) {
46 break;
49 return low <= i && i <= high;
52 function runTest() {
53 var wtu = WebGLTestUtils;
54 var gl = wtu.create3DContext('testbed', { preserveDrawingBuffer : true }, 2);
55 if (!gl) {
56 testFailed('could not create context');
57 return;
59 var program = wtu.setupProgram(gl, ['vshader', 'fshader']);
60 var program_unsigned = wtu.setupProgram(gl, ['vshader_unsigned', 'fshader']);
62 gl.enableVertexAttribArray(0);
63 var pos = gl.createBuffer();
64 gl.bindBuffer(gl.ARRAY_BUFFER, pos);
65 gl.bufferData(gl.ARRAY_BUFFER, new Int32Array([-10, -10, 10, -10, -10, 10, 10, 10]), gl.STATIC_DRAW);
67 gl.vertexAttribIPointer(0, 2, gl.INT, 4 * 2, 0);
69 debug('Test vertexAttribI4[ui][v] by setting different combinations that add up to 15 and use that when rendering.');
70 var vals = [[2, -3, 6, 10], [1, 3, 1, 10], [-10, 3, 2, 20], [5, 6, 2, 2]];
71 var tests = ['vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribI4iv', 'vertexAttribI4uiv'];
73 for (var ii = 0; ii < 4; ++ii) {
74 if (ii % 2 == 0) {
75 gl.useProgram(program);
76 } else {
77 gl.useProgram(program_unsigned);
79 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
80 if (ii < 2) {
81 gl[tests[ii]](1, vals[ii][0], vals[ii][1], vals[ii][2], vals[ii][3]);
82 } else {
83 gl[tests[ii]](1, vals[ii]);
85 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
87 if (checkRedPortion(gl, 50, 50 * 0.7, 50 * 0.8)) {
88 testPassed('Attribute of ' + tests[ii] + ' was set correctly');
89 } else {
90 testFailed('Attribute of ' + tests[ii] + ' was not set correctly');
94 </script>
95 </head>
96 <body>
97 <canvas id="testbed" width="50" height="50"></canvas>
98 <div id="description"></div>
99 <div id="console"></div>
100 <script>
101 "use strict";
102 description('Verify that using constant attributes for vertexAttribI* works.');
103 runTest();
104 var successfullyParsed = true;
105 </script>
106 <script src="../../js/js-test-post.js"></script>
107 </body>
108 </html>