-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGLOWCore.js
88 lines (88 loc) · 40.7 KB
/
GLOWCore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// GLOWCore.js r1.1 - http://github.com/empaempa/GLOW
var GLOW=function(){function d(a,b,c){this.flags=a;this.callback=b;this.context=c}var a={},b={},c=-1,e=[];d.prototype.dispatch=function(a,b){this.flags===a&&(this.context?this.callback.call(this.context,b):this.callback(b))};a.LOGS=1;a.WARNINGS=2;a.ERRORS=4;a.logFlags=a.ERRORS;a.currentContext={};a.registerContext=function(c){b[c.id]=c;a.enableContext(c)};a.getContextById=function(c){if(b[c])return b[c];GLOW.error("Couldn't find context id "+c+", returning current with id "+a.currentContext.id);return a.currentContext};
a.enableContext=function(b){a.currentContext=typeof b==="string"?getContextById(b):b;GL=a.GL=a.currentContext.GL};a.uniqueId=function(){return++c};a.log=function(b){a.logFlags&a.LOGS&&console.log(b);a.dispatch(a.LOGS,b)};a.warn=function(b){a.logFlags&a.WARNINGS&&console.warn(b);a.dispatch(a.WARNINGS,b)};a.error=function(b){a.logFlags&a.ERRORS&&console.error(b);a.dispatch(a.ERRORS,b)};a.addEventListener=function(a,b,c){e.push(new d(a,b,c));return e[e.length-1]};a.removeEventListener=function(b){b=
e.indexOf(b);b!==-1?e.splice(b,1):a.warn("GLOW.removeEventListener: Couldn't find listener object")};a.dispatch=function(a,b){for(var c=e.length;c--;)e[c].dispatch(a,b)};return a}(),GL={};
GLOW.Context=function(){function d(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(b){GLOW.error("GLOW.Context.construct: "+b)}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")}}d.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};d.prototype.clear=function(a){this.setupClear(a);GL.clear(this.clearSettings.bits);return this};d.prototype.enableBlend=function(a,b){a?(GL.enable(GL.BLEND),b&&this.setupBlend(b)):GL.disable(GL.BLEND);return this};d.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};d.prototype.enableDepthTest=function(a,b){a?(GL.enable(GL.DEPTH_TEST),b&&this.setupDepthTest(b)):GL.disable(GL.DEPTH_TEST);return this};d.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};d.prototype.enablePolygonOffset=
function(a,b){a?(GL.enable(GL.POLYGON_OFFSET_FILL),b&&this.setupPolygonOffset(b)):GL.disable(GL.POLYGON_OFFSET_FILL);return this};d.prototype.setupPolygonOffset=function(a){a.factor&&a.units&&GL.polygonOffset(a.factor,a.units)};d.prototype.enableStencilTest=function(a,b){a?(GL.enable(GL.STENCIL_TEST),b&&this.setupStencilTest(b)):GL.disable(GL.STENCIL_TEST);return this};d.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};d.prototype.enableCulling=function(a,b){a?(GL.enable(GL.CULL_FACE),b&&this.setupCulling(b)):GL.disable(GL.CULL_FACE);return this};d.prototype.setupCulling=function(a){try{a.frontFace&&GL.frontFace(a.frontFace),a.cullFace&&
GL.cullFace(a.cullFace)}catch(b){GLOW.error("GLOW.Context.setupCulling: "+b)}return this};d.prototype.enableScissor=function(a,b){a?(GL.enable(GL.SCISSOR_TEST),b&&this.setupScissor(b)):GL.disable(GL.SCISSOR_TEST);return this};d.prototype.setupScissor=function(a){try{GL.scissor(a.x,a.y,a.width,a.height)}catch(b){GLOW.error("GLOW.Context.setupScissorTest: "+b)}return this};d.prototype.setViewport=function(){this.setupViewport()};d.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};d.prototype.availableExtensions=function(){return GL.getSupportedExtensions()};d.prototype.enableExtension=function(a){for(var b=GL.getSupportedExtensions(),c=0,e=b.length;c<e;c++)if(a.toLowerCase()===
b[c].toLowerCase())break;if(c!==e)return GL.getExtension(b[c])};d.prototype.getParameter=function(a){return GL.getParameter(a)};d.prototype.maxVertexTextureImageUnits=function(){return this.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS)};d.prototype.resize=function(a,b){var c=b/this.height;this.viewport.width*=a/this.width;this.viewport.height*=c;this.domElement.width=this.width=a;this.domElement.height=this.height=b};return d}();
GLOW.Compiler=function(){var d={};d.compile=function(a){var b=GLOW.currentContext.cache.codeCompiled(a.vertexShader,a.fragmentShader);b===void 0&&(b=d.linkProgram(d.compileVertexShader(a.vertexShader),d.compileFragmentShader(a.fragmentShader)),GLOW.currentContext.cache.addCompiledProgram(b));var c=d.createUniforms(d.extractUniforms(b),a.data),e=d.createAttributes(d.extractAttributes(b),a.data,a.usage,a.interleave),j=d.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 f=a.indices,h=a.primitives!==void 0?a.primitives:GL.TRIANGLES,g=a.usage!==void 0?a.usage:{},i=g.primitives;if(a.triangles)f=a.triangles,i=g.triangles;else if(a.triangleStrip)f=a.triangleStrip,h=GL.TRIANGLE_STRIP,i=g.triangleStrip;else if(a.triangleFan)f=a.triangleFan,h=GL.TRIANGLE_FAN,i=g.triangleFan;else if(a.points)f=a.points,h=GL.POINTS,i=g.points;else if(a.lines)f=a.lines,h=GL.LINES,i=g.lines;else if(a.lineLoop)f=a.lineLoop,h=GL.LINE_LOOP,i=g.lineLoop;else if(a.lineStrip)f=a.lineStrip,
h=GL.LINE_STRIP,i=g.lineStrip;if(f===void 0){for(var k in e)if(e[k].data){f=e[k].data.length/e[k].size;break}if(f===void 0)for(var l in j){for(k in j[l].attributes){f=j[l].attributes[k].data.length/j[l].attributes[k].size;break}break}f===void 0&&(f=0)}f=d.createElements(f,h,i);return new GLOW.CompiledData(b,c,e,j,f,a)}};d.compileVertexShader=function(a){var b;b=GL.createShader(GL.VERTEX_SHADER);b.id=GLOW.uniqueId();GL.shaderSource(b,a);GL.compileShader(b);!GL.getShaderParameter(b,GL.COMPILE_STATUS)&&
!GL.isContextLost()&&GLOW.error("GLOW.Compiler.compileVertexShader: "+GL.getShaderInfoLog(b));return b};d.compileFragmentShader=function(a){var b;b=GL.createShader(GL.FRAGMENT_SHADER);b.id=GLOW.uniqueId();GL.shaderSource(b,a);GL.compileShader(b);!GL.getShaderParameter(b,GL.COMPILE_STATUS)&&!GL.isContextLost()&&GLOW.error("GLOW.Compiler.compileFragmentShader: "+GL.getShaderInfoLog(b));return b};d.linkProgram=function(a,b){var c=GL.createProgram();c||GLOW.error("GLOW.Compiler.linkProgram: Could not create program");
c.id=GLOW.uniqueId();GL.attachShader(c,a);GL.attachShader(c,b);GL.linkProgram(c);!GL.getProgramParameter(c,GL.LINK_STATUS)&&!GL.isContextLost()&&GLOW.error("GLOW.Compiler.linkProgram: Could not initialise program");return c};d.extractUniforms=function(a){for(var b={},c,e=0,d=GL.getProgramParameter(a,GL.ACTIVE_UNIFORMS);e<d;e++)if(c=GL.getActiveUniform(a,e),c!==null&&c!==-1&&c!==void 0)c={name:c.name.split("[")[0],size:c.size,type:c.type,location:GL.getUniformLocation(a,c.name.split("[")[0]),locationNumber:e},
b[c.name]=c;else break;return b};d.extractAttributes=function(a){for(var b={},c,e=0,d=GL.getProgramParameter(a,GL.ACTIVE_ATTRIBUTES);e<d;e++)if(c=GL.getActiveAttrib(a,e),c!==null&&c!==-1&&c!==void 0)c={name:c.name,size:c.size,type:c.type,location:GL.getAttribLocation(a,c.name),locationNumber:e},b[c.name]=c;else break;a.highestAttributeNumber=e-1;return b};d.createUniforms=function(a,b){var c,e={},d,f,h=0;for(c in a)if(d=a[c],f=d.name,b[f]instanceof GLOW.Uniform)e[f]=b[f];else if(b[f]===void 0&&GLOW.warn("GLOW.Compiler.createUniforms: missing data for uniform "+
f+". Creating anyway, but make sure to set data before drawing."),e[f]=new GLOW.Uniform(d,b[f]),e[f].type===GL.SAMPLER_2D||e[f].type===GL.SAMPLER_CUBE)e[f].textureUnit=h++,e[f].data!==void 0&&e[f].data.init();return e};d.createAttributes=function(a,b,c,e){var d,f,h,g={},i=!0,e=e!==void 0?e:{};e===!1&&(i=!1);c=c!==void 0?c:{};for(d in a)f=a[d],h=f.name,b[h]instanceof GLOW.Attribute?g[h]=b[h]:(b[h]===void 0&&GLOW.warn("GLOW.Compiler.createAttributes: missing data for attribute "+h+". Creating anyway, but make sure to set data before drawing."),
g[h]=new GLOW.Attribute(f,b[h],c[h],e[h]!==void 0?e[h]:i));return g};d.interleaveAttributes=function(a,b){b=b!==void 0?b:{};if(b===!1)return{};var c,e,d,f,h;d=0;var g=[];e=0;for(c in a)e++;if(e===1)for(c in a){if(a[c].interleaved===!0)a[c].interleaved=!1,a[c].data&&a[c].bufferData()}else{for(c in a)b[c]!==void 0&&b[c]!==!1&&(d=Math.max(d-1,b[c])+1);for(c in a)b[c]===void 0&&(b[c]=d);for(h in b)b[h]!==!1&&(g[b[h]]===void 0&&(g[b[h]]=[]),g[b[h]].push(a[h]));var i,k;c=0;for(e=g.length;c<e;c++)if(g[c]!==
void 0){d=i=0;for(f=g[c].length;d<f;d++)if(i+g[c][d].size*4>255){GLOW.warn("GLOW.Compiler.interleaveAttributes: Stride owerflow, moving attributes to new interleave index. Please check your interleave setup!");k=g.length;for(g[k]=[];d<f;)g[k].push(g[c][d]),g[c].splice(d,1),f--}else i+=g[c][d].size*4}k={};c=0;for(e=g.length;c<e;c++)if(g[c]!==void 0){i="";d=0;for(f=g[c].length;d<f;d++)i+=d!==f-1?g[c][d].name+"_":g[c][d].name;k[i]=new GLOW.InterleavedAttributes(g[c])}for(h in b)b[h]!==!1&&delete a[h];
return k}};d.createElements=function(a,b,c){return a instanceof GLOW.Elements?a:new GLOW.Elements(a,b,c)};return d}();
GLOW.CompiledData=function(){function d(a,b,c,e,d){this.id=GLOW.uniqueId();this.program=a;this.uniforms=b||{};this.attributes=c||{};this.interleavedAttributes=e||{};this.elements=d;this.interleavedAttributeArray=this.attributeArray=this.uniformArray=void 0;this.createArrays()}d.prototype.createArrays=function(){this.uniformArray=[];this.attributeArray=[];this.interleavedAttributeArray=[];var a,b,c;for(a in this.uniforms)this.uniformArray.push(this.uniforms[a]);for(b in this.attributes)this.attributeArray.push(this.attributes[b]);
for(c in this.interleavedAttributes)this.interleavedAttributeArray.push(this.interleavedAttributes[c])};d.prototype.clone=function(a){var b=new GLOW.CompiledData,a=a||{},c;for(c in this.uniforms)if(a[c])if(a[c]instanceof GLOW.Uniform)b.uniforms[c]=a[c];else{if(b.uniforms[c]=new GLOW.Uniform(this.uniforms[c],a[c]),b.uniforms[c].type===GL.SAMPLER_2D||b.uniforms[c].type===GL.SAMPLER_CUBE)b.uniforms[c].textureUnit=this.uniforms[c].textureUnit,b.uniforms[c].data&&b.uniforms[c].data.init()}else b.uniforms[c]=
this.uniforms[c];for(var e in this.attributes)b.attributes[e]=a[e]?a[e]instanceof GLOW.Attribute?a[e]:new GLOW.Attribute(this.attributes[e],a[e]):this.attributes[e];for(var d in this.interleavedAttributes)b.interleavedAttributes[d]=a[d]?a[d]:this.interleavedAttributes[d];b.elements=a.indices?new GLOW.Elements(a.indices,a.primitives):a.elements instanceof GLOW.Elements?a.elements:this.elements;b.program=a.program?a.program:this.program;b.createArrays();return b};d.prototype.dispose=function(a,b,c){if(a){for(a=
this.uniformArray.length;a--;)this.uniformArray[a].dispose(c);for(c=this.attributeArray.length;c--;)this.attributeArray[c].dispose();for(c=this.interleavedAttributeArray.length;c--;)this.interleavedAttributeArray[c].dispose();this.elements.dispose()}if(b&&GL.isProgram(this.program)&&(b=GL.getAttachedShaders(this.program))){for(c=b.length;c--;)GL.detachShader(this.program,b[c]),GL.deleteShader(b[c]);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 d}();
GLOW.Cache=function(){function d(){this.highestAttributeNumber=-1;this.uniformByLocation=[];this.attributeByLocation=[];this.textureByLocation=[];this.compiledCode=[];this.programId=this.elementId=-1;this.active=!0}d.prototype.codeCompiled=function(a,b){var c,e,d=this.compiledCode.length;for(e=0;e<d;e++)if(c=this.compiledCode[e],a===c.vertexShader&&b===c.fragmentShader)break;if(e===d)this.compiledCode.push({vertexShader:a,fragmentShader:b});else return this.compiledCode[e].program};d.prototype.addCompiledProgram=
function(a){this.compiledCode[this.compiledCode.length-1].program=a};d.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};d.prototype.setProgramHighestAttributeNumber=function(a){var b=this.highestAttributeNumber;this.highestAttributeNumber=a.highestAttributeNumber;return a.highestAttributeNumber-b};d.prototype.uniformCached=
function(a){if(this.active){if(this.uniformByLocation[a.locationNumber]===a.id)return!0;this.uniformByLocation[a.locationNumber]=a.id}return!1};d.prototype.invalidateUniform=function(a){this.uniformByLocation[a.locationNumber]=void 0};d.prototype.attributeCached=function(a){if(this.active){if(this.attributeByLocation[a.locationNumber]===a.id)return!0;this.attributeByLocation[a.locationNumber]=a.id}return!1};d.prototype.interleavedAttributeCached=function(a){if(this.active)for(var b=0,c=a.attributes.length,
e;b<c;b++){e=a.attributes[b];if(this.attributeByLocation[e.locationNumber]===e.id)return!0;this.attributeByLocation[e.locationNumber]=e.id}return!1};d.prototype.invalidateAttribute=function(a){this.attributeByLocation[a.locationNumber]=void 0};d.prototype.textureCached=function(a,b){if(this.active){if(this.textureByLocation[a]===b.id)return!0;this.textureByLocation[a]=b.id}return!1};d.prototype.invalidateTexture=function(a){this.textureByLocation[a]=void 0};d.prototype.elementsCached=function(a){if(this.active){if(a.id===
this.elementId)return!0;this.elementId=a.id}return!1};d.prototype.invalidateElements=function(){this.elementId=-1};d.prototype.clear=function(){this.highestAttributeNumber=-1;this.uniformByLocation.length=0;this.attributeByLocation.length=0;this.textureByLocation.length=0;this.programId=this.elementId=-1};return d}();
GLOW.FBO=function(){function d(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};d.prototype.createBuffers=function(){this.texture=GL.createTexture();var b=GL.getError();if(b!==GL.NO_ERROR&&b!==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 c in a)GL.texImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[c],0,this.internalFormat,this.width,this.height,0,this.format,this.type,this.data[c]);if(this.depth||this.stencil){this.renderBuffer=GL.createRenderbuffer();b=GL.getError();if(b!==GL.NO_ERROR&&b!==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();b=GL.getError();if(b!==GL.NO_ERROR&&b!==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();b=GL.getError();if(b!==GL.NO_ERROR&&b!==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)}};d.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 b in a)GL.deleteFramebuffer(this.frameBuffers[b])};d.prototype.init=function(){};d.prototype.bind=function(a,c){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[c!==void 0?c:"posX"]);return this};d.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};d.prototype.setViewport=function(){this.setupViewport()};d.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};d.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};d.prototype.clear=function(a){this.isBound&&(this.setupClear(a),GL.clear(this.clearSettings.bits));return this};d.prototype.resize=
function(a,c){var e=c/this.height;this.viewport.width*=a/this.width;this.viewport.height*=e;this.width=a;this.height=c;this.deleteBuffers();this.createBuffers();return this};d.prototype.generateMipMaps=function(){GL.bindTexture(this.textureType,this.texture);GL.generateMipmap(this.textureType);GL.bindTexture(this.textureType,null);return this};d.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 d}();
GLOW.Texture=function(){function d(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.onLoadError=a.onLoadError;this.onLoadContext=a.onLoadContext;this.texture=void 0;this.flipY=a.flipY||0}var a={posX:0,negX:1,posY:2,negY:3,posZ:4,negZ:5};d.prototype.init=function(){if(this.texture!==void 0)return this;GL.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL,this.flipY);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,c=b.toLowerCase();if(c.indexOf(".jpg")!==-1||c.indexOf(".png")!==-1||c.indexOf(".gif")!==-1||c.indexOf("jpeg")!==-1)this.data=new Image,this.data.scope=this,this.data.onerror=this.onLoadError,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],c=b.toLowerCase(),c.indexOf(".jpg")!==-1||c.indexOf(".png")!==-1||c.indexOf(".gif")!==-1||c.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};d.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||this.data instanceof Float32Array)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/Float32Array 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};d.prototype.updateTexture=function(b){if(this.texture!==void 0){var b=b!==void 0?b:{},c=b.level||0,e=b.xOffset||0,d=b.yOffset||0,f=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,c,e,d,this.width,
this.height,this.format,this.type,this.data):GL.texSubImage2D(this.textureType,c,e,d,this.format,this.type,this.data);else for(var h in b)a[h]!==void 0&&(this.data[h]instanceof Uint8Array?GL.texSubImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[h],c,e,d,this.width,this.height,this.format,this.type,this.data[h]):GL.texSubImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X+a[h],c,e,d,this.format,this.type,this.data[h]));this.minFilter!==GL.NEAREST&&this.minFilter!==GL.LINEAR&&f===!0&&GL.generateMipmap(this.textureType)}};
d.prototype.swapTexture=function(a){this.dispose();this.data=a;this.init()};d.prototype.onLoadImage=function(){this.scope.createTexture();this.scope.onLoadComplete&&this.scope.onLoadComplete.call(this.scope.onLoadContext,this.scope)};d.prototype.onLoadError=function(){this.scope.onLoadError&&this.scope.onLoadError.call(this.scope.onLoadContext,this.scope)};d.prototype.onLoadCubeImage=function(){this.scope.itemsToLoad--;this.scope.itemsToLoad===0&&this.scope.createTexture()};d.prototype.onLoadVideo=
function(){this.removeEventListener("loadeddata",this.scope.onLoadVideo,!1);this.scope.createTexture()};d.prototype.onLoadCubeVideo=function(){this.removeEventListener("loadeddata",this.scope.onLoadVideo,!1);this.scope.itemsToLoad--;this.scope.itemsToLoad===0&&this.scope.createTexture()};d.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()};d.prototype.dispose=
function(){if(this.texture!==void 0)GL.deleteTexture(this.texture),this.texture=void 0;this.data=void 0};return d}();
GLOW.Shader=function(){function d(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()}d.prototype.attachData=function(){var a,b,c;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(c in this.compiledData.interleavedAttributes){if(this.interleavedAttributes===void 0)this.interleavedAttributes=this.compiledData.interleavedAttributes;this[c]===void 0?this[c]=this.compiledData.interleavedAttributes[c]:this[c]!==this.compiledData.interleavedAttributes[c]&&GLOW.warn("GLOW.Shader.attachUniformAndAttributeData: name collision on interleavedAttribute "+b+", not attaching for easy access. Please use Shader.interleavedAttributes."+
b+".data to access data.")}};d.prototype.draw=function(){var a=this.compiledData,b=GLOW.currentContext.cache,c=b.attributeByLocation,d=b.uniformByLocation,j=a.attributeArray,f=a.interleavedAttributeArray,h=a.uniformArray,g,i,k,l;if(!b.programCached(a.program)&&(GL.useProgram(a.program),g=b.setProgramHighestAttributeNumber(a.program)))if(i=a.program.highestAttributeNumber,k=i-g+1,g>0)for(;k<=i;k++)GL.enableVertexAttribArray(k);else for(k--;k>i;k--)GL.disableVertexAttribArray(k);if(b.active){for(b=
j.length;b--;)if(g=j[b],g.interleaved===!1&&c[g.locationNumber]!==g.id)c[g.locationNumber]=g.id,g.bind();for(b=f.length;b--;){j=f[b];i=j.attributes;k=i.length;for(l=!1;k--;){g=i[k];if(c[g.locationNumber]===g.id){l=!0;break}c[g.locationNumber]=g.id}l||j.bind()}for(b=h.length;b--;)if(c=h[b],d[c.locationNumber]!==c.id)d[c.locationNumber]=c.id,c.load()}else{for(b=j.length;b--;)j[b].interleaved===!1&&j[b].bind();for(b=f.length;b--;)f[b].bind();for(b=h.length;b--;)h[b].load()}a.elements.draw()};d.prototype.clone=
function(a){return new GLOW.Shader({use:this.compiledData,except:a})};d.prototype.applyUniformData=function(a,b){if(this.compiledData.uniforms[a]!==void 0){this[a]=b;this.compiledData.uniforms[a].data=b;for(var c=this.compiledData.uniformArray.length;c--;)if(this.compiledData.uniformArray[c].name===a){this.compiledData.uniformArray[c].data=b;break}}};d.prototype.dispose=function(a,b,c){var d,j,f;for(d in this.compiledData.uniforms)delete this[d];for(j in this.compiledData.attributes)delete this[j];
for(f in this.compiledData.interleavedAttributes)delete this[f];delete this.program;delete this.elements;delete this.uniforms;delete this.attributes;delete this.interleavedAttributes;this.compiledData.dispose(a,b,c);delete this.compiledData};return d}();
GLOW.Elements=function(){function d(a,b,c,d){this.id=GLOW.uniqueId();this.type=b!==void 0?b:GL.TRIANGLES;this.offset=d!==void 0?d: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,c?c:GL.STATIC_DRAW))}d.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)};d.prototype.clone=function(a){a=a||{};return new GLOW.Elements(a.data||this.data,a.type||this.type,a.usage,a.offset||this.offset)};d.prototype.dispose=function(){this.elements!==void 0&&(GL.deleteBuffer(this.elements),delete this.elements)};return d}();
GLOW.Uniform=function(){function d(){c[GL.INT]=function(){GL.uniform1iv(this.location,this.getNativeValue())};c[GL.FLOAT]=function(){GL.uniform1fv(this.location,this.getNativeValue())};c[GL.INT_VEC2]=function(){GL.uniform2iv(this.location,this.getNativeValue())};c[GL.INT_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};c[GL.INT_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};c[GL.BOOL]=function(){GL.uniform1iv(this.location,this.getNativeValue())};c[GL.BOOL_VEC2]=
function(){GL.uniform2iv(this.location,this.getNativeValue())};c[GL.BOOL_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};c[GL.BOOL_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};c[GL.FLOAT_VEC2]=function(){GL.uniform2fv(this.location,this.getNativeValue())};c[GL.FLOAT_VEC3]=function(){GL.uniform3fv(this.location,this.getNativeValue())};c[GL.FLOAT_VEC4]=function(){GL.uniform4fv(this.location,this.getNativeValue())};c[GL.FLOAT_MAT2]=function(){GL.uniformMatrix2fv(this.location,
!1,this.getNativeValue())};c[GL.FLOAT_MAT3]=function(){GL.uniformMatrix3fv(this.location,!1,this.getNativeValue())};c[GL.FLOAT_MAT4]=function(){GL.uniformMatrix4fv(this.location,!1,this.getNativeValue())};c[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))};c[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,j){b||(b=!0,d());this.id=GLOW.uniqueId();this.data=j;this.name=a.name;this.length=
a.length;this.type=a.type;this.location=a.location;this.locationNumber=a.locationNumber;this.textureUnit=a.textureUnit!==void 0?a.textureUnit:-1;this.load=a.loadFunction||c[this.type]}var b=!1,c=[];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(a){this.data!==void 0&&this.type===GL.SAMPLER_2D&&a&&this.data.dispose();delete this.data;delete this.load;delete this.location};return a}();
GLOW.Attribute=function(){function d(c,d,j,f){a||(a=!0,b[GL.INT]=1,b[GL.INT_VEC2]=2,b[GL.INT_VEC3]=3,b[GL.INT_VEC4]=4,b[GL.BOOL]=1,b[GL.BOOL_VEC2]=2,b[GL.BOOL_VEC3]=3,b[GL.BOOL_VEC4]=4,b[GL.FLOAT]=1,b[GL.FLOAT_VEC2]=2,b[GL.FLOAT_VEC3]=3,b[GL.FLOAT_VEC4]=4,b[GL.FLOAT_MAT2]=4,b[GL.FLOAT_MAT3]=9,b[GL.FLOAT_MAT4]=16);this.id=GLOW.uniqueId();this.data=d;this.location=c.location;this.locationNumber=c.locationNumber;this.offset=this.stride=0;this.usage=j!==void 0?j:GL.STATIC_DRAW;this.interleaved=f!==void 0?
f:!1;this.size=b[c.type];this.name=c.name;this.type=c.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,b=[];d.prototype.setupInterleave=function(a,b){this.interleaved=!0;this.offset=a;this.stride=b};d.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)};d.prototype.bufferSubData=function(a,b){b===void 0&&(b=0);this.buffer===void 0&&GLOW.error("GLOWAttribute.prototype.bufferSubData: call bufferData first");a.constructor.toString().indexOf(" Array()")!==
-1&&(a=new Float32Array(a));GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.bufferSubData(GL.ARRAY_BUFFER,b,a)};d.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)};d.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)};d.prototype.dispose=function(){this.buffer&&(GL.deleteBuffer(this.buffer),delete this.buffer);delete this.data};return d}();
GLOW.InterleavedAttributes=function(){function d(a){this.id=GLOW.uniqueId();this.attributes=a;var b,c=a[0].data.length/a[0].size,d,j=a.length,f,h,g,i=[],k,l=[];for(d=0;d<j;d++)i[d]=0;for(b=0;b<c;b++)for(d=0;d<j;d++){k=a[d].data;g=i[d];f=0;for(h=a[d].size;f<h;f++)l.push(k[g++]);i[d]=g}this.data=new Float32Array(l);this.usage=a[0].usage;for(d=0;d<j;d++)if(this.usage!==a[d].usage){GLOW.warn("GLOW.InterleavedAttributes.construct: Attribute "+a[d].name+" has different usage, defaulting to STATIC_DRAW.");
this.usage=GL.STATIC_DRAW;break}this.bufferData(this.data,this.usage);for(d=b=0;d<j;d++)b+=a[d].size*4;for(d=c=0;d<j;d++)a[d].setupInterleave(c,b),c+=a[d].size*4}d.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)};d.prototype.bind=function(){GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);for(var a=this.attributes.length;a--;)this.attributes[a].bind()};
d.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 d}();