1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_gl04.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +let isWebGLAvailable; 1.9 + 1.10 +function onWebGLFail() { 1.11 + isWebGLAvailable = false; 1.12 +} 1.13 + 1.14 +function onWebGLSuccess() { 1.15 + isWebGLAvailable = true; 1.16 +} 1.17 + 1.18 +function test() { 1.19 + if (!isWebGLSupported()) { 1.20 + info("Skipping tilt_gl04 because WebGL isn't supported on this hardware."); 1.21 + return; 1.22 + } 1.23 + 1.24 + let canvas = createCanvas(); 1.25 + 1.26 + let renderer = new TiltGL.Renderer(canvas, onWebGLFail, onWebGLSuccess); 1.27 + let gl = renderer.context; 1.28 + 1.29 + if (!isWebGLAvailable) { 1.30 + return; 1.31 + } 1.32 + 1.33 + 1.34 + renderer.perspective(); 1.35 + ok(isApproxVec(renderer.projMatrix, [ 1.36 + 1.2071068286895752, 0, 0, 0, 0, -2.4142136573791504, 0, 0, 0, 0, 1.37 + -1.0202020406723022, -1, -181.06602478027344, 181.06602478027344, 1.38 + 148.14492797851562, 181.06602478027344 1.39 + ]), "The default perspective proj. matrix wasn't calculated correctly."); 1.40 + 1.41 + ok(isApproxVec(renderer.mvMatrix, [ 1.42 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 1.43 + ]), "Changing the perpective matrix should reset the modelview by default."); 1.44 + 1.45 + 1.46 + renderer.ortho(); 1.47 + ok(isApproxVec(renderer.projMatrix, [ 1.48 + 0.006666666828095913, 0, 0, 0, 0, -0.013333333656191826, 0, 0, 0, 0, -1, 1.49 + 0, -1, 1, 0, 1 1.50 + ]), "The default ortho proj. matrix wasn't calculated correctly."); 1.51 + ok(isApproxVec(renderer.mvMatrix, [ 1.52 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 1.53 + ]), "Changing the ortho matrix should reset the modelview by default."); 1.54 + 1.55 + 1.56 + renderer.projection(mat4.perspective(45, 1, 0.1, 100)); 1.57 + ok(isApproxVec(renderer.projMatrix, [ 1.58 + 2.4142136573791504, 0, 0, 0, 0, 2.4142136573791504, 0, 0, 0, 0, 1.59 + -1.0020020008087158, -1, 0, 0, -0.20020020008087158, 0 1.60 + ]), "A custom proj. matrix couldn't be set correctly."); 1.61 + ok(isApproxVec(renderer.mvMatrix, [ 1.62 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 1.63 + ]), "Setting a custom proj. matrix should reset the model view by default."); 1.64 + 1.65 + 1.66 + renderer.translate(1, 1, 1); 1.67 + ok(isApproxVec(renderer.mvMatrix, [ 1.68 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1 1.69 + ]), "The translation transformation wasn't applied correctly."); 1.70 + 1.71 + renderer.rotate(0.5, 1, 1, 1); 1.72 + ok(isApproxVec(renderer.mvMatrix, [ 1.73 + 0.9183883666992188, 0.317602276802063, -0.23599065840244293, 0, 1.74 + -0.23599065840244293, 0.9183883666992188, 0.317602276802063, 0, 1.75 + 0.317602276802063, -0.23599065840244293, 0.9183883666992188, 0, 1, 1, 1, 1 1.76 + ]), "The rotation transformation wasn't applied correctly."); 1.77 + 1.78 + renderer.rotateX(0.5); 1.79 + ok(isApproxVec(renderer.mvMatrix, [ 1.80 + 0.9183883666992188, 0.317602276802063, -0.23599065840244293, 0, 1.81 + -0.05483464524149895, 0.6928216814994812, 0.7190210819244385, 0, 1.82 + 0.391862154006958, -0.6474001407623291, 0.6536949872970581, 0, 1, 1, 1, 1 1.83 + ]), "The X rotation transformation wasn't applied correctly."); 1.84 + 1.85 + renderer.rotateY(0.5); 1.86 + ok(isApproxVec(renderer.mvMatrix, [ 1.87 + 0.6180928945541382, 0.5891023874282837, -0.5204993486404419, 0, 1.88 + -0.05483464524149895, 0.6928216814994812, 0.7190210819244385, 0, 1.89 + 0.7841902375221252, -0.4158804416656494, 0.4605313837528229, 0, 1, 1, 1, 1 1.90 + ]), "The Y rotation transformation wasn't applied correctly."); 1.91 + 1.92 + renderer.rotateZ(0.5); 1.93 + ok(isApproxVec(renderer.mvMatrix, [ 1.94 + 0.5161384344100952, 0.8491423726081848, -0.11206408590078354, 0, 1.95 + -0.3444514572620392, 0.3255774974822998, 0.8805410265922546, 0, 1.96 + 0.7841902375221252, -0.4158804416656494, 0.4605313837528229, 0, 1, 1, 1, 1 1.97 + ]), "The Z rotation transformation wasn't applied correctly."); 1.98 + 1.99 + renderer.scale(2, 2, 2); 1.100 + ok(isApproxVec(renderer.mvMatrix, [ 1.101 + 1.0322768688201904, 1.6982847452163696, -0.22412817180156708, 0, 1.102 + -0.6889029145240784, 0.6511549949645996, 1.7610820531845093, 0, 1.103 + 1.5683804750442505, -0.8317608833312988, 0.9210627675056458, 0, 1, 1, 1, 1 1.104 + ]), "The Z rotation transformation wasn't applied correctly."); 1.105 + 1.106 + renderer.transform(mat4.create()); 1.107 + ok(isApproxVec(renderer.mvMatrix, [ 1.108 + 1.0322768688201904, 1.6982847452163696, -0.22412817180156708, 0, 1.109 + -0.6889029145240784, 0.6511549949645996, 1.7610820531845093, 0, 1.110 + 1.5683804750442505, -0.8317608833312988, 0.9210627675056458, 0, 1, 1, 1, 1 1.111 + ]), "The identity matrix transformation wasn't applied correctly."); 1.112 + 1.113 + renderer.origin(1, 1, 1); 1.114 + ok(isApproxVec(renderer.mvMatrix, [ 1.115 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 1.116 + ]), "The origin wasn't reset to identity correctly."); 1.117 + 1.118 + renderer.translate(1, 2); 1.119 + ok(isApproxVec(renderer.mvMatrix, [ 1.120 + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1 1.121 + ]), "The second translation transformation wasn't applied correctly."); 1.122 + 1.123 + renderer.scale(3, 4); 1.124 + ok(isApproxVec(renderer.mvMatrix, [ 1.125 + 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1 1.126 + ]), "The second scale transformation wasn't applied correctly."); 1.127 +}