tor-browser

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

oes-fbo-render-mipmap.html (3136B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>WebGL OES_fbo_render_mipmap Conformance Tests</title>
      6 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
      7 <script src="../../js/js-test-pre.js"></script>
      8 <script src="../../js/webgl-test-utils.js"></script>
      9 </head>
     10 <body>
     11 <canvas id="canvas" width="128" height="128"></canvas>
     12 <div id="description"></div>
     13 <div id="console"></div>
     14 <script>
     15 "use strict";
     16 description("This test verifies the functionality of the OES_fbo_render_mipmap extension, if it is available.");
     17 
     18 var wtu = WebGLTestUtils;
     19 var canvas = document.getElementById("canvas");
     20 var gl = wtu.create3DContext(canvas);
     21 var ext = null;
     22 
     23 (function(){
     24 
     25    const oesFboRenderMipmap = gl.getExtension("OES_fbo_render_mipmap");
     26    if (!oesFboRenderMipmap) {
     27        testPassed("OES_fbo_render_mipmap is allowed to be missing.");
     28        return;
     29    }
     30 
     31    let texture = gl.createTexture();
     32    gl.bindTexture(gl.TEXTURE_2D, texture);
     33    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     34    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
     35 
     36    let colors = [
     37        [255, 0, 0, 255],
     38        [255, 127, 0, 255],
     39        [255, 255, 0, 255],
     40        [0, 255, 0, 255],
     41        [0, 255, 255, 255],
     42        [0, 127, 255, 255],
     43        [0, 0, 255, 255],
     44        [255, 0, 255, 255],
     45    ];
     46 
     47    let fbos = [];
     48    let maxLevel = 7;
     49    for (let level = 0; level <= maxLevel; level++) {
     50        let size = Math.pow(2, maxLevel - level);
     51        gl.texImage2D(gl.TEXTURE_2D, level, gl.RGBA, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     52        let fbo = gl.createFramebuffer();
     53        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
     54        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, level);
     55        fbos.push(fbo);
     56 
     57        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Any level of a texture can be attached to a framebuffer object.");
     58    }
     59 
     60    for (let level = 0; level <= maxLevel; level++) {
     61        gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[level]);
     62        shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
     63        gl.clearColor(colors[level][0] / 255, colors[level][1] / 255, colors[level][2] / 255, colors[level][3] / 255);
     64        gl.clear(gl.COLOR_BUFFER_BIT);
     65    }
     66 
     67    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     68 
     69    let program = wtu.setupTexturedQuad(gl);
     70 
     71    for (let level = 0; level <= maxLevel; level++) {
     72        let size = Math.pow(2, maxLevel - level);
     73        // We use differrent viewport sizes to affect which miplevel is fetched from the texture.
     74        gl.viewport(0, 0, size, size);
     75        gl.drawArrays(gl.TRIANGLES, 0, 6);
     76        wtu.checkCanvasRect(gl, 0, 0, 1, 1, colors[level]);
     77    }
     78 
     79 })();
     80 
     81 debug("");
     82 var successfullyParsed = true;
     83 </script>
     84 <script src="../../js/js-test-post.js"></script>
     85 
     86 </body>
     87 </html>
     88 <!--
     89 Copyright (c) 2019 The Khronos Group Inc.
     90 Use of this source code is governed by an MIT-style license that can be
     91 found in the LICENSE.txt file.
     92 -->