tor-browser

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

framebuffer-texture-layer.html (8267B)


      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 FramebufferTextureLayer 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 <div id="description"></div>
     18 <div id="console"></div>
     19 <canvas id="canvas" width="2" height="2"> </canvas>
     20 
     21 <script>
     22 "use strict";
     23 var wtu = WebGLTestUtils;
     24 var gl;
     25 var canvas = document.getElementById("canvas");
     26 
     27 function numLevelsFromSize(size) {
     28    var levels = 0;
     29    while ((size >> levels) > 0) {
     30        ++levels;
     31    }
     32    return levels;
     33 }
     34 
     35 function checkFramebuffer(expected) {
     36    var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
     37    if (expected.indexOf(actual) < 0) {
     38        var msg = "checkFramebufferStatus expects [";
     39        for (var index = 0; index < expected.length; ++index) {
     40            msg += wtu.glEnumToString(gl, expected[index]);
     41            if (index + 1 < expected.length)
     42                msg += ", ";
     43        }
     44        msg += "], was " + wtu.glEnumToString(gl, actual);
     45        testFailed(msg);
     46    } else {
     47        var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) +
     48                  " as expected";
     49        testPassed(msg);
     50    }
     51 }
     52 
     53 function testFramebufferTextureLayer() {
     54    debug("");
     55    debug("Checking FramebufferTextureLayer stuff.");
     56 
     57    var tex3d = gl.createTexture();
     58    var fb = gl.createFramebuffer();
     59    gl.bindTexture(gl.TEXTURE_3D, tex3d);
     60    gl.texImage3D(gl.TEXTURE_3D,
     61                  0,                                          // level
     62                  gl.RGBA,                                    // internalFormat
     63                  1,                                          // width
     64                  1,                                          // height
     65                  1,                                          // depth
     66                  0,                                          // border
     67                  gl.RGBA,                                    // format
     68                  gl.UNSIGNED_BYTE,                           // type
     69                  new Uint8Array([0xff, 0x00, 0x00, 0x00]));  // data
     70    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, 0);
     71    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
     72        "attaching a texture to default framebuffer should generate INVALID_OPERATION.");
     73    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
     74    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, 0);
     75    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
     76        "attaching a texture to a framebuffer should succeed.");
     77    checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
     78    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, null, 0, 0);
     79    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
     80        "detaching a texture from a framebuffer should succeed.");
     81 
     82    var maxTexSize = gl.getParameter(gl.MAX_3D_TEXTURE_SIZE);
     83    var maxLevels = numLevelsFromSize(maxTexSize);
     84    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, maxLevels - 1, 0);
     85    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
     86        "calling framebufferTextureLayer with an appropriate mipmap level should succeed.");
     87    checkFramebuffer([gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT]);
     88    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, maxLevels, 0);
     89    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
     90        "calling framebufferTextureLayer with a mipmap level out of range should generate INVALID_VALUE.");
     91 
     92    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, -1);
     93    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
     94        "calling framebufferTextureLayer with a negative texture layer should generate INVALID_VALUE.");
     95    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, maxTexSize);
     96    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE,
     97        "calling framebufferTextureLayer with a texture layer out of range should generate INVALID_VALUE.");
     98 
     99    var tex2d = gl.createTexture();
    100    gl.bindTexture(gl.TEXTURE_2D, tex2d);
    101    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex2d, 0, 0);
    102    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
    103        "attaching a 2d texture to a framebuffer should generate INVALID_OPERATION.");
    104 
    105    var texDepthStencil = gl.createTexture();
    106    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texDepthStencil);
    107    var fbDepthStencil = gl.createFramebuffer();
    108    gl.bindFramebuffer(gl.FRAMEBUFFER, fbDepthStencil);
    109    gl.texImage3D(gl.TEXTURE_2D_ARRAY,
    110                  0,                                          // level
    111                  gl.DEPTH24_STENCIL8,                        // internalFormat
    112                  1,                                          // width
    113                  1,                                          // height
    114                  1,                                          // depth
    115                  0,                                          // border
    116                  gl.DEPTH_STENCIL,                           // format
    117                  gl.UNSIGNED_INT_24_8,                       // type
    118                  new Uint32Array([0]));                      // data
    119    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, texDepthStencil, 0, 0);
    120    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
    121        "attaching a depth_stencil texture to a framebuffer should succeed.");
    122    checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
    123 
    124    var texDepthStencil = gl.createTexture();
    125    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texDepthStencil);
    126 
    127    var texDepthStencilMany = gl.createTexture();
    128    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texDepthStencilMany);
    129    var fbDepthStencilMany = gl.createFramebuffer();
    130    gl.bindFramebuffer(gl.FRAMEBUFFER, fbDepthStencilMany);
    131    gl.texImage3D(gl.TEXTURE_2D_ARRAY,
    132                  0,                                          // level
    133                  gl.DEPTH24_STENCIL8,                        // internalFormat
    134                  1,                                          // width
    135                  1,                                          // height
    136                  2,                                          // depth
    137                  0,                                          // border
    138                  gl.DEPTH_STENCIL,                           // format
    139                  gl.UNSIGNED_INT_24_8,                       // type
    140                  new Uint32Array([0, 1]));                      // data
    141 
    142    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, texDepthStencilMany, 0, 0);
    143    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, texDepthStencilMany, 0, 0);
    144    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
    145        "attaching a depth_stencil 2d array texture level 0 to a framebuffer should succeed.");
    146    checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
    147    shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", texDepthStencilMany);
    148    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, texDepthStencilMany, 0, 1);
    149    wtu.glErrorShouldBe(gl, gl.NO_ERROR,
    150        "attaching a 2d array texture level 0 to depth and layer 1 to stencil attachment of a framebuffer should succeed.");
    151    // "Depth and stencil attachments, if present, are the same image." If not, then "FRAMEBUFFER_UNSUPPORTED".
    152    checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
    153    shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", texDepthStencilMany);
    154 
    155    // Clean up
    156    gl.deleteTexture(tex3d);
    157    gl.deleteTexture(texDepthStencil);
    158    gl.deleteTexture(tex2d);
    159    gl.deleteFramebuffer(fb);
    160    gl.deleteFramebuffer(fbDepthStencil);
    161 }
    162 
    163 description("This tests framebufferTextureLayer.");
    164 
    165 shouldBeNonNull("gl = wtu.create3DContext(undefined, undefined, 2)");
    166 
    167 testFramebufferTextureLayer();
    168 
    169 debug("");
    170 var successfullyParsed = true;
    171 </script>
    172 <script src="../../js/js-test-post.js"></script>
    173 
    174 </body>
    175 </html>