tor-browser

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

glsl-built-ins.html (3121B)


      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 GLSL built in variables Conformance Test</title>
     12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     13 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
     14 <script src="../../../js/js-test-pre.js"></script>
     15 <script src="../../../js/webgl-test-utils.js"></script>
     16 </head>
     17 <body>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <canvas id="example" width="2" height="2"> </canvas>
     21 <script id="vshader" type="x-shader/x-vertex">
     22 attribute vec4 a_position;
     23 void main()
     24 {
     25    gl_Position = a_position;
     26 }
     27 </script>
     28 <script id="vshaderCheck" type="x-shader/x-vertex">
     29 attribute vec4 a_position;
     30 varying vec4 v_color;
     31 void main()
     32 {
     33    gl_Position = a_position;
     34    v_color = (gl_$(name) == $(max)) ? vec4(0,1,0,1) : vec4(1,0,0,1);
     35 }
     36 </script>
     37 <script id="fshader" type="x-shader/x-fragment">
     38 precision mediump float;
     39 varying vec4 v_color;
     40 void main()
     41 {
     42    gl_FragColor = v_color;
     43 }
     44 </script>
     45 <script id="fshaderCheck" type="x-shader/x-fragment">
     46 precision mediump float;
     47 void main()
     48 {
     49    gl_FragColor = (gl_$(name) == $(max)) ? vec4(0,1,0,1) : vec4(1,0,0,1);
     50 }
     51 </script>
     52 <script>
     53 "use strict";
     54 description();
     55 var wtu = WebGLTestUtils;
     56 var gl = wtu.create3DContext("example");
     57 var contextVersion = wtu.getDefault3DContextVersion();
     58 
     59 var variables = [
     60  { name: 'MaxVertexAttribs',             min:   8, },
     61  { name: 'MaxVertexUniformVectors',      min: 128, },
     62  { name: 'MaxVaryingVectors',            min:   8, },
     63  { name: 'MaxVertexTextureImageUnits',   min:   0, },
     64  { name: 'MaxCombinedTextureImageUnits', min:   8, },
     65  { name: 'MaxTextureImageUnits',         min:   8, },
     66  { name: 'MaxFragmentUniformVectors',    min:  16, },
     67 ];
     68 
     69 if (contextVersion <= 1) {
     70  variables.push({ name: 'MaxDrawBuffers', min: 1, max: 1});
     71 } else {
     72  variables.push({ name: 'MaxDrawBuffers', min: 1, });
     73 }
     74 
     75 var toUnderscore = function(str) {
     76  return str.replace(/([a-z])([A-Z])/g, function (g) { return g[0] + "_" + g[1].toUpperCase() }).toUpperCase();
     77 };
     78 
     79 var shaderPairs = [
     80   [wtu.getScript("vshader"), wtu.getScript("fshaderCheck")],
     81   [wtu.getScript("vshaderCheck"), wtu.getScript("fshader")],
     82 ];
     83 
     84 wtu.setupUnitQuad(gl);
     85 
     86 variables.forEach(function(variable) {
     87  debug("");
     88  debug("Testing gl_" + variable.name);
     89  if (!variable.max) {
     90    variable.max = gl.getParameter(gl[toUnderscore(variable.name)]);
     91    expectTrue(variable.max >= variable.min, "gl.getParameter(gl." + toUnderscore(variable.name) + ") >= " + variable.min);
     92  }
     93  shaderPairs.forEach(function(pair) {
     94    var shaders = [wtu.replaceParams(pair[0], variable), wtu.replaceParams(pair[1], variable)];
     95    var program = wtu.setupProgram(gl, shaders, ["a_position"], undefined, true);
     96    wtu.clearAndDrawUnitQuad(gl);
     97    wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
     98  });
     99 });
    100 
    101 var successfullyParsed = true;
    102 </script>
    103 <script src="../../../js/js-test-post.js"></script>
    104 </body>
    105 </html>