tor-browser

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

gl-uniformmatrix4fv.html (4021B)


      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 uniformMatrix 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 <div id="console"></div>
     19 <canvas id="example" width="2" height="2"> </canvas>
     20 
     21 <script id="vshader" type="x-shader/x-vertex">
     22 uniform mat2 world2x2;
     23 uniform mat3 world3x3;
     24 uniform mat4 world4x4;
     25 void main() {
     26  gl_Position.x += world2x2[0][0];
     27  gl_Position.x += world3x3[0][0];
     28  gl_Position.x += world4x4[0][0];
     29 }
     30 </script>
     31 
     32 <script id="fshader" type="x-shader/x-fragment">
     33 void main() {}
     34 </script>
     35 
     36 <script id="vshader300" type="x-shader/x-vertex">
     37 #version 300 es
     38 uniform mat2   world2x2;
     39 uniform mat2x3 world2x3;
     40 uniform mat2x4 world2x4;
     41 uniform mat3x2 world3x2;
     42 uniform mat3   world3x3;
     43 uniform mat3x4 world3x4;
     44 uniform mat4x2 world4x2;
     45 uniform mat4x3 world4x3;
     46 uniform mat4   world4x4;
     47 void main() {
     48  gl_Position.x += world2x2[0][0];
     49  gl_Position.x += world2x3[0][0];
     50  gl_Position.x += world2x4[0][0];
     51  gl_Position.x += world3x2[0][0];
     52  gl_Position.x += world3x3[0][0];
     53  gl_Position.x += world3x4[0][0];
     54  gl_Position.x += world4x2[0][0];
     55  gl_Position.x += world4x3[0][0];
     56  gl_Position.x += world4x4[0][0];
     57 }
     58 </script>
     59 
     60 <script id="fshader300" type="x-shader/x-fragment">
     61 #version 300 es
     62 void main() {}
     63 </script>
     64 
     65 <script>
     66 "use strict";
     67 description("This test ensures WebGL implementations handle uniformMatrix in a OpenGL ES 2.0 spec compliant way");
     68 
     69 debug("");
     70 debug("Checking gl.uniformMatrix.");
     71 
     72 var wtu = WebGLTestUtils;
     73 var gl = wtu.create3DContext("example");
     74 var contextVersion = wtu.getDefault3DContextVersion();
     75 
     76 let shaders = ["vshader", "fshader"];
     77 const dims = [
     78  [2, 2, 'uniformMatrix2fv'],
     79  [3, 3, 'uniformMatrix3fv'],
     80  [4, 4, 'uniformMatrix4fv'],
     81 ];
     82 
     83 if (contextVersion >= 2) {
     84  shaders = ["vshader300", "fshader300"];
     85  dims.push(
     86    [2, 3, 'uniformMatrix2x3fv'],
     87    [2, 4, 'uniformMatrix2x4fv'],
     88    [3, 2, 'uniformMatrix3x2fv'],
     89    [3, 4, 'uniformMatrix3x4fv'],
     90    [4, 2, 'uniformMatrix4x2fv'],
     91    [4, 3, 'uniformMatrix4x3fv']
     92  );
     93 }
     94 
     95 const program = wtu.setupProgram(gl, shaders);
     96 let loc;
     97 
     98 for (const [A, B, name] of dims) {
     99  loc = gl.getUniformLocation(program, `world${A}x${B}`);
    100  if (!loc) throw 'missing loc';
    101 
    102  const mat = [];
    103  for (let a = 0; a < A; ++a) {
    104    for (let b = 0; b < B; ++b) {
    105      mat.push((a == b) ? 1 : 0);
    106    }
    107  }
    108  const matLess = mat.slice(0, mat.length-2);
    109  const matMore = mat.concat([1]);
    110 
    111  gl[name](loc, false, matLess);
    112  wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should fail with insufficient array size for " + name);
    113  gl[name](loc, false, mat);
    114  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should succeed with correct array size for " + name);
    115  gl[name](loc, false, matMore);
    116  wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should fail with more than 1 array size for " + name);
    117 
    118  const validDatas = [
    119    `new Float32Array(${mat.length})`,
    120    `new Float32Array(new ArrayBuffer(4*${mat.length}))`,
    121  ];
    122  if (window.SharedArrayBuffer) {
    123    validDatas.push(
    124      `new Float32Array(new SharedArrayBuffer(4*${mat.length}))`
    125    );
    126  }
    127  for (const x of validDatas) {
    128    shouldNotThrow(`gl.${name}(loc, false, ${x});`);
    129  }
    130 
    131  gl[name](loc, false, mat);
    132  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "can call " + name + "with transpose = false");
    133  if (contextVersion <= 1) {
    134    gl[name](loc, true, mat);
    135    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, name + " should return INVALID_VALUE with transpose = true");
    136  } else {
    137    gl[name](loc, true, mat);
    138    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "can call " + name + "with transpose = true");
    139  }
    140 }
    141 
    142 debug("");
    143 var successfullyParsed = true;
    144 
    145 </script>
    146 <script src="../../js/js-test-post.js"></script>
    147 
    148 </body>
    149 </html>