browser/devtools/tilt/test/browser_tilt_gl04.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 let isWebGLAvailable;
     7 function onWebGLFail() {
     8   isWebGLAvailable = false;
     9 }
    11 function onWebGLSuccess() {
    12   isWebGLAvailable = true;
    13 }
    15 function test() {
    16   if (!isWebGLSupported()) {
    17     info("Skipping tilt_gl04 because WebGL isn't supported on this hardware.");
    18     return;
    19   }
    21   let canvas = createCanvas();
    23   let renderer = new TiltGL.Renderer(canvas, onWebGLFail, onWebGLSuccess);
    24   let gl = renderer.context;
    26   if (!isWebGLAvailable) {
    27     return;
    28   }
    31   renderer.perspective();
    32   ok(isApproxVec(renderer.projMatrix, [
    33     1.2071068286895752, 0, 0, 0, 0, -2.4142136573791504, 0, 0, 0, 0,
    34     -1.0202020406723022, -1, -181.06602478027344, 181.06602478027344,
    35     148.14492797851562, 181.06602478027344
    36   ]), "The default perspective proj. matrix wasn't calculated correctly.");
    38   ok(isApproxVec(renderer.mvMatrix, [
    39     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
    40   ]), "Changing the perpective matrix should reset the modelview by default.");
    43   renderer.ortho();
    44   ok(isApproxVec(renderer.projMatrix, [
    45     0.006666666828095913, 0, 0, 0, 0, -0.013333333656191826, 0, 0, 0, 0, -1,
    46     0, -1, 1, 0, 1
    47   ]), "The default ortho proj. matrix wasn't calculated correctly.");
    48   ok(isApproxVec(renderer.mvMatrix, [
    49     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
    50   ]), "Changing the ortho matrix should reset the modelview by default.");
    53   renderer.projection(mat4.perspective(45, 1, 0.1, 100));
    54   ok(isApproxVec(renderer.projMatrix, [
    55     2.4142136573791504, 0, 0, 0, 0, 2.4142136573791504, 0, 0, 0, 0,
    56     -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0
    57   ]), "A custom proj. matrix couldn't be set correctly.");
    58   ok(isApproxVec(renderer.mvMatrix, [
    59     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
    60   ]), "Setting a custom proj. matrix should reset the model view by default.");
    63   renderer.translate(1, 1, 1);
    64   ok(isApproxVec(renderer.mvMatrix, [
    65     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1
    66   ]), "The translation transformation wasn't applied correctly.");
    68   renderer.rotate(0.5, 1, 1, 1);
    69   ok(isApproxVec(renderer.mvMatrix, [
    70     0.9183883666992188, 0.317602276802063, -0.23599065840244293, 0,
    71     -0.23599065840244293, 0.9183883666992188, 0.317602276802063, 0,
    72     0.317602276802063, -0.23599065840244293, 0.9183883666992188, 0, 1, 1, 1, 1
    73   ]), "The rotation transformation wasn't applied correctly.");
    75   renderer.rotateX(0.5);
    76   ok(isApproxVec(renderer.mvMatrix, [
    77     0.9183883666992188, 0.317602276802063, -0.23599065840244293, 0,
    78     -0.05483464524149895, 0.6928216814994812, 0.7190210819244385, 0,
    79     0.391862154006958, -0.6474001407623291, 0.6536949872970581, 0, 1, 1, 1, 1
    80   ]), "The X rotation transformation wasn't applied correctly.");
    82   renderer.rotateY(0.5);
    83   ok(isApproxVec(renderer.mvMatrix, [
    84     0.6180928945541382, 0.5891023874282837, -0.5204993486404419, 0,
    85     -0.05483464524149895, 0.6928216814994812, 0.7190210819244385, 0,
    86     0.7841902375221252, -0.4158804416656494, 0.4605313837528229, 0, 1, 1, 1, 1
    87   ]), "The Y rotation transformation wasn't applied correctly.");
    89   renderer.rotateZ(0.5);
    90   ok(isApproxVec(renderer.mvMatrix, [
    91     0.5161384344100952, 0.8491423726081848, -0.11206408590078354, 0,
    92     -0.3444514572620392, 0.3255774974822998, 0.8805410265922546, 0,
    93     0.7841902375221252, -0.4158804416656494, 0.4605313837528229, 0, 1, 1, 1, 1
    94   ]), "The Z rotation transformation wasn't applied correctly.");
    96   renderer.scale(2, 2, 2);
    97   ok(isApproxVec(renderer.mvMatrix, [
    98     1.0322768688201904, 1.6982847452163696, -0.22412817180156708, 0,
    99     -0.6889029145240784, 0.6511549949645996, 1.7610820531845093, 0,
   100     1.5683804750442505, -0.8317608833312988, 0.9210627675056458, 0, 1, 1, 1, 1
   101   ]), "The Z rotation transformation wasn't applied correctly.");
   103   renderer.transform(mat4.create());
   104   ok(isApproxVec(renderer.mvMatrix, [
   105     1.0322768688201904, 1.6982847452163696, -0.22412817180156708, 0,
   106     -0.6889029145240784, 0.6511549949645996, 1.7610820531845093, 0,
   107     1.5683804750442505, -0.8317608833312988, 0.9210627675056458, 0, 1, 1, 1, 1
   108   ]), "The identity matrix transformation wasn't applied correctly.");
   110   renderer.origin(1, 1, 1);
   111   ok(isApproxVec(renderer.mvMatrix, [
   112     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
   113   ]), "The origin wasn't reset to identity correctly.");
   115   renderer.translate(1, 2);
   116   ok(isApproxVec(renderer.mvMatrix, [
   117     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1
   118   ]), "The second translation transformation wasn't applied correctly.");
   120   renderer.scale(3, 4);
   121   ok(isApproxVec(renderer.mvMatrix, [
   122     3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1
   123   ]), "The second scale transformation wasn't applied correctly.");
   124 }

mercurial