tor-browser

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

mipmap-fbo.html (3959B)


      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>Test if mipmap incomplete textures can be used as FBO attachments, and mipmap generation on a texture filled by an FBO works correctly</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="24" height="24"></canvas>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <script>
     21 "use strict";
     22 
     23 var wtu = WebGLTestUtils;
     24 description();
     25 
     26 var gl = wtu.create3DContext("example");
     27 
     28 function testMipmapGeneration() {
     29    // setup render target texture //
     30    var texture = gl.createTexture();
     31    gl.bindTexture(gl.TEXTURE_2D, texture);
     32    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
     33    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
     34    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 32, 32, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     35    gl.bindTexture(gl.TEXTURE_2D, null);
     36 
     37    // setup framebuffer //
     38    var fbo = gl.createFramebuffer();
     39    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
     40    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
     41    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     42 
     43    // fill the framebuffer //
     44    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
     45    gl.viewport(0, 0, 32, 32);
     46    gl.clearColor(1, 0, 1, 1);
     47    gl.clear(gl.COLOR_BUFFER_BIT);
     48    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     49 
     50    // generate mipmap //
     51    gl.bindTexture(gl.TEXTURE_2D, texture);
     52    gl.generateMipmap(gl.TEXTURE_2D);
     53 
     54    var program = wtu.setupTexturedQuad(gl);
     55    gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
     56    gl.drawArrays(gl.TRIANGLES, 0, 6);
     57 
     58    // readback //
     59    wtu.checkCanvas(gl, [255, 0, 255, 255]);
     60 }
     61 
     62 var testCubemapFaceWithIncompleteMipmapInFBO = function() {
     63    // Create a cube map texture that's not mipmap complete.
     64    var tex2 = gl.createTexture();
     65    gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex2);
     66    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
     67    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
     68 
     69    var cube_map_faces = [
     70        gl.TEXTURE_CUBE_MAP_POSITIVE_X,
     71        gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
     72        gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
     73        gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
     74        gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
     75        gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
     76    ];
     77    for (var i = 0; i < cube_map_faces.length; ++i) {
     78        gl.texImage2D(cube_map_faces[i], 0, gl.RGBA, 32, 32, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     79    }
     80 
     81    var fb2 = gl.createFramebuffer();
     82    gl.bindFramebuffer(gl.FRAMEBUFFER, fb2);
     83    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X, tex2, 0);
     84    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors after attaching cube map face.");
     85    shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
     86    gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
     87 
     88    var colorProgram = wtu.setupColorQuad(gl);
     89    var colorLocation = gl.getUniformLocation(colorProgram, 'u_color');
     90    gl.uniform4f(colorLocation, 0.0, 1.0, 0.0, 1.0);
     91    gl.viewport(0, 0, 32, 32);
     92    wtu.drawUnitQuad(gl);
     93    // Read what's in the framebuffer - note that we need to use checkCanvasRect since the
     94    // FB dimensions are different from canvas dimensions.
     95    wtu.checkCanvasRect(gl, 0, 0, 32, 32, [0, 255, 0, 255],
     96                        "Framebuffer with a non-mipmap complete cube map attachment should be green");
     97 }
     98 
     99 testMipmapGeneration();
    100 debug("");
    101 testCubemapFaceWithIncompleteMipmapInFBO();
    102 
    103 var successfullyParsed = true;
    104 </script>
    105 <script src="../../../js/js-test-post.js"></script>
    106 
    107 </body>
    108 </html>