tor-browser

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

ext-blend-minmax.html (7478B)


      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 EXT_blend_minmax 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 </head>
     16 <body>
     17 <div id="description"></div>
     18 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
     19 <div id="console"></div>
     20 <!-- Shaders to test output -->
     21 <script id="outputVertexShader" type="x-shader/x-vertex">
     22 attribute vec4 vPosition;
     23 void main() {
     24    gl_Position = vPosition;
     25 }
     26 </script>
     27 <script id="outputFragmentShader" type="x-shader/x-fragment">
     28 precision mediump float;
     29 uniform vec4 uColor;
     30 void main() {
     31    gl_FragColor = uColor;
     32 }
     33 </script>
     34 
     35 <script>
     36 "use strict";
     37 description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
     38 
     39 debug("");
     40 
     41 var wtu = WebGLTestUtils;
     42 var canvas = document.getElementById("canvas");
     43 var gl = wtu.create3DContext(canvas);
     44 var ext = null;
     45 
     46 // Use the constant directly when we don't have the extension
     47 var MIN_EXT = 0x8007;
     48 var MAX_EXT = 0x8008;
     49 
     50 if (!gl) {
     51    testFailed("WebGL context does not exist");
     52 } else {
     53    testPassed("WebGL context exists");
     54 
     55    runBlendTestDisabled();
     56 
     57    // Query the extension and store globally so shouldBe can access it
     58    ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_blend_minmax");
     59    if (!ext) {
     60        testPassed("No EXT_blend_minmax support -- this is legal");
     61 
     62        runSupportedTest(false);
     63    } else {
     64        debug("");
     65        testPassed("Successfully enabled EXT_blend_minmax extension");
     66 
     67        runSupportedTest(true);
     68 
     69        runBlendTestEnabled();
     70        runOutputTests();
     71        runUniqueObjectTest();
     72    }
     73 }
     74 
     75 function runSupportedTest(extensionEnabled) {
     76    var supported = gl.getSupportedExtensions();
     77    if (supported.indexOf("EXT_blend_minmax") >= 0) {
     78        if (extensionEnabled) {
     79            testPassed("EXT_blend_minmax listed as supported and getExtension succeeded");
     80        } else {
     81            testFailed("EXT_blend_minmax listed as supported but getExtension failed");
     82        }
     83    } else {
     84        if (extensionEnabled) {
     85            testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
     86        } else {
     87            testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
     88        }
     89    }
     90 }
     91 
     92 function runBlendTestDisabled() {
     93    debug("");
     94    debug("Testing blending enums with extension disabled");
     95 
     96    // Set the blend equation to a known-good enum first
     97    gl.blendEquation(gl.FUNC_ADD);
     98 
     99    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MIN_EXT)");
    100    shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
    101 
    102    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MAX_EXT)");
    103    shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
    104 
    105    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MIN_EXT, gl.FUNC_ADD)");
    106    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
    107 
    108    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MIN_EXT)");
    109    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
    110 
    111    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MAX_EXT, gl.FUNC_ADD)");
    112    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
    113 
    114    wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MAX_EXT)");
    115    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
    116 }
    117 
    118 function runBlendTestEnabled() {
    119    debug("");
    120    debug("Testing blending enums with extension enabled");
    121 
    122    shouldBe("ext.MIN_EXT", "0x8007");
    123    shouldBe("ext.MAX_EXT", "0x8008");
    124 
    125    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MIN_EXT)");
    126    shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MIN_EXT");
    127 
    128    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MAX_EXT)");
    129    shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MAX_EXT");
    130 
    131    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MIN_EXT, gl.FUNC_ADD)");
    132    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MIN_EXT");
    133    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
    134 
    135    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MIN_EXT)");
    136    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
    137    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MIN_EXT");
    138 
    139    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MAX_EXT, gl.FUNC_ADD)");
    140    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MAX_EXT");
    141    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
    142 
    143    wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MAX_EXT)");
    144    shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
    145    shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MAX_EXT");
    146 }
    147 
    148 function runOutputTests() {
    149    var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
    150 
    151    debug("");
    152    debug("Testing various draws for valid blending behavior");
    153 
    154    canvas.width = 50; canvas.height = 50;
    155    gl.viewport(0, 0, canvas.width, canvas.height);
    156    gl.enable(gl.BLEND);
    157    gl.blendFunc(gl.ONE, gl.ONE);
    158 
    159    var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
    160    var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
    161    var colorUniform = gl.getUniformLocation(program, "uColor");
    162 
    163 
    164    // Draw 1
    165    gl.blendEquation(ext.MIN_EXT);
    166 
    167    gl.clearColor(0.2, 0.4, 0.6, 0.8);
    168    gl.clear(gl.COLOR_BUFFER_BIT);
    169 
    170    gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
    171    wtu.drawUnitQuad(gl);
    172 
    173    wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 51]);
    174 
    175    // Draw 2:
    176    gl.blendEquation(ext.MAX_EXT);
    177 
    178    gl.clearColor(0.2, 0.4, 0.6, 0.8);
    179    gl.clear(gl.COLOR_BUFFER_BIT);
    180 
    181    gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
    182    wtu.drawUnitQuad(gl);
    183 
    184    wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 204]);
    185 
    186    // Draw 3
    187    gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);
    188 
    189    gl.clearColor(0.2, 0.4, 0.6, 0.8);
    190    gl.clear(gl.COLOR_BUFFER_BIT);
    191 
    192    gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
    193    wtu.drawUnitQuad(gl);
    194 
    195    wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 204]);
    196 
    197    // Draw 4
    198    gl.blendEquationSeparate(ext.MAX_EXT, ext.MIN_EXT);
    199 
    200    gl.clearColor(0.2, 0.4, 0.6, 0.8);
    201    gl.clear(gl.COLOR_BUFFER_BIT);
    202 
    203    gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
    204    wtu.drawUnitQuad(gl);
    205 
    206    wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 51]);
    207 }
    208 
    209 function runUniqueObjectTest()
    210 {
    211    debug("");
    212    debug("Testing that getExtension() returns the same object each time");
    213    ext = null;
    214    gl.getExtension("EXT_blend_minmax").myProperty = 2;
    215    webglHarnessCollectGarbage();
    216    shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
    217 }
    218 
    219 debug("");
    220 var successfullyParsed = true;
    221 </script>
    222 <script src="../../js/js-test-post.js"></script>
    223 
    224 </body>
    225 </html>