tor-browser

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

struct-nesting-of-variable-names.html (3470B)


      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 <!DOCTYPE html>
      7 <html>
      8 <head>
      9 <meta charset="utf-8">
     10 <link rel="stylesheet" href="../../../resources/js-test-style.css" />
     11 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css" />
     12 <script src="../../../js/js-test-pre.js"></script>
     13 <script src="../../../js/webgl-test-utils.js"></script>
     14 <script src="../../../js/glsl-conformance-test.js"></script>
     15 <title></title>
     16 </head>
     17 <body>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <script id="fragmentShader" type="text/something-not-javascript">
     21 precision mediump float;
     22 struct S { $(outer_type) u; };
     23 void main() {
     24    S S;   // This is legal, 'S' as a typename is defined in another scope.
     25    {
     26        struct S { $(inner_type) a; };  // This is legal as well, 'S' is now defined as a variable name in an ancestor scope
     27        S newvar;
     28        newvar.a = $(initializer);
     29        gl_FragColor = $(fragColor);
     30    }
     31 }
     32 </script>
     33 <script>
     34 "use strict";
     35 description("This test verifies that defining a typename in a new scope when the typename is the name of a variable that hides a typename declaration succeeds for all combinations of GLSL types.");
     36 var tests = [];
     37 var wtu = WebGLTestUtils;
     38 var typeInfo = [
     39    { Type: 'float',    initializer: '1.0',                         fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },
     40    { Type: 'vec2',     initializer: 'vec2(0.0, 1.0)',              fragColor: 'vec4(newvar.a, 0.0, 1.0)' },
     41    { Type: 'vec3',     initializer: 'vec3(0.0, 1.0, 0.0)',         fragColor: 'vec4(newvar.a, 1.0)' },
     42    { Type: 'vec4',     initializer: 'vec4(0.0, 1.0, 0.0, 1.0)',    fragColor: 'newvar.a' },
     43    { Type: 'int',      initializer: '1',                           fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },
     44    { Type: 'ivec2',    initializer: 'ivec2(0, 1)',                 fragColor: 'vec4(newvar.a, 0.0, 1.0)' },
     45    { Type: 'ivec3',    initializer: 'ivec3(0, 1, 0)',              fragColor: 'vec4(newvar.a, 1.0)' },
     46    { Type: 'ivec4',    initializer: 'ivec4(0, 1, 0, 1)',           fragColor: 'vec4(newvar.a)' },
     47    { Type: 'bool',     initializer: 'true',                        fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },
     48    { Type: 'bvec2',    initializer: 'bvec2(false, true)',          fragColor: 'vec4(newvar.a, 0.0, 1.0)' },
     49    { Type: 'bvec3',    initializer: 'bvec3(false, true, false)',   fragColor: 'vec4(newvar.a, 1.0)' },
     50    { Type: 'bvec4',    initializer: 'bvec4(false,true,false,true)',fragColor: 'vec4(newvar.a)' },
     51 ];
     52 typeInfo.forEach(function (outerType) {
     53    typeInfo.forEach(function (innerType) {
     54        var replaceParams = {
     55            outer_type: outerType.Type,
     56            inner_type: innerType.Type,
     57            // use the initializer and fragColor for the inner type. Its definition should override the variable name in the outerscope.
     58            initializer: innerType.initializer,
     59            fragColor: innerType.fragColor
     60        };
     61        tests.push({
     62            fShaderSource: wtu.replaceParams(wtu.getScript('fragmentShader'), replaceParams),
     63            passMsg: 'Outer struct type: ' + outerType.Type + ' inner struct type: ' + innerType.Type,
     64            fShaderSuccess: true,
     65            linkSuccess: true,
     66            render: true
     67        });
     68    })
     69 })
     70 GLSLConformanceTester.runTests(tests);
     71 var successfullyParsed = true;
     72 </script>
     73 </body>
     74 </html>