summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/attribs/gl-vertex-attrib-i-render.html
blob: 5fcbc786fee075ca843b82fcd2211b84e502a1a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script id='vshader' type='x-shader/x-vertex'>#version 300 es
layout(location=0) in ivec2 p;
layout(location=1) in ivec4 a;
void main()
{
    gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y, 0.0, 10.0);
}
</script>
<script id='vshader_unsigned' type='x-shader/x-vertex'>#version 300 es
layout(location=0) in ivec2 p;
layout(location=1) in uvec4 a;
void main()
{
    gl_Position = vec4(p.x + int(a.x + a.y + a.z + a.w), p.y, 0.0, 10.0);
}
</script>
<script id='fshader' type='x-shader/x-fragment'>#version 300 es
precision mediump float;
layout(location=0) out vec4 oColor;
void main()
{
    oColor = vec4(1.0, 0.0, 0.0, 1.0);
}
</script>
<script>
"use strict";
function checkRedPortion(gl, w, low, high) {
    var buf = new Uint8Array(w * w * 4);
    gl.readPixels(0, 0, w, w, gl.RGBA, gl.UNSIGNED_BYTE, buf);
    var i = 0;
    for (; i < w; ++i) {
        if (buf[i * 4 + 0] == 255 && buf[i * 4 + 1] == 0 && buf[i * 4 + 2] == 0 && buf[i * 4 + 3] == 255) {
            break;
        }
    }
    return low <= i && i <= high;
}

function runTest() {
    var wtu = WebGLTestUtils;
    var gl = wtu.create3DContext('testbed', { preserveDrawingBuffer : true }, 2);
    if (!gl) {
        testFailed('could not create context');
        return;
    }
    var program = wtu.setupProgram(gl, ['vshader', 'fshader']);
    var program_unsigned = wtu.setupProgram(gl, ['vshader_unsigned', 'fshader']);

    gl.enableVertexAttribArray(0);
    var pos = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, pos);
    gl.bufferData(gl.ARRAY_BUFFER, new Int32Array([-10, -10, 10, -10, -10, 10, 10, 10]), gl.STATIC_DRAW);

    gl.vertexAttribIPointer(0, 2, gl.INT, 4 * 2, 0);

    debug('Test vertexAttribI4[ui][v] by setting different combinations that add up to 15 and use that when rendering.');
    var vals = [[2, -3, 6, 10], [1, 3, 1, 10], [-10, 3, 2, 20], [5, 6, 2, 2]];
    var tests = ['vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribI4iv', 'vertexAttribI4uiv'];

    for (var ii = 0; ii < 4; ++ii) {
        if (ii % 2 == 0) {
            gl.useProgram(program);
        } else {
            gl.useProgram(program_unsigned);
        }
        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
        if (ii < 2) {
            gl[tests[ii]](1, vals[ii][0], vals[ii][1], vals[ii][2], vals[ii][3]);
        } else {
            gl[tests[ii]](1, vals[ii]);
        }
        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

        if (checkRedPortion(gl, 50, 50 * 0.7, 50 * 0.8)) {
            testPassed('Attribute of ' + tests[ii] + ' was set correctly');
        } else {
            testFailed('Attribute of ' + tests[ii] + ' was not set correctly');
        }
    }
}
</script>
</head>
<body>
<canvas id="testbed" width="50" height="50"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Verify that using constant attributes for vertexAttribI* works.');
runTest();
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>