summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/attribs/gl-vertex-attrib-normalized-int.html
blob: e1e24be608a0716bbc14c99c176618f4745ee67b (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
<!--
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>
    <title>WebGL 2 Normalized Vertex Attributes Conformance Test</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../../resources/js-test-style.css"/>
</head>
<body>
    <canvas width=1 height=1></canvas>
    <div id="description"></div>
    <div id="console"></div>
    <script id="vertex-shader" type="x-shader/x-vertex">#version 300 es
        layout(location = 0) in vec3 vertex;

        out float normAttrib;

        void main(void) {
            gl_Position = vec4(vertex.xy, 0, 1);
            normAttrib = vertex.z;
        }
    </script>
    <script id="fragment-shader" type="x-shader/x-fragment">#version 300 es
        in lowp float normAttrib;

        layout(location=0) out lowp vec4 fragColor;

        void main(void) {
            fragColor = vec4(vec3(normAttrib == -1.0 ? 1.0 : 0.0), 1);
        }
    </script>
    <script src="../../js/js-test-pre.js"></script>
    <script src="../../js/webgl-test-utils.js"></script>
    <script>
        (function () {
            'use strict';

            var wtu = WebGLTestUtils;

            var gl = wtu.create3DContext(document.querySelector('canvas'), null, 2);

            var program = wtu.setupProgram(gl, ['vertex-shader', 'fragment-shader']);

            gl.useProgram(program);

            var buffer = gl.createBuffer();
            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
            gl.bufferData(gl.ARRAY_BUFFER, new Int8Array([
                // Here we set the third component (the one that's actually tested)
                // to (MIN_INT + 1). If non-zero-preserving rules are used, it'll be
                // converted to a float that's slightly greater than -1. If zero-preserving
                // rules are used, as the GLES 3 spec requires, result of conversion
                // should be exactly -1.
                -0x80,  0x7f, -0x7f,
                 0x7f,  0x7f, -0x7f,
                -0x80, -0x7f, -0x7f,
                -0x80, -0x7f, -0x7f,
                 0x7f,  0x7f, -0x7f,
                 0x7f, -0x80, -0x7f
            ]), gl.STATIC_DRAW);

            gl.enableVertexAttribArray(0);
            gl.vertexAttribPointer(0, 3, gl.BYTE, true, 0, 0);

            gl.drawArrays(gl.TRIANGLE_STRIP, 0, 6);

            wtu.checkCanvas(gl, [255, 255, 255, 255], "should be opaque white");
        }());
    </script>
    <script>
        description('Verify that conversion of normalized signed int attributes to floats uses zero-preserving rule.');
        window.successfullyParsed = true;
    </script>
    <script src="../../js/js-test-post.js"></script>
</body>
</html>