tor-browser

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

texture-transparent-pixels-initialized.html (2569B)


      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 <script src="../../../js/js-test-pre.js"></script>
     12 <script src="../../../js/webgl-test-utils.js"></script>
     13 <script>
     14 "use strict";
     15 var wtu = WebGLTestUtils;
     16 var gl = null;
     17 var texture;
     18 var textureLoc = null;
     19 var successfullyParsed = false;
     20 
     21 function init()
     22 {
     23    description('Tests there is no garbage in transparent regions of images uploaded as textures');
     24 
     25    wtu = WebGLTestUtils;
     26    gl = wtu.create3DContext("example");
     27    var program = wtu.setupTexturedQuad(gl);
     28    gl.clearColor(0.5,0.5,0.5,1);
     29    gl.clearDepth(1);
     30 
     31    textureLoc = gl.getUniformLocation(program, "tex");
     32 
     33    // The input texture has 8 characters; take the leftmost one
     34    var coeff = 1.0 / 8.0;
     35    var texCoords = new Float32Array([
     36        coeff, 1.0,
     37        0.0, 1.0,
     38        0.0, 0.0,
     39        coeff, 1.0,
     40        0.0, 0.0,
     41        coeff, 0.0]);
     42 
     43    var vbo = gl.createBuffer();
     44    gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
     45    gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW);
     46    gl.enableVertexAttribArray(1);
     47    gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
     48 
     49    texture = wtu.loadTexture(gl, "../../../resources/bug-32888-texture.png", runTest);
     50 }
     51 
     52 // These two declarations need to be global for "shouldBe" to see them
     53 var buf = null;
     54 var idx = 0;
     55 
     56 function runTest()
     57 {
     58    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     59    gl.enable(gl.BLEND);
     60    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
     61    // Bind the texture to texture unit 0
     62    gl.bindTexture(gl.TEXTURE_2D, texture);
     63    // Point the uniform sampler to texture unit 0
     64    gl.uniform1i(textureLoc, 0);
     65    // Draw the triangles
     66    wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);
     67 
     68    // Spot check a couple of 2x2 regions in the upper and lower left
     69    // corners; they should be the rgb values in the texture.
     70    var color = [0, 0, 0];
     71    debug("Checking lower left corner");
     72    wtu.checkCanvasRect(gl, 1, gl.canvas.height - 3, 2, 2, color,
     73                        "shouldBe " + color);
     74    debug("Checking upper left corner");
     75    wtu.checkCanvasRect(gl, 1, 1, 2, 2, color,
     76                        "shouldBe " + color);
     77 
     78    finishTest();
     79 }
     80 </script>
     81 </head>
     82 <body onload="init()">
     83 <canvas id="example" width="32" height="32"></canvas>
     84 <div id="description"></div>
     85 <div id="console"></div>
     86 </body>
     87 </html>