browser/devtools/tilt/test/browser_tilt_gl04.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial