!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=16)}([function(e,t,r){e.exports=r.p+"dcbe4e47e8a4cb4c76f00dc2ca584ea3.bin"},function(e,t){e.exports=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}},function(e,t,r){e.exports=r.p+"8c72ff38eff4b3d878b6e59563fb2558.bin"},function(e,t,r){e.exports=r.p+"c40f782b6d48c16bbdfa867a67914314.bin"},function(e,t,r){e.exports=r.p+"670398984b2a839f0da3039cd8ae215a.bin"},function(e,t,r){e.exports=r.p+"4cc86edf6517c35dd8aecdbf6a4b1a2e.bin"},function(e,t,r){e.exports=r.p+"aad316ae2f3185e637764ab20f4536ee.bin"},function(e,t,r){e.exports=r.p+"c5d1e42d1b2c2960ef12ca75b5e71fc1.bin"},function(e,t,r){e.exports=r.p+"80e3348d39fbc859dfe0bb2cda08c5b1.bin"},function(e,t,r){e.exports=r.p+"8ab0cc172cd882ef6b69422eaa5a502d.bin"},function(e,t,r){e.exports=r.p+"88a1fb4d8c42c36a027c7ab503de7511.bin"},function(e,t,r){e.exports=r.p+"a7a417e76651f9fa75e63e45e22095e6.bin"},function(e,t,r){e.exports=r.p+"b8f9c879c9c795656294aa401ac3854c.bin"},function(e,t,r){e.exports=r.p+"5293ee29e3db7bbd05f03823aa9bd53a.bin"},function(e,t,r){e.exports=r.p+"6f2d59ca82e22144ee26889cc862912f.bin"},function(e,t,r){e.exports=r.p+"f988ae2257d2f750090c9bda21c58f10.bin"},function(e,t,r){"use strict";r.r(t);var n=r(2),a=r.n(n),i=r(3),o=r.n(i),f=r(4),u=r.n(f),s=r(5),c=r.n(s),l=r(0),d=r.n(l),m=r(6),p=r.n(m),h=r(7),b=r.n(h),v=r(8),g=r.n(v),y=r(9),x=r.n(y),w=r(10),k=r.n(w),_=r(11),A=r.n(_),S=r(12),E=r.n(S),T=r(13),j=r.n(T),D=r(14),O=r.n(D),C=r(15),F=r.n(C);const z={hexsphere_0:a.a,hexsphere_1:o.a,hexsphere_2:u.a,hexsphere_3:c.a,hexsphere_4:d.a,hexsphere_5:p.a,hexsphere_6:b.a,icosahedron_0:g.a,icosahedron_1:x.a,icosahedron_2:k.a,icosahedron_3:A.a,icosahedron_4:E.a,icosahedron_5:j.a,icosahedron_6:O.a,icosahedron_7:F.a},L=r(17)({extensions:["OES_element_index_uint"]}),M=r(18)(L,{center:[0,0,0],distance:3});let P=null;const B=e=>{fetch(e).then(e=>e.arrayBuffer()).then(e=>{let t=new DataView(e),r=t.getUint32(0,!0),n=t.getUint32(4,!0);const a={positions:new Float32Array(e,8,3*r),normals:new Float32Array(e,12*r+8,3*r),colors:new Float32Array(e,24*r+8,3*r),cells:new Uint32Array(e,36*r+8,3*n)};P=(e=>L({vert:"\n precision mediump float;\n uniform mat4 projection, view;\n attribute vec3 position, normal, color;\n varying vec3 fragNormal, fragPosition, fragColor;\n void main() {\n fragNormal = normal;\n fragPosition = position;\n fragColor = color;\n gl_Position = projection * view * vec4(position, 1.0);\n }",frag:"\n precision mediump float;\n struct Light {\n vec3 color;\n vec3 position;\n };\n uniform Light lights[1];\n varying vec3 fragNormal, fragPosition, fragColor;\n void main() {\n vec3 normal = normalize(fragNormal);\n vec3 light = vec3(0.1, 0.1, 0.1);\n for (int i = 0; i < 1; i++) {\n vec3 lightDir = normalize(lights[i].position - fragPosition);\n float diffuse = max(0.0, dot(lightDir, normal));\n light += diffuse * lights[i].color;\n }\n gl_FragColor = vec4(fragColor * light, 1.0);\n }",attributes:{position:e.positions,normal:e.normals,color:e.colors},elements:e.cells,uniforms:{"lights[0].color":[1,1,1],"lights[0].position":({tick:e})=>{const t=.008*e;return[1e3*Math.cos(t),1e3*Math.sin(t),1e3*Math.sin(t)]}}}))(a),L.frame(()=>{L.clear({depth:1,color:[0,0,0,1]}),M(()=>{P()})}),R.style.display="none"})},I=document.querySelector("select#shape-select"),R=document.querySelector("#shape-loading");I.value="hexsphere_4",B(d.a),I.addEventListener("change",e=>{R.style.display="inline",B(z[e.target.value])})},function(e,t,r){e.exports=function(){"use strict";var e=function(e){return e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array||e instanceof Uint8ClampedArray},t=function(e,t){for(var r=Object.keys(t),n=0;n=0&&(0|e)===e||n("invalid parameter type, ("+e+")"+i(t)+". must be a nonnegative integer")},oneOf:o,shaderError:function(e,t,n,i,o){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var f=e.getShaderInfoLog(t),s=i===e.FRAGMENT_SHADER?"fragment":"vertex";v(n,"string",s+" shader source must be a string",o);var c=p(n,o),d=function(e){var t=[];return e.split("\n").forEach(function(e){if(!(e.length<5)){var r=/^ERROR\:\s+(\d+)\:(\d+)\:\s*(.*)$/.exec(e);r?t.push(new l(0|r[1],0|r[2],r[3].trim())):e.length>0&&t.push(new l("unknown",0,e))}}),t}(f);!function(e,t){t.forEach(function(t){var r=e[t.file];if(r){var n=r.index[t.line];if(n)return n.errors.push(t),void(r.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)})}(c,d),Object.keys(c).forEach(function(e){var t=c[e];if(t.hasErrors){var n=[""],a=[""];i("file number "+e+": "+t.name+"\n","color:red;text-decoration:underline;font-weight:bold"),t.lines.forEach(function(e){if(e.errors.length>0){i(u(e.number,4)+"| ","background-color:yellow; font-weight:bold"),i(e.line+r,"color:red; background-color:yellow; font-weight:bold");var t=0;e.errors.forEach(function(n){var a=n.message,o=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(a);if(o){var f=o[1];switch(a=o[2],f){case"assign":f="="}t=Math.max(e.line.indexOf(f,t),0)}else t=0;i(u("| ",6)),i(u("^^^",t+3)+r,"font-weight:bold"),i(u("| ",6)),i(a+r,"font-weight:bold")}),i(u("| ",6)+r)}else i(u(e.number,4)+"| "),i(e.line+r,"color:red")}),"undefined"==typeof document||window.chrome?console.log(n.join("")):(a[0]=n.join("%c"),console.log.apply(console,a))}function i(e,t){n.push(e),a.push(t||"")}}),a.raise("Error compiling "+s+" shader, "+c[0].name)}},linkError:function(e,t,n,i,o){if(!e.getProgramParameter(t,e.LINK_STATUS)){var f=e.getProgramInfoLog(t),u=p(n,o),s=p(i,o),c='Error linking program with vertex shader, "'+s[0].name+'", and fragment shader "'+u[0].name+'"';"undefined"!=typeof document?console.log("%c"+c+r+"%c"+f,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(c+r+f),a.raise(c)}},callSite:m,saveCommandRef:h,saveDrawInfo:function(e,t,r,n){function a(e){return e?n.id(e):0}function i(e,t){Object.keys(t).forEach(function(t){e[n.id(t)]=!0})}h(e),e._fragId=a(e.static.frag),e._vertId=a(e.static.vert);var o=e._uniformSet={};i(o,t.static),i(o,t.dynamic);var f=e._attributeSet={};i(f,r.static),i(f,r.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic},framebufferFormat:function(e,t,r){e.texture?o(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):o(e.renderbuffer._renderbuffer.format,r,"unsupported renderbuffer format for attachment")},guessCommand:d,texture2D:function(e,t,r){var n,i=t.width,o=t.height,f=t.channels;a(i>0&&i<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),(e.wrapS!==g||e.wrapT!==g)&&a(C(i)&&C(o),"incompatible wrap mode for texture, both width and height must be power of 2"),1===t.mipmask?1!==i&&1!==o&&a(e.minFilter!==x&&e.minFilter!==k&&e.minFilter!==w&&e.minFilter!==_,"min filter requires mipmap"):(a(C(i)&&C(o),"texture must be a square power of 2 to support mipmapping"),a(t.mipmask===(i<<1)-1,"missing or incomplete mipmap data")),t.type===A&&(r.extensions.indexOf("oes_texture_float_linear")<0&&a(e.minFilter===y&&e.magFilter===y,"filter not supported, must enable oes_texture_float_linear"),a(!e.genMipmaps,"mipmap generation not supported with float textures"));var u=t.images;for(n=0;n<16;++n)if(u[n]){var s=i>>n,c=o>>n;a(t.mipmask&1<0&&i<=n.maxTextureSize&&o>0&&o<=n.maxTextureSize,"invalid texture shape"),a(i===o,"cube map must be square"),a(t.wrapS===g&&t.wrapT===g,"wrap mode not supported by cube map");for(var u=0;u>l,p=o>>l;a(s.mipmask&1<1&&r===n&&('"'===r||"'"===r))return['"'+P(t.substr(1,t.length-2))+'"'];var a=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(t);if(a)return e(t.substr(0,a.index)).concat(e(a[1])).concat(e(t.substr(a.index+a[0].length)));var i=t.split(".");if(1===i.length)return['"'+P(t)+'"'];for(var o=[],f=0;f0,"invalid pixel ratio"))):F.raise("invalid arguments to regl"),r&&("canvas"===r.nodeName.toLowerCase()?a=r:n=r),!i){if(!a){F("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var h=function(e,r,n){var a=document.createElement("canvas");function i(){var r=window.innerWidth,i=window.innerHeight;if(e!==document.body){var o=e.getBoundingClientRect();r=o.right-o.left,i=o.bottom-o.top}a.width=n*r,a.height=n*i,t(a.style,{width:r+"px",height:i+"px"})}return t(a.style,{border:0,margin:0,padding:0,top:0,left:0}),e.appendChild(a),e===document.body&&(a.style.position="absolute",t(e.style,{margin:0,padding:0})),window.addEventListener("resize",i,!1),i(),{canvas:a,onDestroy:function(){window.removeEventListener("resize",i),e.removeChild(a)}}}(n||document.body,0,l);if(!h)return null;a=h.canvas,p=h.onDestroy}i=function(e,t){function r(r){try{return e.getContext(r,t)}catch(e){return null}}return r("webgl")||r("experimental-webgl")||r("webgl-experimental")}(a,u)}return i?{gl:i,canvas:a,container:n,extensions:s,optionalExtensions:c,pixelRatio:l,profile:d,onDone:m,onDestroy:p}:(p(),m("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function q(e,t){for(var r=Array(e),n=0;n65535)<<4,t|=r=((e>>>=t)>255)<<3,t|=r=((e>>>=r)>15)<<2,(t|=r=((e>>>=r)>3)<<1)|(e>>>=r)>>1}function Z(){var e=q(8,function(){return[]});function t(t){var r=function(e){for(var t=16;t<=1<<28;t*=16)if(e<=t)return t;return 0}(t),n=e[J(r)>>2];return n.length>0?n.pop():new ArrayBuffer(r)}function r(t){e[J(t.byteLength)>>2].push(t)}return{alloc:t,free:r,allocType:function(e,r){var n=null;switch(e){case G:n=new Int8Array(t(r),0,r);break;case Q:n=new Uint8Array(t(r),0,r);break;case V:n=new Int16Array(t(2*r),0,r);break;case Y:n=new Uint16Array(t(2*r),0,r);break;case K:n=new Int32Array(t(4*r),0,r);break;case X:n=new Uint32Array(t(4*r),0,r);break;case $:n=new Float32Array(t(4*r),0,r);break;default:return null}return n.length!==r?n.subarray(0,r):n},freeType:function(e){r(e.buffer)}}}var ee=Z();ee.zero=Z();var te=function(e,t){var r=1;t.ext_texture_filter_anisotropic&&(r=e.getParameter(34047));var n=1,a=1;t.webgl_draw_buffers&&(n=e.getParameter(34852),a=e.getParameter(36063));var i=!!t.oes_texture_float;if(i){var o=e.createTexture();e.bindTexture(3553,o),e.texImage2D(3553,0,6408,1,1,0,6408,5126,null);var f=e.createFramebuffer();if(e.bindFramebuffer(36160,f),e.framebufferTexture2D(36160,36064,3553,o,0),e.bindTexture(3553,null),36053!==e.checkFramebufferStatus(36160))i=!1;else{e.viewport(0,0,1,1),e.clearColor(1,0,0,1),e.clear(16384);var u=ee.allocType(5126,4);e.readPixels(0,0,1,1,6408,5126,u),e.getError()?i=!1:(e.deleteFramebuffer(f),e.deleteTexture(o),i=1===u[0]),ee.freeType(u)}}var s="undefined"!=typeof navigator&&(/MSIE/.test(navigator.userAgent)||/Trident\//.test(navigator.appVersion)||/Edge/.test(navigator.userAgent)),c=!0;if(!s){var l=e.createTexture(),d=ee.allocType(5121,36);e.activeTexture(33984),e.bindTexture(34067,l),e.texImage2D(34069,0,6408,3,3,0,6408,5121,d),ee.freeType(d),e.bindTexture(34067,null),e.deleteTexture(l),c=!e.getError()}return{colorBits:[e.getParameter(3410),e.getParameter(3411),e.getParameter(3412),e.getParameter(3413)],depthBits:e.getParameter(3414),stencilBits:e.getParameter(3415),subpixelBits:e.getParameter(3408),extensions:Object.keys(t).filter(function(e){return!!t[e]}),maxAnisotropic:r,maxDrawbuffers:n,maxColorAttachments:a,pointSizeDims:e.getParameter(33901),lineWidthDims:e.getParameter(33902),maxViewportDims:e.getParameter(3386),maxCombinedTextureUnits:e.getParameter(35661),maxCubeMapSize:e.getParameter(34076),maxRenderbufferSize:e.getParameter(34024),maxTextureUnits:e.getParameter(34930),maxTextureSize:e.getParameter(3379),maxAttributes:e.getParameter(34921),maxVertexUniforms:e.getParameter(36347),maxVertexTextureUnits:e.getParameter(35660),maxVaryingVectors:e.getParameter(36348),maxFragmentUniforms:e.getParameter(36349),glsl:e.getParameter(35724),renderer:e.getParameter(7937),vendor:e.getParameter(7936),version:e.getParameter(7938),readFloat:i,npotTextureCube:c}};function re(t){return!!t&&"object"==typeof t&&Array.isArray(t.shape)&&Array.isArray(t.stride)&&"number"==typeof t.offset&&t.shape.length===t.stride.length&&(Array.isArray(t.data)||e(t.data))}var ne=function(e){return Object.keys(e).map(function(t){return e[t]})},ae={shape:function(e){for(var t=[],r=e;r.length;r=r[0])t.push(r.length);return t},flatten:function(e,t,r,n){var a=1;if(t.length)for(var i=0;i>>31<<15,i=(n<<1>>>24)-127,o=n>>13&1023;if(i<-24)t[r]=a;else if(i<-14){var f=-14-i;t[r]=a+(o+1024>>f)}else t[r]=i>15?a+31744:a+(i+15<<10)+o}return t}function Pe(t){return Array.isArray(t)||e(t)}var Be=function(e){return!(e&e-1||!e)},Ie=34467,Re=3553,We=34067,He=34069,Ue=6408,Ne=6406,qe=6407,Ge=6409,Qe=6410,Ve=32854,Ye=32855,Ke=36194,Xe=32819,$e=32820,Je=33635,Ze=34042,et=6402,tt=34041,rt=35904,nt=35906,at=36193,it=33776,ot=33777,ft=33778,ut=33779,st=35986,ct=35987,lt=34798,dt=35840,mt=35841,pt=35842,ht=35843,bt=36196,vt=5121,gt=5123,yt=5125,xt=5126,wt=10242,kt=10243,_t=10497,At=33071,St=33648,Et=10240,Tt=10241,jt=9728,Dt=9729,Ot=9984,Ct=9985,Ft=9986,zt=9987,Lt=33170,Mt=4352,Pt=4353,Bt=4354,It=34046,Rt=3317,Wt=37440,Ht=37441,Ut=37443,Nt=37444,qt=33984,Gt=[Ot,Ft,Ct,zt],Qt=[0,Ge,Qe,qe,Ue],Vt={};function Yt(e){return"[object "+e+"]"}Vt[Ge]=Vt[Ne]=Vt[et]=1,Vt[tt]=Vt[Qe]=2,Vt[qe]=Vt[rt]=3,Vt[Ue]=Vt[nt]=4;var Kt=Yt("HTMLCanvasElement"),Xt=Yt("CanvasRenderingContext2D"),$t=Yt("ImageBitmap"),Jt=Yt("HTMLImageElement"),Zt=Yt("HTMLVideoElement"),er=Object.keys(oe).concat([Kt,Xt,$t,Jt,Zt]),tr=[];tr[vt]=1,tr[xt]=4,tr[at]=2,tr[gt]=2,tr[yt]=4;var rr=[];function nr(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function ar(e){if(!Array.isArray(e))return!1;var t=e.length;return!(0===t||!Pe(e[0]))}function ir(e){return Object.prototype.toString.call(e)}function or(e){return ir(e)===Kt}function fr(e){if(!e)return!1;var t=ir(e);return er.indexOf(t)>=0||nr(e)||ar(e)||re(e)}function ur(e){return 0|oe[Object.prototype.toString.call(e)]}function sr(e,t){return ee.allocType(e.type===at?xt:e.type,t)}function cr(e,t){e.type===at?(e.data=Me(t),ee.freeType(t)):e.data=t}function lr(e,t,r,n,a,i){var o;if(o=void 0!==rr[e]?rr[e]:Vt[e]*tr[t],i&&(o*=6),a){for(var f=0,u=r;u>=1;)f+=o*u*u,u/=2;return f}return o*r*n}function dr(r,n,a,i,o,f,u){var s={"don't care":Mt,"dont care":Mt,nice:Bt,fast:Pt},c={repeat:_t,clamp:At,mirror:St},l={nearest:jt,linear:Dt},d=t({mipmap:zt,"nearest mipmap nearest":Ot,"linear mipmap nearest":Ct,"nearest mipmap linear":Ft,"linear mipmap linear":zt},l),m={none:0,browser:Nt},p={uint8:vt,rgba4:Xe,rgb565:Je,"rgb5 a1":$e},h={alpha:Ne,luminance:Ge,"luminance alpha":Qe,rgb:qe,rgba:Ue,rgba4:Ve,"rgb5 a1":Ye,rgb565:Ke},b={};n.ext_srgb&&(h.srgb=rt,h.srgba=nt),n.oes_texture_float&&(p.float32=p.float=xt),n.oes_texture_half_float&&(p.float16=p["half float"]=at),n.webgl_depth_texture&&(t(h,{depth:et,"depth stencil":tt}),t(p,{uint16:gt,uint32:yt,"depth stencil":Ze})),n.webgl_compressed_texture_s3tc&&t(b,{"rgb s3tc dxt1":it,"rgba s3tc dxt1":ot,"rgba s3tc dxt3":ft,"rgba s3tc dxt5":ut}),n.webgl_compressed_texture_atc&&t(b,{"rgb atc":st,"rgba atc explicit alpha":ct,"rgba atc interpolated alpha":lt}),n.webgl_compressed_texture_pvrtc&&t(b,{"rgb pvrtc 4bppv1":dt,"rgb pvrtc 2bppv1":mt,"rgba pvrtc 4bppv1":pt,"rgba pvrtc 2bppv1":ht}),n.webgl_compressed_texture_etc1&&(b["rgb etc1"]=bt);var v=Array.prototype.slice.call(r.getParameter(Ie));Object.keys(b).forEach(function(e){var t=b[e];v.indexOf(t)>=0&&(h[e]=t)});var g=Object.keys(h);a.textureFormats=g;var y=[];Object.keys(h).forEach(function(e){var t=h[e];y[t]=e});var x=[];Object.keys(p).forEach(function(e){var t=p[e];x[t]=e});var w=[];Object.keys(l).forEach(function(e){var t=l[e];w[t]=e});var k=[];Object.keys(d).forEach(function(e){var t=d[e];k[t]=e});var _=[];Object.keys(c).forEach(function(e){var t=c[e];_[t]=e});var A=g.reduce(function(e,t){var r=h[t];return r===Ge||r===Ne||r===Ge||r===Qe||r===et||r===tt?e[r]=r:r===Ye||t.indexOf("rgba")>=0?e[r]=Ue:e[r]=qe,e},{});function S(){this.internalformat=Ue,this.format=Ue,this.type=vt,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=Nt,this.width=0,this.height=0,this.channels=0}function E(e,t){e.internalformat=t.internalformat,e.format=t.format,e.type=t.type,e.compressed=t.compressed,e.premultiplyAlpha=t.premultiplyAlpha,e.flipY=t.flipY,e.unpackAlignment=t.unpackAlignment,e.colorSpace=t.colorSpace,e.width=t.width,e.height=t.height,e.channels=t.channels}function T(e,t){if("object"==typeof t&&t){if("premultiplyAlpha"in t&&(F.type(t.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=t.premultiplyAlpha),"flipY"in t&&(F.type(t.flipY,"boolean","invalid texture flip"),e.flipY=t.flipY),"alignment"in t&&(F.oneOf(t.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=t.alignment),"colorSpace"in t&&(F.parameter(t.colorSpace,m,"invalid colorSpace"),e.colorSpace=m[t.colorSpace]),"type"in t){var r=t.type;F(n.oes_texture_float||!("float"===r||"float32"===r),"you must enable the OES_texture_float extension in order to use floating point textures."),F(n.oes_texture_half_float||!("half float"===r||"float16"===r),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),F(n.webgl_depth_texture||!("uint16"===r||"uint32"===r||"depth stencil"===r),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),F.parameter(r,p,"invalid texture type"),e.type=p[r]}var i=e.width,o=e.height,f=e.channels,u=!1;"shape"in t?(F(Array.isArray(t.shape)&&t.shape.length>=2,"shape must be an array"),i=t.shape[0],o=t.shape[1],3===t.shape.length&&(f=t.shape[2],F(f>0&&f<=4,"invalid number of channels"),u=!0),F(i>=0&&i<=a.maxTextureSize,"invalid width"),F(o>=0&&o<=a.maxTextureSize,"invalid height")):("radius"in t&&(i=o=t.radius,F(i>=0&&i<=a.maxTextureSize,"invalid radius")),"width"in t&&(i=t.width,F(i>=0&&i<=a.maxTextureSize,"invalid width")),"height"in t&&(o=t.height,F(o>=0&&o<=a.maxTextureSize,"invalid height")),"channels"in t&&(f=t.channels,F(f>0&&f<=4,"invalid number of channels"),u=!0)),e.width=0|i,e.height=0|o,e.channels=0|f;var s=!1;if("format"in t){var c=t.format;F(n.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),F.parameter(c,h,"invalid texture format");var l=e.internalformat=h[c];e.format=A[l],c in p&&("type"in t||(e.type=p[c])),c in b&&(e.compressed=!0),s=!0}!u&&s?e.channels=Vt[e.format]:u&&!s?e.channels!==Qt[e.format]&&(e.format=e.internalformat=Qt[e.channels]):s&&u&&F(e.channels===Vt[e.format],"number of channels inconsistent with specified format")}}function j(e){r.pixelStorei(Wt,e.flipY),r.pixelStorei(Ht,e.premultiplyAlpha),r.pixelStorei(Ut,e.colorSpace),r.pixelStorei(Rt,e.unpackAlignment)}function D(){S.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function O(t,r){var n=null;if(fr(r)?n=r:r&&(F.type(r,"object","invalid pixel data type"),T(t,r),"x"in r&&(t.xOffset=0|r.x),"y"in r&&(t.yOffset=0|r.y),fr(r.data)&&(n=r.data)),F(!t.compressed||n instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),r.copy){F(!n,"can not specify copy and data field for the same texture");var i=o.viewportWidth,f=o.viewportHeight;t.width=t.width||i-t.xOffset,t.height=t.height||f-t.yOffset,t.needsCopy=!0,F(t.xOffset>=0&&t.xOffset=0&&t.yOffset0&&t.width<=i&&t.height>0&&t.height<=f,"copy texture read out of bounds")}else if(n){if(e(n))t.channels=t.channels||4,t.data=n,"type"in r||t.type!==vt||(t.type=ur(n));else if(nr(n))t.channels=t.channels||4,function(e,t){var r=t.length;switch(e.type){case vt:case gt:case yt:case xt:var n=ee.allocType(e.type,r);n.set(t),e.data=n;break;case at:e.data=Me(t);break;default:F.raise("unsupported texture type, must specify a typed array")}}(t,n),t.alignment=1,t.needsFree=!0;else if(re(n)){var u=n.data;Array.isArray(u)||t.type!==vt||(t.type=ur(u));var s,c,l,d,m,p,h=n.shape,b=n.stride;3===h.length?(l=h[2],p=b[2]):(F(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,p=1),s=h[0],c=h[1],d=b[0],m=b[1],t.alignment=1,t.width=s,t.height=c,t.channels=l,t.format=t.internalformat=Qt[l],t.needsFree=!0,function(e,t,r,n,a,i){for(var o=e.width,f=e.height,u=e.channels,s=sr(e,o*f*u),c=0,l=0;l=0,"oes_texture_float extension not enabled"):t.type===at&&F(a.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function C(e,t,n){var a=e.element,o=e.data,f=e.internalformat,u=e.format,s=e.type,c=e.width,l=e.height,d=e.channels;if(j(e),a)r.texImage2D(t,n,u,u,s,a);else if(e.compressed)r.compressedTexImage2D(t,n,f,c,l,0,o);else if(e.needsCopy)i(),r.copyTexImage2D(t,n,u,e.xOffset,e.yOffset,c,l,0);else{var m=!o;m&&(o=ee.zero.allocType(s,c*l*d)),r.texImage2D(t,n,u,c,l,0,u,s,o),m&&o&&ee.zero.freeType(o)}}function z(e,t,n,a,o){var f=e.element,u=e.data,s=e.internalformat,c=e.format,l=e.type,d=e.width,m=e.height;j(e),f?r.texSubImage2D(t,o,n,a,c,l,f):e.compressed?r.compressedTexSubImage2D(t,o,n,a,s,d,m,u):e.needsCopy?(i(),r.copyTexSubImage2D(t,o,n,a,e.xOffset,e.yOffset,d,m)):r.texSubImage2D(t,o,n,a,d,m,c,l,u)}var L=[];function M(){return L.pop()||new D}function P(e){e.needsFree&&ee.freeType(e.data),D.call(e),L.push(e)}function B(){S.call(this),this.genMipmaps=!1,this.mipmapHint=Mt,this.mipmask=0,this.images=Array(16)}function I(e,t,r){var n=e.images[0]=M();e.mipmask=1,n.width=e.width=t,n.height=e.height=r,n.channels=e.channels=4}function R(e,t){var r=null;if(fr(t))E(r=e.images[0]=M(),e),O(r,t),e.mipmask=1;else if(T(e,t),Array.isArray(t.mipmap))for(var n=t.mipmap,a=0;a>=a,r.height>>=a,O(r,n[a]),e.mipmask|=1<=0&&!("faces"in t)&&(e.genMipmaps=!0)}if("mag"in t){var n=t.mag;F.parameter(n,l),e.magFilter=l[n]}var i=e.wrapS,o=e.wrapT;if("wrap"in t){var f=t.wrap;"string"==typeof f?(F.parameter(f,c),i=o=c[f]):Array.isArray(f)&&(F.parameter(f[0],c),F.parameter(f[1],c),i=c[f[0]],o=c[f[1]])}else{if("wrapS"in t){var u=t.wrapS;F.parameter(u,c),i=c[u]}if("wrapT"in t){var m=t.wrapT;F.parameter(m,c),o=c[m]}}if(e.wrapS=i,e.wrapT=o,"anisotropic"in t){var p=t.anisotropic;F("number"==typeof p&&p>=1&&p<=a.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var h=!1;switch(typeof t.mipmap){case"string":F.parameter(t.mipmap,s,"invalid mipmap hint"),e.mipmapHint=s[t.mipmap],e.genMipmaps=!0,h=!0;break;case"boolean":h=e.genMipmaps=t.mipmap;break;case"object":F(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,h=!0;break;default:F.raise("invalid mipmap type")}!h||"min"in t||(e.minFilter=Ot)}}function Q(e,t){r.texParameteri(t,Tt,e.minFilter),r.texParameteri(t,Et,e.magFilter),r.texParameteri(t,wt,e.wrapS),r.texParameteri(t,kt,e.wrapT),n.ext_texture_filter_anisotropic&&r.texParameteri(t,It,e.anisotropic),e.genMipmaps&&(r.hint(Lt,e.mipmapHint),r.generateMipmap(t))}var V=0,Y={},K=a.maxTextureUnits,X=Array(K).map(function(){return null});function $(e){S.call(this),this.mipmask=0,this.internalformat=Ue,this.id=V++,this.refCount=1,this.target=e,this.texture=r.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new q,u.profile&&(this.stats={size:0})}function J(e){r.activeTexture(qt),r.bindTexture(e.target,e.texture)}function Z(){var e=X[0];e?r.bindTexture(e.target,e.texture):r.bindTexture(Re,null)}function te(e){var t=e.texture;F(t,"must not double destroy texture");var n=e.unit,a=e.target;n>=0&&(r.activeTexture(qt+n),r.bindTexture(a,null),X[n]=null),r.deleteTexture(t),e.texture=null,e.params=null,e.pixels=null,e.refCount=0,delete Y[e.id],f.textureCount--}return t($.prototype,{bind:function(){this.bindCount+=1;var e=this.unit;if(e<0){for(var t=0;t0)continue;n.unit=-1}X[t]=this,e=t;break}e>=K&&F.raise("insufficient number of texture units"),u.profile&&f.maxTextureUnits>u)-o,s.height=s.height||(n.height>>u)-f,F(n.type===s.type&&n.format===s.format&&n.internalformat===s.internalformat,"incompatible format for texture.subimage"),F(o>=0&&f>=0&&o+s.width<=n.width&&f+s.height<=n.height,"texture.subimage write out of bounds"),F(n.mipmask&1<>l;++l){var d=o>>l,m=f>>l;if(!d||!m)break;a=ee.zero.allocType(c,d*m*s),r.texImage2D(Re,l,n.format,d,m,0,n.format,n.type,a),a&&ee.zero.freeType(a)}return Z(),u.profile&&(n.stats.size=lr(n.internalformat,n.type,o,f,!1,!1)),i},i._reglType="texture2d",i._texture=n,u.profile&&(i.stats=n.stats),i.destroy=function(){n.decRef()},i},createCube:function(e,t,n,i,o,s){var c=new $(We);Y[c.id]=c,f.cubeCount++;var l=new Array(6);function d(e,t,r,n,i,o){var f,s=c.texInfo;for(q.call(s),f=0;f<6;++f)l[f]=U();if("number"!=typeof e&&e)if("object"==typeof e)if(t)R(l[0],e),R(l[1],t),R(l[2],r),R(l[3],n),R(l[4],i),R(l[5],o);else if(G(s,e),T(c,e),"faces"in e){var m=e.faces;for(F(Array.isArray(m)&&6===m.length,"cube faces must be a length 6 array"),f=0;f<6;++f)F("object"==typeof m[f]&&!!m[f],"invalid input for cube map face"),E(l[f],c),R(l[f],m[f])}else for(f=0;f<6;++f)R(l[f],e);else F.raise("invalid arguments to cube map");else{var p=0|e||1;for(f=0;f<6;++f)I(l[f],p,p)}for(E(c,l[0]),a.npotTextureCube||F(Be(c.width)&&Be(c.height),"your browser does not support non power or two texture dimensions"),s.genMipmaps?c.mipmask=(l[0].width<<1)-1:c.mipmask=l[0].mipmask,F.textureCube(c,s,l,a),c.internalformat=l[0].internalformat,d.width=l[0].width,d.height=l[0].height,J(c),f=0;f<6;++f)W(l[f],He+f);for(Q(s,We),Z(),u.profile&&(c.stats.size=lr(c.internalformat,c.type,d.width,d.height,s.genMipmaps,!0)),d.format=y[c.internalformat],d.type=x[c.type],d.mag=w[s.magFilter],d.min=k[s.minFilter],d.wrapS=_[s.wrapS],d.wrapT=_[s.wrapT],f=0;f<6;++f)N(l[f]);return d}return d(e,t,n,i,o,s),d.subimage=function(e,t,r,n,a){F(!!t,"must specify image data"),F("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var i=0|r,o=0|n,f=0|a,u=M();return E(u,c),u.width=0,u.height=0,O(u,t),u.width=u.width||(c.width>>f)-i,u.height=u.height||(c.height>>f)-o,F(c.type===u.type&&c.format===u.format&&c.internalformat===u.internalformat,"incompatible format for texture.subimage"),F(i>=0&&o>=0&&i+u.width<=c.width&&o+u.height<=c.height,"texture.subimage write out of bounds"),F(c.mipmask&1<>a;++a)r.texImage2D(He+n,a,c.format,t>>a,t>>a,0,c.format,c.type,null);return Z(),u.profile&&(c.stats.size=lr(c.internalformat,c.type,d.width,d.height,!1,!0)),d}},d._reglType="textureCube",d._texture=c,u.profile&&(d.stats=c.stats),d.destroy=function(){c.decRef()},d},clear:function(){for(var e=0;e>t,e.height>>t,0,e.internalformat,e.type,null);else for(var n=0;n<6;++n)r.texImage2D(He+n,t,e.internalformat,e.width>>t,e.height>>t,0,e.internalformat,e.type,null);Q(e.texInfo,e.target)})}}}rr[Ve]=2,rr[Ye]=2,rr[Ke]=2,rr[tt]=4,rr[it]=.5,rr[ot]=.5,rr[ft]=1,rr[ut]=1,rr[st]=.5,rr[ct]=1,rr[lt]=1,rr[dt]=.5,rr[mt]=.25,rr[pt]=.5,rr[ht]=.25,rr[bt]=.5;var mr=36161,pr=32854,hr=[];function br(e,t,r){return hr[e]*t*r}hr[pr]=2,hr[32855]=2,hr[36194]=2,hr[33189]=2,hr[36168]=1,hr[34041]=4,hr[35907]=4,hr[34836]=16,hr[34842]=8,hr[34843]=6;var vr=function(e,t,r,n,a){var i={rgba4:pr,rgb565:36194,"rgb5 a1":32855,depth:33189,stencil:36168,"depth stencil":34041};t.ext_srgb&&(i.srgba=35907),t.ext_color_buffer_half_float&&(i.rgba16f=34842,i.rgb16f=34843),t.webgl_color_buffer_float&&(i.rgba32f=34836);var o=[];Object.keys(i).forEach(function(e){var t=i[e];o[t]=e});var f=0,u={};function s(e){this.id=f++,this.refCount=1,this.renderbuffer=e,this.format=pr,this.width=0,this.height=0,a.profile&&(this.stats={size:0})}function c(t){var r=t.renderbuffer;F(r,"must not double destroy renderbuffer"),e.bindRenderbuffer(mr,null),e.deleteRenderbuffer(r),t.renderbuffer=null,t.refCount=0,delete u[t.id],n.renderbufferCount--}return s.prototype.decRef=function(){--this.refCount<=0&&c(this)},a.profile&&(n.getTotalRenderbufferSize=function(){var e=0;return Object.keys(u).forEach(function(t){e+=u[t].stats.size}),e}),{create:function(t,f){var c=new s(e.createRenderbuffer());function l(t,n){var f=0,u=0,s=pr;if("object"==typeof t&&t){var d=t;if("shape"in d){var m=d.shape;F(Array.isArray(m)&&m.length>=2,"invalid renderbuffer shape"),f=0|m[0],u=0|m[1]}else"radius"in d&&(f=u=0|d.radius),"width"in d&&(f=0|d.width),"height"in d&&(u=0|d.height);"format"in d&&(F.parameter(d.format,i,"invalid renderbuffer format"),s=i[d.format])}else"number"==typeof t?(f=0|t,u="number"==typeof n?0|n:f):t?F.raise("invalid arguments to renderbuffer constructor"):f=u=1;if(F(f>0&&u>0&&f<=r.maxRenderbufferSize&&u<=r.maxRenderbufferSize,"invalid renderbuffer size"),f!==c.width||u!==c.height||s!==c.format)return l.width=c.width=f,l.height=c.height=u,c.format=s,e.bindRenderbuffer(mr,c.renderbuffer),e.renderbufferStorage(mr,s,f,u),F(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=br(c.format,c.width,c.height)),l.format=o[c.format],l}return u[c.id]=c,n.renderbufferCount++,l(t,f),l.resize=function(t,n){var i=0|t,o=0|n||i;return i===c.width&&o===c.height?l:(F(i>0&&o>0&&i<=r.maxRenderbufferSize&&o<=r.maxRenderbufferSize,"invalid renderbuffer size"),l.width=c.width=i,l.height=c.height=o,e.bindRenderbuffer(mr,c.renderbuffer),e.renderbufferStorage(mr,c.format,i,o),F(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=br(c.format,c.width,c.height)),l)},l._reglType="renderbuffer",l._renderbuffer=c,a.profile&&(l.stats=c.stats),l.destroy=function(){c.decRef()},l},clear:function(){ne(u).forEach(c)},restore:function(){ne(u).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(mr,t.renderbuffer),e.renderbufferStorage(mr,t.format,t.width,t.height)}),e.bindRenderbuffer(mr,null)}}},gr=36160,yr=36161,xr=3553,wr=34069,kr=36064,_r=36096,Ar=36128,Sr=33306,Er=36053,Tr=6402,jr=[6407,6408],Dr=[];Dr[6408]=4,Dr[6407]=3;var Or=[];Or[5121]=1,Or[5126]=4,Or[36193]=2;var Cr=33189,Fr=36168,zr=34041,Lr=[32854,32855,36194,35907,34842,34843,34836],Mr={};Mr[Er]="complete",Mr[36054]="incomplete attachment",Mr[36057]="incomplete dimensions",Mr[36055]="incomplete, missing attachment",Mr[36061]="unsupported";var Pr=5126;function Br(){this.state=0,this.x=0,this.y=0,this.z=0,this.w=0,this.buffer=null,this.size=0,this.normalized=!1,this.type=Pr,this.offset=0,this.stride=0,this.divisor=0}var Ir=35632,Rr=35633,Wr=35718,Hr=35721,Ur=6408,Nr=5121,qr=3333,Gr=5126;function Qr(t,r,n,a,i,o,f){function u(u){var s;null===r.next?(F(i.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),s=Nr):(F(null!==r.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),s=r.next.colorAttachments[0].texture._texture.type,o.oes_texture_float?(F(s===Nr||s===Gr,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"),s===Gr&&F(f.readFloat,"Reading 'float' values is not permitted in your browser. For a fallback, please see: https://www.npmjs.com/package/glsl-read-float")):F(s===Nr,"Reading from a framebuffer is only allowed for the type 'uint8'"));var c=0,l=0,d=a.framebufferWidth,m=a.framebufferHeight,p=null;e(u)?p=u:u&&(F.type(u,"object","invalid arguments to regl.read()"),c=0|u.x,l=0|u.y,F(c>=0&&c=0&&l0&&d+c<=a.framebufferWidth,"invalid width for read pixels"),F(m>0&&m+l<=a.framebufferHeight,"invalid height for read pixels"),n();var h=d*m*4;return p||(s===Nr?p=new Uint8Array(h):s===Gr&&(p=p||new Float32Array(h))),F.isTypedArray(p,"data buffer for regl.read() must be a typedarray"),F(p.byteLength>=h,"data buffer for regl.read() too small"),t.pixelStorei(qr,4),t.readPixels(c,l,d,m,Ur,s,p),p}return function(e){return e&&"framebuffer"in e?function(e){var t;return r.setFBO({framebuffer:e.framebuffer},function(){t=u(e)}),t}(e):u(e)}}function Vr(e){return Array.prototype.slice.call(e)}function Yr(e){return Vr(e).join("")}var Kr="xyzw".split(""),Xr=5121,$r=1,Jr=2,Zr=0,en=1,tn=2,rn=3,nn=4,an="dither",on="blend.enable",fn="blend.color",un="blend.equation",sn="blend.func",cn="depth.enable",ln="depth.func",dn="depth.range",mn="depth.mask",pn="colorMask",hn="cull.enable",bn="cull.face",vn="frontFace",gn="lineWidth",yn="polygonOffset.enable",xn="polygonOffset.offset",wn="sample.alpha",kn="sample.enable",_n="sample.coverage",An="stencil.enable",Sn="stencil.mask",En="stencil.func",Tn="stencil.opFront",jn="stencil.opBack",Dn="scissor.enable",On="scissor.box",Cn="viewport",Fn="profile",zn="framebuffer",Ln="vert",Mn="frag",Pn="elements",Bn="primitive",In="count",Rn="offset",Wn="instances",Hn=zn+"Width",Un=zn+"Height",Nn=Cn+"Width",qn=Cn+"Height",Gn="drawingBufferWidth",Qn="drawingBufferHeight",Vn=[sn,un,En,Tn,jn,_n,Cn,On,xn],Yn=34962,Kn=34963,Xn=3553,$n=34067,Jn=2884,Zn=3042,ea=3024,ta=2960,ra=2929,na=3089,aa=32823,ia=32926,oa=32928,fa=5126,ua=35664,sa=35665,ca=35666,la=5124,da=35667,ma=35668,pa=35669,ha=35670,ba=35671,va=35672,ga=35673,ya=35674,xa=35675,wa=35676,ka=35678,_a=35680,Aa=4,Sa=1028,Ea=1029,Ta=2304,ja=2305,Da=32775,Oa=32776,Ca=519,Fa=7680,za=0,La=1,Ma=32774,Pa=513,Ba=36160,Ia=36064,Ra={0:0,1:1,zero:0,one:1,"src color":768,"one minus src color":769,"src alpha":770,"one minus src alpha":771,"dst color":774,"one minus dst color":775,"dst alpha":772,"one minus dst alpha":773,"constant color":32769,"one minus constant color":32770,"constant alpha":32771,"one minus constant alpha":32772,"src alpha saturate":776},Wa=["constant color, constant alpha","one minus constant color, constant alpha","constant color, one minus constant alpha","one minus constant color, one minus constant alpha","constant alpha, constant color","constant alpha, one minus constant color","one minus constant alpha, constant color","one minus constant alpha, one minus constant color"],Ha={never:512,less:513,"<":513,equal:514,"=":514,"==":514,"===":514,lequal:515,"<=":515,greater:516,">":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},Ua={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},Na={frag:35632,vert:35633},qa={cw:Ta,ccw:ja};function Ga(t){return Array.isArray(t)||e(t)||re(t)}function Qa(e){return e.sort(function(e,t){return e===Cn?-1:t===Cn?1:e=1,n>=2,t)}if(r===nn){var a=e.data;return new Va(a.thisDep,a.contextDep,a.propDep,t)}return new Va(r===rn,r===tn,r===en,t)}var $a=new Va(!1,!1,!1,function(){});function Ja(e,r,n,a,i,o,f,u,s,c,l,d,m,p,h){var b=c.Record,v={add:32774,subtract:32778,"reverse subtract":32779};n.ext_blend_minmax&&(v.min=Da,v.max=Oa);var g=n.angle_instanced_arrays,y=n.webgl_draw_buffers,x={dirty:!0,profile:h.profile},w={},k=[],_={},A={};function S(e){return e.replace(".","_")}function E(e,t,r){var n=S(e);k.push(e),w[n]=x[n]=!!r,_[n]=t}function T(e,t,r){var n=S(e);k.push(e),Array.isArray(r)?(x[n]=r.slice(),w[n]=r.slice()):x[n]=w[n]=r,A[n]=t}E(an,ea),E(on,Zn),T(fn,"blendColor",[0,0,0,0]),T(un,"blendEquationSeparate",[Ma,Ma]),T(sn,"blendFuncSeparate",[La,za,La,za]),E(cn,ra,!0),T(ln,"depthFunc",Pa),T(dn,"depthRange",[0,1]),T(mn,"depthMask",!0),T(pn,pn,[!0,!0,!0,!0]),E(hn,Jn),T(bn,"cullFace",Ea),T(vn,vn,ja),T(gn,gn,1),E(yn,aa),T(xn,"polygonOffset",[0,0]),E(wn,ia),E(kn,oa),T(_n,"sampleCoverage",[1,!1]),E(An,ta),T(Sn,"stencilMask",-1),T(En,"stencilFunc",[Ca,0,-1]),T(Tn,"stencilOpSeparate",[Sa,Fa,Fa,Fa]),T(jn,"stencilOpSeparate",[Ea,Fa,Fa,Fa]),E(Dn,na),T(On,"scissor",[0,0,e.drawingBufferWidth,e.drawingBufferHeight]),T(Cn,Cn,[0,0,e.drawingBufferWidth,e.drawingBufferHeight]);var j={gl:e,context:m,strings:r,next:w,current:x,draw:d,elements:o,buffer:i,shader:l,attributes:c.state,uniforms:s,framebuffer:u,extensions:n,timer:p,isBufferArgs:Ga},D={primTypes:ye,compareFuncs:Ha,blendFuncs:Ra,blendEquations:v,stencilOps:Ua,glTypes:fe,orientationType:qa};F.optional(function(){j.isArrayLike=Pe}),y&&(D.backBuffer=[Ea],D.drawBuffer=q(a.maxDrawbuffers,function(e){return 0===e?[0]:q(e,function(e){return Ia+e})}));var O=0;function C(){var e=function(){var e=0,r=[],n=[];function a(){var r=[],n=[];return t(function(){r.push.apply(r,Vr(arguments))},{def:function(){var t="v"+e++;return n.push(t),arguments.length>0&&(r.push(t,"="),r.push.apply(r,Vr(arguments)),r.push(";")),t},toString:function(){return Yr([n.length>0?"var "+n+";":"",Yr(r)])}})}function i(){var e=a(),r=a(),n=e.toString,i=r.toString;function o(t,n){r(t,n,"=",e.def(t,n),";")}return t(function(){e.apply(e,Vr(arguments))},{def:e.def,entry:e,exit:r,save:o,set:function(t,r,n){o(t,r),e(t,r,"=",n,";")},toString:function(){return n()+i()}})}var o=a(),f={};return{global:o,link:function(t){for(var a=0;a=0,'unknown parameter "'+t+'"',s.commandStr)})}t(c),t(d)});var m=function(e,t){var r=e.static,n=e.dynamic;if(zn in r){var a=r[zn];return a?(a=u.getFramebuffer(a),F.command(a,"invalid framebuffer object"),Ka(function(e,t){var r=e.link(a),n=e.shared;t.set(n.framebuffer,".next",r);var i=n.context;return t.set(i,"."+Hn,r+".width"),t.set(i,"."+Un,r+".height"),r})):Ka(function(e,t){var r=e.shared;t.set(r.framebuffer,".next","null");var n=r.context;return t.set(n,"."+Hn,n+"."+Gn),t.set(n,"."+Un,n+"."+Qn),"null"})}if(zn in n){var i=n[zn];return Xa(i,function(e,t){var r=e.invoke(t,i),n=e.shared,a=n.framebuffer,o=t.def(a,".getFramebuffer(",r,")");F.optional(function(){e.assert(t,"!"+r+"||"+o,"invalid framebuffer object")}),t.set(a,".next",o);var f=n.context;return t.set(f,"."+Hn,o+"?"+o+".width:"+f+"."+Gn),t.set(f,"."+Un,o+"?"+o+".height:"+f+"."+Qn),o})}return null}(e),p=function(e,t,r){var n=e.static,a=e.dynamic;function i(e){if(e in n){var i=n[e];F.commandType(i,"object","invalid "+e,r.commandStr);var o,f,u=!0,s=0|i.x,c=0|i.y;return"width"in i?(o=0|i.width,F.command(o>=0,"invalid "+e,r.commandStr)):u=!1,"height"in i?(f=0|i.height,F.command(f>=0,"invalid "+e,r.commandStr)):u=!1,new Va(!u&&t&&t.thisDep,!u&&t&&t.contextDep,!u&&t&&t.propDep,function(e,t){var r=e.shared.context,n=o;"width"in i||(n=t.def(r,".",Hn,"-",s));var a=f;return"height"in i||(a=t.def(r,".",Un,"-",c)),[s,c,n,a]})}if(e in a){var l=a[e],d=Xa(l,function(t,r){var n=t.invoke(r,l);F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)});var a=t.shared.context,i=r.def(n,".x|0"),o=r.def(n,".y|0"),f=r.def('"width" in ',n,"?",n,".width|0:","(",a,".",Hn,"-",i,")"),u=r.def('"height" in ',n,"?",n,".height|0:","(",a,".",Un,"-",o,")");return F.optional(function(){t.assert(r,f+">=0&&"+u+">=0","invalid "+e)}),[i,o,f,u]});return t&&(d.thisDep=d.thisDep||t.thisDep,d.contextDep=d.contextDep||t.contextDep,d.propDep=d.propDep||t.propDep),d}return t?new Va(t.thisDep,t.contextDep,t.propDep,function(e,t){var r=e.shared.context;return[0,0,t.def(r,".",Hn),t.def(r,".",Un)]}):null}var o=i(Cn);if(o){var f=o;o=new Va(o.thisDep,o.contextDep,o.propDep,function(e,t){var r=f.append(e,t),n=e.shared.context;return t.set(n,"."+Nn,r[2]),t.set(n,"."+qn,r[3]),r})}return{viewport:o,scissor_box:i(On)}}(e,m,s),h=function(e,t){var r=e.static,n=e.dynamic,a=function(){if(Pn in r){var e=r[Pn];Ga(e)?e=o.getElements(o.create(e,!0)):e&&(e=o.getElements(e),F.command(e,"invalid elements",t.commandStr));var a=Ka(function(t,r){if(e){var n=t.link(e);return t.ELEMENTS=n,n}return t.ELEMENTS=null,null});return a.value=e,a}if(Pn in n){var i=n[Pn];return Xa(i,function(e,t){var r=e.shared,n=r.isBufferArgs,a=r.elements,o=e.invoke(t,i),f=t.def("null"),u=t.def(n,"(",o,")"),s=e.cond(u).then(f,"=",a,".createStream(",o,");").else(f,"=",a,".getElements(",o,");");return F.optional(function(){e.assert(s.else,"!"+o+"||"+f,"invalid elements")}),t.entry(s),t.exit(e.cond(u).then(a,".destroyStream(",f,");")),e.ELEMENTS=f,f})}return null}();function i(e,i){if(e in r){var o=0|r[e];return F.command(!i||o>=0,"invalid "+e,t.commandStr),Ka(function(e,t){return i&&(e.OFFSET=o),o})}if(e in n){var f=n[e];return Xa(f,function(t,r){var n=t.invoke(r,f);return i&&(t.OFFSET=n,F.optional(function(){t.assert(r,n+">=0","invalid "+e)})),n})}return i&&a?Ka(function(e,t){return e.OFFSET="0",0}):null}var f=i(Rn,!0);return{elements:a,primitive:function(){if(Bn in r){var e=r[Bn];return F.commandParameter(e,ye,"invalid primitve",t.commandStr),Ka(function(t,r){return ye[e]})}if(Bn in n){var i=n[Bn];return Xa(i,function(e,t){var r=e.constants.primTypes,n=e.invoke(t,i);return F.optional(function(){e.assert(t,n+" in "+r,"invalid primitive, must be one of "+Object.keys(ye))}),t.def(r,"[",n,"]")})}return a?Ya(a)?a.value?Ka(function(e,t){return t.def(e.ELEMENTS,".primType")}):Ka(function(){return Aa}):new Va(a.thisDep,a.contextDep,a.propDep,function(e,t){var r=e.ELEMENTS;return t.def(r,"?",r,".primType:",Aa)}):null}(),count:function(){if(In in r){var e=0|r[In];return F.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),Ka(function(){return e})}if(In in n){var i=n[In];return Xa(i,function(e,t){var r=e.invoke(t,i);return F.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(a){if(Ya(a)){if(a)return f?new Va(f.thisDep,f.contextDep,f.propDep,function(e,t){var r=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return F.optional(function(){e.assert(t,r+">=0","invalid vertex offset/element buffer too small")}),r}):Ka(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var o=Ka(function(){return-1});return F.optional(function(){o.MISSING=!0}),o}var u=new Va(a.thisDep||f.thisDep,a.contextDep||f.contextDep,a.propDep||f.propDep,function(e,t){var r=e.ELEMENTS;return e.OFFSET?t.def(r,"?",r,".vertCount-",e.OFFSET,":-1"):t.def(r,"?",r,".vertCount:-1")});return F.optional(function(){u.DYNAMIC=!0}),u}return null}(),instances:i(Wn,!1),offset:f}}(e,s),y=function(e,t){var r=e.static,n=e.dynamic,i={};return k.forEach(function(e){var o=S(e);function f(t,a){if(e in r){var f=t(r[e]);i[o]=Ka(function(){return f})}else if(e in n){var u=n[e];i[o]=Xa(u,function(e,t){return a(e,t,e.invoke(t,u))})}}switch(e){case hn:case on:case an:case An:case cn:case Dn:case yn:case wn:case kn:case mn:return f(function(r){return F.commandType(r,"boolean",e,t.commandStr),r},function(t,r,n){return F.optional(function(){t.assert(r,"typeof "+n+'==="boolean"',"invalid flag "+e,t.commandStr)}),n});case ln:return f(function(r){return F.commandParameter(r,Ha,"invalid "+e,t.commandStr),Ha[r]},function(t,r,n){var a=t.constants.compareFuncs;return F.optional(function(){t.assert(r,n+" in "+a,"invalid "+e+", must be one of "+Object.keys(Ha))}),r.def(a,"[",n,"]")});case dn:return f(function(e){return F.command(Pe(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1]&&e[0]<=e[1],"depth range is 2d array",t.commandStr),e},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===2&&typeof "+r+'[0]==="number"&&typeof '+r+'[1]==="number"&&'+r+"[0]<="+r+"[1]","depth range must be a 2d array")}),[t.def("+",r,"[0]"),t.def("+",r,"[1]")]});case sn:return f(function(e){F.commandType(e,"object","blend.func",t.commandStr);var r="srcRGB"in e?e.srcRGB:e.src,n="srcAlpha"in e?e.srcAlpha:e.src,a="dstRGB"in e?e.dstRGB:e.dst,i="dstAlpha"in e?e.dstAlpha:e.dst;return F.commandParameter(r,Ra,o+".srcRGB",t.commandStr),F.commandParameter(n,Ra,o+".srcAlpha",t.commandStr),F.commandParameter(a,Ra,o+".dstRGB",t.commandStr),F.commandParameter(i,Ra,o+".dstAlpha",t.commandStr),F.command(-1===Wa.indexOf(r+", "+a),"unallowed blending combination (srcRGB, dstRGB) = ("+r+", "+a+")",t.commandStr),[Ra[r],Ra[a],Ra[n],Ra[i]]},function(t,r,n){var a=t.constants.blendFuncs;function i(i,o){var f=r.def('"',i,o,'" in ',n,"?",n,".",i,o,":",n,".",i);return F.optional(function(){t.assert(r,f+" in "+a,"invalid "+e+"."+i+o+", must be one of "+Object.keys(Ra))}),f}F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid blend func, must be an object")});var o=i("src","RGB"),f=i("dst","RGB");F.optional(function(){var e=t.constants.invalidBlendCombinations;t.assert(r,e+".indexOf("+o+'+", "+'+f+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")});var u=r.def(a,"[",o,"]"),s=r.def(a,"[",i("src","Alpha"),"]");return[u,r.def(a,"[",f,"]"),s,r.def(a,"[",i("dst","Alpha"),"]")]});case un:return f(function(r){return"string"==typeof r?(F.commandParameter(r,v,"invalid "+e,t.commandStr),[v[r],v[r]]):"object"==typeof r?(F.commandParameter(r.rgb,v,e+".rgb",t.commandStr),F.commandParameter(r.alpha,v,e+".alpha",t.commandStr),[v[r.rgb],v[r.alpha]]):void F.commandRaise("invalid blend.equation",t.commandStr)},function(t,r,n){var a=t.constants.blendEquations,i=r.def(),o=r.def(),f=t.cond("typeof ",n,'==="string"');return F.optional(function(){function r(e,r,n){t.assert(e,n+" in "+a,"invalid "+r+", must be one of "+Object.keys(v))}r(f.then,e,n),t.assert(f.else,n+"&&typeof "+n+'==="object"',"invalid "+e),r(f.else,e+".rgb",n+".rgb"),r(f.else,e+".alpha",n+".alpha")}),f.then(i,"=",o,"=",a,"[",n,"];"),f.else(i,"=",a,"[",n,".rgb];",o,"=",a,"[",n,".alpha];"),r(f),[i,o]});case fn:return f(function(e){return F.command(Pe(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),q(4,function(t){return+e[t]})},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===4","blend.color must be a 4d array")}),q(4,function(e){return t.def("+",r,"[",e,"]")})});case Sn:return f(function(e){return F.commandType(e,"number",o,t.commandStr),0|e},function(e,t,r){return F.optional(function(){e.assert(t,"typeof "+r+'==="number"',"invalid stencil.mask")}),t.def(r,"|0")});case En:return f(function(r){F.commandType(r,"object",o,t.commandStr);var n=r.cmp||"keep",a=r.ref||0,i="mask"in r?r.mask:-1;return F.commandParameter(n,Ha,e+".cmp",t.commandStr),F.commandType(a,"number",e+".ref",t.commandStr),F.commandType(i,"number",e+".mask",t.commandStr),[Ha[n],a,i]},function(e,t,r){var n=e.constants.compareFuncs;return F.optional(function(){function a(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}a(r+"&&typeof ",r,'==="object"'),a('!("cmp" in ',r,")||(",r,".cmp in ",n,")")}),[t.def('"cmp" in ',r,"?",n,"[",r,".cmp]",":",Fa),t.def(r,".ref|0"),t.def('"mask" in ',r,"?",r,".mask|0:-1")]});case Tn:case jn:return f(function(r){F.commandType(r,"object",o,t.commandStr);var n=r.fail||"keep",a=r.zfail||"keep",i=r.zpass||"keep";return F.commandParameter(n,Ua,e+".fail",t.commandStr),F.commandParameter(a,Ua,e+".zfail",t.commandStr),F.commandParameter(i,Ua,e+".zpass",t.commandStr),[e===jn?Ea:Sa,Ua[n],Ua[a],Ua[i]]},function(t,r,n){var a=t.constants.stencilOps;function i(i){return F.optional(function(){t.assert(r,'!("'+i+'" in '+n+")||("+n+"."+i+" in "+a+")","invalid "+e+"."+i+", must be one of "+Object.keys(Ua))}),r.def('"',i,'" in ',n,"?",a,"[",n,".",i,"]:",Fa)}return F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)}),[e===jn?Ea:Sa,i("fail"),i("zfail"),i("zpass")]});case xn:return f(function(e){F.commandType(e,"object",o,t.commandStr);var r=0|e.factor,n=0|e.units;return F.commandType(r,"number",o+".factor",t.commandStr),F.commandType(n,"number",o+".units",t.commandStr),[r,n]},function(t,r,n){return F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)}),[r.def(n,".factor|0"),r.def(n,".units|0")]});case bn:return f(function(e){var r=0;return"front"===e?r=Sa:"back"===e&&(r=Ea),F.command(!!r,o,t.commandStr),r},function(e,t,r){return F.optional(function(){e.assert(t,r+'==="front"||'+r+'==="back"',"invalid cull.face")}),t.def(r,'==="front"?',Sa,":",Ea)});case gn:return f(function(e){return F.command("number"==typeof e&&e>=a.lineWidthDims[0]&&e<=a.lineWidthDims[1],"invalid line width, must be a positive number between "+a.lineWidthDims[0]+" and "+a.lineWidthDims[1],t.commandStr),e},function(e,t,r){return F.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">="+a.lineWidthDims[0]+"&&"+r+"<="+a.lineWidthDims[1],"invalid line width")}),r});case vn:return f(function(e){return F.commandParameter(e,qa,o,t.commandStr),qa[e]},function(e,t,r){return F.optional(function(){e.assert(t,r+'==="cw"||'+r+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(r+'==="cw"?'+Ta+":"+ja)});case pn:return f(function(e){return F.command(Pe(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===4","invalid color.mask")}),q(4,function(e){return"!!"+r+"["+e+"]"})});case _n:return f(function(e){F.command("object"==typeof e&&e,o,t.commandStr);var r="value"in e?e.value:1,n=!!e.invert;return F.command("number"==typeof r&&r>=0&&r<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[r,n]},function(e,t,r){return F.optional(function(){e.assert(t,r+"&&typeof "+r+'==="object"',"invalid sample.coverage")}),[t.def('"value" in ',r,"?+",r,".value:1"),t.def("!!",r,".invert")]})}}),i}(e,s),x=function(e){var t=e.static,n=e.dynamic;function a(e){if(e in t){var a=r.id(t[e]);F.optional(function(){l.shader(Na[e],a,F.guessCommand())});var i=Ka(function(){return a});return i.id=a,i}if(e in n){var o=n[e];return Xa(o,function(t,r){var n=t.invoke(r,o),a=r.def(t.shared.strings,".id(",n,")");return F.optional(function(){r(t.shared.shader,".shader(",Na[e],",",a,",",t.command,");")}),a})}return null}var i,o=a(Mn),f=a(Ln),u=null;return Ya(o)&&Ya(f)?(u=l.program(f.id,o.id),i=Ka(function(e,t){return e.link(u)})):i=new Va(o&&o.thisDep||f&&f.thisDep,o&&o.contextDep||f&&f.contextDep,o&&o.propDep||f&&f.propDep,function(e,t){var r,n,a=e.shared.shader;r=o?o.append(e,t):t.def(a,".",Mn),n=f?f.append(e,t):t.def(a,".",Ln);var i=a+".program("+n+","+r;return F.optional(function(){i+=","+e.command}),t.def(i+")")}),{frag:o,vert:f,progVar:i,program:u}}(e);function w(e){var t=p[e];t&&(y[e]=t)}w(Cn),w(S(On));var _=Object.keys(y).length>0,A={framebuffer:m,draw:h,shader:x,state:y,dirty:_};return A.profile=function(e){var t,r=e.static,n=e.dynamic;if(Fn in r){var a=!!r[Fn];(t=Ka(function(e,t){return a})).enable=a}else if(Fn in n){var i=n[Fn];t=Xa(i,function(e,t){return e.invoke(t,i)})}return t}(e),A.uniforms=function(e,t){var r=e.static,n=e.dynamic,a={};return Object.keys(r).forEach(function(e){var n,i=r[e];if("number"==typeof i||"boolean"==typeof i)n=Ka(function(){return i});else if("function"==typeof i){var o=i._reglType;"texture2d"===o||"textureCube"===o?n=Ka(function(e){return e.link(i)}):"framebuffer"===o||"framebufferCube"===o?(F.command(i.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),n=Ka(function(e){return e.link(i.color[0])})):F.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else Pe(i)?n=Ka(function(t){return t.global.def("[",q(i.length,function(r){return F.command("number"==typeof i[r]||"boolean"==typeof i[r],"invalid uniform "+e,t.commandStr),i[r]}),"]")}):F.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);n.value=i,a[e]=n}),Object.keys(n).forEach(function(e){var t=n[e];a[e]=Xa(t,function(e,r){return e.invoke(r,t)})}),a}(n,s),A.attributes=function(e,t){var n=e.static,a=e.dynamic,o={};return Object.keys(n).forEach(function(e){var a=n[e],f=r.id(e),u=new b;if(Ga(a))u.state=$r,u.buffer=i.getBuffer(i.create(a,Yn,!1,!0)),u.type=0;else{var s=i.getBuffer(a);if(s)u.state=$r,u.buffer=s,u.type=0;else if(F.command("object"==typeof a&&a,"invalid data for attribute "+e,t.commandStr),"constant"in a){var c=a.constant;u.buffer="null",u.state=Jr,"number"==typeof c?u.x=c:(F.command(Pe(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,t.commandStr),Kr.forEach(function(e,t){t=0,'invalid offset for attribute "'+e+'"',t.commandStr);var d=0|a.stride;F.command(d>=0&&d<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',t.commandStr);var m=0|a.size;F.command(!("size"in a)||m>0&&m<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',t.commandStr);var p=!!a.normalized,h=0;"type"in a&&(F.commandParameter(a.type,fe,"invalid type for attribute "+e,t.commandStr),h=fe[a.type]);var v=0|a.divisor;"divisor"in a&&(F.command(0===v||g,'cannot specify divisor for attribute "'+e+'", instancing not supported',t.commandStr),F.command(v>=0,'invalid divisor for attribute "'+e+'"',t.commandStr)),F.optional(function(){var r=t.commandStr,n=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(a).forEach(function(t){F.command(n.indexOf(t)>=0,'unknown parameter "'+t+'" for attribute pointer "'+e+'" (valid parameters are '+n+")",r)})}),u.buffer=s,u.state=$r,u.size=m,u.normalized=p,u.type=h||s.dtype,u.offset=l,u.stride=d,u.divisor=v}}o[e]=Ka(function(e,t){var r=e.attribCache;if(f in r)return r[f];var n={isStream:!1};return Object.keys(u).forEach(function(e){n[e]=u[e]}),u.buffer&&(n.buffer=e.link(u.buffer),n.type=n.type||n.buffer+".dtype"),r[f]=n,n})}),Object.keys(a).forEach(function(e){var t=a[e];o[e]=Xa(t,function(r,n){var a=r.invoke(n,t),i=r.shared,o=i.isBufferArgs,f=i.buffer;F.optional(function(){r.assert(n,a+"&&(typeof "+a+'==="object"||typeof '+a+'==="function")&&('+o+"("+a+")||"+f+".getBuffer("+a+")||"+f+".getBuffer("+a+".buffer)||"+o+"("+a+'.buffer)||("constant" in '+a+"&&(typeof "+a+'.constant==="number"||'+i.isArrayLike+"("+a+".constant))))",'invalid dynamic attribute "'+e+'"')});var u={isStream:n.def(!1)},s=new b;s.state=$r,Object.keys(s).forEach(function(e){u[e]=n.def(""+s[e])});var c=u.buffer,l=u.type;function d(e){n(u[e],"=",a,".",e,"|0;")}return n("if(",o,"(",a,")){",u.isStream,"=true;",c,"=",f,".createStream(",Yn,",",a,");",l,"=",c,".dtype;","}else{",c,"=",f,".getBuffer(",a,");","if(",c,"){",l,"=",c,".dtype;",'}else if("constant" in ',a,"){",u.state,"=",Jr,";","if(typeof "+a+'.constant === "number"){',u[Kr[0]],"=",a,".constant;",Kr.slice(1).map(function(e){return u[e]}).join("="),"=0;","}else{",Kr.map(function(e,t){return u[e]+"="+a+".constant.length>"+t+"?"+a+".constant["+t+"]:0;"}).join(""),"}}else{","if(",o,"(",a,".buffer)){",c,"=",f,".createStream(",Yn,",",a,".buffer);","}else{",c,"=",f,".getBuffer(",a,".buffer);","}",l,'="type" in ',a,"?",i.glTypes,"[",a,".type]:",c,".dtype;",u.normalized,"=!!",a,".normalized;"),d("size"),d("offset"),d("stride"),d("divisor"),n("}}"),n.exit("if(",u.isStream,"){",f,".destroyStream(",c,");","}"),u})}),o}(t,s),A.context=function(e){var t=e.static,r=e.dynamic,n={};return Object.keys(t).forEach(function(e){var r=t[e];n[e]=Ka(function(e,t){return"number"==typeof r||"boolean"==typeof r?""+r:e.link(r)})}),Object.keys(r).forEach(function(e){var t=r[e];n[e]=Xa(t,function(e,r){return e.invoke(r,t)})}),n}(f),A}function L(e,t,r){var n=e.shared,a=n.context,i=e.scope();Object.keys(r).forEach(function(n){t.save(a,"."+n);var o=r[n];i(a,".",n,"=",o.append(e,t),";")}),t(i)}function M(e,t,r,n){var a,i=e.shared,o=i.gl,f=i.framebuffer;y&&(a=t.def(i.extensions,".webgl_draw_buffers"));var u,s=e.constants,c=s.drawBuffer,l=s.backBuffer;u=r?r.append(e,t):t.def(f,".next"),n||t("if(",u,"!==",f,".cur){"),t("if(",u,"){",o,".bindFramebuffer(",Ba,",",u,".framebuffer);"),y&&t(a,".drawBuffersWEBGL(",c,"[",u,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",Ba,",null);"),y&&t(a,".drawBuffersWEBGL(",l,");"),t("}",f,".cur=",u,";"),n||t("}")}function P(e,t,r){var n=e.shared,a=n.gl,i=e.current,o=e.next,f=n.current,u=n.next,s=e.cond(f,".dirty");k.forEach(function(t){var n,c,l=S(t);if(!(l in r.state))if(l in o){n=o[l],c=i[l];var d=q(x[l].length,function(e){return s.def(n,"[",e,"]")});s(e.cond(d.map(function(e,t){return e+"!=="+c+"["+t+"]"}).join("||")).then(a,".",A[l],"(",d,");",d.map(function(e,t){return c+"["+t+"]="+e}).join(";"),";"))}else{n=s.def(u,".",l);var m=e.cond(n,"!==",f,".",l);s(m),l in _?m(e.cond(n).then(a,".enable(",_[l],");").else(a,".disable(",_[l],");"),f,".",l,"=",n,";"):m(a,".",A[l],"(",n,");",f,".",l,"=",n,";")}}),0===Object.keys(r.state).length&&s(f,".dirty=false;"),t(s)}function B(e,t,r,n){var a=e.shared,i=e.current,o=a.current,f=a.gl;Qa(Object.keys(r)).forEach(function(a){var u=r[a];if(!n||n(u)){var s=u.append(e,t);if(_[a]){var c=_[a];Ya(u)?t(f,s?".enable(":".disable(",c,");"):t(e.cond(s).then(f,".enable(",c,");").else(f,".disable(",c,");")),t(o,".",a,"=",s,";")}else if(Pe(s)){var l=i[a];t(f,".",A[a],"(",s,");",s.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(f,".",A[a],"(",s,");",o,".",a,"=",s,";")}})}function R(e,t){g&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function W(e,t,r,n,a){var i,o,f,u=e.shared,s=e.stats,c=u.current,l=u.timer,d=r.profile;function m(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function h(e){i=t.def(),e(i,"=",m(),";"),"string"==typeof a?e(s,".count+=",a,";"):e(s,".count++;"),p&&(n?(o=t.def(),e(o,"=",l,".getNumPendingQueries();")):e(l,".beginQuery(",s,");"))}function b(e){e(s,".cpuTime+=",m(),"-",i,";"),p&&(n?e(l,".pushScopeStats(",o,",",l,".getNumPendingQueries(),",s,");"):e(l,".endQuery();"))}function v(e){var r=t.def(c,".profile");t(c,".profile=",e,";"),t.exit(c,".profile=",r,";")}if(d){if(Ya(d))return void(d.enable?(h(t),b(t.exit),v("true")):v("false"));v(f=d.append(e,t))}else f=t.def(c,".profile");var g=e.block();h(g),t("if(",f,"){",g,"}");var y=e.block();b(y),t.exit("if(",f,"){",y,"}")}function H(e,t,r,n,a){var i=e.shared;n.forEach(function(n){var o,f=n.name,u=r.attributes[f];if(u){if(!a(u))return;o=u.append(e,t)}else{if(!a($a))return;var s=e.scopeAttrib(f);F.optional(function(){e.assert(t,s+".state","missing attribute "+f)}),o={},Object.keys(new b).forEach(function(e){o[e]=t.def(s,".",e)})}!function(r,n,a){var o=i.gl,f=t.def(r,".location"),u=t.def(i.attributes,"[",f,"]"),s=a.state,c=a.buffer,l=[a.x,a.y,a.z,a.w],d=["buffer","normalized","offset","stride"];function m(){t("if(!",u,".buffer){",o,".enableVertexAttribArray(",f,");}");var r,i=a.type;if(r=a.size?t.def(a.size,"||",n):n,t("if(",u,".type!==",i,"||",u,".size!==",r,"||",d.map(function(e){return u+"."+e+"!=="+a[e]}).join("||"),"){",o,".bindBuffer(",Yn,",",c,".buffer);",o,".vertexAttribPointer(",[f,r,i,a.normalized,a.stride,a.offset],");",u,".type=",i,";",u,".size=",r,";",d.map(function(e){return u+"."+e+"="+a[e]+";"}).join(""),"}"),g){var s=a.divisor;t("if(",u,".divisor!==",s,"){",e.instancing,".vertexAttribDivisorANGLE(",[f,s],");",u,".divisor=",s,";}")}}function p(){t("if(",u,".buffer){",o,".disableVertexAttribArray(",f,");","}if(",Kr.map(function(e,t){return u+"."+e+"!=="+l[t]}).join("||"),"){",o,".vertexAttrib4f(",f,",",l,");",Kr.map(function(e,t){return u+"."+e+"="+l[t]+";"}).join(""),"}")}s===$r?m():s===Jr?p():(t("if(",s,"===",$r,"){"),m(),t("}else{"),p(),t("}"))}(e.link(n),function(e){switch(e){case ua:case da:case ba:return 2;case sa:case ma:case va:return 3;case ca:case pa:case ga:return 4;default:return 1}}(n.info.type),o)})}function U(e,t,n,a,i){for(var o,f=e.shared,u=f.gl,s=0;s1?q(w,function(e){return c+"["+e+"]"}):c);t(");")}}function N(e,t,r,n){var a=e.shared,i=a.gl,o=a.draw,f=n.draw,u=function(){var a,u=f.elements,s=t;return u?((u.contextDep&&n.contextDynamic||u.propDep)&&(s=r),a=u.append(e,s)):a=s.def(o,".",Pn),a&&s("if("+a+")"+i+".bindBuffer("+Kn+","+a+".buffer.buffer);"),a}();function s(a){var i=f[a];return i?i.contextDep&&n.contextDynamic||i.propDep?i.append(e,r):i.append(e,t):t.def(o,".",a)}var c,l,d=s(Bn),m=s(Rn),p=function(){var a,i=f.count,u=t;return i?((i.contextDep&&n.contextDynamic||i.propDep)&&(u=r),a=i.append(e,u),F.optional(function(){i.MISSING&&e.assert(t,"false","missing vertex count"),i.DYNAMIC&&e.assert(u,a+">=0","missing vertex count")})):(a=u.def(o,".",In),F.optional(function(){e.assert(u,a+">=0","missing vertex count")})),a}();if("number"==typeof p){if(0===p)return}else r("if(",p,"){"),r.exit("}");g&&(c=s(Wn),l=e.instancing);var h=u+".type",b=f.elements&&Ya(f.elements);function v(){function e(){r(l,".drawElementsInstancedANGLE(",[d,p,h,m+"<<(("+h+"-"+Xr+")>>1)",c],");")}function t(){r(l,".drawArraysInstancedANGLE(",[d,m,p,c],");")}u?b?e():(r("if(",u,"){"),e(),r("}else{"),t(),r("}")):t()}function y(){function e(){r(i+".drawElements("+[d,p,h,m+"<<(("+h+"-"+Xr+")>>1)"]+");")}function t(){r(i+".drawArrays("+[d,m,p]+");")}u?b?e():(r("if(",u,"){"),e(),r("}else{"),t(),r("}")):t()}g&&("number"!=typeof c||c>=0)?"string"==typeof c?(r("if(",c,">0){"),v(),r("}else if(",c,"<0){"),y(),r("}")):v():y()}function G(e,t,r,n,a){var i=C(),o=i.proc("body",a);return F.optional(function(){i.commandStr=t.commandStr,i.command=i.link(t.commandStr)}),g&&(i.instancing=o.def(i.shared.extensions,".angle_instanced_arrays")),e(i,o,r,n),i.compile().body}function Q(e,t,r,n){R(e,t),H(e,t,r,n.attributes,function(){return!0}),U(e,t,r,n.uniforms,function(){return!0}),N(e,t,t,r)}function V(e,t,r,n){function a(){return!0}e.batchId="a1",R(e,t),H(e,t,r,n.attributes,a),U(e,t,r,n.uniforms,a),N(e,t,t,r)}function Y(e,t,r,n){R(e,t);var a=r.contextDep,i=t.def(),o=t.def();e.shared.props=o,e.batchId=i;var f=e.scope(),u=e.scope();function s(e){return e.contextDep&&a||e.propDep}function c(e){return!s(e)}if(t(f.entry,"for(",i,"=0;",i,"<","a1",";++",i,"){",o,"=","a0","[",i,"];",u,"}",f.exit),r.needsContext&&L(e,u,r.context),r.needsFramebuffer&&M(e,u,r.framebuffer),B(e,u,r.state,s),r.profile&&s(r.profile)&&W(e,u,r,!1,!0),n)H(e,f,r,n.attributes,c),H(e,u,r,n.attributes,s),U(e,f,r,n.uniforms,c),U(e,u,r,n.uniforms,s),N(e,f,u,r);else{var l=e.global.def("{}"),d=r.shader.progVar.append(e,u),m=u.def(d,".id"),p=u.def(l,"[",m,"]");u(e.shared.gl,".useProgram(",d,".program);","if(!",p,"){",p,"=",l,"[",m,"]=",e.link(function(t){return G(V,e,r,t,2)}),"(",d,");}",p,".call(this,a0[",i,"],",i,");")}}function K(e,t,r){var n=t.static[r];if(n&&function(e){if("object"==typeof e&&!Pe(e)){for(var t=Object.keys(e),r=0;r0&&r(e.shared.current,".dirty=true;")}(o,f),function(e,t){var n=e.proc("scope",3);e.batchId="a2";var a=e.shared,i=a.current;function o(r){var i=t.shader[r];i&&n.set(a.shader,"."+r,i.append(e,n))}L(e,n,t.context),t.framebuffer&&t.framebuffer.append(e,n),Qa(Object.keys(t.state)).forEach(function(r){var i=t.state[r].append(e,n);Pe(i)?i.forEach(function(t,a){n.set(e.next[r],"["+a+"]",t)}):n.set(a.next,"."+r,i)}),W(e,n,t,!0,!0),[Pn,Rn,In,Wn,Bn].forEach(function(r){var i=t.draw[r];i&&n.set(a.draw,"."+r,""+i.append(e,n))}),Object.keys(t.uniforms).forEach(function(i){n.set(a.uniforms,"["+r.id(i)+"]",t.uniforms[i].append(e,n))}),Object.keys(t.attributes).forEach(function(r){var a=t.attributes[r].append(e,n),i=e.scopeAttrib(r);Object.keys(new b).forEach(function(e){n.set(i,"."+e,a[e])})}),o(Ln),o(Mn),Object.keys(t.state).length>0&&(n(i,".dirty=true;"),n.exit(i,".dirty=true;")),n("a1(",e.shared.context,",a0,",e.batchId,");")}(o,f),function(e,t){var r=e.proc("batch",2);e.batchId="0",R(e,r);var n=!1,a=!0;Object.keys(t.context).forEach(function(e){n=n||t.context[e].propDep}),n||(L(e,r,t.context),a=!1);var i=t.framebuffer,o=!1;function f(e){return e.contextDep&&n||e.propDep}i?(i.propDep?n=o=!0:i.contextDep&&n&&(o=!0),o||M(e,r,i)):M(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(n=!0),P(e,r,t),B(e,r,t.state,function(e){return!f(e)}),t.profile&&f(t.profile)||W(e,r,t,!1,"a1"),t.contextDep=n,t.needsContext=a,t.needsFramebuffer=o;var u=t.shader.progVar;if(u.contextDep&&n||u.propDep)Y(e,r,t,null);else{var s=u.append(e,r);if(r(e.shared.gl,".useProgram(",s,".program);"),t.shader.program)Y(e,r,t,t.shader.program);else{var c=e.global.def("{}"),l=r.def(s,".id"),d=r.def(c,"[",l,"]");r(e.cond(d).then(d,".call(this,a0,a1);").else(d,"=",c,"[",l,"]=",e.link(function(r){return G(Y,e,t,r,2)}),"(",s,");",d,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}(o,f),o.compile()}}}var Za=34918,ei=34919,ti=35007,ri=function(e,t){if(!t.ext_disjoint_timer_query)return null;var r=[];function n(e){r.push(e)}var a=[];function i(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null}var o=[];function f(e){o.push(e)}var u=[];function s(e,t,r){var n=o.pop()||new i;n.startQueryIndex=e,n.endQueryIndex=t,n.sum=0,n.stats=r,u.push(n)}var c=[],l=[];return{beginQuery:function(e){var n=r.pop()||t.ext_disjoint_timer_query.createQueryEXT();t.ext_disjoint_timer_query.beginQueryEXT(ti,n),a.push(n),s(a.length-1,a.length,e)},endQuery:function(){t.ext_disjoint_timer_query.endQueryEXT(ti)},pushScopeStats:s,update:function(){var e,r,i=a.length;if(0!==i){l.length=Math.max(l.length,i+1),c.length=Math.max(c.length,i+1),c[0]=0,l[0]=0;var o=0;for(e=0,r=0;r0)if(Array.isArray(r[0])){f=ce(r);for(var c=1,l=1;l0)if("number"==typeof t[0]){var i=ee.allocType(d.dtype,t.length);ve(i,t),p(i,a),ee.freeType(i)}else if(Array.isArray(t[0])||e(t[0])){n=ce(t);var o=se(t,n,d.dtype);p(o,a),ee.freeType(o)}else F.raise("invalid buffer data")}else if(re(t)){n=t.shape;var f=t.stride,u=0,s=0,c=0,l=0;1===n.length?(u=n[0],s=1,c=f[0],l=0):2===n.length?(u=n[0],s=n[1],c=f[0],l=f[1]):F.raise("invalid shape");var h=Array.isArray(t.data)?d.dtype:be(t.data),b=ee.allocType(h,u*s);ge(b,t.data,u,s,c,l,t.offset),p(b,a),ee.freeType(b)}else F.raise("invalid data for buffer subdata");return m},n.profile&&(m.stats=d.stats),m.destroy=function(){l(d)},m},createStream:function(e,t){var r=u.pop();return r||(r=new f(e)),r.bind(),c(r,t,de,0,1,!1),r},destroyStream:function(e){u.push(e)},clear:function(){ne(o).forEach(l),u.forEach(l)},getBuffer:function(e){return e&&e._buffer instanceof f?e._buffer:null},restore:function(){ne(o).forEach(function(e){e.buffer=t.createBuffer(),t.bindBuffer(e.type,e.buffer),t.bufferData(e.type,e.persistentData||e.byteLength,e.usage)})},_initBuffer:c}}(a,l,n,y),w=function(t,r,n,a){var i={},o=0,f={uint8:Ae,uint16:Ee};function u(e){this.id=o++,i[this.id]=this,this.buffer=e,this.primType=ke,this.vertCount=0,this.type=0}r.oes_element_index_uint&&(f.uint32=je),u.prototype.bind=function(){this.buffer.bind()};var s=[];function c(a,i,o,f,u,s,c){if(a.buffer.bind(),i){var l=c;c||e(i)&&(!re(i)||e(i.data))||(l=r.oes_element_index_uint?je:Ee),n._initBuffer(a.buffer,i,o,l,3)}else t.bufferData(De,s,o),a.buffer.dtype=d||Ae,a.buffer.usage=o,a.buffer.dimension=3,a.buffer.byteLength=s;var d=c;if(!c){switch(a.buffer.dtype){case Ae:case _e:d=Ae;break;case Ee:case Se:d=Ee;break;case je:case Te:d=je;break;default:F.raise("unsupported type for element array")}a.buffer.dtype=d}a.type=d,F(d!==je||!!r.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var m=u;m<0&&(m=a.buffer.byteLength,d===Ee?m>>=1:d===je&&(m>>=2)),a.vertCount=m;var p=f;if(f<0){p=ke;var h=a.buffer.dimension;1===h&&(p=xe),2===h&&(p=we),3===h&&(p=ke)}a.primType=p}function l(e){a.elementsCount--,F(null!==e.buffer,"must not double destroy elements"),delete i[e.id],e.buffer.destroy(),e.buffer=null}return{create:function(t,r){var i=n.create(null,De,!0),o=new u(i._buffer);function s(t){if(t)if("number"==typeof t)i(t),o.primType=ke,o.vertCount=0|t,o.type=Ae;else{var r=null,n=Ce,a=-1,u=-1,l=0,d=0;Array.isArray(t)||e(t)||re(t)?r=t:(F.type(t,"object","invalid arguments for elements"),"data"in t&&(r=t.data,F(Array.isArray(r)||e(r)||re(r),"invalid data for element buffer")),"usage"in t&&(F.parameter(t.usage,ue,"invalid element buffer usage"),n=ue[t.usage]),"primitive"in t&&(F.parameter(t.primitive,ye,"invalid element buffer primitive"),a=ye[t.primitive]),"count"in t&&(F("number"==typeof t.count&&t.count>=0,"invalid vertex count for elements"),u=0|t.count),"type"in t&&(F.parameter(t.type,f,"invalid buffer type"),d=f[t.type]),"length"in t?l=0|t.length:(l=u,d===Ee||d===Se?l*=2:d!==je&&d!==Te||(l*=4))),c(o,r,n,a,u,l,d)}else i(),o.primType=ke,o.vertCount=0,o.type=Ae;return s}return a.elementsCount++,s(t),s._reglType="elements",s._elements=o,s.subdata=function(e,t){return i.subdata(e,t),s},s.destroy=function(){l(o)},s},createStream:function(e){var t=s.pop();return t||(t=new u(n.create(null,De,!0,!1)._buffer)),c(t,e,Oe,-1,-1,0,0),t},destroyStream:function(e){s.push(e)},getElements:function(e){return"function"==typeof e&&e._elements instanceof u?e._elements:null},clear:function(){ne(i).forEach(l)}}}(a,d,x,l),k=function(e,t,r,n){var a={},i={};function o(e,t,r,n){this.name=e,this.id=t,this.location=r,this.info=n}function f(e,t){for(var r=0;r1)for(var h=0;he&&(e=t.stats.uniformsCount)}),e},r.getMaxAttributesCount=function(){var e=0;return c.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);ne(a).forEach(t),a={},ne(i).forEach(t),i={},c.forEach(function(t){e.deleteProgram(t.program)}),c.length=0,s={},r.shaderCount=0},program:function(e,t,n){F.command(e>=0,"missing vertex shader",n),F.command(t>=0,"missing fragment shader",n);var a=s[t];a||(a=s[t]={});var i=a[e];return i||(i=new d(t,e),r.shaderCount++,m(i,n),a[e]=i,c.push(i)),i},restore:function(){a={},i={};for(var e=0;e=wr&&t=2,"invalid shape for framebuffer"),o=C[0],d=C[1]}else"radius"in O&&(o=d=O.radius),"width"in O&&(o=O.width),"height"in O&&(d=O.height);("color"in O||"colors"in O)&&(y=O.color||O.colors,Array.isArray(y)&&F(1===y.length||r.webgl_draw_buffers,"multiple render targets not supported")),y||("colorCount"in O&&(S=0|O.colorCount,F(S>0,"invalid color buffer count")),"colorTexture"in O&&(x=!!O.colorTexture,w="rgba4"),"colorType"in O&&(_=O.colorType,x?(F(r.oes_texture_float||!("float"===_||"float32"===_),"you must enable OES_texture_float in order to use floating point framebuffer objects"),F(r.oes_texture_half_float||!("half float"===_||"float16"===_),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===_||"float16"===_?(F(r.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),w="rgba16f"):"float"!==_&&"float32"!==_||(F(r.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),w="rgba32f"),F.oneOf(_,c,"invalid color type")),"colorFormat"in O&&(w=O.colorFormat,u.indexOf(w)>=0?x=!0:s.indexOf(w)>=0?x=!1:x?F.oneOf(O.colorFormat,u,"invalid color format for texture"):F.oneOf(O.colorFormat,s,"invalid color format for renderbuffer"))),("depthTexture"in O||"depthStencilTexture"in O)&&(D=!(!O.depthTexture&&!O.depthStencilTexture),F(!D||r.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in O&&("boolean"==typeof O.depth?p=O.depth:(E=O.depth,g=!1)),"stencil"in O&&("boolean"==typeof O.stencil?g=O.stencil:(T=O.stencil,p=!1)),"depthStencil"in O&&("boolean"==typeof O.depthStencil?p=g=O.depthStencil:(j=O.depthStencil,p=!1,g=!1))}else o=d=1;var z=null,L=null,M=null,P=null;if(Array.isArray(y))z=y.map(h);else if(y)z=[h(y)];else for(z=new Array(S),a=0;a=0||z[a].renderbuffer&&Lr.indexOf(z[a].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+a+" is invalid"),z[a]&&z[a].texture){var I=Dr[z[a].texture._texture.format]*Or[z[a].texture._texture.type];null===B?B=I:F(B===I,"all color attachments much have the same number of bits per pixel.")}return m(L,o,d),F(!L||L.texture&&L.texture._texture.format===Tr||L.renderbuffer&&L.renderbuffer._renderbuffer.format===Cr,"invalid depth attachment for framebuffer object"),m(M,o,d),F(!M||M.renderbuffer&&M.renderbuffer._renderbuffer.format===Fr,"invalid stencil attachment for framebuffer object"),m(P,o,d),F(!P||P.texture&&P.texture._texture.format===zr||P.renderbuffer&&P.renderbuffer._renderbuffer.format===zr,"invalid depth-stencil attachment for framebuffer object"),k(i),i.width=o,i.height=d,i.colorAttachments=z,i.depthAttachment=L,i.stencilAttachment=M,i.depthStencilAttachment=P,l.color=z.map(v),l.depth=v(L),l.stencil=v(M),l.depthStencil=v(P),l.width=i.width,l.height=i.height,A(i),l}return o.framebufferCount++,l(e,a),t(l,{resize:function(e,t){F(f.next!==i,"can not resize a framebuffer which is currently in use");var r=Math.max(0|e,1),n=Math.max(0|t||r,1);if(r===i.width&&n===i.height)return l;for(var a=i.colorAttachments,o=0;o=2,"invalid shape for framebuffer"),F(g[0]===g[1],"cube framebuffer must be square"),d=g[0]}else"radius"in v&&(d=0|v.radius),"width"in v?(d=0|v.width,"height"in v&&F(v.height===d,"must be square")):"height"in v&&(d=0|v.height);("color"in v||"colors"in v)&&(m=v.color||v.colors,Array.isArray(m)&&F(1===m.length||r.webgl_draw_buffers,"multiple render targets not supported")),m||("colorCount"in v&&(b=0|v.colorCount,F(b>0,"invalid color buffer count")),"colorType"in v&&(F.oneOf(v.colorType,c,"invalid color type"),h=v.colorType),"colorFormat"in v&&(p=v.colorFormat,F.oneOf(v.colorFormat,u,"invalid color format for texture"))),"depth"in v&&(l.depth=v.depth),"stencil"in v&&(l.stencil=v.stencil),"depthStencil"in v&&(l.depthStencil=v.depthStencil)}else d=1;if(m)if(Array.isArray(m))for(s=[],n=0;n0&&(l.depth=i[0].depth,l.stencil=i[0].stencil,l.depthStencil=i[0].depthStencil),i[n]?i[n](l):i[n]=S(l)}return t(o,{width:d,height:d,color:s})}return o(e),t(o,{faces:i,resize:function(e){var t,r=0|e;if(F(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===o.width)return o;var a=o.color;for(t=0;t=0;--e){var t=O[e];t&&t(v,null,0)}a.flush(),m&&m.update()}function B(){!M&&O.length>0&&(M=R.next(P))}function H(){M&&(R.cancel(P),M=null)}function U(e){e.preventDefault(),o=!0,H(),C.forEach(function(e){e()})}function q(e){a.getError(),o=!1,f.restore(),k.restore(),x.restore(),_.restore(),A.restore(),S.restore(),m&&m.restore(),E.procs.refresh(),B(),z.forEach(function(e){e()})}function G(e){function r(e){var t={},r={};return Object.keys(e).forEach(function(n){var a=e[n];I.isDynamic(a)?r[n]=I.unbox(a,n):t[n]=a}),{dynamic:r,static:t}}F(!!e,"invalid args to regl({...})"),F.type(e,"object","invalid args to regl({...})");var n=r(e.context||{}),a=r(e.uniforms||{}),i=r(e.attributes||{}),f=r(function(e){var r=t({},e);function n(e){if(e in r){var t=r[e];delete r[e],Object.keys(t).forEach(function(n){r[e+"."+n]=t[n]})}}return delete r.uniforms,delete r.attributes,delete r.context,"stencil"in r&&r.stencil.op&&(r.stencil.opBack=r.stencil.opFront=r.stencil.op,delete r.stencil.op),n("blend"),n("depth"),n("cull"),n("stencil"),n("polygonOffset"),n("scissor"),n("sample"),r}(e)),u={gpuTime:0,cpuTime:0,count:0},s=E.compile(f,i,a,n,u),c=s.draw,l=s.batch,d=s.scope,m=[];return t(function(e,t){var r;if(o&&F.raise("context lost"),"function"==typeof e)return d.call(this,null,e,0);if("function"==typeof t){if("number"==typeof e){for(r=0;r0)return l.call(this,function(e){for(;m.length=0,"cannot cancel a frame twice"),O[t]=function e(){var t=di(O,e);O[t]=O[O.length-1],O.length-=1,O.length<=0&&H()}}}}function K(){var e=j.viewport,t=j.scissor_box;e[0]=e[1]=t[0]=t[1]=0,v.viewportWidth=v.framebufferWidth=v.drawingBufferWidth=e[2]=t[2]=a.drawingBufferWidth,v.viewportHeight=v.framebufferHeight=v.drawingBufferHeight=e[3]=t[3]=a.drawingBufferHeight}function X(){v.tick+=1,v.time=J(),K(),E.procs.poll()}function $(){K(),E.procs.refresh(),m&&m.update()}function J(){return(W()-p)/1e3}$();var Z=t(G,{clear:function(e){if(F("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var r=0;r<6;++r)Q(t({framebuffer:e.framebuffer.faces[r]},e),V);else Q(e,V);else V(null,e)},prop:I.define.bind(null,si),context:I.define.bind(null,ci),this:I.define.bind(null,li),draw:G({}),buffer:function(e){return x.create(e,oi,!1,!1)},elements:function(e){return w.create(e,!1)},texture:_.create2D,cube:_.createCube,renderbuffer:A.create,framebuffer:S.create,framebufferCube:S.createCube,attributes:i,frame:Y,on:function(e,t){var r;switch(F.type(t,"function","listener callback must be a function"),e){case"frame":return Y(t);case"lost":r=C;break;case"restore":r=z;break;case"destroy":r=L;break;default:F.raise("invalid event, must be one of frame,lost,restore,destroy")}return r.push(t),{cancel:function(){for(var e=0;e=0},read:T,destroy:function(){O.length=0,H(),D&&(D.removeEventListener(fi,U),D.removeEventListener(ui,q)),k.clear(),S.clear(),A.clear(),_.clear(),w.clear(),x.clear(),m&&m.clear(),L.forEach(function(e){e()})},_gl:a,_refresh:$,poll:function(){X(),m&&m.update()},now:J,stats:l});return n.onDone(null,Z),Z}}()},function(e,t,r){var n=r(19),a=r(21),i=r(1),o=r(24),f=r(25);e.exports=function(e,t){var r=t||{};void 0===r.noScroll&&(r.noScroll=r.preventDefault);var s={view:i(new Float32Array(16)),projection:i(new Float32Array(16)),center:new Float32Array(r.center||3),theta:r.theta||0,phi:r.phi||0,distance:Math.log(r.distance||10),eye:new Float32Array(3),up:new Float32Array(r.up||[0,1,0]),fovy:r.fovy||Math.PI/4,near:void 0!==r.near?r.near:.01,far:void 0!==r.far?r.far:1e3,noScroll:void 0!==r.noScroll&&r.noScroll,flipY:!!r.flipY,dtheta:0,dphi:0,rotationSpeed:void 0!==r.rotationSpeed?r.rotationSpeed:1,zoomSpeed:void 0!==r.zoomSpeed?r.zoomSpeed:1,renderOnDirty:void 0!==typeof r.renderOnDirty&&!!r.renderOnDirty},c=r.element,l=void 0!==r.damping?r.damping:.9,d=new Float32Array([1,0,0]),m=new Float32Array([0,0,1]),p=Math.log("minDistance"in r?r.minDistance:.1),h=Math.log("maxDistance"in r?r.maxDistance:1e3),b=0,v=0,g=0;if(u&&!1!==r.mouse){var y=c||e._gl.canvas;function x(){return c?c.offsetHeight:window.innerHeight}n(y,function(e,t,r){if(1&e){var n=(t-v)/(c?c.offsetWidth:window.innerWidth),a=(r-g)/x();s.dtheta+=4*s.rotationSpeed*n,s.dphi+=4*s.rotationSpeed*a,s.dirty=!0}v=t,g=r}),a(y,function(e,t){b+=t/x()*s.zoomSpeed,s.dirty=!0},r.noScroll)}function w(e){var t=e*l;return Math.abs(t)<.1?0:(s.dirty=!0,t)}function k(e,t,r){return Math.min(Math.max(e,t),r)}s.dirty=!0;var _=e({context:Object.assign({},s,{dirty:function(){return s.dirty},projection:function(e){return o(s.projection,s.fovy,e.viewportWidth/e.viewportHeight,s.near,s.far),s.flipY&&(s.projection[5]*=-1),s.projection}}),uniforms:Object.keys(s).reduce(function(t,r){return t[r]=e.context(r),t},{})});function A(e,t){void 0!==A.dirty&&(s.dirty=A.dirty||s.dirty,A.dirty=void 0),e&&t&&(s.dirty=!0),s.renderOnDirty&&!s.dirty||(t||(t=e,e={}),function(e){Object.keys(e).forEach(function(t){s[t]=e[t]});var t=s.center,r=s.eye,n=s.up,a=s.dtheta,i=s.dphi;s.theta+=a,s.phi=k(s.phi+i,-Math.PI/2,Math.PI/2),s.distance=k(s.distance+b,p,h),s.dtheta=w(a),s.dphi=w(i),b=w(b);for(var o=s.theta,u=s.phi,c=Math.exp(s.distance),l=c*Math.sin(o)*Math.cos(u),v=c*Math.cos(o)*Math.cos(u),g=c*Math.sin(u),y=0;y<3;++y)r[y]=t[y]+l*m[y]+v*d[y]+g*n[y];f(s.view,r,t,n)}(e),_(t),s.dirty=!1)}return Object.keys(s).forEach(function(e){A[e]=s[e]}),A};var u="undefined"!=typeof window},function(e,t,r){"use strict";e.exports=function(e,t){t||(t=e,e=window);var r=0,a=0,i=0,o={shift:!1,alt:!1,control:!1,meta:!1},f=!1;function u(e){var t=!1;return"altKey"in e&&(t=t||e.altKey!==o.alt,o.alt=!!e.altKey),"shiftKey"in e&&(t=t||e.shiftKey!==o.shift,o.shift=!!e.shiftKey),"ctrlKey"in e&&(t=t||e.ctrlKey!==o.control,o.control=!!e.ctrlKey),"metaKey"in e&&(t=t||e.metaKey!==o.meta,o.meta=!!e.metaKey),t}function s(e,f){var s=n.x(f),c=n.y(f);"buttons"in f&&(e=0|f.buttons),(e!==r||s!==a||c!==i||u(f))&&(r=0|e,a=s||0,i=c||0,t&&t(r,a,i,o))}function c(e){s(0,e)}function l(){(r||a||i||o.shift||o.alt||o.meta||o.control)&&(a=i=0,r=0,o.shift=o.alt=o.control=o.meta=!1,t&&t(0,0,0,o))}function d(e){u(e)&&t&&t(r,a,i,o)}function m(e){0===n.buttons(e)?s(0,e):s(r,e)}function p(e){s(r|n.buttons(e),e)}function h(e){s(r&~n.buttons(e),e)}function b(){f||(f=!0,e.addEventListener("mousemove",m),e.addEventListener("mousedown",p),e.addEventListener("mouseup",h),e.addEventListener("mouseleave",c),e.addEventListener("mouseenter",c),e.addEventListener("mouseout",c),e.addEventListener("mouseover",c),e.addEventListener("blur",l),e.addEventListener("keyup",d),e.addEventListener("keydown",d),e.addEventListener("keypress",d),e!==window&&(window.addEventListener("blur",l),window.addEventListener("keyup",d),window.addEventListener("keydown",d),window.addEventListener("keypress",d)))}b();var v={element:e};return Object.defineProperties(v,{enabled:{get:function(){return f},set:function(t){t?b():f&&(f=!1,e.removeEventListener("mousemove",m),e.removeEventListener("mousedown",p),e.removeEventListener("mouseup",h),e.removeEventListener("mouseleave",c),e.removeEventListener("mouseenter",c),e.removeEventListener("mouseout",c),e.removeEventListener("mouseover",c),e.removeEventListener("blur",l),e.removeEventListener("keyup",d),e.removeEventListener("keydown",d),e.removeEventListener("keypress",d),e!==window&&(window.removeEventListener("blur",l),window.removeEventListener("keyup",d),window.removeEventListener("keydown",d),window.removeEventListener("keypress",d)))},enumerable:!0},buttons:{get:function(){return r},enumerable:!0},x:{get:function(){return a},enumerable:!0},y:{get:function(){return i},enumerable:!0},mods:{get:function(){return o},enumerable:!0}}),v};var n=r(20)},function(e,t,r){"use strict";function n(e){return e.target||e.srcElement||window}t.buttons=function(e){if("object"==typeof e){if("buttons"in e)return e.buttons;if("which"in e){if(2===(t=e.which))return 4;if(3===t)return 2;if(t>0)return 1<=0)return 1<