System.register(["./json-asset-607afd3e.js"],(function(t){"use strict";var e,i,n,h,s,r,u,a;return{setters:[function(t){e=t.b8,i=t.bh,n=t.du,h=t.az,s=t.H,r=t.I,u=t.x,a=t.ao}],execute:function(){var o,_;function f(t){return--t,t|=t>>16,t|=t>>8,t|=t>>4,t|=t>>2,t|=t>>1,++t}function c(t,e){return Math.ceil(t/e)*e}t({P:void 0,R:void 0,n:f}),function(t){t[t.OPAQUE=0]="OPAQUE",t[t.TRANSPARENT=1]="TRANSPARENT",t[t.OVERLAY=2]="OVERLAY"}(o||(o=t("R",{}))),function(t){t[t.DEFAULT=1]="DEFAULT",t[t.FORWARD=2]="FORWARD",t[t.SHADOWCAST=4]="SHADOWCAST"}(_||(_=t("P",{}))),t("T",function(){function t(t){this._device=void 0,this._format=u.UNKNOWN,this._formatSize=0,this._chunks=[],this._chunkCount=0,this._handles=[],this._region0=new a,this._region1=new a,this._region2=new a,this._roundUpFn=null,this._bufferViewCtor=Uint8Array,this._channels=4,this._alignment=1,this._device=t}var o=t.prototype;return o.initialize=function(t){var n=e[t.format];this._format=t.format,this._formatSize=n.size,this._channels=n.count,this._bufferViewCtor=i(n),this._roundUpFn=t.roundUpFn||null,this._alignment=t.alignment||1,t.inOrderFree&&(this.alloc=this._McDonaldAlloc)},o.destroy=function(){for(var t=0;t<this._chunkCount;++t)this._chunks[t].texture.destroy();this._chunks.length=0,this._handles.length=0},o.alloc=function(t,e){t=c(t,this._alignment);var i=-1,n=-1;if(void 0!==e&&(i=e,n=this._findAvailableSpace(t,i)),n<0)for(var h=0;h<this._chunkCount&&(i=h,!((n=this._findAvailableSpace(t,i))>=0));++h);if(n>=0){var s=this._chunks[i];s.start+=t;var r={chunkIdx:i,start:n,end:n+t,texture:s.texture};return this._handles.push(r),r}var u=Math.sqrt(t/this._formatSize),a=this._roundUpFn&&this._roundUpFn(u,this._formatSize)||Math.max(1024,f(u)),o=this._chunks[this.createChunk(a)];o.start+=t;var _={chunkIdx:this._chunkCount-1,start:0,end:t,texture:o.texture};return this._handles.push(_),_},o.free=function(t){for(var e=0;e<this._handles.length;++e)if(this._handles[e]===t)return this._chunks[t.chunkIdx].end=t.end,void this._handles.splice(e,1)},o.createChunk=function(t){var e=t*t*this._formatSize;n("TextureBufferPool: Allocate chunk "+this._chunkCount+", size: "+e+", format: "+this._format);var i={texture:this._device.createTexture(new h(s.TEX2D,r.SAMPLED|r.TRANSFER_DST,this._format,t,t)),size:e,start:0,end:e};return this._chunks[this._chunkCount]=i,this._chunkCount++},o.update=function(t,e){var i=[],n=[],h=t.start/this._formatSize,s=e.byteLength/this._formatSize,r=h%t.texture.width,u=Math.floor(h/t.texture.width),a=Math.min(t.texture.width-r,s),o=0;r>0&&(this._region0.texOffset.x=r,this._region0.texOffset.y=u,this._region0.texExtent.width=a,this._region0.texExtent.height=1,i.push(new this._bufferViewCtor(e,o*this._formatSize,a*this._channels)),n.push(this._region0),r=0,u+=1,s-=a,o+=a),s>0&&(this._region1.texOffset.x=r,this._region1.texOffset.y=u,s>t.texture.width?(this._region1.texExtent.width=t.texture.width,this._region1.texExtent.height=Math.floor(s/t.texture.width),a=this._region1.texExtent.width*this._region1.texExtent.height):(a=s,this._region1.texExtent.width=a,this._region1.texExtent.height=1),i.push(new this._bufferViewCtor(e,o*this._formatSize,a*this._channels)),n.push(this._region1),r=0,u+=this._region1.texExtent.height,s-=a,o+=a),s>0&&(this._region2.texOffset.x=r,this._region2.texOffset.y=u,this._region2.texExtent.width=s,this._region2.texExtent.height=1,i.push(new this._bufferViewCtor(e,o*this._formatSize,s*this._channels)),n.push(this._region2)),this._device.copyBuffersToTexture(i,t.texture,n)},o._findAvailableSpace=function(t,e){var i=this._chunks[e],n=!1,h=i.start;if(h+t<=i.size)n=!0;else{h=0;for(var s=this._handles.filter((function(t){return t.chunkIdx===e})).sort((function(t,e){return t.start-e.start})),r=0;r<s.length;r++){var u=s[r];if(h+t<=u.start){n=!0;break}h=u.end}!n&&h+t<=i.size&&(n=!0)}return n?h:-1},o._McDonaldAlloc=function(t){t=c(t,this._alignment);for(var e=0;e<this._chunkCount;++e){var i=this._chunks[e],n=!1,h=i.start;if(h+t<=i.end?n=!0:h>i.end?h+t<=i.size?n=!0:t<=i.end&&(i.start=h=0,n=!0):h===i.end&&(i.start=h=0,i.end=i.size,t<=i.end&&(n=!0)),n){i.start+=t;var s={chunkIdx:e,start:h,end:h+t,texture:i.texture};return this._handles.push(s),s}}var r=Math.sqrt(t/this._formatSize),u=this._roundUpFn&&this._roundUpFn(r,this._formatSize)||Math.max(1024,f(r)),a=this._chunks[this.createChunk(u)];a.start+=t;var o={chunkIdx:this._chunkCount,start:0,end:t,texture:a.texture};return this._handles.push(o),o},t}())}}}));
