tor-browser

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

ovr_multiview2_depth.html (4696B)


      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 OVR_multiview2 Conformance Tests</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 <script src="../../js/tests/ovr_multiview2_util.js"></script>
     16 <script id="macroFragmentShader" type="x-shader/x-fragment">#version 300 es
     17 precision highp float;
     18 out vec4 my_FragColor;
     19 void main() {
     20 #ifdef GL_OVR_multiview2
     21    my_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
     22 #else
     23    // Error expected
     24    #error no GL_OVR_multiview2;
     25 #endif
     26 }
     27 </script>
     28 </head>
     29 <body>
     30 <div id="description"></div>
     31 <div id="console"></div>
     32 <script>
     33 "use strict";
     34 
     35 let wtu = WebGLTestUtils;
     36 let gl = wtu.create3DContext(null, null, 2);
     37 let ext = null;
     38 
     39 function runDepthRenderTest()
     40 {
     41    debug("");
     42    debug("Testing rendering with a depth texture array and depth test on");
     43 
     44    let width = 64;
     45    let height = 64;
     46 
     47    let views = gl.getParameter(ext.MAX_VIEWS_OVR);
     48 
     49    let multiviewShaders = [
     50      getMultiviewPassthroughVertexShader(views),
     51      getMultiviewColorFragmentShader()
     52    ];
     53    let testProgram = wtu.setupProgram(gl, multiviewShaders, ['a_position'], [0], true);
     54    if (!testProgram) {
     55        testFailed("Compilation with extension enabled failed.");
     56        return;
     57    }
     58 
     59    let fb = gl.createFramebuffer();
     60    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
     61    let colorTex = createTextureWithNearestFiltering(gl.TEXTURE_2D_ARRAY);
     62    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, width, height, views);
     63    ext.framebufferTextureMultiviewOVR(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, colorTex, 0, 0, views);
     64 
     65    let depthTex = createTextureWithNearestFiltering(gl.TEXTURE_2D_ARRAY);
     66    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.DEPTH32F_STENCIL8, width, height, views);
     67    ext.framebufferTextureMultiviewOVR(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, depthTex, 0, 0, views);
     68 
     69    let expectedStatus = gl.FRAMEBUFFER_COMPLETE;
     70    let status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
     71    if (status != expectedStatus) {
     72        testFailed('Framebuffer status: ' + wtu.glEnumToString(gl, status) + ' did not match with the expected value: ' + wtu.glEnumToString(gl, expectedStatus));
     73    }  else {
     74        testPassed('Framebuffer status: ' + wtu.glEnumToString(gl, status) + ' matched with the expected value');
     75    }
     76 
     77    // Draw so that the depth test succeeds for all pixels.
     78    gl.viewport(0, 0, width, height);
     79    gl.enable(gl.DEPTH_TEST);
     80    gl.clearDepth(1.0);
     81    gl.clear(gl.DEPTH_BUFFER_BIT);
     82 
     83    wtu.drawUnitQuad(gl);
     84    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from draw when depth test succeeds");
     85 
     86    let readFb = gl.createFramebuffer();
     87    gl.bindFramebuffer(gl.READ_FRAMEBUFFER, readFb);
     88    for (let viewIndex = 0; viewIndex < views; ++viewIndex) {
     89        gl.framebufferTextureLayer(gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, colorTex, 0, viewIndex);
     90        let expectedColor = getExpectedColor(viewIndex);
     91        wtu.checkCanvasRect(gl, 0, 0, width, height, expectedColor, 'view ' + viewIndex + ' should be colored ' + expectedColor);
     92    }
     93 
     94    // Draw so that the depth test fails for all pixels.
     95    gl.clearDepth(0.0);
     96    gl.clearColor(0.0, 0.0, 0.0, 0.0);
     97    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     98    wtu.drawUnitQuad(gl);
     99    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from draw when depth test fails");
    100 
    101    gl.bindFramebuffer(gl.READ_FRAMEBUFFER, readFb);
    102    for (let viewIndex = 0; viewIndex < views; ++viewIndex) {
    103        gl.framebufferTextureLayer(gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, colorTex, 0, viewIndex);
    104        let expectedColor = [0, 0, 0, 0];
    105        wtu.checkCanvasRect(gl, 0, 0, width, height, expectedColor, 'view ' + viewIndex + ' should be colored ' + expectedColor);
    106    }
    107 }
    108 
    109 description("This test verifies drawing to depth buffers with the OVR_multiview2 extension, if it is available.");
    110 
    111 debug("");
    112 
    113 if (!gl) {
    114  testFailed("WebGL context does not exist");
    115 } else {
    116  testPassed("WebGL context exists");
    117 
    118  debug("");
    119 
    120  if (!gl.getExtension("OVR_multiview2")) {
    121      testPassed("No OVR_multiview2 support -- this is legal");
    122  } else {
    123      testPassed("Successfully enabled OVR_multiview2 extension");
    124      ext = gl.getExtension('OVR_multiview2');
    125 
    126      wtu.setupUnitQuad(gl, 0, 1);
    127 
    128      runDepthRenderTest();
    129  }
    130 }
    131 
    132 debug("");
    133 var successfullyParsed = true;
    134 </script>
    135 <script src="../../js/js-test-post.js"></script>
    136 
    137 </body>
    138 </html>