text: !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.WebGLWrapper=t():e.WebGLWrapper=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractUniformSetter:()=>s,BooleanUniformSetter:()=>S,Float2UniformSetter:()=>d,Float3UniformSetter:()=>u,Float4UniformSetter:()=>f,FloatUniformSetter:()=>l,Framebuffer:()=>n,Int2UniformSetter:()=>g,Int3UniformSetter:()=>_,Int4UniformSetter:()=>c,IntUniformSetter:()=>p,Mat2UniformSetter:()=>T,Mat3UniformSetter:()=>R,Mat4UniformSetter:()=>w,Mesh:()=>o,Program:()=>F,Renderbuffer:()=>i,Sampler:()=>D,Shader:()=>a,Texture:()=>P,Uint2UniformSetter:()=>m,Uint3UniformSetter:()=>E,Uint4UniformSetter:()=>y,UintUniformSetter:()=>b,WebGLWrapper:()=>U,glUtil:()=>x});var r,i=function(){function e(e,t,r,i){this.gl=e,this._width=t,this._height=r,this._internalFormat=i,this._handleGenerated=!1,this._storageGenerated=!1,this._isDeleted=!1}return Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"internalFormat",{get:function(){return this._internalFormat},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"storageGenerated",{get:function(){return this._storageGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),e.prototype.generateHandle=function(){if(this._isDeleted)throw new Error("Renderbuffer has been deleted");if(this._handleGenerated)throw new Error("Renderbuffer handle has already been generated");this._handle=this.gl.createRenderbuffer(),this._handleGenerated=!0},e.prototype.generateStorage=function(e){if(void 0===e&&(e=null),this._isDeleted)throw new Error("Renderbuffer has been deleted");if(this._storageGenerated)throw new Error("Renderbuffer storage has already been generated");this._handleGenerated||this.generateHandle(),null!=e&&(this._internalFormat=e),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._handle),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this._internalFormat,this._width,this._height),this._storageGenerated=!0},e.prototype.bind=function(){if(this._isDeleted)throw new Error("Renderbuffer has been deleted");this._handleGenerated||this.generateHandle(),this._storageGenerated||this.generateStorage(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._handle)},e.prototype.delete=function(){if(this._isDeleted)throw new Error("Renderbuffer has already been deleted");if(!this._handleGenerated)throw new Error("Cannot delete renderbuffer before it has been generated");this.gl.deleteRenderbuffer(this._handle),this._isDeleted=!0},e}(),n=function(){function e(e,t,r){this.gl=e,this._width=t,this._height=r,this._handleGenerated=!1,this._isComplete=!1,this._isDeleted=!1}return Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isComplete",{get:function(){return this._isComplete},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),e.prototype.generateHandle=function(){if(this._isDeleted)throw new Error("Framebuffer has been deleted");if(this._handleGenerated)throw new Error("Framebuffer handle has already been generated");this._handle=this.gl.createFramebuffer(),this._handleGenerated=!0},e.prototype.bind=function(e,t){if(void 0===e&&(e=this.gl.FRAMEBUFFER),void 0===t&&(t=!1),this._isDeleted)throw new Error("Framebuffer has been deleted");if(this._handleGenerated||this.generateHandle(),t&&!this.check(e))throw new Error("Framebuffer check failed! Framebuffer is incomplete!");this.gl.bindFramebuffer(e,this._handle)},e.prototype.check=function(e){if(this._isDeleted)throw new Error("Framebuffer has been deleted");if(!this._handleGenerated)throw new Error("Cannot check framebuffer status before it has been generated");return this.gl.bindFramebuffer(e,this._handle),this.gl.checkFramebufferStatus(e)==this.gl.FRAMEBUFFER_COMPLETE?(this._isComplete=!0,!0):(this._isComplete=!1,!1)},e.prototype.applyViewport=function(){this.gl.viewport(0,0,this._width,this._height)},e.prototype.beforeAttach=function(){if(this._isDeleted)throw new Error("Framebuffer has been deleted");this._handleGenerated||this.generateHandle()},e.prototype.attachColorTexture=function(e,t){if(this.beforeAttach(),t.target!=this.gl.TEXTURE_2D)throw new Error("Cannot attach non-2D texture as color attachment");this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0+e,t.target,t.handle,0)},e.prototype.attachColorTextureLayer=function(e,t,r){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferTextureLayer(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0+e,t.handle,0,r)},e.prototype.attachColorRenderbuffer=function(e,t){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0+e,this.gl.RENDERBUFFER,t.handle)},e.prototype.attachDepthTexture=function(e){if(this.beforeAttach(),e.target!=this.gl.TEXTURE_2D)throw new Error("Cannot attach non-2D texture as depth attachment");this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,e.target,e.handle,0)},e.prototype.attachDepthRenderbuffer=function(e){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,e.handle)},e.prototype.attachStencilTexture=function(e){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.STENCIL_ATTACHMENT,e.target,e.handle,0)},e.prototype.attachStencilRenderbuffer=function(e){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.STENCIL_ATTACHMENT,this.gl.RENDERBUFFER,e.handle)},e.prototype.attachDepthStencilTexture=function(e){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.DEPTH_STENCIL_ATTACHMENT,e.target,e.handle,0)},e.prototype.attachDepthStencilRenderbuffer=function(e){this.beforeAttach(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this._handle),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_STENCIL_ATTACHMENT,this.gl.RENDERBUFFER,e.handle)},e.prototype.delete=function(){if(this._isDeleted)throw new Error("Framebuffer has already been deleted");if(!this._handleGenerated)throw new Error("Cannot delete framebuffer before it has been generated");this.gl.deleteFramebuffer(this._handle),this._isDeleted=!0},e}(),o=function(){function e(e){this.gl=e,this._isInitialized=!1,this._isIndexed=!1,this._vertexCount=0,this._vertexAttributes=[],this._indexType=null,this._primitiveType=null}return Object.defineProperty(e.prototype,"vao",{get:function(){return this._vao},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vbo",{get:function(){return this._vbo},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ibo",{get:function(){return this._ibo},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isInitialized",{get:function(){return this._isInitialized},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isIndexed",{get:function(){return this._isIndexed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vertexCount",{get:function(){return this._vertexCount},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vertexAttributes",{get:function(){return this._vertexAttributes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"indexType",{get:function(){return this._indexType},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"primitiveType",{get:function(){return this._primitiveType},enumerable:!1,configurable:!0}),e.prototype.setup=function(e,t,r){this._isIndexed=r,this._vertexAttributes=e,this._primitiveType=t,this.setupBuffers(),this.setupVAO(),this._isInitialized=!0},e.prototype.sizeOfGLType=function(e){switch(e){case this.gl.FLOAT:return Float32Array.BYTES_PER_ELEMENT;case this.gl.UNSIGNED_INT:case this.gl.INT:return Int32Array.BYTES_PER_ELEMENT;case this.gl.UNSIGNED_SHORT:case this.gl.SHORT:return Int16Array.BYTES_PER_ELEMENT;case this.gl.UNSIGNED_BYTE:case this.gl.BYTE:return Int8Array.BYTES_PER_ELEMENT;default:throw new Error("Unknown GL type for vertex attributes: "+e)}},e.prototype.vertexSize=function(){for(var e=0,t=0;t<this._vertexAttributes.length;t++){var r=this._vertexAttributes[t];e+=this.sizeOfGLType(r.type)*r.length}return e},e.prototype.setupVAO=function(){for(var e=0,t=[0],r=0;r<this._vertexAttributes.length;r++){var i=this._vertexAttributes[r];e+=n=this.sizeOfGLType(i.type)*i.length,t.push(t[r]+n)}for(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._vbo),this._isIndexed&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._ibo),r=0;r<this._vertexAttributes.length;r++){i=this._vertexAttributes[r];var n=this.sizeOfGLType(i.type)*i.length;this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,i.length,i.type,i.normalized,e,t[r])}},e.prototype.setupBuffers=function(){this._vbo=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._vbo),this.gl.bufferData(this.gl.ARRAY_BUFFER,0,this.gl.STATIC_DRAW),this._isIndexed&&(this._ibo=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._ibo),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,0,this.gl.STATIC_DRAW))},e.prototype.uploadVertexData=function(e,t){if(void 0===t&&(t=null),!this._isIndexed&&null==t)throw new Error("Vertex count must be set when not using indexed rendering!");if(!this._isInitialized)throw new Error("Mesh must be initialized before data upload!");this._isIndexed||(this._vertexCount=t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this._vbo),this.gl.bufferData(this.gl.ARRAY_BUFFER,e,this.gl.STATIC_DRAW)},e.prototype.uploadIndexDataShort=function(e,t){if(!this._isInitialized)throw new Error("Mesh must be initialized before data upload!");if(!this._isIndexed)throw new Error("This mesh does not use indexed rendering!");this._vertexCount=t,this._indexType=this.gl.UNSIGNED_SHORT,this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._ibo),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,e,this.gl.STATIC_DRAW)},e.prototype.uploadIndexDataInt=function(e,t){if(!this._isInitialized)throw new Error("Mesh must be initialized before data upload!");if(!this._isIndexed)throw new Error("This mesh does not use indexed rendering!");this._vertexCount=t,this._indexType=this.gl.UNSIGNED_INT,this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this._ibo),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,e,this.gl.STATIC_DRAW)},e.prototype.draw=function(){if(!this._isInitialized)throw new Error("Mesh must be initialized before drawing!");this.gl.bindVertexArray(this._vao),this._isIndexed?this.gl.drawElements(this._primitiveType,this._vertexCount,this._indexType,0):this.gl.drawArrays(this._primitiveType,0,this._vertexCount)},e}(),a=function(){function e(e,t,r){this.gl=e,this._handleGenerated=!1,this._isCompiled=!1,this._hasCompilationError=!1,this._isDeleted=!1,this._type=t,r&&(this._source=r)}return Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"source",{get:function(){return this._source},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isCompiled",{get:function(){return this._isCompiled},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasCompilationError",{get:function(){return this._hasCompilationError},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),e.prototype.generateHandle=function(){if(this._handleGenerated)throw new Error("Handle has already been generated!");if(this._isDeleted)throw new Error("Shader has been deleted!");this._handle=this.gl.createShader(this._type),this._handleGenerated=!0},e.prototype.attachSource=function(e){if(this._isCompiled)throw new Error("Shader is already compiled, cannot attach source at this point!");if(this._isDeleted)throw new Error("Shader has been deleted!");e&&(this._source=e),this._handleGenerated||this.generateHandle(),this._source&&this.gl.shaderSource(this._handle,this._source)},e.prototype.compile=function(){if(this._isCompiled)throw new Error("Shader is already compiled!");if(this._hasCompilationError)throw new Error("Shader compilation was requested previously, but failed with compilation error!");if(this._isDeleted)throw new Error("Shader has been deleted!");this._handleGenerated||this.generateHandle(),this.gl.compileShader(this.handle),this.gl.getShaderParameter(this._handle,this.gl.COMPILE_STATUS)?(this._isCompiled=!0,this._hasCompilationError=!1):(this._isCompiled=!1,this._hasCompilationError=!0)},e.prototype.delete=function(){if(this._isDeleted)throw new Error("Shader is already deleted!");this._handleGenerated||this.generateHandle(),this.gl.deleteShader(this._handle),this._isDeleted=!0},e.prototype.getInfoLog=function(){if(this._isDeleted)throw new Error("Shader has been deleted!");return this._handleGenerated||this.generateHandle(),this.gl.getShaderInfoLog(this._handle)},e}(),h=(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}),s=function(){function e(e,t,r,i,n){this.gl=e,this._uniformName=t,this._uniformLocation=r,this._uniformInfo=i,this._program=n}return Object.defineProperty(e.prototype,"uniformName",{get:function(){return this._uniformName},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"uniformLocation",{get:function(){return this._uniformLocation},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"uniformInfo",{get:function(){return this._uniformInfo},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"program",{get:function(){return this._program},enumerable:!1,configurable:!0}),e}(),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform1f(this._uniformLocation,e)},t}(s),d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform2f(this._uniformLocation,e[0],e[1])},t}(s),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform3f(this._uniformLocation,e[0],e[1],e[2])},t}(s),f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform4f(this._uniformLocation,e[0],e[1],e[2],e[3])},t}(s),p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform1i(this._uniformLocation,e)},t}(s),g=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform2i(this._uniformLocation,e[0],e[1])},t}(s),_=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform3i(this._uniformLocation,e[0],e[1],e[2])},t}(s),c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform4i(this._uniformLocation,e[0],e[1],e[2],e[3])},t}(s),b=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform1ui(this._uniformLocation,e)},t}(s),m=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform2ui(this._uniformLocation,e[0],e[1])},t}(s),E=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform3ui(this._uniformLocation,e[0],e[1],e[2])},t}(s),y=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform4ui(this._uniformLocation,e[0],e[1],e[2],e[3])},t}(s),T=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniformMatrix2fv(this._uniformLocation,!1,e)},t}(s),R=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniformMatrix3fv(this._uniformLocation,!1,e)},t}(s),w=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniformMatrix4fv(this._uniformLocation,!1,e)},t}(s),S=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return h(t,e),t.prototype.apply=function(e){this.gl.uniform1i(this._uniformLocation,e?1:0)},t}(s),F=function(){function e(e,t,r){this.gl=e,this._vertexShader=null,this._fragmentShader=null,this._handleGenerated=!1,this._isLinked=!1,this._hasLinkError=!1,this._isValidated=!1,this._hasValidationError=!1,this._isDeleted=!1,this._inputAttributes={},this._attributeLocations={},this._uniforms={},this._uniformSetters={},this._isVertexShaderAttached=!1,this._isFragmentShaderAttached=!1,t&&(this._vertexShader=t),r&&(this._fragmentShader=r)}return Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"vertexShader",{get:function(){return this._vertexShader},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fragmentShader",{get:function(){return this._fragmentShader},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isLinked",{get:function(){return this._isLinked},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasLinkError",{get:function(){return this._hasLinkError},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValidated",{get:function(){return this._isValidated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasValidationError",{get:function(){return this._hasValidationError},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"inputAttributes",{get:function(){return this._inputAttributes},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"attributeLocations",{get:function(){return this._attributeLocations},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"uniforms",{get:function(){return this._uniforms},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"uniformSetters",{get:function(){return this._uniformSetters},enumerable:!1,configurable:!0}),e.prototype.tryAttachShaders=function(){this._vertexShader&&!this._isVertexShaderAttached&&(this.gl.attachShader(this._handle,this._vertexShader.handle),this._isVertexShaderAttached=!0),this._fragmentShader&&!this._isFragmentShaderAttached&&(this.gl.attachShader(this._handle,this._fragmentShader.handle),this._isFragmentShaderAttached=!0)},e.prototype.populateAttributes=function(){for(var e=this.gl.getProgramParameter(this._handle,this.gl.ACTIVE_ATTRIBUTES),t=0;t<e;t++){var r=this.gl.getActiveAttrib(this._handle,t);this._inputAttributes[r.name]=r,this._attributeLocations[r.name]=t}},e.prototype.createUniformSetter=function(e,t){switch(e.type){case this.gl.FLOAT:return new l(this.gl,e.name,t,e,this);case this.gl.FLOAT_VEC2:return new d(this.gl,e.name,t,e,this);case this.gl.FLOAT_VEC3:return new u(this.gl,e.name,t,e,this);case this.gl.FLOAT_VEC4:return new f(this.gl,e.name,t,e,this);case this.gl.INT:case this.gl.SAMPLER_2D:case this.gl.SAMPLER_3D:case this.gl.SAMPLER_CUBE:case this.gl.INT_SAMPLER_2D:case this.gl.INT_SAMPLER_3D:case this.gl.INT_SAMPLER_CUBE:case this.gl.UNSIGNED_INT_SAMPLER_2D:case this.gl.UNSIGNED_INT_SAMPLER_3D:case this.gl.UNSIGNED_INT_SAMPLER_CUBE:return new p(this.gl,e.name,t,e,this);case this.gl.INT_VEC2:return new g(this.gl,e.name,t,e,this);case this.gl.INT_VEC3:return new _(this.gl,e.name,t,e,this);case this.gl.INT_VEC4:return new c(this.gl,e.name,t,e,this);case this.gl.UNSIGNED_INT:return new b(this.gl,e.name,t,e,this);case this.gl.UNSIGNED_INT_VEC2:return new m(this.gl,e.name,t,e,this);case this.gl.UNSIGNED_INT_VEC3:return new E(this.gl,e.name,t,e,this);case this.gl.UNSIGNED_INT_VEC4:return new y(this.gl,e.name,t,e,this);case this.gl.FLOAT_MAT2:return new T(this.gl,e.name,t,e,this);case this.gl.FLOAT_MAT3:return new R(this.gl,e.name,t,e,this);case this.gl.FLOAT_MAT4:return new w(this.gl,e.name,t,e,this)}},e.prototype.populateUniforms=function(){for(var e=this.gl.getProgramParameter(this._handle,this.gl.ACTIVE_UNIFORMS),t=0;t<e;t++){var r=this.gl.getActiveUniform(this._handle,t);if(r.size>1)for(var i=0;i<r.size;i++){var n=r.name.replace(/\[0\]/,"["+i+"]"),o=this.gl.getUniformLocation(this._handle,n),a=this.createUniformSetter(r,o);this._uniforms[n]=r,this._uniformSetters[n]=a}else{var h=this.gl.getUniformLocation(this._handle,r.name);this._uniforms[r.name]=r,this._uniformSetters[r.name]=this.createUniformSetter(r,h)}}},e.prototype.populate=function(){this.populateAttributes(),this.populateUniforms()},e.prototype.generateHandle=function(){if(this._handleGenerated)throw new Error("Handle has already been generated!");if(this._isDeleted)throw new Error("Program has been deleted!");this._handle=this.gl.createProgram(),this._handleGenerated=!0,(this._vertexShader||this._fragmentShader)&&this.tryAttachShaders()},e.prototype.attachShader=function(e){if(this._isLinked)throw new Error("Program has already been linked, cannot attach shaders at this point!");if(this._isDeleted)throw new Error("Program has been deleted!");this._handleGenerated||this.generateHandle(),e.type==this.gl.VERTEX_SHADER?(this._isVertexShaderAttached&&this.gl.detachShader(this._handle,this._vertexShader.handle),this.gl.attachShader(this._handle,e.handle),this._vertexShader=e,this._isVertexShaderAttached=!0):e.type==this.gl.FRAGMENT_SHADER&&(this._isFragmentShaderAttached&&this.gl.detachShader(this._handle,this._fragmentShader.handle),this.gl.attachShader(this._handle,e.handle),this._fragmentShader=e,this._isFragmentShaderAttached=!0)},e.prototype.link=function(){if(this._isLinked)throw new Error("Program has already been linked!");if(this._hasLinkError)throw new Error("Linking of program was requested before, but failed with error!");if(this._isDeleted)throw new Error("Program has been deleted!");this._handleGenerated||this.generateHandle(),this.gl.linkProgram(this._handle),this.gl.getProgramParameter(this._handle,this.gl.LINK_STATUS)?(this._isLinked=!0,this._hasLinkError=!1,this.populate()):(this._isLinked=!1,this._hasLinkError=!0)},e.prototype.validate=function(){if(!this._isLinked)throw new Error("Program must be linked before validation!");if(this._isDeleted)throw new Error("Program has been deleted!");this.gl.validateProgram(this._handle),this.gl.getProgramParameter(this._handle,this.gl.VALIDATE_STATUS)?(this._isValidated=!0,this._hasValidationError=!1):(this._isValidated=!1,this._hasValidationError=!0)},e.prototype.delete=function(){if(this._isDeleted)throw new Error("Program has already been deleted!");this.gl.deleteProgram(this._handle),this._isDeleted=!0},e.prototype.getInfoLog=function(){if(this._isDeleted)throw new Error("Program has been deleted!");return this._handleGenerated||this.generateHandle(),this.gl.getProgramInfoLog(this._handle)},e.prototype.setUniform=function(e,t){var r=this._uniformSetters[e];if(!r)throw new Error("No uniform with name "+e+" can be found in the program!");r.apply(t)},e.prototype.use=function(){if(!this._isLinked)throw new Error("Program cannot be used before it has been linked!");if(this._isDeleted)throw new Error("Program has been deleted!");this.gl.useProgram(this._handle)},e.prototype.unuse=function(){this.gl.useProgram(null)},e}(),A=function(){function e(){var e=this;this.reverseGLEnumMap={};var t=WebGL2RenderingContext.prototype;Object.keys(WebGL2RenderingContext.prototype).forEach((function(r){/^[A-Z0-9_]+$/.test(r)&&(e.reverseGLEnumMap[t[r]]=r)}))}return e.prototype.nameOfGLEnum=function(e){return this.reverseGLEnumMap[e]||"Unknown enum"},e.prototype.cubemapFaceIDValue=function(e){switch(e){case"+x":return WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X;case"-x":return WebGL2RenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_X;case"+y":return WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Y;case"-y":return WebGL2RenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Y;case"+z":return WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Z;default:return WebGL2RenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Z}},e}();window.glUtil||(window.glUtil=new A);const x=window.glUtil;var P=function(){function e(t,r,i,n,o){if(void 0===n&&(n=e.DEFAULT_PIXEL_FORMAT),void 0===o&&(o=e.DEFAULT_SAMPLING_PROPERTIES),this.gl=t,this._target=i,this._pixelFormat=n,this._samplingProperties=o,this._handleGenerated=!1,this._isDeleted=!1,this._isStorageInitialized=!1,!this.validateTarget(i))throw new Error(x.nameOfGLEnum(i)+" is not a valid target!");this._width=r[0],this._height=r[1],3==r.length&&(this._depth=r[2]),n||(this._pixelFormat=e.DEFAULT_PIXEL_FORMAT),o||(this._samplingProperties=e.DEFAULT_SAMPLING_PROPERTIES)}return e.prototype.validateTarget=function(t){return e.VALID_TARGETS.indexOf(t)>=0},Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"depth",{get:function(){return this._depth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pixelFormat",{get:function(){return this._pixelFormat},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"samplingProperties",{get:function(){return this._samplingProperties},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isStorageInitialized",{get:function(){return this._isStorageInitialized},enumerable:!1,configurable:!0}),e.prototype.is2DTexture=function(){return e.TWO_DIMENSIONAL_TARGETS.indexOf(this._target)>=0},e.prototype.is3DTexture=function(){return e.THREE_DIMENSIONAL_TARGETS.indexOf(this._target)>=0},e.prototype.generateHandle=function(){if(this._handleGenerated)throw new Error("Handle is already generated");if(this._isDeleted)throw new Error("Texture has been deleted");this._handle=this.gl.createTexture(),this._handleGenerated=!0},e.prototype.setSampling=function(){if(this._handleGenerated||this.generateHandle(),this._isDeleted)throw new Error("Texture has been deleted");this.gl.bindTexture(this._target,this._handle),this.gl.texParameteri(this._target,this.gl.TEXTURE_MIN_FILTER,this._samplingProperties.minFilter),this.gl.texParameteri(this._target,this.gl.TEXTURE_MAG_FILTER,this._samplingProperties.magFilter),this.gl.texParameteri(this._target,this.gl.TEXTURE_WRAP_S,this._samplingProperties.wrapS),this.gl.texParameteri(this._target,this.gl.TEXTURE_WRAP_T,this._samplingProperties.wrapT),this.is3DTexture()&&this.gl.texParameteri(this._target,this.gl.TEXTURE_WRAP_R,this._samplingProperties.wrapR)},e.prototype.createStorage=function(){if(this._handleGenerated||this.generateHandle(),this._isDeleted)throw new Error("Texture has been deleted");if(this._isStorageInitialized)throw new Error("Storage has already been initialized");if(this.is2DTexture())this.gl.texStorage2D(this._target,1,this._pixelFormat.internalFormat,this._width,this._height);else{if(!this.is3DTexture())throw new Error("Could not decide on how to create storage for texture");this.gl.texStorage3D(this._target,1,this._pixelFormat.internalFormat,this._width,this._height,this._depth)}this.setSampling(),this._isStorageInitialized=!0},e.prototype.delete=function(){if(!this._handleGenerated)throw new Error("Cannot delete texture before it has been initialized");if(this._isDeleted)throw new Error("Texture has already been deleted");this.gl.deleteTexture(this._handle),this._isDeleted=!0},e.prototype.bind=function(e){if(this._handleGenerated||this.generateHandle(),this._isDeleted)throw new Error("Texture has been deleted");this._isStorageInitialized||this.createStorage(),this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this._target,this._handle)},e.prototype.beforeUpload=function(){if(this._handleGenerated||(this.generateHandle(),console.log("Generating handle")),this._isDeleted)throw new Error("Texture has been deleted")},e.prototype.upload2D=function(e){this.gl.bindTexture(this.gl.TEXTURE_2D,this._handle),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this._pixelFormat.internalFormat,this._width,this._height,0,this._pixelFormat.format,this._pixelFormat.dataType,e),this.setSampling(),this._isStorageInitialized=!0},e.prototype.upload3D=function(e){this.gl.bindTexture(this.gl.TEXTURE_3D,this._handle),this.gl.texImage3D(this.gl.TEXTURE_3D,0,this._pixelFormat.internalFormat,this._width,this._height,this._depth,0,this._pixelFormat.format,this._pixelFormat.dataType,e),this.setSampling(),this._isStorageInitialized=!0},e.prototype.performUpload=function(e){if(this.is2DTexture())this.upload2D(e);else{if(!this.is3DTexture())throw new Error("Could not decide on how to upload texture data");this.upload3D(e)}},e.prototype.uploadFloat=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadInt=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadUnsignedInt=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadShort=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadUnsignedShort=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadByte=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.prototype.uploadUnsignedByte=function(e,t){void 0===t&&(t=null),this.beforeUpload(),t&&(this._pixelFormat=t),this.performUpload(e)},e.DEFAULT_PIXEL_FORMAT={format:WebGL2RenderingContext.RGBA,internalFormat:WebGL2RenderingContext.RGBA8,dataType:WebGL2RenderingContext.UNSIGNED_BYTE},e.DEFAULT_SAMPLING_PROPERTIES={minFilter:WebGL2RenderingContext.NEAREST,magFilter:WebGL2RenderingContext.NEAREST,wrapS:WebGL2RenderingContext.CLAMP_TO_EDGE,wrapT:WebGL2RenderingContext.CLAMP_TO_EDGE,wrapR:WebGL2RenderingContext.CLAMP_TO_EDGE},e.VALID_TARGETS=[WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_3D],e.TWO_DIMENSIONAL_TARGETS=[WebGL2RenderingContext.TEXTURE_2D],e.THREE_DIMENSIONAL_TARGETS=[WebGL2RenderingContext.TEXTURE_3D],e}(),D=function(){function e(t,r){void 0===r&&(r=e.DEFAULT_SAMPLING_PROPERTIES),this.gl=t,this._properties=r,this._handleGenerated=!1,this._samplingPropertiesSet=!1,this._isDeleted=!1,r||(this._properties=e.DEFAULT_SAMPLING_PROPERTIES)}return Object.defineProperty(e.prototype,"handle",{get:function(){return this._handle},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"properties",{get:function(){return this._properties},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handleGenerated",{get:function(){return this._handleGenerated},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDeleted",{get:function(){return this._isDeleted},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"samplingPropertiesSet",{get:function(){return this._samplingPropertiesSet},enumerable:!1,configurable:!0}),e.prototype.generateHandle=function(){if(this._handleGenerated)throw new Error("Handle has already been generated");if(this._isDeleted)throw new Error("Sampler has been deleted");this._handle=this.gl.createSampler(),this._handleGenerated=!0},e.prototype.update=function(e){if(void 0===e&&(e=null),this._isDeleted)throw new Error("Sampler has been deleted");this._handleGenerated||this.generateHandle(),e&&(this._properties=e),this.gl.samplerParameteri(this._handle,this.gl.TEXTURE_MIN_FILTER,this._properties.minFilter),this.gl.samplerParameteri(this._handle,this.gl.TEXTURE_MAG_FILTER,this._properties.minFilter),this.gl.samplerParameteri(this._handle,this.gl.TEXTURE_WRAP_S,this._properties.wrapS),this.gl.samplerParameteri(this._handle,this.gl.TEXTURE_WRAP_T,this._properties.wrapT),this.gl.samplerParameteri(this._handle,this.gl.TEXTURE_WRAP_R,this._properties.wrapR),this._samplingPropertiesSet=!0},e.prototype.bind=function(e){if(this._isDeleted)throw new Error("Sampler has been deleted");this._handleGenerated||this.generateHandle(),this._samplingPropertiesSet||this.update(),this.gl.bindSampler(e,this._handle)},e.prototype.delete=function(){if(this._isDeleted)throw new Error("Sampler has been deleted");if(!this._handleGenerated)throw new Error("Cannot delete sampler before it has been generated");this.gl.deleteSampler(this._handle),this._isDeleted=!0},e.DEFAULT_SAMPLING_PROPERTIES={minFilter:WebGL2RenderingContext.NEAREST,magFilter:WebGL2RenderingContext.NEAREST,wrapS:WebGL2RenderingContext.CLAMP_TO_EDGE,wrapT:WebGL2RenderingContext.CLAMP_TO_EDGE,wrapR:WebGL2RenderingContext.CLAMP_TO_EDGE},e}(),L=function(){function e(e,t){this.gl=e,this.canvas=t}return Object.defineProperty(e.prototype,"width",{get:function(){return this.canvas.width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.canvas.height},enumerable:!1,configurable:!0}),e.prototype.applyViewport=function(){this.gl.viewport(0,0,this.width,this.height)},e.prototype.bind=function(e){void 0===e&&(e=this.gl.FRAMEBUFFER),this.gl.bindFramebuffer(e,null)},e}(),U=function(){function e(e,t){this.canvasSelector=e,this._onInit=null,this._onRender=null,this._canvas=null,this._glContext=null,this.resolution=[0,0],this._lastFrame=0,this.resizeCanvasToFitWindow=!0,this._enableExtensions=[],this._defaultFramebuffer=null,t&&(t.onRender&&(this._onRender=t.onRender),t.onInit&&(this._onInit=t.onInit),"resizeCanvasToFitWindow"in t&&(this.resizeCanvasToFitWindow=t.resizeCanvasToFitWindow),"extensions"in t&&(t.extensions.colorBufferFloat&&this._enableExtensions.push("EXT_color_buffer_float"),t.extensions.textureFloatLinear&&this._enableExtensions.push("OES_texture_float_linear"),t.extensions.elementIndexUint))}return Object.defineProperty(e.prototype,"canvas",{get:function(){return this._canvas},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"glContext",{get:function(){return this._glContext},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"defaultFramebuffer",{get:function(){return this._defaultFramebuffer},enumerable:!1,configurable:!0}),e.prototype.resizeCanvas=function(){this.resolution=[document.body.clientWidth,document.body.clientHeight],this._canvas.width=this.resolution[0],this._canvas.height=this.resolution[1],this._glContext.viewport(0,0,this.resolution[0],this.resolution[1])},e.prototype.start=function(){for(var e in this._canvas=document.querySelector(this.canvasSelector),this._glContext=this._canvas.getContext("webgl2"),this._enableExtensions)this._glContext.getExtension(e);this._defaultFramebuffer=new L(this._glContext,this._canvas),this.resolution=[this._canvas.width,this._canvas.height],this.resizeCanvasToFitWindow&&(this.resizeCanvas(),document.body.onresize=this.resizeCanvas.bind(this)),this._onInit&&this._onInit(this._glContext,this),this._lastFrame=Date.now(),window.requestAnimationFrame(this.onAnimationFrame.bind(this))},e.prototype.onAnimationFrame=function(){var e=Date.now(),t=(e-this._lastFrame)/1e3;this._lastFrame=e,this._onRender&&this._onRender(t,this._glContext,this),window.requestAnimationFrame(this.onAnimationFrame.bind(this))},e.prototype.makeShader=function(e){return new a(this._glContext,e)},e.prototype.makeVertexShader=function(e){var t=this.makeShader(this._glContext.VERTEX_SHADER);if(t.attachSource(e),t.compile(),!t.isCompiled)throw new Error("Vertex shader compilation error: "+t.getInfoLog());return t},e.prototype.makeFragmentShader=function(e){var t=this.makeShader(this._glContext.FRAGMENT_SHADER);if(t.attachSource(e),t.compile(),!t.isCompiled)throw new Error("Fragment shader compilation error: "+t.getInfoLog());return t},e.prototype.makeProgram=function(){return new F(this._glContext)},e.prototype.makeProgramFromShaders=function(e,t,r){void 0===r&&(r=!1);var i=this.makeProgram();if(i.attachShader(e),i.attachShader(t),i.link(),!i.isLinked)throw new Error("Program could not be linked: "+i.getInfoLog());if(r&&(i.validate(),!i.isValidated))throw new Error("Program could not be validated: "+i.getInfoLog());return i},e.prototype.makeMesh=function(e){void 0===e&&(e=null);var t=new o(this._glContext);return e&&t.setup(e.attributes,e.primitive,e.indexed),t},e.prototype.makeTexture=function(e){var t=[e.width,e.height];"depth"in e&&t.push(e.depth);var r=new P(this._glContext,t,e.target,e.pixelFormat,e.samplingProperties);return r.generateHandle(),r},e.prototype.make2DTexture=function(e){var t=new P(this._glContext,[e.width,e.height],this._glContext.TEXTURE_2D,e.pixelFormat,e.samplingProperties);return t.generateHandle(),t},e.prototype.make3DTexture=function(e){var t=new P(this._glContext,[e.width,e.height,e.depth],this._glContext.TEXTURE_3D,e.pixelFormat,e.samplingProperties);return t.generateHandle(),t},e.prototype.makeSampler=function(e){var t=new D(this._glContext,e.properties);return t.generateHandle(),t.update(),t},e.prototype.makeRenderbuffer=function(e){var t=new i(this._glContext,e.width,e.height,e.internalFormat);return t.generateHandle(),t.generateStorage(),t},e.prototype.makeFramebuffer=function(e){var t=new n(this._glContext,e.width,e.height);if(t.generateHandle(),e.generatedRenderbuffers)if(e.generatedRenderbuffers.generateDepthStencilRenderbuffer){var r=this.makeRenderbuffer({width:e.width,height:e.height,internalFormat:this._glContext.DEPTH_STENCIL});t.attachDepthStencilRenderbuffer(r)}else e.generatedRenderbuffers.generateDepthRenderbuffer&&(r=this.makeRenderbuffer({width:e.width,height:e.height,internalFormat:this._glContext.DEPTH_COMPONENT16}),t.attachDepthRenderbuffer(r)),e.generatedRenderbuffers.generateStencilRenderbuffer&&(r=this.makeRenderbuffer({width:e.width,height:e.height,internalFormat:this._glContext.STENCIL_INDEX8}),t.attachStencilRenderbuffer(r));return t},e}();return t})()}));