mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-02-07 14:22:36 +01:00
157 lines
60 KiB
JavaScript
157 lines
60 KiB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-H-H0n5qT.cjs");class U{constructor(){this._didUpload=!1,this._tempState=o.State.for2d()}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUpload=!1}start(e,r,n){const s=e.renderer;s.shader.bind(n,this._didUpload),s.shader.updateUniformGroup(s.globalUniforms.uniformGroup),s.geometry.bind(r,n.glProgram)}execute(e,r){const n=e.renderer;this._didUpload=!0,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("triangle-list",r.size,r.start)}}U.extension={type:[o.ExtensionType.WebGLPipesAdaptor],name:"batch"};var p=(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))(p||{});class se{constructor(e,r){this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}}class O{constructor(e){this._gpuBuffers=Object.create(null),this._boundBufferBases=Object.create(null),this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_gpuBuffers")}destroy(){this._renderer=null,this._gl=null,this._gpuBuffers=null,this._boundBufferBases=null}contextChange(){this._gpuBuffers=Object.create(null),this._gl=this._renderer.gl}getGlBuffer(e){return this._gpuBuffers[e.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;if(this._boundBufferBases[r]!==e){const s=this.getGlBuffer(e);this._boundBufferBases[r]=e,n.bindBufferBase(n.UNIFORM_BUFFER,r,s.buffer)}}bindBufferRange(e,r,n){const{_gl:s}=this;n=n||0;const i=this.getGlBuffer(e);s.bindBufferRange(s.UNIFORM_BUFFER,r||0,i.buffer,n*256,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;if(n.byteLength>=e.data.byteLength)r.bufferSubData(n.type,0,s,0,e._updateSize/s.BYTES_PER_ELEMENT);else{const i=e.descriptor.usage&o.BufferUsage.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;n.byteLength=s.byteLength,r.bufferData(n.type,s,i)}return n}destroyAll(){const e=this._gl;for(const r in this._gpuBuffers)e.deleteBuffer(this._gpuBuffers[r].buffer);this._gpuBuffers=Object.create(null)}onBufferDestroy(e,r){const n=this._gpuBuffers[e.uid],s=this._gl;r||s.deleteBuffer(n.buffer),this._gpuBuffers[e.uid]=null}createGLBuffer(e){const{_gl:r}=this;let n=p.ARRAY_BUFFER;e.descriptor.usage&o.BufferUsage.INDEX?n=p.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&o.BufferUsage.UNIFORM&&(n=p.UNIFORM_BUFFER);const s=new se(r.createBuffer(),n);return this._gpuBuffers[e.uid]=s,e.on("destroy",this.onBufferDestroy,this),s}}O.extension={type:[o.ExtensionType.WebGLSystem],name:"buffer"};const v=class P{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={...P.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(o.warn("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=o.DOMAdapter.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&&o.warn("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 o.DOMAdapter.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._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&&o.warn("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||o.warn("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};v.extension={type:[o.ExtensionType.WebGLSystem],name:"context"};v.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let ie=v;var x=(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))(x||{}),F=(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))(F||{}),h=(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))(h||{});const N={uint8x2:h.UNSIGNED_BYTE,uint8x4:h.UNSIGNED_BYTE,sint8x2:h.BYTE,sint8x4:h.BYTE,unorm8x2:h.UNSIGNED_BYTE,unorm8x4:h.UNSIGNED_BYTE,snorm8x2:h.BYTE,snorm8x4:h.BYTE,uint16x2:h.UNSIGNED_SHORT,uint16x4:h.UNSIGNED_SHORT,sint16x2:h.SHORT,sint16x4:h.SHORT,unorm16x2:h.UNSIGNED_SHORT,unorm16x4:h.UNSIGNED_SHORT,snorm16x2:h.SHORT,snorm16x4:h.SHORT,float16x2:h.HALF_FLOAT,float16x4:h.HALF_FLOAT,float32:h.FLOAT,float32x2:h.FLOAT,float32x3:h.FLOAT,float32x4:h.FLOAT,uint32:h.UNSIGNED_INT,uint32x2:h.UNSIGNED_INT,uint32x3:h.UNSIGNED_INT,uint32x4:h.UNSIGNED_INT,sint32:h.INT,sint32x2:h.INT,sint32x3:h.INT,sint32x4:h.INT};function ae(t){return N[t]??N.float32}const oe={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class M{constructor(e){this._geometryVaoHash=Object.create(null),this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._renderer.renderableGC.addManagedHash(this,"_geometryVaoHash")}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");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,c)=>{n.drawArraysInstancedANGLE(s,i,a,c)},e.drawElementsInstanced=(s,i,a,c,u)=>{n.drawElementsInstancedANGLE(s,i,a,c,u)},e.vertexAttribDivisor=(s,i)=>n.vertexAttribDivisorANGLE(s,i)),this._activeGeometry=null,this._activeVao=null,this._geometryVaoHash=Object.create(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()}reset(){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)}}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=this._geometryVaoHash[e.uid])==null?void 0:n[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);this._geometryVaoHash[e.uid]||(this._geometryVaoHash[e.uid]=Object.create(null),e.on("destroy",this.onGeometryDestroy,this));const c=this._geometryVaoHash[e.uid];let u=c[a];if(u)return c[r._key]=u,u;o.ensureAttributes(e,r._attributeData);const _=e.buffers;u=s.createVertexArray(),s.bindVertexArray(u);for(let f=0;f<_.length;f++){const l=_[f];i.bind(l)}return this.activateVao(e,r),c[r._key]=u,c[a]=u,s.bindVertexArray(null),u}onGeometryDestroy(e,r){const n=this._geometryVaoHash[e.uid],s=this.gl;if(n){if(r)for(const i in n)this._activeVao!==n[i]&&this.unbind(),s.deleteVertexArray(n[i]);this._geometryVaoHash[e.uid]=null}}destroyAll(e=!1){const r=this.gl;for(const n in this._geometryVaoHash){if(e)for(const s in this._geometryVaoHash[n]){const i=this._geometryVaoHash[n];this._activeVao!==i&&this.unbind(),r.deleteVertexArray(i[s])}this._geometryVaoHash[n]=null}}activateVao(e,r){var c;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 _=i[u],f=_.buffer,l=s.getGlBuffer(f),d=r._attributeData[u];if(d){a!==l&&(s.bind(f),a=l);const m=d.location;n.enableVertexAttribArray(m);const E=o.getAttributeInfoFromFormat(_.format),B=ae(_.format);if(((c=d.format)==null?void 0:c.substring(1,4))==="int"?n.vertexAttribIPointer(m,E.size,B,_.stride,_.offset):n.vertexAttribPointer(m,E.size,B,E.normalised,_.stride,_.offset),_.instance)if(this.hasInstance){const ne=_.divisor??1;n.vertexAttribDivisor(m,ne)}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,c=oe[a.topology||e];if(s||(s=a.instanceCount),a.indexBuffer){const u=a.indexBuffer.data.BYTES_PER_ELEMENT,_=u===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT;s>1?i.drawElementsInstanced(c,r||a.indexBuffer.data.length,_,(n||0)*u,s):i.drawElements(c,r||a.indexBuffer.data.length,_,(n||0)*u)}else s>1?i.drawArraysInstanced(c,n||0,r||a.getSize(),s):i.drawArrays(c,n||0,r||a.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}M.extension={type:[o.ExtensionType.WebGLSystem],name:"geometry"};const ce=new o.Geometry({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),A=class L{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:n}={...L.defaultOptions,...e};this.useBackBuffer=r,this._antialias=n,this._renderer.context.supports.msaa||(o.warn("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=o.State.for2d();const s=new o.GlProgram({vertex:`
|
|
attribute vec2 aPosition;
|
|
out vec2 vUv;
|
|
|
|
void main() {
|
|
gl_Position = vec4(aPosition, 0.0, 1.0);
|
|
|
|
vUv = (aPosition + 1.0) / 2.0;
|
|
|
|
// flip dem UVs
|
|
vUv.y = 1.0 - vUv.y;
|
|
}`,fragment:`
|
|
in vec2 vUv;
|
|
out vec4 finalColor;
|
|
|
|
uniform sampler2D uTexture;
|
|
|
|
void main() {
|
|
finalColor = texture(uTexture, vUv);
|
|
}`,name:"big-triangle"});this._bigTriangleShader=new o.Shader({glProgram:s,resources:{uTexture:o.Texture.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:ce,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new o.Texture({source:new o.TextureSource({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)}};A.extension={type:[o.ExtensionType.WebGLSystem],name:"backBuffer",priority:1};A.defaultOptions={useBackBuffer:!1};let ue=A;class H{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)))}}H.extension={type:[o.ExtensionType.WebGLSystem],name:"colorMask"};class w{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:c,size:u,start:_,instanceCount:f}=e;r.shader.bind(s,a),r.geometry.bind(n,r.shader._activeProgram),i&&r.state.set(i),r.geometry.draw(c,u,_,f??n.instanceCount)}destroy(){this._renderer=null}}w.extension={type:[o.ExtensionType.WebGLSystem],name:"encoder"};class _e{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this.msaaRenderBuffer=[]}}class V{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:o.STENCIL_MODES.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._stencilCache.enabled=!1,this._stencilCache.stencilMode=o.STENCIL_MODES.NONE,this._stencilCache.stencilReference=0}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:o.STENCIL_MODES.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}setStencilMode(e,r){const n=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,i=o.GpuStencilModesToPixi[e],a=this._stencilCache;if(n.stencilMode=e,n.stencilReference=r,e===o.STENCIL_MODES.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]))}}V.extension={type:[o.ExtensionType.WebGLSystem],name:"stencil"};const k={f32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"mat2x2<f32>":16*2,"mat3x3<f32>":16*3,"mat4x4<f32>":16*4};function fe(t){const e=t.map(i=>({data:i,offset:0,size:0}));let r=0,n=0,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(r=k[a.data.type],!r)throw new Error(`Unknown type ${a.data.type}`);if(a.data.size>1&&(r=Math.max(r,16)*a.data.size),a.size=r,n%r!==0&&n<16){const c=n%r%16;n+=c,s+=c}n+r>16?(s=Math.ceil(s/16)*16,a.offset=s,s+=r,n=r):(a.offset=s,n+=r,s+=r)}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function he(t,e){const r=Math.max(k[t.data.type]/16,1),n=t.data.value.length/t.data.size,s=(4-n%4)%4;return`
|
|
v = uv.${t.data.name};
|
|
offset += ${e};
|
|
|
|
arrayOffset = offset;
|
|
|
|
t = 0;
|
|
|
|
for(var i=0; i < ${t.data.size*r}; i++)
|
|
{
|
|
for(var j = 0; j < ${n}; j++)
|
|
{
|
|
data[arrayOffset++] = v[t++];
|
|
}
|
|
${s!==0?`arrayOffset += ${s};`:""}
|
|
}
|
|
`}function le(t){return o.createUboSyncFunction(t,"uboStd40",he,o.uboSyncFunctionsSTD40)}class X extends o.UboSystem{constructor(){super({createUboElements:fe,generateUboSync:le})}}X.extension={type:[o.ExtensionType.WebGLSystem],name:"ubo"};class de{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new o.Rectangle}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new o.Rectangle}copyToTexture(e,r,n,s,i){const a=this._renderTargetSystem,c=this._renderer,u=a.getGpuRenderTarget(e),_=c.gl;return this.finishRenderPass(e),_.bindFramebuffer(_.FRAMEBUFFER,u.resolveTargetFramebuffer),c.texture.bind(r,0),_.copyTexSubImage2D(_.TEXTURE_2D,0,i.x,i.y,n.x,n.y,s.width,s.height),r}startRenderPass(e,r=!0,n,s){const i=this._renderTargetSystem,a=e.colorTexture,c=i.getGpuRenderTarget(e);let u=s.y;e.isRoot&&(u=a.pixelHeight-s.height),e.colorTextures.forEach(l=>{this._renderer.texture.unbind(l)});const _=this._renderer.gl;_.bindFramebuffer(_.FRAMEBUFFER,c.framebuffer);const f=this._viewPortCache;(f.x!==s.x||f.y!==u||f.width!==s.width||f.height!==s.height)&&(f.x=s.x,f.y=u,f.width=s.width,f.height=s.height,_.viewport(s.x,u,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 r=this._renderer,n=r.gl,s=new _e;return e.colorTexture.resource===r.canvas?(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){if(!r)return;const s=this._renderTargetSystem;typeof r=="boolean"&&(r=r?o.CLEAR.ALL:o.CLEAR.NONE);const i=this._renderer.gl;if(r&o.CLEAR.COLOR){n??(n=s.defaultClearColor);const a=this._clearColorCache,c=n;(a[0]!==c[0]||a[1]!==c[1]||a[2]!==c[2]||a[3]!==c[3])&&(a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],i.clearColor(c[0],c[1],c[2],c[3]))}i.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((a,c)=>{const u=a.source;u.antialias&&(n.context.supports.msaa?r.msaa=!0:o.warn("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(u,0);const f=n.texture.getGlSource(u).texture;s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+c,3553,f,0)}),r.msaa){const a=s.createFramebuffer();r.framebuffer=a,s.bindFramebuffer(s.FRAMEBUFFER,a),e.colorTextures.forEach((c,u)=>{const _=s.createRenderbuffer();r.msaaRenderBuffer[u]=_})}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,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((c,u)=>{const _=c.source;s.texture.bindSource(_,0);const l=s.texture.getGlSource(_).internalFormat,d=r.msaaRenderBuffer[u];i.bindRenderbuffer(i.RENDERBUFFER,d),i.renderbufferStorageMultisample(i.RENDERBUFFER,4,l,_.pixelWidth,_.pixelHeight),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+u,i.RENDERBUFFER,d)})}}_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)}postrender(e){if(this._renderer.context.multiView&&o.CanvasSource.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,n=e.colorTexture;n.context2D.drawImage(r,0,n.pixelHeight-r.height)}}}class W extends o.RenderTargetSystem{constructor(e){super(e),this.adaptor=new de,this.adaptor.init(e,this)}}W.extension={type:[o.ExtensionType.WebGLSystem],name:"renderTarget"};function me(t,e){const r=[],n=[`
|
|
var g = s.groups;
|
|
var sS = r.shader;
|
|
var p = s.glProgram;
|
|
var ugS = r.uniformGroup;
|
|
var resources;
|
|
`];let s=!1,i=0,a=0;const c=e._getProgramData(t.glProgram);for(const _ in t.groups){const f=t.groups[_];r.push(`
|
|
resources = g[${_}].resources;
|
|
`);for(const l in f.resources){const d=f.resources[l];if(d instanceof o.UniformGroup)d.ubo?r.push(`
|
|
sS.bindUniformBlock(
|
|
resources[${l}],
|
|
sS._uniformBindMap[${_}[${l}],
|
|
${i++}
|
|
);
|
|
`):r.push(`
|
|
ugS.updateUniformGroup(resources[${l}], p, sD);
|
|
`);else if(d instanceof o.BufferResource)r.push(`
|
|
sS.bindUniformBlock(
|
|
resources[${l}],
|
|
sS._uniformBindMap[${_}[${l}],
|
|
${i++}
|
|
);
|
|
`);else if(d instanceof o.TextureSource){const m=t._uniformBindMap[_][l],E=c.uniformData[m];E&&(s||(s=!0,n.push(`
|
|
var tS = r.texture;
|
|
`)),e._gl.uniform1i(E.location,a),r.push(`
|
|
tS.bind(resources[${l}], ${a});
|
|
`),a++)}}}const u=[...n,...r].join(`
|
|
`);return new Function("r","s","sD",u)}class Ee{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 y(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function g(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function j(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 g(2*e);case"bvec3":return g(3*e);case"bvec4":return g(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 b=null;const I={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"},be={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 K(t,e){if(!b){const r=Object.keys(I);b={};for(let n=0;n<r.length;++n){const s=r[n];b[t[s]]=I[s]}}return b[e]}function Se(t,e){const r=K(t,e);return be[r]||"float32"}function pe(t,e,r=!1){const n={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let a=0;a<s;a++){const c=e.getActiveAttrib(t,a);if(c.name.startsWith("gl_"))continue;const u=Se(e,c.type);n[c.name]={location:0,format:u,stride:o.getAttributeInfoFromFormat(u).stride,offset:0,instance:!1,start:0}}const i=Object.keys(n);if(r){i.sort((a,c)=>a>c?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 ge(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),c=e.getActiveUniformBlockParameter(t,s,e.UNIFORM_BLOCK_DATA_SIZE);r[i]={name:i,index:a,size:c}}return r}function Re(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(/\[.*?\]$/,""),c=!!i.name.match(/\[.*?\]$/),u=K(e,i.type);r[a]={name:a,index:s,type:u,size:i.size,isArray:c,value:j(u,i.size)}}return r}function D(t,e){const r=t.getShaderSource(e).split(`
|
|
`).map((_,f)=>`${f}: ${_}`),n=t.getShaderInfoLog(e),s=n.split(`
|
|
`),i={},a=s.map(_=>parseFloat(_.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(_=>_&&!i[_]?(i[_]=!0,!0):!1),c=[""];a.forEach(_=>{r[_-1]=`%c${r[_-1]}%c`,c.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=r.join(`
|
|
`);c[0]=u,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...c),console.groupEnd()}function xe(t,e,r,n){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||D(t,r),t.getShaderParameter(n,t.COMPILE_STATUS)||D(t,n),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function Te(t,e){const r=y(t,t.VERTEX_SHADER,e.vertex),n=y(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"?o.warn("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)||xe(t,s,r,n),e._attributeData=pe(s,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=Re(s,t),e._uniformBlockData=ge(s,t),t.deleteShader(r),t.deleteShader(n);const a={};for(const u in e._uniformData){const _=e._uniformData[u];a[u]={location:t.getUniformLocation(s,u),value:j(_.type,_.size)}}return new Ee(s,a)}const S={textureCount:0,blockIndex:0};class ${constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._nextIndex=0,this._boundUniformsIdsToIndexHash=Object.create(null),this._boundIndexToUniformsHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_programDataHash")}contextChange(e){this._gl=e,this._maxBindings=e.MAX_UNIFORM_BUFFER_BINDINGS?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0,this._programDataHash=Object.create(null),this._boundUniformsIdsToIndexHash=Object.create(null),this._boundIndexToUniformsHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null,this.maxTextures=o.getMaxTexturesPerBatch()}bind(e,r){if(this._setProgram(e.glProgram),r)return;S.textureCount=0,S.blockIndex=0;let n=this._shaderSyncFunctions[e.glProgram._key];n||(n=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),n(this._renderer,e,S)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,S)}bindUniformBlock(e,r,n=0){const s=this._renderer.buffer,i=this._getProgramData(this._activeProgram),a=e._bufferResource;a&&this._renderer.ubo.updateUniformGroup(e),s.updateBuffer(e.buffer);let c=this._boundUniformsIdsToIndexHash[e.uid];if(c===void 0){const f=this._nextIndex++%this._maxBindings,l=this._boundIndexToUniformsHash[f];l&&(this._boundUniformsIdsToIndexHash[l.uid]=void 0),c=this._boundUniformsIdsToIndexHash[e.uid]=f,this._boundIndexToUniformsHash[f]=e,a?s.bindBufferRange(e.buffer,f,e.offset):s.bindBufferBase(e.buffer,f)}const u=this._gl,_=this._activeProgram._uniformBlockData[r].index;i.uniformBlockBindings[n]!==c&&(i.uniformBlockBindings[n]=c,u.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]=Te(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy(),this._programDataHash[e]=null;this._programDataHash=null,this._boundUniformsIdsToIndexHash=null}_generateShaderSync(e,r){return me(e,r)}}$.extension={type:[o.ExtensionType.WebGLSystem],name:"shader"};const ve={f32:`if (cv !== v) {
|
|
cu.value = v;
|
|
gl.uniform1f(location, v);
|
|
}`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
gl.uniform2f(location, v[0], v[1]);
|
|
}`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
gl.uniform3f(location, v[0], v[1], v[2]);
|
|
}`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
cv[3] = v[3];
|
|
gl.uniform4f(location, v[0], v[1], v[2], v[3]);
|
|
}`,i32:`if (cv !== v) {
|
|
cu.value = v;
|
|
gl.uniform1i(location, v);
|
|
}`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
gl.uniform2i(location, v[0], v[1]);
|
|
}`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
gl.uniform3i(location, v[0], v[1], v[2]);
|
|
}`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
cv[3] = v[3];
|
|
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
}`,u32:`if (cv !== v) {
|
|
cu.value = v;
|
|
gl.uniform1ui(location, v);
|
|
}`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
gl.uniform2ui(location, v[0], v[1]);
|
|
}`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
gl.uniform3ui(location, v[0], v[1], v[2]);
|
|
}`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
cv[3] = v[3];
|
|
gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
|
|
}`,bool:`if (cv !== v) {
|
|
cu.value = v;
|
|
gl.uniform1i(location, v);
|
|
}`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
gl.uniform2i(location, v[0], v[1]);
|
|
}`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
gl.uniform3i(location, v[0], v[1], v[2]);
|
|
}`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
|
cv[0] = v[0];
|
|
cv[1] = v[1];
|
|
cv[2] = v[2];
|
|
cv[3] = v[3];
|
|
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
}`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},Ae={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 Be(t,e){const r=[`
|
|
var v = null;
|
|
var cv = null;
|
|
var cu = null;
|
|
var t = 0;
|
|
var gl = renderer.gl;
|
|
var name = null;
|
|
`];for(const n in t.uniforms){if(!e[n]){t.uniforms[n]instanceof o.UniformGroup?t.uniforms[n].ubo?r.push(`
|
|
renderer.shader.bindUniformBlock(uv.${n}, "${n}");
|
|
`):r.push(`
|
|
renderer.shader.updateUniformGroup(uv.${n});
|
|
`):t.uniforms[n]instanceof o.BufferResource&&r.push(`
|
|
renderer.shader.bindBufferResource(uv.${n}, "${n}");
|
|
`);continue}const s=t.uniformStructures[n];let i=!1;for(let a=0;a<o.uniformParsers.length;a++){const c=o.uniformParsers[a];if(s.type===c.type&&c.test(s)){r.push(`name = "${n}";`,o.uniformParsers[a].uniform),i=!0;break}}if(!i){const c=(s.size===1?ve:Ae)[s.type].replace("location",`ud["${n}"].location`);r.push(`
|
|
cu = ud["${n}"];
|
|
cv = cu.value;
|
|
v = uv["${n}"];
|
|
${c};`)}}return new Function("ud","uv","renderer","syncData",r.join(`
|
|
`))}class z{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 Be(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}}z.extension={type:[o.ExtensionType.WebGLSystem],name:"uniformGroup"};function Ne(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 o.DOMAdapter.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 ye=0,Ie=1,De=2,Ce=3,Ge=4,Ue=5,Y=class T{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[ye]=this.setBlend,this.map[Ie]=this.setOffset,this.map[De]=this.setCullFace,this.map[Ce]=this.setDepthTest,this.map[Ge]=this.setFrontFace,this.map[Ue]=this.setDepthMask,this.checks=[],this.defaultState=o.State.for2d()}contextChange(e){this.gl=e,this.blendModesMap=Ne(e),this.reset()}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=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(T._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(T._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.gl[e?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(e){this.gl.frontFace(this.gl[e?"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)}reset(){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}};Y.extension={type:[o.ExtensionType.WebGLSystem],name:"state"};let Oe=Y;class Pe{constructor(e){this.target=F.TEXTURE_2D,this.texture=e,this.width=-1,this.height=-1,this.type=h.UNSIGNED_BYTE,this.internalFormat=x.RGBA,this.format=x.RGBA,this.samplerType=0}}const Fe={id:"buffer",upload(t,e,r){e.width===t.width||e.height===t.height?r.texSubImage2D(r.TEXTURE_2D,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(e.target,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},Me={"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},Le={id:"compressed",upload(t,e,r){r.pixelStorei(r.UNPACK_ALIGNMENT,4);let n=t.pixelWidth,s=t.pixelHeight;const i=!!Me[t.format];for(let a=0;a<t.resource.length;a++){const c=t.resource[a];i?r.compressedTexImage2D(r.TEXTURE_2D,a,e.internalFormat,n,s,0,c):r.texImage2D(r.TEXTURE_2D,a,e.internalFormat,n,s,0,e.format,e.type,c),n=Math.max(n>>1,1),s=Math.max(s>>1,1)}}},q={id:"image",upload(t,e,r,n){const s=t.alphaMode==="premultiply-alpha-on-upload";r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s);const i=e.width,a=e.height,c=t.pixelWidth,u=t.pixelHeight,_=t.resourceWidth,f=t.resourceHeight;_<c||f<u?((i!==c||a!==u)&&r.texImage2D(e.target,0,e.internalFormat,c,u,0,e.format,e.type,null),n===2?r.texSubImage2D(r.TEXTURE_2D,0,0,0,_,f,e.format,e.type,t.resource):r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,e.type,t.resource)):i===c||a===u?r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.format,e.type,t.resource):n===2?r.texImage2D(e.target,0,e.internalFormat,c,u,0,e.format,e.type,t.resource):r.texImage2D(e.target,0,e.internalFormat,e.format,e.type,t.resource),e.width=c,e.height=u}},He={id:"video",upload(t,e,r,n){if(!t.isValid){r.texImage2D(e.target,0,e.internalFormat,1,1,0,e.format,e.type,null);return}q.upload(t,e,r,n)}},C={linear:9729,nearest:9728},we={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},R={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Ve={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function G(t,e,r,n,s,i,a,c){const u=i;if(!c||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const _=R[a?"clamp-to-edge":t.addressModeU],f=R[a?"clamp-to-edge":t.addressModeV],l=R[a?"clamp-to-edge":t.addressModeW];e[s](u,e.TEXTURE_WRAP_S,_),e[s](u,e.TEXTURE_WRAP_T,f),e.TEXTURE_WRAP_R&&e[s](u,e.TEXTURE_WRAP_R,l)}if((!c||t.magFilter!=="linear")&&e[s](u,e.TEXTURE_MAG_FILTER,C[t.magFilter]),r){if(!c||t.mipmapFilter!=="linear"){const _=we[t.minFilter][t.mipmapFilter];e[s](u,e.TEXTURE_MIN_FILTER,_)}}else e[s](u,e.TEXTURE_MIN_FILTER,C[t.minFilter]);if(n&&t.maxAnisotropy>1){const _=Math.min(t.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](u,n.TEXTURE_MAX_ANISOTROPY_EXT,_)}t.compare&&e[s](u,e.TEXTURE_COMPARE_FUNC,Ve[t.compare])}function ke(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 Xe(t,e){let r={},n=t.RGBA;return t instanceof o.DOMAdapter.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 We(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}}const je=4;class Z{constructor(e){this.managedTextures=[],this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._uploads={image:q,buffer:Fe,video:He,compressed:Le},this._useSeparateSamplers=!1,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_glTextures"),this._renderer.renderableGC.addManagedHash(this,"_glSamplers")}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Xe(e,this._renderer.context.extensions),this._mapFormatToType=We(e),this._mapFormatToFormat=ke(e)),this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null);for(let r=0;r<16;r++)this.bind(o.Texture.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._touched=this._renderer.textureGC.count,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e=e||o.Texture.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 Pe(r.createTexture());if(n.type=this._mapFormatToType[e.format],n.internalFormat=this._mapFormatToInternalFormat[e.format],n.format=this._mapFormatToFormat[e.format],e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const s=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(s))+1}return this._glTextures[e.uid]=n,this.managedTextures.includes(e)||(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("destroy",this.onSourceDestroy,this),e.on("unload",this.onSourceUnload,this),e.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(e)),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(n.TEXTURE_2D,s.texture),this._boundTextures[this._activeTextureLocation]=e,G(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",n.TEXTURE_2D,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e){const r=this._glTextures[e.uid];r&&(this.unbind(e),this._glTextures[e.uid]=null,this._gl.deleteTexture(r.texture))}onSourceUpdate(e){const r=this._gl,n=this.getGlSource(e);r.bindTexture(r.TEXTURE_2D,n.texture),this._boundTextures[this._activeTextureLocation]=e,this._uploads[e.uploadMethodId]?this._uploads[e.uploadMethodId].upload(e,n,r,this._renderer.context.webGLVersion):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e.pixelWidth,e.pixelHeight,0,r.RGBA,r.UNSIGNED_BYTE,null),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)}onSourceDestroy(e){e.off("destroy",this.onSourceDestroy,this),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("unload",this.onSourceUnload,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(e),1),this.onSourceUnload(e)}_initSampler(e){const r=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,G(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 this._glTextures[e.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:n,height:s}=this.getPixels(e),i=o.DOMAdapter.get().createCanvas();i.width=n,i.height=s;const a=i.getContext("2d");if(a){const c=a.createImageData(n,s);c.data.set(r),a.putImageData(c,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(je*s*i),c=this._renderer,u=c.renderTarget.getRenderTarget(e),_=c.renderTarget.getGpuRenderTarget(u),f=c.gl;return f.bindFramebuffer(f.FRAMEBUFFER,_.resolveTargetFramebuffer),f.readPixels(Math.round(n.x*r),Math.round(n.y*r),s,i,f.RGBA,f.UNSIGNED_BYTE,a),{pixels:new Uint8ClampedArray(a.buffer),width:s,height:i}}destroy(){this.managedTextures.slice().forEach(e=>this.onSourceDestroy(e)),this.managedTextures=null,this._renderer=null}}Z.extension={type:[o.ExtensionType.WebGLSystem],name:"texture"};class Q{init(){const e=new o.UniformGroup({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new o.Matrix,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),r=o.getMaxTexturesPerBatch(),n=o.compileHighShaderGlProgram({name:"graphics",bits:[o.colorBitGl,o.generateTextureBatchBitGl(r),o.localUniformBitGl,o.roundPixelsBitGl]});this.shader=new o.Shader({glProgram:n,resources:{localUniforms:e,batchSamplers:o.getBatchSamplersUniformGroup(r)}})}execute(e,r){const n=r.context,s=n.customShader||this.shader,i=e.renderer,a=i.graphicsContext,{batcher:c,instructions:u}=a.getContextRenderData(n);s.groups[0]=i.globalUniforms.bindGroup,i.state.set(e.state),i.shader.bind(s),i.geometry.bind(c.geometry,s.glProgram);const _=u.instructions;for(let f=0;f<u.instructionSize;f++){const l=_[f];if(l.size){for(let d=0;d<l.textures.count;d++)i.texture.bind(l.textures.textures[d],d);i.geometry.draw("triangle-list",l.size,l.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}Q.extension={type:[o.ExtensionType.WebGLPipesAdaptor],name:"graphics"};class J{init(){const e=o.compileHighShaderGlProgram({name:"mesh",bits:[o.localUniformBitGl,o.textureBitGl,o.roundPixelsBitGl]});this._shader=new o.Shader({glProgram:e,resources:{uTexture:o.Texture.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new o.Matrix}}}})}execute(e,r){const n=e.renderer;let s=r._shader;if(s){if(!s.glProgram){o.warn("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}}J.extension={type:[o.ExtensionType.WebGLPipesAdaptor],name:"mesh"};const Ke=[...o.SharedSystems,X,ue,ie,O,Z,W,M,z,$,w,Oe,V,H],$e=[...o.SharedRenderPipes],ze=[U,J,Q],ee=[],te=[],re=[];o.extensions.handleByNamedList(o.ExtensionType.WebGLSystem,ee);o.extensions.handleByNamedList(o.ExtensionType.WebGLPipes,te);o.extensions.handleByNamedList(o.ExtensionType.WebGLPipesAdaptor,re);o.extensions.add(...Ke,...$e,...ze);class Ye extends o.AbstractRenderer{constructor(){const e={name:"webgl",type:o.RendererType.WEBGL,systems:ee,renderPipes:te,renderPipeAdaptors:re};super(e)}}exports.WebGLRenderer=Ye;
|