browser/devtools/tilt/test/browser_tilt_gl01.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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_gl01 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 ok(renderer,
michael@0 32 "The TiltGL.Renderer constructor should have initialized a new object.");
michael@0 33
michael@0 34 ok(gl instanceof WebGLRenderingContext,
michael@0 35 "The renderer context wasn't created correctly from the passed canvas.");
michael@0 36
michael@0 37
michael@0 38 let clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE),
michael@0 39 clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
michael@0 40
michael@0 41 is(clearColor[0], 0,
michael@0 42 "The default red clear color wasn't set correctly at initialization.");
michael@0 43 is(clearColor[1], 0,
michael@0 44 "The default green clear color wasn't set correctly at initialization.");
michael@0 45 is(clearColor[2], 0,
michael@0 46 "The default blue clear color wasn't set correctly at initialization.");
michael@0 47 is(clearColor[3], 0,
michael@0 48 "The default alpha clear color wasn't set correctly at initialization.");
michael@0 49 is(clearDepth, 1,
michael@0 50 "The default clear depth wasn't set correctly at initialization.");
michael@0 51
michael@0 52 is(renderer.width, canvas.width,
michael@0 53 "The renderer width wasn't set correctly from the passed canvas.");
michael@0 54 is(renderer.height, canvas.height,
michael@0 55 "The renderer height wasn't set correctly from the passed canvas.");
michael@0 56
michael@0 57 ok(renderer.mvMatrix,
michael@0 58 "The model view matrix wasn't initialized properly.");
michael@0 59 ok(renderer.projMatrix,
michael@0 60 "The model view matrix wasn't initialized properly.");
michael@0 61
michael@0 62 ok(isApproxVec(renderer._fillColor, [1, 1, 1, 1]),
michael@0 63 "The default fill color wasn't set correctly.");
michael@0 64 ok(isApproxVec(renderer._strokeColor, [0, 0, 0, 1]),
michael@0 65 "The default stroke color wasn't set correctly.");
michael@0 66 is(renderer._strokeWeightValue, 1,
michael@0 67 "The default stroke weight wasn't set correctly.");
michael@0 68
michael@0 69 ok(renderer._colorShader,
michael@0 70 "A default color shader should have been created.");
michael@0 71
michael@0 72 ok(typeof renderer.Program, "function",
michael@0 73 "At init, the renderer should have created a Program constructor.");
michael@0 74 ok(typeof renderer.VertexBuffer, "function",
michael@0 75 "At init, the renderer should have created a VertexBuffer constructor.");
michael@0 76 ok(typeof renderer.IndexBuffer, "function",
michael@0 77 "At init, the renderer should have created a IndexBuffer constructor.");
michael@0 78 ok(typeof renderer.Texture, "function",
michael@0 79 "At init, the renderer should have created a Texture constructor.");
michael@0 80
michael@0 81 renderer.depthTest(true);
michael@0 82 is(gl.getParameter(gl.DEPTH_TEST), true,
michael@0 83 "The depth test wasn't enabled when requested.");
michael@0 84
michael@0 85 renderer.depthTest(false);
michael@0 86 is(gl.getParameter(gl.DEPTH_TEST), false,
michael@0 87 "The depth test wasn't disabled when requested.");
michael@0 88
michael@0 89 renderer.stencilTest(true);
michael@0 90 is(gl.getParameter(gl.STENCIL_TEST), true,
michael@0 91 "The stencil test wasn't enabled when requested.");
michael@0 92
michael@0 93 renderer.stencilTest(false);
michael@0 94 is(gl.getParameter(gl.STENCIL_TEST), false,
michael@0 95 "The stencil test wasn't disabled when requested.");
michael@0 96
michael@0 97 renderer.cullFace("front");
michael@0 98 is(gl.getParameter(gl.CULL_FACE), true,
michael@0 99 "The cull face wasn't enabled when requested.");
michael@0 100 is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT,
michael@0 101 "The cull face front mode wasn't set correctly.");
michael@0 102
michael@0 103 renderer.cullFace("back");
michael@0 104 is(gl.getParameter(gl.CULL_FACE), true,
michael@0 105 "The cull face wasn't enabled when requested.");
michael@0 106 is(gl.getParameter(gl.CULL_FACE_MODE), gl.BACK,
michael@0 107 "The cull face back mode wasn't set correctly.");
michael@0 108
michael@0 109 renderer.cullFace("both");
michael@0 110 is(gl.getParameter(gl.CULL_FACE), true,
michael@0 111 "The cull face wasn't enabled when requested.");
michael@0 112 is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT_AND_BACK,
michael@0 113 "The cull face back mode wasn't set correctly.");
michael@0 114
michael@0 115 renderer.cullFace(false);
michael@0 116 is(gl.getParameter(gl.CULL_FACE), false,
michael@0 117 "The cull face wasn't disabled when requested.");
michael@0 118
michael@0 119 renderer.frontFace("cw");
michael@0 120 is(gl.getParameter(gl.FRONT_FACE), gl.CW,
michael@0 121 "The front face cw mode wasn't set correctly.");
michael@0 122
michael@0 123 renderer.frontFace("ccw");
michael@0 124 is(gl.getParameter(gl.FRONT_FACE), gl.CCW,
michael@0 125 "The front face ccw mode wasn't set correctly.");
michael@0 126
michael@0 127 renderer.blendMode("alpha");
michael@0 128 is(gl.getParameter(gl.BLEND), true,
michael@0 129 "The blend mode wasn't enabled when requested.");
michael@0 130 is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA,
michael@0 131 "The soruce blend func wasn't set correctly.");
michael@0 132 is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE_MINUS_SRC_ALPHA,
michael@0 133 "The destination blend func wasn't set correctly.");
michael@0 134
michael@0 135 renderer.blendMode("add");
michael@0 136 is(gl.getParameter(gl.BLEND), true,
michael@0 137 "The blend mode wasn't enabled when requested.");
michael@0 138 is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA,
michael@0 139 "The soruce blend func wasn't set correctly.");
michael@0 140 is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE,
michael@0 141 "The destination blend func wasn't set correctly.");
michael@0 142
michael@0 143 renderer.blendMode(false);
michael@0 144 is(gl.getParameter(gl.CULL_FACE), false,
michael@0 145 "The blend mode wasn't disabled when requested.");
michael@0 146
michael@0 147
michael@0 148 is(gl.getParameter(gl.CURRENT_PROGRAM), null,
michael@0 149 "No program should be initially set in the WebGL context.");
michael@0 150
michael@0 151 renderer.useColorShader(new renderer.VertexBuffer([1, 2, 3], 3));
michael@0 152
michael@0 153 ok(gl.getParameter(gl.CURRENT_PROGRAM) instanceof WebGLProgram,
michael@0 154 "The correct program hasn't been set in the WebGL context.");
michael@0 155 }

mercurial