tor-browser

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

occlusion-query.html (4093B)


      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>WebGL Occlusion Query Conformance Tests</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 <div id="description"></div>
     18 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
     19 <div id="console"></div>
     20 <script>
     21 "use strict";
     22 description("This test verifies the functionality of occlusion query objects.");
     23 
     24 debug("");
     25 
     26 var tests = [];
     27 var currentTest;
     28 var currentTestIndex = 0;
     29 var numberOfTestAttempts = 4; // Just to stress implementations a bit more.
     30 var query;
     31 var numberOfCompletionAttempts = 0;
     32 
     33 function setupTests(gl) {
     34    tests = [
     35        {
     36            target: gl.ANY_SAMPLES_PASSED_CONSERVATIVE,
     37            name:   "ANY_SAMPLES_PASSED_CONSERVATIVE",
     38            result: 1,
     39        },
     40        {
     41            target: gl.ANY_SAMPLES_PASSED,
     42            name:   "ANY_SAMPLES_PASSED",
     43            result: 1,
     44        },
     45    ];
     46 }
     47 
     48 function runOcclusionQueryTest() {
     49    currentTest = tests[currentTestIndex];
     50 
     51    debug("");
     52    debug("Testing completion and behavior of " + currentTest.name + " occlusion query");
     53    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     54    var program = wtu.setupSimpleColorProgram(gl, 0);
     55    gl.uniform4f(gl.getUniformLocation(program, "u_color"), 0, 1, 0, 1);
     56    wtu.setupUnitQuad(gl, 0);
     57    query = gl.createQuery();
     58    var target = currentTest.target;
     59    gl.beginQuery(target, query);
     60    wtu.drawUnitQuad(gl);
     61    gl.endQuery(target);
     62 
     63    // Verify as best as possible that the implementation doesn't
     64    // allow a query's result to become available the same frame, by
     65    // spin-looping for some time and ensuring that none of the
     66    // queries' results become available.
     67    var numEarlyTests = 20000;
     68    while (--numEarlyTests > 0) {
     69        gl.finish();
     70        if (gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) {
     71            testFailed("Query's result became available too early");
     72            finishTest();
     73            return;
     74        }
     75    }
     76 
     77    testPassed("Query's result didn't become available too early");
     78    numberOfCompletionAttempts = 0;
     79    requestAnimationFrame(completeOcclusionQueryTest);
     80 }
     81 
     82 function completeOcclusionQueryTest() {
     83    ++numberOfCompletionAttempts;
     84 
     85    if (numberOfCompletionAttempts > 500) {
     86        testFailed("Query didn't become available in a reasonable time");
     87        finishTest();
     88        return;
     89    }
     90 
     91    if (!gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) {
     92        requestAnimationFrame(completeOcclusionQueryTest);
     93        return;
     94    }
     95 
     96    // No matter whether the test was run with ANY_SAMPLES_PASSED or
     97    // ANY_SAMPLES_PASSED_CONSERVATIVE, the query object should always
     98    // report a non-zero result.
     99    var result = gl.getQueryParameter(query, gl.QUERY_RESULT);
    100    if (result == currentTest.result) {
    101        testPassed("Occlusion query " + currentTest.name + " returned a correct result (" + result + ")");
    102    } else {
    103        testFailed("Occlusion query " + currentTest.name + " returned an incorrect result " + result + " (expected " + currentTest.result + ")");
    104    }
    105 
    106    gl.deleteQuery(query);
    107    query = null;
    108 
    109    ++currentTestIndex;
    110    if (currentTestIndex >= tests.length) {
    111        --numberOfTestAttempts;
    112        if (numberOfTestAttempts == 0) {
    113            finishTest();
    114        } else {
    115            currentTestIndex = 0;
    116            requestAnimationFrame(runOcclusionQueryTest);
    117        }
    118    } else {
    119        requestAnimationFrame(runOcclusionQueryTest);
    120    }
    121 }
    122 
    123 var wtu = WebGLTestUtils;
    124 var canvas = document.getElementById("canvas");
    125 var gl = wtu.create3DContext(canvas, null, 2);
    126 
    127 if (!gl) {
    128    testFailed("WebGL context does not exist");
    129 } else {
    130    testPassed("WebGL context exists");
    131 
    132    setupTests(gl);
    133    runOcclusionQueryTest();
    134 }
    135 </script>
    136 </body>
    137 </html>