UNPKG

gl-shells

Version:

Simple ready-to-go viewers for static models in WebGL

108 lines 73.4 kB
// GLOW.js r1.1 - http://github.com/empaempa/GLOW window.GLOW=function(){function b(a,c,b){this.flags=a;this.callback=c;this.context=b}var a={},c={},f=-1,e=[];b.prototype.dispatch=function(a,c){this.flags===a&&(this.context?this.callback.call(this.context,c):this.callback(c))};a.LOGS=1;a.WARNINGS=2;a.ERRORS=4;a.logFlags=a.ERRORS;a.currentContext={};a.registerContext=function(b){c[b.id]=b;a.enableContext(b)};a.getContextById=function(b){if(c[b])return c[b];GLOW.error("Couldn't find context id "+b+", returning current with id "+a.currentContext.id);return a.currentContext}; a.enableContext=function(c){a.currentContext=typeof c==="string"?getContextById(c):c;GL=a.GL=a.currentContext.GL};a.uniqueId=function(){return++f};a.log=function(c){a.logFlags&a.LOGS&&console.log(c);a.dispatch(a.LOGS,c)};a.warn=function(c){a.logFlags&a.WARNINGS&&console.warn(c);a.dispatch(a.WARNINGS,c)};a.error=function(c){a.logFlags&a.ERRORS&&console.error(c);a.dispatch(a.ERRORS,c)};a.addEventListener=function(a,c,f){e.push(new b(a,c,f));return e[e.length-1]};a.removeEventListener=function(c){c= e.indexOf(c);c!==-1?e.splice(c,1):a.warn("GLOW.removeEventListener: Couldn't find listener object")};a.dispatch=function(a,c){for(var b=e.length;b--;)e[b].dispatch(a,c)};return a}(),GL={}; GLOW.Context=function(){function b(a){a===void 0&&(a={});this.id=a.id!==void 0?a.id:GLOW.uniqueId();this.alpha=a.alpha!==void 0?a.alpha:!0;this.depth=a.depth!==void 0?a.depth:!0;this.antialias=a.antialias!==void 0?a.antialias:!0;this.stencil=a.stencil!==void 0?a.stencil:!1;this.premultipliedAlpha=a.premultipliedAlpha!==void 0?a.premultipliedAlpha:!0;this.preserveDrawingBuffer=a.preserveDrawingBuffer!==void 0?a.preserveDrawingBuffer:!1;this.width=a.width!==void 0?a.width:window.innerWidth;this.height= a.height!==void 0?a.height:window.innerHeight;this.cache=new GLOW.Cache;this.debug=a.debug!==void 0?a.debug:!1;if(a.context)this.GL=a.context,GLOW.registerContext(this);else{try{this.domElement=document.createElement("canvas");if(this.debug&&window.WebGLDebugUtils)this.domElement=WebGLDebugUtils.makeLostContextSimulatingCanvas(this.domElement);this.GL=this.domElement.getContext("experimental-webgl",{alpha:this.alpha,depth:this.depth,antialias:this.antialias,stencil:this.stencil,premultipliedAlpha:this.premultipliedAlpha, preserveDrawingBuffer:this.preserveDrawingBuffer})}catch(c){GLOW.error("GLOW.Context.construct: "+c)}if(this.GL!==null){GLOW.registerContext(this);this.domElement.width=this.width;this.domElement.height=this.height;this.viewport=a.viewport?{x:a.viewport.x!==void 0?a.viewport.x:0,y:a.viewport.y!==void 0?a.viewport.y:0,width:a.viewport.width!==void 0?a.viewport.width:this.width,height:a.viewport.height!==void 0?a.viewport.height:this.height}:{x:0,y:0,width:this.width,height:this.height};if(a.clear){if(this.clearSettings= {r:a.clear.red!==void 0?a.clear.red:0,g:a.clear.green!==void 0?a.clear.green:0,b:a.clear.blue!==void 0?a.clear.blue:0,a:a.clear.alpha!==void 0?a.clear.alpha:1,depth:a.clear.depth!==void 0?a.clear.depth:1,bits:a.clear.bits!==void 0?a.clear.bits:-1},this.clearSettings.bits===-1)this.clearSettings.bits=GL.COLOR_BUFFER_BIT,this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0}else this.clearSettings={r:0,g:0,b:0,a:1,depth:1,bits:0},this.clearSettings.bits= GL.COLOR_BUFFER_BIT,this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0;this.enableCulling(!0,{frontFace:GL.CCW,cullFace:GL.BACK});this.enableDepthTest(!0,{func:GL.LEQUAL,write:!0,zNear:0,zFar:1});this.enableBlend(!1);this.setViewport();this.clear()}else GLOW.error("GLOW.Context.construct: unable to initialize WebGL")}}b.prototype.setupClear=function(a){if(a!==void 0)this.clearSettings.r=a.red!==void 0?Math.min(1,Math.max(0,a.red)): this.clearSettings.r,this.clearSettings.g=a.green!==void 0?Math.min(1,Math.max(0,a.green)):this.clearSettings.g,this.clearSettings.b=a.blue!==void 0?Math.min(1,Math.max(0,a.blue)):this.clearSettings.b,this.clearSettings.a=a.alpha!==void 0?Math.min(1,Math.max(0,a.alpha)):this.clearSettings.a,this.clearSettings.depth=a.depth!==void 0?Math.min(1,Math.max(0,a.depth)):this.clearSettings.depth,this.clearSettings.bits=a.bits!==void 0?a.bits:this.clearSettings.bits;GL.clearColor(this.clearSettings.r,this.clearSettings.g, this.clearSettings.b,this.clearSettings.a);GL.clearDepth(this.clearSettings.depth);return this};b.prototype.clear=function(a){this.setupClear(a);GL.clear(this.clearSettings.bits);return this};b.prototype.enableBlend=function(a,c){a?(GL.enable(GL.BLEND),c&&this.setupBlend(c)):GL.disable(GL.BLEND);return this};b.prototype.setupBlend=function(a){a.equationRGB?(a.equationAlpha&&GL.blendEquationSeparate(a.equationRGB,a.equationAlpha),a.srcRGB&&GL.blendFuncSeparate(a.srcRGB,a.dstRGB,a.srcAlpha,a.dstAlpha)): (a.equation&&GL.blendEquation(a.equation),a.src&&GL.blendFunc(a.src,a.dst));return this};b.prototype.enableDepthTest=function(a,c){a?(GL.enable(GL.DEPTH_TEST),c&&this.setupDepthTest(c)):GL.disable(GL.DEPTH_TEST);return this};b.prototype.setupDepthTest=function(a){a.func!==void 0&&GL.depthFunc(a.func);a.write!==void 0&&GL.depthMask(a.write);a.zNear!==void 0&&a.zFar!==void 0&&a.zNear<=a.zFar&&GL.depthRange(Math.max(0,Math.min(1,a.zNear)),Math.max(0,Math.min(1,a.zFar)));return this};b.prototype.enablePolygonOffset= function(a,c){a?(GL.enable(GL.POLYGON_OFFSET_FILL),c&&this.setupPolygonOffset(c)):GL.disable(GL.POLYGON_OFFSET_FILL);return this};b.prototype.setupPolygonOffset=function(a){a.factor&&a.units&&GL.polygonOffset(a.factor,a.units)};b.prototype.enableStencilTest=function(a,c){a?(GL.enable(GL.STENCIL_TEST),c&&this.setupStencilTest(c)):GL.disable(GL.STENCIL_TEST);return this};b.prototype.setupStencilTest=function(a){a.func&&a.funcFace?GL.stencilFuncSeparate(a.funcFace,a.func,a.funcRef,a.funcMask):a.func&& GL.stencilFunc(a.func,a.funcRef,a.funcMask);a.mask&&a.maskFace?GL.stencilMaskSeparate(a.maskFace,a.mask):a.mask&&GL.stencilMask(a.mask);a.opFail&&a.opFace?GL.stencilOpSeparate(a.opFace,a.opFail,a.opZfail,a.opZpass):a.opFail&&GL.stencilOp(a.opFail,a.opZfail,a.opZpass);return this};b.prototype.enableCulling=function(a,c){a?(GL.enable(GL.CULL_FACE),c&&this.setupCulling(c)):GL.disable(GL.CULL_FACE);return this};b.prototype.setupCulling=function(a){try{a.frontFace&&GL.frontFace(a.frontFace),a.cullFace&& GL.cullFace(a.cullFace)}catch(c){GLOW.error("GLOW.Context.setupCulling: "+c)}return this};b.prototype.enableScissor=function(a,c){a?(GL.enable(GL.SCISSOR_TEST),c&&this.setupScissor(c)):GL.disable(GL.SCISSOR_TEST);return this};b.prototype.setupScissor=function(a){try{GL.scissor(a.x,a.y,a.width,a.height)}catch(c){GLOW.error("GLOW.Context.setupScissorTest: "+c)}return this};b.prototype.setViewport=function(){this.setupViewport()};b.prototype.setupViewport=function(a){if(a)this.viewport.x=a.x!==void 0? a.x:this.viewport.x,this.viewport.y=a.y!==void 0?a.y:this.viewport.y,this.viewport.width=a.width!==void 0?a.width:this.viewport.width,this.viewport.height=a.height!==void 0?a.height:this.viewport.height;GL.viewport(this.viewport.x,this.viewport.y,this.viewport.width,this.viewport.height);return this};b.prototype.availableExtensions=function(){return GL.getSupportedExtensions()};b.prototype.enableExtension=function(a){for(var c=GL.getSupportedExtensions(),b=0,e=c.length;b<e;b++)if(a.toLowerCase()=== c[b].toLowerCase())break;if(b!==e)return GL.getExtension(c[b])};b.prototype.getParameter=function(a){return GL.getParameter(a)};b.prototype.maxVertexTextureImageUnits=function(){return this.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS)};b.prototype.resize=function(a,c){var b=c/this.height;this.viewport.width*=a/this.width;this.viewport.height*=b;this.domElement.width=this.width=a;this.domElement.height=this.height=c};return b}(); GLOW.Compiler=function(){var b={};b.compile=function(a){var c=GLOW.currentContext.cache.codeCompiled(a.vertexShader,a.fragmentShader);c===void 0&&(c=b.linkProgram(b.compileVertexShader(a.vertexShader),b.compileFragmentShader(a.fragmentShader)),GLOW.currentContext.cache.addCompiledProgram(c));var f=b.createUniforms(b.extractUniforms(c),a.data),e=b.createAttributes(b.extractAttributes(c),a.data,a.usage,a.interleave),g=b.interleaveAttributes(e,a.interleave);if(a.elements)GLOW.error("GLOW.Compiler.compile: .elements is no longer supported, please use .indices combined with .primitives"); else{var h=a.indices,i=a.primitives!==void 0?a.primitives:GL.TRIANGLES,j=a.usage!==void 0?a.usage:{},k=j.primitives;if(a.triangles)h=a.triangles,k=j.triangles;else if(a.triangleStrip)h=a.triangleStrip,i=GL.TRIANGLE_STRIP,k=j.triangleStrip;else if(a.triangleFan)h=a.triangleFan,i=GL.TRIANGLE_FAN,k=j.triangleFan;else if(a.points)h=a.points,i=GL.POINTS,k=j.points;else if(a.lines)h=a.lines,i=GL.LINES,k=j.lines;else if(a.lineLoop)h=a.lineLoop,i=GL.LINE_LOOP,k=j.lineLoop;else if(a.lineStrip)h=a.lineStrip, i=GL.LINE_STRIP,k=j.lineStrip;if(h===void 0){for(var l in e)if(e[l].data){h=e[l].data.length/e[l].size;break}if(h===void 0)for(var m in g){for(l in g[m].attributes){h=g[m].attributes[l].data.length/g[m].attributes[l].size;break}break}h===void 0&&(h=0)}h=b.createElements(h,i,k);return new GLOW.CompiledData(c,f,e,g,h,a)}};b.compileVertexShader=function(a){var c;c=GL.createShader(GL.VERTEX_SHADER);c.id=GLOW.uniqueId();GL.shaderSource(c,a);GL.compileShader(c);!GL.getShaderParameter(c,GL.COMPILE_STATUS)&& !GL.isContextLost()&&GLOW.error("GLOW.Compiler.compileVertexShader: "+GL.getShaderInfoLog(c));return c};b.compileFragmentShader=function(a){var c;c=GL.createShader(GL.FRAGMENT_SHADER);c.id=GLOW.uniqueId();GL.shaderSource(c,a);GL.compileShader(c);!GL.getShaderParameter(c,GL.COMPILE_STATUS)&&!GL.isContextLost()&&GLOW.error("GLOW.Compiler.compileFragmentShader: "+GL.getShaderInfoLog(c));return c};b.linkProgram=function(a,c){var b=GL.createProgram();b||GLOW.error("GLOW.Compiler.linkProgram: Could not create program"); b.id=GLOW.uniqueId();GL.attachShader(b,a);GL.attachShader(b,c);GL.linkProgram(b);!GL.getProgramParameter(b,GL.LINK_STATUS)&&!GL.isContextLost()&&GLOW.error("GLOW.Compiler.linkProgram: Could not initialise program");return b};b.extractUniforms=function(a){for(var c={},b,e=0,g=GL.getProgramParameter(a,GL.ACTIVE_UNIFORMS);e<g;e++)if(b=GL.getActiveUniform(a,e),b!==null&&b!==-1&&b!==void 0)b={name:b.name.split("[")[0],size:b.size,type:b.type,location:GL.getUniformLocation(a,b.name.split("[")[0]),locationNumber:e}, c[b.name]=b;else break;return c};b.extractAttributes=function(a){for(var c={},b,e=0,g=GL.getProgramParameter(a,GL.ACTIVE_ATTRIBUTES);e<g;e++)if(b=GL.getActiveAttrib(a,e),b!==null&&b!==-1&&b!==void 0)b={name:b.name,size:b.size,type:b.type,location:GL.getAttribLocation(a,b.name),locationNumber:e},c[b.name]=b;else break;a.highestAttributeNumber=e-1;return c};b.createUniforms=function(a,c){var b,e={},g,h,i=0;for(b in a)if(g=a[b],h=g.name,c[h]instanceof GLOW.Uniform)e[h]=c[h];else if(c[h]===void 0&&GLOW.warn("GLOW.Compiler.createUniforms: missing data for uniform "+ h+". Creating anyway, but make sure to set data before drawing."),e[h]=new GLOW.Uniform(g,c[h]),e[h].type===GL.SAMPLER_2D||e[h].type===GL.SAMPLER_CUBE)e[h].textureUnit=i++,e[h].data!==void 0&&e[h].data.init();return e};b.createAttributes=function(a,c,b,e){var g,h,i,j={},e=e!==void 0?e:{},b=b!==void 0?b:{};for(g in a)h=a[g],i=h.name,c[i]instanceof GLOW.Attribute?j[i]=c[i]:(c[i]===void 0&&GLOW.warn("GLOW.Compiler.createAttributes: missing data for attribute "+i+". Creating anyway, but make sure to set data before drawing."), j[i]=new GLOW.Attribute(h,c[i],b[i],e[i]!==void 0?e[i]:!0));return j};b.interleaveAttributes=function(a,c){var c=c!==void 0?c:{},b,e,g,h,i;g=0;var j=[];e=0;for(b in a)e++;if(e===1)for(b in a){if(a[b].interleaved===!0)a[b].interleaved=!1,a[b].data&&a[b].bufferData()}else{for(b in a)c[b]!==void 0&&c[b]!==!1&&(g=Math.max(g-1,c[b])+1);for(b in a)c[b]===void 0&&(c[b]=g);for(i in c)c[i]!==!1&&(j[c[i]]===void 0&&(j[c[i]]=[]),j[c[i]].push(a[i]));var k,l;b=0;for(e=j.length;b<e;b++)if(j[b]!==void 0){g=k=0; for(h=j[b].length;g<h;g++)if(k+j[b][g].size*4>255){GLOW.warn("GLOW.Compiler.interleaveAttributes: Stride owerflow, moving attributes to new interleave index. Please check your interleave setup!");l=j.length;for(j[l]=[];g<h;)j[l].push(j[b][g]),j[b].splice(g,1),h--}else k+=j[b][g].size*4}l={};b=0;for(e=j.length;b<e;b++)if(j[b]!==void 0){k="";g=0;for(h=j[b].length;g<h;g++)k+=g!==h-1?j[b][g].name+"_":j[b][g].name;l[k]=new GLOW.InterleavedAttributes(j[b])}for(i in c)c[i]!==!1&&delete a[i];return l}};b.createElements= function(a,c,b){return a instanceof GLOW.Elements?a:new GLOW.Elements(a,c,b)};return b}(); GLOW.CompiledData=function(){function b(a,c,b,e,g){this.program=a;this.uniforms=c||{};this.attributes=b||{};this.interleavedAttributes=e||{};this.elements=g;this.interleavedAttributeArray=this.attributeArray=this.uniformArray=void 0;this.createArrays()}b.prototype.createArrays=function(){this.uniformArray=[];this.attributeArray=[];this.interleavedAttributeArray=[];var a,c,b;for(a in this.uniforms)this.uniformArray.push(this.uniforms[a]);for(c in this.attributes)this.attributeArray.push(this.attributes[c]); for(b in this.interleavedAttributes)this.interleavedAttributeArray.push(this.interleavedAttributes[b])};b.prototype.clone=function(a){var c=new GLOW.CompiledData,a=a||{},b;for(b in this.uniforms)if(a[b])if(a[b]instanceof GLOW.Uniform)c.uniforms[b]=execept[b];else{if(c.uniforms[b]=new GLOW.Uniform(this.uniforms[b],a[b]),c.uniforms[b].type===GL.SAMPLER_2D||c.uniforms[b].type===GL.SAMPLER_CUBE)c.uniforms[b].textureUnit=this.uniforms[b].textureUnit,c.uniforms[b].data&&c.uniforms[b].data.init()}else c.uniforms[b]= this.uniforms[b];for(var e in this.attributes)c.attributes[e]=a[e]?a[e]instanceof GLOW.Attribute?a[e]:new GLOW.Attribute(this.attributes[e],a[e]):this.attributes[e];for(var g in this.interleavedAttributes)c.interleavedAttributes[g]=a[g]?a[g]:this.interleavedAttributes[g];c.elements=a.indices?new GLOW.Elements(a.indices,a.primitives):a.elements instanceof GLOW.Elements?a.elements:this.elements;c.program=a.program?a.program:this.program;c.createArrays();return c};b.prototype.dispose=function(a,c){if(a){var b; for(b=this.uniformArray.length;b--;)this.uniformArray[b].dispose();for(b=this.attributeArray.length;b--;)this.attributeArray[b].dispose();for(b=this.interleavedAttributeArray.length;b--;)this.interleavedAttributeArray[b].dispose();this.elements.dispose()}if(c&&GL.isProgram(this.program)&&(b=GL.getAttachedShaders(this.program))){for(var e=b.length;e--;)GL.detachShader(this.program,b[e]),GL.deleteShader(b[e]);GL.deleteProgram(this.program)}delete this.program;delete this.uniforms;delete this.attributes; delete this.interleavedAttributes;delete this.elements;delete this.uniformArray;delete this.attributeArray;delete this.interleavedAttributeArray};return b}(); GLOW.Cache=function(){function b(){this.highestAttributeNumber=-1;this.uniformByLocation=[];this.attributeByLocation=[];this.textureByLocation=[];this.compiledCode=[];this.programId=this.elementId=-1;this.active=!0}b.prototype.codeCompiled=function(a,c){var b,e,g=this.compiledCode.length;for(e=0;e<g;e++)if(b=this.compiledCode[e],a===b.vertexShader&&c===b.fragmentShader)break;if(e===g)this.compiledCode.push({vertexShader:a,fragmentShader:c});else return this.compiledCode[e].program};b.prototype.addCompiledProgram= function(a){this.compiledCode[this.compiledCode.length-1].program=a};b.prototype.programCached=function(a){if(this.active){if(a.id===this.programId)return!0;this.programId=a.id;this.uniformByLocation.length=0;this.attributeByLocation.length=0;this.textureByLocation.length=0;this.elementId=-1}return!1};b.prototype.setProgramHighestAttributeNumber=function(a){var c=this.highestAttributeNumber;this.highestAttributeNumber=a.highestAttributeNumber;return a.highestAttributeNumber-c};b.prototype.uniformCached= function(a){if(this.active){if(this.uniformByLocation[a.locationNumber]===a.id)return!0;this.uniformByLocation[a.locationNumber]=a.id}return!1};b.prototype.invalidateUniform=function(a){this.uniformByLocation[a.locationNumber]=void 0};b.prototype.attributeCached=function(a){if(this.active){if(this.attributeByLocation[a.locationNumber]===a.id)return!0;this.attributeByLocation[a.locationNumber]=a.id}return!1};b.prototype.interleavedAttributeCached=function(a){if(this.active)for(var c=0,b=a.attributes.length, e;c<b;c++){e=a.attributes[c];if(this.attributeByLocation[e.locationNumber]===e.id)return!0;this.attributeByLocation[e.locationNumber]=e.id}return!1};b.prototype.invalidateAttribute=function(a){this.attributeByLocation[a.locationNumber]=void 0};b.prototype.textureCached=function(a,c){if(this.active){if(this.textureByLocation[a]===c.id)return!0;this.textureByLocation[a]=c.id}return!1};b.prototype.invalidateTexture=function(a){this.textureByLocation[a]=void 0};b.prototype.elementsCached=function(a){if(this.active){if(a.id=== this.elementId)return!0;this.elementId=a.id}return!1};b.prototype.invalidateElements=function(){this.elementId=-1};b.prototype.clear=function(){this.highestAttributeNumber=-1;this.uniformByLocation.length=0;this.attributeByLocation.length=0;this.textureByLocation.length=0;this.programId=this.elementId=-1};return b}(); GLOW.FBO=function(){function b(a){a=a!==void 0?a:{};this.id=GLOW.uniqueId();this.width=a.width||a.size||window.innerWidth;this.height=a.height||a.size||window.innerHeight;this.wrapS=a.wrapS||a.wrap||GL.CLAMP_TO_EDGE;this.wrapT=a.wrapT||a.wrap||GL.CLAMP_TO_EDGE;this.magFilter=a.magFilter||a.filter||GL.LINEAR;this.minFilter=a.minFilter||a.filter||GL.LINEAR;this.internalFormat=a.internalFormat||GL.RGBA;this.format=a.format||GL.RGBA;this.type=a.type||GL.UNSIGNED_BYTE;this.depth=a.depth!==void 0?a.depth: !0;this.stencil=a.stencil!==void 0?a.stencil:!1;this.data=a.data||null;this.isBound=!1;this.textureUnit=-1;this.textureType=a.cube!==!0?GL.TEXTURE_2D:GL.TEXTURE_CUBE_MAP;this.viewport=a.viewport?{x:a.viewport.x!==void 0?a.viewport.x:0,y:a.viewport.y!==void 0?a.viewport.y:0,width:a.viewport.width!==void 0?a.viewport.width:this.width,height:a.viewport.height!==void 0?a.viewport.height:this.height}:{x:0,y:0,width:this.width,height:this.height};if(a.clear){if(this.clearSettings={r:a.clear.red!==void 0? a.clear.red:0,g:a.clear.green!==void 0?a.clear.green:0,b:a.clear.blue!==void 0?a.clear.blue:0,a:a.clear.alpha!==void 0?a.clear.alpha:1,depth:a.clear.depth!==void 0?a.clear.depth:1,bits:a.clear.bits!==void 0?a.clear.bits:-1},this.clearSettings.bits===-1)this.clearSettings.bits=GL.COLOR_BUFFER_BIT,this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0}else this.clearSettings={r:0,g:0,b:0,a:1,depth:1,bits:0},this.clearSettings.bits=GL.COLOR_BUFFER_BIT, this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0;this.createBuffers()}var a={posX:0,negX:1,posY:2,negY:3,posZ:4,negZ:5};b.prototype.createBuffers=function(){this.texture=GL.createTexture();var c=GL.getError();if(c!==GL.NO_ERROR&&c!==GL.CONTEXT_LOST_WEBGL)GLOW.error("GLOW.FBO.createBuffers: Error creating render texture.");else{GL.bindTexture(this.textureType,this.texture);GL.texParameteri(this.textureType,GL.TEXTURE_WRAP_S,this.wrapS); GL.texParameteri(this.textureType,GL.TEXTURE_WRAP_T,this.wrapT);GL.texParameteri(this.textureType,GL.TEXTURE_MAG_FILTER,this.magFilter);GL.texParameteri(this.textureType,GL.TEXTURE_MIN_FILTER,this.minFilter);if(this.textureType===GL.TEXTURE_2D)this.data===null||this.data instanceof Uint8Array||this.data instanceof Float32Array?GL.texImage2D(this.textureType,0,this.internalFormat,this.width,this.height,0,this.format,this.type,this.data):GL.texImage2D(this.textureType,0,this.internalFormat,this.format, this.type,this.data);else for(var b in a)GL.texImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[b],0,this.internalFormat,this.width,this.height,0,this.format,this.type,this.data[b]);if(this.depth||this.stencil){this.renderBuffer=GL.createRenderbuffer();c=GL.getError();if(c!==GL.NO_ERROR&&c!==GL.CONTEXT_LOST_WEBGL){GLOW.error("GLOW.FBO.createBuffers: Error creating render buffer.");return}GL.bindRenderbuffer(GL.RENDERBUFFER,this.renderBuffer);this.depth&&!this.stencil?GL.renderbufferStorage(GL.RENDERBUFFER, GL.DEPTH_COMPONENT16,this.width,this.height):!this.depth&&this.stencil?GL.renderbufferStorage(GL.RENDERBUFFER,GL.STENCIL_INDEX8,this.width,this.height):this.depth&&this.stencil&&GL.renderbufferStorage(GL.RENDERBUFFER,GL.DEPTH_STENCIL,this.width,this.height)}if(this.textureType===GL.TEXTURE_2D){this.frameBuffer=GL.createFramebuffer();c=GL.getError();if(c!==GL.NO_ERROR&&c!==GL.CONTEXT_LOST_WEBGL){GLOW.error("GLOW.FBO.createBuffers: Error creating frame buffer.");return}GL.bindFramebuffer(GL.FRAMEBUFFER, this.frameBuffer);GL.framebufferTexture2D(GL.FRAMEBUFFER,GL.COLOR_ATTACHMENT0,GL.TEXTURE_2D,this.texture,0);this.depth&&!this.stencil?GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.DEPTH_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer):!this.depth&&this.stencil?GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.STENCIL_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer):this.depth&&this.stencil&&GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.DEPTH_STENCIL_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer)}else{this.frameBuffers= {};for(var e in a){this.frameBuffers[e]=GL.createFramebuffer();c=GL.getError();if(c!==GL.NO_ERROR&&c!==GL.CONTEXT_LOST_WEBGL){GLOW.error("GLOW.FBO.createBuffers: Error creating frame buffer for side "+e);return}GL.bindFramebuffer(GL.FRAMEBUFFER,this.frameBuffers[e]);GL.framebufferTexture2D(GL.FRAMEBUFFER,GL.COLOR_ATTACHMENT0,GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[e],this.texture,0);this.depth&&!this.stencil?GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.DEPTH_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer): !this.depth&&this.stencil?GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.STENCIL_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer):this.depth&&this.stencil&&GL.framebufferRenderbuffer(GL.FRAMEBUFFER,GL.DEPTH_STENCIL_ATTACHMENT,GL.RENDERBUFFER,this.renderBuffer)}}GL.bindTexture(this.textureType,null);GL.bindRenderbuffer(GL.RENDERBUFFER,null);GL.bindFramebuffer(GL.FRAMEBUFFER,null)}};b.prototype.deleteBuffers=function(){this.texture&&GL.deleteTexture(this.texture);this.renderBuffer&&GL.deleteRenderbuffer(this.renderBuffer); if(this.textureType===GL.TEXTURE_2D)this.frameBuffer&&GL.deleteFramebuffer(this.frameBuffer);else for(var c in a)GL.deleteFramebuffer(this.frameBuffers[c])};b.prototype.init=function(){};b.prototype.bind=function(a,b){if(!this.isBound)this.isBound=!0,(a||a===void 0)&&this.setupViewport(a),this.textureType===GL.TEXTURE_2D?GL.bindFramebuffer(GL.FRAMEBUFFER,this.frameBuffer):GL.bindFramebuffer(GL.FRAMEBUFFER,this.frameBuffers[b!==void 0?b:"posX"]);return this};b.prototype.unbind=function(a){if(this.isBound)this.isBound= !1,GL.bindFramebuffer(GL.FRAMEBUFFER,null),(a===void 0||a===!0)&&GL.viewport(GLOW.currentContext.viewport.x,GLOW.currentContext.viewport.y,GLOW.currentContext.viewport.width,GLOW.currentContext.viewport.height);return this};b.prototype.setViewport=function(){this.setupViewport()};b.prototype.setupViewport=function(a){if(a)this.viewport.x=a.x!==void 0?a.x:this.viewport.x,this.viewport.y=a.y!==void 0?a.y:this.viewport.y,this.viewport.width=a.width!==void 0?a.width:this.viewport.width,this.viewport.height= a.height!==void 0?a.height:this.viewport.height;GL.viewport(this.viewport.x,this.viewport.y,this.viewport.width,this.viewport.height);return this};b.prototype.setupClear=function(a){if(a!==void 0)this.clearSettings.r=a.red!==void 0?Math.min(1,Math.max(0,a.red)):this.clearSettings.r,this.clearSettings.g=a.green!==void 0?Math.min(1,Math.max(0,a.green)):this.clearSettings.g,this.clearSettings.b=a.blue!==void 0?Math.min(1,Math.max(0,a.blue)):this.clearSettings.b,this.clearSettings.a=a.alpha!==void 0? Math.min(1,Math.max(0,a.alpha)):this.clearSettings.a,this.clearSettings.depth=a.depth!==void 0?Math.min(1,Math.max(0,a.depth)):this.clearSettings.depth,this.clearSettings.bits=a.bits!==void 0?a.bits:this.clearSettings.bits;GL.clearColor(this.clearSettings.r,this.clearSettings.g,this.clearSettings.b,this.clearSettings.a);GL.clearDepth(this.clearSettings.depth);return this};b.prototype.clear=function(a){this.isBound&&(this.setupClear(a),GL.clear(this.clearSettings.bits));return this};b.prototype.resize= function(a,b){var e=b/this.height;this.viewport.width*=a/this.width;this.viewport.height*=e;this.width=a;this.height=b;this.deleteBuffers();this.createBuffers();return this};b.prototype.generateMipMaps=function(){GL.bindTexture(this.textureType,this.texture);GL.generateMipmap(this.textureType);GL.bindTexture(this.textureType,null);return this};b.prototype.dispose=function(){this.deleteBuffers();delete this.data;delete this.viewport;delete this.texture;delete this.renderBuffer;delete this.frameBuffer; delete this.frameBuffers;delete this.viewport;delete this.clearSettings};return b}(); GLOW.Texture=function(){function b(a){if(a.url!==void 0)a.data=a.url;this.id=GLOW.uniqueId();this.data=a.data;this.autoUpdate=a.autoUpdate;this.internalFormat=a.internalFormat||GL.RGBA;this.format=a.format||GL.RGBA;this.type=a.type||GL.UNSIGNED_BYTE;this.wrapS=a.wrapS||a.wrap||GL.REPEAT;this.wrapT=a.wrapT||a.wrap||GL.REPEAT;this.magFilter=a.magFilter||a.filter||GL.LINEAR;this.minFilter=a.minFilter||a.filter||GL.LINEAR_MIPMAP_LINEAR;this.width=a.width;this.height=a.height;this.onLoadComplete=a.onLoadComplete; this.onLoadContext=a.onLoadContext;this.texture=void 0}var a={posX:0,negX:1,posY:2,negY:3,posZ:4,negZ:5};b.prototype.init=function(){if(this.texture!==void 0)return this;if(this.data===void 0&&this.width!==void 0&&this.height!==void 0)this.data=this.type===GL.UNSIGNED_BYTE?new Uint8Array(this.width*this.height*(this.format===GL.RGBA?4:3)):new Float32Array(this.width*this.height*(this.format===GL.RGBA?4:3));else if(typeof this.data==="string"){this.textureType=GL.TEXTURE_2D;var b=this.data,f=b.toLowerCase(); if(f.indexOf(".jpg")!==-1||f.indexOf(".png")!==-1||f.indexOf(".gif")!==-1||f.indexOf("jpeg")!==-1)this.data=new Image,this.data.scope=this,this.data.onload=this.onLoadImage;else{if(this.autoUpdate===void 0)this.autoUpdate=!0;this.data=document.createElement("video");this.data.scope=this;this.data.addEventListener("loadeddata",this.onLoadVideo,!1)}this.data.src=b}else if(this.data instanceof HTMLImageElement||this.data instanceof HTMLVideoElement||this.data instanceof HTMLCanvasElement||this.data instanceof Uint8Array||this.data instanceof Float32Array)this.textureType=GL.TEXTURE_2D,this.createTexture();else{this.textureType=GL.TEXTURE_CUBE_MAP;this.itemsToLoad=0;for(var e in a)this.data[e]!==void 0?typeof this.data[e]==="string"&&this.itemsToLoad++:GLOW.error("GLOW.Texture.init: data type error. Did you forget cube map "+e+"? If not, the data type is not supported");if(this.itemsToLoad===0)this.createTexture();else for(e in a)if(typeof this.data[e]==="string")b=this.data[e],f=b.toLowerCase(),f.indexOf(".jpg")!== -1||f.indexOf(".png")!==-1||f.indexOf(".gif")!==-1||f.indexOf("jpeg")!==-1?(this.data[e]=new Image,this.data[e].scope=this,this.data[e].onload=this.onLoadCubeImage):(this.autoUpdate!==void 0?this.autoUpdate[e]=this.autoUpdate[e]!==void 0?this.autoUpdate[e]:!0:(this.autoUpdate={},this.autoUpdate[e]=!0),this.data[e]=document.createElement("video"),this.data[e].scope=this,this.data[e].addEventListener("loadeddata",this.onLoadCubeVideo,!1)),this.data[e].src=b}return this};b.prototype.createTexture=function(){this.texture!== void 0&&GL.deleteTexture(this.texture);this.texture=GL.createTexture();GL.bindTexture(this.textureType,this.texture);if(this.textureType===GL.TEXTURE_2D)if(this.data instanceof Uint8Array)if(this.width!==void 0&&this.height!==void 0)GL.texImage2D(this.textureType,0,this.internalFormat,this.width,this.height,0,this.format,this.type,this.data);else{GLOW.error("GLOW.Texture.createTexture: Textures of type Uint8Array requires width and height parameters. Quitting.");return}else GL.texImage2D(this.textureType, 0,this.internalFormat,this.format,this.type,this.data);else for(var b in a)if(this.data[b]instanceof Uint8Array||this.data[b]instanceof Float32Array)if(this.width!==void 0&&this.height!==void 0)GL.texImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[b],0,this.internalFormat,this.width,this.height,0,this.format,this.type,this.data[b]);else{GLOW.error("GLOW.Texture.createTexture: Textures of type Uint8Array/Float32Array requires width and height parameters. Quitting.");return}else GL.texImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+ a[b],0,this.internalFormat,this.format,this.type,this.data[b]);GL.texParameteri(this.textureType,GL.TEXTURE_WRAP_S,this.wrapS);GL.texParameteri(this.textureType,GL.TEXTURE_WRAP_T,this.wrapT);GL.texParameteri(this.textureType,GL.TEXTURE_MIN_FILTER,this.minFilter);GL.texParameteri(this.textureType,GL.TEXTURE_MAG_FILTER,this.magFilter);this.minFilter!==GL.NEAREST&&this.minFilter!==GL.LINEAR&&GL.generateMipmap(this.textureType);return this};b.prototype.updateTexture=function(b){if(this.texture!==void 0){var b= b!==void 0?b:{},f=b.level||0,e=b.xOffset||0,g=b.yOffset||0,h=b.updateMipmap!==void 0?b.updateMipmap:!0;this.data=b.data||this.data;GL.bindTexture(this.textureType,this.texture);if(this.textureType==GL.TEXTURE_2D)this.data instanceof Uint8Array?GL.texSubImage2D(this.textureType,f,e,g,this.width,this.height,this.format,this.type,this.data):GL.texSubImage2D(this.textureType,f,e,g,this.format,this.type,this.data);else for(var i in b)a[i]!==void 0&&(this.data[i]instanceof Uint8Array?GL.texSubImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+ a[i],f,e,g,this.width,this.height,this.format,this.type,this.data[i]):GL.texSubImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[i],f,e,g,this.format,this.type,this.data[i]));this.minFilter!==GL.NEAREST&&this.minFilter!==GL.LINEAR&&h===!0&&GL.generateMipmap(this.textureType)}};b.prototype.swapTexture=function(a){this.dispose();this.data=a;this.init()};b.prototype.onLoadImage=function(){this.scope.createTexture();this.scope.onLoadComplete&&this.scope.onLoadComplete.call(this.scope.onLoadContext,this.scope)}; b.prototype.onLoadCubeImage=function(){this.scope.itemsToLoad--;this.scope.itemsToLoad===0&&this.scope.createTexture()};b.prototype.onLoadVideo=function(){this.removeEventListener("loadeddata",this.scope.onLoadVideo,!1);this.scope.createTexture()};b.prototype.onLoadCubeVideo=function(){this.removeEventListener("loadeddata",this.scope.onLoadVideo,!1);this.scope.itemsToLoad--;this.scope.itemsToLoad===0&&this.scope.createTexture()};b.prototype.play=function(){if(this.textureType===GL.TEXTURE_2D)this.data instanceof HTMLVideoElement&&this.data.play();else for(var b in a)this.data[b]instanceof HTMLVideoElement&&this.data[b].play()};b.prototype.dispose=function(){if(this.texture!==void 0)GL.deleteTexture(this.texture),this.texture=void 0;this.data=void 0};return b}(); GLOW.Shader=function(){function b(a){this.id=GLOW.uniqueId();this.compiledData=a.use?a.use.clone(a.except):GLOW.Compiler.compile(a);this.uniforms=this.compiledData.uniforms;this.elements=this.compiledData.elements;this.program=this.compiledData.program;this.attachData()}b.prototype.attachData=function(){var a,b,f;for(a in this.uniforms)this[a]===void 0?this.uniforms[a].data!==void 0?this[a]=this.uniforms[a].data:GLOW.warn("GLOW.Shader.attachUniformAndAttributeData: no data for uniform "+a+", not attaching for easy access. Please use Shader.uniforms."+ a+".data to set data."):this[a]!==this.uniforms[a].data&&GLOW.warn("GLOW.Shader.attachUniformAndAttributeData: name collision on uniform "+a+", not attaching for easy access. Please use Shader.uniforms."+a+".data to access data.");for(b in this.compiledData.attributes){if(this.attributes===void 0)this.attributes=this.compiledData.attributes;this[b]===void 0?this[b]=this.compiledData.attributes[b]:this[b]!==this.compiledData.attributes[b]&&GLOW.warn("GLOW.Shader.attachUniformAndAttributeData: name collision on attribute "+ b+", not attaching for easy access. Please use Shader.attributes."+b+".data to access data.")}for(f in this.compiledData.interleavedAttributes){if(this.interleavedAttributes===void 0)this.interleavedAttributes=this.compiledData.interleavedAttributes;this[f]===void 0?this[f]=this.compiledData.interleavedAttributes[f]:this[f]!==this.compiledData.interleavedAttributes[f]&&GLOW.warn("GLOW.Shader.attachUniformAndAttributeData: name collision on interleavedAttribute "+b+", not attaching for easy access. Please use Shader.interleavedAttributes."+ b+".data to access data.")}};b.prototype.draw=function(){var a=this.compiledData,b=GLOW.currentContext.cache;if(!b.programCached(a.program)){GL.useProgram(a.program);var f=b.setProgramHighestAttributeNumber(a.program);if(f){var e=a.program.highestAttributeNumber,g=e-f+1;if(f>0)for(;g<=e;g++)GL.enableVertexAttribArray(g);else for(g--;g>e;g--)GL.disableVertexAttribArray(g)}}f=a.attributeArray;for(e=f.length;e--;)f[e].interleaved===!1&&(b.attributeCached(f[e])||f[e].bind());f=a.interleavedAttributeArray; for(e=f.length;e--;)b.interleavedAttributeCached(f[e])||f[e].bind();f=a.uniformArray;for(e=f.length;e--;)b.uniformCached(f[e])||f[e].load();a.elements.draw()};b.prototype.clone=function(a){return new GLOW.Shader({use:this.compiledData,except:a})};b.prototype.dispose=function(a,b){var f,e,g;for(f in this.compiledData.uniforms)delete this[f];for(e in this.compiledData.attributes)delete this[e];for(g in this.compiledData.interleavedAttributes)delete this[g];delete this.program;delete this.elements;delete this.uniforms; delete this.attributes;delete this.interleavedAttributes;this.compiledData.dispose(a,b);delete this.compiledData};return b}(); GLOW.Elements=function(){function b(a,b,f,e){this.id=GLOW.uniqueId();this.type=b!==void 0?b:GL.TRIANGLES;this.offset=e!==void 0?e:0;typeof a==="number"||a===void 0?this.length=a:(a instanceof Uint16Array||(a=new Uint16Array(a)),this.length=a.length,this.elements=GL.createBuffer(),GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER,this.elements),GL.bufferData(GL.ELEMENT_ARRAY_BUFFER,a,f?f:GL.STATIC_DRAW))}b.prototype.draw=function(){this.elements!==void 0?(GLOW.currentContext.cache.elementsCached(this)||GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, this.elements),GL.drawElements(this.type,this.length,GL.UNSIGNED_SHORT,this.offset)):GL.drawArrays(this.type,this.offset,this.length)};b.prototype.clone=function(a){a=a||{};return new GLOW.Elements(a.data||this.data,a.type||this.type,a.usage,a.offset||this.offset)};b.prototype.dispose=function(){this.elements!==void 0&&(GL.deleteBuffer(this.elements),delete this.elements)};return b}(); GLOW.Uniform=function(){function b(){f[GL.INT]=function(){GL.uniform1iv(this.location,this.getNativeValue())};f[GL.FLOAT]=function(){GL.uniform1fv(this.location,this.getNativeValue())};f[GL.INT_VEC2]=function(){GL.uniform2iv(this.location,this.getNativeValue())};f[GL.INT_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};f[GL.INT_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};f[GL.BOOL]=function(){GL.uniform1iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC2]= function(){GL.uniform2iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC2]=function(){GL.uniform2fv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC3]=function(){GL.uniform3fv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC4]=function(){GL.uniform4fv(this.location,this.getNativeValue())};f[GL.FLOAT_MAT2]=function(){GL.uniformMatrix2fv(this.location, !1,this.getNativeValue())};f[GL.FLOAT_MAT3]=function(){GL.uniformMatrix3fv(this.location,!1,this.getNativeValue())};f[GL.FLOAT_MAT4]=function(){GL.uniformMatrix4fv(this.location,!1,this.getNativeValue())};f[GL.SAMPLER_2D]=function(){this.data.texture!==void 0&&this.textureUnit!==-1&&!GLOW.currentContext.cache.textureCached(this.textureUnit,this.data)&&(GL.uniform1i(this.location,this.textureUnit),GL.activeTexture(GL.TEXTURE0+this.textureUnit),GL.bindTexture(GL.TEXTURE_2D,this.data.texture),this.data.autoUpdate&& this.data.updateTexture(this.data.autoUpdate))};f[GL.SAMPLER_CUBE]=function(){this.data.texture!==void 0&&this.textureUnit!==-1&&!GLOW.currentContext.cache.textureCached(this.textureUnit,this.data)&&(GL.uniform1i(this.location,this.textureUnit),GL.activeTexture(GL.TEXTURE0+this.textureUnit),GL.bindTexture(GL.TEXTURE_CUBE_MAP,this.data.texture),this.data.autoUpdate&&this.data.updateTexture(this.data.autoUpdate))}}function a(a,g){c||(c=!0,b());this.id=GLOW.uniqueId();this.data=g;this.name=a.name;this.length= a.length;this.type=a.type;this.location=a.location;this.locationNumber=a.locationNumber;this.textureUnit=-1;this.load=a.loadFunction||f[this.type]}var c=!1,f=[];a.prototype.getNativeValue=function(){return this.data.value};a.prototype.clone=function(a){return new GLOW.Uniform(this,a||this.data)};a.prototype.dispose=function(){delete this.data;delete this.load;delete this.location};return a}(); GLOW.Attribute=function(){function b(b,e,g,h){a||(a=!0,c[GL.INT]=1,c[GL.INT_VEC2]=2,c[GL.INT_VEC3]=3,c[GL.INT_VEC4]=4,c[GL.BOOL]=1,c[GL.BOOL_VEC2]=2,c[GL.BOOL_VEC3]=3,c[GL.BOOL_VEC4]=4,c[GL.FLOAT]=1,c[GL.FLOAT_VEC2]=2,c[GL.FLOAT_VEC3]=3,c[GL.FLOAT_VEC4]=4,c[GL.FLOAT_MAT2]=4,c[GL.FLOAT_MAT3]=9,c[GL.FLOAT_MAT4]=16);this.id=GLOW.uniqueId();this.data=e;this.location=b.location;this.locationNumber=b.locationNumber;this.offset=this.stride=0;this.usage=g!==void 0?g:GL.STATIC_DRAW;this.interleaved=h!==void 0? h:!1;this.size=c[b.type];this.name=b.name;this.type=b.type;this.data&&(this.data.length/this.size>65536&&GLOW.warn("GLOW.Attribute.constructor: Unreachable attribute? Please activate GL.drawArrays or split into multiple shaders. Indexed elements cannot reach attribute data beyond 65535."),this.interleaved===!1&&this.bufferData(this.data,this.usage))}var a=!1,c=[];b.prototype.setupInterleave=function(a,b){this.interleaved=!0;this.offset=a;this.stride=b};b.prototype.bufferData=function(a,b){if(a!== void 0&&this.data!==a)this.data=a;if(b!==void 0&&this.usage!==b)this.usage=b;if(this.buffer===void 0)this.buffer=GL.createBuffer();if(this.data.constructor.toString().indexOf(" Array()")!==-1)this.data=new Float32Array(this.data);GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.bufferData(GL.ARRAY_BUFFER,this.data,this.usage)};b.prototype.bind=function(){this.interleaved===!1&&GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.vertexAttribPointer(this.location,this.size,GL.FLOAT,!1,this.stride,this.offset)}; b.prototype.clone=function(a){if(this.interleaved)GLOW.error("GLOW.Attribute.clone: Cannot clone interleaved attribute. Please check your interleave setup.");else return a=a||{},new GLOW.Attribute(this,a.data||this.data,a.usage||this.usage,a.interleaved||this.interleaved)};b.prototype.dispose=function(){this.buffer&&(GL.deleteBuffer(this.buffer),delete this.buffer);delete this.data};return b}(); GLOW.InterleavedAttributes=function(){function b(a){this.id=GLOW.uniqueId();this.attributes=a;var b,f=a[0].data.length/a[0].size,e,g=a.length,h,i,j,k=[],l,m=[];for(e=0;e<g;e++)k[e]=0;for(b=0;b<f;b++)for(e=0;e<g;e++){l=a[e].data;j=k[e];h=0;for(i=a[e].size;h<i;h++)m.push(l[j++]);k[e]=j}this.data=new Float32Array(m);this.usage=a[0].usage;for(e=0;e<g;e++)if(this.usage!==a[e].usage){GLOW.warn("GLOW.InterleavedAttributes.construct: Attribute "+a[e].name+" has different usage, defaulting to STATIC_DRAW."); this.usage=GL.STATIC_DRAW;break}this.bufferData(this.data,this.usage);for(e=b=0;e<g;e++)b+=a[e].size*4;for(e=f=0;e<g;e++)a[e].setupInterleave(f,b),f+=a[e].size*4}b.prototype.bufferData=function(a,b){if(a!==void 0&&this.data!==a)this.data=a;if(this.buffer===void 0)this.buffer=GL.createBuffer();GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.bufferData(GL.ARRAY_BUFFER,this.data,b?b:GL.STATIC_DRAW)};b.prototype.bind=function(){GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);for(var a=this.attributes.length;a--;)this.attributes[a].bind()}; b.prototype.dispose=function(){this.buffer&&(GL.deleteBuffer(this.buffer),delete this.buffer);delete this.data;if(this.attributes){for(var a=this.attributes.length;a--;)this.attributes[a].dispose();delete this.attributes}};return b}(); GLOW.Float=function(){function b(a){a!==void 0&&a.length?this.value=new Float32Array(a):(this.value=new Float32Array(1),this.value[0]=a!==void 0?a:0)}b.prototype.set=function(a){this.value[0]=a;return this};b.prototype.add=function(a){this.value[0]+=a;return this};b.prototype.sub=function(a){this.value[0]-=a;return this};b.prototype.multiply=function(a){this.value[0]*=a;return this};b.prototype.divide=function(a){this.value[0]/=a;return this};b.prototype.modulo=function(a){this.value[0]%=a;return this}; return b}(); GLOW.Int=function(){function b(a){a!==void 0&&a.length?this.value=new Int32Array(a):(this.value=new Int32Array(1),this.value[0]=a!==void 0?a:0)}b.prototype.set=function(a){this.value[0]=a;return this};b.prototype.add=function(a){this.value[0]+=a;return this};b.prototype.sub=function(a){this.value[0]-=a;return this};b.prototype.multiply=function(a){this.value[0]*=a;return this};b.prototype.divide=function(a){this.value[0]/=a;return this};b.prototype.modulo=function(a){this.value[0]%=a;return this}; return b}();GLOW.Bool=function(){function b(a){this.value=[];this.value[0]=a!==void 0?!!a:!1}b.prototype.set=function(a){this.value[0]=!!a;return this};return b}();GLOW.Bool2=function(){function b(a,b){this.value=[];this.value[0]=a!==void 0?!!a:!1;this.value[1]=b!==void 0?!!b:!1}b.prototype.set=function(a,b){this.value[0]=!!a;this.value[1]=!!b;return this};return b}(); GLOW.Bool3=function(){function b(a,b,f){this.value=[];this.value[0]=a!==void 0?!!a:!1;this.value[1]=b!==void 0?!!b:!1;this.value[2]=f!==void 0?!!f:!1}b.prototype.set=function(a,b,f){this.value[0]=!!a;this.value[1]=!!b;this.value[2]=!!f;return this};return b}(); GLOW.Bool4=function(){function b(a,b,f,e){this.value=[];this.value[0]=a!==void 0?!!a:!1;this.value[1]=b!==void 0?!!b:!1;this.value[2]=f!==void 0?!!f:!1;this.value[3]=e!==void 0?!!e:!1}b.prototype.set=function(a,b,f,e){this.value[0]=!!a;this.value[1]=!!b;this.value[2]=!!f;this.value[3]=!!e;return this};return b}(); GLOW.Vector2=function(){function b(a,b){this.value=new Float32Array(2);this.value[0]=a!==void 0?a:0;this.value[1]=b!==void 0?b:0}b.prototype.set=function(a,b){this.value[0]=a;this.value[1]=b;return this};b.prototype.copy=function(a){this.value[0]=a.value[0];this.value[1]=a.value[1];return this};b.prototype.addSelf=function(a){this.value[0]+=a.value[0];this.value[1]+=a.value[1];return this};b.prototype.add=function(a,b){this.value[0]=a.value[0]+b.value[0];this.value[1]=a.value[1]+b.value[1];return this}; b.prototype.subSelf=function(a){this.value[0]-=a.x;this.value[1]-=a.y;return this};b.prototype.sub=function(a,b){this.value[0]=a.value[0]-b.value[0];this.value[1]=a.value[1]-b.value[1];return this};b.prototype.multiplySelf=function(a){this.value[0]*=a.value[0];this.value[1]*=a.value[1];return this};b.prototype.multiply=function(a,b){this.value[0]=a.value[0]*b.value[0];this.value[1]=a.value[1]*b.value[1];return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;return this}; b.prototype.negate=function(){this.value[0]=-this.value[0];this.value[1]=-this.value[1];return this};b.prototype.normalize=function(){this.multiplyScalar(1/this.length());return this};b.prototype.length=function(){return Math.sqrt(this.lengthSq())};b.prototype.lengthSq=function(){return this.value[0]*this.value[0]+this.value[1]*this.value[1]};b.prototype.clone=function(){return new GLOW.Vector2(this.value[0],this.value[1])};return b}(); GLOW.Vector3=function(){function b(a,b,f){this.value=new Float32Array(3);this.value[0]=a!==void 0?a:0;this.value[1]=b!==void 0?b:0;this.value[2]=f!==void 0?f:0}b.prototype.set=function(a,b,f){this.value[0]=a;this.value[1]=b;this.value[2]=f;return this};b.prototype.copy=function(a){this.set(a.value[0],a.value[1],a.value[2]);return this};b.prototype.add=function(a,b){a=a.value;b=b.value;this.value[0]=a[0]+b[0];this.value[1]=a[1]+b[1];this.value[2]=a[2]+b[2];return this};b.prototype.addSelf=function(a){a= a.value;this.value[0]+=a[0];this.value[1]+=a[1];this.value[2]+=a[2];return this};b.prototype.addScalar=function(a){this.value[0]+=a;this.value[1]+=a;this.value[2]+=a;return this};b.prototype.sub=function(a,b){a=a.value;b=b.value;this.value[0]=a[0]-b[0];this.value[1]=a[1]-b[1];this.value[2]=a[2]-b[2];return this};b.prototype.subSelf=function(a){a=a.value;this.value[0]-=a[0];this.value[1]-=a[1];this.value[2]-=a[2];return this};b.prototype.cross=function(a,b){a=a.value;b=b.value;this.value[0]=a[1]*b[2]- a[2]*b[1];this.value[1]=a[2]*b[0]-a[0]*b[2];this.value[2]=a[0]*b[1]-a[1]*b[0];return this};b.prototype.crossSelf=function(a){var a=a.value,b=a[0],f=a[1],a=a[2],e=this.value[0],g=this.value[1],h=this.value[2];this.value[0]=f*h-a*g;this.value[1]=a*e-b*h;this.value[2]=b*g-f*e;return this};b.prototype.multiply=function(a,b){a=a.value;b=b.value;this.value[0]=a[0]*b[0];this.value[1]=a[1]*b[1];this.value[2]=a[2]*b[2];return this};b.prototype.multiplySelf=function(a){a=a.value;this.value[0]*=a[0];this.value[1]*= a[1];this.value[2]*=a[2];return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;this.value[2]*=a;return this};b.prototype.divideSelf=function(a){a=a.value;this.value[0]/=a[0];this.value[1]/=a[1];this.value[2]/=a[2];return this};b.prototype.divideScalar=function(a){this.value[0]/=a;this.value[1]/=a;this.value[2]/=a;return this};b.prototype.negate=function(){this.value[0]=-this.value[0];this.value[1]=-this.value[1];this.value[2]=-this.value[2];return this};b.prototype.dot= function(a){a=a.value;return this.value[0]*a[0]+this.value[1]*a[1]+this.value[2]*a[2]};b.prototype.distanceTo=function(a){return Math.sqrt(this.distanceToSquared(a))};b.prototype.distanceToSquared=function(a){var a=a.value,b=this.value[0]-a[0],f=this.value[1]-a[1],a=this.value[2]-a[2];return b*b+f*f+a*a};b.prototype.length=function(){return Math.sqrt(this.lengthSq())};b.prototype.lengthSq=function(){return this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2]};b.prototype.lengthManhattan= function(){return this.value[0]+this.value[1]+this.value[2]};b.prototype.normalize=function(){var a=Math.sqrt(this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2]);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this};b.prototype.setPositionFromMatrix=function(a){a=a.value;this.value[0]=a[12];this.value[1]=a[13];this.value[2]=a[14]};b.prototype.setLength=function(a){return this.normalize().multiplyScalar(a)};b.prototype.isZero=function(){return Math.abs(this.value[0])< 1.0E-4&&Math.abs(this.value[1])<1.0E-4&&Math.abs(this.value[2])<1.0E-4};b.prototype.clone=function(){return GLOW.Vector3(this.value[0],this.value[1],this.value[2])};return b}(); GLOW.Vector4=function(){function b(a,b,f,e){this.value=new Float32Array(4);this.value[0]=a!==void 0?a:0;this.value[1]=b!==void 0?b:0;this.value[2]=f!==void 0?f:0;this.value[3]=e!==void 0?e:0}b.prototype.set=function(a,b,f,e){this.value[0]=a;this.value[1]=b;this.value[2]=f;this.value[3]=e;return this};b.prototype.copy=function(a){this.value[0]=a.value[0];this.value[1]=a.value[1];this.value[2]=a.value[2];this.value[3]=a.value[3];return this};b.prototype.add=function(a,b){this.value[0]=a.value[0]+b.value[0]; this.value[1]=a.value[1]+b.value[1];this.value[2]=a.value[2]+b.value[2];this.value[3]=a.value[3]+b.value[3];return this};b.prototype.addSelf=function(a){this.value[0]+=a.value[0];this.value[1]+=a.value[1];this.value[2]+=a.value[2];this.value[3]+=a.value[3];return this};b.prototype.sub=function(a,b){this.value[0]=a.value[0]-b.value[0];this.value[1]=a.value[1]-b.value[1];this.value[2]=a.value[2]-b.value[2];this.value[3]=a.value[3]-b.value[3];return this};b.prototype.subSelf=function(a){this.value[0]-= a.value[0];this.value[1]-=a.value[1];this.value[2]-=a.value[2];this.value[3]-=a.value[3];return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;this.value[2]*=a;this.value[3]*=a;return this};b.prototype.divideScalar=function(a){this.value[0]/=a;this.value[1]/=a;this.value[2]/=a;this.value[3]/=a;return this};b.prototype.lerpSelf=function(a,b){this.value[0]+=(a.x-this.value[0])*b;this.value[1]+=(a.y-this.value[1])*b;this.value[2]+=(a.z-this.value[2])*b;this.value[3]+= (a.w-this.value[3])*b;return this};b.prototype.lengthOfXYZ=function(){return Math.sqrt(this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2])};b.prototype.clone=function(){return new GLOW.Vector4(this.value[0],this.value[1],this.value[2],this.value[3])};return b}(); GLOW.Matrix3=function(){function b(){this.value=new Float32Array(9);this.identity()}b.prototype.set=function(a,b,f,e,g,h,i,j,k){this.value[0]=a;this.value[3]=b;this.value[6]=f;this.value[1]=e;this.value[4]=g;this.value[7]=h;this.value[2]=i;this.value[5]=j;this.value[8]=k;return this};b.prototype.identity=function(){this.set(1,0,0,0,1,0,0,0,1);return this};b.prototype.extractFromMatrix4=function(a){this.set(a.value[0],a.value[4],a.value[8],a.value[1],a.value[5],a.value[9],a.value[2],a.value[6],a.value[10]); return this};b.prototype.multiplyVector3=function(a){var b=a.value[0],f=a.value[1],e=a.value[2];a.value[0]=this.value[0]*b+this.value[3]*f+this.value[6]*e;a.value[1]=this.value[1]*b+this.value[4]*f+this.value[7]*e;a.value[2]=this.value[2]*b+this.value[5]*f+this.value[8]*e;return a};return b}(); GLOW.Matrix4=function(){function b(){this.value=new Float32Array(16);this.rotation=new GLOW.Vector3;this.position=new GLOW.Vector3;this.columnX=new GLOW.Vector3;this.columnY=new GLOW.Vector3;this.columnZ=new GLOW.Vector3;this.identity()}b.prototype.set=function(a,b,f,e,g,h,i,j,k,l,m,o,n,r,p,q){this.value[0]=a;this.value[4]=b;this.value[8]=f;this.value[12]=e;this.value[1]=g;this.value[5]=h;