tor-browser

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

gl-pointcoord.html (4100B)


      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 <title>gl-pointcoord Test</title>
     12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     13 <script src="../../../js/js-test-pre.js"></script>
     14 <script src="../../../js/webgl-test-utils.js"> </script>
     15 </head>
     16 <body>
     17 <canvas id="example" width="256" height="256">
     18 </canvas>
     19 <div id="description"></div>
     20 <div id="console"></div>
     21 <script id="vshader" type="x-shader/x-vertex">
     22 attribute vec4 vPosition;
     23 uniform float uPointSize;
     24 void main()
     25 {
     26  gl_PointSize = uPointSize;
     27  gl_Position = vPosition;
     28 }
     29 </script>
     30 
     31 <script id="fshader" type="x-shader/x-fragment">
     32 precision mediump float;
     33 void main()
     34 {
     35  gl_FragColor = vec4(
     36      gl_PointCoord.x,
     37      gl_PointCoord.y,
     38      0,
     39      1);
     40 }
     41 </script>
     42 
     43 <script>
     44 "use strict";
     45 description("Checks gl_PointCoord and gl_PointSize");
     46 debug("");
     47 
     48 // NOTE: I'm not 100% confident in this test. I think it is correct.
     49 
     50 var wtu = WebGLTestUtils;
     51 var gl = wtu.create3DContext("example");
     52 shouldBeNonNull("gl");
     53 var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
     54 shouldBe("gl.getError()", "gl.NO_ERROR");
     55 
     56 var canvas = gl.canvas;
     57 var width = canvas.width;
     58 var height = canvas.height;
     59 shouldBe("width", "height");
     60 
     61 var maxPointSize = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE)[1];
     62 shouldBeTrue("maxPointSize >= 1");
     63 // The minimum and maximum point sizes may be floating-point numbers.
     64 shouldBeTrue("Math.floor(maxPointSize) >= 1");
     65 maxPointSize = Math.floor(maxPointSize);
     66 shouldBeTrue("maxPointSize % 1 == 0");
     67 
     68 maxPointSize = Math.min(maxPointSize, 64);
     69 var pointWidth = maxPointSize / width;
     70 var pointStep = Math.floor(maxPointSize / 4);
     71 var pointStep = Math.max(1, pointStep);
     72 
     73 var pointSizeLoc = gl.getUniformLocation(program, "uPointSize");
     74 gl.uniform1f(pointSizeLoc, maxPointSize);
     75 
     76 var pixelOffset = (maxPointSize % 2) ? (1 / width) : 0;
     77 var vertexObject = gl.createBuffer();
     78 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
     79 gl.bufferData(
     80    gl.ARRAY_BUFFER,
     81    new Float32Array(
     82        [-0.5 + pixelOffset, -0.5 + pixelOffset,
     83          0.5 + pixelOffset, -0.5 + pixelOffset,
     84         -0.5 + pixelOffset,  0.5 + pixelOffset,
     85          0.5 + pixelOffset,  0.5 + pixelOffset]),
     86    gl.STATIC_DRAW);
     87 gl.enableVertexAttribArray(0);
     88 gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
     89 
     90 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     91 
     92 gl.drawArrays(gl.POINTS, 0, 4);
     93 shouldBe("gl.getError()", "gl.NO_ERROR");
     94 
     95 function s2p(s) {
     96  return (s + 1.0) * 0.5 * width;
     97 }
     98 
     99 //function print(x, y) {
    100 //  var b = new Uint8Array(4);
    101 //  gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, b);
    102 //  debug("" + x + "," + y + ": " + b[0] + "," + b[1] + "," + b[2]);
    103 //}
    104 //
    105 //for (var ii = 0; ii < 100; ++ii) {
    106 //  print(ii, ii);
    107 //}
    108 
    109 for (var py = 0; py < 2; ++py) {
    110  for (var px = 0; px < 2; ++px) {
    111    debug("");
    112    var pointX = -0.5 + px + pixelOffset;
    113    var pointY = -0.5 + py + pixelOffset;
    114    for (var yy = 0; yy < maxPointSize; yy += pointStep) {
    115      for (var xx = 0; xx < maxPointSize; xx += pointStep) {
    116        // formula for s and t from OpenGL ES 2.0 spec section 3.3
    117        var xw = s2p(pointX);
    118        var yw = s2p(pointY);
    119        //debug("xw: " + xw + " yw: " + yw);
    120        var u = xx / maxPointSize * 2 - 1;
    121        var v = yy / maxPointSize * 2 - 1;
    122        var xf = Math.floor(s2p(pointX + u * pointWidth));
    123        var yf = Math.floor(s2p(pointY + v * pointWidth));
    124        //debug("xf: " + xf + " yf: " + yf);
    125        var s = 0.5 + (xf + 0.5 - xw) / maxPointSize;
    126        var t = 0.5 + (yf + 0.5 - yw) / maxPointSize;
    127        //debug("s: " + s + " t: " + t);
    128        var color = [Math.floor(s * 255), Math.floor((1 - t) * 255), 0];
    129        var msg = "pixel " + xf + "," + yf + " should be " + color;
    130        wtu.checkCanvasRect(gl, xf, yf, 1, 1, color, msg, 4);
    131      }
    132    }
    133  }
    134 }
    135 
    136 var successfullyParsed = true;
    137 </script>
    138 <script src="../../../js/js-test-post.js"></script>
    139 
    140 </body>
    141 </html>