Nicolas Cannasse 11 anni fa
parent
commit
8c1887f09f

+ 0 - 91
doc/Render.hx

@@ -1,91 +0,0 @@
-// shader setup:
-	
-if( globals.constModified || shader.constModified ) {
-	shader.syncGlobalConsts(globals);
-	// will get/build an instance based on globals + const bits
-	// the instance is the eval'd version of the shader and has an unique ID
-}
-instances.push(shader.instance);
-
-// get/build a linked shader based on the unique instance identifiers and outputs
-// make sure that it's unique (use md5(toString) to prevent dups)
-var linked = getLinkedVersion(instances, ["output.pos", "output.color"]);
-
-shaders.sort(sortByLinkedId)
-for( s in linked ) {
-	if( s != prevId ) {
-		selectShader(s);
-		uploadParams(s.buildGlobals(globals));
-	}
-	// handle params and per-object globals (modelView, modelViewInv)
-	uploadParams(s.buildParams(globals));
-	render();g
-}
-
-// CHECK HOW RENDER PASS ARE DONE
-
-var passes : Map< String, Array<ObjectPass> > = collecObjectPasses();
-for( m in allPasses ) {
-	var objs = passes.get(m.name);
-	m.render(objs);
-}
-
-function renderPass() {
-	for( op in objectPasses ) {
-		op.pass.setup(...);
-		op.pass.assemble();
-	}
-	objectPass.sort(sortByShaderID);
-	beginPass();
-	for( op in objectPasses ) {
-		engine.selectPass(op.pass);
-		op.primitive.render();
-	}
-	endPass();
-}
-
-// ----------------------------
-// on mesh, passes are referenced by their name, not by a concrete object (decouple local setup from global one)
-
-var m = new Mesh(prim).material;
-
-(color white by default)
-m.texture = mytexture; // add the TextureShader on pass[0] if not already added
-m.addShader(new TextureMap(tex2)).additive = true; // second texture with additive
-m.castShadows = true; // add/remove the "shadowMap" pass with DepthShader
-m.receiveShadows = false; //add/remove the ShadowShader on pass[0]
-
-m.blendMode = Normal | Alpha | Additive
-	will set m.pass[0].name to "default" | "alpha" | "additive" and blendSrc/blendDst as well
-	-> blend / depth / culling / color are now in Pass properties, not in Material
-	
-mesh.addPass("outline",true/*inherit*/).addShader(new OutlineShader({ params }));
-mesh.removePass("outline");
-
-// on Scene, global setup as Array of passes
-
-var passes = scene.passes;
-passes.push(new ShadowMapPass("shadowMap",2048,...));
-
-Pass :
-	name : String; // a quel pass il s'execute
-	parentPass : inherit des modifiers (null si on ne veux pas garder les transforms par exemple)
-	shaders : Array<Shader> // this pass modifier
-	blendSrc/Dst
-	depthTest/Write
-	culling
-	colorMask
-
-ObjectPass:
-	pass : Pass (params already set)
-	prim : Primitive
-	obj : Object (for absPos, invAbsPos and error reporting)
-
-how are "globals" injected ?
-	before a pass is rendered, each pass is setup() using the current pass globals + the object specific globals
-	--> each pass can reinterpret the globals (eg : ShadowMap uses Light instead of Camera)
-	it is then assembled at pass rendering time (not before)
-	--> we need to know the pass output variable, global list and output selection to do so
-
-
-	

+ 0 - 306
doc/Shaders.hx

