tor-browser

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

nested-loops-with-break-and-continue.html (2303B)


      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>Using nested loops with break and/or continue statements in a fragment shader should work</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 <canvas id="canvas" width="256" height="256"> </canvas>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <script id="vshader" type="x-shader/x-vertex">
     21 attribute vec3 aPosition;
     22 
     23 void main() {
     24    gl_Position = vec4(aPosition, 1);
     25 }
     26 </script>
     27 <script id="fshader" type="x-shader/x-fragment">
     28 precision mediump float;
     29 uniform int uCount;
     30 
     31 void main() {
     32    int a = 0;
     33    for (int i = 0; i < 10; ++i) {
     34        if (i >= uCount) { break; }
     35        for (int j = 0; j < 10; ++j) {
     36            if (j >= uCount) { continue; }
     37            a += 1;
     38        }
     39        for (int j = 0; j < 10; ++j) {
     40            if (j >= uCount) { break; }
     41            a += 1;
     42        }
     43        for (int j = 0; j < 10; ++j) {
     44            if (j >= uCount) { continue; }
     45            a += 1;
     46        }
     47        for (int j = 0; j < 10; ++j) {
     48            if (j >= uCount) { break; }
     49            a += 1;
     50        }
     51        for (int j = 0; j < 10; ++j) {
     52            if (j >= uCount) { continue; }
     53            a += 1;
     54        }
     55    }
     56    float b = (float(a) / 125.0) * (64.0 / 255.0);
     57    gl_FragColor = vec4(b, 1.0 - b, 0.0, 1.0);
     58 }
     59 </script>
     60 <script type="application/javascript">
     61 "use strict";
     62 description("Multiple loops using break and continue statements should work.");
     63 debug("");
     64 var wtu = WebGLTestUtils;
     65 function test() {
     66    var gl = wtu.create3DContext("canvas");
     67    if (!gl) {
     68        testFailed("context does not exist");
     69        return;
     70    }
     71    wtu.setupUnitQuad(gl);
     72    var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["aPosition"], undefined, true);
     73    var uniformLoc = gl.getUniformLocation(program, 'uCount');
     74    gl.uniform1i(uniformLoc, 5);
     75    wtu.drawUnitQuad(gl);
     76    wtu.checkCanvas(gl, [64, 191, 0, 255], "should be 64,191,0,255");
     77 };
     78 
     79 test();
     80 finishTest();
     81 </script>
     82 </body>
     83 </html>