tor-browser

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

webgl-draw-buffers-max-draw-buffers.html (3950B)


      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 WEBGL_draw_buffers gl_FragData[gl_MaxDrawBuffers] Conformance 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 <canvas id="canvas" width="64" height="64"> </canvas>
     19 <div id="console"></div>
     20 <script id="vshader" type="x-shader/x-vertex">
     21 attribute vec4 a_position;
     22 void main() {
     23    gl_Position = a_position;
     24 }
     25 </script>
     26 <script id="fshader" type="x-shader/x-fragment">
     27 #extension GL_EXT_draw_buffers : require
     28 precision mediump float;
     29 void main() {
     30    gl_FragData[gl_MaxDrawBuffers] = vec4(0.0);
     31 }
     32 </script>
     33 <script id="fshaderConstantIndex" type="x-shader/x-fragment">
     34 #extension GL_EXT_draw_buffers : require
     35 precision mediump float;
     36 void main() {
     37    gl_FragData[$(gl_MaxDrawBuffers)] = vec4(0.0);
     38 }
     39 </script>
     40 <script id="fshaderTestMaxDrawBuffersValue" type="x-shader/x-fragment">
     41 #extension GL_EXT_draw_buffers : require
     42 precision mediump float;
     43 void main() {
     44    gl_FragColor = ($(gl_MaxDrawBuffers) == gl_MaxDrawBuffers) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
     45 }
     46 </script>
     47 <script>
     48 "use strict";
     49 description("This test verifies that compiling the same shader using GL_EXT_draw_buffers twice will have similar results on both rounds.");
     50 
     51 debug("");
     52 
     53 var wtu = WebGLTestUtils;
     54 var canvas = document.getElementById("canvas");
     55 var gl = wtu.create3DContext(canvas);
     56 var ext = null;
     57 var maxDrawBuffers;
     58 
     59 if (!gl) {
     60  testFailed("WebGL context does not exist");
     61 } else {
     62  testPassed("WebGL context exists");
     63 
     64  ext = gl.getExtension("WEBGL_draw_buffers");
     65  if (!ext) {
     66    testPassed("No WEBGL_draw_buffers support -- this is legal");
     67    finishTest();
     68  } else {
     69    testPassed("Successfully enabled WEBGL_draw_buffers extension");
     70    maxDrawBuffers = gl.getParameter(ext.MAX_DRAW_BUFFERS_WEBGL);
     71    runShadersTest();
     72    finishTest();
     73  }
     74 }
     75 
     76 function testValueOfMaxDrawBuffers() {
     77  debug("Test the value of gl_MaxDrawBuffers in a shader");
     78  var fshader = wtu.replaceParams(wtu.getScript("fshaderTestMaxDrawBuffersValue"), {"gl_MaxDrawBuffers": maxDrawBuffers});
     79  var program = wtu.setupProgram(gl, ["vshader", fshader], ["a_position"], undefined, true);
     80  expectTrue(program != null, "Test program should compile");
     81  wtu.setupUnitQuad(gl);
     82  wtu.clearAndDrawUnitQuad(gl);
     83  wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green to indicate that gl_MaxDrawBuffers had the right value");
     84  gl.deleteProgram(program);
     85  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
     86 }
     87 
     88 function runSingleTest(shaders, indexMsg) {
     89  var program = wtu.setupProgram(gl, shaders, ["a_position"], undefined, true);
     90  var programLinkedSuccessfully = (program != null);
     91  expectTrue(!programLinkedSuccessfully, "Program where gl_FragData is indexed by " + indexMsg + " should fail compilation.");
     92  gl.deleteProgram(program);
     93 }
     94 
     95 function runShadersTest() {
     96  debug("MAX_DRAW_BUFFERS_WEBGL is: " + maxDrawBuffers);
     97 
     98  // For reference, use a constant out-of-range parameter to test:
     99  debug("Test indexing gl_FragData with value of MAX_DRAW_BUFFERS_WEBGL");
    100  var fshader = wtu.replaceParams(wtu.getScript("fshaderConstantIndex"), {"gl_MaxDrawBuffers": maxDrawBuffers});
    101  runSingleTest(["vshader", fshader], maxDrawBuffers + " (value of MAX_DRAW_BUFFERS_WEBGL)");
    102 
    103  debug("");
    104 
    105  debug("Test indexing gl_FragData with gl_MaxDrawBuffers");
    106  debug("Repeat this test twice as that has revealed a bug.");
    107  for (var i = 0; i < 2; ++i) {
    108    runSingleTest(["vshader", "fshader"], "gl_MaxDrawBuffers");
    109  }
    110  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
    111 
    112  debug("");
    113 
    114  testValueOfMaxDrawBuffers();
    115 }
    116 </script>
    117 </body>
    118 </html>