@@ -1,306 +0,0 @@
-
-//
-//  Resolve dependencies :
-// 		Given a Proto + X shader modifiers, build a complete shader and optimize it
-//		TODO : where to insert changes made by modifiers ?
-//		it seems necessary to build a code tree with dependencies in order to allow code permutation
-//		it is absolutely necessary to treat each struct field as a single variable (was not in HxSL)
-	
-Steps :
-	A) apply conditionals / reduce
-	B) calculate per-function dependencies
-	C) resolve order
-	D) eliminate code based on final pass requirement (output.color or another var)
-	E) calculate used vars and classify them
-
-	
-Variable types:
-
-	@global : no per-shader but per-pass (read-only)
-	@param : per-object parameter (read - only)
-	@input : vertex input
-	@var (default) : variable available between shaders (tracked for dependency)
-
-	Qualifiers:
-		
-	@private : for a @var, hide it from other shaders
-	@const : qualifier for param (default) or global. Mean that the value is eliminated at compilation
-
-Proto:
-	
-	// globals are injected by passes, they are not local to the per-shader-object. They are thus accessible in sub passes as well
-	@global var camera : {
-		var view : Matrix;
-		var proj : Matrix;
-		var projDiag : Float3; // [_11,_22,_33]
-		var viewProj : Matrix;
-		var inverseViewProj : Matrix;
-		@var var dir : Float3; // allow mix of variable types in structure (each variable is independent anyway)
-	};
-
-	@global var global : {
-		var time : Float;
-		var modelView : Matrix;
-		// ... other available globals in BasePass
-	};
-	
-	@input var input : {
-		var position : Float3;
-		var normal : Float3;
-	};
-	
-	var output : {
-		var position : Float4; // written in vertex
-		var color : Float4; // written in fragment
-	};
-	
-	// vars are always exported
-	
-	var transformedPosition : Float3;
-	var transformedNormal : Float3;
-	var projectedPosition : Float4;
-	var pixelColor : Float4;
-	
-	// each __init__ expr is out of order dependency-based
-	function __init__() {
-		transformedPosition = input.position * global.modelView;
-		projectedPosition = float4(transformedPosition, 1) * camera.viewProj;
-		transformedNormal = input.normal * global.modelView.m33;
-		camera.dir = (camera.position - transformedPosition).normalize();
-		pixelColor = color;
-	}
-	
-	function vertex() {
-		output.position = projectedPosition;
-	}
-	
-	function fragment() {
-		output.color = pixelColor;
-	}
-	
-	
-VertexColor
-	
-	@input var input : {
-		var color : Float3;
-	};
-	
-	var pixelColor : Float4;
-	
-	function vertex() {
-		vertexColor = input.color;
-	}
-	
-	function fragment() {
-		pixelColor.rgb *= vertexColor;
-	}
-
-
-TextureMaterial
-
-	// will add extra required fields to input
-	@input var input : {
-		var uv : Float2;
-	};
-	
-	@const var additive : Bool;
-	@const var killAlpha : Bool;
-	@param var killAlphaThreshold : Float;
-	
-	@param var texture : Texture;
-	var calculatedUV : Float2;
-	var pixelColor : Float4;
-	
-	function vertex() {
-		calculatedUV = input.uv;
-	}
-	
-	function fragment() {
-		var c = texture.get(calculatedUV);
-		if( killAlpha ) kill(c.a - killAlphaThreshold); // in multipass, we will have to specify if we want to keep the kill's or not
-		if( additive )
-			pixelColor += c;
-		else
-			pixelColor *= c;
-	}
-
-	// ajouter plusieurs TextureMaterial permet de faire du multiTexturing (à partir des même UV)
-
-AnimatedUV
-
-	var calculatedUV : Float2;
-	@global("global.time") var globalTime : Float;
-	@param var animationUV : Float2;
-	
-	function vertex() {
-		calculatedUV += animationUV * globalTime;
-	}
-
-	
-LightSystem:
-
-	// the light system is set by the pass setup, even if it's potentially per-object, it's still a global
-	@global var light : {
-		@const var perPixel : Bool;
-		var ambient : Float3;
-		var dirs : Array<{ dir : Float3, color : Float3 }>;
-		var points : Array<{ pos : Float3, color : Float3, att : Float3 }>;
-	};
-	
-	var transformedNormal : Float3; // will be tagged as read in either vertex or fragment depending on conditional
-	
-	@private var color : Float3; // will be tagged as written in vertex and read in fragment if !perPixel, or unused either
-	
-	var pixelColor : Float4; // will be tagged as read+written in fragment
-
-	function calcLight() {
-		var col = light.ambient;
-		var tn = transformedNormal.normalize();
-		for( d in light.dirs )
-			col += d.color * tn.dot(-d.dir).max(0);
-		for( p in light.points ) {
-			var d = transformedPosition - p.pos;
-			var dist2 = d.dot(d);
-			var dist = dist2.sqt();
-			col += p.color * (tn.dot(d).max(0) / (p.att.x * dist + p.att.y * dist2 + p.att.z * dist2 * dist));
-		}
-		return col;
-	}
-	
-	function vertex() {
-		if( !light.perPixel ) color = calcLight();
-	}
-	
-	function fragment() {
-		if( light.perPixel )
-			pixelColor.rgb *= calcLight();
-		else
-			pixelColor.rgb *= color;
-	}
-	
-	// DEPENDENCY:
-		Vertex:
-		READ transformedNormal   |-> must be inserted after all vertex that write transformNormals have been done
-		READ transformedPosition |
-		WRITE lightColor -> must be inserted before any vertex that reads light color
-		Fragment:
-		READ lightColor -> must be inserted after all fragments that write these two
-		READ+WRITE pixelColor -> must be inserted after it's been written first, but then keep the shader order
-		
-	CONFLICT if a program read lightColor and write transformNormal (unresolved cycle)
-	
-	CONFLICT if a program inserted after WRITE both lightColor and pixelColor:
-		writing lightColor will put it before, but since it also write pixelColor it should be after to enforce evaluation order
-		the user should then put it before
-
-	
-Outline
-
-	// Param are always local
-	@param var color : Float4;
-	@param var power : Float;
-	@param var size : Float;
-	
-	var camera : {
-		var projDiag : Float3;
-		var dir : Float3;
-	};
-	var transformedNormal : Float3;
-
-	function vertex() {
-		transformedPosition.xy += transformedNormal.xy * camera.projDiag.xy * size;
-	}
-	
-	function fragment() {
-		var e = 1 - transformedNormal.normalize().dot(camera.dir.normalize());
-		output.color = color * e.pow(power);
-	}
-	
-Skin
-
-	@input var input : {
-		pos : Float3,
-		normal : Float3,
-		weights : Float3,
-		indexes : Int,
-	};
-	
-	var transformedPosition : Float3;
-	var transformedNormal : Float3;
-	
-	function vertex() {
-		var p = input.pos, n = input.normal;
-		transformedPosition = p * input.weights.x * skinMatrixes[input.indexes.x * (255 * 3)] + p * input.weights.y * skinMatrixes[input.indexes.y * (255 * 3)] + p * input.weights.z * skinMatrixes[input.indexes.z * (255 * 3)];
-		transformedNormal = n * input.weights.x * skinMatrixes[input.indexes.x * (255 * 3)].m33 + n * input.weights.y * skinMatrixes[input.indexes.y * (255 * 3)].m33 + n * input.weights.z * skinMatrixes[input.indexes.z * (255 * 3)].m33;
-	}
-	
-	// will write TP/TN, hence disabling proto init
-
-ApplyShadow
-
-	@global var shadow : {
-		var map : Texture;
-		var color : Float3;
-		var power : Float;
-		var lightProj : Matrix;
-		var lightCenter : Matrix;
-	};
-
-	// Nullable params, allow to check them in shaders. Will create a isNull Const automatically
-	// actually use the global values unless object-specific local values are defined
-	var shadowColor : Param<Null<Float3>>;
-	var shadowPower : Param<Null<Float>>;
-
-	var pixelColor : Float4;
-
-	@:private var tshadowPos : Float3;
-	
-	function vertex() {
-		tshadowPos = float4(transformedPosition,1) * shadow.lightProj * shadow.lightCenter;
-	}
-	
-	function fragment() {
-		var s = exp( (shadowPower == null ? shadow.power : shadowPower) * (tshadowPos.z - shadow.map.get(tshadowPos.xy).dot([1, 1 / 255, 1 / (255 * 255), 1 / (255 * 255 * 255)]))).sat();
-		pixelColor.rgb *= (1 - s) * (shadowColor == null ? shadow.color : shadowColor) + s.xxx;
-	}
-
-DepthMap
-
-	@global var depthDelta : Float;
-	@:private var distance : Float;
-	
-	// the pass setup will have to declare that it will write distanceColor to its rendertarget
-	var depthColor : Float4;
-
-	function vertex() {
-		distance = projectedPosition.z / projectedPosition.w + depthDelta;
-	}
-	
-	function fragment() {
-		var color : Float4 = (distance.xxxx * [1,255,255*255,255*255*255]).frac();
-		depthColor = color - color.yzww * [1 / 255, 1 / 255, 1 / 255, 0];
-	}
-
-DistanceMap
-
-	@global var distance : {
-		var center : Float3;
-		var scale : Float;
-		var power : Float;
-	};
-
-	@private var dist : Float3;
-	
-	// the pass will have to declare that it will write distanceColor to its rendertarget
-	var distanceColor : Float4;
-
-	function vertex() {
-		dist = (transformedPosition - center).abs();
-	}
-	
-	function fragment() {
-		var d = (dist.length() * scale).pow(power);
-		var color : Float4 = (d.xxxx * [1,255,255*255,255*255*255]).frac();
-		distanceColor = color - color.yzww * [1 / 255, 1 / 255, 1 / 255, 0];
-	}
-

+ 0 - 1
extraParams.hxml

@@ -1 +0,0 @@
--swf-version 11.6

+ 2 - 1
h3d/mat/Material.hx

@@ -11,7 +11,7 @@ class Material {
 		this.passes = passes;
 	}
 	
