michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: let isWebGLAvailable; michael@0: michael@0: function onWebGLFail() { michael@0: isWebGLAvailable = false; michael@0: } michael@0: michael@0: function onWebGLSuccess() { michael@0: isWebGLAvailable = true; michael@0: } michael@0: michael@0: function test() { michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping tilt_gl01 because WebGL isn't supported on this hardware."); michael@0: return; michael@0: } michael@0: michael@0: let canvas = createCanvas(); michael@0: michael@0: let renderer = new TiltGL.Renderer(canvas, onWebGLFail, onWebGLSuccess); michael@0: let gl = renderer.context; michael@0: michael@0: if (!isWebGLAvailable) { michael@0: return; michael@0: } michael@0: michael@0: michael@0: ok(renderer, michael@0: "The TiltGL.Renderer constructor should have initialized a new object."); michael@0: michael@0: ok(gl instanceof WebGLRenderingContext, michael@0: "The renderer context wasn't created correctly from the passed canvas."); michael@0: michael@0: michael@0: let clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE), michael@0: clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE); michael@0: michael@0: is(clearColor[0], 0, michael@0: "The default red clear color wasn't set correctly at initialization."); michael@0: is(clearColor[1], 0, michael@0: "The default green clear color wasn't set correctly at initialization."); michael@0: is(clearColor[2], 0, michael@0: "The default blue clear color wasn't set correctly at initialization."); michael@0: is(clearColor[3], 0, michael@0: "The default alpha clear color wasn't set correctly at initialization."); michael@0: is(clearDepth, 1, michael@0: "The default clear depth wasn't set correctly at initialization."); michael@0: michael@0: is(renderer.width, canvas.width, michael@0: "The renderer width wasn't set correctly from the passed canvas."); michael@0: is(renderer.height, canvas.height, michael@0: "The renderer height wasn't set correctly from the passed canvas."); michael@0: michael@0: ok(renderer.mvMatrix, michael@0: "The model view matrix wasn't initialized properly."); michael@0: ok(renderer.projMatrix, michael@0: "The model view matrix wasn't initialized properly."); michael@0: michael@0: ok(isApproxVec(renderer._fillColor, [1, 1, 1, 1]), michael@0: "The default fill color wasn't set correctly."); michael@0: ok(isApproxVec(renderer._strokeColor, [0, 0, 0, 1]), michael@0: "The default stroke color wasn't set correctly."); michael@0: is(renderer._strokeWeightValue, 1, michael@0: "The default stroke weight wasn't set correctly."); michael@0: michael@0: ok(renderer._colorShader, michael@0: "A default color shader should have been created."); michael@0: michael@0: ok(typeof renderer.Program, "function", michael@0: "At init, the renderer should have created a Program constructor."); michael@0: ok(typeof renderer.VertexBuffer, "function", michael@0: "At init, the renderer should have created a VertexBuffer constructor."); michael@0: ok(typeof renderer.IndexBuffer, "function", michael@0: "At init, the renderer should have created a IndexBuffer constructor."); michael@0: ok(typeof renderer.Texture, "function", michael@0: "At init, the renderer should have created a Texture constructor."); michael@0: michael@0: renderer.depthTest(true); michael@0: is(gl.getParameter(gl.DEPTH_TEST), true, michael@0: "The depth test wasn't enabled when requested."); michael@0: michael@0: renderer.depthTest(false); michael@0: is(gl.getParameter(gl.DEPTH_TEST), false, michael@0: "The depth test wasn't disabled when requested."); michael@0: michael@0: renderer.stencilTest(true); michael@0: is(gl.getParameter(gl.STENCIL_TEST), true, michael@0: "The stencil test wasn't enabled when requested."); michael@0: michael@0: renderer.stencilTest(false); michael@0: is(gl.getParameter(gl.STENCIL_TEST), false, michael@0: "The stencil test wasn't disabled when requested."); michael@0: michael@0: renderer.cullFace("front"); michael@0: is(gl.getParameter(gl.CULL_FACE), true, michael@0: "The cull face wasn't enabled when requested."); michael@0: is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT, michael@0: "The cull face front mode wasn't set correctly."); michael@0: michael@0: renderer.cullFace("back"); michael@0: is(gl.getParameter(gl.CULL_FACE), true, michael@0: "The cull face wasn't enabled when requested."); michael@0: is(gl.getParameter(gl.CULL_FACE_MODE), gl.BACK, michael@0: "The cull face back mode wasn't set correctly."); michael@0: michael@0: renderer.cullFace("both"); michael@0: is(gl.getParameter(gl.CULL_FACE), true, michael@0: "The cull face wasn't enabled when requested."); michael@0: is(gl.getParameter(gl.CULL_FACE_MODE), gl.FRONT_AND_BACK, michael@0: "The cull face back mode wasn't set correctly."); michael@0: michael@0: renderer.cullFace(false); michael@0: is(gl.getParameter(gl.CULL_FACE), false, michael@0: "The cull face wasn't disabled when requested."); michael@0: michael@0: renderer.frontFace("cw"); michael@0: is(gl.getParameter(gl.FRONT_FACE), gl.CW, michael@0: "The front face cw mode wasn't set correctly."); michael@0: michael@0: renderer.frontFace("ccw"); michael@0: is(gl.getParameter(gl.FRONT_FACE), gl.CCW, michael@0: "The front face ccw mode wasn't set correctly."); michael@0: michael@0: renderer.blendMode("alpha"); michael@0: is(gl.getParameter(gl.BLEND), true, michael@0: "The blend mode wasn't enabled when requested."); michael@0: is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA, michael@0: "The soruce blend func wasn't set correctly."); michael@0: is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE_MINUS_SRC_ALPHA, michael@0: "The destination blend func wasn't set correctly."); michael@0: michael@0: renderer.blendMode("add"); michael@0: is(gl.getParameter(gl.BLEND), true, michael@0: "The blend mode wasn't enabled when requested."); michael@0: is(gl.getParameter(gl.BLEND_SRC_ALPHA), gl.SRC_ALPHA, michael@0: "The soruce blend func wasn't set correctly."); michael@0: is(gl.getParameter(gl.BLEND_DST_ALPHA), gl.ONE, michael@0: "The destination blend func wasn't set correctly."); michael@0: michael@0: renderer.blendMode(false); michael@0: is(gl.getParameter(gl.CULL_FACE), false, michael@0: "The blend mode wasn't disabled when requested."); michael@0: michael@0: michael@0: is(gl.getParameter(gl.CURRENT_PROGRAM), null, michael@0: "No program should be initially set in the WebGL context."); michael@0: michael@0: renderer.useColorShader(new renderer.VertexBuffer([1, 2, 3], 3)); michael@0: michael@0: ok(gl.getParameter(gl.CURRENT_PROGRAM) instanceof WebGLProgram, michael@0: "The correct program hasn't been set in the WebGL context."); michael@0: }