tor-browser

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

struct-as-inout-parameter.html (3080B)


      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>GLSL Structure as Inout Parameter 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 <script src="../../../js/glsl-conformance-test.js"></script>
     17 
     18 <script id="simple-vs" type="x-shader/x-vertex">
     19 attribute vec4 a_position;
     20 void main(void) {
     21    gl_Position = a_position;
     22 }
     23 </script>
     24 <script id="struct-inout-parameter-fs" type="x-shader/x-fragment">
     25 struct ColorData {
     26  vec3 red;
     27  vec3 blue;
     28 };
     29 
     30 void modify(inout ColorData colorData) {
     31  colorData.red += vec3(0.5, 0.0, 0.0);
     32  colorData.blue += vec3(0.0, 0.0, 0.5);
     33 }
     34 
     35 void main() {
     36  ColorData colorData;
     37  colorData.red = vec3(0.5, 0.0, 0.0);
     38  colorData.blue = vec3(0.0, 0.0, 0.5);
     39 
     40  vec3 red = vec3(1.0, 0.0, 0.0);
     41  vec3 green = vec3(0.0, 1.0, 0.0);
     42  vec3 blue = vec3(0.0, 0.0, 1.0);
     43  vec3 finalColor;
     44 
     45  modify(colorData);
     46 
     47  if (colorData.red == red && colorData.blue == blue)
     48    finalColor = green;
     49  else
     50    finalColor = red;
     51 
     52  gl_FragColor = vec4(finalColor, 1.0);
     53 }
     54 </script>
     55 </head>
     56 <body>
     57 <div id="description"></div>
     58 <div id="console"></div>
     59 <script>
     60 "use strict";
     61 description("Testing structs as inout parameter");
     62 
     63 debug('Regression test for <a href="http://crbug.com/851870">http://crbug.com/851870</a> / <a href="https://github.com/mrdoob/three.js/issues/14137">https://github.com/mrdoob/three.js/issues/14137</a>');
     64 
     65 function prepend(floatPrecision) {
     66  let source = document.getElementById('struct-inout-parameter-fs').text;
     67  return 'precision ' + floatPrecision + ' float;\n' + source;
     68 }
     69 
     70 let tests = [
     71  {
     72    vShaderId: "simple-vs",
     73    vShaderSuccess: true,
     74    fShaderSource: prepend('lowp'),
     75    fShaderSuccess: true,
     76    linkSuccess: true,
     77    render: true,
     78    passMsg: "lowp struct used as inout parameter",
     79  },
     80  {
     81    vShaderId: "simple-vs",
     82    vShaderSuccess: true,
     83    fShaderSource: prepend('mediump'),
     84    fShaderSuccess: true,
     85    linkSuccess: true,
     86    render: true,
     87    passMsg: "mediump struct used as inout parameter",
     88  },
     89 ];
     90 
     91 let wtu = WebGLTestUtils;
     92 let gl = wtu.create3DContext();
     93 let precision = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
     94 let highpSupported = (precision.rangeMin >= 62 && precision.rangeMax >= 62 && precision.precision >= 16);
     95 debug("highp is" + (highpSupported ? "" : " not") + " supported in fragment shaders");
     96 
     97 if (highpSupported) {
     98  tests.push(
     99    {
    100      vShaderId: "simple-vs",
    101      vShaderSuccess: true,
    102      fShaderSource: prepend('highp'),
    103      fShaderSuccess: true,
    104      linkSuccess: true,
    105      render: true,
    106      passMsg: "highp struct used as inout parameter",
    107    }
    108  );
    109 }
    110 
    111 GLSLConformanceTester.runTests(tests);
    112 debug("");
    113 
    114 var successfullyParsed = true;
    115 </script>
    116 </body>
    117 </html>