tor-browser

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

renderbuffer-initialization.html (3064B)


      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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     12 <script src="../../js/js-test-pre.js"></script>
     13 <script src="../../js/webgl-test-utils.js"></script>
     14 </head>
     15 <body>
     16 <canvas id="testbed" width="400" height="400" style="width: 40px; height: 40px;"></canvas>
     17 <div id="description"></div>
     18 <div id="console"></div>
     19 <script>
     20 "use strict";
     21 var wtu = WebGLTestUtils;
     22 description('Verify renderbuffers are initialized to 0 before being read in WebGL');
     23 
     24 var gl = wtu.create3DContext("testbed");
     25 if (!gl) {
     26    testFailed('canvas.getContext() failed');
     27 } else {
     28    // Set the clear color to green. It should never show up.
     29    gl.clearColor(0, 1, 0, 1);
     30 
     31    runTest(gl, gl.canvas.width, gl.canvas.height, 0);
     32    runTest(gl, gl.canvas.width, gl.canvas.height, 1);
     33    runTest(gl, gl.canvas.width, gl.canvas.height, 0);
     34    runTest(gl, gl.canvas.width, gl.canvas.height, 1);
     35 
     36    // Testing buffer clearing won't change the clear values.
     37    var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
     38    shouldBe("clearColor", "[0, 1, 0, 1]");
     39    wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
     40 }
     41 
     42 function runTest(gl, width, height, order)
     43 {
     44    wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0],
     45                        "internal buffers have been initialized to 0");
     46 
     47    // fill the back buffer so we know that reading below happens from
     48    // the renderbuffer.
     49    gl.clear(gl.COLOR_BUFFER_BIT);
     50 
     51    var fbo = gl.createFramebuffer();
     52    gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
     53    var colorbuffer = gl.createRenderbuffer();
     54    gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
     55    switch (order) {
     56      case 0:
     57        allocStorage(width, height);
     58        attachBuffer(colorbuffer);
     59        break;
     60      case 1:
     61        attachBuffer(colorbuffer);
     62        allocStorage(width, height);
     63        break;
     64    }
     65 
     66    function allocStorage(width, height) {
     67      gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height);
     68      wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbufferStorage(internalformat = RGBA4).');
     69    }
     70 
     71    function attachBuffer(colorbuffer) {
     72      gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer);
     73    }
     74 
     75    if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
     76        testFailed('Framebuffer incomplete.');
     77        return;
     78    }
     79 
     80    wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0],
     81                        "user buffers have been initialized to 0");
     82 
     83    gl.deleteFramebuffer(fbo);
     84    gl.deleteRenderbuffer(colorbuffer);
     85 
     86    // this clear should not matter we are about to resize
     87    gl.clear(gl.COLOR_BUFFER_BIT);
     88 
     89    gl.canvas.width += 1;
     90    gl.canvas.height += 1;
     91 
     92    debug('');
     93 }
     94 
     95 var successfullyParsed = true;
     96 </script>
     97 <script src="../../js/js-test-post.js"></script>
     98 </body>
     99 </html>