!function e(t,n,r){function a(o,f){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!f&&u)return u(o,!0);if(i)return i(o,!0);var s=new Error("Cannot find module '"+o+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return a(n?n:e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o0&&void 0!==arguments[0]?arguments[0]:{},a=Object.assign({onDone:function(r){if("function"==typeof n.onDone&&n.onDone.apply(e,t),r){var a=document.createElement("div");document.body.appendChild(a),a.className="error";var i=document.createElement("div");i.innerText=r,a.appendChild(i)}}},n);return"function"==typeof headlessRegl?a=headlessRegl(a):window.frameDone=function(){},r(a)}},{31:31}],5:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],f=t[5],u=t[6],s=t[7],c=t[8],l=t[9],m=t[10],d=t[11],p=t[12],h=t[13],v=t[14],b=t[15];return e[0]=f*(m*b-d*v)-l*(u*b-s*v)+h*(u*d-s*m),e[1]=-(r*(m*b-d*v)-l*(a*b-i*v)+h*(a*d-i*m)),e[2]=r*(u*b-s*v)-f*(a*b-i*v)+h*(a*s-i*u),e[3]=-(r*(u*d-s*m)-f*(a*d-i*m)+l*(a*s-i*u)),e[4]=-(o*(m*b-d*v)-c*(u*b-s*v)+p*(u*d-s*m)),e[5]=n*(m*b-d*v)-c*(a*b-i*v)+p*(a*d-i*m),e[6]=-(n*(u*b-s*v)-o*(a*b-i*v)+p*(a*s-i*u)),e[7]=n*(u*d-s*m)-o*(a*d-i*m)+c*(a*s-i*u),e[8]=o*(l*b-d*h)-c*(f*b-s*h)+p*(f*d-s*l),e[9]=-(n*(l*b-d*h)-c*(r*b-i*h)+p*(r*d-i*l)),e[10]=n*(f*b-s*h)-o*(r*b-i*h)+p*(r*s-i*f),e[11]=-(n*(f*d-s*l)-o*(r*d-i*l)+c*(r*s-i*f)),e[12]=-(o*(l*v-m*h)-c*(f*v-u*h)+p*(f*m-u*l)),e[13]=n*(l*v-m*h)-c*(r*v-a*h)+p*(r*m-a*l),e[14]=-(n*(f*v-u*h)-o*(r*v-a*h)+p*(r*u-a*f)),e[15]=n*(f*m-u*l)-o*(r*m-a*l)+c*(r*u-a*f),e}t.exports=r},{}],6:[function(e,t,n){function r(e){var t=new Float32Array(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}t.exports=r},{}],7:[function(e,t,n){function r(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}t.exports=r},{}],8:[function(e,t,n){function r(){var e=new Float32Array(16);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}t.exports=r},{}],9:[function(e,t,n){function r(e){var t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],o=e[5],f=e[6],u=e[7],s=e[8],c=e[9],l=e[10],m=e[11],d=e[12],p=e[13],h=e[14],v=e[15],b=t*o-n*i,g=t*f-r*i,y=t*u-a*i,x=n*f-r*o,w=n*u-a*o,k=r*u-a*f,S=s*p-c*d,_=s*h-l*d,A=s*v-m*d,E=c*h-l*p,D=c*v-m*p,T=l*v-m*h;return b*T-g*D+y*E+x*A-w*_+k*S}t.exports=r},{}],10:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n+n,f=r+r,u=a+a,s=n*o,c=r*o,l=r*f,m=a*o,d=a*f,p=a*u,h=i*o,v=i*f,b=i*u;return e[0]=1-l-p,e[1]=c+b,e[2]=m-v,e[3]=0,e[4]=c-b,e[5]=1-s-p,e[6]=d+h,e[7]=0,e[8]=m+v,e[9]=d-h,e[10]=1-s-l,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}t.exports=r},{}],11:[function(e,t,n){function r(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],f=r+r,u=a+a,s=i+i,c=r*f,l=r*u,m=r*s,d=a*u,p=a*s,h=i*s,v=o*f,b=o*u,g=o*s;return e[0]=1-(d+h),e[1]=l+g,e[2]=m-b,e[3]=0,e[4]=l-g,e[5]=1-(c+h),e[6]=p+v,e[7]=0,e[8]=m+b,e[9]=p-v,e[10]=1-(c+d),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}t.exports=r},{}],12:[function(e,t,n){function r(e,t,n,r,a,i,o){var f=1/(n-t),u=1/(a-r),s=1/(i-o);return e[0]=2*i*f,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=2*i*u,e[6]=0,e[7]=0,e[8]=(n+t)*f,e[9]=(a+r)*u,e[10]=(o+i)*s,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*i*2*s,e[15]=0,e}t.exports=r},{}],13:[function(e,t,n){function r(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}t.exports=r},{}],14:[function(e,t,n){t.exports={create:e(8),clone:e(6),copy:e(7),identity:e(13),transpose:e(28),invert:e(15),adjoint:e(5),determinant:e(9),multiply:e(17),translate:e(27),scale:e(25),rotate:e(21),rotateX:e(22),rotateY:e(23),rotateZ:e(24),fromRotationTranslation:e(11),fromQuat:e(10),frustum:e(12),perspective:e(19),perspectiveFromFieldOfView:e(20),ortho:e(18),lookAt:e(16),str:e(26)}},{10:10,11:11,12:12,13:13,15:15,16:16,17:17,18:18,19:19,20:20,21:21,22:22,23:23,24:24,25:25,26:26,27:27,28:28,5:5,6:6,7:7,8:8,9:9}],15:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],f=t[5],u=t[6],s=t[7],c=t[8],l=t[9],m=t[10],d=t[11],p=t[12],h=t[13],v=t[14],b=t[15],g=n*f-r*o,y=n*u-a*o,x=n*s-i*o,w=r*u-a*f,k=r*s-i*f,S=a*s-i*u,_=c*h-l*p,A=c*v-m*p,E=c*b-d*p,D=l*v-m*h,T=l*b-d*h,j=m*b-d*v,C=g*j-y*T+x*D+w*E-k*A+S*_;return C?(C=1/C,e[0]=(f*j-u*T+s*D)*C,e[1]=(a*T-r*j-i*D)*C,e[2]=(h*S-v*k+b*w)*C,e[3]=(m*k-l*S-d*w)*C,e[4]=(u*E-o*j-s*A)*C,e[5]=(n*j-a*E+i*A)*C,e[6]=(v*x-p*S-b*y)*C,e[7]=(c*S-m*x+d*y)*C,e[8]=(o*T-f*E+s*_)*C,e[9]=(r*E-n*T-i*_)*C,e[10]=(p*k-h*x+b*g)*C,e[11]=(l*x-c*k-d*g)*C,e[12]=(f*A-o*D-u*_)*C,e[13]=(n*D-r*A+a*_)*C,e[14]=(h*y-p*w-v*g)*C,e[15]=(c*w-l*y+m*g)*C,e):null}t.exports=r},{}],16:[function(e,t,n){function r(e,t,n,r){var i,o,f,u,s,c,l,m,d,p,h=t[0],v=t[1],b=t[2],g=r[0],y=r[1],x=r[2],w=n[0],k=n[1],S=n[2];return Math.abs(h-w)<1e-6&&Math.abs(v-k)<1e-6&&Math.abs(b-S)<1e-6?a(e):(l=h-w,m=v-k,d=b-S,p=1/Math.sqrt(l*l+m*m+d*d),l*=p,m*=p,d*=p,i=y*d-x*m,o=x*l-g*d,f=g*m-y*l,p=Math.sqrt(i*i+o*o+f*f),p?(p=1/p,i*=p,o*=p,f*=p):(i=0,o=0,f=0),u=m*f-d*o,s=d*i-l*f,c=l*o-m*i,p=Math.sqrt(u*u+s*s+c*c),p?(p=1/p,u*=p,s*=p,c*=p):(u=0,s=0,c=0),e[0]=i,e[1]=u,e[2]=l,e[3]=0,e[4]=o,e[5]=s,e[6]=m,e[7]=0,e[8]=f,e[9]=c,e[10]=d,e[11]=0,e[12]=-(i*h+o*v+f*b),e[13]=-(u*h+s*v+c*b),e[14]=-(l*h+m*v+d*b),e[15]=1,e)}var a=e(13);t.exports=r},{13:13}],17:[function(e,t,n){function r(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],f=t[4],u=t[5],s=t[6],c=t[7],l=t[8],m=t[9],d=t[10],p=t[11],h=t[12],v=t[13],b=t[14],g=t[15],y=n[0],x=n[1],w=n[2],k=n[3];return e[0]=y*r+x*f+w*l+k*h,e[1]=y*a+x*u+w*m+k*v,e[2]=y*i+x*s+w*d+k*b,e[3]=y*o+x*c+w*p+k*g,y=n[4],x=n[5],w=n[6],k=n[7],e[4]=y*r+x*f+w*l+k*h,e[5]=y*a+x*u+w*m+k*v,e[6]=y*i+x*s+w*d+k*b,e[7]=y*o+x*c+w*p+k*g,y=n[8],x=n[9],w=n[10],k=n[11],e[8]=y*r+x*f+w*l+k*h,e[9]=y*a+x*u+w*m+k*v,e[10]=y*i+x*s+w*d+k*b,e[11]=y*o+x*c+w*p+k*g,y=n[12],x=n[13],w=n[14],k=n[15],e[12]=y*r+x*f+w*l+k*h,e[13]=y*a+x*u+w*m+k*v,e[14]=y*i+x*s+w*d+k*b,e[15]=y*o+x*c+w*p+k*g,e}t.exports=r},{}],18:[function(e,t,n){function r(e,t,n,r,a,i,o){var f=1/(t-n),u=1/(r-a),s=1/(i-o);return e[0]=-2*f,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*u,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*s,e[11]=0,e[12]=(t+n)*f,e[13]=(a+r)*u,e[14]=(o+i)*s,e[15]=1,e}t.exports=r},{}],19:[function(e,t,n){function r(e,t,n,r,a){var i=1/Math.tan(t/2),o=1/(r-a);return e[0]=i/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(a+r)*o,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*a*r*o,e[15]=0,e}t.exports=r},{}],20:[function(e,t,n){function r(e,t,n,r){var a=Math.tan(t.upDegrees*Math.PI/180),i=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),f=Math.tan(t.rightDegrees*Math.PI/180),u=2/(o+f),s=2/(a+i);return e[0]=u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=-((o-f)*u*.5),e[9]=(a-i)*s*.5,e[10]=r/(n-r),e[11]=-1,e[12]=0,e[13]=0,e[14]=r*n/(n-r),e[15]=0,e}t.exports=r},{}],21:[function(e,t,n){function r(e,t,n,r){var a,i,o,f,u,s,c,l,m,d,p,h,v,b,g,y,x,w,k,S,_,A,E,D,T=r[0],j=r[1],C=r[2],O=Math.sqrt(T*T+j*j+C*C);return Math.abs(O)<1e-6?null:(O=1/O,T*=O,j*=O,C*=O,a=Math.sin(n),i=Math.cos(n),o=1-i,f=t[0],u=t[1],s=t[2],c=t[3],l=t[4],m=t[5],d=t[6],p=t[7],h=t[8],v=t[9],b=t[10],g=t[11],y=T*T*o+i,x=j*T*o+C*a,w=C*T*o-j*a,k=T*j*o-C*a,S=j*j*o+i,_=C*j*o+T*a,A=T*C*o+j*a,E=j*C*o-T*a,D=C*C*o+i,e[0]=f*y+l*x+h*w,e[1]=u*y+m*x+v*w,e[2]=s*y+d*x+b*w,e[3]=c*y+p*x+g*w,e[4]=f*k+l*S+h*_,e[5]=u*k+m*S+v*_,e[6]=s*k+d*S+b*_,e[7]=c*k+p*S+g*_,e[8]=f*A+l*E+h*D,e[9]=u*A+m*E+v*D,e[10]=s*A+d*E+b*D,e[11]=c*A+p*E+g*D,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}t.exports=r},{}],22:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[4],o=t[5],f=t[6],u=t[7],s=t[8],c=t[9],l=t[10],m=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*a+s*r,e[5]=o*a+c*r,e[6]=f*a+l*r,e[7]=u*a+m*r,e[8]=s*a-i*r,e[9]=c*a-o*r,e[10]=l*a-f*r,e[11]=m*a-u*r,e}t.exports=r},{}],23:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[0],o=t[1],f=t[2],u=t[3],s=t[8],c=t[9],l=t[10],m=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*a-s*r,e[1]=o*a-c*r,e[2]=f*a-l*r,e[3]=u*a-m*r,e[8]=i*r+s*a,e[9]=o*r+c*a,e[10]=f*r+l*a,e[11]=u*r+m*a,e}t.exports=r},{}],24:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[0],o=t[1],f=t[2],u=t[3],s=t[4],c=t[5],l=t[6],m=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*a+s*r,e[1]=o*a+c*r,e[2]=f*a+l*r,e[3]=u*a+m*r,e[4]=s*a-i*r,e[5]=c*a-o*r,e[6]=l*a-f*r,e[7]=m*a-u*r,e}t.exports=r},{}],25:[function(e,t,n){function r(e,t,n){var r=n[0],a=n[1],i=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*a,e[5]=t[5]*a,e[6]=t[6]*a,e[7]=t[7]*a,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}t.exports=r},{}],26:[function(e,t,n){function r(e){return"mat4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+")"}t.exports=r},{}],27:[function(e,t,n){function r(e,t,n){var r,a,i,o,f,u,s,c,l,m,d,p,h=n[0],v=n[1],b=n[2];return t===e?(e[12]=t[0]*h+t[4]*v+t[8]*b+t[12],e[13]=t[1]*h+t[5]*v+t[9]*b+t[13],e[14]=t[2]*h+t[6]*v+t[10]*b+t[14],e[15]=t[3]*h+t[7]*v+t[11]*b+t[15]):(r=t[0],a=t[1],i=t[2],o=t[3],f=t[4],u=t[5],s=t[6],c=t[7],l=t[8],m=t[9],d=t[10],p=t[11],e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=f,e[5]=u,e[6]=s,e[7]=c,e[8]=l,e[9]=m,e[10]=d,e[11]=p,e[12]=r*h+f*v+l*b+t[12],e[13]=a*h+u*v+m*b+t[13],e[14]=i*h+s*v+d*b+t[14],e[15]=o*h+c*v+p*b+t[15]),e}t.exports=r},{}],28:[function(e,t,n){function r(e,t){if(e===t){var n=t[1],r=t[2],a=t[3],i=t[6],o=t[7],f=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=a,e[13]=o,e[14]=f}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}t.exports=r},{}],29:[function(e,t,n){t.exports=function(e){"string"==typeof e&&(e=[e]);for(var t=[].slice.call(arguments,1),n=[],r=0;r=0&&(0|e)===e||t("invalid parameter type, ("+e+")"+r(n)+". must be a nonnegative integer")}function u(e,n,a){n.indexOf(e)<0&&t("invalid value"+r(a)+". must be one of: "+n)}function s(e){Object.keys(e).forEach(function(e){et.indexOf(e)<0&&t('invalid regl constructor argument "'+e+'". must be one of '+et)})}function c(e,t){for(e+="";e.length0&&t.push(new d("unknown",0,e))}}),t}function g(e,t){t.forEach(function(t){var n=e[t.file];if(n){var r=n.index[t.line];if(r)return r.errors.push(t),void(n.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)})}function y(e,t,r,a,i){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var o=e.getShaderInfoLog(t),f=a===e.FRAGMENT_SHADER?"fragment":"vertex";E(r,"string",f+" shader source must be a string",i);var u=v(r,i),s=b(o);g(u,s),Object.keys(u).forEach(function(e){function t(e,t){r.push(e),a.push(t||"")}var n=u[e];if(n.hasErrors){var r=[""],a=[""];t("file number "+e+": "+n.name+"\n","color:red;text-decoration:underline;font-weight:bold"),n.lines.forEach(function(e){if(e.errors.length>0){t(c(e.number,4)+"| ","background-color:yellow; font-weight:bold"),t(e.line+"\n","color:red; background-color:yellow; font-weight:bold");var n=0;e.errors.forEach(function(r){var a=r.message,i=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(a);if(i){var o=i[1];switch(a=i[2],o){case"assign":o="="}n=Math.max(e.line.indexOf(o,n),0)}else n=0;t(c("| ",6)),t(c("^^^",n+3)+"\n","font-weight:bold"),t(c("| ",6)),t(a+"\n","font-weight:bold")}),t(c("| ",6)+"\n")}else t(c(e.number,4)+"| "),t(e.line+"\n","color:red")}),"undefined"!=typeof document?(a[0]=r.join("%c"),console.log.apply(console,a)):console.log(r.join(""))}}),n.raise("Error compiling "+f+" shader, "+u[0].name)}}function x(e,t,r,a,i){if(!e.getProgramParameter(t,e.LINK_STATUS)){var o=e.getProgramInfoLog(t),f=v(r,i),u=v(a,i),s='Error linking program with vertex shader, "'+u[0].name+'", and fragment shader "'+f[0].name+'"';"undefined"!=typeof document?console.log("%c"+s+"\n%c"+o,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(s+"\n"+o),n.raise(s)}}function w(e){e._commandRef=p()}function k(e,t,n,r){function a(e){return e?r.id(e):0}function i(e,t){Object.keys(t).forEach(function(t){e[r.id(t)]=!0})}w(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,n.static),i(f,n.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic}function S(e,n){var r=h();t(e+" in command "+(n||p())+("unknown"===r?"":" called from "+r))}function _(e,t,n){e||S(t,n||p())}function A(e,t,n,a){e in t||S("unknown parameter ("+e+")"+r(n)+". possible values: "+Object.keys(t).join(),a||p())}function E(e,t,n,a){typeof e!==t&&S("invalid parameter type"+r(n)+". expected "+t+", got "+typeof e,a||p())}function D(e){e()}function T(e,t,n){e.texture?u(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):u(e.renderbuffer._renderbuffer.format,n,"unsupported renderbuffer format for attachment")}function j(e,t){return e===ht||e===pt||e===vt?2:e===bt?4:yt[e]*t}function C(e){return!(e&e-1||!e)}function O(e,t,r){var a,i=t.width,o=t.height,f=t.channels;n(i>0&&i<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),e.wrapS===tt&&e.wrapT===tt||n(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&&n(e.minFilter!==rt&&e.minFilter!==it&&e.minFilter!==at&&e.minFilter!==ot,"min filter requires mipmap"):(n(C(i)&&C(o),"texture must be a square power of 2 to support mipmapping"),n(t.mipmask===(i<<1)-1,"missing or incomplete mipmap data")),t.type===dt&&(r.extensions.indexOf("oes_texture_float_linear")<0&&n(e.minFilter===nt&&e.magFilter===nt,"filter not supported, must enable oes_texture_float_linear"),n(!e.genMipmaps,"mipmap generation not supported with float textures"));var u=t.images;for(a=0;a<16;++a)if(u[a]){var s=i>>a,c=o>>a;n(t.mipmask&1<0&&i<=a.maxTextureSize&&o>0&&o<=a.maxTextureSize,"invalid texture shape"),n(i===o,"cube map must be square"),n(t.wrapS===tt&&t.wrapT===tt,"wrap mode not supported by cube map");for(var u=0;u>l,p=o>>l;n(s.mipmask&1<1&&t===n&&('"'===t||"'"===t))return['"'+M(e.substr(1,e.length-2))+'"'];var r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e);if(r)return P(e.substr(0,r.index)).concat(P(r[1])).concat(P(e.substr(r.index+r[0].length)));var a=e.split(".");if(1===a.length)return['"'+M(e)+'"'];for(var i=[],o=0;o0,"invalid pixel ratio"))):xt.raise("invalid arguments to regl"),t&&("canvas"===t.nodeName.toLowerCase()?r=t:n=t),!a){if(!r){xt("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var d=U(n||document.body,l,s);if(!d)return null;r=d.canvas,m=d.onDestroy}a=q(r,o)}return a?{gl:a,canvas:r,container:n,extensions:f,optionalExtensions:u,pixelRatio:s,profile:c,onDone:l,onDestroy:m}:(m(),l("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function Y(e,t){function n(t){xt.type(t,"string","extension name must be string");var n,a=t.toLowerCase();try{n=r[a]=e.getExtension(a)}catch(e){}return!!n}for(var r={},a=0;a65535)<<4,e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1}function Z(e){var t=K(e),n=sn[J(t)>>2];return n.length>0?n.pop():new ArrayBuffer(t)}function ee(e){sn[J(e.byteLength)>>2].push(e)}function te(e,t){var n=null;switch(e){case tn:n=new Int8Array(Z(t),0,t);break;case nn:n=new Uint8Array(Z(t),0,t);break;case rn:n=new Int16Array(Z(2*t),0,t);break;case an:n=new Uint16Array(Z(2*t),0,t);break;case on:n=new Int32Array(Z(4*t),0,t);break;case fn:n=new Uint32Array(Z(4*t),0,t);break;case un:n=new Float32Array(Z(4*t),0,t);break;default:return null}return n.length!==t?n.subarray(0,t):n}function ne(e){ee(e.buffer)}function re(e,t,n){for(var r=0;r0){var u;if(Array.isArray(t[0])){f=An(t);for(var s=1,c=1;c0)if("number"==typeof e[0]){var a=cn.allocType(p.dtype,e.length);ce(a,e),l(a,r),cn.freeType(a)}else if(Array.isArray(e[0])||Je(e[0])){n=An(e);var i=_n(e,n,p.dtype);l(i,r),cn.freeType(i)}else xt.raise("invalid buffer data")}else if(Je(e))l(e,r);else if(X(e)){n=e.shape;var o=e.stride,f=0,u=0,s=0,m=0;1===n.length?(f=n[0],u=1,s=o[0],m=0):2===n.length?(f=n[0],u=n[1],s=o[0],m=o[1]):xt.raise("invalid shape");var d=Array.isArray(e.data)?p.dtype:se(e.data),h=cn.allocType(d,f*u);le(h,e.data,f,u,s,m,e.offset),l(h,r),cn.freeType(h)}else xt.raise("invalid data for buffer subdata");return c}t.bufferCount++;var p=new r(i);return m[p.id]=p,o||c(a),c._reglType="buffer",c._buffer=p,c.subdata=d,n.profile&&(c.stats=p.stats),c.destroy=function(){u(p)},c}function c(){en(m).forEach(function(t){t.buffer=e.createBuffer(),e.bindBuffer(t.type,t.buffer),e.bufferData(t.type,t.persistentData||t.byteLength,t.usage)})}var l=0,m={};r.prototype.bind=function(){e.bindBuffer(this.type,this.buffer)},r.prototype.destroy=function(){u(this)};var d=[];return n.profile&&(t.getTotalBufferSize=function(){var e=0;return Object.keys(m).forEach(function(t){e+=m[t].stats.size}),e}),{create:s,createStream:a,destroyStream:i,clear:function(){en(m).forEach(u),d.forEach(u)},getBuffer:function(e){return e&&e._buffer instanceof r?e._buffer:null},restore:c,_initBuffer:f}}function de(e,t,n,r){function a(e){this.id=l++,c[this.id]=this,this.buffer=e,this.primType=Nn,this.vertCount=0,this.type=0}function i(e){var t=d.pop();return t||(t=new a(n.create(null,Vn,!0,!1)._buffer)),f(t,e,Yn,-1,-1,0,0),t}function o(e){d.push(e)}function f(r,a,i,o,f,u,s){if(r.buffer.bind(),a){var c=s;s||Je(a)&&(!X(a)||Je(a.data))||(c=t.oes_element_index_uint?Qn:Gn),n._initBuffer(r.buffer,a,i,c,3)}else e.bufferData(Vn,u,i),r.buffer.dtype=l||qn,r.buffer.usage=i,r.buffer.dimension=3,r.buffer.byteLength=u;var l=s;if(!s){switch(r.buffer.dtype){case qn:case Un:l=qn;break;case Gn:case Wn:l=Gn;break;case Qn:case Hn:l=Qn;break;default:xt.raise("unsupported type for element array")}r.buffer.dtype=l}r.type=l,xt(l!==Qn||!!t.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var m=f;m<0&&(m=r.buffer.byteLength,l===Gn?m>>=1:l===Qn&&(m>>=2)),r.vertCount=m;var d=o;if(o<0){d=Nn;var p=r.buffer.dimension;1===p&&(d=Bn),2===p&&(d=Rn),3===p&&(d=Nn)}r.primType=d}function u(e){r.elementsCount--,xt(null!==e.buffer,"must not double destroy elements"),delete c[e.id],e.buffer.destroy(),e.buffer=null}function s(e,t){function i(e){if(e)if("number"==typeof e)o(e),s.primType=Nn,s.vertCount=0|e,s.type=qn;else{var t=null,n=Xn,r=-1,a=-1,u=0,c=0;Array.isArray(e)||Je(e)||X(e)?t=e:(xt.type(e,"object","invalid arguments for elements"),"data"in e&&(t=e.data,xt(Array.isArray(t)||Je(t)||X(t),"invalid data for element buffer")),"usage"in e&&(xt.parameter(e.usage,Sn,"invalid element buffer usage"),n=Sn[e.usage]),"primitive"in e&&(xt.parameter(e.primitive,Ln,"invalid element buffer primitive"),r=Ln[e.primitive]),"count"in e&&(xt("number"==typeof e.count&&e.count>=0,"invalid vertex count for elements"),a=0|e.count),"type"in e&&(xt.parameter(e.type,m,"invalid buffer type"),c=m[e.type]),"length"in e?u=0|e.length:(u=a,c===Gn||c===Wn?u*=2:c!==Qn&&c!==Hn||(u*=4))),f(s,t,n,r,a,u,c)}else o(),s.primType=Nn,s.vertCount=0,s.type=qn;return i}var o=n.create(null,Vn,!0),s=new a(o._buffer);return r.elementsCount++,i(e),i._reglType="elements",i._elements=s,i.subdata=function(e,t){return o.subdata(e,t),i},i.destroy=function(){u(s)},i}var c={},l=0,m={uint8:qn,uint16:Gn};t.oes_element_index_uint&&(m.uint32=Qn),a.prototype.bind=function(){this.buffer.bind()};var d=[];return{create:s,createStream:i,destroyStream:o,getElements:function(e){return"function"==typeof e&&e._elements instanceof a?e._elements:null},clear:function(){en(c).forEach(u)}}}function pe(e){for(var t=cn.allocType(Jn,e.length),n=0;n>>31<<15,i=(r<<1>>>24)-127,o=r>>13&1023;if(i<-24)t[n]=a;else if(i<-14){var f=-14-i;t[n]=a+(o+1024>>f)}else i>15?t[n]=a+31744:t[n]=a+(i+15<<10)+o}return t}function he(e){return Array.isArray(e)||Je(e)}function ve(e){return"[object "+e+"]"}function be(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function ge(e){if(!Array.isArray(e))return!1;var t=e.length;return!(0===t||!he(e[0]))}function ye(e){return Object.prototype.toString.call(e)}function xe(e){return ye(e)===sa}function we(e){return ye(e)===ca}function ke(e){return ye(e)===la}function Se(e){return ye(e)===ma}function _e(e){if(!e)return!1;var t=ye(e);return da.indexOf(t)>=0||(be(e)||ge(e)||X(e))}function Ae(e){return 0|Ke[Object.prototype.toString.call(e)]}function Ee(e,t){var n=t.length;switch(e.type){case zr:case Fr:case Mr:case Pr:var r=cn.allocType(e.type,n);r.set(t),e.data=r;break;case yr:e.data=pe(t);break;default:xt.raise("unsupported texture type, must specify a typed array")}}function De(e,t){return cn.allocType(e.type===yr?Pr:e.type,t)}function Te(e,t){e.type===yr?(e.data=pe(t),cn.freeType(t)):e.data=t}function je(e,t,n,r,a,i){for(var o=e.width,f=e.height,u=e.channels,s=o*f*u,c=De(e,s),l=0,m=0;m=1;)f+=o*u*u,u/=2;return f}return o*n*r}function Oe(e,t,n,r,a,i,o){function f(){this.internalformat=rr,this.format=rr,this.type=zr,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=0,this.width=0,this.height=0,this.channels=0}function u(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 s(e,r){if("object"==typeof r&&r){if("premultiplyAlpha"in r&&(xt.type(r.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=r.premultiplyAlpha),"flipY"in r&&(xt.type(r.flipY,"boolean","invalid texture flip"),e.flipY=r.flipY),"alignment"in r&&(xt.oneOf(r.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=r.alignment),"colorSpace"in r&&(xt.parameter(r.colorSpace,B,"invalid colorSpace"),e.colorSpace=B[r.colorSpace]),"type"in r){var a=r.type;xt(t.oes_texture_float||!("float"===a||"float32"===a),"you must enable the OES_texture_float extension in order to use floating point textures."),xt(t.oes_texture_half_float||!("half float"===a||"float16"===a),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),xt(t.webgl_depth_texture||!("uint16"===a||"uint32"===a||"depth stencil"===a),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),xt.parameter(a,R,"invalid texture type"),e.type=R[a]}var i=e.width,o=e.height,f=e.channels,u=!1;"shape"in r?(xt(Array.isArray(r.shape)&&r.shape.length>=2,"shape must be an array"),i=r.shape[0],o=r.shape[1],3===r.shape.length&&(f=r.shape[2],xt(f>0&&f<=4,"invalid number of channels"),u=!0),xt(i>=0&&i<=n.maxTextureSize,"invalid width"),xt(o>=0&&o<=n.maxTextureSize,"invalid height")):("radius"in r&&(i=o=r.radius,xt(i>=0&&i<=n.maxTextureSize,"invalid radius")),"width"in r&&(i=r.width,xt(i>=0&&i<=n.maxTextureSize,"invalid width")),"height"in r&&(o=r.height,xt(o>=0&&o<=n.maxTextureSize,"invalid height")),"channels"in r&&(f=r.channels,xt(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 r){var c=r.format;xt(t.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),xt.parameter(c,N,"invalid texture format");var l=e.internalformat=N[c];e.format=$[l],c in R&&("type"in r||(e.type=R[c])),c in U&&(e.compressed=!0),s=!0}!u&&s?e.channels=ua[e.format]:u&&!s?e.channels!==fa[e.format]&&(e.format=e.internalformat=fa[e.channels]):s&&u&&xt(e.channels===ua[e.format],"number of channels inconsistent with specified format")}}function c(t){e.pixelStorei(ta,t.flipY),e.pixelStorei(na,t.premultiplyAlpha),e.pixelStorei(ra,t.colorSpace),e.pixelStorei(ea,t.unpackAlignment)}function l(){f.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function m(e,t){var r=null;if(_e(t)?r=t:t&&(xt.type(t,"object","invalid pixel data type"),s(e,t),"x"in t&&(e.xOffset=0|t.x),"y"in t&&(e.yOffset=0|t.y),_e(t.data)&&(r=t.data)),xt(!e.compressed||r instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),t.copy){xt(!r,"can not specify copy and data field for the same texture");var i=a.viewportWidth,o=a.viewportHeight;e.width=e.width||i-e.xOffset,e.height=e.height||o-e.yOffset,e.needsCopy=!0,xt(e.xOffset>=0&&e.xOffset=0&&e.yOffset0&&e.width<=i&&e.height>0&&e.height<=o,"copy texture read out of bounds")}else if(r){if(Je(r))e.channels=e.channels||4,e.data=r,"type"in t||e.type!==zr||(e.type=Ae(r));else if(be(r))e.channels=e.channels||4,Ee(e,r),e.alignment=1,e.needsFree=!0;else if(X(r)){var f=r.data;Array.isArray(f)||e.type!==zr||(e.type=Ae(f));var u,c,l,m,d,p,h=r.shape,v=r.stride;3===h.length?(l=h[2],p=v[2]):(xt(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,p=1),u=h[0],c=h[1],m=v[0],d=v[1],e.alignment=1,e.width=u,e.height=c,e.channels=l,e.format=e.internalformat=fa[l],e.needsFree=!0,je(e,f,m,d,p,r.offset)}else if(xe(r)||we(r))xe(r)?e.element=r:e.element=r.canvas,e.width=e.element.width,e.height=e.element.height,e.channels=4;else if(ke(r))e.element=r,e.width=r.naturalWidth,e.height=r.naturalHeight,e.channels=4;else if(Se(r))e.element=r,e.width=r.videoWidth,e.height=r.videoHeight,e.channels=4;else if(ge(r)){var b=e.width||r[0].length,g=e.height||r.length,y=e.channels;y=he(r[0][0])?y||r[0][0].length:y||1;for(var x=ln.shape(r),w=1,k=0;k=0,"oes_texture_float extension not enabled"):e.type===yr&&xt(n.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function d(t,n,a){var i=t.element,o=t.data,f=t.internalformat,u=t.format,s=t.type,l=t.width,m=t.height;c(t),i?e.texImage2D(n,a,u,u,s,i):t.compressed?e.compressedTexImage2D(n,a,f,l,m,0,o):t.needsCopy?(r(),e.copyTexImage2D(n,a,u,t.xOffset,t.yOffset,l,m,0)):e.texImage2D(n,a,u,l,m,0,u,s,o)}function p(t,n,a,i,o){var f=t.element,u=t.data,s=t.internalformat,l=t.format,m=t.type,d=t.width,p=t.height;c(t),f?e.texSubImage2D(n,o,a,i,l,m,f):t.compressed?e.compressedTexSubImage2D(n,o,a,i,s,d,p,u):t.needsCopy?(r(),e.copyTexSubImage2D(n,o,a,i,t.xOffset,t.yOffset,d,p)):e.texSubImage2D(n,o,a,i,d,p,l,m,u)}function h(){return K.pop()||new l}function v(e){e.needsFree&&cn.freeType(e.data),l.call(e),K.push(e)}function b(){f.call(this),this.genMipmaps=!1,this.mipmapHint=$r,this.mipmask=0,this.images=Array(16)}function g(e,t,n){var r=e.images[0]=h();e.mipmask=1,r.width=e.width=t,r.height=e.height=n,r.channels=e.channels=4}function y(e,t){var n=null;if(_e(t))n=e.images[0]=h(),u(n,e),m(n,t),e.mipmask=1;else if(s(e,t),Array.isArray(t.mipmap))for(var r=t.mipmap,a=0;a>=a,n.height>>=a,m(n,r[a]),e.mipmask|=1<=0&&(e.genMipmaps=!0)}if("mag"in t){var a=t.mag;xt.parameter(a,I),e.magFilter=I[a]}var i=e.wrapS,o=e.wrapT;if("wrap"in t){var f=t.wrap;"string"==typeof f?(xt.parameter(f,P),i=o=P[f]):Array.isArray(f)&&(xt.parameter(f[0],P),xt.parameter(f[1],P),i=P[f[0]],o=P[f[1]])}else{if("wrapS"in t){var u=t.wrapS;xt.parameter(u,P),i=P[u]}if("wrapT"in t){var s=t.wrapT;xt.parameter(s,P),o=P[s]}}if(e.wrapS=i,e.wrapT=o,"anisotropic"in t){var c=t.anisotropic;xt("number"==typeof c&&c>=1&&c<=n.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var l=!1;switch(typeof t.mipmap){case"string":xt.parameter(t.mipmap,M,"invalid mipmap hint"),e.mipmapHint=M[t.mipmap],e.genMipmaps=!0,l=!0;break;case"boolean":l=e.genMipmaps=t.mipmap;break;case"object":xt(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,l=!0;break;default:xt.raise("invalid mipmap type")}!l||"min"in t||(e.minFilter=Hr)}}function A(n,r){e.texParameteri(r,qr,n.minFilter),e.texParameteri(r,Ur,n.magFilter),e.texParameteri(r,Ir,n.wrapS),e.texParameteri(r,Lr,n.wrapT),t.ext_texture_filter_anisotropic&&e.texParameteri(r,Zr,n.anisotropic),n.genMipmaps&&(e.hint(Xr,n.mipmapHint),e.generateMipmap(r))}function E(t){f.call(this),this.mipmask=0,this.internalformat=rr,this.id=Z++,this.refCount=1,this.target=t,this.texture=e.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new S,o.profile&&(this.stats={size:0})}function D(t){e.activeTexture(ia),e.bindTexture(t.target,t.texture)}function T(){var t=ne[0];t?e.bindTexture(t.target,t.texture):e.bindTexture(er,null)}function j(t){var n=t.texture;xt(n,"must not double destroy texture");var r=t.unit,a=t.target;r>=0&&(e.activeTexture(ia+r),e.bindTexture(a,null),ne[r]=null),e.deleteTexture(n),t.texture=null,t.params=null,t.pixels=null,t.refCount=0,delete ee[t.id],i.textureCount--}function C(t,r){function a(e,t){var r=c.texInfo;S.call(r);var i=w();return"number"==typeof e?"number"==typeof t?g(i,0|e,0|t):g(i,0|e,0|e):e?(xt.type(e,"object","invalid arguments to regl.texture"),_(r,e),y(i,e)):g(i,1,1),r.genMipmaps&&(i.mipmask=(i.width<<1)-1),c.mipmask=i.mipmask,u(c,i),xt.texture2D(r,i,n),c.internalformat=i.internalformat,a.width=i.width,a.height=i.height,D(c),x(i,er),A(r,er),T(),k(i),o.profile&&(c.stats.size=Ce(c.internalformat,c.type,i.width,i.height,r.genMipmaps,!1)),a.format=G[c.internalformat],a.type=H[c.type],a.mag=Q[r.magFilter],a.min=V[r.minFilter],a.wrapS=Y[r.wrapS],a.wrapT=Y[r.wrapT],a}function f(e,t,n,r){xt(!!e,"must specify image data");var i=0|t,o=0|n,f=0|r,s=h();return u(s,c),s.width=0,s.height=0,m(s,e),s.width=s.width||(c.width>>f)-i,s.height=s.height||(c.height>>f)-o,xt(c.type===s.type&&c.format===s.format&&c.internalformat===s.internalformat,"incompatible format for texture.subimage"),xt(i>=0&&o>=0&&i+s.width<=c.width&&o+s.height<=c.height,"texture.subimage write out of bounds"),xt(c.mipmask&1<>f;++f)e.texImage2D(er,f,c.format,r>>f,i>>f,0,c.format,c.type,null);return T(),o.profile&&(c.stats.size=Ce(c.internalformat,c.type,r,i,!1,!1)),a}var c=new E(er);return ee[c.id]=c,i.textureCount++,a(t,r),a.subimage=f,a.resize=s,a._reglType="texture2d",a._texture=c,o.profile&&(a.stats=c.stats),a.destroy=function(){c.decRef()},a}function O(t,r,a,f,c,l){function d(e,t,r,a,i,f){var c,l=C.texInfo;for(S.call(l),c=0;c<6;++c)O[c]=w();if("number"!=typeof e&&e)if("object"==typeof e)if(t)y(O[0],e),y(O[1],t),y(O[2],r),y(O[3],a),y(O[4],i),y(O[5],f);else if(_(l,e),s(C,e),"faces"in e){var m=e.faces;for(xt(Array.isArray(m)&&6===m.length,"cube faces must be a length 6 array"),c=0;c<6;++c)xt("object"==typeof m[c]&&!!m[c],"invalid input for cube map face"),u(O[c],C),y(O[c],m[c])}else for(c=0;c<6;++c)y(O[c],e);else xt.raise("invalid arguments to cube map");else{var p=0|e||1;for(c=0;c<6;++c)g(O[c],p,p)}for(u(C,O[0]),l.genMipmaps?C.mipmask=(O[0].width<<1)-1:C.mipmask=O[0].mipmask,xt.textureCube(C,l,O,n),C.internalformat=O[0].internalformat,d.width=O[0].width,d.height=O[0].height,D(C),c=0;c<6;++c)x(O[c],nr+c);for(A(l,tr),T(),o.profile&&(C.stats.size=Ce(C.internalformat,C.type,d.width,d.height,l.genMipmaps,!0)),d.format=G[C.internalformat],d.type=H[C.type],d.mag=Q[l.magFilter],d.min=V[l.minFilter],d.wrapS=Y[l.wrapS],d.wrapT=Y[l.wrapT],c=0;c<6;++c)k(O[c]);return d}function b(e,t,n,r,a){xt(!!t,"must specify image data"),xt("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var i=0|n,o=0|r,f=0|a,s=h();return u(s,C),s.width=0,s.height=0,m(s,t),s.width=s.width||(C.width>>f)-i,s.height=s.height||(C.height>>f)-o,xt(C.type===s.type&&C.format===s.format&&C.internalformat===s.internalformat,"incompatible format for texture.subimage"),xt(i>=0&&o>=0&&i+s.width<=C.width&&o+s.height<=C.height,"texture.subimage write out of bounds"),xt(C.mipmask&1<>a;++a)e.texImage2D(nr+r,a,C.format,n>>a,n>>a,0,C.format,C.type,null);return T(),o.profile&&(C.stats.size=Ce(C.internalformat,C.type,d.width,d.height,!1,!0)),d}}var C=new E(tr);ee[C.id]=C,i.cubeCount++;var O=new Array(6);return d(t,r,a,f,c,l),d.subimage=b,d.resize=j,d._reglType="textureCube",d._texture=C,o.profile&&(d.stats=C.stats),d.destroy=function(){C.decRef()},d}function z(){for(var t=0;t>n,t.height>>n,0,t.internalformat,t.type,null);else for(var r=0;r<6;++r)e.texImage2D(nr+r,n,t.internalformat,t.width>>n,t.height>>n,0,t.internalformat,t.type,null);A(t.texInfo,t.target)})}var M={"don't care":$r,"dont care":$r,nice:Jr,fast:Kr},P={repeat:Br,clamp:Rr,mirror:Nr},I={nearest:Wr,linear:Gr},L=Ze({mipmap:Yr,"nearest mipmap nearest":Hr,"linear mipmap nearest":Qr,"nearest mipmap linear":Vr,"linear mipmap linear":Yr},I),B={none:0,browser:aa},R={uint8:zr,rgba4:lr,rgb565:dr,"rgb5 a1":mr},N={alpha:ar,luminance:or,"luminance alpha":fr,rgb:ir,rgba:rr,rgba4:ur,"rgb5 a1":sr,rgb565:cr},U={};t.ext_srgb&&(N.srgb=br,N.srgba=gr),t.oes_texture_float&&(R.float32=R.float=Pr),t.oes_texture_half_float&&(R.float16=R["half float"]=yr),t.webgl_depth_texture&&(Ze(N,{depth:hr,"depth stencil":vr}),Ze(R,{uint16:Fr,uint32:Mr,"depth stencil":pr})),t.webgl_compressed_texture_s3tc&&Ze(U,{"rgb s3tc dxt1":xr,"rgba s3tc dxt1":wr,"rgba s3tc dxt3":kr,"rgba s3tc dxt5":Sr}),t.webgl_compressed_texture_atc&&Ze(U,{"rgb atc":_r,"rgba atc explicit alpha":Ar,"rgba atc interpolated alpha":Er}),t.webgl_compressed_texture_pvrtc&&Ze(U,{"rgb pvrtc 4bppv1":Dr,"rgb pvrtc 2bppv1":Tr,"rgba pvrtc 4bppv1":jr,"rgba pvrtc 2bppv1":Cr}),t.webgl_compressed_texture_etc1&&(U["rgb etc1"]=Or);var q=Array.prototype.slice.call(e.getParameter(Zn));Object.keys(U).forEach(function(e){var t=U[e];q.indexOf(t)>=0&&(N[e]=t)});var W=Object.keys(N);n.textureFormats=W;var G=[];Object.keys(N).forEach(function(e){var t=N[e];G[t]=e});var H=[];Object.keys(R).forEach(function(e){var t=R[e];H[t]=e});var Q=[];Object.keys(I).forEach(function(e){var t=I[e];Q[t]=e});var V=[];Object.keys(L).forEach(function(e){var t=L[e];V[t]=e});var Y=[];Object.keys(P).forEach(function(e){var t=P[e];Y[t]=e});var $=W.reduce(function(e,t){var n=N[t];return n===or||n===ar||n===or||n===fr||n===hr||n===vr?e[n]=n:n===sr||t.indexOf("rgba")>=0?e[n]=rr:e[n]=ir,e},{}),K=[],J=[],Z=0,ee={},te=n.maxTextureUnits,ne=Array(te).map(function(){return null});return Ze(E.prototype,{bind:function(){var t=this;t.bindCount+=1;var n=t.unit;if(n<0){for(var r=0;r0)continue;a.unit=-1}ne[r]=t,n=r;break}n>=te&&xt.raise("insufficient number of texture units"),o.profile&&i.maxTextureUnits=za&&t=2,"invalid shape for framebuffer"),s=z[0],d=z[1]}else"radius"in O&&(s=d=O.radius),"width"in O&&(s=O.width),"height"in O&&(d=O.height);("color"in O||"colors"in O)&&(g=O.color||O.colors,Array.isArray(g)&&xt(1===g.length||o,"multiple render targets not supported")),g||("colorCount"in O&&(E=0|O.colorCount,xt(E>0,"invalid color buffer count")),"colorTexture"in O&&(y=!!O.colorTexture,x="rgba4"),"colorType"in O&&(A=O.colorType,y?(xt(t.oes_texture_float||!("float"===A||"float32"===A),"you must enable OES_texture_float in order to use floating point framebuffer objects"),xt(t.oes_texture_half_float||!("half float"===A||"float16"===A),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===A||"float16"===A?(xt(t.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),x="rgba16f"):"float"!==A&&"float32"!==A||(xt(t.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),x="rgba32f"),xt.oneOf(A,_,"invalid color type")),"colorFormat"in O&&(x=O.colorFormat,k.indexOf(x)>=0?y=!0:S.indexOf(x)>=0?y=!1:y?xt.oneOf(O.colorFormat,k,"invalid color format for texture"):xt.oneOf(O.colorFormat,S,"invalid color format for renderbuffer"))),("depthTexture"in O||"depthStencilTexture"in O)&&(C=!(!O.depthTexture&&!O.depthStencilTexture),xt(!C||t.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in O&&("boolean"==typeof O.depth?p=O.depth:(D=O.depth,v=!1)),"stencil"in O&&("boolean"==typeof O.stencil?v=O.stencil:(T=O.stencil,p=!1)),"depthStencil"in O&&("boolean"==typeof O.depthStencil?p=v=O.depthStencil:(j=O.depthStencil,p=!1,v=!1))}else s=d=1;var F=null,M=null,P=null,I=null;if(Array.isArray(g))F=g.map(c);else if(g)F=[c(g)];else for(F=new Array(E),i=0;i=0||F[i].renderbuffer&&oi.indexOf(F[i].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+i+" is invalid"),F[i]&&F[i].texture){var B=Ya[F[i].texture._texture.format]*Xa[F[i].texture._texture.type];null===L?L=B:xt(L===B,"all color attachments much have the same number of bits per pixel.")}return u(M,s,d),xt(!M||M.texture&&M.texture._texture.format===Qa||M.renderbuffer&&M.renderbuffer._renderbuffer.format===Za,"invalid depth attachment for framebuffer object"),u(P,s,d),xt(!P||P.renderbuffer&&P.renderbuffer._renderbuffer.format===ei,"invalid stencil attachment for framebuffer object"),u(I,s,d),xt(!I||I.texture&&I.texture._texture.format===ti||I.renderbuffer&&I.renderbuffer._renderbuffer.format===ti,"invalid depth-stencil attachment for framebuffer object"),h(f),f.width=s,f.height=d,f.colorAttachments=F,f.depthAttachment=M,f.stencilAttachment=P,f.depthStencilAttachment=I,a.color=F.map(m),a.depth=m(M),a.stencil=m(P),a.depthStencil=m(I),a.width=f.width,a.height=f.height,b(f),a}function o(e,t){xt(w.next!==f,"can not resize a framebuffer which is currently in use"); var n=0|e,r=0|t||n;if(n===f.width&&r===f.height)return a;for(var i=f.colorAttachments,o=0;o=2,"invalid shape for framebuffer"),xt(p[0]===p[1],"cube framebuffer must be square"),u=p[0]}else"radius"in d&&(u=0|d.radius),"width"in d?(u=0|d.width,"height"in d&&xt(d.height===u,"must be square")):"height"in d&&(u=0|d.height);("color"in d||"colors"in d)&&(s=d.color||d.colors,Array.isArray(s)&&xt(1===s.length||i,"multiple render targets not supported")),s||("colorCount"in d&&(m=0|d.colorCount,xt(m>0,"invalid color buffer count")),"colorType"in d&&(xt.oneOf(d.colorType,_,"invalid color type"),l=d.colorType),"colorFormat"in d&&(c=d.colorFormat,xt.oneOf(d.colorFormat,k,"invalid color format for texture"))),"depth"in d&&(f.depth=d.depth),"stencil"in d&&(f.stencil=d.stencil),"depthStencil"in d&&(f.depthStencil=d.depthStencil)}else u=1;var h;if(s)if(Array.isArray(s))for(h=[],n=0;n0&&(f.depth=o[0].depth,f.stencil=o[0].stencil,f.depthStencil=o[0].depthStencil),o[n]?o[n](f):o[n]=g(f)}return Ze(a,{width:u,height:u,color:h})}function i(e){var t,r=0|e;if(xt(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===a.width)return a;var i=a.color;for(t=0;t1)for(var h=0;he&&(e=t.stats.uniformsCount)}),e},n.getMaxAttributesCount=function(){var e=0;return d.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);en(c).forEach(t),c={},en(l).forEach(t),l={},d.forEach(function(t){e.deleteProgram(t.program)}),d.length=0,m={},n.shaderCount=0},program:function(e,t,r){xt.command(e>=0,"missing vertex shader",r),xt.command(t>=0,"missing fragment shader",r);var a=m[t];a||(a=m[t]={});var i=a[e];return i||(i=new f(t,e),n.shaderCount++,u(i,r),a[e]=i,d.push(i)),i},restore:s,shader:o,frag:-1,vert:-1}}function Le(e,t,n,r,a,i){function o(o){var f;null===t.next?(xt(a.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),f=pi):(xt(null!==t.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),f=t.next.colorAttachments[0].texture._texture.type,i.oes_texture_float?xt(f===pi||f===vi,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"):xt(f===pi,"Reading from a framebuffer is only allowed for the type 'uint8'"));var u=0,s=0,c=r.framebufferWidth,l=r.framebufferHeight,m=null;Je(o)?m=o:o&&(xt.type(o,"object","invalid arguments to regl.read()"),u=0|o.x,s=0|o.y,xt(u>=0&&u=0&&s0&&c+u<=r.framebufferWidth,"invalid width for read pixels"),xt(l>0&&l+s<=r.framebufferHeight,"invalid height for read pixels"),n();var d=c*l*4;return m||(f===pi?m=new Uint8Array(d):f===vi&&(m=m||new Float32Array(d))),xt.isTypedArray(m,"data buffer for regl.read() must be a typedarray"),xt(m.byteLength>=d,"data buffer for regl.read() too small"),e.pixelStorei(hi,4),e.readPixels(u,s,c,l,di,f,m),m}function f(e){var n;return t.setFBO({framebuffer:e.framebuffer},function(){n=o(e)}),n}function u(e){return e&&"framebuffer"in e?f(e):o(e)}return u}function Be(e){return Array.prototype.slice.call(e)}function Re(e){return Be(e).join("")}function Ne(){function e(e){for(var t=0;t0&&(n.push(e,"="),n.push.apply(n,Be(arguments)),n.push(";")),e}var n=[],r=[];return Ze(e,{def:t,toString:function(){return Re([r.length>0?"var "+r+";":"",Re(n)])}})}function n(){function e(e,t){r(e,t,"=",n.def(e,t),";")}var n=t(),r=t(),a=n.toString,i=r.toString;return Ze(function(){n.apply(n,Be(arguments))},{def:n.def,entry:n,exit:r,save:e,set:function(t,r,a){e(t,r),n(t,r,"=",a,";")},toString:function(){return a()+i()}})}function r(){var e=Re(arguments),t=n(),r=n(),a=t.toString,i=r.toString;return Ze(t,{then:function(){return t.apply(t,Be(arguments)),this},else:function(){return r.apply(r,Be(arguments)),this},toString:function(){var t=i();return t&&(t="else{"+t+"}"),Re(["if(",e,"){",a(),"}",t])}})}function a(e,t){function r(){var e="a"+a.length;return a.push(e),e}var a=[];t=t||0;for(var i=0;i=1,r>=2,t)}if(n===Ai){var a=e.data;return new We(a.thisDep,a.contextDep,a.propDep,t)}return new We(n===_i,n===Si,n===ki,t)}function Ve(e,t,n,r,a,i,o,f,u,s,c,l,m,d,p){function h(e){return e.replace(".","_")}function v(e,t,n){var r=h(e);te.push(e),ee[r]=Z[r]=!!n,ne[r]=t}function b(e,t,n){var r=h(e);te.push(e),Array.isArray(n)?(Z[r]=n.slice(),ee[r]=n.slice()):Z[r]=ee[r]=n,re[r]=t}function g(){var e=Ne(),n=e.link,r=e.global;e.id=oe++,e.batchId="0";var a=n(ae),i=e.shared={props:"a0"};Object.keys(ae).forEach(function(e){i[e]=r.def(a,".",e)}),xt.optional(function(){e.CHECK=n(xt),e.commandStr=xt.guessCommand(),e.command=n(e.commandStr),e.assert=function(e,t,r){e("if(!(",t,"))",this.CHECK,".commandRaise(",n(r),",",this.command,");")},ie.invalidBlendCombinations=pf});var o=e.next={},f=e.current={};Object.keys(re).forEach(function(e){Array.isArray(Z[e])&&(o[e]=r.def(i.next,".",e),f[e]=r.def(i.current,".",e))});var u=e.constants={};Object.keys(ie).forEach(function(e){u[e]=r.def(JSON.stringify(ie[e]))}),e.invoke=function(t,r){switch(r.type){case wi:var a=["this",i.context,i.props,e.batchId];return t.def(n(r.data),".call(",a.slice(0,Math.max(r.data.length+1,4)),")");case ki:return t.def(i.props,r.data);case Si:return t.def(i.context,r.data);case _i:return t.def("this",r.data);case Ai:return r.data.append(e,t),r.data.ref}},e.attribCache={};var c={};return e.scopeAttrib=function(e){var r=t.id(e);if(r in c)return c[r];var a=s.scope[r];a||(a=s.scope[r]=new Y);var i=c[r]=n(a);return i},e}function y(e){var t,n=e.static,r=e.dynamic;if(Zi in n){var a=!!n[Zi];t=He(function(e,t){return a}),t.enable=a}else if(Zi in r){var i=r[Zi];t=Qe(i,function(e,t){return e.invoke(t,i)})}return t}function x(e,t){var n=e.static,r=e.dynamic;if(eo in n){var a=n[eo];return a?(a=f.getFramebuffer(a),xt.command(a,"invalid framebuffer object"),He(function(e,t){var n=e.link(a),r=e.shared;t.set(r.framebuffer,".next",n);var i=r.context;return t.set(i,"."+co,n+".width"),t.set(i,"."+lo,n+".height"),n})):He(function(e,t){var n=e.shared;t.set(n.framebuffer,".next","null");var r=n.context;return t.set(r,"."+co,r+"."+vo),t.set(r,"."+lo,r+"."+bo),"null"})}if(eo in r){var i=r[eo];return Qe(i,function(e,t){var n=e.invoke(t,i),r=e.shared,a=r.framebuffer,o=t.def(a,".getFramebuffer(",n,")");xt.optional(function(){e.assert(t,"!"+n+"||"+o,"invalid framebuffer object")}),t.set(a,".next",o);var f=r.context;return t.set(f,"."+co,o+"?"+o+".width:"+f+"."+vo),t.set(f,"."+lo,o+"?"+o+".height:"+f+"."+bo),o})}return null}function w(e,t,n){function r(e){if(e in a){var r=a[e];xt.commandType(r,"object","invalid "+e,n.commandStr);var o,f,u=!0,s=0|r.x,c=0|r.y;return"width"in r?(o=0|r.width,xt.command(o>=0,"invalid "+e,n.commandStr)):u=!1,"height"in r?(f=0|r.height,xt.command(f>=0,"invalid "+e,n.commandStr)):u=!1,new We(!u&&t&&t.thisDep,!u&&t&&t.contextDep,!u&&t&&t.propDep,function(e,t){var n=e.shared.context,a=o;"width"in r||(a=t.def(n,".",co,"-",s));var i=f;return"height"in r||(i=t.def(n,".",lo,"-",c)),[s,c,a,i]})}if(e in i){var l=i[e],m=Qe(l,function(t,n){var r=t.invoke(n,l);xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)});var a=t.shared.context,i=n.def(r,".x|0"),o=n.def(r,".y|0"),f=n.def('"width" in ',r,"?",r,".width|0:","(",a,".",co,"-",i,")"),u=n.def('"height" in ',r,"?",r,".height|0:","(",a,".",lo,"-",o,")");return xt.optional(function(){t.assert(n,f+">=0&&"+u+">=0","invalid "+e)}),[i,o,f,u]});return t&&(m.thisDep=m.thisDep||t.thisDep,m.contextDep=m.contextDep||t.contextDep,m.propDep=m.propDep||t.propDep),m}return t?new We(t.thisDep,t.contextDep,t.propDep,function(e,t){var n=e.shared.context;return[0,0,t.def(n,".",co),t.def(n,".",lo)]}):null}var a=e.static,i=e.dynamic,o=r(Ji);if(o){var f=o;o=new We(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=f.append(e,t),r=e.shared.context;return t.set(r,"."+mo,n[2]),t.set(r,"."+po,n[3]),n})}return{viewport:o,scissor_box:r(Ki)}}function k(e){function n(e){if(e in a){var n=t.id(a[e]);xt.optional(function(){c.shader(bf[e],n,xt.guessCommand())});var r=He(function(){return n});return r.id=n,r}if(e in i){var o=i[e];return Qe(o,function(t,n){var r=t.invoke(n,o),a=n.def(t.shared.strings,".id(",r,")");return xt.optional(function(){n(t.shared.shader,".shader(",bf[e],",",a,",",t.command,");")}),a})}return null}var r,a=e.static,i=e.dynamic,o=n(no),f=n(to),u=null;return Ge(o)&&Ge(f)?(u=c.program(f.id,o.id),r=He(function(e,t){return e.link(u)})):r=new We(o&&o.thisDep||f&&f.thisDep,o&&o.contextDep||f&&f.contextDep,o&&o.propDep||f&&f.propDep,function(e,t){var n,r=e.shared.shader;n=o?o.append(e,t):t.def(r,".",no);var a;a=f?f.append(e,t):t.def(r,".",to);var i=r+".program("+a+","+n;return xt.optional(function(){i+=","+e.command}),t.def(i+")")}),{frag:o,vert:f,progVar:r,program:u}}function S(e,t){function n(){if(ro in f){var e=f[ro];Ue(e)?e=i.getElements(i.create(e,!0)):e&&(e=i.getElements(e),xt.command(e,"invalid elements",t.commandStr));var n=He(function(t,n){if(e){var r=t.link(e);return t.ELEMENTS=r,r}return t.ELEMENTS=null,null});return n.value=e,n}if(ro in u){var r=u[ro];return Qe(r,function(e,t){var n=e.shared,a=n.isBufferArgs,i=n.elements,o=e.invoke(t,r),f=t.def("null"),u=t.def(a,"(",o,")"),s=e.cond(u).then(f,"=",i,".createStream(",o,");").else(f,"=",i,".getElements(",o,");");return xt.optional(function(){e.assert(s.else,"!"+o+"||"+f,"invalid elements")}),t.entry(s),t.exit(e.cond(u).then(i,".destroyStream(",f,");")),e.ELEMENTS=f,f})}return null}function r(){if(ao in f){var e=f[ao];return xt.commandParameter(e,Ln,"invalid primitve",t.commandStr),He(function(t,n){return Ln[e]})}if(ao in u){var n=u[ao];return Qe(n,function(e,t){var r=e.constants.primTypes,a=e.invoke(t,n);return xt.optional(function(){e.assert(t,a+" in "+r,"invalid primitive, must be one of "+Object.keys(Ln))}),t.def(r,"[",a,"]")})}return s?Ge(s)?He(s.value?function(e,t){return t.def(e.ELEMENTS,".primType")}:function(){return Ko}):new We(s.thisDep,s.contextDep,s.propDep,function(e,t){var n=e.ELEMENTS;return t.def(n,"?",n,".primType:",Ko)}):null}function a(e,n){if(e in f){var r=0|f[e];return xt.command(!n||r>=0,"invalid "+e,t.commandStr),He(function(e,t){return n&&(e.OFFSET=r),r})}if(e in u){var a=u[e];return Qe(a,function(t,r){var i=t.invoke(r,a);return n&&(t.OFFSET=i,xt.optional(function(){t.assert(r,i+">=0","invalid "+e)})),i})}return n&&s?He(function(e,t){return e.OFFSET="0",0}):null}function o(){if(io in f){var e=0|f[io];return xt.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),He(function(){return e})}if(io in u){var n=u[io];return Qe(n,function(e,t){var r=e.invoke(t,n);return xt.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(s){if(Ge(s)){if(s)return c?new We(c.thisDep,c.contextDep,c.propDep,function(e,t){var n=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return xt.optional(function(){e.assert(t,n+">=0","invalid vertex offset/element buffer too small")}),n}):He(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var r=He(function(){return-1});return xt.optional(function(){r.MISSING=!0}),r}var a=new We(s.thisDep||c.thisDep,s.contextDep||c.contextDep,s.propDep||c.propDep,function(e,t){var n=e.ELEMENTS;return e.OFFSET?t.def(n,"?",n,".vertCount-",e.OFFSET,":-1"):t.def(n,"?",n,".vertCount:-1")});return xt.optional(function(){a.DYNAMIC=!0}),a}return null}var f=e.static,u=e.dynamic,s=n(),c=a(oo,!0);return{elements:s,primitive:r(),count:o(),instances:a(fo,!1),offset:c}}function _(e,t){var n=e.static,a=e.dynamic,i={};return te.forEach(function(e){function o(t,r){if(e in n){var o=t(n[e]);i[f]=He(function(){return o})}else if(e in a){var u=a[e];i[f]=Qe(u,function(e,t){return r(e,t,e.invoke(t,u))})}}var f=h(e);switch(e){case Ii:case Di:case Ei:case Hi:case Oi:case $i:case Ni:case qi:case Wi:case Mi:return o(function(n){return xt.commandType(n,"boolean",e,t.commandStr),n},function(t,n,r){return xt.optional(function(){t.assert(n,"typeof "+r+'==="boolean"',"invalid flag "+e,t.commandStr)}),r});case zi:return o(function(n){return xt.commandParameter(n,hf,"invalid "+e,t.commandStr),hf[n]},function(t,n,r){var a=t.constants.compareFuncs;return xt.optional(function(){t.assert(n,r+" in "+a,"invalid "+e+", must be one of "+Object.keys(hf))}),n.def(a,"[",r,"]")});case Fi:return o(function(e){return xt.command(he(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,n){xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===2&&typeof "+n+'[0]==="number"&&typeof '+n+'[1]==="number"&&'+n+"[0]<="+n+"[1]","depth range must be a 2d array")});var r=t.def("+",n,"[0]"),a=t.def("+",n,"[1]");return[r,a]});case Ci:return o(function(e){xt.commandType(e,"object","blend.func",t.commandStr);var n="srcRGB"in e?e.srcRGB:e.src,r="srcAlpha"in e?e.srcAlpha:e.src,a="dstRGB"in e?e.dstRGB:e.dst,i="dstAlpha"in e?e.dstAlpha:e.dst;return xt.commandParameter(n,df,f+".srcRGB",t.commandStr),xt.commandParameter(r,df,f+".srcAlpha",t.commandStr),xt.commandParameter(a,df,f+".dstRGB",t.commandStr),xt.commandParameter(i,df,f+".dstAlpha",t.commandStr),xt.command(pf.indexOf(n+", "+a)===-1,"unallowed blending combination (srcRGB, dstRGB) = ("+n+", "+a+")",t.commandStr),[df[n],df[a],df[r],df[i]]},function(t,n,r){function a(a,o){var f=n.def('"',a,o,'" in ',r,"?",r,".",a,o,":",r,".",a);return xt.optional(function(){t.assert(n,f+" in "+i,"invalid "+e+"."+a+o+", must be one of "+Object.keys(df))}),f}var i=t.constants.blendFuncs;xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid blend func, must be an object")});var o=a("src","RGB"),f=a("dst","RGB");xt.optional(function(){var e=t.constants.invalidBlendCombinations;t.assert(n,e+".indexOf("+o+'+", "+'+f+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")});var u=n.def(i,"[",o,"]"),s=n.def(i,"[",a("src","Alpha"),"]"),c=n.def(i,"[",f,"]"),l=n.def(i,"[",a("dst","Alpha"),"]");return[u,c,s,l]});case ji:return o(function(n){return"string"==typeof n?(xt.commandParameter(n,X,"invalid "+e,t.commandStr),[X[n],X[n]]):"object"==typeof n?(xt.commandParameter(n.rgb,X,e+".rgb",t.commandStr),xt.commandParameter(n.alpha,X,e+".alpha",t.commandStr),[X[n.rgb],X[n.alpha]]):void xt.commandRaise("invalid blend.equation",t.commandStr)},function(t,n,r){var a=t.constants.blendEquations,i=n.def(),o=n.def(),f=t.cond("typeof ",r,'==="string"');return xt.optional(function(){function n(e,n,r){t.assert(e,r+" in "+a,"invalid "+n+", must be one of "+Object.keys(X))}n(f.then,e,r),t.assert(f.else,r+"&&typeof "+r+'==="object"',"invalid "+e),n(f.else,e+".rgb",r+".rgb"),n(f.else,e+".alpha",r+".alpha")}),f.then(i,"=",o,"=",a,"[",r,"];"),f.else(i,"=",a,"[",r,".rgb];",o,"=",a,"[",r,".alpha];"),n(f),[i,o]});case Ti:return o(function(e){return xt.command(he(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),$(4,function(t){return+e[t]})},function(e,t,n){return xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","blend.color must be a 4d array")}),$(4,function(e){return t.def("+",n,"[",e,"]")})});case Qi:return o(function(e){return xt.commandType(e,"number",f,t.commandStr),0|e},function(e,t,n){return xt.optional(function(){e.assert(t,"typeof "+n+'==="number"',"invalid stencil.mask")}),t.def(n,"|0")});case Vi:return o(function(n){xt.commandType(n,"object",f,t.commandStr);var r=n.cmp||"keep",a=n.ref||0,i="mask"in n?n.mask:-1;return xt.commandParameter(r,hf,e+".cmp",t.commandStr),xt.commandType(a,"number",e+".ref",t.commandStr),xt.commandType(i,"number",e+".mask",t.commandStr),[hf[r],a,i]},function(e,t,n){var r=e.constants.compareFuncs;xt.optional(function(){function a(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}a(n+"&&typeof ",n,'==="object"'),a('!("cmp" in ',n,")||(",n,".cmp in ",r,")")});var a=t.def('"cmp" in ',n,"?",r,"[",n,".cmp]",":",of),i=t.def(n,".ref|0"),o=t.def('"mask" in ',n,"?",n,".mask|0:-1");return[a,i,o]});case Yi:case Xi:return o(function(n){xt.commandType(n,"object",f,t.commandStr);var r=n.fail||"keep",a=n.zfail||"keep",i=n.zpass||"keep";return xt.commandParameter(r,vf,e+".fail",t.commandStr),xt.commandParameter(a,vf,e+".zfail",t.commandStr),xt.commandParameter(i,vf,e+".zpass",t.commandStr),[e===Xi?Zo:Jo,vf[r],vf[a],vf[i]]},function(t,n,r){function a(a){return xt.optional(function(){t.assert(n,'!("'+a+'" in '+r+")||("+r+"."+a+" in "+i+")","invalid "+e+"."+a+", must be one of "+Object.keys(vf))}),n.def('"',a,'" in ',r,"?",i,"[",r,".",a,"]:",of)}var i=t.constants.stencilOps;return xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[e===Xi?Zo:Jo,a("fail"),a("zfail"),a("zpass")]});case Ui:return o(function(e){xt.commandType(e,"object",f,t.commandStr);var n=0|e.factor,r=0|e.units;return xt.commandType(n,"number",f+".factor",t.commandStr),xt.commandType(r,"number",f+".units",t.commandStr),[n,r]},function(t,n,r){xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)});var a=n.def(r,".factor|0"),i=n.def(r,".units|0");return[a,i]});case Li:return o(function(e){var n=0;return"front"===e?n=Jo:"back"===e&&(n=Zo),xt.command(!!n,f,t.commandStr),n},function(e,t,n){return xt.optional(function(){e.assert(t,n+'==="front"||'+n+'==="back"',"invalid cull.face")}),t.def(n,'==="front"?',Jo,":",Zo)});case Ri:return o(function(e){return xt.command("number"==typeof e&&e>=r.lineWidthDims[0]&&e<=r.lineWidthDims[1],"invalid line width, must positive number between "+r.lineWidthDims[0]+" and "+r.lineWidthDims[1],t.commandStr),e},function(e,t,n){return xt.optional(function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">="+r.lineWidthDims[0]+"&&"+n+"<="+r.lineWidthDims[1],"invalid line width")}),n});case Bi:return o(function(e){return xt.commandParameter(e,gf,f,t.commandStr),gf[e]},function(e,t,n){return xt.optional(function(){e.assert(t,n+'==="cw"||'+n+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(n+'==="cw"?'+ef+":"+tf)});case Pi:return o(function(e){return xt.command(he(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,n){return xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","invalid color.mask")}),$(4,function(e){return"!!"+n+"["+e+"]"})});case Gi:return o(function(e){xt.command("object"==typeof e&&e,f,t.commandStr);var n="value"in e?e.value:1,r=!!e.invert;return xt.command("number"==typeof n&&n>=0&&n<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[n,r]},function(e,t,n){xt.optional(function(){e.assert(t,n+"&&typeof "+n+'==="object"',"invalid sample.coverage")});var r=t.def('"value" in ',n,"?+",n,".value:1"),a=t.def("!!",n,".invert");return[r,a]})}}),i}function A(e,t){var n=e.static,r=e.dynamic,a={};return Object.keys(n).forEach(function(e){var r,i=n[e];if("number"==typeof i||"boolean"==typeof i)r=He(function(){return i});else if("function"==typeof i){var o=i._reglType;"texture2d"===o||"textureCube"===o?r=He(function(e){return e.link(i)}):"framebuffer"===o||"framebufferCube"===o?(xt.command(i.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),r=He(function(e){return e.link(i.color[0])})):xt.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else he(i)?r=He(function(t){var n=t.global.def("[",$(i.length,function(n){return xt.command("number"==typeof i[n]||"boolean"==typeof i[n],"invalid uniform "+e,t.commandStr),i[n]}),"]");return n}):xt.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);r.value=i,a[e]=r}),Object.keys(r).forEach(function(e){var t=r[e];a[e]=Qe(t,function(e,n){return e.invoke(n,t)})}),a}function E(e,n){var r=e.static,i=e.dynamic,o={};return Object.keys(r).forEach(function(e){var i=r[e],f=t.id(e),u=new Y;if(Ue(i))u.state=yi,u.buffer=a.getBuffer(a.create(i,yo,!1,!0)),u.type=0;else{var s=a.getBuffer(i);if(s)u.state=yi,u.buffer=s,u.type=0;else if(xt.command("object"==typeof i&&i,"invalid data for attribute "+e,n.commandStr),i.constant){var c=i.constant;u.buffer="null",u.state=xi,"number"==typeof c?u.x=c:(xt.command(he(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,n.commandStr),bi.forEach(function(e,t){t=0,'invalid offset for attribute "'+e+'"',n.commandStr);var m=0|i.stride;xt.command(m>=0&&m<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',n.commandStr);var d=0|i.size;xt.command(!("size"in i)||d>0&&d<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',n.commandStr);var p=!!i.normalized,h=0;"type"in i&&(xt.commandParameter(i.type,xn,"invalid type for attribute "+e,n.commandStr),h=xn[i.type]);var v=0|i.divisor;"divisor"in i&&(xt.command(0===v||K,'cannot specify divisor for attribute "'+e+'", instancing not supported',n.commandStr),xt.command(v>=0,'invalid divisor for attribute "'+e+'"',n.commandStr)),xt.optional(function(){var t=n.commandStr,r=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(i).forEach(function(n){xt.command(r.indexOf(n)>=0,'unknown parameter "'+n+'" for attribute pointer "'+e+'" (valid parameters are '+r+")",t)})}),u.buffer=s,u.state=yi,u.size=d,u.normalized=p,u.type=h||s.dtype,u.offset=l,u.stride=m,u.divisor=v}}o[e]=He(function(e,t){var n=e.attribCache;if(f in n)return n[f];var r={isStream:!1};return Object.keys(u).forEach(function(e){r[e]=u[e]}),u.buffer&&(r.buffer=e.link(u.buffer),r.type=r.type||r.buffer+".dtype"),n[f]=r,r})}),Object.keys(i).forEach(function(e){function t(t,r){function a(e){r(s[e],"=",i,".",e,"|0;")}var i=t.invoke(r,n),o=t.shared,f=o.isBufferArgs,u=o.buffer;xt.optional(function(){t.assert(r,i+"&&(typeof "+i+'==="object"||typeof '+i+'==="function")&&('+f+"("+i+")||"+u+".getBuffer("+i+")||"+u+".getBuffer("+i+".buffer)||"+f+"("+i+'.buffer)||("constant" in '+i+"&&(typeof "+i+'.constant==="number"||'+o.isArrayLike+"("+i+".constant))))",'invalid dynamic attribute "'+e+'"')});var s={isStream:r.def(!1)},c=new Y;c.state=yi,Object.keys(c).forEach(function(e){s[e]=r.def(""+c[e])});var l=s.buffer,m=s.type;return r("if(",f,"(",i,")){",s.isStream,"=true;",l,"=",u,".createStream(",yo,",",i,");",m,"=",l,".dtype;","}else{",l,"=",u,".getBuffer(",i,");","if(",l,"){",m,"=",l,".dtype;",'}else if("constant" in ',i,"){",s.state,"=",xi,";","if(typeof "+i+'.constant === "number"){',s[bi[0]],"=",i,".constant;",bi.slice(1).map(function(e){return s[e]}).join("="),"=0;","}else{",bi.map(function(e,t){return s[e]+"="+i+".constant.length>="+t+"?"+i+".constant["+t+"]:0;"}).join(""),"}}else{","if(",f,"(",i,".buffer)){",l,"=",u,".createStream(",yo,",",i,".buffer);","}else{",l,"=",u,".getBuffer(",i,".buffer);","}",m,'="type" in ',i,"?",o.glTypes,"[",i,".type]:",l,".dtype;",s.normalized,"=!!",i,".normalized;"),a("size"),a("offset"),a("stride"),a("divisor"),r("}}"),r.exit("if(",s.isStream,"){",u,".destroyStream(",l,");","}"),s}var n=i[e];o[e]=Qe(n,t)}),o}function D(e){var t=e.static,n=e.dynamic,r={};return Object.keys(t).forEach(function(e){var n=t[e];r[e]=He(function(e,t){return"number"==typeof n||"boolean"==typeof n?""+n:e.link(n)})}),Object.keys(n).forEach(function(e){var t=n[e];r[e]=Qe(t,function(e,n){return e.invoke(n,t)})}),r}function T(e,t,n,r,a){function i(e){var t=s[e];t&&(l[e]=t)}var o=e.static,f=e.dynamic;xt.optional(function(){function e(e){Object.keys(e).forEach(function(e){xt.command(t.indexOf(e)>=0,'unknown parameter "'+e+'"',a.commandStr)})}var t=[eo,to,no,ro,ao,oo,io,fo,Zi].concat(te);e(o),e(f)});var u=x(e,a),s=w(e,u,a),c=S(e,a),l=_(e,a),m=k(e,a);i(Ji),i(h(Ki));var d=Object.keys(l).length>0,p={framebuffer:u,draw:c,shader:m,state:l,dirty:d};return p.profile=y(e,a),p.uniforms=A(n,a),p.attributes=E(t,a),p.context=D(r,a),p}function j(e,t,n){var r=e.shared,a=r.context,i=e.scope();Object.keys(n).forEach(function(r){t.save(a,"."+r);var o=n[r];i(a,".",r,"=",o.append(e,t),";")}),t(i)}function C(e,t,n,r){var a,i=e.shared,o=i.gl,f=i.framebuffer;J&&(a=t.def(i.extensions,".webgl_draw_buffers"));var u,s=e.constants,c=s.drawBuffer,l=s.backBuffer;u=n?n.append(e,t):t.def(f,".next"),r||t("if(",u,"!==",f,".cur){"),t("if(",u,"){",o,".bindFramebuffer(",lf,",",u,".framebuffer);"),J&&t(a,".drawBuffersWEBGL(",c,"[",u,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",lf,",null);"),J&&t(a,".drawBuffersWEBGL(",l,");"),t("}",f,".cur=",u,";"),r||t("}")}function O(e,t,n){var r=e.shared,a=r.gl,i=e.current,o=e.next,f=r.current,u=r.next,s=e.cond(f,".dirty");te.forEach(function(t){var r=h(t);if(!(r in n.state)){var c,l;if(r in o){c=o[r],l=i[r];var m=$(Z[r].length,function(e){return s.def(c,"[",e,"]")});s(e.cond(m.map(function(e,t){return e+"!=="+l+"["+t+"]"}).join("||")).then(a,".",re[r],"(",m,");",m.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";"))}else{c=s.def(u,".",r);var d=e.cond(c,"!==",f,".",r);s(d),r in ne?d(e.cond(c).then(a,".enable(",ne[r],");").else(a,".disable(",ne[r],");"),f,".",r,"=",c,";"):d(a,".",re[r],"(",c,");",f,".",r,"=",c,";")}}}),0===Object.keys(n.state).length&&s(f,".dirty=false;"),t(s)}function z(e,t,n,r){var a=e.shared,i=e.current,o=a.current,f=a.gl;qe(Object.keys(n)).forEach(function(a){var u=n[a];if(!r||r(u)){var s=u.append(e,t);if(ne[a]){var c=ne[a];Ge(u)?s?t(f,".enable(",c,");"):t(f,".disable(",c,");"):t(e.cond(s).then(f,".enable(",c,");").else(f,".disable(",c,");")),t(o,".",a,"=",s,";")}else if(he(s)){var l=i[a];t(f,".",re[a],"(",s,");",s.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(f,".",re[a],"(",s,");",o,".",a,"=",s,";")}})}function F(e,t){K&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function M(e,t,n,r,a){function i(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function o(e){s=t.def(),e(s,"=",i(),";"),"string"==typeof a?e(p,".count+=",a,";"):e(p,".count++;"),d&&(r?(c=t.def(),e(c,"=",v,".getNumPendingQueries();")):e(v,".beginQuery(",p,");"))}function f(e){e(p,".cpuTime+=",i(),"-",s,";"),d&&(r?e(v,".pushScopeStats(",c,",",v,".getNumPendingQueries(),",p,");"):e(v,".endQuery();"))}function u(e){var n=t.def(h,".profile");t(h,".profile=",e,";"),t.exit(h,".profile=",n,";")}var s,c,l,m=e.shared,p=e.stats,h=m.current,v=m.timer,b=n.profile;if(b){if(Ge(b))return void(b.enable?(o(t),f(t.exit),u("true")):u("false"));l=b.append(e,t),u(l)}else l=t.def(h,".profile");var g=e.block();o(g),t("if(",l,"){",g,"}");var y=e.block();f(y),t.exit("if(",l,"){",y,"}")}function P(e,t,n,r,a){function i(e){switch(e){case Po:case Ro:case Wo:return 2;case Io:case No:case Go:return 3;case Lo:case Uo:case Ho:return 4;default:return 1}}function o(n,r,a){function i(){t("if(!",c,".buffer){",u,".enableVertexAttribArray(",s,");}");var n,i=a.type; if(n=a.size?t.def(a.size,"||",r):r,t("if(",c,".type!==",i,"||",c,".size!==",n,"||",p.map(function(e){return c+"."+e+"!=="+a[e]}).join("||"),"){",u,".bindBuffer(",yo,",",m,".buffer);",u,".vertexAttribPointer(",[s,n,i,a.normalized,a.stride,a.offset],");",c,".type=",i,";",c,".size=",n,";",p.map(function(e){return c+"."+e+"="+a[e]+";"}).join(""),"}"),K){var o=a.divisor;t("if(",c,".divisor!==",o,"){",e.instancing,".vertexAttribDivisorANGLE(",[s,o],");",c,".divisor=",o,";}")}}function o(){t("if(",c,".buffer){",u,".disableVertexAttribArray(",s,");","}if(",bi.map(function(e,t){return c+"."+e+"!=="+d[t]}).join("||"),"){",u,".vertexAttrib4f(",s,",",d,");",bi.map(function(e,t){return c+"."+e+"="+d[t]+";"}).join(""),"}")}var u=f.gl,s=t.def(n,".location"),c=t.def(f.attributes,"[",s,"]"),l=a.state,m=a.buffer,d=[a.x,a.y,a.z,a.w],p=["buffer","normalized","offset","stride"];l===yi?i():l===xi?o():(t("if(",l,"===",yi,"){"),i(),t("}else{"),o(),t("}"))}var f=e.shared;r.forEach(function(r){var f,u=r.name,s=n.attributes[u];if(s){if(!a(s))return;f=s.append(e,t)}else{if(!a(yf))return;var c=e.scopeAttrib(u);xt.optional(function(){e.assert(t,c+".state","missing attribute "+u)}),f={},Object.keys(new Y).forEach(function(e){f[e]=t.def(c,".",e)})}o(e.link(r),i(r.info.type),f)})}function I(e,n,r,a,i){for(var o,f=e.shared,u=f.gl,s=0;s1?$(w,function(e){return c+"["+e+"]"}):c);n(");")}}function L(e,t,n,r){function a(){var a,i=m.elements,o=t;return i?((i.contextDep&&r.contextDynamic||i.propDep)&&(o=n),a=i.append(e,o)):a=o.def(l,".",ro),a&&o("if("+a+")"+c+".bindBuffer("+xo+","+a+".buffer.buffer);"),a}function i(){var a,i=m.count,o=t;return i?((i.contextDep&&r.contextDynamic||i.propDep)&&(o=n),a=i.append(e,o),xt.optional(function(){i.MISSING&&e.assert(t,"false","missing vertex count"),i.DYNAMIC&&e.assert(o,a+">=0","missing vertex count")})):(a=o.def(l,".",io),xt.optional(function(){e.assert(o,a+">=0","missing vertex count")})),a}function o(a){var i=m[a];return i?i.contextDep&&r.contextDynamic||i.propDep?i.append(e,n):i.append(e,t):t.def(l,".",a)}function f(){function e(){n(g,".drawElementsInstancedANGLE(",[p,v,y,h+"<<(("+y+"-"+gi+")>>1)",b],");")}function t(){n(g,".drawArraysInstancedANGLE(",[p,h,v,b],");")}d?x?e():(n("if(",d,"){"),e(),n("}else{"),t(),n("}")):t()}function u(){function e(){n(c+".drawElements("+[p,v,y,h+"<<(("+y+"-"+gi+")>>1)"]+");")}function t(){n(c+".drawArrays("+[p,h,v]+");")}d?x?e():(n("if(",d,"){"),e(),n("}else{"),t(),n("}")):t()}var s=e.shared,c=s.gl,l=s.draw,m=r.draw,d=a(),p=o(ao),h=o(oo),v=i();if("number"==typeof v){if(0===v)return}else n("if(",v,"){"),n.exit("}");var b,g;K&&(b=o(fo),g=e.instancing);var y=d+".type",x=m.elements&&Ge(m.elements);K&&("number"!=typeof b||b>=0)?"string"==typeof b?(n("if(",b,">0){"),f(),n("}else if(",b,"<0){"),u(),n("}")):f():u()}function B(e,t,n,r,a){var i=g(),o=i.proc("body",a);return xt.optional(function(){i.commandStr=t.commandStr,i.command=i.link(t.commandStr)}),K&&(i.instancing=o.def(i.shared.extensions,".angle_instanced_arrays")),e(i,o,n,r),i.compile().body}function R(e,t,n,r){F(e,t),P(e,t,n,r.attributes,function(){return!0}),I(e,t,n,r.uniforms,function(){return!0}),L(e,t,t,n)}function N(e,t){var n=e.proc("draw",1);F(e,n),j(e,n,t.context),C(e,n,t.framebuffer),O(e,n,t),z(e,n,t.state),M(e,n,t,!1,!0);var r=t.shader.progVar.append(e,n);if(n(e.shared.gl,".useProgram(",r,".program);"),t.shader.program)R(e,n,t,t.shader.program);else{var a=e.global.def("{}"),i=n.def(r,".id"),o=n.def(a,"[",i,"]");n(e.cond(o).then(o,".call(this,a0);").else(o,"=",a,"[",i,"]=",e.link(function(n){return B(R,e,t,n,1)}),"(",r,");",o,".call(this,a0);"))}Object.keys(t.state).length>0&&n(e.shared.current,".dirty=true;")}function U(e,t,n,r){function a(){return!0}e.batchId="a1",F(e,t),P(e,t,n,r.attributes,a),I(e,t,n,r.uniforms,a),L(e,t,t,n)}function q(e,t,n,r){function a(e){return e.contextDep&&o||e.propDep}function i(e){return!a(e)}F(e,t);var o=n.contextDep,f=t.def(),u="a0",s="a1",c=t.def();e.shared.props=c,e.batchId=f;var l=e.scope(),m=e.scope();if(t(l.entry,"for(",f,"=0;",f,"<",s,";++",f,"){",c,"=",u,"[",f,"];",m,"}",l.exit),n.needsContext&&j(e,m,n.context),n.needsFramebuffer&&C(e,m,n.framebuffer),z(e,m,n.state,a),n.profile&&a(n.profile)&&M(e,m,n,!1,!0),r)P(e,l,n,r.attributes,i),P(e,m,n,r.attributes,a),I(e,l,n,r.uniforms,i),I(e,m,n,r.uniforms,a),L(e,l,m,n);else{var d=e.global.def("{}"),p=n.shader.progVar.append(e,m),h=m.def(p,".id"),v=m.def(d,"[",h,"]");m(e.shared.gl,".useProgram(",p,".program);","if(!",v,"){",v,"=",d,"[",h,"]=",e.link(function(t){return B(U,e,n,t,2)}),"(",p,");}",v,".call(this,a0[",f,"],",f,");")}}function W(e,t){function n(e){return e.contextDep&&a||e.propDep}var r=e.proc("batch",2);e.batchId="0",F(e,r);var a=!1,i=!0;Object.keys(t.context).forEach(function(e){a=a||t.context[e].propDep}),a||(j(e,r,t.context),i=!1);var o=t.framebuffer,f=!1;o?(o.propDep?a=f=!0:o.contextDep&&a&&(f=!0),f||C(e,r,o)):C(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(a=!0),O(e,r,t),z(e,r,t.state,function(e){return!n(e)}),t.profile&&n(t.profile)||M(e,r,t,!1,"a1"),t.contextDep=a,t.needsContext=i,t.needsFramebuffer=f;var u=t.shader.progVar;if(u.contextDep&&a||u.propDep)q(e,r,t,null);else{var s=u.append(e,r);if(r(e.shared.gl,".useProgram(",s,".program);"),t.shader.program)q(e,r,t,t.shader.program);else{var c=e.global.def("{}"),l=r.def(s,".id"),m=r.def(c,"[",l,"]");r(e.cond(m).then(m,".call(this,a0,a1);").else(m,"=",c,"[",l,"]=",e.link(function(n){return B(q,e,t,n,2)}),"(",s,");",m,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}function G(e,n){function r(t){var r=n.shader[t];r&&a.set(i.shader,"."+t,r.append(e,a))}var a=e.proc("scope",3);e.batchId="a2";var i=e.shared,o=i.current;j(e,a,n.context),n.framebuffer&&n.framebuffer.append(e,a),qe(Object.keys(n.state)).forEach(function(t){var r=n.state[t],o=r.append(e,a);he(o)?o.forEach(function(n,r){a.set(e.next[t],"["+r+"]",n)}):a.set(i.next,"."+t,o)}),M(e,a,n,!0,!0),[ro,oo,io,fo,ao].forEach(function(t){var r=n.draw[t];r&&a.set(i.draw,"."+t,""+r.append(e,a))}),Object.keys(n.uniforms).forEach(function(r){a.set(i.uniforms,"["+t.id(r)+"]",n.uniforms[r].append(e,a))}),Object.keys(n.attributes).forEach(function(t){var r=n.attributes[t].append(e,a),i=e.scopeAttrib(t);Object.keys(new Y).forEach(function(e){a.set(i,"."+e,r[e])})}),r(to),r(no),Object.keys(n.state).length>0&&(a(o,".dirty=true;"),a.exit(o,".dirty=true;")),a("a1(",e.shared.context,",a0,",e.batchId,");")}function H(e){if("object"==typeof e&&!he(e)){for(var t=Object.keys(e),n=0;n=0;--e){var n=G[e];n&&n(T,null,0)}b.flush(),_&&_.update()}function n(){!$&&G.length>0&&($=_t.next(t))}function r(){$&&(_t.cancel(t),$=null)}function a(e){e.preventDefault(),y=!0,r(),H.forEach(function(e){e()})}function i(e){b.getError(),y=!1,x.restore(),P.restore(),z.restore(),I.restore(),L.restore(),B.restore(),_&&_.restore(),R.procs.refresh(),n(),Q.forEach(function(e){e()})}function o(){G.length=0,r(),W&&(W.removeEventListener(Tf,a),W.removeEventListener(jf,i)),P.clear(),B.clear(),L.clear(),I.clear(),F.clear(),z.clear(),_&&_.clear(),X.forEach(function(e){e()})}function f(e){function t(e){function t(e){if(e in n){var t=n[e];delete n[e],Object.keys(t).forEach(function(r){n[e+"."+r]=t[r]})}}var n=Ze({},e);return delete n.uniforms,delete n.attributes,delete n.context,"stencil"in n&&n.stencil.op&&(n.stencil.opBack=n.stencil.opFront=n.stencil.op,delete n.stencil.op),t("blend"),t("depth"),t("cull"),t("stencil"),t("polygonOffset"),t("scissor"),t("sample"),n}function n(e){var t={},n={};return Object.keys(e).forEach(function(r){var a=e[r];St.isDynamic(a)?n[r]=St.unbox(a,r):t[r]=a}),{dynamic:n,static:t}}function r(e){for(;p.length0)return m.call(this,r(0|e),0|e)}else{if(!Array.isArray(e))return l.call(this,e);if(e.length)return m.call(this,e,e.length)}}xt(!!e,"invalid args to regl({...})"),xt.type(e,"object","invalid args to regl({...})");var i=n(e.context||{}),o=n(e.uniforms||{}),f=n(e.attributes||{}),u=n(t(e)),s={gpuTime:0,cpuTime:0,count:0},c=R.compile(u,f,o,i,s),l=c.draw,m=c.batch,d=c.scope,p=[];return Ze(a,{stats:s})}function u(e,t){var n=0;R.procs.poll();var r=t.color;r&&(b.clearColor(+r[0]||0,+r[1]||0,+r[2]||0,+r[3]||0),n|=_f),"depth"in t&&(b.clearDepth(+t.depth),n|=Af),"stencil"in t&&(b.clearStencil(0|t.stencil),n|=Ef),xt(!!n,"called regl.clear with no buffer specified"),b.clear(n)}function s(e){if(xt("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var t=0;t<6;++t)K(Ze({framebuffer:e.framebuffer.faces[t]},e),u);else K(e,u);else u(null,e)}function c(e){function t(){function t(){var e=Xe(G,t);G[e]=G[G.length-1],G.length-=1,G.length<=0&&r()}var n=Xe(G,e);xt(n>=0,"cannot cancel a frame twice"),G[n]=t}return xt.type(e,"function","regl.frame() callback must be a function"),G.push(e),n(),{cancel:t}}function l(){var e=q.viewport,t=q.scissor_box;e[0]=e[1]=t[0]=t[1]=0,T.viewportWidth=T.framebufferWidth=T.drawingBufferWidth=e[2]=t[2]=b.drawingBufferWidth,T.viewportHeight=T.framebufferHeight=T.drawingBufferHeight=e[3]=t[3]=b.drawingBufferHeight}function m(){T.tick+=1,T.time=p(),l(),R.procs.poll()}function d(){l(),R.procs.refresh(),_&&_.update()}function p(){return(At()-A)/1e3}function h(e,t){xt.type(t,"function","listener callback must be a function");var n;switch(e){case"frame":return c(t);case"lost":n=H;break;case"restore":n=Q;break;case"destroy":n=X;break;default:xt.raise("invalid event, must be one of frame,lost,restore,destroy")}return n.push(t),{cancel:function(){for(var e=0;e=0},read:U,destroy:o,_gl:b,_refresh:d,poll:function(){m(),_&&_.update()},now:p,stats:k});return v.onDone(null,J),J}var Ke={"[object Int8Array]":5120,"[object Int16Array]":5122,"[object Int32Array]":5124,"[object Uint8Array]":5121,"[object Uint8ClampedArray]":5121,"[object Uint16Array]":5123,"[object Uint32Array]":5125,"[object Float32Array]":5126,"[object Float64Array]":5121,"[object ArrayBuffer]":5121},Je=function(e){return Object.prototype.toString.call(e)in Ke},Ze=function(e,t){for(var n=Object.keys(t),r=0;r=2,"invalid renderbuffer shape"),i=0|d[0],o=0|d[1]}else"radius"in m&&(i=o=0|m.radius),"width"in m&&(i=0|m.width),"height"in m&&(o=0|m.height);"format"in m&&(xt.parameter(m.format,s,"invalid renderbuffer format"),u=s[m.format])}else"number"==typeof t?(i=0|t,o="number"==typeof r?0|r:i):t?xt.raise("invalid arguments to renderbuffer constructor"):i=o=1;if(xt(i>0&&o>0&&i<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),i!==l.width||o!==l.height||u!==l.format)return f.width=l.width=i,f.height=l.height=o,l.format=u,e.bindRenderbuffer(va,l.renderbuffer),e.renderbufferStorage(va,u,i,o),a.profile&&(l.stats.size=ze(l.format,l.width,l.height)),f.format=c[l.format],f}function u(t,r){var i=0|t,o=0|r||i;return i===l.width&&o===l.height?f:(xt(i>0&&o>0&&i<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),f.width=l.width=i,f.height=l.height=o,e.bindRenderbuffer(va,l.renderbuffer),e.renderbufferStorage(va,l.format,i,o),a.profile&&(l.stats.size=ze(l.format,l.width,l.height)),f)}var l=new i(e.createRenderbuffer());return m[l.id]=l,r.renderbufferCount++,f(t,o),f.resize=u,f._reglType="renderbuffer",f._renderbuffer=l,a.profile&&(f.stats=l.stats),f.destroy=function(){l.decRef()},f}function u(){en(m).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(va,t.renderbuffer),e.renderbufferStorage(va,t.format,t.width,t.height)}),e.bindRenderbuffer(va,null)}var s={rgba4:ba,rgb565:ya,"rgb5 a1":ga,depth:xa,stencil:wa,"depth stencil":ka};t.ext_srgb&&(s.srgba=Sa),t.ext_color_buffer_half_float&&(s.rgba16f=Aa,s.rgb16f=Ea),t.webgl_color_buffer_float&&(s.rgba32f=_a);var c=[];Object.keys(s).forEach(function(e){var t=s[e];c[t]=e});var l=0,m={};return i.prototype.decRef=function(){--this.refCount<=0&&o(this)},a.profile&&(r.getTotalRenderbufferSize=function(){var e=0;return Object.keys(m).forEach(function(t){e+=m[t].stats.size}),e}),{create:f,clear:function(){en(m).forEach(o)},restore:u}},ja=36160,Ca=36161,Oa=3553,za=34069,Fa=36064,Ma=36096,Pa=36128,Ia=33306,La=36053,Ba=36054,Ra=36055,Na=36057,Ua=36061,qa=36193,Wa=5121,Ga=5126,Ha=6408,Qa=6402,Va=[Ha],Ya=[];Ya[Ha]=4;var Xa=[];Xa[Wa]=1,Xa[Ga]=4,Xa[qa]=2;var $a=32854,Ka=32855,Ja=36194,Za=33189,ei=36168,ti=34041,ni=35907,ri=34836,ai=34842,ii=34843,oi=[$a,Ka,Ja,ni,ai,ii,ri],fi={};fi[La]="complete",fi[Ba]="incomplete attachment",fi[Na]="incomplete dimensions",fi[Ra]="incomplete, missing attachment",fi[Ua]="unsupported";var ui=5126,si=35632,ci=35633,li=35718,mi=35721,di=6408,pi=5121,hi=3333,vi=5126,bi="xyzw".split(""),gi=5121,yi=1,xi=2,wi=0,ki=1,Si=2,_i=3,Ai=4,Ei="dither",Di="blend.enable",Ti="blend.color",ji="blend.equation",Ci="blend.func",Oi="depth.enable",zi="depth.func",Fi="depth.range",Mi="depth.mask",Pi="colorMask",Ii="cull.enable",Li="cull.face",Bi="frontFace",Ri="lineWidth",Ni="polygonOffset.enable",Ui="polygonOffset.offset",qi="sample.alpha",Wi="sample.enable",Gi="sample.coverage",Hi="stencil.enable",Qi="stencil.mask",Vi="stencil.func",Yi="stencil.opFront",Xi="stencil.opBack",$i="scissor.enable",Ki="scissor.box",Ji="viewport",Zi="profile",eo="framebuffer",to="vert",no="frag",ro="elements",ao="primitive",io="count",oo="offset",fo="instances",uo="Width",so="Height",co=eo+uo,lo=eo+so,mo=Ji+uo,po=Ji+so,ho="drawingBuffer",vo=ho+uo,bo=ho+so,go=[Ci,ji,Vi,Yi,Xi,Gi,Ji,Ki,Ui],yo=34962,xo=34963,wo=35632,ko=35633,So=3553,_o=34067,Ao=2884,Eo=3042,Do=3024,To=2960,jo=2929,Co=3089,Oo=32823,zo=32926,Fo=32928,Mo=5126,Po=35664,Io=35665,Lo=35666,Bo=5124,Ro=35667,No=35668,Uo=35669,qo=35670,Wo=35671,Go=35672,Ho=35673,Qo=35674,Vo=35675,Yo=35676,Xo=35678,$o=35680,Ko=4,Jo=1028,Zo=1029,ef=2304,tf=2305,nf=32775,rf=32776,af=519,of=7680,ff=0,uf=1,sf=32774,cf=513,lf=36160,mf=36064,df={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},pf=["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"],hf={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},vf={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},bf={frag:wo,vert:ko},gf={cw:ef,ccw:tf},yf=new We(!1,!1,!1,function(){}),xf=34918,wf=34919,kf=35007,Sf=function(e,t){function n(){return m.pop()||l.createQueryEXT()}function r(e){m.push(e)}function a(e){var t=n();l.beginQueryEXT(kf,t),d.push(t),s(d.length-1,d.length,e)}function i(){l.endQueryEXT(kf)}function o(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null}function f(){return p.pop()||new o}function u(e){p.push(e)}function s(e,t,n){var r=f();r.startQueryIndex=e,r.endQueryIndex=t,r.sum=0,r.stats=n,h.push(r)}function c(){var e,t,n=d.length;if(0!==n){b.length=Math.max(b.length,n+1),v.length=Math.max(v.length,n+1),v[0]=0,b[0]=0;var a=0;for(e=0,t=0;t