-	public function addPass( p : Pass ) {
+	public function addPass<T:Pass>( p : T ) : T {
 		var prev = null, cur = passes;
 		while( cur != null ) {
 			prev = cur;
@@ -22,6 +22,7 @@ class Material {
 		else
 			prev.nextPass = p;
 		p.nextPass = null;
+		return p;
 	}
 	
 	public function removePass( p : Pass ) {

+ 2 - 1
h3d/pass/Pass.hx

@@ -55,8 +55,9 @@ class Pass {
 		this.colorMask = (r?1:0) | (g?2:0) | (b?4:0) | (a?8:0);
 	}
 	
-	public function addShader(s) {
+	public function addShader<T:hxsl.Shader>(s:T) : T {
 		shaders.push(s);
+		return s;
 	}
 	
 	public function removeShader(s) {

+ 4 - 5
haxelib.json

@@ -1,10 +1,9 @@
 {
-	"name" : "h3d",
-	"url" : "https://github.com/ncannasse/h3d",
+	"name" : "heaps",
+	"url" : "http://heaps.io",
 	"license" : "BSD",
-    "description" : "Lightweight Stage3D engine",
+    "description" : "The GPU Game Framework",
     "version" : "0.0.1",
 	"releasenote" : "",
-	"contributors" : ["ncannasse"],
-    "dependencies" : { "hxsl" : "" }
+	"contributors" : ["ncannasse"]
 }

+ 1 - 1
hxsl/Types.hx

@@ -1,6 +1,6 @@
 package hxsl;
 
-#if h3d
+#if true
 
 typedef Vec = h3d.Vector;
 typedef IVec = Array<Int>;

+ 0 - 1
index.html

@@ -2,7 +2,6 @@
 <body style="margin:0;padding:0;background-color:black">
 	
 	<canvas id="webgl" style="width:100%;height:100%"></canvas>
-	<script type="text/javascript" src="webgl-debug.js"></script>
 	<script type="text/javascript" src="engine.js"></script>
 	
 </body>

+ 0 - 0
test/Test.hx → samples/hxsl/Test.hx


+ 0 - 0
hxsl.html → samples/hxsl/hxsl.html


+ 1 - 2
hxsl.hxml → samples/hxsl/hxsl.hxml

@@ -2,5 +2,4 @@
 -js hxsl.js
 -main Test
 -dce full
--lib h3d
--cp .
+-lib heaps

+ 1 - 1
hxsl.hxproj → samples/hxsl/hxsl.hxproj

@@ -23,7 +23,7 @@
     <option flashStrict="True" />
     <option mainClass="Test" />
     <option enabledebug="False" />
-    <option additional="-dce full&#xA;-lib h3d&#xA;-cp ." />
+    <option additional="-dce full&#xA;-lib heaps" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>

+ 0 - 211
tools/xbx/XBXMake.hx

@@ -1,211 +0,0 @@
-import h3d.fbx.*;
-import h3d.fbx.Data;
-
-class XBXMake
-{
-	var inFile : String;
-	var outputFile : Null<String>;
-	var verbose:Bool;
-	var nozip:Bool;
-	var doTest:Bool;
-	function new()
-	{
-		
-	}
-
-	function usage() {
-		neko.Lib.println( "neko XBXMake.n <file> [-o|--output <file> ] [-z] ");
-		neko.Lib.println( "writes FBX <file> in XBX which is basically a stripped binary version of it." );
-		neko.Lib.println( "--no-zip impeach terminal fiel for compression (useful for debug)" );
-	}
-	
-	public function make(prm:Array<String>)
-	{
-		var params = prm;
-
-		for ( a in 0...params.length )
-		{
-			var arg = params[a];
-			if (null == arg) continue;
-			
-			switch(arg)
-			{
-				case "--usage", "/?":
-					usage();
-					return;
-					
-				case "-o", "--output":
-					outputFile = params[a + 1];
-					params.remove( arg );
-					params.remove( params[a + 1] );
-		
-				case "--no-zip": nozip = true;
-				case "--test": doTest = true;
-				case "-v", "--verbose":verbose=true;
-				default:
-					inFile = arg;
-			}
-		}
-		
-		if( inFile == null ) {
-			usage();
-			return;
-		}
-		
-		var idx = inFile.toLowerCase().lastIndexOf(".fbx");
-		
-		if ( idx < 0 )
-			throw inFile + " is not an Fbx file";
-		
-		if ( outputFile == null)
-			outputFile = inFile.substr(0, idx) + ".xbx";
-		
-		var f = sys.io.File.read( inFile, true);
-		var fbx = h3d.fbx.Parser.parse( f.readAll().toString() );
-		f.close();
-		
-		var bout = new haxe.io.BytesOutput();
-		var writer = new h3d.fbx.XBXWriter( bout );
-		writer.write(fbx);
-	
-		var b = bout.getBytes();
-		
-		{
-			var entry : format.zip.Data.Entry =
-			{
-				fileName:"fbx_root",
-				fileSize : b.length,
-				fileTime:Date.now(),
-				compressed:false,
-				dataSize:0,
-				data:b,
-				crc32:haxe.crypto.Crc32.make(b),
-				extraFields:new List(),
-			}
-			
-			var zb = new haxe.io.BytesOutput();
-			var zw = new format.zip.Writer(zb);
-			var  nl = new List();
-			
-			if( !nozip )
-				format.zip.Tools.compress( entry, 9);
-				
-			nl.add( entry);
-			zw.write(nl);
-			var file = sys.io.File.write( outputFile, true);
-			file.write( zb.getBytes() );
-			file.flush();
-			file.close();
-			
-			if ( doTest )
-			{
-				var f = sys.io.File.read( outputFile, true);
-				var zr = new format.zip.Reader( f);
-				var entries = zr.read();
-				var p = entries.first();
-				
-				if ( p.compressed )
-					format.zip.Tools.uncompress( p );
-
-				var buf = p.data;
-
-				var inp = new haxe.io.BytesInput( buf );
-				var reader = new XBXReader( inp );
-				
-				function explore(n:h3d.fbx.Data.FbxNode)
-				{
-					trace( n.name );
-					trace( n.props);
-					for (n in n.childs)
-						explore(n);
-				}
-				
-				var rfbx = reader.read();
-				
-				function cmp(t0:FbxNode,t1:FbxNode)
-				{
-					if ( t0.name != t1.name)
-					{
-						trace( t0.name + " != " + t1.name );
-						return false;
-					}
-					
-					if ( t0.childs.length != t1.childs.length) {
-						trace( t0.name + " has not same child num to its counterpart" );
-						return false;
-					}
-					
-					for ( idx in 0...t0.childs.length)
-					{
-						if ( !cmp( t0.childs[idx], t1.childs[idx] ))
-						{
-							return false;
-						}
-					}
-					
-					if ( t0.props.length != t1.props.length) {
-						trace( t0.name + " has not same prop num to its counterpart" );
-					}
-					
-					for ( idx in 0...t0.props.length)
-					{
-						var p0 = t0.props[idx];
-						var p1 = t1.props[idx];
-						
-						var msg = function(s) trace( "prop (" + 	idx+") of " + t0.name + " has not same value as its counterpart "+s );
-						
-						switch( p0 )
-						{
-							case PInt(v0): switch(p1) { case PInt(v1): if (v0 != v1) { msg( v0 + "<>" + v1); return false; }  default: msg("type err PInt"); return false; };
-							case PFloat(v0): switch(p1) { case PFloat(v1): if (v0 != v1) { msg( v0 + "<>" + v1); return false; }  default: msg("type err PFloat"); return false; };
-							case PString(v0): switch(p1) { case PString(v1): if (v0 != v1) { msg( v0 + "<>" + v1); return false; }  default: msg("type err PString"); return false; };
-							case PIdent(v0): switch(p1) { case PIdent(v1): if (v0 != v1) { msg( v0 + "<>" + v1); return false; }  default: msg("type err PIdent"); return false; };
-							
-							case PInts(v0):
-								switch(p1) {
-									default: msg("type err PInts"); return false;
-									case PInts(v1):
-										for ( idx in 0...v0.length)
-											if ( v0[idx] != v1[idx])
-											{
-												msg("mismtched value in ints at index " + idx + " " + v0[idx] + "<>" + v1[idx]);
-												return false;
-											}
-								}
-								
-							case PFloats(v0):
-								switch(p1) {
-									default: msg("type err PFloats "); return false;
-									case PFloats(v1):
-										for ( idx in 0...v0.length)
-											if ( Math.abs( v0[idx] - v1[idx]) > 1e-3 )
-											{
-												msg("mismtched value in floats at index " + idx + " " + v0[idx] + "<>" + v1[idx]);
-												return false;
-											}
-								}
-						}
-						
-					}
-				
-					
-						
-					return true;
-				}
-			
-				cmp( fbx, rfbx);
-			}
-		}
-	}
-	
-	
-	public static function main()
-	{
-		new XBXMake().make(  Sys.args().copy() );
-	}
-	
-	public static function test()
-	{
-		
-	}
-}

+ 0 - 4
tools/xbx/XBXMake.hxml

@@ -1,4 +0,0 @@
--cp ../..
--neko XBXMake.n
--main XBXMake
--lib format

+ 0 - 52
tools/xbx/XBXMake.hxproj

@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<project version="2">
-  <!-- Output SWF options -->
-  <output>
-    <movie outputType="Application" />
-    <movie input="" />
-    <movie path="XBXMake.n" />
-    <movie fps="0" />
-    <movie width="0" />
-    <movie height="0" />
-    <movie version="1" />
-    <movie minorVersion="0" />
-    <movie platform="Neko" />
-    <movie background="#FFFFFF" />
-  </output>
-  <!-- Other classes to be compiled into your SWF -->
-  <classpaths>
-    <class path="..\.." />
-  </classpaths>
-  <!-- Build options -->
-  <build>
-    <option directives="" />
-    <option flashStrict="False" />
-    <option mainClass="XBXMake" />
-    <option enabledebug="False" />
-    <option additional="-lib format" />
-  </build>
-  <!-- haxelib libraries -->
-  <haxelib>
-    <!-- example: <library name="..." /> -->
-  </haxelib>
-  <!-- Class files to compile (other referenced classes will automatically be included) -->
-  <compileTargets>
-    <compile path="src\Main.hx" />
-  </compileTargets>
-  <!-- Paths to exclude from the Project Explorer tree -->
-  <hiddenPaths>
-    <!-- example: <hidden path="..." /> -->
-  </hiddenPaths>
-  <!-- Executed before build -->
-  <preBuildCommand />
-  <!-- Executed after build -->
-  <postBuildCommand alwaysRun="False" />
-  <!-- Other project options -->
-  <options>
-    <option showHiddenPaths="False" />
-    <option testMovie="Custom" />
-    <option testMovieCommand="run.bat" />
-  </options>
-  <!-- Plugin storage -->
-  <storage />
-</project>

File diff suppressed because it is too large
+ 0 - 346
tools/xbx/boneTest3DS.fbx


BIN
tools/xbx/boneTest3DS.xbx


+ 0 - 900
webgl-debug.js

@@ -1,900 +0,0 @@
-/*
-** Copyright (c) 2012 The Khronos Group Inc.
-**
-** Permission is hereby granted, free of charge, to any person obtaining a
-** copy of this software and/or associated documentation files (the
-** "Materials"), to deal in the Materials without restriction, including
-** without limitation the rights to use, copy, modify, merge, publish,
-** distribute, sublicense, and/or sell copies of the Materials, and to
-** permit persons to whom the Materials are furnished to do so, subject to
-** the following conditions:
-**
-** The above copyright notice and this permission notice shall be included
-** in all copies or substantial portions of the Materials.
-**
-** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
-*/
-
-// Various functions for helping debug WebGL apps.
-
-WebGLDebugUtils = function() {
-
-/**
- * Wrapped logging function.
- * @param {string} msg Message to log.
- */
-var log = function(msg) {
-  if (window.console && window.console.log) {
-    window.console.log(msg);
-  }
-};
-
-/**
- * Wrapped error logging function.
- * @param {string} msg Message to log.
- */
-var error = function(msg) {
-  if (window.console && window.console.error) {
-    window.console.error(msg);
-  } else {
-    log(msg);
-  }
-};
-
-
-/**
- * Which arguments are enums based on the number of arguments to the function.
- * So
- *    'texImage2D': {
- *       9: { 0:true, 2:true, 6:true, 7:true },
- *       6: { 0:true, 2:true, 3:true, 4:true },
- *    },
- *
- * means if there are 9 arguments then 6 and 7 are enums, if there are 6
- * arguments 3 and 4 are enums
- *
- * @type {!Object.<number, !Object.<number, string>}}
- */
-var glValidEnumContexts = {
-  // Generic setters and getters
-
-  'enable': {1: { 0:true }},
-  'disable': {1: { 0:true }},
-  'getParameter': {1: { 0:true }},
-
-  // Rendering
-
-  'drawArrays': {3:{ 0:true }},
-  'drawElements': {4:{ 0:true, 2:true }},
-
-  // Shaders
-
-  'createShader': {1: { 0:true }},
-  'getShaderParameter': {2: { 1:true }},
-  'getProgramParameter': {2: { 1:true }},
-  'getShaderPrecisionFormat': {2: { 0: true, 1:true }},
-
-  // Vertex attributes
-
-  'getVertexAttrib': {2: { 1:true }},
-  'vertexAttribPointer': {6: { 2:true }},
-
-  // Textures
-
-  'bindTexture': {2: { 0:true }},
-  'activeTexture': {1: { 0:true }},
-  'getTexParameter': {2: { 0:true, 1:true }},
-  'texParameterf': {3: { 0:true, 1:true }},
-  'texParameteri': {3: { 0:true, 1:true, 2:true }},
-  'texImage2D': {
-     9: { 0:true, 2:true, 6:true, 7:true },
-     6: { 0:true, 2:true, 3:true, 4:true },
-  },
-  'texSubImage2D': {
-    9: { 0:true, 6:true, 7:true },
-    7: { 0:true, 4:true, 5:true },
-  },
-  'copyTexImage2D': {8: { 0:true, 2:true }},
-  'copyTexSubImage2D': {8: { 0:true }},
-  'generateMipmap': {1: { 0:true }},
-  'compressedTexImage2D': {7: { 0: true, 2:true }},
-  'compressedTexSubImage2D': {8: { 0: true, 6:true }},
-
-  // Buffer objects
-
-  'bindBuffer': {2: { 0:true }},
-  'bufferData': {3: { 0:true, 2:true }},
-  'bufferSubData': {3: { 0:true }},
-  'getBufferParameter': {2: { 0:true, 1:true }},
-
-  // Renderbuffers and framebuffers
-
-  'pixelStorei': {2: { 0:true, 1:true }},
-  'readPixels': {7: { 4:true, 5:true }},
-  'bindRenderbuffer': {2: { 0:true }},
-  'bindFramebuffer': {2: { 0:true }},
-  'checkFramebufferStatus': {1: { 0:true }},
-  'framebufferRenderbuffer': {4: { 0:true, 1:true, 2:true }},
-  'framebufferTexture2D': {5: { 0:true, 1:true, 2:true }},
-  'getFramebufferAttachmentParameter': {3: { 0:true, 1:true, 2:true }},
-  'getRenderbufferParameter': {2: { 0:true, 1:true }},
-  'renderbufferStorage': {4: { 0:true, 1:true }},
-
-  // Frame buffer operations (clear, blend, depth test, stencil)
-
-  'clear': {1: { 0:true }},
-  'depthFunc': {1: { 0:true }},
-  'blendFunc': {2: { 0:true, 1:true }},
-  'blendFuncSeparate': {4: { 0:true, 1:true, 2:true, 3:true }},
-  'blendEquation': {1: { 0:true }},
-  'blendEquationSeparate': {2: { 0:true, 1:true }},
-  'stencilFunc': {3: { 0:true }},
-  'stencilFuncSeparate': {4: { 0:true, 1:true }},
-  'stencilMaskSeparate': {2: { 0:true }},
-  'stencilOp': {3: { 0:true, 1:true, 2:true }},
-  'stencilOpSeparate': {4: { 0:true, 1:true, 2:true, 3:true }},
-
-  // Culling
-
-  'cullFace': {1: { 0:true }},
-  'frontFace': {1: { 0:true }},
-};
-
-/**
- * Map of numbers to names.
- * @type {Object}
- */
-var glEnums = null;
-
-/**
- * Initializes this module. Safe to call more than once.
- * @param {!WebGLRenderingContext} ctx A WebGL context. If
- *    you have more than one context it doesn't matter which one
- *    you pass in, it is only used to pull out constants.
- */
-function init(ctx) {
-  if (glEnums == null) {
-    glEnums = { };
-    for (var propertyName in ctx) {
-      if (typeof ctx[propertyName] == 'number') {
-        glEnums[ctx[propertyName]] = propertyName;
-      }
-    }
-  }
-}
-
-/**
- * Checks the utils have been initialized.
- */
-function checkInit() {
-  if (glEnums == null) {
-    throw 'WebGLDebugUtils.init(ctx) not called';
-  }
-}
-
-/**
- * Returns true or false if value matches any WebGL enum
- * @param {*} value Value to check if it might be an enum.
- * @return {boolean} True if value matches one of the WebGL defined enums
- */
-function mightBeEnum(value) {
-  checkInit();
-  return (glEnums[value] !== undefined);
-}
-
-/**
- * Gets an string version of an WebGL enum.
- *
- * Example:
- *   var str = WebGLDebugUtil.glEnumToString(ctx.getError());
- *
- * @param {number} value Value to return an enum for
- * @return {string} The string version of the enum.
- */
-function glEnumToString(value) {
-  checkInit();
-  var name = glEnums[value];
-  return (name !== undefined) ? ("gl." + name) :
-      ("/*UNKNOWN WebGL ENUM*/ 0x" + value.toString(16) + "");
-}
-
-/**
- * Returns the string version of a WebGL argument.
- * Attempts to convert enum arguments to strings.
- * @param {string} functionName the name of the WebGL function.
- * @param {number} numArgs the number of arguments passed to the function.
- * @param {number} argumentIndx the index of the argument.
- * @param {*} value The value of the argument.
- * @return {string} The value as a string.
- */
-function glFunctionArgToString(functionName, numArgs, argumentIndex, value) {
-  var funcInfo = glValidEnumContexts[functionName];
-  if (funcInfo !== undefined) {
-    var funcInfo = funcInfo[numArgs];
-    if (funcInfo !== undefined) {
-      if (funcInfo[argumentIndex]) {
-        return glEnumToString(value);
-      }
-    }
-  }
-  if (value === null) {
-    return "null";
-  } else if (value === undefined) {
-    return "undefined";
-  } else {
-    return value.toString();
-  }
-}
-
-/**
- * Converts the arguments of a WebGL function to a string.
- * Attempts to convert enum arguments to strings.
- *
- * @param {string} functionName the name of the WebGL function.
- * @param {number} args The arguments.
- * @return {string} The arguments as a string.
- */
-function glFunctionArgsToString(functionName, args) {
-  // apparently we can't do args.join(",");
-  var argStr = "";
-  var numArgs = args.length;
-  for (var ii = 0; ii < numArgs; ++ii) {
-    argStr += ((ii == 0) ? '' : ', ') +
-        glFunctionArgToString(functionName, numArgs, ii, args[ii]);
-  }
-  return argStr;
-};
-
-
-function makePropertyWrapper(wrapper, original, propertyName) {
-  //log("wrap prop: " + propertyName);
-  wrapper.__defineGetter__(propertyName, function() {
-    return original[propertyName];
-  });
-  // TODO(gmane): this needs to handle properties that take more than
-  // one value?
-  wrapper.__defineSetter__(propertyName, function(value) {
-    //log("set: " + propertyName);
-    original[propertyName] = value;
-  });
-}
-
-// Makes a function that calls a function on another object.
-function makeFunctionWrapper(original, functionName) {
-  //log("wrap fn: " + functionName);
-  var f = original[functionName];
-  return function() {
-    //log("call: " + functionName);
-    var result = f.apply(original, arguments);
-    return result;
-  };
-}
-
-/**
- * Given a WebGL context returns a wrapped context that calls
- * gl.getError after every command and calls a function if the
- * result is not gl.NO_ERROR.
- *
- * @param {!WebGLRenderingContext} ctx The webgl context to
- *        wrap.
- * @param {!function(err, funcName, args): void} opt_onErrorFunc
- *        The function to call when gl.getError returns an
- *        error. If not specified the default function calls
- *        console.log with a message.
- * @param {!function(funcName, args): void} opt_onFunc The
- *        function to call when each webgl function is called.
- *        You can use this to log all calls for example.
- */
-function makeDebugContext(ctx, opt_onErrorFunc, opt_onFunc) {
-  init(ctx);
-  opt_onErrorFunc = opt_onErrorFunc || function(err, functionName, args) {
-        // apparently we can't do args.join(",");
-        var argStr = "";
-        var numArgs = args.length;
-        for (var ii = 0; ii < numArgs; ++ii) {
-          argStr += ((ii == 0) ? '' : ', ') +
-              glFunctionArgToString(functionName, numArgs, ii, args[ii]);
-        }
-        error("WebGL error "+ glEnumToString(err) + " in "+ functionName +
-              "(" + argStr + ")");
-      };
-
-  // Holds booleans for each GL error so after we get the error ourselves
-  // we can still return it to the client app.
-  var glErrorShadow = { };
-
-  // Makes a function that calls a WebGL function and then calls getError.
-  function makeErrorWrapper(ctx, functionName) {
-    return function() {
-      if (opt_onFunc) {
-        opt_onFunc(functionName, arguments);
-      }
-      var result = ctx[functionName].apply(ctx, arguments);
-      var err = ctx.getError();
-      if (err != 0) {
-        glErrorShadow[err] = true;
-        opt_onErrorFunc(err, functionName, arguments);
-      }
-      return result;
-    };
-  }
-
-  // Make a an object that has a copy of every property of the WebGL context
-  // but wraps all functions.
-  var wrapper = {};
-  for (var propertyName in ctx) {
-    if (typeof ctx[propertyName] == 'function') {
-       wrapper[propertyName] = makeErrorWrapper(ctx, propertyName);
-     } else {
-       makePropertyWrapper(wrapper, ctx, propertyName);
-     }
-  }
-
-  // Override the getError function with one that returns our saved results.
-  wrapper.getError = function() {
-    for (var err in glErrorShadow) {
-      if (glErrorShadow.hasOwnProperty(err)) {
-        if (glErrorShadow[err]) {
-          glErrorShadow[err] = false;
-          return err;
-        }
-      }
-    }
-    return ctx.NO_ERROR;
-  };
-
-  return wrapper;
-}
-
-function resetToInitialState(ctx) {
-  var numAttribs = ctx.getParameter(ctx.MAX_VERTEX_ATTRIBS);
-  var tmp = ctx.createBuffer();
-  ctx.bindBuffer(ctx.ARRAY_BUFFER, tmp);
-  for (var ii = 0; ii < numAttribs; ++ii) {
-    ctx.disableVertexAttribArray(ii);
-    ctx.vertexAttribPointer(ii, 4, ctx.FLOAT, false, 0, 0);
-    ctx.vertexAttrib1f(ii, 0);
-  }
-  ctx.deleteBuffer(tmp);
-
-  var numTextureUnits = ctx.getParameter(ctx.MAX_TEXTURE_IMAGE_UNITS);
-  for (var ii = 0; ii < numTextureUnits; ++ii) {
-    ctx.activeTexture(ctx.TEXTURE0 + ii);
-    ctx.bindTexture(ctx.TEXTURE_CUBE_MAP, null);
-    ctx.bindTexture(ctx.TEXTURE_2D, null);
-  }
-
-  ctx.activeTexture(ctx.TEXTURE0);
-  ctx.useProgram(null);
-  ctx.bindBuffer(ctx.ARRAY_BUFFER, null);
-  ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, null);
-  ctx.bindFramebuffer(ctx.FRAMEBUFFER, null);
-  ctx.bindRenderbuffer(ctx.RENDERBUFFER, null);
-  ctx.disable(ctx.BLEND);
-  ctx.disable(ctx.CULL_FACE);
-  ctx.disable(ctx.DEPTH_TEST);
-  ctx.disable(ctx.DITHER);
-  ctx.disable(ctx.SCISSOR_TEST);
-  ctx.blendColor(0, 0, 0, 0);
-  ctx.blendEquation(ctx.FUNC_ADD);
-  ctx.blendFunc(ctx.ONE, ctx.ZERO);
-  ctx.clearColor(0, 0, 0, 0);
-  ctx.clearDepth(1);
-  ctx.clearStencil(-1);
-  ctx.colorMask(true, true, true, true);
-  ctx.cullFace(ctx.BACK);
-  ctx.depthFunc(ctx.LESS);
-  ctx.depthMask(true);
-  ctx.depthRange(0, 1);
-  ctx.frontFace(ctx.CCW);
-  ctx.hint(ctx.GENERATE_MIPMAP_HINT, ctx.DONT_CARE);
-  ctx.lineWidth(1);
-  ctx.pixelStorei(ctx.PACK_ALIGNMENT, 4);
-  ctx.pixelStorei(ctx.UNPACK_ALIGNMENT, 4);
-  ctx.pixelStorei(ctx.UNPACK_FLIP_Y_WEBGL, false);
-  ctx.pixelStorei(ctx.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
-  // TODO: Delete this IF.
-  if (ctx.UNPACK_COLORSPACE_CONVERSION_WEBGL) {
-    ctx.pixelStorei(ctx.UNPACK_COLORSPACE_CONVERSION_WEBGL, ctx.BROWSER_DEFAULT_WEBGL);
-  }
-  ctx.polygonOffset(0, 0);
-  ctx.sampleCoverage(1, false);
-  ctx.scissor(0, 0, ctx.canvas.width, ctx.canvas.height);
-  ctx.stencilFunc(ctx.ALWAYS, 0, 0xFFFFFFFF);
-  ctx.stencilMask(0xFFFFFFFF);
-  ctx.stencilOp(ctx.KEEP, ctx.KEEP, ctx.KEEP);
-  ctx.viewport(0, 0, ctx.canvas.width, ctx.canvas.height);
-  ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT | ctx.STENCIL_BUFFER_BIT);
-
-  // TODO: This should NOT be needed but Firefox fails with 'hint'
-  while(ctx.getError());
-}
-
-function makeLostContextSimulatingCanvas(canvas) {
-  var unwrappedContext_;
-  var wrappedContext_;
-  var onLost_ = [];
-  var onRestored_ = [];
-  var wrappedContext_ = {};
-  var contextId_ = 1;
-  var contextLost_ = false;
-  var resourceId_ = 0;
-  var resourceDb_ = [];
-  var numCallsToLoseContext_ = 0;
-  var numCalls_ = 0;
-  var canRestore_ = false;
-  var restoreTimeout_ = 0;
-
-  // Holds booleans for each GL error so can simulate errors.
-  var glErrorShadow_ = { };
-
-  canvas.getContext = function(f) {
-    return function() {
-      var ctx = f.apply(canvas, arguments);
-      // Did we get a context and is it a WebGL context?
-      if (ctx instanceof WebGLRenderingContext) {
-        if (ctx != unwrappedContext_) {
-          if (unwrappedContext_) {
-            throw "got different context"
-          }
-          unwrappedContext_ = ctx;
-          wrappedContext_ = makeLostContextSimulatingContext(unwrappedContext_);
-        }
-        return wrappedContext_;
-      }
-      return ctx;
-    }
-  }(canvas.getContext);
-
-  function wrapEvent(listener) {
-    if (typeof(listener) == "function") {
-      return listener;
-    } else {
-      return function(info) {
-        listener.handleEvent(info);
-      }
-    }
-  }
-
-  var addOnContextLostListener = function(listener) {
-    onLost_.push(wrapEvent(listener));
-  };
-
-  var addOnContextRestoredListener = function(listener) {
-    onRestored_.push(wrapEvent(listener));
-  };
-
-
-  function wrapAddEventListener(canvas) {
-    var f = canvas.addEventListener;
-    canvas.addEventListener = function(type, listener, bubble) {
-      switch (type) {
-        case 'webglcontextlost':
-          addOnContextLostListener(listener);
-          break;
-        case 'webglcontextrestored':
-          addOnContextRestoredListener(listener);
-          break;
-        default:
-          f.apply(canvas, arguments);
-      }
-    };
-  }
-
-  wrapAddEventListener(canvas);
-
-  canvas.loseContext = function() {
-    if (!contextLost_) {
-      contextLost_ = true;
-      numCallsToLoseContext_ = 0;
-      ++contextId_;
-      while (unwrappedContext_.getError());
-      clearErrors();
-      glErrorShadow_[unwrappedContext_.CONTEXT_LOST_WEBGL] = true;
-      var event = makeWebGLContextEvent("context lost");
-      var callbacks = onLost_.slice();
-      setTimeout(function() {
-          //log("numCallbacks:" + callbacks.length);
-          for (var ii = 0; ii < callbacks.length; ++ii) {
-            //log("calling callback:" + ii);
-            callbacks[ii](event);
-          }
-          if (restoreTimeout_ >= 0) {
-            setTimeout(function() {
-                canvas.restoreContext();
-              }, restoreTimeout_);
-          }
-        }, 0);
-    }
-  };
-
-  canvas.restoreContext = function() {
-    if (contextLost_) {
-      if (onRestored_.length) {
-        setTimeout(function() {
-            if (!canRestore_) {
-              throw "can not restore. webglcontestlost listener did not call event.preventDefault";
-            }
-            freeResources();
-            resetToInitialState(unwrappedContext_);
-            contextLost_ = false;
-            numCalls_ = 0;
-            canRestore_ = false;
-            var callbacks = onRestored_.slice();
-            var event = makeWebGLContextEvent("context restored");
-            for (var ii = 0; ii < callbacks.length; ++ii) {
-              callbacks[ii](event);
-            }
-          }, 0);
-      }
-    }
-  };
-
-  canvas.loseContextInNCalls = function(numCalls) {
-    if (contextLost_) {
-      throw "You can not ask a lost contet to be lost";
-    }
-    numCallsToLoseContext_ = numCalls_ + numCalls;
-  };
-
-  canvas.getNumCalls = function() {
-    return numCalls_;
-  };
-
-  canvas.setRestoreTimeout = function(timeout) {
-    restoreTimeout_ = timeout;
-  };
-
-  function isWebGLObject(obj) {
-    //return false;
-    return (obj instanceof WebGLBuffer ||
-            obj instanceof WebGLFramebuffer ||
-            obj instanceof WebGLProgram ||
-            obj instanceof WebGLRenderbuffer ||
-            obj instanceof WebGLShader ||
-            obj instanceof WebGLTexture);
-  }
-
-  function checkResources(args) {
-    for (var ii = 0; ii < args.length; ++ii) {
-      var arg = args[ii];
-      if (isWebGLObject(arg)) {
-        return arg.__webglDebugContextLostId__ == contextId_;
-      }
-    }
-    return true;
-  }
-
-  function clearErrors() {
-    var k = Object.keys(glErrorShadow_);
-    for (var ii = 0; ii < k.length; ++ii) {
-      delete glErrorShadow_[k];
-    }
-  }
-
-  function loseContextIfTime() {
-    ++numCalls_;
-    if (!contextLost_) {
-      if (numCallsToLoseContext_ == numCalls_) {
-        canvas.loseContext();
-      }
-    }
-  }
-
-  // Makes a function that simulates WebGL when out of context.
-  function makeLostContextFunctionWrapper(ctx, functionName) {
-    var f = ctx[functionName];
-    return function() {
-      // log("calling:" + functionName);
-      // Only call the functions if the context is not lost.
-      loseContextIfTime();
-      if (!contextLost_) {
-        //if (!checkResources(arguments)) {
-        //  glErrorShadow_[wrappedContext_.INVALID_OPERATION] = true;
-        //  return;
-        //}
-        var result = f.apply(ctx, arguments);
-        return result;
-      }
-    };
-  }
-
-  function freeResources() {
-    for (var ii = 0; ii < resourceDb_.length; ++ii) {
-      var resource = resourceDb_[ii];
-      if (resource instanceof WebGLBuffer) {
-        unwrappedContext_.deleteBuffer(resource);
-      } else if (resource instanceof WebGLFramebuffer) {
-        unwrappedContext_.deleteFramebuffer(resource);
-      } else if (resource instanceof WebGLProgram) {
-        unwrappedContext_.deleteProgram(resource);
-      } else if (resource instanceof WebGLRenderbuffer) {
-        unwrappedContext_.deleteRenderbuffer(resource);
-      } else if (resource instanceof WebGLShader) {
-        unwrappedContext_.deleteShader(resource);
-      } else if (resource instanceof WebGLTexture) {
-        unwrappedContext_.deleteTexture(resource);
-      }
-    }
-  }
-
-  function makeWebGLContextEvent(statusMessage) {
-    return {
-      statusMessage: statusMessage,
-      preventDefault: function() {
-          canRestore_ = true;
-        }
-    };
-  }
-
-  return canvas;
-
-  function makeLostContextSimulatingContext(ctx) {
-    // copy all functions and properties to wrapper
-    for (var propertyName in ctx) {
-      if (typeof ctx[propertyName] == 'function') {
-         wrappedContext_[propertyName] = makeLostContextFunctionWrapper(
-             ctx, propertyName);
-       } else {
-         makePropertyWrapper(wrappedContext_, ctx, propertyName);
-       }
-    }
-
-    // Wrap a few functions specially.
-    wrappedContext_.getError = function() {
-      loseContextIfTime();
-      if (!contextLost_) {
-        var err;
-        while (err = unwrappedContext_.getError()) {
-          glErrorShadow_[err] = true;
-        }
-      }
-      for (var err in glErrorShadow_) {
-        if (glErrorShadow_[err]) {
-          delete glErrorShadow_[err];
-          return err;
-        }
-      }
-      return wrappedContext_.NO_ERROR;
-    };
-
-    var creationFunctions = [
-      "createBuffer",
-      "createFramebuffer",
-      "createProgram",
-      "createRenderbuffer",
-      "createShader",
-      "createTexture"
-    ];
-    for (var ii = 0; ii < creationFunctions.length; ++ii) {
-      var functionName = creationFunctions[ii];
-      wrappedContext_[functionName] = function(f) {
-        return function() {
-          loseContextIfTime();
-          if (contextLost_) {
-            return null;
-          }
-          var obj = f.apply(ctx, arguments);
-          obj.__webglDebugContextLostId__ = contextId_;
-          resourceDb_.push(obj);
-          return obj;
-        };
-      }(ctx[functionName]);
-    }
-
-    var functionsThatShouldReturnNull = [
-      "getActiveAttrib",
-      "getActiveUniform",
-      "getBufferParameter",
-      "getContextAttributes",
-      "getAttachedShaders",
-      "getFramebufferAttachmentParameter",
-      "getParameter",
-      "getProgramParameter",
-      "getProgramInfoLog",
-      "getRenderbufferParameter",
-      "getShaderParameter",
-      "getShaderInfoLog",
-      "getShaderSource",
-      "getTexParameter",
-      "getUniform",
-      "getUniformLocation",
-      "getVertexAttrib"
-    ];
-    for (var ii = 0; ii < functionsThatShouldReturnNull.length; ++ii) {
-      var functionName = functionsThatShouldReturnNull[ii];
-      wrappedContext_[functionName] = function(f) {
-        return function() {
-          loseContextIfTime();
-          if (contextLost_) {
-            return null;
-          }
-          return f.apply(ctx, arguments);
-        }
-      }(wrappedContext_[functionName]);
-    }
-
-    var isFunctions = [
-      "isBuffer",
-      "isEnabled",
-      "isFramebuffer",
-      "isProgram",
-      "isRenderbuffer",
-      "isShader",
-      "isTexture"
-    ];
-    for (var ii = 0; ii < isFunctions.length; ++ii) {
-      var functionName = isFunctions[ii];
-      wrappedContext_[functionName] = function(f) {
-        return function() {
-          loseContextIfTime();
-          if (contextLost_) {
-            return false;
-          }
-          return f.apply(ctx, arguments);
-        }
-      }(wrappedContext_[functionName]);
-    }
-
-    wrappedContext_.checkFramebufferStatus = function(f) {
-      return function() {
-        loseContextIfTime();
-        if (contextLost_) {
-          return wrappedContext_.FRAMEBUFFER_UNSUPPORTED;
-        }
-        return f.apply(ctx, arguments);
-      };
-    }(wrappedContext_.checkFramebufferStatus);
-
-    wrappedContext_.getAttribLocation = function(f) {
-      return function() {
-        loseContextIfTime();
-        if (contextLost_) {
-          return -1;
-        }
-        return f.apply(ctx, arguments);
-      };
-    }(wrappedContext_.getAttribLocation);
-
-    wrappedContext_.getVertexAttribOffset = function(f) {
-      return function() {
-        loseContextIfTime();
-        if (contextLost_) {
-          return 0;
-        }
-        return f.apply(ctx, arguments);
-      };
-    }(wrappedContext_.getVertexAttribOffset);
-
-    wrappedContext_.isContextLost = function() {
-      return contextLost_;
-    };
-
-    return wrappedContext_;
-  }
-}
-
-return {
-    /**
-     * Initializes this module. Safe to call more than once.
-     * @param {!WebGLRenderingContext} ctx A WebGL context. If
-    }
-   *    you have more than one context it doesn't matter which one
-   *    you pass in, it is only used to pull out constants.
-   */
-  'init': init,
-
-  /**
-   * Returns true or false if value matches any WebGL enum
-   * @param {*} value Value to check if it might be an enum.
-   * @return {boolean} True if value matches one of the WebGL defined enums
-   */
-  'mightBeEnum': mightBeEnum,
-
-  /**
-   * Gets an string version of an WebGL enum.
-   *
-   * Example:
-   *   WebGLDebugUtil.init(ctx);
-   *   var str = WebGLDebugUtil.glEnumToString(ctx.getError());
-   *
-   * @param {number} value Value to return an enum for
-   * @return {string} The string version of the enum.
-   */
-  'glEnumToString': glEnumToString,
-
-  /**
-   * Converts the argument of a WebGL function to a string.
-   * Attempts to convert enum arguments to strings.
-   *
-   * Example:
-   *   WebGLDebugUtil.init(ctx);
-   *   var str = WebGLDebugUtil.glFunctionArgToString('bindTexture', 2, 0, gl.TEXTURE_2D);
-   *
-   * would return 'TEXTURE_2D'
-   *
-   * @param {string} functionName the name of the WebGL function.
-   * @param {number} numArgs The number of arguments
-   * @param {number} argumentIndx the index of the argument.
-   * @param {*} value The value of the argument.
-   * @return {string} The value as a string.
-   */
-  'glFunctionArgToString': glFunctionArgToString,
-
-  /**
-   * Converts the arguments of a WebGL function to a string.
-   * Attempts to convert enum arguments to strings.
-   *
-   * @param {string} functionName the name of the WebGL function.
-   * @param {number} args The arguments.
-   * @return {string} The arguments as a string.
-   */
-  'glFunctionArgsToString': glFunctionArgsToString,
-
-  /**
-   * Given a WebGL context returns a wrapped context that calls
-   * gl.getError after every command and calls a function if the
-   * result is not NO_ERROR.
-   *
-   * You can supply your own function if you want. For example, if you'd like
-   * an exception thrown on any GL error you could do this
-   *
-   *    function throwOnGLError(err, funcName, args) {
-   *      throw WebGLDebugUtils.glEnumToString(err) +
-   *            " was caused by call to " + funcName;
-   *    };
-   *
-   *    ctx = WebGLDebugUtils.makeDebugContext(
-   *        canvas.getContext("webgl"), throwOnGLError);
-   *
-   * @param {!WebGLRenderingContext} ctx The webgl context to wrap.
-   * @param {!function(err, funcName, args): void} opt_onErrorFunc The function
-   *     to call when gl.getError returns an error. If not specified the default
-   *     function calls console.log with a message.
-   * @param {!function(funcName, args): void} opt_onFunc The
-   *     function to call when each webgl function is called. You
-   *     can use this to log all calls for example.
-   */
-  'makeDebugContext': makeDebugContext,
-
-  /**
-   * Given a canvas element returns a wrapped canvas element that will
-   * simulate lost context. The canvas returned adds the following functions.
-   *
-   * loseContext:
-   *   simulates a lost context event.
-   *
-   * restoreContext:
-   *   simulates the context being restored.
-   *
-   * lostContextInNCalls:
-   *   loses the context after N gl calls.
-   *
-   * getNumCalls:
-   *   tells you how many gl calls there have been so far.
-   *
-   * setRestoreTimeout:
-   *   sets the number of milliseconds until the context is restored
-   *   after it has been lost. Defaults to 0. Pass -1 to prevent
-   *   automatic restoring.
-   *
-   * @param {!Canvas} canvas The canvas element to wrap.
-   */
-  'makeLostContextSimulatingCanvas': makeLostContextSimulatingCanvas,
-
-  /**
-   * Resets a context to the initial state.
-   * @param {!WebGLRenderingContext} ctx The webgl context to
-   *     reset.
-   */
-  'resetToInitialState': resetToInitialState
-};
-
-}();
-

Some files were not shown because too many files changed in this diff