tor-browser

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

uniform-samplers-test.html (3438B)


      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 sampler uniforms 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 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 
     21 <script>
     22 "use strict";
     23 function init()
     24 {
     25  description(
     26      "Tests that only Uniform1i and Uniform1iv can be used to set" +
     27      "sampler uniforms.");
     28 
     29  var canvas2d = document.getElementById("canvas2d");
     30 
     31  var wtu = WebGLTestUtils;
     32  var gl = wtu.create3DContext("example");
     33  var program = wtu.setupTexturedQuad(gl);
     34 
     35  var textureLoc = gl.getUniformLocation(program, "tex");
     36 
     37  gl.uniform1i(textureLoc, 1);
     38  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
     39      "uniform1i can set a sampler uniform");
     40  gl.uniform1iv(textureLoc, [1]);
     41  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
     42      "uniform1iv can set a sampler uniform");
     43  gl.uniform1f(textureLoc, 1);
     44  wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
     45      "uniform1f returns INVALID_OPERATION if attempting to set a sampler uniform");
     46  gl.uniform1fv(textureLoc, [1]);
     47  wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
     48      "uniform1fv returns INVALID_OPERATION if attempting to set a sampler uniform");
     49 
     50  var maxTextureUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
     51 
     52  var testUniformi = function() {
     53    var success = true;
     54    for (var ii = 0; ii < maxTextureUnits; ++ii) {
     55      gl.uniform1i(textureLoc, ii);
     56      success = success && (gl.getError() == gl.NO_ERROR);
     57    }
     58    expectTrue(success, "uniform1i works for any valid texture unit");
     59  };
     60 
     61  var testUniformiv = function() {
     62    var success = true;
     63    for (var ii = 0; ii < maxTextureUnits; ++ii) {
     64      gl.uniform1iv(textureLoc, [ii]);
     65      success = success && (gl.getError() == gl.NO_ERROR);
     66    }
     67    expectTrue(success, "uniform1iv works for any valid texture unit");
     68  };
     69 
     70  var steps = [
     71    testUniformi,
     72    testUniformiv,
     73  ];
     74 
     75  var generateInvalidUniformiTests = function(start, end) {
     76    return function() {
     77      var success = true;
     78      for (var ii = start; ii < end; ++ii) {
     79        gl.uniform1i(textureLoc, ii);
     80        success = success && (gl.getError() == gl.INVALID_VALUE);
     81      }
     82      expectTrue(success, "uniform1i generates INVALID_VALUE for invalid texture units 0x" + start.toString(16) + " to 0x" + end.toString(16));
     83    };
     84  };
     85 
     86  var generateInvalidUniformivTests = function(start, end) {
     87    return function() {
     88      var success = true;
     89      for (var ii = start; ii < end; ++ii) {
     90        gl.uniform1iv(textureLoc, [ii]);
     91        success = success && (gl.getError() == gl.INVALID_VALUE);
     92      }
     93      expectTrue(success, "uniform1iv generates INVALID_VALUE for invalid texture units 0x" + start.toString(16) + " to 0x" + end.toString(16));
     94    };
     95  };
     96 
     97  var step = 0x1000;
     98  for (var ii = maxTextureUnits; ii < 0x10000; ii += step) {
     99    steps.push(generateInvalidUniformiTests(ii, ii + step));
    100    steps.push(generateInvalidUniformivTests(ii, ii + step));
    101  }
    102 
    103  steps.push(finishTest);
    104  wtu.runSteps(steps);
    105 }
    106 
    107 init();
    108 var successfullyParsed = true;
    109 </script>
    110 </body>
    111 </html>