tor-browser

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

copyTexImage2D.html (3453B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <!--
      6 Copyright (c) 2019 The Khronos Group Inc.
      7 Use of this source code is governed by an MIT-style license that can be
      8 found in the LICENSE.txt file.
      9 -->
     10 <link rel="stylesheet" type="text/css" href="../unit.css" />
     11 <script type="application/javascript" src="../unit.js"></script>
     12 <script type="application/javascript" src="../util.js"></script>
     13 <script type="application/javascript">
     14 
     15 Tests.startUnit = function () {
     16  var canvas = document.getElementById('gl');
     17  var gl = wrapGLContext(getGLContext(canvas));
     18  return [gl];
     19 }
     20 
     21 Tests.setup = function(gl) {
     22  var tex = gl.createTexture();
     23  gl.bindTexture(gl.TEXTURE_2D, tex);
     24  var texCubeMap = gl.createTexture();
     25  gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap);
     26  return [gl]
     27 }
     28 
     29 Tests.teardown = function(gl,tex, texCubeMap) {
     30  gl.bindTexture(gl.TEXTURE_2D, null);
     31  gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
     32  gl.deleteTexture(tex);
     33  gl.deleteTexture(texCubeMap);
     34 }
     35 
     36 Tests.testTexImage2D = function(gl) {
     37  gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0,0,1,1,0);
     38  gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0,0,2,1,0);
     39  gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0,0,1,2,0);
     40  gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0,0,16,16,0);
     41  gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 15,15,1,1,0);
     42  var valid_targets = [
     43    gl.TEXTURE_2D,
     44    gl.TEXTURE_CUBE_MAP_POSITIVE_X,
     45    gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
     46    gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
     47    gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
     48    gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
     49    gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
     50  ];
     51  valid_targets.forEach(function(t) {
     52    assertOk(function(){gl.copyTexImage2D(t, 0, gl.RGBA, 0,0,1,1,0);});
     53  });
     54 }
     55 Tests.testRoundtrip = function(gl) {
     56    var sh = new Filter(gl, 'identity-flip-vert', 'identity-frag');
     57    gl.clearColor(1.0, 0.0, 0.0, 1.0);
     58    gl.clear(gl.COLOR_BUFFER_BIT);
     59    var buf = new Uint8Array(4);
     60    gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, buf);
     61    assertEquals([255,0,0,255], [buf[0], buf[1], buf[2], buf[3]]);
     62    // red texture
     63    gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0,0,16,16,0);
     64    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     65    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
     66    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
     67    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
     68    gl.clearColor(0.0, 0.0, 1.0, 1.0);
     69    gl.clear(gl.COLOR_BUFFER_BIT);
     70    // blue framebuffer
     71    gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, buf);
     72    assertEquals([0,0,255,255], [buf[0], buf[1], buf[2], buf[3]]);
     73    sh.apply(); // paint it with texture
     74    gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, buf);
     75    assertEquals([255,0,0,255], [buf[0], buf[1], buf[2], buf[3]]);
     76    sh.destroy();
     77 }
     78 
     79 Tests.endUnit = function(gl) {
     80 }
     81 
     82 </script>
     83 <script id="identity-flip-vert" type="x-shader/x-vertex">
     84 attribute vec3 Vertex;
     85 attribute vec2 Tex;
     86 
     87 varying vec4 texCoord0;
     88 void main()
     89 {
     90    texCoord0 = vec4(Tex.s, 1.0-Tex.t, 0.0, 0.0);
     91    gl_Position = vec4(Vertex, 1.0);
     92 }
     93 </script>
     94 <script id="identity-frag" type="x-shader/x-fragment">
     95 precision mediump float;
     96 
     97 uniform sampler2D Texture;
     98 
     99 varying vec4 texCoord0;
    100 void main()
    101 {
    102    vec4 c = texture2D(Texture, texCoord0.st);
    103    gl_FragColor = c;
    104 }
    105 </script>
    106 <style>canvas{ position:absolute; }</style>
    107 </head><body>
    108 <canvas id="gl" width="16" height="16"></canvas>
    109 </body></html>