tor-browser

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

tex-sub-image-2d.html (3118B)


      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 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     12 <script src="../../../js/js-test-pre.js"></script>
     13 <script src="../../../js/webgl-test-utils.js"></script>
     14 <script id="fshader" type="x-shader/x-fragment">
     15 precision mediump float;
     16 
     17 uniform sampler2D tex;
     18 varying vec2 texCoord;
     19 
     20 void main()
     21 {
     22    float intensity = texture2D(tex, texCoord).a;
     23    gl_FragColor = vec4(intensity, intensity, intensity, 1.0);
     24 }
     25 </script>
     26 
     27 </head>
     28 <body>
     29 <canvas id="example" width="256" height="1"></canvas>
     30 <div id="description"></div>
     31 <div id="console"></div>
     32 <script>
     33 "use strict";
     34 description('Tests texSubImage2D upload path from Uint8Array');
     35 
     36 var wtu = WebGLTestUtils;
     37 var canvas = document.getElementById("example");
     38 var gl = wtu.create3DContext(canvas);
     39 gl.disable(gl.DITHER);
     40 var program = wtu.setupProgram(
     41    gl,
     42    [wtu.simpleTextureVertexShader, "fshader"],
     43    ['vPosition', 'texCoord0']);
     44 wtu.setupUnitQuad(gl);
     45 var textureWidth = 256;
     46 var textureHeight = 1;
     47 
     48 var textureLoc = gl.getUniformLocation(program, "tex");
     49 
     50 var texture = gl.createTexture();
     51 gl.bindTexture(gl.TEXTURE_2D, texture);
     52 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     53 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
     54 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     55 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     56 // Allocate the texture object
     57 gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, textureWidth, textureHeight, 0, gl.ALPHA, gl.UNSIGNED_BYTE, null);
     58 // Prepare the image data
     59 var array = new Uint8Array(textureWidth);
     60 for (var i = 0; i < textureWidth; i++)
     61    array[i] = i;
     62 // Fill the texture object with data -- this is actually the code path being tested
     63 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, gl.ALPHA, gl.UNSIGNED_BYTE, array);
     64 
     65 // Clear and set up
     66 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     67 gl.bindTexture(gl.TEXTURE_2D, texture);
     68 gl.useProgram(program);
     69 gl.uniform1i(textureLoc, 0);
     70 // Draw the texture to the frame buffer
     71 gl.drawArrays(gl.TRIANGLES, 0, 6);
     72 
     73 // Read back the frame buffer
     74 var buf = new Uint8Array(textureWidth * textureHeight * 4);
     75 gl.readPixels(0, 0, textureWidth, textureHeight, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     76 
     77 // Verify the frame buffer's contents
     78 var passed = true;
     79 for (var i = 0; i < textureWidth; i++) {
     80    var val = i;
     81    if (buf[4 * i + 0] != val ||
     82        buf[4 * i + 1] != val ||
     83        buf[4 * i + 2] != val) {
     84        testFailed("pixel at (" + i + ", 0) was (" +
     85                   buf[4 * i + 0] + ", " +
     86                   buf[4 * i + 1] + ", " +
     87                   buf[4 * i + 2] + "), should be (" +
     88                   val + ", " + val + ", " + val + ")");
     89        passed = false;
     90        break;
     91    }
     92 }
     93 
     94 if (passed)
     95    testPassed("");
     96 
     97 var successfullyParsed = true;
     98 </script>
     99 <script src="../../../js/js-test-post.js"></script>
    100 </body>
    101 </html>