tor-browser

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

context-attributes-depth-stencil-antialias-obeyed.html (2736B)


      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 </head>
     14 <body>
     15 <div id="description"></div>
     16 <div id="console"></div>
     17 <script>
     18 "use strict";
     19 
     20 function getWebGL(attribs) {
     21  var canvas = document.createElement("canvas");
     22  if (!canvas)
     23    return null;
     24 
     25  // We can't use wtu.create3DContext because it defaults to antialias=false.
     26  var names = ["webgl2"];
     27  var gl = null;
     28  for (var i = 0; i < names.length; ++i) {
     29    try {
     30      gl = canvas.getContext(names[i], attribs);
     31    } catch (e) {
     32    }
     33    if (gl) {
     34      break;
     35    }
     36  }
     37  if (!gl)
     38    return null;
     39  return gl;
     40 }
     41 
     42 function testAttribs(attribs) {
     43  var antialias, depth, stencil;
     44  if (!attribs) {
     45    antialias = true;
     46    depth = true;
     47    stencil = false;
     48    debug("Testing default attributes: { antialias: true, depth: true, stencil:false }");
     49  } else {
     50    antialias = attribs.antialias;
     51    depth = attribs.depth;
     52    stencil = attribs.stencil;
     53    debug("Testing specified attributes: { antialias: " + antialias + ", depth: " + depth + ", stencil: " + stencil + " }");
     54  }
     55  var gl = getWebGL(attribs);
     56  if (!gl) {
     57    testFailed("Fail to create a context");
     58    return;
     59  }
     60  var actual_attribs = gl.getContextAttributes();
     61  if (antialias != actual_attribs.antialias)
     62    testFailed("antialias = " + antialias + " is not obeyed")
     63  if (depth != actual_attribs.depth)
     64    testFailed("depth = " + depth + " is not obeyed")
     65  if (stencil != actual_attribs.stencil)
     66    testFailed("stencil = " + stencil + " is not obeyed")
     67  if (antialias == actual_attribs.antialias &&
     68      depth == actual_attribs.depth &&
     69      stencil == actual_attribs.stencil) {
     70    testPassed("Context created with the correct antialias, depth, and stencil.");
     71  }
     72 }
     73 
     74 description('Verify WebGLContextAttributes are working as specified, including depth, stencil, antialias');
     75 testAttribs(null);  // Default attribs
     76 testAttribs({antialias: true, depth: true, stencil: true});
     77 testAttribs({antialias: false, depth: true, stencil: true});
     78 testAttribs({antialias: true, depth: false, stencil: true});
     79 testAttribs({antialias: false, depth: false, stencil: true});
     80 testAttribs({antialias: true, depth: true, stencil: false});
     81 testAttribs({antialias: false, depth: true, stencil: false});
     82 testAttribs({antialias: true, depth: false, stencil: false});
     83 testAttribs({antialias: false, depth: false, stencil: false});
     84 
     85 var successfullyParsed = true;
     86 </script>
     87 <script src="../../js/js-test-post.js"></script>
     88 </body>
     89 </html>