expxagents 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,156 @@
1
+ import{D as R,p as F,e as d,q as O,a as B,w as p,g as z,X as ye,O as P,T as S,aj as Ce,z as q,ak as Ne,S as g,aa as V,j as y,y as C,H as M,M as Z,al as Q,am as De,an as J,ao as Ie,ap as Ge,A as Ue,R as Fe,k as A}from"./index-BwP29LGC.js";import{e as Oe,G as Pe,c as Me,b as Le,U as we,B as ee,d as N,f as te,g as He}from"./BufferResource-C0G45m2G.js";import{R as Ve,S as Xe,d as ke}from"./RenderTargetSystem-B0x2vSUR.js";function We(){const{userAgent:t}=R.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}class re{constructor(){this._tempState=F.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,r,n){const s=e.renderer,i=this._didUploadHash[n.uid];s.shader.bind(n,i),i||(this._didUploadHash[n.uid]=!0),s.shader.updateUniformGroup(s.globalUniforms.uniformGroup),s.geometry.bind(r,n.glProgram)}execute(e,r){const n=e.renderer;this._tempState.blendMode=r.blendMode,n.state.set(this._tempState);const s=r.textures.textures;for(let i=0;i<r.textures.count;i++)n.texture.bind(s[i],i);n.geometry.draw(r.topology,r.size,r.start)}}re.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var v=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(v||{});class je{constructor(e,r){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class ne{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new O({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:r}=this,n=this.getGlBuffer(e);r.bindBuffer(n.type,n.buffer)}bindBufferBase(e,r){const{_gl:n}=this;this._boundBufferBases[r]!==e&&(this._boundBufferBases[r]=e,e._lastBindBaseLocation=r,n.bindBufferBase(n.UNIFORM_BUFFER,r,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let r=this.getLastBindBaseLocation(e);if(r>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,r;let n=0,s=this._nextBindBaseIndex;for(;n<2;){s>=this._maxBindings&&(s=this._minBaseLocation,n++);const i=this._boundBufferBases[s];if(i&&i._lastBindCallId===this._bindCallId){s++;continue}break}return r=s,this._nextBindBaseIndex=s+1,n>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[r]=null,r)}getLastBindBaseLocation(e){const r=e._lastBindBaseLocation;return this._boundBufferBases[r]===e?r:-1}bindBufferRange(e,r,n,s){const{_gl:i}=this;n||(n=0),r||(r=0),this._boundBufferBases[r]=null,i.bindBufferRange(i.UNIFORM_BUFFER,r||0,e.buffer,n*256,s||256)}updateBuffer(e){const{_gl:r}=this,n=this.getGlBuffer(e);if(e._updateID===n.updateID)return n;n.updateID=e._updateID,r.bindBuffer(n.type,n.buffer);const s=e.data,i=e.descriptor.usage&B.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;return s?n.byteLength>=s.byteLength?r.bufferSubData(n.type,0,s,0,e._updateSize/s.BYTES_PER_ELEMENT):(n.byteLength=s.byteLength,r.bufferData(n.type,s,i)):(n.byteLength=e.descriptor.size,r.bufferData(n.type,n.byteLength,i)),n}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){const{_gl:r}=this;let n=v.ARRAY_BUFFER;e.descriptor.usage&B.INDEX?n=v.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&B.UNIFORM&&(n=v.UNIFORM_BUFFER);const s=new je(r.createBuffer(),n);return e._gpuData[this._renderer.uid]=s,this._managedBuffers.add(e),s}resetState(){this._boundBufferBases=Object.create(null)}}ne.extension={type:[d.WebGLSystem],name:"buffer"};const L=class se{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...se.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(p("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=R.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const n=this._renderer.background.alpha<1,s=e.premultipliedAlpha??!0,i=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:n,premultipliedAlpha:s,antialias:i,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&p("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:r}=this;(r.width<e.width||r.height<e.height)&&(r.width=Math.max(e.width,e.width),r.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof R.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const r=this._renderer.view.canvas;r.addEventListener("webglcontextlost",this.handleContextLost,!1),r.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,r){let n;const s=this.canvas;if(e===2&&(n=s.getContext("webgl2",r)),!n&&(n=s.getContext("webgl",r),!n))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=n,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,r={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...r,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...r,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const n=e.getExtension("WEBGL_provoking_vertex");n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{var r;this.gl.isContextLost()&&((r=this.extensions.loseContext)==null||r.restoreContext())},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){var r;const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),(r=this.extensions.loseContext)==null||r.loseContext()}forceContextLoss(){var e;(e=this.extensions.loseContext)==null||e.loseContext(),this._contextLossForced=!0}validateContext(e){const r=e.getContextAttributes();r&&!r.stencil&&p("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const n=this.supports,s=this.webGLVersion===2,i=this.extensions;n.uint32Indices=s||!!i.uint32ElementIndex,n.uniformBufferObject=s,n.vertexArrayObject=s||!!i.vertexArrayObject,n.srgbTextures=s||!!i.srgb,n.nonPowOf2wrapping=s,n.nonPowOf2mipmaps=s,n.msaa=s,n.uint32Indices||p("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};L.extension={type:[d.WebGLSystem],name:"context"};L.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Ke=L;var G=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(G||{}),w=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(w||{}),l=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(l||{});const X={uint8x2:l.UNSIGNED_BYTE,uint8x4:l.UNSIGNED_BYTE,sint8x2:l.BYTE,sint8x4:l.BYTE,unorm8x2:l.UNSIGNED_BYTE,unorm8x4:l.UNSIGNED_BYTE,snorm8x2:l.BYTE,snorm8x4:l.BYTE,uint16x2:l.UNSIGNED_SHORT,uint16x4:l.UNSIGNED_SHORT,sint16x2:l.SHORT,sint16x4:l.SHORT,unorm16x2:l.UNSIGNED_SHORT,unorm16x4:l.UNSIGNED_SHORT,snorm16x2:l.SHORT,snorm16x4:l.SHORT,float16x2:l.HALF_FLOAT,float16x4:l.HALF_FLOAT,float32:l.FLOAT,float32x2:l.FLOAT,float32x3:l.FLOAT,float32x4:l.FLOAT,uint32:l.UNSIGNED_INT,uint32x2:l.UNSIGNED_INT,uint32x3:l.UNSIGNED_INT,uint32x4:l.UNSIGNED_INT,sint32:l.INT,sint32x2:l.INT,sint32x3:l.INT,sint32x4:l.INT};function $e(t){return X[t]??X.float32}const Ye={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class ze{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class ie{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new O({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const r=this._renderer.context.extensions.vertexArrayObject;r&&(e.createVertexArray=()=>r.createVertexArrayOES(),e.bindVertexArray=s=>r.bindVertexArrayOES(s),e.deleteVertexArray=s=>r.deleteVertexArrayOES(s));const n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(s,i,a,o)=>{n.drawArraysInstancedANGLE(s,i,a,o)},e.drawElementsInstanced=(s,i,a,o,u)=>{n.drawElementsInstancedANGLE(s,i,a,o,u)},e.vertexAttribDivisor=(s,i)=>n.vertexAttribDivisorANGLE(s,i)),this._activeGeometry=null,this._activeVao=null}bind(e,r){const n=this.gl;this._activeGeometry=e;const s=this.getVao(e,r);this._activeVao!==s&&(this._activeVao=s,n.bindVertexArray(s)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,r=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){const s=e.buffers[n];r.updateBuffer(s)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,r){const n=e.attributes,s=r._attributeData;for(const i in s)if(!n[i])throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`)}getSignature(e,r){const n=e.attributes,s=r._attributeData,i=["g",e.uid];for(const a in n)s[a]&&i.push(a,s[a].location);return i.join("-")}getVao(e,r){var n;return((n=e._gpuData[this._renderer.uid])==null?void 0:n.vaoCache[r._key])||this.initGeometryVao(e,r)}initGeometryVao(e,r,n=!0){const s=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(r),this.checkCompatibility(e,r);const a=this.getSignature(e,r);let o=e._gpuData[this._renderer.uid];o||(o=new ze,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));const u=o.vaoCache;let c=u[a];if(c)return u[r._key]=c,c;Oe(e,r._attributeData);const _=e.buffers;c=s.createVertexArray(),s.bindVertexArray(c);for(let f=0;f<_.length;f++){const h=_[f];i.bind(h)}return this.activateVao(e,r),u[r._key]=c,u[a]=c,s.bindVertexArray(null),c}onGeometryUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];if(!n)return;const s=n.vaoCache;if(!r)for(const i in s)this._activeVao!==s[i]&&this.resetState(),this.gl.deleteVertexArray(s[i])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,r){var o;const n=this._renderer.gl,s=this._renderer.buffer,i=e.attributes;e.indexBuffer&&s.bind(e.indexBuffer);let a=null;for(const u in i){const c=i[u],_=c.buffer,f=s.getGlBuffer(_),h=r._attributeData[u];if(h){a!==f&&(s.bind(_),a=f);const m=h.location;n.enableVertexAttribArray(m);const b=z(c.format),E=$e(c.format);if(((o=h.format)==null?void 0:o.substring(1,4))==="int"?n.vertexAttribIPointer(m,b.size,E,c.stride,c.offset):n.vertexAttribPointer(m,b.size,E,b.normalised,c.stride,c.offset),c.instance)if(this.hasInstance){const Be=c.divisor??1;n.vertexAttribDivisor(m,Be)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,r,n,s){const{gl:i}=this._renderer,a=this._activeGeometry,o=Ye[e||a.topology];if(s??(s=a.instanceCount),a.indexBuffer){const u=a.indexBuffer.data.BYTES_PER_ELEMENT,c=u===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT;s!==1?i.drawElementsInstanced(o,r||a.indexBuffer.data.length,c,(n||0)*u,s):i.drawElements(o,r||a.indexBuffer.data.length,c,(n||0)*u)}else s!==1?i.drawArraysInstanced(o,n||0,r||a.getSize(),s):i.drawArrays(o,n||0,r||a.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}ie.extension={type:[d.WebGLSystem],name:"geometry"};const qe=new Ce({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),H=class ae{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:n}={...ae.defaultOptions,...e};this.useBackBuffer=r,this._antialias=n,this._renderer.context.supports.msaa||(p("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=F.for2d();const s=new ye({vertex:`
2
+ attribute vec2 aPosition;
3
+ out vec2 vUv;
4
+
5
+ void main() {
6
+ gl_Position = vec4(aPosition, 0.0, 1.0);
7
+
8
+ vUv = (aPosition + 1.0) / 2.0;
9
+
10
+ // flip dem UVs
11
+ vUv.y = 1.0 - vUv.y;
12
+ }`,fragment:`
13
+ in vec2 vUv;
14
+ out vec4 finalColor;
15
+
16
+ uniform sampler2D uTexture;
17
+
18
+ void main() {
19
+ finalColor = texture(uTexture, vUv);
20
+ }`,name:"big-triangle"});this._bigTriangleShader=new P({glProgram:s,resources:{uTexture:S.WHITE.source}})}renderStart(e){const r=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!r.isRoot,this._useBackBufferThisRender){const n=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=n.colorTexture,e.target=this._getBackBufferTexture(n.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:qe,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new S({source:new q({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};H.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};H.defaultOptions={useBackBuffer:!1};let Ze=H;class oe{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}oe.extension={type:[d.WebGLSystem],name:"colorMask"};class ce{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,r){this._renderer.geometry.bind(e,r.glProgram)}finishRenderPass(){}draw(e){const r=this._renderer,{geometry:n,shader:s,state:i,skipSync:a,topology:o,size:u,start:c,instanceCount:_}=e;r.shader.bind(s,a),r.geometry.bind(n,r.shader._activeProgram),i&&r.state.set(i),r.geometry.draw(o,u,c,_??n.instanceCount)}destroy(){this._renderer=null}}ce.extension={type:[d.WebGLSystem],name:"encoder"};class ue{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ne(this.maxTextures,e);const r=this._renderer.context.webGLVersion===2;this.maxUniformBindings=r?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}ue.extension={type:[d.WebGLSystem],name:"limits"};class Qe{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[]}}class _e{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:g.NONE},this._renderTargetStencilState=Object.create(null),e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:g.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=g.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,r){const n=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,i=Pe[e],a=this._stencilCache;if(n.stencilMode=e,n.stencilReference=r,e===g.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,s.disable(s.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,s.enable(s.STENCIL_TEST)),(e!==a.stencilMode||a.stencilReference!==r)&&(a.stencilMode=e,a.stencilReference=r,s.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare],r,255),s.stencilOp(s.KEEP,s.KEEP,this._stencilOpsMapping[i.stencilBack.passOp]))}}_e.extension={type:[d.WebGLSystem],name:"stencil"};const fe={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function Je(t){const e=t.map(i=>({data:i,offset:0,size:0})),r=16;let n=0,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(n=fe[a.data.type],!n)throw new Error(`Unknown type ${a.data.type}`);a.data.size>1&&(n=Math.max(n,r)*a.data.size);const o=n===12?16:n;a.size=n;const u=s%r;u>0&&r-u<o?s+=(r-u)%16:s+=(n-u%n)%n,a.offset=s,s+=n}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function et(t,e){const r=Math.max(fe[t.data.type]/16,1),n=t.data.value.length/t.data.size,s=(4-n%4)%4,i=t.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
21
+ v = uv.${t.data.name};
22
+ offset += ${e};
23
+
24
+ arrayOffset = offset;
25
+
26
+ t = 0;
27
+
28
+ for(var i=0; i < ${t.data.size*r}; i++)
29
+ {
30
+ for(var j = 0; j < ${n}; j++)
31
+ {
32
+ ${i}[arrayOffset++] = v[t++];
33
+ }
34
+ ${s!==0?`arrayOffset += ${s};`:""}
35
+ }
36
+ `}function tt(t){return Me(t,"uboStd40",et,Le)}class he extends we{constructor(){super({createUboElements:Je,generateUboSync:tt})}}he.extension={type:[d.WebGLSystem],name:"ubo"};class rt{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V;const e=this._renderer.gl;this._drawBuffersCache=[];for(let r=1;r<=16;r++)this._drawBuffersCache[r]=Array.from({length:r},(n,s)=>e.COLOR_ATTACHMENT0+s)}copyToTexture(e,r,n,s,i){const a=this._renderTargetSystem,o=this._renderer,u=a.getGpuRenderTarget(e),c=o.gl;return this.finishRenderPass(e),c.bindFramebuffer(c.FRAMEBUFFER,u.resolveTargetFramebuffer),o.texture.bind(r,0),c.copyTexSubImage2D(c.TEXTURE_2D,0,i.x,i.y,n.x,n.y,s.width,s.height),r}startRenderPass(e,r=!0,n,s,i=0,a=0){const o=this._renderTargetSystem,u=e.colorTexture,c=o.getGpuRenderTarget(e);if(a!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(i>0){if(c.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}let _=s.y;e.isRoot&&(_=u.pixelHeight-s.height-s.y),e.colorTextures.forEach(m=>{this._renderer.texture.unbind(m)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,c.framebuffer),!e.isRoot&&(c._attachedMipLevel!==i||c._attachedLayer!==a)&&(e.colorTextures.forEach((m,b)=>{const E=this._renderer.texture.getGlSource(m);if(E.target===f.TEXTURE_2D){if(a!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_2D,E.texture,i)}else if(E.target===f.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");f.framebufferTextureLayer(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,E.texture,i,a)}else if(E.target===f.TEXTURE_CUBE_MAP){if(a<0||a>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_CUBE_MAP_POSITIVE_X+a,E.texture,i)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),c._attachedMipLevel=i,c._attachedLayer=a),e.colorTextures.length>1&&this._setDrawBuffers(e,f);const h=this._viewPortCache;(h.x!==s.x||h.y!==_||h.width!==s.width||h.height!==s.height)&&(h.x=s.x,h.y=_,h.width=s.width,h.height=s.height,f.viewport(s.x,_,s.width,s.height)),!c.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(c),this.clear(e,r,n)}finishRenderPass(e){const n=this._renderTargetSystem.getGpuRenderTarget(e);if(!n.msaa)return;const s=this._renderer.gl;s.bindFramebuffer(s.FRAMEBUFFER,n.resolveTargetFramebuffer),s.bindFramebuffer(s.READ_FRAMEBUFFER,n.framebuffer),s.blitFramebuffer(0,0,n.width,n.height,0,0,n.width,n.height,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.FRAMEBUFFER,n.framebuffer)}initGpuRenderTarget(e){const n=this._renderer.gl,s=new Qe;return s._attachedMipLevel=0,s._attachedLayer=0,e.colorTexture instanceof y?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),s.framebuffer=null,s):(this._initColor(e,s),n.bindFramebuffer(n.FRAMEBUFFER,null),s)}destroyGpuRenderTarget(e){const r=this._renderer.gl;e.framebuffer&&(r.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(r.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(r.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(n=>{r.deleteRenderbuffer(n)}),e.msaaRenderBuffer=null}clear(e,r,n,s,i=0,a=0){if(!r)return;if(a!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const o=this._renderTargetSystem;typeof r=="boolean"&&(r=r?C.ALL:C.NONE);const u=this._renderer.gl;if(r&C.COLOR){n??(n=o.defaultClearColor);const c=this._clearColorCache,_=n;(c[0]!==_[0]||c[1]!==_[1]||c[2]!==_[2]||c[3]!==_[3])&&(c[0]=_[0],c[1]=_[1],c[2]=_[2],c[3]=_[3],u.clearColor(_[0],_[1],_[2],_[3]))}u.clear(r)}resizeGpuRenderTarget(e){if(e.isRoot)return;const n=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,n),(e.stencil||e.depth)&&this._resizeStencil(n)}_initColor(e,r){const n=this._renderer,s=n.gl,i=s.createFramebuffer();if(r.resolveTargetFramebuffer=i,s.bindFramebuffer(s.FRAMEBUFFER,i),r.width=e.colorTexture.source.pixelWidth,r.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((o,u)=>{const c=o.source;c.antialias&&(n.context.supports.msaa?r.msaa=!0:p("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(c,0);const _=n.texture.getGlSource(c),f=_.texture;if(_.target===s.TEXTURE_2D)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_2D,f,0);else if(_.target===s.TEXTURE_2D_ARRAY){if(n.context.webGLVersion<2)throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");s.framebufferTextureLayer(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,f,0,0)}else if(_.target===s.TEXTURE_CUBE_MAP)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_CUBE_MAP_POSITIVE_X,f,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),r.msaa){const o=s.createFramebuffer();r.framebuffer=o,s.bindFramebuffer(s.FRAMEBUFFER,o),e.colorTextures.forEach((u,c)=>{const _=s.createRenderbuffer();r.msaaRenderBuffer[c]=_})}else r.framebuffer=i;this._resizeColor(e,r)}_resizeColor(e,r){const n=e.colorTexture.source;if(r.width=n.pixelWidth,r.height=n.pixelHeight,r._attachedMipLevel=0,r._attachedLayer=0,e.colorTextures.forEach((s,i)=>{i!==0&&s.source.resize(n.width,n.height,n._resolution)}),r.msaa){const s=this._renderer,i=s.gl,a=r.framebuffer;i.bindFramebuffer(i.FRAMEBUFFER,a),e.colorTextures.forEach((o,u)=>{const c=o.source;s.texture.bindSource(c,0);const f=s.texture.getGlSource(c).internalFormat,h=r.msaaRenderBuffer[u];i.bindRenderbuffer(i.RENDERBUFFER,h),i.renderbufferStorageMultisample(i.RENDERBUFFER,4,f,c.pixelWidth,c.pixelHeight),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+u,i.RENDERBUFFER,h)})}}_initStencil(e){if(e.framebuffer===null)return;const r=this._renderer.gl,n=r.createRenderbuffer();e.depthStencilRenderBuffer=n,r.bindRenderbuffer(r.RENDERBUFFER,n),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,n),this._resizeStencil(e)}_resizeStencil(e){const r=this._renderer.gl;r.bindRenderbuffer(r.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?r.renderbufferStorageMultisample(r.RENDERBUFFER,4,r.DEPTH24_STENCIL8,e.width,e.height):r.renderbufferStorage(r.RENDERBUFFER,this._renderer.context.webGLVersion===2?r.DEPTH24_STENCIL8:r.DEPTH_STENCIL,e.width,e.height)}prerender(e){const r=e.colorTexture.resource;this._renderer.context.multiView&&y.test(r)&&this._renderer.context.ensureCanvasSize(r)}postrender(e){if(this._renderer.context.multiView&&y.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,n=e.colorTexture;n.context2D.drawImage(r,0,n.pixelHeight-r.height)}}_setDrawBuffers(e,r){const n=e.colorTextures.length,s=this._drawBuffersCache[n];if(this._renderer.context.webGLVersion===1){const i=this._renderer.context.extensions.drawBuffers;i?i.drawBuffersWEBGL(s):p("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else r.drawBuffers(s)}}class le extends Ve{constructor(e){super(e),this.adaptor=new rt,this.adaptor.init(e,this)}}le.extension={type:[d.WebGLSystem],name:"renderTarget"};function nt(t,e){const r=[],n=[`
37
+ var g = s.groups;
38
+ var sS = r.shader;
39
+ var p = s.glProgram;
40
+ var ugS = r.uniformGroup;
41
+ var resources;
42
+ `];let s=!1,i=0;const a=e._getProgramData(t.glProgram);for(const u in t.groups){const c=t.groups[u];r.push(`
43
+ resources = g[${u}].resources;
44
+ `);for(const _ in c.resources){const f=c.resources[_];if(f instanceof M)if(f.ubo){const h=t._uniformBindMap[u][Number(_)];r.push(`
45
+ sS.bindUniformBlock(
46
+ resources[${_}],
47
+ '${h}',
48
+ ${t.glProgram._uniformBlockData[h].index}
49
+ );
50
+ `)}else r.push(`
51
+ ugS.updateUniformGroup(resources[${_}], p, sD);
52
+ `);else if(f instanceof ee){const h=t._uniformBindMap[u][Number(_)];r.push(`
53
+ sS.bindUniformBlock(
54
+ resources[${_}],
55
+ '${h}',
56
+ ${t.glProgram._uniformBlockData[h].index}
57
+ );
58
+ `)}else if(f instanceof q){const h=t._uniformBindMap[u][_],m=a.uniformData[h];m&&(s||(s=!0,n.push(`
59
+ var tS = r.texture;
60
+ `)),e._gl.uniform1i(m.location,i),r.push(`
61
+ tS.bind(resources[${_}], ${i});
62
+ `),i++)}}}const o=[...n,...r].join(`
63
+ `);return new Function("r","s","sD",o)}class st{constructor(e,r){this.program=e,this.uniformData=r,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function k(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function D(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function de(t,e){switch(t){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return D(2*e);case"bvec3":return D(3*e);case"bvec4":return D(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let T=null;const W={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},it={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function me(t,e){if(!T){const r=Object.keys(W);T={};for(let n=0;n<r.length;++n){const s=r[n];T[t[s]]=W[s]}}return T[e]}function at(t,e){const r=me(t,e);return it[r]||"float32"}function ot(t,e,r=!1){const n={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let a=0;a<s;a++){const o=e.getActiveAttrib(t,a);if(o.name.startsWith("gl_"))continue;const u=at(e,o.type);n[o.name]={location:0,format:u,stride:z(u).stride,offset:0,instance:!1,start:0}}const i=Object.keys(n);if(r){i.sort((a,o)=>a>o?1:-1);for(let a=0;a<i.length;a++)n[i[a]].location=a,e.bindAttribLocation(t,a,i[a]);e.linkProgram(t)}else for(let a=0;a<i.length;a++)n[i[a]].location=e.getAttribLocation(t,i[a]);return n}function ct(t,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<n;s++){const i=e.getActiveUniformBlockName(t,s),a=e.getUniformBlockIndex(t,i),o=e.getActiveUniformBlockParameter(t,s,e.UNIFORM_BLOCK_DATA_SIZE);r[i]={name:i,index:a,size:o}}return r}function ut(t,e){const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let s=0;s<n;s++){const i=e.getActiveUniform(t,s),a=i.name.replace(/\[.*?\]$/,""),o=!!i.name.match(/\[.*?\]$/),u=me(e,i.type);r[a]={name:a,index:s,type:u,size:i.size,isArray:o,value:de(u,i.size)}}return r}function j(t,e){const r=t.getShaderSource(e).split(`
64
+ `).map((c,_)=>`${_}: ${c}`),n=t.getShaderInfoLog(e),s=n.split(`
65
+ `),i={},a=s.map(c=>parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(c=>c&&!i[c]?(i[c]=!0,!0):!1),o=[""];a.forEach(c=>{r[c-1]=`%c${r[c-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=r.join(`
66
+ `);o[0]=u,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function _t(t,e,r,n){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||j(t,r),t.getShaderParameter(n,t.COMPILE_STATUS)||j(t,n),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function ft(t,e){const r=k(t,t.VERTEX_SHADER,e.vertex),n=k(t,t.FRAGMENT_SHADER,e.fragment),s=t.createProgram();t.attachShader(s,r),t.attachShader(s,n);const i=e.transformFeedbackVaryings;i&&(typeof t.transformFeedbackVaryings!="function"?p("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(s,i.names,i.bufferMode==="separate"?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)||_t(t,s,r,n),e._attributeData=ot(s,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=ut(s,t),e._uniformBlockData=ct(s,t),t.deleteShader(r),t.deleteShader(n);const a={};for(const u in e._uniformData){const c=e._uniformData[u];a[u]={location:t.getUniformLocation(s,u),value:de(c.type,c.size)}}return new st(s,a)}const x={textureCount:0,blockIndex:0};class Ee{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,r){if(this._setProgram(e.glProgram),r)return;x.textureCount=0,x.blockIndex=0;let n=this._shaderSyncFunctions[e.glProgram._key];n||(n=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),n(this._renderer,e,x)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,x)}bindUniformBlock(e,r,n=0){const s=this._renderer.buffer,i=this._getProgramData(this._activeProgram),a=e._bufferResource;a||this._renderer.ubo.updateUniformGroup(e);const o=e.buffer,u=s.updateBuffer(o),c=s.freeLocationForBufferBase(u);if(a){const{offset:f,size:h}=e;f===0&&h===o.data.byteLength?s.bindBufferBase(u,c):s.bindBufferRange(u,c,f)}else s.getLastBindBaseLocation(u)!==c&&s.bindBufferBase(u,c);const _=this._activeProgram._uniformBlockData[r].index;i.uniformBlockBindings[n]!==c&&(i.uniformBlockBindings[n]=c,this._renderer.gl.uniformBlockBinding(i.program,_,c))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const r=this._getProgramData(e);this._gl.useProgram(r.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const r=e._key;return this._programDataHash[r]=ft(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,r){return nt(e,r)}resetState(){this._activeProgram=null}}Ee.extension={type:[d.WebGLSystem],name:"shader"};const ht={f32:`if (cv !== v) {
67
+ cu.value = v;
68
+ gl.uniform1f(location, v);
69
+ }`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
70
+ cv[0] = v[0];
71
+ cv[1] = v[1];
72
+ gl.uniform2f(location, v[0], v[1]);
73
+ }`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
74
+ cv[0] = v[0];
75
+ cv[1] = v[1];
76
+ cv[2] = v[2];
77
+ gl.uniform3f(location, v[0], v[1], v[2]);
78
+ }`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
79
+ cv[0] = v[0];
80
+ cv[1] = v[1];
81
+ cv[2] = v[2];
82
+ cv[3] = v[3];
83
+ gl.uniform4f(location, v[0], v[1], v[2], v[3]);
84
+ }`,i32:`if (cv !== v) {
85
+ cu.value = v;
86
+ gl.uniform1i(location, v);
87
+ }`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
88
+ cv[0] = v[0];
89
+ cv[1] = v[1];
90
+ gl.uniform2i(location, v[0], v[1]);
91
+ }`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
92
+ cv[0] = v[0];
93
+ cv[1] = v[1];
94
+ cv[2] = v[2];
95
+ gl.uniform3i(location, v[0], v[1], v[2]);
96
+ }`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
97
+ cv[0] = v[0];
98
+ cv[1] = v[1];
99
+ cv[2] = v[2];
100
+ cv[3] = v[3];
101
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
102
+ }`,u32:`if (cv !== v) {
103
+ cu.value = v;
104
+ gl.uniform1ui(location, v);
105
+ }`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
106
+ cv[0] = v[0];
107
+ cv[1] = v[1];
108
+ gl.uniform2ui(location, v[0], v[1]);
109
+ }`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
110
+ cv[0] = v[0];
111
+ cv[1] = v[1];
112
+ cv[2] = v[2];
113
+ gl.uniform3ui(location, v[0], v[1], v[2]);
114
+ }`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
115
+ cv[0] = v[0];
116
+ cv[1] = v[1];
117
+ cv[2] = v[2];
118
+ cv[3] = v[3];
119
+ gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
120
+ }`,bool:`if (cv !== v) {
121
+ cu.value = v;
122
+ gl.uniform1i(location, v);
123
+ }`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
124
+ cv[0] = v[0];
125
+ cv[1] = v[1];
126
+ gl.uniform2i(location, v[0], v[1]);
127
+ }`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
128
+ cv[0] = v[0];
129
+ cv[1] = v[1];
130
+ cv[2] = v[2];
131
+ gl.uniform3i(location, v[0], v[1], v[2]);
132
+ }`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
133
+ cv[0] = v[0];
134
+ cv[1] = v[1];
135
+ cv[2] = v[2];
136
+ cv[3] = v[3];
137
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
138
+ }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},lt={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function dt(t,e){const r=[`
139
+ var v = null;
140
+ var cv = null;
141
+ var cu = null;
142
+ var t = 0;
143
+ var gl = renderer.gl;
144
+ var name = null;
145
+ `];for(const n in t.uniforms){if(!e[n]){t.uniforms[n]instanceof M?t.uniforms[n].ubo?r.push(`
146
+ renderer.shader.bindUniformBlock(uv.${n}, "${n}");
147
+ `):r.push(`
148
+ renderer.shader.updateUniformGroup(uv.${n});
149
+ `):t.uniforms[n]instanceof ee&&r.push(`
150
+ renderer.shader.bindBufferResource(uv.${n}, "${n}");
151
+ `);continue}const s=t.uniformStructures[n];let i=!1;for(let a=0;a<N.length;a++){const o=N[a];if(s.type===o.type&&o.test(s)){r.push(`name = "${n}";`,N[a].uniform),i=!0;break}}if(!i){const o=(s.size===1?ht:lt)[s.type].replace("location",`ud["${n}"].location`);r.push(`
152
+ cu = ud["${n}"];
153
+ cv = cu.value;
154
+ v = uv["${n}"];
155
+ ${o};`)}}return new Function("ud","uv","renderer","syncData",r.join(`
156
+ `))}class be{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,r,n){const s=this._renderer.shader._getProgramData(r);(!e.isStatic||e._dirtyId!==s.uniformDirtyGroups[e.uid])&&(s.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,r)(s.uniformData,e.uniforms,this._renderer,n))}_getUniformSyncFunction(e,r){var n;return((n=this._uniformGroupSyncHash[e._signature])==null?void 0:n[r._key])||this._createUniformSyncFunction(e,r)}_createUniformSyncFunction(e,r){const n=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),s=this._getSignature(e,r._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(e,r._uniformData)),n[r._key]=this._cache[s],n[r._key]}_generateUniformsSync(e,r){return dt(e,r)}_getSignature(e,r,n){const s=e.uniforms,i=[`${n}-`];for(const a in s)i.push(a),r[a]&&i.push(r[a].type);return i.join("-")}destroy(){this._renderer=null,this._cache=null}}be.extension={type:[d.WebGLSystem],name:"uniformGroup"};function mt(t){const e={};if(e.normal=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e.add=[t.ONE,t.ONE],e.multiply=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.screen=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e["screen-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.erase=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],!(t instanceof R.get().getWebGLRenderingContext()))e.min=[t.ONE,t.ONE,t.ONE,t.ONE,t.MIN,t.MIN],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,t.MAX,t.MAX];else{const n=t.getExtension("EXT_blend_minmax");n&&(e.min=[t.ONE,t.ONE,t.ONE,t.ONE,n.MIN_EXT,n.MIN_EXT],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,n.MAX_EXT,n.MAX_EXT])}return e}const Et=0,bt=1,pt=2,St=3,Rt=4,gt=5,pe=class U{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[Et]=this.setBlend,this.map[bt]=this.setOffset,this.map[pt]=this.setCullFace,this.map[St]=this.setDepthTest,this.map[Rt]=this.setFrontFace,this.map[gt]=this.setDepthMask,this.checks=[],this.defaultState=F.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=mt(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let r=this.stateId^e.data,n=0;for(;r;)r&1&&this.map[n].call(this,!!(e.data&1<<n)),r>>=1,n++;this.stateId=e.data}for(let r=0;r<this.checks.length;r++)this.checks[r](this,e)}forceState(e){e||(e=this.defaultState);for(let r=0;r<this.map.length;r++)this.map[r].call(this,!!(e.data&1<<r));for(let r=0;r<this.checks.length;r++)this.checks[r](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(U._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(U._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const r=this._invertFrontFace?!e:e;this._glFrontFace!==r&&(this._glFrontFace=r,this.gl.frontFace(this.gl[r?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const r=this.blendModesMap[e],n=this.gl;r.length===2?n.blendFunc(r[0],r[1]):n.blendFuncSeparate(r[0],r[1],r[2],r[3]),r.length===6?(this._blendEq=!0,n.blendEquationSeparate(r[4],r[5])):this._blendEq&&(this._blendEq=!1,n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD))}setPolygonOffset(e,r){this.gl.polygonOffset(e,r)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,r){const n=this.checks.indexOf(e);r&&n===-1?this.checks.push(e):!r&&n!==-1&&this.checks.splice(n,1)}static _checkBlendMode(e,r){e.setBlendMode(r.blendMode)}static _checkPolygonOffset(e,r){e.setPolygonOffset(1,r.polygonOffset)}destroy(){this.gl=null,this.checks.length=0}};pe.extension={type:[d.WebGLSystem],name:"state"};let Tt=pe;class xt{constructor(e){this.target=w.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=l.UNSIGNED_BYTE,this.internalFormat=G.RGBA,this.format=G.RGBA,this.samplerType=0}destroy(){}}const vt={id:"buffer",upload(t,e,r,n,s,i=!1){const a=s||e.target;!i&&e.width===t.width&&e.height===t.height?r.texSubImage2D(a,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(a,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},At={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},Bt={id:"compressed",upload(t,e,r,n,s,i){const a=s??e.target;r.pixelStorei(r.UNPACK_ALIGNMENT,4);let o=t.pixelWidth,u=t.pixelHeight;const c=!!At[t.format];for(let _=0;_<t.resource.length;_++){const f=t.resource[_];c?r.compressedTexImage2D(a,_,e.internalFormat,o,u,0,f):r.texImage2D(a,_,e.internalFormat,o,u,0,e.format,e.type,f),o=Math.max(o>>1,1),u=Math.max(u>>1,1)}}},K=["right","left","top","bottom","front","back"];function yt(t){return{id:"cube",upload(e,r,n,s){const i=e.faces;for(let a=0;a<K.length;a++){const o=K[a],u=i[o];(t[u.uploadMethodId]||t.image).upload(u,r,n,s,w.TEXTURE_CUBE_MAP_POSITIVE_X+a,(r._layerInitMask&1<<a)===0),r._layerInitMask|=1<<a}r.width=e.pixelWidth,r.height=e.pixelHeight}}}const Se={id:"image",upload(t,e,r,n,s,i=!1){const a=s||e.target,o=t.pixelWidth,u=t.pixelHeight,c=t.resourceWidth,_=t.resourceHeight,f=n===2,h=i||e.width!==o||e.height!==u,m=c>=o&&_>=u,b=t.resource;(f?Ct:Nt)(r,a,e,o,u,c,_,b,h,m),e.width=o,e.height=u}};function Ct(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,i,a,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,o)}function Nt(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,r.format,r.type,o)}const Dt=We(),It={id:"video",upload(t,e,r,n,s,i=Dt){if(!t.isValid){const a=s??e.target;r.texImage2D(a,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Se.upload(t,e,r,n,s,i)}},$={linear:9729,nearest:9728},Gt={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},I={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Ut={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Y(t,e,r,n,s,i,a,o){const u=i;if(!o||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const c=I[a?"clamp-to-edge":t.addressModeU],_=I[a?"clamp-to-edge":t.addressModeV],f=I[a?"clamp-to-edge":t.addressModeW];e[s](u,e.TEXTURE_WRAP_S,c),e[s](u,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[s](u,e.TEXTURE_WRAP_R,f)}if((!o||t.magFilter!=="linear")&&e[s](u,e.TEXTURE_MAG_FILTER,$[t.magFilter]),r){if(!o||t.mipmapFilter!=="linear"){const c=Gt[t.minFilter][t.mipmapFilter];e[s](u,e.TEXTURE_MIN_FILTER,c)}}else e[s](u,e.TEXTURE_MIN_FILTER,$[t.minFilter]);if(n&&t.maxAnisotropy>1){const c=Math.min(t.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](u,n.TEXTURE_MAX_ANISOTROPY_EXT,c)}t.compare&&e[s](u,e.TEXTURE_COMPARE_FUNC,Ut[t.compare])}function Ft(t){return{r8unorm:t.RED,r8snorm:t.RED,r8uint:t.RED,r8sint:t.RED,r16uint:t.RED,r16sint:t.RED,r16float:t.RED,rg8unorm:t.RG,rg8snorm:t.RG,rg8uint:t.RG,rg8sint:t.RG,r32uint:t.RED,r32sint:t.RED,r32float:t.RED,rg16uint:t.RG,rg16sint:t.RG,rg16float:t.RG,rgba8unorm:t.RGBA,"rgba8unorm-srgb":t.RGBA,rgba8snorm:t.RGBA,rgba8uint:t.RGBA,rgba8sint:t.RGBA,bgra8unorm:t.RGBA,"bgra8unorm-srgb":t.RGBA,rgb9e5ufloat:t.RGB,rgb10a2unorm:t.RGBA,rg11b10ufloat:t.RGB,rg32uint:t.RG,rg32sint:t.RG,rg32float:t.RG,rgba16uint:t.RGBA,rgba16sint:t.RGBA,rgba16float:t.RGBA,rgba32uint:t.RGBA,rgba32sint:t.RGBA,rgba32float:t.RGBA,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT,depth24plus:t.DEPTH_COMPONENT,"depth24plus-stencil8":t.DEPTH_STENCIL,depth32float:t.DEPTH_COMPONENT,"depth32float-stencil8":t.DEPTH_STENCIL}}function Ot(t,e){let r={},n=t.RGBA;return t instanceof R.get().getWebGLRenderingContext()?e.srgb&&(r={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(r={"rgba8unorm-srgb":t.SRGB8_ALPHA8,"bgra8unorm-srgb":t.SRGB8_ALPHA8},n=t.RGBA8),{r8unorm:t.R8,r8snorm:t.R8_SNORM,r8uint:t.R8UI,r8sint:t.R8I,r16uint:t.R16UI,r16sint:t.R16I,r16float:t.R16F,rg8unorm:t.RG8,rg8snorm:t.RG8_SNORM,rg8uint:t.RG8UI,rg8sint:t.RG8I,r32uint:t.R32UI,r32sint:t.R32I,r32float:t.R32F,rg16uint:t.RG16UI,rg16sint:t.RG16I,rg16float:t.RG16F,rgba8unorm:t.RGBA,...r,rgba8snorm:t.RGBA8_SNORM,rgba8uint:t.RGBA8UI,rgba8sint:t.RGBA8I,bgra8unorm:n,rgb9e5ufloat:t.RGB9_E5,rgb10a2unorm:t.RGB10_A2,rg11b10ufloat:t.R11F_G11F_B10F,rg32uint:t.RG32UI,rg32sint:t.RG32I,rg32float:t.RG32F,rgba16uint:t.RGBA16UI,rgba16sint:t.RGBA16I,rgba16float:t.RGBA16F,rgba32uint:t.RGBA32UI,rgba32sint:t.RGBA32I,rgba32float:t.RGBA32F,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT16,depth24plus:t.DEPTH_COMPONENT24,"depth24plus-stencil8":t.DEPTH24_STENCIL8,depth32float:t.DEPTH_COMPONENT32F,"depth32float-stencil8":t.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function Pt(t){return{r8unorm:t.UNSIGNED_BYTE,r8snorm:t.BYTE,r8uint:t.UNSIGNED_BYTE,r8sint:t.BYTE,r16uint:t.UNSIGNED_SHORT,r16sint:t.SHORT,r16float:t.HALF_FLOAT,rg8unorm:t.UNSIGNED_BYTE,rg8snorm:t.BYTE,rg8uint:t.UNSIGNED_BYTE,rg8sint:t.BYTE,r32uint:t.UNSIGNED_INT,r32sint:t.INT,r32float:t.FLOAT,rg16uint:t.UNSIGNED_SHORT,rg16sint:t.SHORT,rg16float:t.HALF_FLOAT,rgba8unorm:t.UNSIGNED_BYTE,"rgba8unorm-srgb":t.UNSIGNED_BYTE,rgba8snorm:t.BYTE,rgba8uint:t.UNSIGNED_BYTE,rgba8sint:t.BYTE,bgra8unorm:t.UNSIGNED_BYTE,"bgra8unorm-srgb":t.UNSIGNED_BYTE,rgb9e5ufloat:t.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:t.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:t.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:t.UNSIGNED_INT,rg32sint:t.INT,rg32float:t.FLOAT,rgba16uint:t.UNSIGNED_SHORT,rgba16sint:t.SHORT,rgba16float:t.HALF_FLOAT,rgba32uint:t.UNSIGNED_INT,rgba32sint:t.INT,rgba32float:t.FLOAT,stencil8:t.UNSIGNED_BYTE,depth16unorm:t.UNSIGNED_SHORT,depth24plus:t.UNSIGNED_INT,"depth24plus-stencil8":t.UNSIGNED_INT_24_8,depth32float:t.FLOAT,"depth32float-stencil8":t.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Mt(t){return{"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP,"1d":null,"3d":(t==null?void 0:t.TEXTURE_3D)||null,"2d-array":(t==null?void 0:t.TEXTURE_2D_ARRAY)||null,"cube-array":(t==null?void 0:t.TEXTURE_CUBE_MAP_ARRAY)||null}}const Lt=4;class Re{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new O({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const r={image:Se,buffer:vt,video:It,compressed:Bt};this._uploads={...r,cube:yt(r)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Ot(e,this._renderer.context.extensions),this._mapFormatToType=Pt(e),this._mapFormatToFormat=Ft(e),this._mapViewDimensionToGlTarget=Mt(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let r=0;r<16;r++)this.bind(S.EMPTY,r)}initSource(e){this.bind(e)}bind(e,r=0){const n=e.source;e?(this.bindSource(n,r),this._useSeparateSamplers&&this._bindSampler(n.style,r)):(this.bindSource(null,r),this._useSeparateSamplers&&this._bindSampler(null,r))}bindSource(e,r=0){const n=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e||(e=S.EMPTY.source);const s=this.getGlSource(e);n.bindTexture(s.target,s.texture)}}_bindSampler(e,r=0){const n=this._gl;if(!e){this._boundSamplers[r]=null,n.bindSampler(r,null);return}const s=this._getGlSampler(e);this._boundSamplers[r]!==s&&(this._boundSamplers[r]=s,n.bindSampler(r,s))}unbind(e){const r=e.source,n=this._boundTextures,s=this._gl;for(let i=0;i<n.length;i++)if(n[i]===r){this._activateLocation(i);const a=this.getGlSource(r);s.bindTexture(a.target,null),n[i]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const r=this._gl,n=new xt(r.createTexture());if(n.type=this._mapFormatToType[e.format],n.internalFormat=this._mapFormatToInternalFormat[e.format],n.format=this._mapFormatToFormat[e.format],n.target=this._mapViewDimensionToGlTarget[e.viewDimension],n.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.uploadMethodId==="cube"&&(n.target=r.TEXTURE_CUBE_MAP),e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const i=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(i))+1}return e._gpuData[this._renderer.uid]=n,this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),this.updateStyle(e,!1),n}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,r){const n=this._gl,s=this.getGlSource(e);n.bindTexture(s.target,s.texture),this._boundTextures[this._activeTextureLocation]=e,Y(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||(this.unbind(e),this._gl.deleteTexture(n.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const r=this._gl,n=this.getGlSource(e);r.bindTexture(n.target,n.texture),this._boundTextures[this._activeTextureLocation]=e;const s=e.alphaMode==="premultiply-alpha-on-upload";if(this._premultiplyAlpha!==s&&(this._premultiplyAlpha=s,r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,n,r,this._renderer.context.webGLVersion);else if(n.target===r.TEXTURE_2D)this._initEmptyTexture2D(n,e);else if(n.target===r.TEXTURE_2D_ARRAY)this._initEmptyTexture2DArray(n,e);else if(n.target===r.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(n,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(n,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,r=!0){r&&this.bindSource(e,0);const n=this.getGlSource(e);this._gl.generateMipmap(n.target)}_initEmptyTexture2D(e,r){const n=this._gl;n.texImage2D(n.TEXTURE_2D,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let s=Math.max(r.pixelWidth>>1,1),i=Math.max(r.pixelHeight>>1,1);for(let a=1;a<r.mipLevelCount;a++)n.texImage2D(n.TEXTURE_2D,a,e.internalFormat,s,i,0,e.format,e.type,null),s=Math.max(s>>1,1),i=Math.max(i>>1,1)}_initEmptyTexture2DArray(e,r){if(this._renderer.context.webGLVersion!==2)throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");const n=this._gl,s=Math.max(r.arrayLayerCount|0,1);n.texImage3D(n.TEXTURE_2D_ARRAY,0,e.internalFormat,r.pixelWidth,r.pixelHeight,s,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++)n.texImage3D(n.TEXTURE_2D_ARRAY,o,e.internalFormat,i,a,s,0,e.format,e.type,null),i=Math.max(i>>1,1),a=Math.max(a>>1,1)}_initEmptyTextureCube(e,r){const n=this._gl,s=6;for(let o=0;o<s;o++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++){for(let u=0;u<s;u++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+u,o,e.internalFormat,i,a,0,e.format,e.type,null);i=Math.max(i>>1,1),a=Math.max(a>>1,1)}}_applyMipRange(e,r){if(this._renderer.context.webGLVersion!==2)return;const n=this._gl,s=Math.max((r.mipLevelCount|0)-1,0);n.texParameteri(e.target,n.TEXTURE_BASE_LEVEL,0),n.texParameteri(e.target,n.TEXTURE_MAX_LEVEL,s)}_initSampler(e){const r=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,Y(e,r,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",n,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:n,height:s}=this.getPixels(e),i=R.get().createCanvas();i.width=n,i.height=s;const a=i.getContext("2d");if(a){const o=a.createImageData(n,s);o.data.set(r),a.putImageData(o,0,0)}return i}getPixels(e){const r=e.source.resolution,n=e.frame,s=Math.max(Math.round(n.width*r),1),i=Math.max(Math.round(n.height*r),1),a=new Uint8Array(Lt*s*i),o=this._renderer,u=o.renderTarget.getRenderTarget(e),c=o.renderTarget.getGpuRenderTarget(u),_=o.gl;return _.bindFramebuffer(_.FRAMEBUFFER,c.resolveTargetFramebuffer),_.readPixels(Math.round(n.x*r),Math.round(n.y*r),s,i,_.RGBA,_.UNSIGNED_BYTE,a),{pixels:new Uint8ClampedArray(a.buffer),width:s,height:i}}destroy(){this._managedTextures.destroy(),this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){this._activeTextureLocation=-1,this._boundTextures.fill(S.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Re.extension={type:[d.WebGLSystem],name:"texture"};class ge{contextChange(e){const r=new M({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new Z,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),n=e.limits.maxBatchableTextures,s=Q({name:"graphics",bits:[De,Ie(n),te,J]});this.shader=new P({glProgram:s,resources:{localUniforms:r,batchSamplers:Ge(n)}})}execute(e,r){const n=r.context,s=n.customShader||this.shader,i=e.renderer,a=i.graphicsContext,{batcher:o,instructions:u}=a.getContextRenderData(n);s.groups[0]=i.globalUniforms.bindGroup,i.state.set(e.state),i.shader.bind(s),i.geometry.bind(o.geometry,s.glProgram);const c=u.instructions;for(let _=0;_<u.instructionSize;_++){const f=c[_];if(f.size){for(let h=0;h<f.textures.count;h++)i.texture.bind(f.textures.textures[h],h);i.geometry.draw(f.topology,f.size,f.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}ge.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class Te{init(){const e=Q({name:"mesh",bits:[te,He,J]});this._shader=new P({glProgram:e,resources:{uTexture:S.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new Z}}}})}execute(e,r){const n=e.renderer;let s=r._shader;if(s){if(!s.glProgram){p("Mesh shader has no glProgram",r.shader);return}}else{s=this._shader;const i=r.texture,a=i.source;s.resources.uTexture=a,s.resources.uSampler=a.style,s.resources.textureUniforms.uniforms.uTextureMatrix=i.textureMatrix.mapCoord}s.groups[100]=n.globalUniforms.bindGroup,s.groups[101]=e.localUniformsBindGroup,n.encoder.draw({geometry:r._geometry,shader:s,state:r.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Te.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const wt=[...Xe,he,Ze,Ke,ue,ne,Re,le,ie,be,Ee,ce,Tt,_e,oe],Ht=[...ke],Vt=[re,Te,ge],xe=[],ve=[],Ae=[];A.handleByNamedList(d.WebGLSystem,xe);A.handleByNamedList(d.WebGLPipes,ve);A.handleByNamedList(d.WebGLPipesAdaptor,Ae);A.add(...wt,...Ht,...Vt);class jt extends Ue{constructor(){const e={name:"webgl",type:Fe.WEBGL,systems:xe,renderPipes:ve,renderPipeAdaptors:Ae};super(e)}}export{jt as WebGLRenderer};
@@ -0,0 +1,156 @@
1
+ import{D as R,p as F,e as d,q as O,a as B,w as p,g as z,X as ye,O as P,T as S,aj as Ce,z as q,ak as Ne,S as g,aa as V,j as y,y as C,H as M,M as Z,al as Q,am as De,an as J,ao as Ie,ap as Ge,A as Ue,R as Fe,k as A}from"./index-D-7NXU4-.js";import{e as Oe,G as Pe,c as Me,b as Le,U as we,B as ee,d as N,f as te,g as He}from"./BufferResource-D7n27_ZU.js";import{R as Ve,S as Xe,d as ke}from"./RenderTargetSystem-DSsFNic8.js";function We(){const{userAgent:t}=R.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}class re{constructor(){this._tempState=F.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,r,n){const s=e.renderer,i=this._didUploadHash[n.uid];s.shader.bind(n,i),i||(this._didUploadHash[n.uid]=!0),s.shader.updateUniformGroup(s.globalUniforms.uniformGroup),s.geometry.bind(r,n.glProgram)}execute(e,r){const n=e.renderer;this._tempState.blendMode=r.blendMode,n.state.set(this._tempState);const s=r.textures.textures;for(let i=0;i<r.textures.count;i++)n.texture.bind(s[i],i);n.geometry.draw(r.topology,r.size,r.start)}}re.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var v=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(v||{});class je{constructor(e,r){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class ne{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new O({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:r}=this,n=this.getGlBuffer(e);r.bindBuffer(n.type,n.buffer)}bindBufferBase(e,r){const{_gl:n}=this;this._boundBufferBases[r]!==e&&(this._boundBufferBases[r]=e,e._lastBindBaseLocation=r,n.bindBufferBase(n.UNIFORM_BUFFER,r,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let r=this.getLastBindBaseLocation(e);if(r>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,r;let n=0,s=this._nextBindBaseIndex;for(;n<2;){s>=this._maxBindings&&(s=this._minBaseLocation,n++);const i=this._boundBufferBases[s];if(i&&i._lastBindCallId===this._bindCallId){s++;continue}break}return r=s,this._nextBindBaseIndex=s+1,n>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[r]=null,r)}getLastBindBaseLocation(e){const r=e._lastBindBaseLocation;return this._boundBufferBases[r]===e?r:-1}bindBufferRange(e,r,n,s){const{_gl:i}=this;n||(n=0),r||(r=0),this._boundBufferBases[r]=null,i.bindBufferRange(i.UNIFORM_BUFFER,r||0,e.buffer,n*256,s||256)}updateBuffer(e){const{_gl:r}=this,n=this.getGlBuffer(e);if(e._updateID===n.updateID)return n;n.updateID=e._updateID,r.bindBuffer(n.type,n.buffer);const s=e.data,i=e.descriptor.usage&B.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;return s?n.byteLength>=s.byteLength?r.bufferSubData(n.type,0,s,0,e._updateSize/s.BYTES_PER_ELEMENT):(n.byteLength=s.byteLength,r.bufferData(n.type,s,i)):(n.byteLength=e.descriptor.size,r.bufferData(n.type,n.byteLength,i)),n}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){const{_gl:r}=this;let n=v.ARRAY_BUFFER;e.descriptor.usage&B.INDEX?n=v.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&B.UNIFORM&&(n=v.UNIFORM_BUFFER);const s=new je(r.createBuffer(),n);return e._gpuData[this._renderer.uid]=s,this._managedBuffers.add(e),s}resetState(){this._boundBufferBases=Object.create(null)}}ne.extension={type:[d.WebGLSystem],name:"buffer"};const L=class se{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...se.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(p("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=R.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const n=this._renderer.background.alpha<1,s=e.premultipliedAlpha??!0,i=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:n,premultipliedAlpha:s,antialias:i,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&p("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:r}=this;(r.width<e.width||r.height<e.height)&&(r.width=Math.max(e.width,e.width),r.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof R.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const r=this._renderer.view.canvas;r.addEventListener("webglcontextlost",this.handleContextLost,!1),r.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,r){let n;const s=this.canvas;if(e===2&&(n=s.getContext("webgl2",r)),!n&&(n=s.getContext("webgl",r),!n))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=n,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,r={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...r,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...r,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const n=e.getExtension("WEBGL_provoking_vertex");n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{var r;this.gl.isContextLost()&&((r=this.extensions.loseContext)==null||r.restoreContext())},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){var r;const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),(r=this.extensions.loseContext)==null||r.loseContext()}forceContextLoss(){var e;(e=this.extensions.loseContext)==null||e.loseContext(),this._contextLossForced=!0}validateContext(e){const r=e.getContextAttributes();r&&!r.stencil&&p("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const n=this.supports,s=this.webGLVersion===2,i=this.extensions;n.uint32Indices=s||!!i.uint32ElementIndex,n.uniformBufferObject=s,n.vertexArrayObject=s||!!i.vertexArrayObject,n.srgbTextures=s||!!i.srgb,n.nonPowOf2wrapping=s,n.nonPowOf2mipmaps=s,n.msaa=s,n.uint32Indices||p("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};L.extension={type:[d.WebGLSystem],name:"context"};L.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Ke=L;var G=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(G||{}),w=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(w||{}),l=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(l||{});const X={uint8x2:l.UNSIGNED_BYTE,uint8x4:l.UNSIGNED_BYTE,sint8x2:l.BYTE,sint8x4:l.BYTE,unorm8x2:l.UNSIGNED_BYTE,unorm8x4:l.UNSIGNED_BYTE,snorm8x2:l.BYTE,snorm8x4:l.BYTE,uint16x2:l.UNSIGNED_SHORT,uint16x4:l.UNSIGNED_SHORT,sint16x2:l.SHORT,sint16x4:l.SHORT,unorm16x2:l.UNSIGNED_SHORT,unorm16x4:l.UNSIGNED_SHORT,snorm16x2:l.SHORT,snorm16x4:l.SHORT,float16x2:l.HALF_FLOAT,float16x4:l.HALF_FLOAT,float32:l.FLOAT,float32x2:l.FLOAT,float32x3:l.FLOAT,float32x4:l.FLOAT,uint32:l.UNSIGNED_INT,uint32x2:l.UNSIGNED_INT,uint32x3:l.UNSIGNED_INT,uint32x4:l.UNSIGNED_INT,sint32:l.INT,sint32x2:l.INT,sint32x3:l.INT,sint32x4:l.INT};function $e(t){return X[t]??X.float32}const Ye={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class ze{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class ie{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new O({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const r=this._renderer.context.extensions.vertexArrayObject;r&&(e.createVertexArray=()=>r.createVertexArrayOES(),e.bindVertexArray=s=>r.bindVertexArrayOES(s),e.deleteVertexArray=s=>r.deleteVertexArrayOES(s));const n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(s,i,a,o)=>{n.drawArraysInstancedANGLE(s,i,a,o)},e.drawElementsInstanced=(s,i,a,o,u)=>{n.drawElementsInstancedANGLE(s,i,a,o,u)},e.vertexAttribDivisor=(s,i)=>n.vertexAttribDivisorANGLE(s,i)),this._activeGeometry=null,this._activeVao=null}bind(e,r){const n=this.gl;this._activeGeometry=e;const s=this.getVao(e,r);this._activeVao!==s&&(this._activeVao=s,n.bindVertexArray(s)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,r=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){const s=e.buffers[n];r.updateBuffer(s)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,r){const n=e.attributes,s=r._attributeData;for(const i in s)if(!n[i])throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`)}getSignature(e,r){const n=e.attributes,s=r._attributeData,i=["g",e.uid];for(const a in n)s[a]&&i.push(a,s[a].location);return i.join("-")}getVao(e,r){var n;return((n=e._gpuData[this._renderer.uid])==null?void 0:n.vaoCache[r._key])||this.initGeometryVao(e,r)}initGeometryVao(e,r,n=!0){const s=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(r),this.checkCompatibility(e,r);const a=this.getSignature(e,r);let o=e._gpuData[this._renderer.uid];o||(o=new ze,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));const u=o.vaoCache;let c=u[a];if(c)return u[r._key]=c,c;Oe(e,r._attributeData);const _=e.buffers;c=s.createVertexArray(),s.bindVertexArray(c);for(let f=0;f<_.length;f++){const h=_[f];i.bind(h)}return this.activateVao(e,r),u[r._key]=c,u[a]=c,s.bindVertexArray(null),c}onGeometryUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];if(!n)return;const s=n.vaoCache;if(!r)for(const i in s)this._activeVao!==s[i]&&this.resetState(),this.gl.deleteVertexArray(s[i])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,r){var o;const n=this._renderer.gl,s=this._renderer.buffer,i=e.attributes;e.indexBuffer&&s.bind(e.indexBuffer);let a=null;for(const u in i){const c=i[u],_=c.buffer,f=s.getGlBuffer(_),h=r._attributeData[u];if(h){a!==f&&(s.bind(_),a=f);const m=h.location;n.enableVertexAttribArray(m);const b=z(c.format),E=$e(c.format);if(((o=h.format)==null?void 0:o.substring(1,4))==="int"?n.vertexAttribIPointer(m,b.size,E,c.stride,c.offset):n.vertexAttribPointer(m,b.size,E,b.normalised,c.stride,c.offset),c.instance)if(this.hasInstance){const Be=c.divisor??1;n.vertexAttribDivisor(m,Be)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,r,n,s){const{gl:i}=this._renderer,a=this._activeGeometry,o=Ye[e||a.topology];if(s??(s=a.instanceCount),a.indexBuffer){const u=a.indexBuffer.data.BYTES_PER_ELEMENT,c=u===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT;s!==1?i.drawElementsInstanced(o,r||a.indexBuffer.data.length,c,(n||0)*u,s):i.drawElements(o,r||a.indexBuffer.data.length,c,(n||0)*u)}else s!==1?i.drawArraysInstanced(o,n||0,r||a.getSize(),s):i.drawArrays(o,n||0,r||a.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}ie.extension={type:[d.WebGLSystem],name:"geometry"};const qe=new Ce({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),H=class ae{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:n}={...ae.defaultOptions,...e};this.useBackBuffer=r,this._antialias=n,this._renderer.context.supports.msaa||(p("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=F.for2d();const s=new ye({vertex:`
2
+ attribute vec2 aPosition;
3
+ out vec2 vUv;
4
+
5
+ void main() {
6
+ gl_Position = vec4(aPosition, 0.0, 1.0);
7
+
8
+ vUv = (aPosition + 1.0) / 2.0;
9
+
10
+ // flip dem UVs
11
+ vUv.y = 1.0 - vUv.y;
12
+ }`,fragment:`
13
+ in vec2 vUv;
14
+ out vec4 finalColor;
15
+
16
+ uniform sampler2D uTexture;
17
+
18
+ void main() {
19
+ finalColor = texture(uTexture, vUv);
20
+ }`,name:"big-triangle"});this._bigTriangleShader=new P({glProgram:s,resources:{uTexture:S.WHITE.source}})}renderStart(e){const r=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!r.isRoot,this._useBackBufferThisRender){const n=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=n.colorTexture,e.target=this._getBackBufferTexture(n.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:qe,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new S({source:new q({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};H.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};H.defaultOptions={useBackBuffer:!1};let Ze=H;class oe{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}oe.extension={type:[d.WebGLSystem],name:"colorMask"};class ce{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,r){this._renderer.geometry.bind(e,r.glProgram)}finishRenderPass(){}draw(e){const r=this._renderer,{geometry:n,shader:s,state:i,skipSync:a,topology:o,size:u,start:c,instanceCount:_}=e;r.shader.bind(s,a),r.geometry.bind(n,r.shader._activeProgram),i&&r.state.set(i),r.geometry.draw(o,u,c,_??n.instanceCount)}destroy(){this._renderer=null}}ce.extension={type:[d.WebGLSystem],name:"encoder"};class ue{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ne(this.maxTextures,e);const r=this._renderer.context.webGLVersion===2;this.maxUniformBindings=r?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}ue.extension={type:[d.WebGLSystem],name:"limits"};class Qe{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[]}}class _e{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:g.NONE},this._renderTargetStencilState=Object.create(null),e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:g.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=g.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,r){const n=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,i=Pe[e],a=this._stencilCache;if(n.stencilMode=e,n.stencilReference=r,e===g.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,s.disable(s.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,s.enable(s.STENCIL_TEST)),(e!==a.stencilMode||a.stencilReference!==r)&&(a.stencilMode=e,a.stencilReference=r,s.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare],r,255),s.stencilOp(s.KEEP,s.KEEP,this._stencilOpsMapping[i.stencilBack.passOp]))}}_e.extension={type:[d.WebGLSystem],name:"stencil"};const fe={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function Je(t){const e=t.map(i=>({data:i,offset:0,size:0})),r=16;let n=0,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(n=fe[a.data.type],!n)throw new Error(`Unknown type ${a.data.type}`);a.data.size>1&&(n=Math.max(n,r)*a.data.size);const o=n===12?16:n;a.size=n;const u=s%r;u>0&&r-u<o?s+=(r-u)%16:s+=(n-u%n)%n,a.offset=s,s+=n}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function et(t,e){const r=Math.max(fe[t.data.type]/16,1),n=t.data.value.length/t.data.size,s=(4-n%4)%4,i=t.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
21
+ v = uv.${t.data.name};
22
+ offset += ${e};
23
+
24
+ arrayOffset = offset;
25
+
26
+ t = 0;
27
+
28
+ for(var i=0; i < ${t.data.size*r}; i++)
29
+ {
30
+ for(var j = 0; j < ${n}; j++)
31
+ {
32
+ ${i}[arrayOffset++] = v[t++];
33
+ }
34
+ ${s!==0?`arrayOffset += ${s};`:""}
35
+ }
36
+ `}function tt(t){return Me(t,"uboStd40",et,Le)}class he extends we{constructor(){super({createUboElements:Je,generateUboSync:tt})}}he.extension={type:[d.WebGLSystem],name:"ubo"};class rt{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V;const e=this._renderer.gl;this._drawBuffersCache=[];for(let r=1;r<=16;r++)this._drawBuffersCache[r]=Array.from({length:r},(n,s)=>e.COLOR_ATTACHMENT0+s)}copyToTexture(e,r,n,s,i){const a=this._renderTargetSystem,o=this._renderer,u=a.getGpuRenderTarget(e),c=o.gl;return this.finishRenderPass(e),c.bindFramebuffer(c.FRAMEBUFFER,u.resolveTargetFramebuffer),o.texture.bind(r,0),c.copyTexSubImage2D(c.TEXTURE_2D,0,i.x,i.y,n.x,n.y,s.width,s.height),r}startRenderPass(e,r=!0,n,s,i=0,a=0){const o=this._renderTargetSystem,u=e.colorTexture,c=o.getGpuRenderTarget(e);if(a!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(i>0){if(c.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}let _=s.y;e.isRoot&&(_=u.pixelHeight-s.height-s.y),e.colorTextures.forEach(m=>{this._renderer.texture.unbind(m)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,c.framebuffer),!e.isRoot&&(c._attachedMipLevel!==i||c._attachedLayer!==a)&&(e.colorTextures.forEach((m,b)=>{const E=this._renderer.texture.getGlSource(m);if(E.target===f.TEXTURE_2D){if(a!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_2D,E.texture,i)}else if(E.target===f.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");f.framebufferTextureLayer(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,E.texture,i,a)}else if(E.target===f.TEXTURE_CUBE_MAP){if(a<0||a>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_CUBE_MAP_POSITIVE_X+a,E.texture,i)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),c._attachedMipLevel=i,c._attachedLayer=a),e.colorTextures.length>1&&this._setDrawBuffers(e,f);const h=this._viewPortCache;(h.x!==s.x||h.y!==_||h.width!==s.width||h.height!==s.height)&&(h.x=s.x,h.y=_,h.width=s.width,h.height=s.height,f.viewport(s.x,_,s.width,s.height)),!c.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(c),this.clear(e,r,n)}finishRenderPass(e){const n=this._renderTargetSystem.getGpuRenderTarget(e);if(!n.msaa)return;const s=this._renderer.gl;s.bindFramebuffer(s.FRAMEBUFFER,n.resolveTargetFramebuffer),s.bindFramebuffer(s.READ_FRAMEBUFFER,n.framebuffer),s.blitFramebuffer(0,0,n.width,n.height,0,0,n.width,n.height,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.FRAMEBUFFER,n.framebuffer)}initGpuRenderTarget(e){const n=this._renderer.gl,s=new Qe;return s._attachedMipLevel=0,s._attachedLayer=0,e.colorTexture instanceof y?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),s.framebuffer=null,s):(this._initColor(e,s),n.bindFramebuffer(n.FRAMEBUFFER,null),s)}destroyGpuRenderTarget(e){const r=this._renderer.gl;e.framebuffer&&(r.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(r.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(r.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(n=>{r.deleteRenderbuffer(n)}),e.msaaRenderBuffer=null}clear(e,r,n,s,i=0,a=0){if(!r)return;if(a!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const o=this._renderTargetSystem;typeof r=="boolean"&&(r=r?C.ALL:C.NONE);const u=this._renderer.gl;if(r&C.COLOR){n??(n=o.defaultClearColor);const c=this._clearColorCache,_=n;(c[0]!==_[0]||c[1]!==_[1]||c[2]!==_[2]||c[3]!==_[3])&&(c[0]=_[0],c[1]=_[1],c[2]=_[2],c[3]=_[3],u.clearColor(_[0],_[1],_[2],_[3]))}u.clear(r)}resizeGpuRenderTarget(e){if(e.isRoot)return;const n=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,n),(e.stencil||e.depth)&&this._resizeStencil(n)}_initColor(e,r){const n=this._renderer,s=n.gl,i=s.createFramebuffer();if(r.resolveTargetFramebuffer=i,s.bindFramebuffer(s.FRAMEBUFFER,i),r.width=e.colorTexture.source.pixelWidth,r.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((o,u)=>{const c=o.source;c.antialias&&(n.context.supports.msaa?r.msaa=!0:p("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(c,0);const _=n.texture.getGlSource(c),f=_.texture;if(_.target===s.TEXTURE_2D)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_2D,f,0);else if(_.target===s.TEXTURE_2D_ARRAY){if(n.context.webGLVersion<2)throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");s.framebufferTextureLayer(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,f,0,0)}else if(_.target===s.TEXTURE_CUBE_MAP)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_CUBE_MAP_POSITIVE_X,f,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),r.msaa){const o=s.createFramebuffer();r.framebuffer=o,s.bindFramebuffer(s.FRAMEBUFFER,o),e.colorTextures.forEach((u,c)=>{const _=s.createRenderbuffer();r.msaaRenderBuffer[c]=_})}else r.framebuffer=i;this._resizeColor(e,r)}_resizeColor(e,r){const n=e.colorTexture.source;if(r.width=n.pixelWidth,r.height=n.pixelHeight,r._attachedMipLevel=0,r._attachedLayer=0,e.colorTextures.forEach((s,i)=>{i!==0&&s.source.resize(n.width,n.height,n._resolution)}),r.msaa){const s=this._renderer,i=s.gl,a=r.framebuffer;i.bindFramebuffer(i.FRAMEBUFFER,a),e.colorTextures.forEach((o,u)=>{const c=o.source;s.texture.bindSource(c,0);const f=s.texture.getGlSource(c).internalFormat,h=r.msaaRenderBuffer[u];i.bindRenderbuffer(i.RENDERBUFFER,h),i.renderbufferStorageMultisample(i.RENDERBUFFER,4,f,c.pixelWidth,c.pixelHeight),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+u,i.RENDERBUFFER,h)})}}_initStencil(e){if(e.framebuffer===null)return;const r=this._renderer.gl,n=r.createRenderbuffer();e.depthStencilRenderBuffer=n,r.bindRenderbuffer(r.RENDERBUFFER,n),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,n),this._resizeStencil(e)}_resizeStencil(e){const r=this._renderer.gl;r.bindRenderbuffer(r.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?r.renderbufferStorageMultisample(r.RENDERBUFFER,4,r.DEPTH24_STENCIL8,e.width,e.height):r.renderbufferStorage(r.RENDERBUFFER,this._renderer.context.webGLVersion===2?r.DEPTH24_STENCIL8:r.DEPTH_STENCIL,e.width,e.height)}prerender(e){const r=e.colorTexture.resource;this._renderer.context.multiView&&y.test(r)&&this._renderer.context.ensureCanvasSize(r)}postrender(e){if(this._renderer.context.multiView&&y.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,n=e.colorTexture;n.context2D.drawImage(r,0,n.pixelHeight-r.height)}}_setDrawBuffers(e,r){const n=e.colorTextures.length,s=this._drawBuffersCache[n];if(this._renderer.context.webGLVersion===1){const i=this._renderer.context.extensions.drawBuffers;i?i.drawBuffersWEBGL(s):p("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else r.drawBuffers(s)}}class le extends Ve{constructor(e){super(e),this.adaptor=new rt,this.adaptor.init(e,this)}}le.extension={type:[d.WebGLSystem],name:"renderTarget"};function nt(t,e){const r=[],n=[`
37
+ var g = s.groups;
38
+ var sS = r.shader;
39
+ var p = s.glProgram;
40
+ var ugS = r.uniformGroup;
41
+ var resources;
42
+ `];let s=!1,i=0;const a=e._getProgramData(t.glProgram);for(const u in t.groups){const c=t.groups[u];r.push(`
43
+ resources = g[${u}].resources;
44
+ `);for(const _ in c.resources){const f=c.resources[_];if(f instanceof M)if(f.ubo){const h=t._uniformBindMap[u][Number(_)];r.push(`
45
+ sS.bindUniformBlock(
46
+ resources[${_}],
47
+ '${h}',
48
+ ${t.glProgram._uniformBlockData[h].index}
49
+ );
50
+ `)}else r.push(`
51
+ ugS.updateUniformGroup(resources[${_}], p, sD);
52
+ `);else if(f instanceof ee){const h=t._uniformBindMap[u][Number(_)];r.push(`
53
+ sS.bindUniformBlock(
54
+ resources[${_}],
55
+ '${h}',
56
+ ${t.glProgram._uniformBlockData[h].index}
57
+ );
58
+ `)}else if(f instanceof q){const h=t._uniformBindMap[u][_],m=a.uniformData[h];m&&(s||(s=!0,n.push(`
59
+ var tS = r.texture;
60
+ `)),e._gl.uniform1i(m.location,i),r.push(`
61
+ tS.bind(resources[${_}], ${i});
62
+ `),i++)}}}const o=[...n,...r].join(`
63
+ `);return new Function("r","s","sD",o)}class st{constructor(e,r){this.program=e,this.uniformData=r,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function k(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function D(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function de(t,e){switch(t){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return D(2*e);case"bvec3":return D(3*e);case"bvec4":return D(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let T=null;const W={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},it={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function me(t,e){if(!T){const r=Object.keys(W);T={};for(let n=0;n<r.length;++n){const s=r[n];T[t[s]]=W[s]}}return T[e]}function at(t,e){const r=me(t,e);return it[r]||"float32"}function ot(t,e,r=!1){const n={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let a=0;a<s;a++){const o=e.getActiveAttrib(t,a);if(o.name.startsWith("gl_"))continue;const u=at(e,o.type);n[o.name]={location:0,format:u,stride:z(u).stride,offset:0,instance:!1,start:0}}const i=Object.keys(n);if(r){i.sort((a,o)=>a>o?1:-1);for(let a=0;a<i.length;a++)n[i[a]].location=a,e.bindAttribLocation(t,a,i[a]);e.linkProgram(t)}else for(let a=0;a<i.length;a++)n[i[a]].location=e.getAttribLocation(t,i[a]);return n}function ct(t,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<n;s++){const i=e.getActiveUniformBlockName(t,s),a=e.getUniformBlockIndex(t,i),o=e.getActiveUniformBlockParameter(t,s,e.UNIFORM_BLOCK_DATA_SIZE);r[i]={name:i,index:a,size:o}}return r}function ut(t,e){const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let s=0;s<n;s++){const i=e.getActiveUniform(t,s),a=i.name.replace(/\[.*?\]$/,""),o=!!i.name.match(/\[.*?\]$/),u=me(e,i.type);r[a]={name:a,index:s,type:u,size:i.size,isArray:o,value:de(u,i.size)}}return r}function j(t,e){const r=t.getShaderSource(e).split(`
64
+ `).map((c,_)=>`${_}: ${c}`),n=t.getShaderInfoLog(e),s=n.split(`
65
+ `),i={},a=s.map(c=>parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(c=>c&&!i[c]?(i[c]=!0,!0):!1),o=[""];a.forEach(c=>{r[c-1]=`%c${r[c-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=r.join(`
66
+ `);o[0]=u,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function _t(t,e,r,n){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||j(t,r),t.getShaderParameter(n,t.COMPILE_STATUS)||j(t,n),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function ft(t,e){const r=k(t,t.VERTEX_SHADER,e.vertex),n=k(t,t.FRAGMENT_SHADER,e.fragment),s=t.createProgram();t.attachShader(s,r),t.attachShader(s,n);const i=e.transformFeedbackVaryings;i&&(typeof t.transformFeedbackVaryings!="function"?p("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(s,i.names,i.bufferMode==="separate"?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)||_t(t,s,r,n),e._attributeData=ot(s,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=ut(s,t),e._uniformBlockData=ct(s,t),t.deleteShader(r),t.deleteShader(n);const a={};for(const u in e._uniformData){const c=e._uniformData[u];a[u]={location:t.getUniformLocation(s,u),value:de(c.type,c.size)}}return new st(s,a)}const x={textureCount:0,blockIndex:0};class Ee{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,r){if(this._setProgram(e.glProgram),r)return;x.textureCount=0,x.blockIndex=0;let n=this._shaderSyncFunctions[e.glProgram._key];n||(n=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),n(this._renderer,e,x)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,x)}bindUniformBlock(e,r,n=0){const s=this._renderer.buffer,i=this._getProgramData(this._activeProgram),a=e._bufferResource;a||this._renderer.ubo.updateUniformGroup(e);const o=e.buffer,u=s.updateBuffer(o),c=s.freeLocationForBufferBase(u);if(a){const{offset:f,size:h}=e;f===0&&h===o.data.byteLength?s.bindBufferBase(u,c):s.bindBufferRange(u,c,f)}else s.getLastBindBaseLocation(u)!==c&&s.bindBufferBase(u,c);const _=this._activeProgram._uniformBlockData[r].index;i.uniformBlockBindings[n]!==c&&(i.uniformBlockBindings[n]=c,this._renderer.gl.uniformBlockBinding(i.program,_,c))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const r=this._getProgramData(e);this._gl.useProgram(r.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const r=e._key;return this._programDataHash[r]=ft(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,r){return nt(e,r)}resetState(){this._activeProgram=null}}Ee.extension={type:[d.WebGLSystem],name:"shader"};const ht={f32:`if (cv !== v) {
67
+ cu.value = v;
68
+ gl.uniform1f(location, v);
69
+ }`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
70
+ cv[0] = v[0];
71
+ cv[1] = v[1];
72
+ gl.uniform2f(location, v[0], v[1]);
73
+ }`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
74
+ cv[0] = v[0];
75
+ cv[1] = v[1];
76
+ cv[2] = v[2];
77
+ gl.uniform3f(location, v[0], v[1], v[2]);
78
+ }`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
79
+ cv[0] = v[0];
80
+ cv[1] = v[1];
81
+ cv[2] = v[2];
82
+ cv[3] = v[3];
83
+ gl.uniform4f(location, v[0], v[1], v[2], v[3]);
84
+ }`,i32:`if (cv !== v) {
85
+ cu.value = v;
86
+ gl.uniform1i(location, v);
87
+ }`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
88
+ cv[0] = v[0];
89
+ cv[1] = v[1];
90
+ gl.uniform2i(location, v[0], v[1]);
91
+ }`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
92
+ cv[0] = v[0];
93
+ cv[1] = v[1];
94
+ cv[2] = v[2];
95
+ gl.uniform3i(location, v[0], v[1], v[2]);
96
+ }`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
97
+ cv[0] = v[0];
98
+ cv[1] = v[1];
99
+ cv[2] = v[2];
100
+ cv[3] = v[3];
101
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
102
+ }`,u32:`if (cv !== v) {
103
+ cu.value = v;
104
+ gl.uniform1ui(location, v);
105
+ }`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
106
+ cv[0] = v[0];
107
+ cv[1] = v[1];
108
+ gl.uniform2ui(location, v[0], v[1]);
109
+ }`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
110
+ cv[0] = v[0];
111
+ cv[1] = v[1];
112
+ cv[2] = v[2];
113
+ gl.uniform3ui(location, v[0], v[1], v[2]);
114
+ }`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
115
+ cv[0] = v[0];
116
+ cv[1] = v[1];
117
+ cv[2] = v[2];
118
+ cv[3] = v[3];
119
+ gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
120
+ }`,bool:`if (cv !== v) {
121
+ cu.value = v;
122
+ gl.uniform1i(location, v);
123
+ }`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
124
+ cv[0] = v[0];
125
+ cv[1] = v[1];
126
+ gl.uniform2i(location, v[0], v[1]);
127
+ }`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
128
+ cv[0] = v[0];
129
+ cv[1] = v[1];
130
+ cv[2] = v[2];
131
+ gl.uniform3i(location, v[0], v[1], v[2]);
132
+ }`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
133
+ cv[0] = v[0];
134
+ cv[1] = v[1];
135
+ cv[2] = v[2];
136
+ cv[3] = v[3];
137
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
138
+ }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},lt={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function dt(t,e){const r=[`
139
+ var v = null;
140
+ var cv = null;
141
+ var cu = null;
142
+ var t = 0;
143
+ var gl = renderer.gl;
144
+ var name = null;
145
+ `];for(const n in t.uniforms){if(!e[n]){t.uniforms[n]instanceof M?t.uniforms[n].ubo?r.push(`
146
+ renderer.shader.bindUniformBlock(uv.${n}, "${n}");
147
+ `):r.push(`
148
+ renderer.shader.updateUniformGroup(uv.${n});
149
+ `):t.uniforms[n]instanceof ee&&r.push(`
150
+ renderer.shader.bindBufferResource(uv.${n}, "${n}");
151
+ `);continue}const s=t.uniformStructures[n];let i=!1;for(let a=0;a<N.length;a++){const o=N[a];if(s.type===o.type&&o.test(s)){r.push(`name = "${n}";`,N[a].uniform),i=!0;break}}if(!i){const o=(s.size===1?ht:lt)[s.type].replace("location",`ud["${n}"].location`);r.push(`
152
+ cu = ud["${n}"];
153
+ cv = cu.value;
154
+ v = uv["${n}"];
155
+ ${o};`)}}return new Function("ud","uv","renderer","syncData",r.join(`
156
+ `))}class be{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,r,n){const s=this._renderer.shader._getProgramData(r);(!e.isStatic||e._dirtyId!==s.uniformDirtyGroups[e.uid])&&(s.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,r)(s.uniformData,e.uniforms,this._renderer,n))}_getUniformSyncFunction(e,r){var n;return((n=this._uniformGroupSyncHash[e._signature])==null?void 0:n[r._key])||this._createUniformSyncFunction(e,r)}_createUniformSyncFunction(e,r){const n=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),s=this._getSignature(e,r._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(e,r._uniformData)),n[r._key]=this._cache[s],n[r._key]}_generateUniformsSync(e,r){return dt(e,r)}_getSignature(e,r,n){const s=e.uniforms,i=[`${n}-`];for(const a in s)i.push(a),r[a]&&i.push(r[a].type);return i.join("-")}destroy(){this._renderer=null,this._cache=null}}be.extension={type:[d.WebGLSystem],name:"uniformGroup"};function mt(t){const e={};if(e.normal=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e.add=[t.ONE,t.ONE],e.multiply=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.screen=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e["screen-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.erase=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],!(t instanceof R.get().getWebGLRenderingContext()))e.min=[t.ONE,t.ONE,t.ONE,t.ONE,t.MIN,t.MIN],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,t.MAX,t.MAX];else{const n=t.getExtension("EXT_blend_minmax");n&&(e.min=[t.ONE,t.ONE,t.ONE,t.ONE,n.MIN_EXT,n.MIN_EXT],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,n.MAX_EXT,n.MAX_EXT])}return e}const Et=0,bt=1,pt=2,St=3,Rt=4,gt=5,pe=class U{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[Et]=this.setBlend,this.map[bt]=this.setOffset,this.map[pt]=this.setCullFace,this.map[St]=this.setDepthTest,this.map[Rt]=this.setFrontFace,this.map[gt]=this.setDepthMask,this.checks=[],this.defaultState=F.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=mt(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let r=this.stateId^e.data,n=0;for(;r;)r&1&&this.map[n].call(this,!!(e.data&1<<n)),r>>=1,n++;this.stateId=e.data}for(let r=0;r<this.checks.length;r++)this.checks[r](this,e)}forceState(e){e||(e=this.defaultState);for(let r=0;r<this.map.length;r++)this.map[r].call(this,!!(e.data&1<<r));for(let r=0;r<this.checks.length;r++)this.checks[r](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(U._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(U._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const r=this._invertFrontFace?!e:e;this._glFrontFace!==r&&(this._glFrontFace=r,this.gl.frontFace(this.gl[r?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const r=this.blendModesMap[e],n=this.gl;r.length===2?n.blendFunc(r[0],r[1]):n.blendFuncSeparate(r[0],r[1],r[2],r[3]),r.length===6?(this._blendEq=!0,n.blendEquationSeparate(r[4],r[5])):this._blendEq&&(this._blendEq=!1,n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD))}setPolygonOffset(e,r){this.gl.polygonOffset(e,r)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,r){const n=this.checks.indexOf(e);r&&n===-1?this.checks.push(e):!r&&n!==-1&&this.checks.splice(n,1)}static _checkBlendMode(e,r){e.setBlendMode(r.blendMode)}static _checkPolygonOffset(e,r){e.setPolygonOffset(1,r.polygonOffset)}destroy(){this.gl=null,this.checks.length=0}};pe.extension={type:[d.WebGLSystem],name:"state"};let Tt=pe;class xt{constructor(e){this.target=w.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=l.UNSIGNED_BYTE,this.internalFormat=G.RGBA,this.format=G.RGBA,this.samplerType=0}destroy(){}}const vt={id:"buffer",upload(t,e,r,n,s,i=!1){const a=s||e.target;!i&&e.width===t.width&&e.height===t.height?r.texSubImage2D(a,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(a,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},At={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},Bt={id:"compressed",upload(t,e,r,n,s,i){const a=s??e.target;r.pixelStorei(r.UNPACK_ALIGNMENT,4);let o=t.pixelWidth,u=t.pixelHeight;const c=!!At[t.format];for(let _=0;_<t.resource.length;_++){const f=t.resource[_];c?r.compressedTexImage2D(a,_,e.internalFormat,o,u,0,f):r.texImage2D(a,_,e.internalFormat,o,u,0,e.format,e.type,f),o=Math.max(o>>1,1),u=Math.max(u>>1,1)}}},K=["right","left","top","bottom","front","back"];function yt(t){return{id:"cube",upload(e,r,n,s){const i=e.faces;for(let a=0;a<K.length;a++){const o=K[a],u=i[o];(t[u.uploadMethodId]||t.image).upload(u,r,n,s,w.TEXTURE_CUBE_MAP_POSITIVE_X+a,(r._layerInitMask&1<<a)===0),r._layerInitMask|=1<<a}r.width=e.pixelWidth,r.height=e.pixelHeight}}}const Se={id:"image",upload(t,e,r,n,s,i=!1){const a=s||e.target,o=t.pixelWidth,u=t.pixelHeight,c=t.resourceWidth,_=t.resourceHeight,f=n===2,h=i||e.width!==o||e.height!==u,m=c>=o&&_>=u,b=t.resource;(f?Ct:Nt)(r,a,e,o,u,c,_,b,h,m),e.width=o,e.height=u}};function Ct(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,i,a,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,o)}function Nt(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,r.format,r.type,o)}const Dt=We(),It={id:"video",upload(t,e,r,n,s,i=Dt){if(!t.isValid){const a=s??e.target;r.texImage2D(a,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Se.upload(t,e,r,n,s,i)}},$={linear:9729,nearest:9728},Gt={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},I={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Ut={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Y(t,e,r,n,s,i,a,o){const u=i;if(!o||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const c=I[a?"clamp-to-edge":t.addressModeU],_=I[a?"clamp-to-edge":t.addressModeV],f=I[a?"clamp-to-edge":t.addressModeW];e[s](u,e.TEXTURE_WRAP_S,c),e[s](u,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[s](u,e.TEXTURE_WRAP_R,f)}if((!o||t.magFilter!=="linear")&&e[s](u,e.TEXTURE_MAG_FILTER,$[t.magFilter]),r){if(!o||t.mipmapFilter!=="linear"){const c=Gt[t.minFilter][t.mipmapFilter];e[s](u,e.TEXTURE_MIN_FILTER,c)}}else e[s](u,e.TEXTURE_MIN_FILTER,$[t.minFilter]);if(n&&t.maxAnisotropy>1){const c=Math.min(t.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](u,n.TEXTURE_MAX_ANISOTROPY_EXT,c)}t.compare&&e[s](u,e.TEXTURE_COMPARE_FUNC,Ut[t.compare])}function Ft(t){return{r8unorm:t.RED,r8snorm:t.RED,r8uint:t.RED,r8sint:t.RED,r16uint:t.RED,r16sint:t.RED,r16float:t.RED,rg8unorm:t.RG,rg8snorm:t.RG,rg8uint:t.RG,rg8sint:t.RG,r32uint:t.RED,r32sint:t.RED,r32float:t.RED,rg16uint:t.RG,rg16sint:t.RG,rg16float:t.RG,rgba8unorm:t.RGBA,"rgba8unorm-srgb":t.RGBA,rgba8snorm:t.RGBA,rgba8uint:t.RGBA,rgba8sint:t.RGBA,bgra8unorm:t.RGBA,"bgra8unorm-srgb":t.RGBA,rgb9e5ufloat:t.RGB,rgb10a2unorm:t.RGBA,rg11b10ufloat:t.RGB,rg32uint:t.RG,rg32sint:t.RG,rg32float:t.RG,rgba16uint:t.RGBA,rgba16sint:t.RGBA,rgba16float:t.RGBA,rgba32uint:t.RGBA,rgba32sint:t.RGBA,rgba32float:t.RGBA,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT,depth24plus:t.DEPTH_COMPONENT,"depth24plus-stencil8":t.DEPTH_STENCIL,depth32float:t.DEPTH_COMPONENT,"depth32float-stencil8":t.DEPTH_STENCIL}}function Ot(t,e){let r={},n=t.RGBA;return t instanceof R.get().getWebGLRenderingContext()?e.srgb&&(r={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(r={"rgba8unorm-srgb":t.SRGB8_ALPHA8,"bgra8unorm-srgb":t.SRGB8_ALPHA8},n=t.RGBA8),{r8unorm:t.R8,r8snorm:t.R8_SNORM,r8uint:t.R8UI,r8sint:t.R8I,r16uint:t.R16UI,r16sint:t.R16I,r16float:t.R16F,rg8unorm:t.RG8,rg8snorm:t.RG8_SNORM,rg8uint:t.RG8UI,rg8sint:t.RG8I,r32uint:t.R32UI,r32sint:t.R32I,r32float:t.R32F,rg16uint:t.RG16UI,rg16sint:t.RG16I,rg16float:t.RG16F,rgba8unorm:t.RGBA,...r,rgba8snorm:t.RGBA8_SNORM,rgba8uint:t.RGBA8UI,rgba8sint:t.RGBA8I,bgra8unorm:n,rgb9e5ufloat:t.RGB9_E5,rgb10a2unorm:t.RGB10_A2,rg11b10ufloat:t.R11F_G11F_B10F,rg32uint:t.RG32UI,rg32sint:t.RG32I,rg32float:t.RG32F,rgba16uint:t.RGBA16UI,rgba16sint:t.RGBA16I,rgba16float:t.RGBA16F,rgba32uint:t.RGBA32UI,rgba32sint:t.RGBA32I,rgba32float:t.RGBA32F,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT16,depth24plus:t.DEPTH_COMPONENT24,"depth24plus-stencil8":t.DEPTH24_STENCIL8,depth32float:t.DEPTH_COMPONENT32F,"depth32float-stencil8":t.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function Pt(t){return{r8unorm:t.UNSIGNED_BYTE,r8snorm:t.BYTE,r8uint:t.UNSIGNED_BYTE,r8sint:t.BYTE,r16uint:t.UNSIGNED_SHORT,r16sint:t.SHORT,r16float:t.HALF_FLOAT,rg8unorm:t.UNSIGNED_BYTE,rg8snorm:t.BYTE,rg8uint:t.UNSIGNED_BYTE,rg8sint:t.BYTE,r32uint:t.UNSIGNED_INT,r32sint:t.INT,r32float:t.FLOAT,rg16uint:t.UNSIGNED_SHORT,rg16sint:t.SHORT,rg16float:t.HALF_FLOAT,rgba8unorm:t.UNSIGNED_BYTE,"rgba8unorm-srgb":t.UNSIGNED_BYTE,rgba8snorm:t.BYTE,rgba8uint:t.UNSIGNED_BYTE,rgba8sint:t.BYTE,bgra8unorm:t.UNSIGNED_BYTE,"bgra8unorm-srgb":t.UNSIGNED_BYTE,rgb9e5ufloat:t.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:t.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:t.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:t.UNSIGNED_INT,rg32sint:t.INT,rg32float:t.FLOAT,rgba16uint:t.UNSIGNED_SHORT,rgba16sint:t.SHORT,rgba16float:t.HALF_FLOAT,rgba32uint:t.UNSIGNED_INT,rgba32sint:t.INT,rgba32float:t.FLOAT,stencil8:t.UNSIGNED_BYTE,depth16unorm:t.UNSIGNED_SHORT,depth24plus:t.UNSIGNED_INT,"depth24plus-stencil8":t.UNSIGNED_INT_24_8,depth32float:t.FLOAT,"depth32float-stencil8":t.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Mt(t){return{"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP,"1d":null,"3d":(t==null?void 0:t.TEXTURE_3D)||null,"2d-array":(t==null?void 0:t.TEXTURE_2D_ARRAY)||null,"cube-array":(t==null?void 0:t.TEXTURE_CUBE_MAP_ARRAY)||null}}const Lt=4;class Re{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new O({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const r={image:Se,buffer:vt,video:It,compressed:Bt};this._uploads={...r,cube:yt(r)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Ot(e,this._renderer.context.extensions),this._mapFormatToType=Pt(e),this._mapFormatToFormat=Ft(e),this._mapViewDimensionToGlTarget=Mt(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let r=0;r<16;r++)this.bind(S.EMPTY,r)}initSource(e){this.bind(e)}bind(e,r=0){const n=e.source;e?(this.bindSource(n,r),this._useSeparateSamplers&&this._bindSampler(n.style,r)):(this.bindSource(null,r),this._useSeparateSamplers&&this._bindSampler(null,r))}bindSource(e,r=0){const n=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e||(e=S.EMPTY.source);const s=this.getGlSource(e);n.bindTexture(s.target,s.texture)}}_bindSampler(e,r=0){const n=this._gl;if(!e){this._boundSamplers[r]=null,n.bindSampler(r,null);return}const s=this._getGlSampler(e);this._boundSamplers[r]!==s&&(this._boundSamplers[r]=s,n.bindSampler(r,s))}unbind(e){const r=e.source,n=this._boundTextures,s=this._gl;for(let i=0;i<n.length;i++)if(n[i]===r){this._activateLocation(i);const a=this.getGlSource(r);s.bindTexture(a.target,null),n[i]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const r=this._gl,n=new xt(r.createTexture());if(n.type=this._mapFormatToType[e.format],n.internalFormat=this._mapFormatToInternalFormat[e.format],n.format=this._mapFormatToFormat[e.format],n.target=this._mapViewDimensionToGlTarget[e.viewDimension],n.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.uploadMethodId==="cube"&&(n.target=r.TEXTURE_CUBE_MAP),e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const i=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(i))+1}return e._gpuData[this._renderer.uid]=n,this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),this.updateStyle(e,!1),n}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,r){const n=this._gl,s=this.getGlSource(e);n.bindTexture(s.target,s.texture),this._boundTextures[this._activeTextureLocation]=e,Y(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||(this.unbind(e),this._gl.deleteTexture(n.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const r=this._gl,n=this.getGlSource(e);r.bindTexture(n.target,n.texture),this._boundTextures[this._activeTextureLocation]=e;const s=e.alphaMode==="premultiply-alpha-on-upload";if(this._premultiplyAlpha!==s&&(this._premultiplyAlpha=s,r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,n,r,this._renderer.context.webGLVersion);else if(n.target===r.TEXTURE_2D)this._initEmptyTexture2D(n,e);else if(n.target===r.TEXTURE_2D_ARRAY)this._initEmptyTexture2DArray(n,e);else if(n.target===r.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(n,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(n,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,r=!0){r&&this.bindSource(e,0);const n=this.getGlSource(e);this._gl.generateMipmap(n.target)}_initEmptyTexture2D(e,r){const n=this._gl;n.texImage2D(n.TEXTURE_2D,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let s=Math.max(r.pixelWidth>>1,1),i=Math.max(r.pixelHeight>>1,1);for(let a=1;a<r.mipLevelCount;a++)n.texImage2D(n.TEXTURE_2D,a,e.internalFormat,s,i,0,e.format,e.type,null),s=Math.max(s>>1,1),i=Math.max(i>>1,1)}_initEmptyTexture2DArray(e,r){if(this._renderer.context.webGLVersion!==2)throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");const n=this._gl,s=Math.max(r.arrayLayerCount|0,1);n.texImage3D(n.TEXTURE_2D_ARRAY,0,e.internalFormat,r.pixelWidth,r.pixelHeight,s,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++)n.texImage3D(n.TEXTURE_2D_ARRAY,o,e.internalFormat,i,a,s,0,e.format,e.type,null),i=Math.max(i>>1,1),a=Math.max(a>>1,1)}_initEmptyTextureCube(e,r){const n=this._gl,s=6;for(let o=0;o<s;o++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++){for(let u=0;u<s;u++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+u,o,e.internalFormat,i,a,0,e.format,e.type,null);i=Math.max(i>>1,1),a=Math.max(a>>1,1)}}_applyMipRange(e,r){if(this._renderer.context.webGLVersion!==2)return;const n=this._gl,s=Math.max((r.mipLevelCount|0)-1,0);n.texParameteri(e.target,n.TEXTURE_BASE_LEVEL,0),n.texParameteri(e.target,n.TEXTURE_MAX_LEVEL,s)}_initSampler(e){const r=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,Y(e,r,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",n,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:n,height:s}=this.getPixels(e),i=R.get().createCanvas();i.width=n,i.height=s;const a=i.getContext("2d");if(a){const o=a.createImageData(n,s);o.data.set(r),a.putImageData(o,0,0)}return i}getPixels(e){const r=e.source.resolution,n=e.frame,s=Math.max(Math.round(n.width*r),1),i=Math.max(Math.round(n.height*r),1),a=new Uint8Array(Lt*s*i),o=this._renderer,u=o.renderTarget.getRenderTarget(e),c=o.renderTarget.getGpuRenderTarget(u),_=o.gl;return _.bindFramebuffer(_.FRAMEBUFFER,c.resolveTargetFramebuffer),_.readPixels(Math.round(n.x*r),Math.round(n.y*r),s,i,_.RGBA,_.UNSIGNED_BYTE,a),{pixels:new Uint8ClampedArray(a.buffer),width:s,height:i}}destroy(){this._managedTextures.destroy(),this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){this._activeTextureLocation=-1,this._boundTextures.fill(S.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Re.extension={type:[d.WebGLSystem],name:"texture"};class ge{contextChange(e){const r=new M({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new Z,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),n=e.limits.maxBatchableTextures,s=Q({name:"graphics",bits:[De,Ie(n),te,J]});this.shader=new P({glProgram:s,resources:{localUniforms:r,batchSamplers:Ge(n)}})}execute(e,r){const n=r.context,s=n.customShader||this.shader,i=e.renderer,a=i.graphicsContext,{batcher:o,instructions:u}=a.getContextRenderData(n);s.groups[0]=i.globalUniforms.bindGroup,i.state.set(e.state),i.shader.bind(s),i.geometry.bind(o.geometry,s.glProgram);const c=u.instructions;for(let _=0;_<u.instructionSize;_++){const f=c[_];if(f.size){for(let h=0;h<f.textures.count;h++)i.texture.bind(f.textures.textures[h],h);i.geometry.draw(f.topology,f.size,f.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}ge.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class Te{init(){const e=Q({name:"mesh",bits:[te,He,J]});this._shader=new P({glProgram:e,resources:{uTexture:S.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new Z}}}})}execute(e,r){const n=e.renderer;let s=r._shader;if(s){if(!s.glProgram){p("Mesh shader has no glProgram",r.shader);return}}else{s=this._shader;const i=r.texture,a=i.source;s.resources.uTexture=a,s.resources.uSampler=a.style,s.resources.textureUniforms.uniforms.uTextureMatrix=i.textureMatrix.mapCoord}s.groups[100]=n.globalUniforms.bindGroup,s.groups[101]=e.localUniformsBindGroup,n.encoder.draw({geometry:r._geometry,shader:s,state:r.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Te.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const wt=[...Xe,he,Ze,Ke,ue,ne,Re,le,ie,be,Ee,ce,Tt,_e,oe],Ht=[...ke],Vt=[re,Te,ge],xe=[],ve=[],Ae=[];A.handleByNamedList(d.WebGLSystem,xe);A.handleByNamedList(d.WebGLPipes,ve);A.handleByNamedList(d.WebGLPipesAdaptor,Ae);A.add(...wt,...Ht,...Vt);class jt extends Ue{constructor(){const e={name:"webgl",type:Fe.WEBGL,systems:xe,renderPipes:ve,renderPipeAdaptors:Ae};super(e)}}export{jt as WebGLRenderer};