tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gl-vertex-attrib-i-render.html (3400B)


      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 -->
      6 
      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()
     18 {
     19    gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y, 0.0, 10.0);
     20 }
     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()
     26 {
     27    gl_Position = vec4(p.x + int(a.x + a.y + a.z + a.w), p.y, 0.0, 10.0);
     28 }
     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()
     34 {
     35    oColor = vec4(1.0, 0.0, 0.0, 1.0);
     36 }
     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;
     47        }
     48    }
     49    return low <= i && i <= high;
     50 }
     51 
     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;
     58    }
     59    var program = wtu.setupProgram(gl, ['vshader', 'fshader']);
     60    var program_unsigned = wtu.setupProgram(gl, ['vshader_unsigned', 'fshader']);
     61 
     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);
     66 
     67    gl.vertexAttribIPointer(0, 2, gl.INT, 4 * 2, 0);
     68 
     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'];
     72 
     73    for (var ii = 0; ii < 4; ++ii) {
     74        if (ii % 2 == 0) {
     75            gl.useProgram(program);
     76        } else {
     77            gl.useProgram(program_unsigned);
     78        }
     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]);
     84        }
     85        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
     86 
     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');
     91        }
     92    }
     93 }
     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>