mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-02-07 22:32:35 +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 dis
|
||
|
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++){co
|
||
|
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.msaaRenderBuf
|
||
|
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={t
|