1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_gl01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 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_gl01 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 + ok(renderer, 1.35 + "The TiltGL.Renderer constructor should have initialized a new object."); 1.36 + 1.37 + ok(gl instanceof WebGLRenderingContext, 1.38 + "The renderer context wasn't created correctly from the passed canvas."); 1.39 + 1.40 + 1.41 + let clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE), 1.42 + clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE); 1.43 + 1.44 + is(clearColor[0], 0, 1.45 + "The default red clear color wasn't set correctly at initialization."); 1.46 + is(clearColor[1], 0, 1.47 + "The default green clear color wasn't set correctly at initialization."); 1.48 + is(clearColor[2], 0, 1.49 + "The default blue clear color wasn't set correctly at initialization."); 1.50 + is(clearColor[3], 0, 1.51 + "The default alpha clear color wasn't set correctly at initialization."); 1.52 + is(clearDepth, 1, 1.53 + "The default clear depth wasn't set correctly at initialization."); 1.54 + 1.55 + is(renderer.width, canvas.width, 1.56 + "The renderer width wasn't set correctly from the passed canvas."); 1.57 + is(renderer.height, canvas.height, 1.58 + "The renderer height wasn't set correctly from the passed canvas."); 1.59 + 1.60 + ok(renderer.mvMatrix, 1.61 + "The model view matrix wasn't initialized properly."); 1.62 + ok(renderer.projMatrix, 1.63 + "The model view matrix wasn't initialized properly."); 1.64 + 1.65 + ok(isApproxVec(renderer._fillColor, [1, 1, 1, 1]), 1.66 + "The default fill color wasn't set correctly."); 1.67 + ok(isApproxVec(renderer._strokeColor, [0, 0, 0, 1]), 1.68 + "The default stroke color wasn't set correctly."); 1.69 + is(renderer._strokeWeightValue, 1, 1.70 + "The default stroke weight wasn't set correctly."); 1.71 + 1.72 + ok(renderer._colorShader, 1.73 + "A default color shader should have been created."); 1.74 + 1.75 + ok(typeof renderer.Program, "function", 1.76 + "At init, the renderer should have created a Program constructor."); 1.77 + ok(typeof renderer.VertexBuffer, "function", 1.78 + "At init, the renderer should have created a VertexBuffer constructor."); 1.79 + ok(typeof renderer.IndexBuffer, "function", 1.80 + "At init, the renderer should have created a IndexBuffer constructor."); 1.81 + ok(typeof renderer.Texture, "function", 1.82 + "At init, the renderer should have created a Texture constructor."); 1.83 + 1.84 + renderer.depthTest(true); 1.85 + is(gl.getParameter(gl.DEPTH_TEST), true, 1.86 + "The depth test wasn't enabled when requested."); 1.87 + 1.88 + renderer.depthTest(false); 1.89 + is(gl.getParameter(gl.DEPTH_TEST), false, 1.90 + "The depth test wasn't disabled when requested."); 1.91 + 1.92 + renderer.stencilTest(true); 1.93 + is(gl.getParameter(gl.STENCIL_TEST), true, 1.94 + "The stencil test wasn't enabled when requested."); 1.95 + 1.96 + renderer.stencilTest(false); 1.97 + is(gl.getParameter(gl.STENCIL_TEST), false, 1.98 + "The stencil test wasn't disabled when requested."); 1.99 + 1.100 + renderer.cullFace("front"); 1.101 + is(gl.getParameter(gl.CULL_FACE), true, 1.102 + "The cull face wasn't enabled when requested."); 1.103 + is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT, 1.104 + "The cull face front mode wasn't set correctly."); 1.105 + 1.106 + renderer.cullFace("back"); 1.107 + is(gl.getParameter(gl.CULL_FACE), true, 1.108 + "The cull face wasn't enabled when requested."); 1.109 + is(gl.getParameter(gl.CULL_FACE_MODE), gl.BACK, 1.110 + "The cull face back mode wasn't set correctly."); 1.111 + 1.112 + renderer.cullFace("both"); 1.113 + is(gl.getParameter(gl.CULL_FACE), true, 1.114 + "The cull face wasn't enabled when requested."); 1.115 + is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT_AND_BACK, 1.116 + "The cull face back mode wasn't set correctly."); 1.117 + 1.118 + renderer.cullFace(false); 1.119 + is(gl.getParameter(gl.CULL_FACE), false, 1.120 + "The cull face wasn't disabled when requested."); 1.121 + 1.122 + renderer.frontFace("cw"); 1.123 + is(gl.getParameter(gl.FRONT_FACE), gl.CW, 1.124 + "The front face cw mode wasn't set correctly."); 1.125 + 1.126 + renderer.frontFace("ccw"); 1.127 + is(gl.getParameter(gl.FRONT_FACE), gl.CCW, 1.128 + "The front face ccw mode wasn't set correctly."); 1.129 + 1.130 + renderer.blendMode("alpha"); 1.131 + is(gl.getParameter(gl.BLEND), true, 1.132 + "The blend mode wasn't enabled when requested."); 1.133 + is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA, 1.134 + "The soruce blend func wasn't set correctly."); 1.135 + is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE_MINUS_SRC_ALPHA, 1.136 + "The destination blend func wasn't set correctly."); 1.137 + 1.138 + renderer.blendMode("add"); 1.139 + is(gl.getParameter(gl.BLEND), true, 1.140 + "The blend mode wasn't enabled when requested."); 1.141 + is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA, 1.142 + "The soruce blend func wasn't set correctly."); 1.143 + is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE, 1.144 + "The destination blend func wasn't set correctly."); 1.145 + 1.146 + renderer.blendMode(false); 1.147 + is(gl.getParameter(gl.CULL_FACE), false, 1.148 + "The blend mode wasn't disabled when requested."); 1.149 + 1.150 + 1.151 + is(gl.getParameter(gl.CURRENT_PROGRAM), null, 1.152 + "No program should be initially set in the WebGL context."); 1.153 + 1.154 + renderer.useColorShader(new renderer.VertexBuffer([1, 2, 3], 3)); 1.155 + 1.156 + ok(gl.getParameter(gl.CURRENT_PROGRAM) instanceof WebGLProgram, 1.157 + "The correct program hasn't been set in the WebGL context."); 1.158 +}