tor-browser

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

glsl-function-texture2dproj.html (3429B)


      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 texture2D GLSL conformance 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="example" width="32" height="32"></canvas>
     19 <div id="description"></div>
     20 <div id="console"></div>
     21 <script id="vshader0" type="x-shader/x-vertex">
     22 attribute vec4 vPosition;
     23 attribute vec2 texCoord0;
     24 varying vec2 texCoord;
     25 void main() {
     26    gl_Position = vPosition;
     27    texCoord = texCoord0;
     28 }
     29 </script>
     30 <script id="fshader0" type="x-shader/x-fragment">
     31 precision mediump float;
     32 uniform sampler2D tex;
     33 uniform float divisor;
     34 varying vec2 texCoord;
     35 void main() {
     36    gl_FragData[0] = texture2DProj(tex, vec3(texCoord, divisor));
     37 }
     38 </script>
     39 <script id="vshader1" type="x-shader/x-vertex">
     40 attribute vec4 vPosition;
     41 attribute vec2 texCoord0;
     42 varying vec2 texCoord;
     43 void main() {
     44    gl_Position = vPosition;
     45    texCoord = texCoord0;
     46 }
     47 </script>
     48 <script id="fshader1" type="x-shader/x-fragment">
     49 precision mediump float;
     50 uniform sampler2D tex;
     51 uniform float divisor;
     52 varying vec2 texCoord;
     53 void main() {
     54    gl_FragData[0] = texture2DProj(tex, vec4(texCoord, 123.0, divisor));
     55 }
     56 </script>
     57 <script>
     58 "use strict";
     59 description("tests GLSL texture2DProj function with");
     60 
     61 var wtu = WebGLTestUtils;
     62 var gl = wtu.create3DContext("example", {antialias: false});
     63 
     64 wtu.setupUnitQuad(gl, 0, 1);
     65 var tex = gl.createTexture();
     66 gl.bindTexture(gl.TEXTURE_2D, tex);
     67 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     68 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     69 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
     70 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
     71 
     72 var c = document.createElement("canvas");
     73 c.width = 16;
     74 c.height = 16;
     75 var ctx = c.getContext("2d");
     76 ctx.fillStyle = "rgb(0,255,0)";
     77 ctx.fillRect(0, 0, 16, 16);
     78 ctx.fillStyle = "rgb(0,0,255)";
     79 ctx.fillRect(0, 0, 8, 8);
     80 ctx.fillRect(8, 8, 8, 8);
     81 
     82 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
     83 
     84 for (var ss = 0; ss < 2; ++ss) {
     85  debug("");
     86  debug(ss ? "testing vec4 version" : "testing vec3 version");
     87  var program = wtu.setupProgram(
     88      gl, ['vshader' + ss, 'fshader' + ss],
     89      ['vPosition', 'texCoord0'], [0, 1]);
     90  gl.useProgram(program);
     91  var loc = gl.getUniformLocation(program, "divisor");
     92 
     93  for (var ii = 0; ii < 3; ++ii) {
     94    var denominator = Math.pow(2, ii);
     95    gl.uniform1f(loc, 1 / denominator);
     96    wtu.clearAndDrawUnitQuad(gl);
     97    var size = 16 / denominator;
     98    for (var yy = 0; yy < 32; yy += size) {
     99      for (var xx = 0; xx < 32; xx += size) {
    100        var odd = (xx / size + yy / size) % 2;
    101        var color = odd ? [0, 255, 0, 255] : [0, 0, 255, 255];
    102        var msg = "" + xx + ", " + yy + ", " + size + ", " + size + " should be " + (odd ? "green" : "blue");
    103        wtu.checkCanvasRect(gl, xx, yy, size, size, color, msg);
    104      }
    105    }
    106  }
    107 }
    108 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
    109 
    110 var successfullyParsed = true;
    111 
    112 </script>
    113 <script src="../../../js/js-test-post.js"></script>
    114 
    115 </body>
    116 </html>