tor-browser

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

clipping-wide-points.js (2620B)


      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 'use strict';
      8 description("This test ensures clipping works with wide points whose centers are out of the viewport");
      9 
     10 var wtu = WebGLTestUtils;
     11 var gl = wtu.create3DContext("testbed", undefined, contextVersion);
     12 
     13 var pointSize;
     14 
     15 function setupProgram() {
     16    var vs = "attribute vec4 pos;" +
     17        "uniform float pointSize; " +
     18        "void main() {" +
     19        "  gl_PointSize = pointSize;" +
     20        "  gl_Position = pos;" +
     21        "}";
     22    var fs = "precision mediump float;" +
     23        "void main() {" +
     24        "  gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);" +
     25        "}";
     26    var program = wtu.setupProgram(gl, [vs, fs], ['pos']);
     27    if (program) {
     28        var loc = gl.getUniformLocation(program, 'pointSize');
     29        gl.uniform1f(loc, pointSize);
     30        gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
     31        gl.enableVertexAttribArray(0);
     32        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors after setting up program");
     33    }
     34    return program;
     35 }
     36 
     37 function runOneTestCase(vertex) {
     38    debug("");
     39    debug("testing point at (" + vertex[0] + ", " + vertex[1] + ", " + vertex[2] + ")");
     40    var data = new Float32Array(vertex);
     41    gl.bufferSubData(gl.ARRAY_BUFFER, 0, data);
     42 
     43    gl.clear(gl.COLOR_BUFFER_BIT);
     44    gl.drawArrays(gl.POINTS, 0, 1);
     45    wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 255, 0]);
     46    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors after running one test case");
     47 }
     48 
     49 function runTests() {
     50    if (!gl) {
     51        testFailed("context does not exist");
     52        return;
     53    }
     54 
     55    var range = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
     56    if (range[1] < 2.0) {
     57        testPassed("ALIASDED_POINT_SIZE_RANGE less than 2");
     58        return;
     59    }
     60    pointSize = 2.0;
     61 
     62    var data = new Float32Array(4);
     63    var buffer = gl.createBuffer();
     64    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
     65    gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
     66 
     67    var program = setupProgram();
     68    if (!program) {
     69        testFailed("fail to set up program");
     70        return;
     71    }
     72 
     73    gl.disable(gl.BLEND);
     74    gl.disable(gl.DITHER);
     75    gl.disable(gl.DEPTH_TEST);
     76 
     77    gl.clearColor(1.0, 0.0, 0.0, 1.0);
     78 
     79    var vertices = [
     80        [ 0.99, 0.5, 0.0, 1.0 ],
     81        [ 1.01, 0.5, 0.0, 1.0 ],
     82        [ 0.5, 0.99, 0.0, 1.0 ],
     83        [ 0.5, 1.01, 0.0, 1.0 ],
     84    ];
     85    for (var idx = 0; idx < vertices.length; ++idx) {
     86        runOneTestCase(vertices[idx]);
     87    }
     88 }
     89 
     90 runTests();
     91 debug("");
     92 var successfullyParsed = true;