tor-browser

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

feedback-loop.html (4192B)


      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 Rendering Feedback Loop</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="example" width="1" height="1" style="width: 40px; height: 40px;"></canvas>
     18    <div id="description"></div>
     19    <div id="console"></div>
     20 
     21    <script id="vs" type="text/something-not-javascript">
     22    attribute vec4 a_position;
     23    attribute vec2 a_texCoord;
     24    varying vec2 v_texCoord;
     25    void main() {
     26        gl_Position = a_position;
     27        v_texCoord = a_texCoord;
     28    }
     29    </script>
     30    <script id="fs" type="text/something-not-javascript">
     31    precision mediump float;
     32    varying vec2 v_texCoord;
     33    uniform sampler2D u_texture;
     34    void main() {
     35        // Shader swizzles color channels so we can tell if the draw succeeded.
     36        gl_FragColor = texture2D(u_texture, v_texCoord).gbra;
     37    }
     38    </script>
     39    <script>
     40    "use strict";
     41    description("Checks that rendering feedback loops fail correctly.");
     42    var wtu = WebGLTestUtils;
     43    var gl = wtu.create3DContext("example");
     44 
     45    var texture = gl.createTexture();
     46    gl.bindTexture(gl.TEXTURE_2D, texture);
     47    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
     48                  new Uint8Array([255, 0, 0, 255]));
     49    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     50    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     51    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     52    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
     53 
     54    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture");
     55 
     56    var framebuffer = gl.createFramebuffer();
     57    gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     58    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
     59 
     60    assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE,
     61        "framebuffer should be FRAMEBUFFER_COMPLETE.");
     62 
     63    var program = wtu.setupProgram(gl, ["vs", "fs"], ["a_position", "a_texCoord"]);
     64    gl.uniform1i(gl.getUniformLocation(program, "u_texture"), 0);
     65    gl.disable(gl.BLEND);
     66    gl.disable(gl.DEPTH_TEST);
     67    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initWebGL");
     68 
     69    // Drawing with a texture that is also bound to the current framebuffer should fail
     70    var bufferObjects = wtu.setupUnitQuad(gl, 0, 1);
     71    gl.bindTexture(gl.TEXTURE_2D, texture);
     72    wtu.drawUnitQuad(gl);
     73    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "after draw with invalid feedback loop");
     74 
     75    // Ensure that the texture contents did not change after the previous render
     76    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     77    wtu.clearAndDrawUnitQuad(gl);
     78    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
     79    wtu.checkCanvas(gl, [0, 0, 255, 255], "Should be blue.");
     80 
     81    // Drawing when texture is bound to an inactive uniform should succeed
     82    var texture2 = gl.createTexture();
     83    gl.bindTexture(gl.TEXTURE_2D, texture2);
     84    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
     85                  new Uint8Array([0, 255, 0, 255]));
     86    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     87    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     88    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     89    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
     90 
     91    gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     92    gl.activeTexture(gl.TEXTURE1);
     93    gl.bindTexture(gl.TEXTURE_2D, texture);
     94    wtu.drawUnitQuad(gl);
     95    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after draw where framebuffer texture is bound to inactive texture unit");
     96    wtu.checkCanvas(gl, [255, 0, 0, 255], "Should be red.");
     97 
     98    var successfullyParsed = true;
     99    </script>
    100 
    101    <script src="../../js/js-test-post.js"></script>
    102 
    103  </body>
    104 </html>