@awayjs/stage
Version:
Stage for AwayJS
1 lines • 223 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@awayjs/core")):"function"==typeof define&&define.amd?define(["exports","@awayjs/core"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).AwayjsStage={},t.AwayjsCore)}(this,(function(t,e){"use strict";var i,r,n,o,a,s,l,h,u,c,p,d,f,_,g,m,y=function(){},v=function(){},b=function(t,e,i,r,n,o,a,s,l,h){this.a=new v,this.b=new v,this.flags=new y,this.dest=t,this.a.format=e,this.a.size=i,this.b.format=r,this.b.size=n,this.opcode=o,this.flags.simple=a,this.flags.horizontal=s,this.flags.fragonly=l,this.flags.matrix=h},x=function(){function t(){}return Object.defineProperty(t,"map",{get:function(){return t._map||(t._map=new Array,t._map.mov=new b("vector","vector",4,"none",0,0,!0,null,null,null),t._map.add=new b("vector","vector",4,"vector",4,1,!0,null,null,null),t._map.sub=new b("vector","vector",4,"vector",4,2,!0,null,null,null),t._map.mul=new b("vector","vector",4,"vector",4,3,!0,null,null,null),t._map.div=new b("vector","vector",4,"vector",4,4,!0,null,null,null),t._map.rcp=new b("vector","vector",4,"none",0,5,!0,null,null,null),t._map.min=new b("vector","vector",4,"vector",4,6,!0,null,null,null),t._map.max=new b("vector","vector",4,"vector",4,7,!0,null,null,null),t._map.frc=new b("vector","vector",4,"none",0,8,!0,null,null,null),t._map.sqt=new b("vector","vector",4,"none",0,9,!0,null,null,null),t._map.rsq=new b("vector","vector",4,"none",0,10,!0,null,null,null),t._map.pow=new b("vector","vector",4,"vector",4,11,!0,null,null,null),t._map.log=new b("vector","vector",4,"none",0,12,!0,null,null,null),t._map.exp=new b("vector","vector",4,"none",0,13,!0,null,null,null),t._map.nrm=new b("vector","vector",4,"none",0,14,!0,null,null,null),t._map.sin=new b("vector","vector",4,"none",0,15,!0,null,null,null),t._map.cos=new b("vector","vector",4,"none",0,16,!0,null,null,null),t._map.crs=new b("vector","vector",4,"vector",4,17,!0,!0,null,null),t._map.dp3=new b("vector","vector",4,"vector",4,18,!0,!0,null,null),t._map.dp4=new b("vector","vector",4,"vector",4,19,!0,!0,null,null),t._map.abs=new b("vector","vector",4,"none",0,20,!0,null,null,null),t._map.neg=new b("vector","vector",4,"none",0,21,!0,null,null,null),t._map.sat=new b("vector","vector",4,"none",0,22,!0,null,null,null),t._map.ted=new b("vector","vector",4,"sampler",1,38,!0,null,!0,null),t._map.kil=new b("none","scalar",1,"none",0,39,!0,null,!0,null),t._map.tex=new b("vector","vector",4,"sampler",1,40,!0,null,!0,null),t._map.m33=new b("vector","matrix",3,"vector",3,23,!0,null,null,!0),t._map.m44=new b("vector","matrix",4,"vector",4,24,!0,null,null,!0),t._map.m43=new b("vector","matrix",3,"vector",4,25,!0,null,null,!0),t._map.ddx=new b("vector","vector",4,"none",0,26,!0,null,!0,null),t._map.ddy=new b("vector","vector",4,"none",0,27,!0,null,!0,null),t._map.sge=new b("vector","vector",4,"vector",4,41,!0,null,null,null),t._map.slt=new b("vector","vector",4,"vector",4,42,!0,null,null,null),t._map.sgn=new b("vector","vector",4,"vector",4,43,!0,null,null,null),t._map.seq=new b("vector","vector",4,"vector",4,44,!0,null,null,null),t._map.sne=new b("vector","vector",4,"vector",4,45,!0,null,null,null)),t._map},enumerable:!1,configurable:!0}),t}(),T=function(t,i){void 0===t&&(t=null),void 0===i&&(i=null),this.name="",this.version=0,this.native={},this.name=t,this.version=i,this.data=new e.ByteArray},A=function(t,e){this.code=t,this.desc=e},E=function(){function t(){}return Object.defineProperty(t,"map",{get:function(){return t._map||(t._map={},t._map.va=new A(0,"vertex attribute"),t._map.fc=new A(1,"fragment constant"),t._map.vc=new A(1,"vertex constant"),t._map.ft=new A(2,"fragment temporary"),t._map.vt=new A(2,"vertex temporary"),t._map.vo=new A(3,"vertex output"),t._map.op=new A(3,"vertex output"),t._map.fd=new A(3,"fragment depth output"),t._map.fo=new A(3,"fragment output"),t._map.oc=new A(3,"fragment output"),t._map.v=new A(4,"varying"),t._map.vi=new A(4,"varying output"),t._map.fi=new A(4,"varying input"),t._map.fs=new A(5,"sampler"),t._map.vn=new A(15,"native"),t._map.fn=new A(15,"native")),t._map},enumerable:!1,configurable:!0}),t}(),w=function(t,e,i){this.shift=t,this.mask=e,this.value=i},S=function(){function t(){}return Object.defineProperty(t,"map",{get:function(){return t._map||(t._map=new Array,t._map.rgba=new w(8,15,0),t._map.rg=new w(8,15,5),t._map.r=new w(8,15,4),t._map.compressed=new w(8,15,1),t._map.compressed_alpha=new w(8,15,2),t._map.dxt1=new w(8,15,1),t._map.dxt5=new w(8,15,2),t._map["2d"]=new w(12,15,0),t._map.cube=new w(12,15,1),t._map["3d"]=new w(12,15,2),t._map.centroid=new w(16,1,1),t._map.ignoresampler=new w(16,4,4),t._map.clamp=new w(20,15,0),t._map.repeat=new w(20,15,1),t._map.wrap=new w(20,15,1),t._map.nomip=new w(24,15,0),t._map.mipnone=new w(24,15,0),t._map.mipnearest=new w(24,15,1),t._map.miplinear=new w(24,15,2),t._map.nearest=new w(28,15,0),t._map.linear=new w(28,15,1)),t._map},enumerable:!1,configurable:!0}),t}(),C=function(){function t(){this.nativeInstructionLastRegister=65534,this.r={vertex:null,fragment:null},this.cur=new T}return t.prototype.assemble=function(t,e,i){void 0===e&&(e=null),void 0===i&&(i=null),i||(i=1),e&&this.addHeader(e,i);var r=t.replace(/[\f\n\r\v]+/g,"\n").split("\n");for(var n in r)this.processLine(r[n],+n);return this.r},t.prototype.processLine=function(t,e){var i=t.search("//");if(-1!=i&&(t=t.slice(0,i)),(t=t.replace(/^\s+|\s+$/g,"")).length>0){var r=t.search(/<.*>/g),n=null;-1!=r&&(n=t.slice(r).match(/([\w\.\-\+]+)/gi),t=t.slice(0,r));for(var o,a={},s=0;(o=t.indexOf("#native"))>0;){var l=o,h=(o=t.indexOf("native#",o))>-1?o+7:t.length;a["nat"+s]=t.substring(l+7,h-7),t=t.substring(0,l)+"nat"+s+t.substring(h),s++}var u=t.match(/([\w\.\+\[\]]+)/gi);if(!u||u.length<1)t.length>=3&&console.log("Warning: bad line "+e+": "+t);else switch(u[0]){case"part":this.addHeader(u[1],Number(u[2]));break;case"endpart":if(!this.cur)throw"Unexpected endpart";return this.cur.data.position=0,void(this.cur=null);default:if(!this.cur)return void console.log("Warning: bad line "+e+": "+t+" (Outside of any part definition)");if("comment"==this.cur.name)return;var c=x.map[u[0]];if(!c)throw"Bad opcode "+u[0]+" "+e+": "+t;this.emitOpcode(this.cur,c.opcode);var p=1;if(c.dest&&"none"!=c.dest){if(!this.emitDest(this.cur,u[p++],c.dest))throw"Bad destination register "+u[p-1]+" "+e+": "+t}else this.emitZeroDword(this.cur);if(c.a&&"none"!=c.a.format){if(!this.emitSource(this.cur,u[p++],c.a,a))throw"Bad source register "+u[p-1]+" "+e+": "+t}else this.emitZeroQword(this.cur);if(c.b&&"none"!=c.b.format){if("sampler"==c.b.format){if(!this.emitSampler(this.cur,u[p++],c.b,n))throw"Bad sampler register "+u[p-1]+" "+e+": "+t}else if(!this.emitSource(this.cur,u[p++],c.b,a))throw"Bad source register "+u[p-1]+" "+e+": "+t}else this.emitZeroQword(this.cur)}}},t.prototype.emitHeader=function(t){switch(t.data.writeUnsignedByte(160),t.data.writeUnsignedInt(t.version),t.version>=16&&t.data.writeUnsignedByte(0),t.data.writeUnsignedByte(161),t.name){case"fragment":t.data.writeUnsignedByte(1);break;case"vertex":t.data.writeUnsignedByte(0);break;case"cpu":t.data.writeUnsignedByte(2);break;default:t.data.writeUnsignedByte(255)}},t.prototype.emitOpcode=function(t,e){t.data.writeUnsignedInt(e)},t.prototype.emitZeroDword=function(t){t.data.writeUnsignedInt(0)},t.prototype.emitZeroQword=function(t){t.data.writeUnsignedInt(0),t.data.writeUnsignedInt(0)},t.prototype.emitDest=function(t,e,i){var r=e.match(/([fov]?[tpocidavs])(\d*)(\.[xyzw]{1,4})?/i);if(!E.map[r[1]])return!1;var n={num:r[2]?r[2]:0,code:E.map[r[1]].code,mask:this.stringToMask(r[3])};return t.data.writeUnsignedShort(n.num),t.data.writeUnsignedByte(n.mask),t.data.writeUnsignedByte(n.code),!0},t.prototype.stringToMask=function(t){if(!t)return 15;var e=0;return-1!=t.indexOf("x")&&(e|=1),-1!=t.indexOf("y")&&(e|=2),-1!=t.indexOf("z")&&(e|=4),-1!=t.indexOf("w")&&(e|=8),e},t.prototype.stringToSwizzle=function(t){if(!t)return 228;var e={x:0,y:1,z:2,w:3},i=0;if("."!=t.charAt(0))throw"Missing . for swizzle";return t.length>1&&(i|=e[t.charAt(1)]),t.length>2?i|=e[t.charAt(2)]<<2:i|=(3&i)<<2,t.length>3?i|=e[t.charAt(3)]<<4:i|=(12&i)<<2,t.length>4?i|=e[t.charAt(4)]<<6:i|=(48&i)<<2,i},t.prototype.emitSampler=function(t,e,i,r){var n=e.match(/fs(\d*)/i);if(!n||!n[1])return!1;t.data.writeUnsignedShort(parseInt(n[1])),t.data.writeUnsignedByte(0),t.data.writeUnsignedByte(0);for(var o=5,a=0,s=0;s<r.length;s++){var l=S.map[r[s].toLowerCase()];l?(0!=(a>>l.shift&l.mask)&&console.log("Warning, duplicate sampler option"),a|=l.mask<<l.shift,o&=~(l.mask<<l.shift),o|=l.value<<l.shift):console.log("Warning, unknown sampler option: ",r[s])}return t.data.writeUnsignedInt(o),!0},t.prototype.emitSource=function(t,e,i,r){var n;r&&e in r&&(this.cur.native[this.nativeInstructionLastRegister]=r[e],e="".concat("vertex"===this.cur.name?"vn":"fn").concat(this.nativeInstructionLastRegister),this.nativeInstructionLastRegister--);var o=e.match(/vc\[(v[tcai])(\d+)\.([xyzw])([+-]\d+)?\](\.[xyzw]{1,4})?/i);if(o){if(!E.map[o[1]])return!1;t.data.writeUnsignedShort(0|+o[2]),t.data.writeByte(0|+o[4]),t.data.writeUnsignedByte(this.stringToSwizzle(o[5])),t.data.writeUnsignedByte(1),t.data.writeUnsignedByte(E.map[o[1]].code),t.data.writeUnsignedByte({x:0,y:1,z:2,w:3}[o[3]]),t.data.writeUnsignedByte(128)}else{if(n=e.match(/([fov]?[tpocidavsn])(\d*)(\.[xyzw]{1,4})?/i),!E.map[n[1]])return!1;t.data.writeUnsignedShort(0|n[2]),t.data.writeUnsignedByte(0),t.data.writeUnsignedByte(this.stringToSwizzle(n[3])),t.data.writeUnsignedByte(E.map[n[1]].code),t.data.writeUnsignedByte(0),t.data.writeUnsignedByte(0),t.data.writeUnsignedByte(0)}return!0},t.prototype.addHeader=function(t,e){if(void 0===e&&(e=1),null==this.r[t])this.r[t]=new T(t,e),this.emitHeader(this.r[t]);else if(this.r[t].version!=e)throw"Multiple versions for part "+t;this.cur=this.r[t]},t}(),R=function(){this.progid=0,this.version=0,this.type=""},P=function(){var t,e;this.regread=((t={})[0]=[],t[1]=[],t[4]=[],t[2]=[],t[3]=[],t[5]=[],t[15]=[],t),this.regwrite=((e={})[0]=[],e[1]=[],e[4]=[],e[2]=[],e[3]=[],e[5]=[],e[15]=[],e),this.hasindirect=!1,this.writedepth=!1,this.hasmatrix=!1,this.samplers=[],this.constants=0,this.tokens=[],this.header=new R,this.native={}},B=function(t,e,i,r,n,o,a,s,l,h,u){this.s=t,this.flags=e,this.dest=i,this.a=r,this.b=n,this.matrixwidth=o,this.matrixheight=a,this.ndwm=s,this.scalar=l,this.dm=h,this.lod=u},O=function(){function t(t){}return t.lib=((i={})[24]="\n// agal lib fun: multiply matrix4 onto v\nvec4 mul_mat44 (int matIndex, vec4 v) {\n\treturn vec4(\n\t\tdot(v, vc[matIndex + 0]),\n\t\tdot(v, vc[matIndex + 1]),\n\t\tdot(v, vc[matIndex + 2]),\n\t\tdot(v, vc[matIndex + 3])\n\t);\n}\n",i),t.agal2glsllut=[new B("%dest = %cast(%a);\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(%a + %b);\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(%a - %b);\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(%a * %b);\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(%a / %b);\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(1.0) / %a;\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(min(%a,%b));\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(max(%a,%b));\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(fract(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(sqrt(abs(%a)));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(inversesqrt(abs(%a)));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(pow(abs(%a),%b));\n",0,!0,!0,!0,null,null,null,null,null,null),new B("%dest = %cast(log2(abs(%a)));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(exp2(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(normalize(vec3( %a ) ));\n",0,!0,!0,!1,null,null,!0,null,null,null),new B("%dest = %cast(sin(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(cos(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(cross(vec3(%a),vec3(%b)));\n",0,!0,!0,!0,null,null,!0,null,null,null),new B("%dest = %cast(dot(vec3(%a),vec3(%b)));\n",0,!0,!0,!0,null,null,!0,null,null,null),new B("%dest = %cast(dot(vec4(%a),vec4(%b)));\n",0,!0,!0,!0,null,null,!0,null,null,null),new B("%dest = %cast(abs(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(%a * -1.0);\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(clamp(%a,0.0,1.0));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(dot(vec3(%a),vec3(%b)));\n",null,!0,!0,!0,3,3,!0,null,null,null),new B("%dest = %cast(mul_mat44(%ib,vec4(%a)));\n",null,!0,!0,!0,4,4,!0,null,null,null),new B("%dest = %cast(dot(vec4(%a),vec4(%b)));\n",null,!0,!0,!0,4,3,!0,null,null,null),new B("%dest = %cast(dFdx(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(dFdy(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("if (float(%a)==float(%b)) {;\n",0,!1,!0,!0,null,null,null,!0,null,null),new B("if (float(%a)!=float(%b)) {;\n",0,!1,!0,!0,null,null,null,!0,null,null),new B("if (float(%a)>=float(%b)) {;\n",0,!1,!0,!0,null,null,null,!0,null,null),new B("if (float(%a)<float(%b)) {;\n",0,!1,!0,!0,null,null,null,!0,null,null),new B("} else {;\n",0,!1,!1,!1,null,null,null,null,null,null),new B("};\n",0,!1,!1,!1,null,null,null,null,null,null),new B(null,null,null,null,!1,null,null,null,null,null,null),new B(null,null,null,null,!1,null,null,null,null,null,null),new B(null,null,null,null,!1,null,null,null,null,null,null),new B(null,null,null,null,!1,null,null,null,null,null,null),new B("%dest = %cast(texture%texdimLod(%b,%texsize(%a)).%dm);\n",null,!0,!0,!0,null,null,null,null,!0,null),new B("if ( float(%a)<0.0 ) discard;\n",null,!1,!0,!1,null,null,null,!0,null,null),new B("%dest = %cast(texture%texdim(%b,%texsize(%a)%lod).%dm);\n",null,!0,!0,!0,null,null,!0,null,!0,!0),new B("%dest = %cast(greaterThanEqual(%a,%b).%dm);\n",0,!0,!0,!0,null,null,!0,null,!0,null),new B("%dest = %cast(lessThan(%a,%b).%dm);\n",0,!0,!0,!0,null,null,!0,null,!0,null),new B("%dest = %cast(sign(%a));\n",0,!0,!0,!1,null,null,null,null,null,null),new B("%dest = %cast(equal(%a,%b).%dm);\n",0,!0,!0,!0,null,null,!0,null,!0,null),new B("%dest = %cast(notEqual(%a,%b).%dm);\n",0,!0,!0,!0,null,null,!0,null,!0,null)],t}(),L=function(){this.mask=0,this.regnum=0,this.regtype=0,this.dim=0,this.indexoffset=0,this.swizzle=0,this.lodbiad=0,this.readmode=0,this.special=0,this.wrap=0,this.filter=0,this.indexregtype=0,this.indexselect=0,this.indirectflag=0},D=function(){this.dest=new L,this.opcode=0,this.a=new L,this.b=new L},U=function(){function t(){}return t.prototype.decribeAGALPart=function(t){if(t instanceof e.ByteArray)return this.decribeAGALByteArray(t);var i=this.decribeAGALByteArray(t.data);return i.native=t.native,i},t.prototype.decribeAGALByteArray=function(t){var e=new R;if(160!=t.readUnsignedByte())throw"Bad AGAL: Missing 0xa0 magic byte.";if(e.version=t.readUnsignedInt(),e.version>=16&&(t.readUnsignedByte(),e.version>>=1),161!=t.readUnsignedByte())throw"Bad AGAL: Missing 0xa1 magic byte.";switch(e.progid=t.readUnsignedByte(),e.progid){case 1:e.type="fragment";break;case 0:e.type="vertex";break;case 2:e.type="cpu";break;default:e.type=""}for(var i=new P,r=[];t.position<t.length;){var n=new D;n.opcode=t.readUnsignedInt();var o=O.agal2glsllut[n.opcode];if(!o)throw"Opcode not valid or not implemented yet: "+n.opcode;o.matrixheight&&(i.hasmatrix=!0),o.dest?(n.dest.regnum=t.readUnsignedShort(),n.dest.mask=t.readUnsignedByte(),n.dest.regtype=t.readUnsignedByte(),i.regwrite[n.dest.regtype][n.dest.regnum]|=n.dest.mask):(n.dest=null,t.readUnsignedInt()),o.a?this.readReg(n.a,1,i,t):(n.a=null,t.readUnsignedInt(),t.readUnsignedInt()),o.b?this.readReg(n.b,0|o.matrixheight,i,t):(n.b=null,t.readUnsignedInt(),t.readUnsignedInt()),r.push(n)}return i.header=e,i.tokens=r,i},t.prototype.readReg=function(t,e,i,r){if(t.regnum=r.readUnsignedShort(),t.indexoffset=r.readByte(),t.swizzle=r.readUnsignedByte(),t.regtype=r.readUnsignedByte(),i.regread[t.regtype][t.regnum]=15,5===t.regtype?(t.lodbiad=t.indexoffset,t.indexoffset=void 0,t.swizzle=void 0,t.readmode=r.readUnsignedByte(),t.dim=t.readmode>>4,t.readmode&=15,t.special=r.readUnsignedByte(),t.wrap=t.special>>4,t.special&=15,t.mipmap=r.readUnsignedByte(),t.filter=t.mipmap>>4,t.mipmap&=15,i.samplers[t.regnum]=t):(t.indexregtype=r.readUnsignedByte(),t.indexselect=r.readUnsignedByte(),t.indirectflag=r.readUnsignedByte()),t.indirectflag&&(i.hasindirect=!0),!t.indirectflag&&e)for(var n=0;n<e;n++)i.regread[t.regtype][t.regnum+n]=i.regread[t.regtype][t.regnum]},t}(),M=e.ConfigManager.instance.addStore("stage",{PREF_WEBGL_VERSION:2,USE_300_SHADERS_FOR_WEBGL2:!0,ENABLE_MULTISAMPLE_TEXTURE:!0,ENABLE_ANTIALIAS:!0,ENABLE_WEAK_REF:!0,PROFILE_CONTEXT_LOST:!1,ENABLE_UNLOAD_BITMAP:!0,MAX_BITMAP_UNLOAD_TASKS:10,MAX_BITMAP_UNLOAD_TASKS_ASYNC:50,ENABLE_UNLOAD_TEXTURE:!0,ENABLE_TEXTURE_POOLING:!1,ENABLE_UNLOAD_BUFFER:!0,MAX_BUFFER_POOL_SIZE:300,MAX_BUFFER_ALIVE_TIME:5e3,ENABLE_BUFFER_POOLING:!1,ENABLE_VAO:!0,ENABLE_UNIFORM_CACHE:!1,ENABLE_ASYNC_READ:!0,ENABLE_PARSER_NATIVE_BITMAP:!0,UNSAFE_USE_AUTOINDEXED_SAMPLER:!0,UNSAFE_USE_AUTOINDEXED_ATTRIBUTES:!0,UNSAFE_USE_SHADER_COMPOSER:!0,USE_NON_NATIVE_BLEND:!1}),F=function(){function t(){this._usedLibs={},this._usedTemps={}}return t.prototype._linkLib=function(t){var e=this._usedLibs;return!e[t]&&O.lib[t]?(e[t]=!0,this._header+="\n"+O.lib[t]+"\n",!0):e[t]},t.prototype.parse=function(e,i,r){void 0===r&&(r=!1),r=M.USE_300_SHADERS_FOR_WEBGL2&&r,this._usedTemps={},this._usedLibs={},this._header="",this._body="",this._header+=r?"#version 300 es\n":"#version 100\n",this._header+="precision "+i+" float;\n";var n=e.header.type[0],o=e.regread[1].length;o>0&&(this._header+="uniform vec4 "+n+"c["+o+"];\n");for(var a=0;a<e.regread[0].length;a++)e.regread[0][a]&&(this._header+=(r?"in":"attribute")+" vec4 va"+a+";\n");for(a=0;a<e.regread[4].length||a<e.regwrite[4].length;a++)(e.regread[4][a]||e.regwrite[4][a])&&(this._header+=r?("vertex"===e.header.type?"out":"in")+" vec4 vi"+a+";\n":"varying vec4 vi"+a+";\n");for(a=0;a<e.samplers.length;a++)e.samplers[a]&&(this._header+="uniform sampler"+t.SAMPLERS[3&e.samplers[a].dim]+" fs"+a+";\n");"vertex"==e.header.type?this._header+="vec4 outpos;\n":r&&(this._header+="out vec4 outColor;\n"),e.writedepth&&(this._header+="vec4 tmp_FragDepth;\n");var s=!1;this._body+="void main() {\n";for(a=0;a<e.tokens.length;a++){var l=e.tokens[a],h=O.agal2glsllut[l.opcode],u=this._linkLib(l.opcode);if(-1==h.s.indexOf("dFdx")&&-1==h.s.indexOf("dFdy")||(s=!0),!h)throw"Opcode not valid or not implemented yet: ";for(var c=u?1:h.matrixheight||1,p=0;p<c;p++){var d=" "+h.s,f="",_="float",g="";if(l.dest){if(h.matrixheight&&!u){if(1!=(l.dest.mask>>p&1))continue;g=t.SWIZZLE[p],f=this.regtostring(l.dest.regtype,l.dest.regnum,e,n,r),f+="."+g}else if(f=this.regtostring(l.dest.regtype,l.dest.regnum,e,n,r),15!=l.dest.mask){var m=0;switch(g="",1&l.dest.mask&&(m++,g+="x"),2&l.dest.mask&&(m++,g+="y"),4&l.dest.mask&&(m++,g+="z"),8&l.dest.mask&&(m++,g+="w"),f+="."+g,m){case 1:_="float";break;case 2:_="vec2";break;case 3:_="vec3";break;default:throw"Unexpected destination mask"}}else _="vec4",g="xyzw";if(2==l.dest.regtype&&!this._usedTemps[l.dest.regnum]){var y=n+"t"+l.dest.regnum;"vec4"===_?f="vec4 "+y:d=" vec4 "+y+";\n"+d,this._usedTemps[l.dest.regnum]=!0}d=(d=(d=d.replace("%dest",f)).replace("%cast",_)).replace("%dm",g)}var v=15;if(!h.ndwm&&h.dest&&l.dest&&(v=l.dest.mask),l.a&&(d=(d=d.replace("%a",this.sourcetostring(l.a,0,v,h.scalar,e,n,r))).replace("%ia",""+l.a.regnum)),l.b&&(d=(d=d.replace("%b",this.sourcetostring(l.b,p,v,h.scalar,e,n,r))).replace("%ib",""+l.b.regnum),5==l.b.regtype)){var b=t.SAMPLERS[l.b.dim],x=["vec2","vec3","vec3"][l.b.dim];d=(d=(d=d.replace("%texdim",r?"":b)).replace("%texsize",x)).replace("%lod","")}this._body+=d}}return"vertex"==e.header.type&&(this._body+=" gl_Position = vec4(outpos.x, outpos.y, outpos.z*2.0 - outpos.w, outpos.w);\n"),s&&"fragment"==e.header.type&&(this._header="#extension GL_OES_standard_derivatives : enable\n"+this._header),e.writedepth&&(this._body+=" gl_FragDepth = clamp(tmp_FragDepth,0.0,1.0);\n"),this._body+="}\n",this._header+this._body},t.prototype.regtostring=function(t,e,i,r,n){switch(t){case 0:return"va"+e;case 1:return i.header.type[0]+"c["+e+"]";case 2:return r+"t"+e;case 3:return"vertex"==i.header.type?"outpos":n?"outColor":"gl_FragColor";case 4:return"vi"+e;case 5:return"fs"+e;case 15:if(void 0===i.native[e])throw"Native mapping not presented for register:"+e;return i.native[e];default:throw"Unknown register type"}},t.prototype.sourcetostring=function(e,i,r,n,o,a,s){var l,h=t.SWIZZLE;if(e.indirectflag){l="vcarrr[int("+this.regtostring(e.indexregtype,e.regnum,o,a,s)+"."+h[e.indexselect]+")";var u=i+e.indexoffset;u<0&&(l+=u.toString()),u>0&&(l+="+"+u.toString()),l+="]"}else l=this.regtostring(e.regtype,e.regnum+i,o,a,s);return 5==e.regtype||15==e.regtype?l:n?l+"."+h[e.swizzle>>0&3]:(228==e.swizzle&&15==r||(l+=".",1&r&&(l+=h[e.swizzle>>0&3]),2&r&&(l+=h[e.swizzle>>2&3]),4&r&&(l+=h[e.swizzle>>4&3]),8&r&&(l+=h[e.swizzle>>6&3])),l)},t.SWIZZLE=["x","y","z","w"],t.SAMPLERS=["2D","Cube","3D",""],t.maxvertexconstants=128,t.maxfragconstants=28,t.maxtemp=8,t.maxstreams=8,t.maxtextures=8,t}();t.ContextGLBlendFactor=void 0,(r=t.ContextGLBlendFactor||(t.ContextGLBlendFactor={}))[r.DESTINATION_ALPHA=0]="DESTINATION_ALPHA",r[r.DESTINATION_COLOR=1]="DESTINATION_COLOR",r[r.ONE=2]="ONE",r[r.ONE_MINUS_DESTINATION_ALPHA=3]="ONE_MINUS_DESTINATION_ALPHA",r[r.ONE_MINUS_DESTINATION_COLOR=4]="ONE_MINUS_DESTINATION_COLOR",r[r.ONE_MINUS_SOURCE_ALPHA=5]="ONE_MINUS_SOURCE_ALPHA",r[r.ONE_MINUS_SOURCE_COLOR=6]="ONE_MINUS_SOURCE_COLOR",r[r.SOURCE_ALPHA=7]="SOURCE_ALPHA",r[r.SOURCE_COLOR=8]="SOURCE_COLOR",r[r.ZERO=9]="ZERO",t.ContextGLBlendEquation=void 0,(n=t.ContextGLBlendEquation||(t.ContextGLBlendEquation={}))[n.ADD=0]="ADD",n[n.SUBTRACT=1]="SUBTRACT",n[n.REVERSE_SUBTRACT=2]="REVERSE_SUBTRACT",n[n.MIN=3]="MIN",n[n.MAX=4]="MAX",t.ContextGLClearMask=void 0,(o=t.ContextGLClearMask||(t.ContextGLClearMask={}))[o.COLOR=1]="COLOR",o[o.DEPTH=2]="DEPTH",o[o.STENCIL=4]="STENCIL",o[o.ALL=7]="ALL",t.ContextGLCompareMode=void 0,(a=t.ContextGLCompareMode||(t.ContextGLCompareMode={}))[a.ALWAYS=0]="ALWAYS",a[a.EQUAL=1]="EQUAL",a[a.GREATER=2]="GREATER",a[a.GREATER_EQUAL=3]="GREATER_EQUAL",a[a.LESS=4]="LESS",a[a.LESS_EQUAL=5]="LESS_EQUAL",a[a.NEVER=6]="NEVER",a[a.NOT_EQUAL=7]="NOT_EQUAL",t.ContextGLDrawMode=void 0,(s=t.ContextGLDrawMode||(t.ContextGLDrawMode={}))[s.TRIANGLES=0]="TRIANGLES",s[s.LINES=1]="LINES",t.ContextGLMipFilter=void 0,(l=t.ContextGLMipFilter||(t.ContextGLMipFilter={}))[l.MIPLINEAR=0]="MIPLINEAR",l[l.MIPNEAREST=1]="MIPNEAREST",l[l.MIPNONE=2]="MIPNONE",t.ContextGLProfile=void 0,(h=t.ContextGLProfile||(t.ContextGLProfile={}))[h.BASELINE=0]="BASELINE",h[h.BASELINE_CONSTRAINED=1]="BASELINE_CONSTRAINED",h[h.BASELINE_EXTENDED=2]="BASELINE_EXTENDED",t.ContextGLProgramType=void 0,(u=t.ContextGLProgramType||(t.ContextGLProgramType={}))[u.FRAGMENT=0]="FRAGMENT",u[u.SAMPLER=1]="SAMPLER",u[u.VERTEX=2]="VERTEX",t.ContextGLStencilAction=void 0,(c=t.ContextGLStencilAction||(t.ContextGLStencilAction={}))[c.DECREMENT_SATURATE=0]="DECREMENT_SATURATE",c[c.DECREMENT_WRAP=1]="DECREMENT_WRAP",c[c.INCREMENT_SATURATE=2]="INCREMENT_SATURATE",c[c.INCREMENT_WRAP=3]="INCREMENT_WRAP",c[c.INVERT=4]="INVERT",c[c.KEEP=5]="KEEP",c[c.SET=6]="SET",c[c.ZERO=7]="ZERO",t.ContextGLTextureFilter=void 0,(p=t.ContextGLTextureFilter||(t.ContextGLTextureFilter={}))[p.LINEAR=0]="LINEAR",p[p.NEAREST=1]="NEAREST",t.ContextGLTextureFormat=void 0,(d=t.ContextGLTextureFormat||(t.ContextGLTextureFormat={}))[d.BGRA=0]="BGRA",d[d.BGRA_PACKED=1]="BGRA_PACKED",d[d.BGR_PACKED=2]="BGR_PACKED",d[d.COMPRESSED=3]="COMPRESSED",d[d.COMPRESSED_ALPHA=4]="COMPRESSED_ALPHA",t.ContextGLTriangleFace=void 0,(f=t.ContextGLTriangleFace||(t.ContextGLTriangleFace={}))[f.BACK=0]="BACK",f[f.FRONT=1]="FRONT",f[f.FRONT_AND_BACK=2]="FRONT_AND_BACK",f[f.NONE=3]="NONE",t.ContextGLVertexBufferFormat=void 0,(_=t.ContextGLVertexBufferFormat||(t.ContextGLVertexBufferFormat={}))[_.FLOAT_1=0]="FLOAT_1",_[_.FLOAT_2=1]="FLOAT_2",_[_.FLOAT_3=2]="FLOAT_3",_[_.FLOAT_4=3]="FLOAT_4",_[_.BYTE_1=4]="BYTE_1",_[_.BYTE_2=5]="BYTE_2",_[_.BYTE_3=6]="BYTE_3",_[_.BYTE_4=7]="BYTE_4",_[_.UNSIGNED_BYTE_1=8]="UNSIGNED_BYTE_1",_[_.UNSIGNED_BYTE_2=9]="UNSIGNED_BYTE_2",_[_.UNSIGNED_BYTE_3=10]="UNSIGNED_BYTE_3",_[_.UNSIGNED_BYTE_4=11]="UNSIGNED_BYTE_4",_[_.SHORT_1=12]="SHORT_1",_[_.SHORT_2=13]="SHORT_2",_[_.SHORT_3=14]="SHORT_3",_[_.SHORT_4=15]="SHORT_4",_[_.UNSIGNED_SHORT_1=16]="UNSIGNED_SHORT_1",_[_.UNSIGNED_SHORT_2=17]="UNSIGNED_SHORT_2",_[_.UNSIGNED_SHORT_3=18]="UNSIGNED_SHORT_3",_[_.UNSIGNED_SHORT_4=19]="UNSIGNED_SHORT_4",t.ContextGLWrapMode=void 0,(g=t.ContextGLWrapMode||(t.ContextGLWrapMode={}))[g.CLAMP=0]="CLAMP",g[g.REPEAT=1]="REPEAT",t.ContextMode=void 0,(m=t.ContextMode||(t.ContextMode={}))[m.AUTO=0]="AUTO",m[m.WEBGL=1]="WEBGL",m[m.FLASH=2]="FLASH",m[m.GLES=3]="GLES",m[m.NATIVE=4]="NATIVE",m[m.SOFTWARE=5]="SOFTWARE";var I=function(){function t(t,e){void 0===t&&(t=-1),void 0===e&&(e=null),this.id=t,this.type=e,this.wrap=0,this.filter=0,this.mipfilter=0,this.boundedTexture=null,this._dirty=!0}return Object.defineProperty(t.prototype,"valid",{get:function(){return null!==this.type&&this.id>=0},enumerable:!1,configurable:!0}),t.prototype.set=function(t,e,i){return this._dirty=this._dirty||t!=t||e!=e||i!=i,this.wrap=t,this.filter=e,this.mipfilter=i,this},t.prototype.equals=function(t){return this.type===t.type&&this.wrap===t.wrap&&this.filter===t.filter&&this.mipfilter===t.mipfilter},t.prototype.copyFrom=function(t){return this.type=t.type,this.wrap=t.wrap,this.filter=t.filter,this.mipfilter=t.mipfilter,this},t.prototype.dispose=function(){this.id=-1,this.type=null,this.wrap=0,this.filter=0,this.mipfilter=0},t}(),N=function(t,e,i){this.x=t,this.y=e,this.id=i},k=function(t,e){return k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},k(t,e)};function G(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}k(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}function V(t,e,i,r){var n,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,r);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(a=(o<3?n(a):o>3?n(e,i,a):n(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}"function"==typeof SuppressedError&&SuppressedError;var z=function(t){function e(e,i){var r=t.call(this,e)||this;return r._image=i,r}return G(e,t),Object.defineProperty(e.prototype,"image",{get:function(){return this._image},enumerable:!1,configurable:!0}),e.INVALIDATE_MIPMAPS="invalidateMipmaps",e}(e.EventBase),j=function(t){function e(e,i){var r=t.call(this,e)||this;return r._stage=i,r}return G(e,t),Object.defineProperty(e.prototype,"stage",{get:function(){return this._stage},enumerable:!1,configurable:!0}),e.prototype.clone=function(){return new e(this.type,this._stage)},e.STAGE_ERROR="stageError",e.CONTEXT_CREATED="contextCreated",e.CONTEXT_DISPOSED="contextDisposed",e.CONTEXT_RECREATED="contextRecreated",e.INVALIDATE_SIZE="invalidateSize",e}(e.EventBase),X=function(t){function e(e,i){var r=t.call(this,e)||this;return r._rttManager=i,r}return G(e,t),Object.defineProperty(e.prototype,"rttManager",{get:function(){return this._rttManager},enumerable:!1,configurable:!0}),e.prototype.clone=function(){return new e(this.type,this._rttManager)},e.RESIZE="rttManagerResize",e}(e.EventBase),H=function(){function t(){}return t.getImageBuffer=function(t){var e=this.CANVAS||(this.CANVAS=document.createElement("canvas")),i=this.CONTEXT||(this.CONTEXT=e.getContext("2d",{willReadFrequently:!0}));return t instanceof HTMLImageElement?(e.width=t.naturalWidth,e.height=t.naturalHeight):(e.width=t.width,e.height=t.height),i.drawImage(t,0,0),i.getImageData(0,0,e.width,e.height).data},t.imageToBitmapImage2D=function(e,i,r){var n,o;void 0===r&&(r=!0),e instanceof HTMLImageElement?(n=e.naturalWidth,o=e.naturalHeight):(n=e.width,o=e.height);var a=i.createImage2D(n,o,!0,null,r);return a.addLazySymbol({needParse:!0,definition:{width:n,height:o,isPMA:!0,data:null},lazyParser:function(){return this.needParse=!1,this.definition.data=t.getImageBuffer(e),this.lazyParser=null,this}}),a},t.isImage2DValid=function(t){return null==t||this.isDimensionValid(t.width,t.powerOfTwo)&&this.isDimensionValid(t.height,t.powerOfTwo)},t.isHTMLImageElementValid=function(t){return null==t||this.isDimensionValid(t.width)&&this.isDimensionValid(t.height)},t.isDimensionValid=function(t,e){return void 0===e&&(e=!0),t>=1&&t<=this.MAX_SIZE&&(!e||this.isPowerOfTwo(t))},t.isPowerOfTwo=function(t){return!!t&&(t&-t)==t},t.getBestPowerOf2=function(t){for(var e=1;e<t;)e<<=1;return e>this.MAX_SIZE&&(e=this.MAX_SIZE),e},t.getDefaultImage2D=function(){return this._defaultImage2D||(this._defaultImage2D=this._defaultImage2DFactory())},t.getDefaultImageCube=function(){return this._defaultImageCube||(this._defaultImageCube=this._defaultImageCubeFactory())},t.getDefaultImageSampler=function(){return this._defaultImageSampler||(this._defaultImageSampler=this._defaultImageSamplerFactory())},t.registerDefaults=function(t,e,i,r){void 0===t&&(t=null),void 0===e&&(e=null),void 0===i&&(i=null),void 0===r&&(r=null),t&&(this._defaultImage2DFactory=t),e&&(this._defaultImageCubeFactory=e),i&&(this._defaultImageSamplerFactory=i),r&&(this._defaultFactory=r)},t.MAX_SIZE=8192,t}(),W=function(t){function i(){var i=t.call(this)||this;return i._format="bgra",i._isDisposed=!1,i._owners=new e.WeakAssetSet,i}return G(i,t),Object.defineProperty(i.prototype,"isDisposed",{get:function(){return this._isDisposed},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"format",{get:function(){return this._format},enumerable:!1,configurable:!0}),i.prototype.getImageType=function(){throw new e.AbstractMethodError},i.prototype.addOwner=function(t){this._owners.add(t)},i.prototype.removeOwner=function(t){this._owners.remove(t)},i.prototype.invalidateOwners=function(){var t=this;this._owners.forEach((function(e){return e.onImageInvalidate(t)}))},i.prototype.clearOwners=function(){var t=this;this._owners.forEach((function(e){return e.onImageClear(t)}))},i.prototype.dispose=function(){this._isDisposed=!0,this.clear()},i.prototype.invalidateMipmaps=function(){this.dispatchEvent(new z(z.INVALIDATE_MIPMAPS,this))},i}(e.AssetBase),Y=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.usages=0,e._invalidMipmaps=!0,e._invalidMapper=!0,e}return G(i,t),i.prototype.getTexture=function(){return this._texture||(this._createTexture(),this._invalid=!0),this._texture},Object.defineProperty(i.prototype,"image",{get:function(){return this._useWeak?this._asset.deref():this._asset},enumerable:!1,configurable:!0}),i.prototype.init=function(e,i){var r=this;t.prototype.init.call(this,e,i,!0),this._onInvalidateMipmapsDelegate=function(t){return r._onInvalidateMipmaps(t)},e.addEventListener(z.INVALIDATE_MIPMAPS,this._onInvalidateMipmapsDelegate)},i.prototype.onClear=function(){var e;this._texture&&(this._texture.dispose(),this._texture=null),null===(e=this.image)||void 0===e||e.removeEventListener(z.INVALIDATE_MIPMAPS,this._onInvalidateMipmapsDelegate),t.prototype.onClear.call(this)},i.prototype.activate=function(t,e){void 0===e&&(e=null),e||(e=H.getDefaultImageSampler());var i=!(!e.mipmap||this._pool.globalDisableMipmap)&&e.mipmap;this._pool.setSamplerAt(t,e),this._pool.context.setTextureAt(t,this.getTexture()),!this._mipmap&&i&&(this._mipmap=!0,this._invalidMipmaps=!0),this._invalidMipmaps&&(this._invalidMipmaps=!1,i&&this._texture.generateMipmaps())},i.prototype._createTexture=function(){throw new e.AbstractMethodError},i.prototype._onInvalidateMipmaps=function(t){this._invalidMipmaps=!0},i}(e.AbstractionBase),q=function(t){function i(i,r,n){void 0===n&&(n=!0);var o=t.call(this)||this;return o._powerOfTwo=!0,o._rect=new e.Rectangle(0,0,Math.round(i),Math.round(r)),o._powerOfTwo=n,o._testDimensions(),o}return G(i,t),Object.defineProperty(i.prototype,"assetType",{get:function(){return i.assetType},enumerable:!1,configurable:!0}),i.prototype.getImageType=function(){return"2d"},Object.defineProperty(i.prototype,"height",{get:function(){return this._rect.height},set:function(t){this._setSize(this._rect.width,t)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"alphaChannel",{get:function(){return this._alphaChannel},set:function(t){this._alphaChannel=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"rect",{get:function(){return this._rect},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"width",{get:function(){return this._rect.width},set:function(t){this._setSize(t,this._rect.height)},enumerable:!1,configurable:!0}),i.prototype._setSize=function(t,e){t=Math.round(t),e=Math.round(e),this._rect.width==t&&this._rect.height==e||(this.clear(),this._rect.width=t,this._rect.height=e,this._testDimensions())},i.prototype._testDimensions=function(){if(this._powerOfTwo&&(!H.isDimensionValid(this._rect.width)||!H.isDimensionValid(this._rect.height)))throw new Error("Invalid dimension: Width and height must be power of 2 and cannot exceed 2048")},Object.defineProperty(i.prototype,"powerOfTwo",{get:function(){return this._powerOfTwo},set:function(t){this._powerOfTwo!=t&&(this._powerOfTwo=t,this._testDimensions())},enumerable:!1,configurable:!0}),i.assetType="[image Image2D]",i}(W),Z=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return G(i,e),i.prototype._createTexture=function(){var e=this.image;this._texture=this._pool.context.createTexture(e.width,e.height,t.ContextGLTextureFormat.BGRA,!0)},i}(Y);function K(t,e){return t.priority-e.priority}var Q=function(){function t(){}return t.createManager=function(t){t=Object.assign({name:J.name+":"+this.managers.length},t||{});var e=new J(t);return this.managers.push(e),this.managers.sort(K),e},t.executeAll=function(){for(var t=0,e=this.managers;t<e.length;t++){var i=e[t],r=i.execute();r&&console.debug("[UnloadService:".concat(i.name,", tick: ").concat(this.tick,"] unloaded:"),r)}this.tick++},t.clearAll=function(){for(var t=0,e=this.managers;t<e.length;t++){e[t].clear()}this.tick=0,this.managers.length=0},t.tick=0,t.managers=[],t}(),J=function(){function t(e){var i;this._tasks=new Set,this.name=t.name,this.priority=0,this.keepAliveTime=1e4,this.exectuionTimeout=5e3,this.unloadTaskShift=1e3,this.maxUnloadTask=100,this._lastExecutionTime=0,this._lastCorrectedTime=-1,e&&(this.name=e.name||this.name,this.priority=null!==(i=e.priority)&&void 0!==i?i:this.priority,this.keepAliveTime=e.keepAliveTime||this.keepAliveTime,this.maxUnloadTask=e.maxUnloadTasks||this.maxUnloadTask,this.exectuionTimeout=e.exectionPeriod||this.exectuionTimeout)}return Object.defineProperty(t.prototype,"correctedTime",{get:function(){var e=performance.now();return(this._lastCorrectedTime<0||this._lastCorrectedTime-e>=t.MIN_QUANT)&&(e+=t.MIN_QUANT),this._lastCorrectedTime=e},enumerable:!1,configurable:!0}),t.prototype.addTask=function(t){return!(!t||this._tasks.has(t))&&(this._tasks.add(t),!0)},t.prototype.removeTask=function(t){return this._tasks.delete(t)},t.prototype.execute=function(t){if(void 0===t&&(t=!1),this._tasks.size){var e=this.correctedTime;if(!t){if(!this._lastExecutionTime)return void(this._lastExecutionTime=e);if(e-this._lastExecutionTime<this.exectuionTimeout)return}this._lastExecutionTime=e;for(var i=[],r=this._tasks.values(),n=0,o=this._tasks.size;n<o;n++){var a=r.next().value;if(a.canUnload&&e-a.lastUsedTime>(a.keepAliveTime||this.keepAliveTime)&&(a.unload(),i[i.length]=a,i.length>=this.maxUnloadTask)){this._lastExecutionTime-=this.exectuionTimeout-this.unloadTaskShift;break}}for(var s=0,l=i;s<l.length;s++){var h=l[s];this._tasks.delete(h)}return i.length}},t.prototype.clear=function(){this._tasks.clear()},t.MIN_QUANT=32,t}(),$=function(){function t(){}return t.ALPHA=8,t.BLUE=4,t.GREEN=2,t.RED=1,t}(),tt=function(){function t(t){this._x=t}return t.prototype.gen=function(){return this._x=16807*this._x%2147483647},t.prototype.genRange=function(t,e){return t+this.gen()%(e-t+1)},t}(),et=2147483647,it=127773,rt=256,nt=255,ot=4096,at=function(){function t(t){this.seed=0,t<=0&&(t=-t%(et-1)+1),t>et-1&&(t=et-1),this.seed=t}return t.prototype.next=function(){var t=this.seed%it*16807-2836*(this.seed/it|0);return t<=0&&(t+=et),t},t}();function st(t){return t*t*(3-2*t)}function lt(t,e,i){return e+t*(i-e)}var ht=function(){function t(t,e){this.gradient=t,this.lattice_selector=e}return t.prototype.noise2=function(t,e,i){var r=e[0]+ot,n=0|r,o=n+1,a=r-(0|r),s=a-1,l=e[1]+ot,h=0|l,u=h+1,c=l-(0|l),p=c-1;i&&(n>=i.wrap_x&&(n-=i.width),o>=i.wrap_x&&(o-=i.width),h>=i.wrap_y&&(h-=i.height),u>=i.wrap_y&&(u-=i.height)),n&=nt,o&=nt,h&=nt,u&=nt;var d=this.lattice_selector[n],f=this.lattice_selector[o],_=this.lattice_selector[d+h],g=this.lattice_selector[f+h],m=this.lattice_selector[d+u],y=this.lattice_selector[f+u],v=st(a),b=st(c),x=this.gradient[t][_],T=a*x[0]+c*x[1],A=this.gradient[t][g],E=lt(v,T,s*A[0]+c*A[1]),w=this.gradient[t][m],S=a*w[0]+p*w[1],C=this.gradient[t][y],R=lt(v,S,s*C[0]+p*C[1]);return lt(b,E,R)},t.prototype.turbulence=function(t,e,i,r,n,o,a,s,l){void 0===l&&(l=null);var h=null;if(o){if(0!==i[0]){var u=Math.floor(s[0]*i[0])/s[0],c=Math.ceil(s[0]*i[0])/s[0];i[0]/u<c/i[0]?i[0]=u:i[0]=c}if(0!==i[1]){u=Math.floor(s[1]*i[1])/s[1],c=Math.ceil(s[1]*i[1])/s[1];i[1]/u<c/i[1]?i[1]=u:i[1]=c}var p=s[0]*i[0]+.5|0,d=s[1]*i[1]+.5|0;h={width:p,height:d,wrap_x:a[0]*i[0]|4096+p,wrap_y:a[1]*i[1]|4096+d}}for(var f=0,_=1,g=[0,0],m=0;m<r;m++){var y=l?l[m]:g,v=[(e[0]+y[0])*i[0]*_,(e[1]+y[1])*i[1]*_],b=this.noise2(t,v,h);f+=(n?b:Math.abs(b))/_,_*=2,h&&(h.width*=2,h.wrap_x=2*h.wrap_x-ot,h.height*=2,h.wrap_y=2*h.wrap_y-ot)}return f},t.fromSeed=function(e){for(var i,r=Array.from({length:514},(function(){return 0})),n=[],o=new at(e),a=0;a<4;a++){n[a]=Array.from({length:514},(function(){return[0,0]}));for(var s=0;s<rt;s++){r[s]=s;for(var l=0;l<2;l++)e=o.next(),o.seed=e,n[a][s][l]=(e%512-rt)/rt;i=Math.sqrt(n[a][s][0]*n[a][s][0]+n[a][s][1]*n[a][s][1]),n[a][s][0]/=i,n[a][s][1]/=i}}for(s=255;s>=0;s--){a=r[s];e=o.next(),o.seed=e;l=e%rt;r[s]=r[l],r[l]=a}for(s=0;s<258;s++){r[rt+s]=r[s];for(a=0;a<4;a++)for(l=0;l<2;l++)n[a][rt+s][l]=n[a][s][l]}return new t(n,r)},t}(),ut=function(){function t(){}return t.drawBitmap=function(i,r,n,o,a,s,l,h,u,c,p){if(void 0===p&&(p=null),p||u!=o||c!=a){p||(p=new e.Matrix).scale(u/o,c/a);var d=Math.sqrt(p.a*p.a+p.b*p.b),f=Math.sqrt(p.c*p.c+p.d*p.d),_=o*d,g=a*f;if(p.tx+=l,p.ty+=h,l=Math.floor(p.tx),h=Math.floor(p.ty),p.invert(),d>=1||f>=1)for(var m=new e.Point,y=l;y<l+_;y++)for(var v=h;v<h+g;v++){m.x=y,m.y=v,m=p.transformPoint(m);var b=t.sampleBilinear(m.x,m.y,i,o,a);t.applyPixel32(s,u,c,y,v,b)}else{var x=new e.Point,T=new e.Point;for(y=l;y<l+_;y++)for(v=h;v<h+g;v++){x.x=y,x.y=v,x=p.transformPoint(x),T.x=y+1,T.y=v+1,T=p.transformPoint(T);b=t.sampleBox(x.x+r,x.y+n,T.x+r,T.y+n,i,o,a);t.applyPixel32(s,u,c,y,v,b)}}p.invert()}else for(y=l;y<l+o;y++)for(v=h;v<h+a;v++){b=t.sample(y-l+r,v-h+n,i,o,a);t.applyPixel32(s,u,c,y,v,b)}},t.applyPixel32=function(t,e,i,r,n,o){if(r=Math.floor(r),n=Math.floor(n),!(r<0||r>=e||n>=i||n<0)){var a=4*(r+n*e);t[a]=o[0],t[a+1]=o[1],t[a+2]=o[2],t[a+3]=o[3],t[a]=255&t[a],t[a+1]=255&t[a+1],t[a+2]=255&t[a+2],t[a+3]=255&t[a+3]}},t.sampleBilinear=function(e,i,r,n,o,a,s){void 0===a&&(a=1),void 0===s&&(s=1);var l=t.sample(e,i,r,n,o),h=t.sample(e+a,i,r,n,o),u=t.sample(e,i+s,r,n,o),c=t.sample(e+a,i+s,r,n,o),p=e;p-=Math.floor(p);var d=t.interpolateColor(l,h,p),f=t.interpolateColor(u,c,p),_=i;return _-=Math.floor(_),t.interpolateColor(d,f,_)},t.sample=function(t,e,i,r,n){t=Math.floor(t),e=Math.floor(e);var o=[0,0,0,0];if(t<0||t>=r||e<0||e>=n)return o;var a=4*(t+e*r);return o[0]=i[a],o[1]=i[a+1],o[2]=i[a+2],o[3]=i[a+3],o},t.sampleBox=function(e,i,r,n,o,a,s){var l,h,u,c,p=0,d=[0,0,0,0],f=Math.floor(i),_=Math.ceil(n);for(f=Math.max(Math.min(f,s-1),0),_=Math.max(Math.min(_,s-1),0),h=f;h<_;h++){c=1,h<i&&(c*=1-(i-h)),h>n&&(c*=1-(h-n));var g=Math.floor(e),m=Math.ceil(r);for(g=Math.max(Math.min(g,a-1),0),m=Math.max(Math.min(m,a-1),0),l=g;l<m;l++){u=c;var y=t.sample(l,h,o,a,s);l<e&&(u*=1-(e-l)),l>r&&(u*=1-(l-r)),d[0]+=y[0]*u,d[1]+=y[1]*u,d[2]+=y[2]*u,d[3]+=y[3]*u,p+=u}}return d[0]/=p,d[1]/=p,d[2]/=p,d[3]/=p,d[0]=255&d[0],d[1]=255&d[1],d[2]=255&d[2],d[3]=255&d[3],d},t.interpolateColor=function(t,e,i){var r=[];return r[0]=t[0]+(e[0]-t[0])*i,r[1]=t[1]+(e[1]-t[1])*i,r[2]=t[2]+(e[2]-t[2])*i,r[3]=t[3]+(e[3]-t[3])*i,r},t}(),ct="WeakRef"in window,pt=!1;function dt(t,e){return void 0===e&&(e=!0),((e?4278190080&t:4278190080)|(255&t)<<16|65280&t|(16711680&t)>>16&255)>>>0}var ft=function(t){function i(e,r,n,o,a,s){void 0===n&&(n=!0),void 0===o&&(o=null),void 0===a&&(a=!0),void 0===s&&(s=null);var l=t.call(this,e,r,a)||this;return l._isSymbolSource=!1,l._isWeakRef=!1,l._unpackPMA=!0,l._locked=!1,l._floodStack=[],l._initalFillColor=null,l._lastUsedFill=null,l.needUpload=!1,l.wasUpload=!1,l.isUnloaded=!1,l.lastUsedTime=0,s&&i.getManager(s),l._transparent=n,l._stage=s,l._initalFillColor=o,l._lastUsedFill=o,l}return G(i,t),i.getManager=function(t){if(!M.ENABLE_UNLOAD_BITMAP||!t)return null;if(this._unloadManager)return this._unloadManager;var e=t.context.hasFence;return this._unloadManager=Q.createManager({name:"BitmapImage2D"+(e?"async":""),priority:0,maxUnloadTasks:e?M.MAX_BITMAP_UNLOAD_TASKS_ASYNC:M.MAX_BITMAP_UNLOAD_TASKS,exectionPeriod:100}),this._unloadManager},i.prototype.syncData=function(t){var e=this;if(void 0===t&&(t=!1),t&&this._asyncRead)return this._asyncRead;if(!t&&this._asyncRead)throw"[SceneImage2D] Synced read not allowed while async read is requested!";if(this.applySymbol(),!this._imageDataDirty)return!!t&&Promise.resolve(!1);var i=this._stage.context;return this._stage.setRenderTarget(this,!0,0,0,!0),this._stage.context.disableStencil(),this._data||(this._data=new Uint8ClampedArray(this.width*this.height*4)),this._asyncRead=i.drawToBitmapImage2D(this,!1,t),this._stage.setRenderTarget(null),t?this._asyncRead.then((function(t){return e._imageDataDirty=!1,e._unpackPMA=!1,e._asyncRead=null,!0})):(this._imageDataDirty=!1,this._unpackPMA=!1,!0)},i.prototype.getDataInternal=function(t,e){if(void 0===t&&(t=!0),void 0===e&&(e=!1),null!==this._initalFillColor&&this.fillRect(this.rect,this._initalFillColor,!e||!this._stage),!e&&this._imageDataDirty)return this.syncData(!1),this._data;if(this.applySymbol(),this._data||!t&&!this._alphaChannel||(this._data=new Uint8ClampedArray(this.width*this.height*4)),this._alphaChannel){for(var i=this._alphaChannel,r=this._data,n=0;n<i.length;n++)i[n]<=1&&(r[4*n+0]=r[4*n+1]=r[4*n+2]=0),r[4*n+3]=i[n];this._alphaChannel=null,this._transparent=!0,this._unpackPMA=!1}return this._data},i.prototype.invalidateGPU=function(){this.needUpload||(this.needUpload=!0,this.invalidate())},i.prototype.invalidate=function(){this._locked||(this.invalidateOwners(),t.prototype.invalidate.call(this))},Object.defineProperty(i.prototype,"canUnload",{get:function(){return!this._locked&&!this._isSymbolSource},enumerable:!1,configurable:!0}),i.prototype.unmarkToUnload=function(){var t;null===(t=i.getManager(this._stage))||void 0===t||t.removeTask(this)},i.prototype.markToUnload=function(){i.getManager(this._stage)&&(this._isSymbolSource||(this.lastUsedTime=i._unloadManager.correctedTime,i._unloadManager.addTask(this)))},i.prototype.unload=function(){this.lastUsedTime=-1,this.dispatchEvent(new e.AssetEvent(i.UNLOAD_EVENT,this)),this.invalidateGPU()},i.prototype.addMipLevel=function(t){this._customMipLevels||(this._customMipLevels=[]),this._customMipLevels.push(t)},Object.defineProperty(i.prototype,"mipLevels",{get:function(){return this._customMipLevels},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"assetType",{get:function(){return i.assetType},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"transparent",{get:function(){return this._transparent},set:function(t){this._transparent=t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"unpackPMA",{get:function(){return this._unpackPMA&&this._transparent},enumerable:!1,configurable:!0}),i.prototype.addLazySymbol=function(t){this._lazySymbol=t,this._isSymbolSource=!0,this._initalFillColor=null,this.invalidateGPU()},i.prototype.applySymbol=function(){return!!this._lazySymbol&&(this._lazySymbol.needParse&&this._lazySymbol.lazyParser(),this._data=this._lazySymbol.definition.data,this._unpackPMA=!this._lazySymbol.definition.isPMA,this._lazySymbol=null,!0)},i.prototype.useWeakRef=function(){pt||(pt=!0,(ct=ct&&M.ENABLE_WEAK_REF)&&console.debug("[ImageBitmap2D Experemental] Use WeakRef for ImageBitmap2D")),ct&&!this._isWeakRef&&(this._isWeakRef=!0,this._finalizer||(this._finalizer=new FinalizationRegistry(this.onAdapterDropped.bind(this))),this.adapter=this._adapter)},i.prototype.unuseWeakRef=function(){this._isWeakRef&&(this._isWeakRef=!1,this._finalizer.unregister(this),this._weakRefAdapter=null,this.adapter=this._adapter)},Object.defineProperty(i.prototype,"isWeakRef",{get:function(){return this._isWeakRef},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"adapter",{get:function(){return(this._weakRefAdapter?this._weakRefAdapter.deref():this._adapter)||this},set:function(t){this._isWeakRef?(this._finalizer.unregister(this),t?(this._weakRefAdapter=new WeakRef(t),this._finalizer.register(t,this.id,this)):this._weakRefAdapter=null,this._adapter=null):this._adapter=t},enumerable:!1,configurable:!0}),i.prototype.onAdapterDropped=function(t){console.debug("[ImageBitmap2D Experemental] Disposing adaptee, GC runs for:",t),this.dispose()},i.prototype.copyTo=function(t){t.setPixels(t.rect,this.data),t.invalidateGPU()},i.prototype.clone=function(){var t=new i(this._rect.width,this._rect.height,this._transparent,null,this._powerOfTwo);return this.copyTo(t),t},i.prototype.colorTransform=function(t,e){var i,r,n,o=this.data;for(i=0;i<t.width;++i)for(r=0;r<t.height;++r)o[n=4*(i+t.x+(r+t.y)*this._rect.width)]=o[n]*e.redMultiplier+e.redOffset,o[n+1]=o[n+1]*e.greenMultiplier+e.greenOffset,o[n+2]=o[n+2]*e.blueMultiplier+e.blueOffset,o[n+3]=o[n+3]*e.alphaMultiplier+e.alphaOffset;this.invalidateGPU()},i.prototype.copyChannel=function(t,e,i,r,n){if(this._lastUsedFill=null,this.unmarkToUnload(),8==n&&(this._imageDataDirty||t._imageDataDirty))null!==this._initalFillColor&&this.fillRect(this._rect,this._initalFillColor),this._stage.filterManager.copyChannel(t,this,e,i,r,n),this._imageDataDirty=!0,this.invalidateOwners();else{var o=t.data,a=this.data,s=Math.round(Math.log(r)/Math.log(2)),l=Math.round(Math.log(n)/Math.log(2)),h=Math.round(e.x),u=Math.round(e.y),c=Math.round(i.x),p=Math.round(i.y),d=void 0,f=void 0,_=void 0,g=void 0,m=void 0;for(f=0;f<e.width;++f)for(_=0;_<e.height;++_)g=4*(f+h+(_+u)*t.width),m=4*(f+c+(_+p)*this._rect.width),d=3==s?o[g+3]:o[g+3]?255*o[g+s]/o[g+3]:0,3==l?(a[m+0]=a[g+3]?a[m+0]*d/a[g+3]:0,a[m+1]=a[g+3]?a[m+1]*d/a[g+3]:0,a[m+2]=a[g+3]?a[m+2]*d/a[g+3]:0,a[m+3]=d):a[m+l]=d;this.invalidateGPU()}},i.prototype.merge=function(t,e,i,r,n,o,a){var s,l,h,u=this.getDataInternal(!0),c=t.data;for(r=~~r,n=~~n,o=~~o,a=~~a,s=0;s<e.width;++s)for(l=0;l<e.height;++l)u[h=4*(s+e.x+(l+e.y)*this.width)]=~~((c[h]*r+u[h]*(256-r))/256),u[h+1]=~~((c[h+1]*n+u[h+1]*(256-n))/256),u[h+2]=~~((c[h+2]*o+u[h+2]*(256-o))/256),u[h+3]=~~((c[h+3]*a+u[h+3]*(256-a))/256);this.invalidateGPU()},i.prototype.dispose=function(){var e;null===(e=i.getManager(this._stage))||void 0===e||e.removeTask(this),this._isWeakRef&&this._finalizer.unregister(this),this._data=null,this._rect=null,this._transparent=null,this._locked=null,t.prototype.dispose.call(this)},i.prototype.getColorBoundsRect=function(t,i,r){void 0===r&&(r=!0);var n=new Uint32Array(this.getDataInternal(!0).buffer),o=this.rect;i=dt(i,this._transparent),t=dt(t,this._transparent);for(var a=o.width,s=o.height,l=0,h=0,u=!1,c=0;c<o.height;c++)for(var p=0;p<o.width;p++){var d=n[c*o.width+p];((d=(d&t)>>>0)===i&&r||d!==i&&!r)&&(u=!0,a=p<a?p:a,l=p>l?p:l,s=c<s?c:s,h=c>h?c:h)}return u?new e.Rectangle(a,s,l-a+1,h-s+1):new e.Rectangle(0,0,0,0)},i.prototype.hitTest=function(t,i,r,n,o){if(r instanceof e.Point)return(this.getPixel32(r.x-t.x,r.y-t.y)>>24&255)>=i;if(r instanceof e.Rectangle){if((r=r.clone()).x-=t.x,r.y-=t.y,!this._rect.intersects(r))return!1;for(var a=r.y;a<r.bottom;a++)for(var s=r.x;s<r.right;s++){if((this.getPixel32(s,a)>>24&255)>=i)return!0}}else null!==r&&console.warn("[BitmapImage2D] HitTest not implemented for:",r.assetType);return!1},i.prototype.floodFill=function(t,i,r){var n=t,o=i;t|=0,i|=0;var a=new Uint32Array(this.getDataInternal(!0).buffer),s=this._rect.width,l=this._rect.height,h=this._floodStack;h.length=s*l*2;var u=a[t+i*s],c=e.ColorUtils.float32ColorToARGB(r),p=c[0],d=c[1],f=c[2],_=c[3],g=((p=this._transparent?p:255)<<24|(_=_*p/255|0)<<16|(f=f*p/255|0)<<8|(d=d*p/255|0))>>>0;if(g!==u){var m,y,v=0,b=0;for(h[b++]=t,h[b++]=i;b>0;){if(b/2>a.length)throw"[BitmapImage2D] FloodFill bug, to many interation: ".concat(n,":").concat(o);for(i=h[--b],v=t=h[--b];v>=0&&a[i*s+v]===u;)v--;for(v++,m=y=!1;v<s&&a[i*s+v]===u;)a[i*s+v]=g,!m&&i>0&&a[(i-1)*s+v]===u?(h[b++]=v,h[b++]=i-1,m=!0):m&&i>0&&a[(i-1)*s+v]!==u&&(m=!1),!y&&i<l-1&&a[(i+1)*s+v]===u?(h[b++]=v,h[b++]=i+1,y=!0):y&&i<l-1&&a[(i+1)*s+v]!==u&&(y=!1),v++}this.invalidateGPU()}},i.prototype.noise=function(t,e,i,r,n){void 0===e&&(e=0),void 0===i&&(i=255),void 0===r&&(r=7),void 0===n&&(n=!1);for(var o=new tt(t),a=this.width,s=this.height,l=this.getDataInternal(!0),h=0;h<s;h++)for(var u=0;u<a;u