tor-browser

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

texel-fetch-undefined.html (2598B)


      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 texel fetch 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 <canvas id="c" width="256" height="256"></canvas>
     19 <div id="description"></div>
     20 <div id="console"></div>
     21 <script id="vertex-shader" type="x-shader/x-vertex">#version 300 es
     22  precision highp float;
     23  in vec4 aPosition;
     24 
     25  void main() {
     26    gl_Position = aPosition;
     27  }
     28 </script>
     29 <script id="fragment-shader" type="x-shader/x-fragment">#version 300 es
     30  precision mediump float;
     31  uniform sampler2D uSampler;
     32  uniform ivec2 uTestPos;
     33 
     34  out vec4 my_FragColor;
     35  void main() {
     36    my_FragColor = texelFetch(uSampler, uTestPos, 0);
     37  }
     38 </script>
     39 <script>
     40 "use strict";
     41 description("This test makes sure that texelFetch works to the WebGL 2.0 spec when retrieving a texel outside of the texture's size.");
     42 
     43 var wtu = WebGLTestUtils;
     44 var textureSize = 24;
     45 
     46 var gl = wtu.create3DContext('c', undefined, 2);
     47 
     48 function testFetchAt(x, y, expectedColor) {
     49  debug("");
     50  debug("Test fetching a texel of the texture at x = " + x +", y = " + y);
     51  gl.uniform2i(uTestPos, x, y);
     52  wtu.clearAndDrawUnitQuad(gl);
     53  wtu.checkCanvas(gl, expectedColor);
     54 }
     55 
     56 var program = wtu.setupProgram(gl, ["vertex-shader", "fragment-shader"]);
     57 var aPosition = gl.getAttribLocation(program, "aPosition");
     58 var uTestPos = gl.getUniformLocation(program, "uTestPos");
     59 
     60 debug('Creating a texture with size ' + textureSize + '*' + textureSize);
     61 var tex = gl.createTexture();
     62 gl.bindTexture(gl.TEXTURE_2D, tex);
     63 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     64 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
     65 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     66 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     67 wtu.fillTexture(gl, tex, textureSize, textureSize, [0, 255, 0, 255]);
     68 
     69 wtu.setupUnitQuad(gl, aPosition);
     70 
     71 testFetchAt(0, 0, [0, 255, 0, 255]);
     72 testFetchAt(textureSize - 1, textureSize - 1, [0, 255, 0, 255]);
     73 testFetchAt(textureSize, 0, [0, 0, 0, 0]);
     74 testFetchAt(0, textureSize, [0, 0, 0, 0]);
     75 testFetchAt(-1, 0, [0, 0, 0, 0]);
     76 testFetchAt(0, -1, [0, 0, 0, 0]);
     77 testFetchAt(-1, 1, [0, 0, 0, 0]);
     78 
     79 finishTest();
     80 </script>
     81 </body>
     82 </html>