tor-browser

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

gl-pixelstorei.html (2866B)


      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 pixelStorei Test</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="50" height="50"></canvas>
     18 <canvas id="2d00" width="50" height="50"></canvas>
     19 <canvas id="2d01" width="50" height="50"></canvas>
     20 <canvas id="2d02" width="50" height="50"></canvas>
     21 <canvas id="2d03" width="50" height="50"></canvas>
     22 <div id="description"></div>
     23 <div id="console"></div>
     24 <script id="vshader" type="x-shader/x-vertex">
     25 attribute vec4 vPosition;
     26 void main() {
     27  gl_Position = vPosition;
     28 }
     29 </script>
     30 
     31 <script id="fshader" type="x-shader/x-fragment">
     32 void main() {
     33  gl_FragColor = vec4(1.0,0.0,0.0,1.0);
     34 }
     35 </script>
     36 
     37 <script>
     38 "use strict";
     39 function init() {
     40  description("This test checks that drawImage and readPixels are not effected by gl.Pixelstorei(gl.PACK_ALIGNMENT) and visa versa");
     41 
     42  debug("There should be 5 red triangles on 5 black squares above");
     43  debug("");
     44 
     45  var wtu = WebGLTestUtils;
     46  var canvas3d = document.getElementById("example");
     47  var gl = wtu.create3DContext("example");
     48  var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
     49 
     50  var vertexObject = gl.createBuffer();
     51  gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
     52  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
     53  gl.enableVertexAttribArray(0);
     54  gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
     55 
     56  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     57  gl.drawArrays(gl.TRIANGLES, 0, 3);
     58 
     59  function checkData(ctx, name) {
     60    // Test several locations
     61    // First line should be all black
     62    wtu.checkCanvasRect(ctx, 0, 0, 50, 1, [0, 0, 0, 0]);
     63 
     64    // Line 25 should be red for at least 6 red pixels starting 22 pixels in
     65    wtu.checkCanvasRect(ctx, 22, 25, 6, 1, [255, 0, 0, 255]);
     66 
     67    // Last line should be all black
     68    wtu.checkCanvasRect(ctx, 0, 49, 50, 1, [0, 0, 0, 0]);
     69  }
     70 
     71  var ctx2d;
     72 
     73  function checkColors() {
     74    checkData(gl, "3d context");
     75    checkData(ctx2d, "2d context");
     76  }
     77 
     78  var table = [1, 2, 4, 8];
     79  for (var ii = 0; ii < table.length; ++ii) {
     80    gl.pixelStorei(gl.PACK_ALIGNMENT, table[ii]);
     81    ctx2d = document.getElementById("2d0" + ii).getContext("2d");
     82    ctx2d.globalCompositeOperation = 'copy';
     83    ctx2d.drawImage(canvas3d, 0, 0);
     84    checkColors();
     85    assertMsg(gl.getParameter(gl.PACK_ALIGNMENT) == table[ii],
     86        "PACK_ALIGNMENT is " + table[ii]);
     87  }
     88 }
     89 
     90 init();
     91 var successfullyParsed = true;
     92 </script>
     93 <script src="../../../js/js-test-post.js"></script>
     94 
     95 </body>
     96 </html>