@kauakdev/kauak 0.0.0-stage → 0.1.1
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.
- package/LICENSE +202 -0
- package/README.md +186 -2
- package/bin/kauak.js +12 -0
- package/bridge/config.js +34 -0
- package/bridge/context_remote.py +344 -0
- package/bridge/diffs_remote.py +85 -0
- package/bridge/server.js +2387 -0
- package/cli/commands/serve.js +97 -0
- package/cli/errors.js +2 -0
- package/cli/main.js +101 -0
- package/dist/THIRD_PARTY_LICENSES.txt +183 -0
- package/dist/assets/BufferResource-CHYsmqd5.js +195 -0
- package/dist/assets/CanvasRenderer-DY1TnK1M.js +1 -0
- package/dist/assets/Filter-IrwvDh3w.js +1 -0
- package/dist/assets/RenderTargetSystem-CBR4meCp.js +184 -0
- package/dist/assets/WebGLRenderer-DprtkQRW.js +156 -0
- package/dist/assets/WebGPURenderer-ByQ-10KB.js +42 -0
- package/dist/assets/browserAll-B-9xDvMq.js +14 -0
- package/dist/assets/contours-DG3HeJNa.svg +68 -0
- package/dist/assets/demo-DyZsh87s.css +1 -0
- package/dist/assets/demo-mFndvU9t.js +5 -0
- package/dist/assets/index-BxvDL43s.css +32 -0
- package/dist/assets/index-Do5XwO_P.js +349 -0
- package/dist/assets/webworkerAll-gM2Z784I.js +83 -0
- package/dist/index.html +160 -0
- package/dist/kauak.png +0 -0
- package/package.json +24 -4
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import{a0 as Xe,W as me,M as x,G as Je,b as Qe,w as R,T as _,a as Ze,a1 as ge,l as d,x as $,a2 as E,a3 as et,a4 as Y,a5 as v,R as O,a6 as _e,a7 as tt,d as T,Q as U,a8 as xe,a9 as oe,aa as be,ab as ye,ac as Te,ad as ve,H as L,C as W,D as q,V as w,ae as P,af as rt,P as st,ag as nt,L as at,y as le,ah as de,ai as f,E as it,f as ot,v as V,aj as lt,ak as dt,X as ce,al as ct,am as ht,an as ut}from"./index-Do5XwO_P.js";import{F as pt}from"./Filter-IrwvDh3w.js";var ft=`in vec2 vMaskCoord;
|
|
2
|
+
in vec2 vTextureCoord;
|
|
3
|
+
|
|
4
|
+
uniform sampler2D uTexture;
|
|
5
|
+
uniform sampler2D uMaskTexture;
|
|
6
|
+
|
|
7
|
+
uniform float uAlpha;
|
|
8
|
+
uniform vec4 uMaskClamp;
|
|
9
|
+
uniform float uInverse;
|
|
10
|
+
uniform float uChannel;
|
|
11
|
+
|
|
12
|
+
out vec4 finalColor;
|
|
13
|
+
|
|
14
|
+
void main(void)
|
|
15
|
+
{
|
|
16
|
+
float clip = step(3.5,
|
|
17
|
+
step(uMaskClamp.x, vMaskCoord.x) +
|
|
18
|
+
step(uMaskClamp.y, vMaskCoord.y) +
|
|
19
|
+
step(vMaskCoord.x, uMaskClamp.z) +
|
|
20
|
+
step(vMaskCoord.y, uMaskClamp.w));
|
|
21
|
+
|
|
22
|
+
// TODO look into why this is needed
|
|
23
|
+
float npmAlpha = uAlpha;
|
|
24
|
+
vec4 original = texture(uTexture, vTextureCoord);
|
|
25
|
+
vec4 masky = texture(uMaskTexture, vMaskCoord);
|
|
26
|
+
|
|
27
|
+
float a;
|
|
28
|
+
if (uChannel == 1.0) {
|
|
29
|
+
a = masky.a * npmAlpha * clip;
|
|
30
|
+
} else {
|
|
31
|
+
float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
|
|
32
|
+
a = alphaMul * masky.r * npmAlpha * clip;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (uInverse == 1.0) {
|
|
36
|
+
a = 1.0 - a;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
finalColor = original * a;
|
|
40
|
+
}
|
|
41
|
+
`,mt=`in vec2 aPosition;
|
|
42
|
+
|
|
43
|
+
out vec2 vTextureCoord;
|
|
44
|
+
out vec2 vMaskCoord;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
uniform vec4 uInputSize;
|
|
48
|
+
uniform vec4 uOutputFrame;
|
|
49
|
+
uniform vec4 uOutputTexture;
|
|
50
|
+
uniform mat3 uFilterMatrix;
|
|
51
|
+
|
|
52
|
+
vec4 filterVertexPosition( vec2 aPosition )
|
|
53
|
+
{
|
|
54
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
55
|
+
|
|
56
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
57
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
58
|
+
|
|
59
|
+
return vec4(position, 0.0, 1.0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
vec2 filterTextureCoord( vec2 aPosition )
|
|
63
|
+
{
|
|
64
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
vec2 getFilterCoord( vec2 aPosition )
|
|
68
|
+
{
|
|
69
|
+
return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void main(void)
|
|
73
|
+
{
|
|
74
|
+
gl_Position = filterVertexPosition(aPosition);
|
|
75
|
+
vTextureCoord = filterTextureCoord(aPosition);
|
|
76
|
+
vMaskCoord = getFilterCoord(aPosition);
|
|
77
|
+
}
|
|
78
|
+
`,he=`struct GlobalFilterUniforms {
|
|
79
|
+
uInputSize:vec4<f32>,
|
|
80
|
+
uInputPixel:vec4<f32>,
|
|
81
|
+
uInputClamp:vec4<f32>,
|
|
82
|
+
uOutputFrame:vec4<f32>,
|
|
83
|
+
uGlobalFrame:vec4<f32>,
|
|
84
|
+
uOutputTexture:vec4<f32>,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
struct MaskUniforms {
|
|
88
|
+
uFilterMatrix:mat3x3<f32>,
|
|
89
|
+
uMaskClamp:vec4<f32>,
|
|
90
|
+
uAlpha:f32,
|
|
91
|
+
uInverse:f32,
|
|
92
|
+
uChannel:f32,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
96
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
97
|
+
@group(0) @binding(2) var uSampler : sampler;
|
|
98
|
+
|
|
99
|
+
@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
|
|
100
|
+
@group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
|
|
101
|
+
|
|
102
|
+
struct VSOutput {
|
|
103
|
+
@builtin(position) position: vec4<f32>,
|
|
104
|
+
@location(0) uv : vec2<f32>,
|
|
105
|
+
@location(1) filterUv : vec2<f32>,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
109
|
+
{
|
|
110
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
111
|
+
|
|
112
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
113
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
114
|
+
|
|
115
|
+
return vec4(position, 0.0, 1.0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
119
|
+
{
|
|
120
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
124
|
+
{
|
|
125
|
+
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
|
|
129
|
+
{
|
|
130
|
+
return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn getSize() -> vec2<f32>
|
|
134
|
+
{
|
|
135
|
+
return gfu.uGlobalFrame.zw;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@vertex
|
|
139
|
+
fn mainVertex(
|
|
140
|
+
@location(0) aPosition : vec2<f32>,
|
|
141
|
+
) -> VSOutput {
|
|
142
|
+
return VSOutput(
|
|
143
|
+
filterVertexPosition(aPosition),
|
|
144
|
+
filterTextureCoord(aPosition),
|
|
145
|
+
getFilterCoord(aPosition)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@fragment
|
|
150
|
+
fn mainFragment(
|
|
151
|
+
@location(0) uv: vec2<f32>,
|
|
152
|
+
@location(1) filterUv: vec2<f32>,
|
|
153
|
+
@builtin(position) position: vec4<f32>
|
|
154
|
+
) -> @location(0) vec4<f32> {
|
|
155
|
+
|
|
156
|
+
var maskClamp = filterUniforms.uMaskClamp;
|
|
157
|
+
var uAlpha = filterUniforms.uAlpha;
|
|
158
|
+
|
|
159
|
+
var clip = step(3.5,
|
|
160
|
+
step(maskClamp.x, filterUv.x) +
|
|
161
|
+
step(maskClamp.y, filterUv.y) +
|
|
162
|
+
step(filterUv.x, maskClamp.z) +
|
|
163
|
+
step(filterUv.y, maskClamp.w));
|
|
164
|
+
|
|
165
|
+
var mask = textureSample(uMaskTexture, uSampler, filterUv);
|
|
166
|
+
var source = textureSample(uTexture, uSampler, uv);
|
|
167
|
+
|
|
168
|
+
var a: f32;
|
|
169
|
+
if (filterUniforms.uChannel == 1.0) {
|
|
170
|
+
a = mask.a * uAlpha * clip;
|
|
171
|
+
} else {
|
|
172
|
+
var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
|
|
173
|
+
a = alphaMul * mask.r * uAlpha * clip;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (filterUniforms.uInverse == 1.0) {
|
|
177
|
+
a = 1.0 - a;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return source * a;
|
|
181
|
+
}
|
|
182
|
+
`;class gt extends pt{constructor(e){const{sprite:t,...r}=e,s=new Xe(t.texture),n=new me({uFilterMatrix:{value:new x,type:"mat3x3<f32>"},uMaskClamp:{value:s.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"},uChannel:{value:e.channel==="alpha"?1:0,type:"f32"}}),i=Je.from({vertex:{source:he,entryPoint:"mainVertex"},fragment:{source:he,entryPoint:"mainFragment"}}),l=Qe.from({vertex:mt,fragment:ft,name:"mask-filter"});super({...r,gpuProgram:i,glProgram:l,clipToViewport:!1,resources:{filterUniforms:n,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=s}setSprite(e){this.sprite=e;const t=this._getSafeTexture();this._textureMatrix.texture=t,this.resources.uMaskTexture=t.source}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}set channel(e){this.resources.filterUniforms.uniforms.uChannel=e==="alpha"?1:0}get channel(){return this.resources.filterUniforms.uniforms.uChannel===1?"alpha":"red"}apply(e,t,r,s){const n=this._getSafeTexture();this._textureMatrix.texture=n,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=n.source,e.applyFilter(this,t,r,s)}_getSafeTexture(){const e=this.sprite.texture;return e.destroyed||!e.source||e.source.destroyed?(R("[MaskFilter] The mask texture was destroyed while the mask is still in use. Remove the mask before destroying its texture."),_.EMPTY):e}destroy(e=!1){this._textureMatrix.destroy(),super.destroy(e)}}const K=class Ce{constructor(e,t){var r,s;this.state=Ze.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,(s=(r=this._adaptor).init)==null||s.call(r,this)}static getBatcher(e,t){return new this._availableBatchers[e]({maxTextures:t})}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new ge({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const r in this._activeBatches)this._activeBatches[r].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let r=this._activeBatches[e.batcherName];r||(r=this._activeBatches[e.batcherName]=Ce.getBatcher(e.batcherName,this.renderer.limits.maxBatchableTextures),r.begin()),this._activeBatch=r}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const r in t){const s=t[r],n=s.geometry;n.indexBuffer.setDataWithSize(s.indexBuffer,s.indexSize,!0),n.buffers[0].setDataWithSize(s.attributeBuffer.float32View,s.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const r in t){const s=t[r],n=s.geometry;s.dirty&&(s.dirty=!1,n.buffers[0].update(s.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,r=t.geometry,s=t.shader;this._adaptor.start(this,r,s)}this._adaptor.execute(this,e)}destroyInstructionSet(e){const t=this._batchersByInstructionSet[e.uid];if(t){for(const r in t)t[r].destroy();delete this._batchersByInstructionSet[e.uid],this._activeBatches===t&&(this._activeBatches=Object.create(null),this._activeBatch=null)}}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};K.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"batch"};K._availableBatchers=Object.create(null);let Se=K;$.handleByMap(d.Batcher,Se._availableBatchers);$.add(ge);const _t=new Y;class xt extends _e{constructor(){super(),this._placeholderSprite=new tt(_.EMPTY),this.filters=[new gt({sprite:this._placeholderSprite,inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].setSprite(e)}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}get channel(){return this.filters[0].channel}set channel(e){this.filters[0].channel=e}reset(){this._placeholderSprite.texture=_.EMPTY,this.sprite=this._placeholderSprite}}class ke{constructor(e){this._activeMaskStage=[],this._usedEffects=[],this._renderer=e,e.runners.postrender.add(this)}push(e,t,r){const s=this._renderer;if(s.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.channel=t._maskOptions.channel??"red",e.renderMaskToTexture){const n=e.mask;n.includeInBuild=!0,n.collectRenderables(r,s,null),n.includeInBuild=!1}s.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,r=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const s=E.get(xt);if(s.inverse=e.inverse,s.channel=e.mask.channel,r){e.mask.mask.measurable=!0;const n=et(e.mask.mask,!0,_t);e.mask.mask.measurable=!1,n.ceil();const i=t.renderTarget.renderTarget.colorTexture.source,l=v.getOptimalTexture({width:n.width,height:n.height,resolution:i._resolution,antialias:i.antialias});t.renderTarget.push({target:l,clear:!0}),t.globalUniforms.push({offset:n,worldColor:4294967295});const o=s.sprite;o.texture=l,o.worldTransform.tx=n.minX,o.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:s,maskedContainer:e.maskedContainer,filterTexture:l})}else s.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:s,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const s=this._activeMaskStage[this._activeMaskStage.length-1];r&&(t.type===O.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:s.maskedContainer,filterEffect:s.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const s=this._activeMaskStage.pop();r&&v.returnTexture(s.filterTexture),this._usedEffects.push(s.filterEffect)}}postrender(){const e=this._usedEffects;for(let t=0;t<e.length;t++)E.return(e[t]);e.length=0}destroy(){this.postrender(),this._renderer.runners.postrender.remove(this),this._renderer=null,this._activeMaskStage=null,this._usedEffects=null}}ke.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"alphaMask"};class Re{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,r){this._renderer.renderPipes.batch.break(r);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const i=this._colorStack[this._colorStackIndex];i!==this._currentColor&&(this._currentColor=i,r.add({renderPipeId:"colorMask",colorMask:i,canBundle:!1})),this._colorStackIndex++}pop(e,t,r){this._renderer.renderPipes.batch.break(r);const n=this._colorStack;this._colorStackIndex--;const i=n[this._colorStackIndex-1];i!==this._currentColor&&(this._currentColor=i,r.add({renderPipeId:"colorMask",colorMask:i,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}Re.extension={type:[d.WebGLPipes,d.WebGPUPipes],name:"colorMask"};class Me{constructor(e){this._maskHash=new WeakMap,this._renderer=e}push(e,t,r){const s=e,n=this._renderer;n.renderPipes.batch.break(r),n.renderPipes.blendMode.setBlendMode(s.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const i=s.mask;i.includeInBuild=!0,this._maskHash.has(s)||this._maskHash.set(s,{instructionsStart:0,instructionsLength:0});const l=this._maskHash.get(s);l.instructionsStart=r.instructionSize,i.collectRenderables(r,n,null),i.includeInBuild=!1,n.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const o=r.instructionSize-l.instructionsStart-1;l.instructionsLength=o}pop(e,t,r){const s=e,n=this._renderer;n.renderPipes.batch.break(r),n.renderPipes.blendMode.setBlendMode(s.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const i=this._maskHash.get(e);for(let l=0;l<i.instructionsLength;l++)r.instructions[r.instructionSize++]=r.instructions[i.instructionsStart++];r.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){const r=this._renderer,s=r.renderTarget.getGpuRenderTarget(r.renderTarget.renderTarget);let n=s.maskStackIndex;e.action==="pushMaskBegin"?(r.renderTarget.ensureDepthStencil(),r.stencil.setStencilMode(T.RENDERING_MASK_ADD,n),n++,r.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?r.stencil.setStencilMode(T.INVERSE_MASK_ACTIVE,n):r.stencil.setStencilMode(T.MASK_ACTIVE,n),r.colorMask.setMask(15)):e.action==="popMaskBegin"?(r.colorMask.setMask(0),n!==0?r.stencil.setStencilMode(T.RENDERING_MASK_REMOVE,n):(r.renderTarget.clear(null,U.STENCIL),r.stencil.setStencilMode(T.DISABLED,n)),n--):e.action==="popMaskEnd"&&(e.inverse?r.stencil.setStencilMode(T.INVERSE_MASK_ACTIVE,n):r.stencil.setStencilMode(T.MASK_ACTIVE,n),r.colorMask.setMask(15)),s.maskStackIndex=n}destroy(){this._renderer=null,this._maskHash=null}}Me.extension={type:[d.WebGLPipes,d.WebGPUPipes],name:"stencilMask"};class we{constructor(e){this._renderer=e}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}addRenderable(e,t){this._renderer.renderPipes.batch.break(t),t.add(e)}execute(e){e.isRenderable&&e.render(this._renderer)}destroy(){this._renderer=null}}we.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"customRender"};function N(a,e){const t=a.instructionSet,r=t.instructions;for(let s=0;s<t.instructionSize;s++){const n=r[s];e[n.renderPipeId].execute(n)}}class Pe{constructor(e){this._renderer=e}addRenderGroup(e,t){e.isCachedAsTexture?this._addRenderableCacheAsTexture(e,t):this._addRenderableDirect(e,t)}execute(e){e.isRenderable&&(e.isCachedAsTexture?this._executeCacheAsTexture(e):this._executeDirect(e))}destroy(){this._renderer=null}_addRenderableDirect(e,t){this._renderer.renderPipes.batch.break(t),e._batchableRenderGroup&&(E.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const r=e._batchableRenderGroup??(e._batchableRenderGroup=E.get(xe));r.renderable=e.root,r.transform=e.root.relativeGroupTransform,r.texture=e.texture,r.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(r,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=new x().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push({target:e.texture,clear:!0,frame:e.texture.frame}),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),N(e,this._renderer.renderPipes),this._renderer.renderTarget.finishRenderPass(),this._renderer.renderTarget.pop(),this._renderer.globalUniforms.pop()}e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup),e._batchableRenderGroup._batcher.geometry.buffers[0].update()}_executeDirect(e){this._renderer.globalUniforms.push({worldTransformMatrix:e.inverseParentTextureTransform,worldColor:e.worldColorAlpha}),N(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Pe.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"renderGroup"};class Be{constructor(e){this._renderer=e}addRenderable(e,t){const r=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,r),this._renderer.renderPipes.batch.addToBatch(r,t)}updateRenderable(e){const t=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,t),t._batcher.updateElement(t)}validateRenderable(e){const t=this._getGpuSprite(e);return!t._batcher.checkAndUpdateTexture(t,e._texture)}_updateBatchableSprite(e,t){t.bounds=e.visualBounds,t.texture=e._texture}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=new xe;return t.renderable=e,t.transform=e.groupTransform,t.texture=e._texture,t.bounds=e.visualBounds,t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}Be.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"sprite"};const B={};$.handle(d.BlendMode,a=>{if(!a.name)throw new Error("BlendMode extension must have a name property");B[a.name]=a.ref},a=>{delete B[a.name]});class Ge{constructor(e){this._blendModeStack=[],this._isAdvanced=!1,this._filterHash=Object.create(null),this._renderer=e,this._renderer.runners.prerender.add(this)}prerender(){this._activeBlendMode="normal",this._isAdvanced=!1}pushBlendMode(e,t,r){this._blendModeStack.push(t),this.setBlendMode(e,t,r)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,r){var n;const s=e instanceof oe;if(this._activeBlendMode===t){this._isAdvanced&&e&&!s&&((n=this._renderableList)==null||n.push(e));return}this._isAdvanced&&this._endAdvancedBlendMode(r),this._activeBlendMode=t,e&&(this._isAdvanced=!!B[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,r))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const r=this._activeBlendMode;if(!B[r]){R(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const s=this._ensureFilterEffect(r),n=e instanceof oe,i={renderPipeId:"filter",action:"pushFilter",filterEffect:s,renderables:n?null:[e],container:n?e.root:null,canBundle:!1};this._renderableList=i.renderables,t.add(i)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new _e,t.filters=[new B[e]]),t}_endAdvancedBlendMode(e){this._isAdvanced=!1,this._renderableList=null,this._renderer.renderPipes.batch.break(e),e.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}buildStart(){this._isAdvanced=!1}buildEnd(e){this._isAdvanced&&this._endAdvancedBlendMode(e)}destroy(){this._renderer=null,this._renderableList=null;for(const e in this._filterHash)this._filterHash[e].destroy();this._filterHash=null}}Ge.extension={type:[d.WebGLPipes,d.WebGPUPipes,d.CanvasPipes],name:"blendMode"};function j(a,e){e||(e=0);for(let t=e;t<a.length&&a[t];t++)a[t]=null}const bt=new L,ue=ye|Te|ve;function Ae(a,e=!1){yt(a);const t=a.childrenToUpdate,r=a.updateTick++;for(const s in t){const n=Number(s),i=t[s],l=i.list,o=i.index;for(let h=0;h<o;h++){const c=l[h];c.parentRenderGroup===a&&c.relativeRenderGroupDepth===n&&Ue(c,r,0)}j(l,o),i.index=0}if(e)for(let s=0;s<a.renderGroupChildren.length;s++)Ae(a.renderGroupChildren[s],e)}function yt(a){const e=a.root;let t;if(a.renderGroupParent){const r=a.renderGroupParent;a.worldTransform.appendFrom(e.relativeGroupTransform,r.worldTransform),a.worldColor=be(e.groupColor,r.worldColor),t=e.groupAlpha*r.worldAlpha}else a.worldTransform.copyFrom(e.localTransform),a.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,a.worldAlpha=t,a.worldColorAlpha=a.worldColor+((t*255|0)<<24)}function Ue(a,e,t){if(e===a.updateTick)return;a.updateTick=e,a.didChange=!1;const r=a.localTransform;a.updateLocalTransform();const s=a.parent;if(s&&!s.renderGroup?(t|=a._updateFlags,a.relativeGroupTransform.appendFrom(r,s.relativeGroupTransform),t&ue&&pe(a,s,t)):(t=a._updateFlags,a.relativeGroupTransform.copyFrom(r),t&ue&&pe(a,bt,t)),!a.renderGroup){const n=a.children,i=n.length;for(let h=0;h<i;h++)Ue(n[h],e,t);const l=a.parentRenderGroup,o=a;o.renderPipeId&&!l.structureDidChange&&l.updateRenderable(o)}}function pe(a,e,t){if(t&Te){a.groupColor=be(a.localColor,e.groupColor);let r=a.localAlpha*e.groupAlpha;r=r<0?0:r>1?1:r,a.groupAlpha=r,a.groupColorAlpha=a.groupColor+((r*255|0)<<24)}t&ve&&(a.groupBlendMode=a.localBlendMode==="inherit"?e.groupBlendMode:a.localBlendMode),t&ye&&(a.globalDisplayStatus=a.localDisplayStatus&e.globalDisplayStatus),a._updateFlags=0}function Tt(a,e){const{list:t}=a.childrenRenderablesToUpdate;let r=!1;for(let s=0;s<a.childrenRenderablesToUpdate.index;s++){const n=t[s];if(r=e[n.renderPipeId].validateRenderable(n),r)break}return a.structureDidChange=r,r}const vt=new x;class Ie{constructor(e){this._renderer=e}render({container:e,transform:t}){const r=e.parent,s=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const n=this._renderer,i=vt;t&&(i.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const l=n.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),n.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),N(e.renderGroup,l),l.uniformBatch&&l.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(i),e.parent=r,e.renderGroup.renderGroupParent=s}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let r=e.renderGroupChildren.length-1;r>=0;r--)this._updateCachedRenderGroups(e.renderGroupChildren[r],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const r=e.root.getLocalBounds(),s=this._renderer,n=e.textureOptions.resolution||s.view.resolution,i=e.textureOptions.antialias??s.view.antialias,l=e.textureOptions.scaleMode??"linear",o=e.texture;r.ceil(),e.texture&&v.returnTexture(e.texture);const h=v.getOptimalTexture({width:r.width,height:r.height,resolution:n,antialias:i,scaleMode:l});e.texture=h,e._textureBounds||(e._textureBounds=new Y),e._textureBounds.copyFrom(r),o!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(v.returnTexture(e.texture),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,r=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=r,e.structureDidChange?j(e.childrenRenderablesToUpdate.list,0):Tt(e,r),Ae(e),e.structureDidChange?(e.structureDidChange=!1,this._buildInstructions(e,t)):this._updateRenderables(e),e.childrenRenderablesToUpdate.index=0,t.renderPipes.batch.upload(e.instructionSet),!(e.isCachedAsTexture&&!e.textureNeedsUpdate))for(let s=0;s<e.renderGroupChildren.length;s++)this._updateRenderGroups(e.renderGroupChildren[s])}_updateRenderables(e){const{list:t,index:r}=e.childrenRenderablesToUpdate;for(let s=0;s<r;s++){const n=t[s];n.didViewUpdate&&e.updateRenderable(n)}j(t,r)}_buildInstructions(e,t){const r=e.root,s=e.instructionSet;s.reset();const n=t.renderPipes?t:t.batch.renderer,i=n.renderPipes;i.batch.buildStart(s),i.blendMode.buildStart(),i.colorMask.buildStart(),r.sortableChildren&&r.sortChildren(),r.collectRenderablesWithEffects(s,n,null),i.batch.buildEnd(s),i.blendMode.buildEnd(s)}}Ie.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"renderGroup"};const X=class De{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new W(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...De.defaultOptions,...e},this.clearBeforeRender=e.clearBeforeRender,this.color=e.background||e.backgroundColor||this._backgroundColor,this.alpha=e.backgroundAlpha,this._backgroundColor.setAlpha(e.backgroundAlpha)}get color(){return this._backgroundColor}set color(e){W.shared.setValue(e).alpha<1&&this._backgroundColor.alpha===1&&R("Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."),this._backgroundColor.setValue(e)}get alpha(){return this._backgroundColor.alpha}set alpha(e){this._backgroundColor.setAlpha(e)}get colorRgba(){return this._backgroundColor.toArray()}destroy(){}};X.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"background",priority:0};X.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let Ct=X;const H={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},J=class Ee{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof L||e instanceof _?{target:e,...t}:{...t,...e}}async image(e){const t=q.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Ee.defaultImageOptions);const{format:t,quality:r}=e,s=this.canvas(e);if(s.toBlob!==void 0)return new Promise((n,i)=>{s.toBlob(l=>{if(!l){i(new Error("ICanvas.toBlob failed!"));return}const o=new FileReader;o.onload=()=>n(o.result),o.onerror=i,o.readAsDataURL(l)},H[t],r)});if(s.toDataURL!==void 0)return s.toDataURL(H[t],r);if(s.convertToBlob!==void 0){const n=await s.convertToBlob({type:H[t],quality:r});return new Promise((i,l)=>{const o=new FileReader;o.onload=()=>i(o.result),o.onerror=l,o.readAsDataURL(n)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer;if(t instanceof _)return r.texture.generateCanvas(t);const s=r.textureGenerator.generateTexture(e),n=r.texture.generateCanvas(s);return s.destroy(!0),n}pixels(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer,s=t instanceof _?t:r.textureGenerator.generateTexture(e),n=r.texture.getPixels(s);return t instanceof L&&s.destroy(!0),n}texture(e){return e=this._normalizeOptions(e),e.target instanceof _?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),r=document.createElement("a");r.download=e.filename??"image.png",r.href=t.toDataURL("image/png"),document.body.appendChild(r),r.click(),document.body.removeChild(r)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const r=this.canvas(e),s=r.toDataURL();console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);const n=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${s}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",n)}destroy(){this._renderer=null}};J.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"extract"};J.defaultImageOptions={format:"png",quality:1};let St=J;class Q extends _{static create(e){const{dynamic:t,textureOptions:r,...s}=e;return new Q({...r,source:new w(s),dynamic:t??!1})}resize(e,t,r){return this.source.resize(e,t,r),this}}const kt=new P,Rt=new Y,Mt=[0,0,0,0];class Le{constructor(e){this._renderer=e}generateTexture(e){var c;e instanceof L&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,r=e.antialias||this._renderer.view.antialias,s=e.target;let n=e.clearColor;n?n=Array.isArray(n)&&n.length===4?n:W.shared.setValue(n).toArray():n=Mt;const i=((c=e.frame)==null?void 0:c.copyTo(kt))||rt(s,Rt).rectangle,l=e.defaultAnchor&&{defaultAnchor:e.defaultAnchor};i.width=Math.max(i.width,1/t)|0,i.height=Math.max(i.height,1/t)|0;const o=Q.create({...e.textureSourceOptions,width:i.width,height:i.height,resolution:t,antialias:r,textureOptions:l}),h=x.shared.translate(-i.x,-i.y);return this._renderer.render({container:s,transform:h,target:o,clearColor:n}),o.source.updateMipmaps(),o}destroy(){this._renderer=null}}Le.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"textureGenerator"};function wt(a){let e=!1;for(const r in a)if(a[r]==null){e=!0;break}if(!e)return a;const t=Object.create(null);for(const r in a){const s=a[r];s&&(t[r]=s)}return t}function Pt(a){let e=0;for(let t=0;t<a.length;t++)a[t]==null?e++:a[t-e]=a[t];return a.length-=e,a}const Z=class Oe{constructor(e){this._managedResources=[],this._managedResourceHashes=[],this._managedCollections=[],this._ready=!1,this._running=!1,this._renderer=e}init(e){e={...Oe.defaultOptions,...e},this.maxUnusedTime=e.gcMaxUnusedTime,this._frequency=e.gcFrequency,this.enabled=e.gcActive,this.now=performance.now()}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>{this._ready=!0},this._frequency,!1),this._collectionsHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedCollections){const{context:r,collection:s,type:n}=t;n==="hash"?r[s]=wt(r[s]):r[s]=Pt(r[s])}},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._collectionsHandler),this._handler=0,this._collectionsHandler=0))}prerender({container:e}){this.now=performance.now(),e.renderGroup.gcTick=this._renderer.tick++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}postrender(){!this._ready||!this.enabled||(this.run(),this._ready=!1)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t,e.gcTick=t;for(const r of e.renderGroupChildren)this._updateInstructionGCTick(r,t)}addCollection(e,t,r){this._managedCollections.push({context:e,collection:t,type:r})}addResource(e,t){var s,n;if(e._gcLastUsed!==-1){e._gcLastUsed=this.now,(s=e._onTouch)==null||s.call(e,this.now);return}const r=this._managedResources.length;e._gcData={index:r,type:t},e._gcLastUsed=this.now,(n=e._onTouch)==null||n.call(e,this.now),e.once("unload",this.removeResource,this),this._managedResources.push(e)}removeResource(e){const t=e._gcData;if(!t)return;const r=t.index,s=this._managedResources.length-1;if(this._running)this._managedResources[r]=null;else{if(r!==s){const n=this._managedResources[s];this._managedResources[r]=n,n._gcData.index=r}this._managedResources.length--}e._gcData=null,e._gcLastUsed=-1}addResourceHash(e,t,r,s=0){this._managedResourceHashes.push({context:e,hash:t,type:r,priority:s}),this._managedResourceHashes.sort((n,i)=>n.priority-i.priority)}run(){if(this._running)return;const e=performance.now(),t=this._managedResourceHashes,r=this._managedResources;this._running=!0;try{for(const n of t)this.runOnHash(n,e);const s=r.length;for(let n=0;n<s;n++){const i=r[n];i&&this.runOnResource(i,e)}}finally{let s=0;for(let n=0;n<r.length;n++){const i=r[n];i&&(s!==n&&(r[s]=i,i._gcData.index=s),s++)}r.length=s,this._running=!1}}updateRenderableGCTick(e,t){var n,i;const r=e.renderGroup??e.parentRenderGroup,s=((n=r==null?void 0:r.instructionSet)==null?void 0:n.gcTick)??-1;((r==null?void 0:r.gcTick)??0)===s&&(e._gcLastUsed=t,(i=e._onTouch)==null||i.call(e,t))}runOnResource(e,t){e._gcData.type==="renderable"&&this.updateRenderableGCTick(e,t),!(t-e._gcLastUsed<this.maxUnusedTime||!e.autoGarbageCollect)&&(e.off("unload",this.removeResource,this),e.unload(),this.removeResource(e))}_createHashClone(e,t){const r=Object.create(null);for(const s in e){if(s===t)break;e[s]!==null&&(r[s]=e[s])}return r}runOnHash(e,t){var h;const{context:r,hash:s,type:n}=e,i=r[s];let l=null,o=0;for(const c in i){const u=i[c];if(u===null){o++,o===1e4&&!l&&(l=this._createHashClone(i,c));continue}if(u._gcLastUsed===-1){u._gcLastUsed=t,(h=u._onTouch)==null||h.call(u,t),l&&(l[c]=u);continue}if(n==="renderable"&&this.updateRenderableGCTick(u,t),!(t-u._gcLastUsed<this.maxUnusedTime)&&u.autoGarbageCollect){if(n==="renderable"){const p=u,m=p.renderGroup??p.parentRenderGroup;m&&(m.structureDidChange=!0)}u.unload(),u._gcData=null,u._gcLastUsed=-1,l||(o+1!==1e4?(i[c]=null,o++):l=this._createHashClone(i,c))}else l&&(l[c]=u)}l&&(r[s]=l)}destroy(){this.enabled=!1,this._managedResources.forEach(e=>{e==null||e.off("unload",this.removeResource,this)}),this._managedResources.length=0,this._managedResourceHashes.length=0,this._managedCollections.length=0,this._renderer=null}};Z.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"gc",priority:0};Z.defaultOptions={gcActive:!0,gcMaxUnusedTime:6e4,gcFrequency:3e4};let Bt=Z;class Fe{constructor(e){this._stackIndex=0,this._globalUniformDataStack=[],this._uniformsPool=[],this._activeUniforms=[],this._bindGroupPool=[],this._activeBindGroups=[],this._renderer=e}reset(){this._stackIndex=0;for(let e=0;e<this._activeUniforms.length;e++)this._uniformsPool.push(this._activeUniforms[e]);for(let e=0;e<this._activeBindGroups.length;e++)this._bindGroupPool.push(this._activeBindGroups[e]);this._activeUniforms.length=0,this._activeBindGroups.length=0}start(e){this.reset(),this.push(e)}bind({size:e,projectionMatrix:t,worldTransformMatrix:r,worldColor:s,offset:n}){const i=this._renderer.renderTarget.renderTarget,l=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new x,worldColor:4294967295,offset:new st},o={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||i.size,worldTransformMatrix:r||l.worldTransformMatrix,worldColor:s||l.worldColor,offset:n||l.offset,bindGroup:null},h=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(h);const c=h.uniforms;c.uProjectionMatrix=o.projectionMatrix,c.uResolution=o.resolution,c.uWorldTransformMatrix.copyFrom(o.worldTransformMatrix),c.uWorldTransformMatrix.tx-=o.offset.x,c.uWorldTransformMatrix.ty-=o.offset.y,nt(o.worldColor,c.uWorldColorAlpha,0),h.update();let u;this._renderer.renderPipes.uniformBatch?u=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(h,!1):(u=this._bindGroupPool.pop()||new at,this._activeBindGroups.push(u),u.setResource(h,0)),o.bindGroup=u,this._currentGlobalUniformData=o}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===O.WEBGL&&this._currentGlobalUniformData.bindGroup.resources[0].update()}get bindGroup(){return this._currentGlobalUniformData.bindGroup}get globalUniformData(){return this._currentGlobalUniformData}get uniformGroup(){return this._currentGlobalUniformData.bindGroup.resources[0]}_createUniforms(){return new me({uProjectionMatrix:{value:new x,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new x,type:"mat3x3<f32>"},uWorldColorAlpha:{value:new Float32Array(4),type:"vec4<f32>"},uResolution:{value:[0,0],type:"vec2<f32>"}},{isStatic:!0})}destroy(){this._renderer=null,this._globalUniformDataStack.length=0,this._uniformsPool.length=0,this._activeUniforms.length=0,this._bindGroupPool.length=0,this._activeBindGroups.length=0,this._currentGlobalUniformData=null}}Fe.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"globalUniforms"};let Gt=1;class ze{constructor(){this._tasks=[],this._offset=0}init(){le.system.add(this._update,this)}repeat(e,t,r=!0){const s=Gt++;let n=0;return r&&(this._offset+=1e3,n=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:n,last:performance.now(),repeat:!0,id:s}),s}cancel(e){for(let t=0;t<this._tasks.length;t++)if(this._tasks[t].id===e){this._tasks.splice(t,1);return}}_update(){const e=performance.now();for(let t=0;t<this._tasks.length;t++){const r=this._tasks[t];if(e-r.offset-r.last>=r.duration){const s=e-r.start;r.func(s),r.last=e}}}destroy(){le.system.remove(this._update,this),this._tasks.length=0}}ze.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"scheduler",priority:0};let fe=!1;function At(a){if(!fe){if(q.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${de} (${a}) http://www.pixijs.com/
|
|
183
|
+
|
|
184
|
+
`,"background: #E72264; padding:5px 0;","background: #6CA2EA; padding:5px 0;","background: #B5D33D; padding:5px 0;","background: #FED23F; padding:5px 0;","color: #FFFFFF; background: #E72264; padding:5px 0;","color: #E72264; background: #FFFFFF; padding:5px 0;"];globalThis.console.log(...e)}else globalThis.console&&globalThis.console.log(`PixiJS ${de} - ${a} - http://www.pixijs.com/`);fe=!0}}class ee{constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===O.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),At(t)}}}ee.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"hello",priority:-2};ee.defaultOptions={hello:!1};const te=class He{constructor(e){this._renderer=e}init(e){e={...He.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime}get enabled(){return f("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled}set enabled(e){f("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled=e}addManagedHash(e,t){f("8.15.0","RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"hash")}addManagedArray(e,t){f("8.15.0","RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"array")}addRenderable(e){f("8.15.0","RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead."),this._renderer.gc.addResource(e,"renderable")}run(){f("8.15.0","RenderableGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};te.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"renderableGC",priority:0};te.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let Ut=te;const re=class I{get count(){return this._renderer.tick}get checkCount(){return this._checkCount}set checkCount(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._checkCount=e}get maxIdle(){return this._renderer.gc.maxUnusedTime/1e3*60}set maxIdle(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.maxUnusedTime=e/60*1e3}get checkCountMax(){return Math.floor(this._renderer.gc._frequency/1e3)}set checkCountMax(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead.")}get active(){return this._renderer.gc.enabled}set active(e){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.enabled=e}constructor(e){this._renderer=e,this._checkCount=0}init(e){e.textureGCActive!==I.defaultOptions.textureGCActive&&(this.active=e.textureGCActive),e.textureGCMaxIdle!==I.defaultOptions.textureGCMaxIdle&&(this.maxIdle=e.textureGCMaxIdle),e.textureGCCheckCountMax!==I.defaultOptions.textureGCCheckCountMax&&(this.checkCountMax=e.textureGCCheckCountMax)}run(){f("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};re.extension={type:[d.WebGLSystem,d.WebGPUSystem],name:"textureGC"};re.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let It=re;const We=class Ve extends it{constructor(e={}){super(),this.uid=ot("renderTarget"),this.colorAttachments=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,this._depth=!1,this._stencil=!1,this._colorTextures=null;const t="colorAttachments"in e?e:this._normalizeOptions(e);if(this.isRoot=t.isRoot??!1,this.label=t.label,this.colorAttachments=t.colorAttachments,this.depthStencilAttachment=t.depthStencilAttachment,this.depthStencilAttachment){const r=this.depthStencilAttachment.texture.format;this._depth||(this._depth=r.includes("depth")),this._stencil||(this._stencil=r.includes("stencil"))}if(this.colorAttachments.length===0&&!this.depthStencilAttachment)throw new Error("[RenderTarget] no color textures or depth textures were provided. Provide a depthStencilTexture or set depth/stencil to true when using colorTextures: 0.");if(this.colorAttachments.length>0){const r=this.colorTexture;this.resize(r.width,r.height,r._resolution)}this.sizeSource&&this.sizeSource.on("resize",this.onSourceResize,this)}_normalizeOptions(e){const t={...Ve.defaultOptions,...e},r=[];let s;if(typeof t.colorTextures=="number"){if(t.colorTextures>0){this._managedColorTextures=!0;for(let i=0;i<t.colorTextures;i++)r.push({texture:new w({width:t.width,height:t.height,resolution:t.resolution,antialias:t.antialias}),loadOp:"clear",storeOp:"store"})}}else t.colorTextures.forEach(i=>{r.push({texture:i.source,loadOp:"clear",storeOp:"store"})});const n=t.depthStencilTexture===!0;if(this._depth=!!(t.depth||n),this._stencil=!!(t.stencil||n),t.depthStencilTexture instanceof _||t.depthStencilTexture instanceof w){if(t.isRoot)throw new Error("[RenderTarget] cannot attach a depth-stencil texture to the screen — the canvas owns its own depth/stencil buffers. Render to a texture target instead.");s={texture:t.depthStencilTexture.source}}else(n&&!t.isRoot||(t.stencil||t.depth)&&r.length===0)&&(s=this._createDepthStencilTexture(t.width,t.height,t.resolution));return{colorAttachments:r,depthStencilAttachment:s,isRoot:t.isRoot,label:t.label}}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.sizeSource.width}get height(){return this.sizeSource.height}get pixelWidth(){return this.sizeSource.pixelWidth}get pixelHeight(){return this.sizeSource.pixelHeight}get resolution(){return this.sizeSource._resolution}get colorTextures(){return this._colorTextures||(this._colorTextures=this.colorAttachments.map(e=>e.texture)),this._colorTextures}get depthStencilTexture(){var e;return((e=this.depthStencilAttachment)==null?void 0:e.texture)??null}get depth(){return this._depth}get stencil(){return this._stencil}get colorTexture(){var e;return(e=this.colorAttachments[0])==null?void 0:e.texture}get sizeSource(){var e,t;return((e=this.colorAttachments[0])==null?void 0:e.texture)??((t=this.depthStencilAttachment)==null?void 0:t.texture)}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this._createDepthStencilTexture(this.sizeSource.width,this.sizeSource.height,this.sizeSource._resolution),this._depth=!0,this._stencil=!0}resize(e,t,r=this.resolution,s=!1){if(this.dirtyId++,this.colorAttachments.forEach((n,i)=>{s&&i===0||n.texture.resize(e,t,r)}),this.depthStencilAttachment){if(s&&this.colorAttachments.length===0)return;this.depthStencilAttachment.texture.resize(e,t,r)}}destroy(){!this.colorAttachments&&!this.depthStencilAttachment||(this.emit("destroy",this),this.sizeSource.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorAttachments.forEach(e=>{e.texture.destroy()}),this.depthStencilAttachment&&(this.depthStencilAttachment.texture.destroy(),delete this.depthStencilAttachment),this.colorAttachments=null,this._colorTextures=null,this.removeAllListeners())}_createDepthStencilTexture(e,t,r){return this.depthStencilAttachment??(this.depthStencilAttachment={texture:new w({width:e,height:t,resolution:r,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1})}),this.depthStencilAttachment}};We.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let D=We;const k=new Map;lt.register(k);function Ne(a,e){if(!k.has(a)){const t=new _({source:new V({resource:a,...e})}),r=()=>{k.get(a)===t&&k.delete(a)};t.once("destroy",r),t.source.once("destroy",r),k.set(a,t)}return k.get(a)}const se=class je{get autoDensity(){return this.texture.source.autoDensity}set autoDensity(e){this.texture.source.autoDensity=e}get resolution(){return this.texture.source._resolution}set resolution(e){this.texture.source.resize(this.texture.source.width,this.texture.source.height,e)}constructor(e){this._renderer=e}init(e){e={...je.defaultOptions,...e},e.view&&(f(dt,"ViewSystem.view has been renamed to ViewSystem.canvas"),e.canvas=e.view),this.screen=new P(0,0,e.width,e.height),this.canvas=e.canvas||q.get().createCanvas(),this.antialias=!!e.antialias,this.texture=Ne(this.canvas,e),this.renderTarget=new D({colorTextures:[this.texture],depth:!!e.depth,isRoot:!0}),this.texture.source.transparent=e.backgroundAlpha<1,this.texture.source.on("resize",this._updateScreenSize,this),this.resolution=e.resolution,this._updateScreenSize()}resize(e,t,r){this.texture.source.resize(e,t,r),this.screen.width=this.texture.frame.width,this.screen.height=this.texture.frame.height}destroy(e=!1){(typeof e=="boolean"?e:!!(e!=null&&e.removeView))&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.texture.source.off("resize",this._updateScreenSize,this),v.removeScreen(this._renderer.uid),ce.removeScreen(this._renderer.uid),this.texture.destroy()}_updateScreenSize(){const{pixelWidth:e,pixelHeight:t}=this.texture.source,r=this._renderer.uid;v.setScreenSize(r,e,t),ce.setScreenSize(r,e,t)}};se.extension={type:[d.WebGLSystem,d.WebGPUSystem,d.CanvasSystem],name:"view",priority:0};se.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let Dt=se;const zt=[Ct,Fe,ee,Dt,Ie,Bt,It,Le,St,ct,Ut,ze],Ht=[Ge,Se,Be,Pe,ke,Me,Re,we];function Et(a,e,t,r,s,n){const i=n?1:-1;return a.identity(),a.a=1/r*2,a.d=i*(1/s*2),a.tx=-1-e*a.a,a.ty=-i-t*a.d,a}function Lt(a){if(a.colorAttachments.length===0)return!1;const e=a.colorTexture.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}class Wt{constructor(e){this.rootViewPort=new P,this.viewport=new P,this.onRenderTargetChange=new ht("onRenderTargetChange"),this.projectionMatrix=new x,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._bindState={target:null,frame:void 0,mipLevel:0,layer:0,flipY:!1},this._bindFrame=new P,this._renderer=e,e.gc.addCollection(this,"_gpuRenderTargetHash","hash")}get renderSurface(){return this._bindState.target}get mipLevel(){return this._bindState.mipLevel}get layer(){return this._bindState.layer}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart(e){var t,r;this._renderTargetStack.length=0,this.push(e),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=Lt(this.rootRenderTarget),(r=(t=this.adaptor).prerender)==null||r.call(t,this.rootRenderTarget)}postrender(){var e,t;(t=(e=this.adaptor).postrender)==null||t.call(e,this.rootRenderTarget)}bind(e,t=!0,r,s,n=0,i=0,l){var ae,ie;let o;"target"in e?o=e:(f("8.20.0","RenderTargetSystem.bind: positional arguments are deprecated, please use an options object instead: bind({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),o={target:e,clear:t,clearColor:r,frame:s,mipLevel:n,layer:i,flipY:l});const h=o.target;t=o.clear??!0,r=o.clearColor,n=(o.mipLevel??0)|0,i=(o.layer??0)|0,l=o.flipY,s=o.frame;const c=this.getRenderTarget(h),u=this.renderTarget!==c||!!c.flipY!=!!l;this.renderTarget=c;const g=this.getGpuRenderTarget(c);(c.pixelWidth!==g.width||c.pixelHeight!==g.height)&&(this.adaptor.resizeGpuRenderTarget(c),g.width=c.pixelWidth,g.height=c.pixelHeight);const p=((ae=c.colorAttachments[0])==null?void 0:ae.texture)||((ie=c.depthStencilAttachment)==null?void 0:ie.texture),m=this.viewport,ne=p.arrayLayerCount||1;if(i<0||i>=ne)throw new Error(`[RenderTargetSystem] layer ${i} is out of bounds (arrayLayerCount=${ne}).`);const M=this._bindState;M.target=h,M.frame=s?this._bindFrame.copyFrom(s):void 0,M.mipLevel=n,M.layer=i,M.flipY=l;const F=Math.max(p.pixelWidth>>n,1),z=Math.max(p.pixelHeight>>n,1);if(!s&&h instanceof _&&(s=h.frame),s){const G=p._resolution,A=1<<Math.max(n,0),$e=s.x*G+.5|0,Ye=s.y*G+.5|0,qe=s.width*G+.5|0,Ke=s.height*G+.5|0;let b=Math.floor($e/A),y=Math.floor(Ye/A),C=Math.ceil(qe/A),S=Math.ceil(Ke/A);b<0&&(C+=b,b=0),y<0&&(S+=y,y=0),b=Math.min(b,F-1),y=Math.min(y,z-1),C=Math.min(C,F-b),S=Math.min(S,z-y),C=Math.max(C,1),S=Math.max(S,1),m.x=b,m.y=y,m.width=C,m.height=S}else m.x=0,m.y=0,m.width=F,m.height=z;return c.flipY=l,Et(this.projectionMatrix,0,0,m.width/p.resolution,m.height/p.resolution,!c.isRoot!=!!c.flipY),this.adaptor.startRenderPass(c,t,r,m,n,i),u&&this.onRenderTargetChange.emit(c),c}getBindState(e){if(!this.renderTarget)throw new Error("[RenderTargetSystem] getBindState is only valid while a render surface is bound");const t=this._bindState;return e??(e={}),e.target=t.target,e.clear=U.NONE,e.clearColor=void 0,t.frame?e.frame?e.frame.copyFrom(t.frame):e.frame=t.frame.clone():e.frame=void 0,e.mipLevel=t.mipLevel,e.layer=t.layer,e.flipY=!!t.flipY,e}isFrontFaceInverted(e,t){if(!e){if(e=this.renderTarget,!e)return!1;t=e.flipY}return!!t!=(this._renderer.type===O.WEBGL&&!e.isRoot)}get frontFaceInverted(){return f(ut,"RenderTargetSystem.frontFaceInverted is deprecated, use isFrontFaceInverted() instead"),this.isFrontFaceInverted()}clear(e,t=U.ALL,r,s=this.mipLevel,n=this.layer){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,r,this.viewport,s,n))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=U.ALL,r,s,n=0,i=0,l){let o;"target"in e?o=e:(f("8.20.0","RenderTargetSystem.push: positional arguments are deprecated, please use an options object instead: push({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),o={target:e,clear:t,clearColor:r,frame:s,mipLevel:n,layer:i,flipY:l});const h=this.bind(o);return this._renderTargetStack.push({target:o.target,clear:!1,clearColor:void 0,frame:o.frame?o.frame.clone():void 0,mipLevel:o.mipLevel,layer:o.layer,flipY:o.flipY}),h}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];if(!e)throw new Error("[RenderTargetSystem] pop: no previous binding to restore (unbalanced pop)");return this.bind(e)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,r,s,n){const i=this.getRenderTarget(e);r.x<0&&(s.width+=r.x,n.x-=r.x,r.x=0),r.y<0&&(s.height+=r.y,n.y-=r.y,r.y=0);const{pixelWidth:l,pixelHeight:o}=i;return s.width=Math.min(s.width,l-r.x),s.height=Math.min(s.height,o-r.y),this.adaptor.copyToTexture(i,t,r,s,n)}copyDepthTexture(e,t,r,s,n={x:0,y:0}){const i=this.getRenderTarget(e);if(!i.depthStencilAttachment){R("[RenderTargetSystem] copyDepthTexture: the source render target has no depth attachment to copy from");return}const l=t.source;if(!l.format.includes("depth")&&!l.format.includes("stencil")){R(`[RenderTargetSystem] copyDepthTexture: the destination texture must have a depth/stencil format (got '${l.format}')`);return}let o=r.x,h=r.y,c=n.x,u=n.y,g=s.width,p=s.height;o<0&&(g+=o,c-=o,o=0),h<0&&(p+=h,u-=h,h=0),g=Math.min(g,i.pixelWidth-o),p=Math.min(p,i.pixelHeight-h),g=Math.min(g,l.pixelWidth-c),p=Math.min(p,l.pixelHeight-u),!(g<=0||p<=0)&&this.adaptor.copyDepthTexture(i,t,{x:o,y:h},{width:g,height:p},{x:c,y:u})}ensureDepthStencil(){if(!this.renderTarget.stencil){if(this.renderTarget.depthStencilTexture){R(`[RenderTargetSystem] a stencil mask is being used, but the render target's depthStencilTexture format '${this.renderTarget.depthStencilTexture.format}' has no stencil aspect, so masking cannot work here. Use a 'depth24plus-stencil8' texture instead.`);return}this.renderTarget._depth=!0,this.renderTarget._stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport,0,this.layer)}}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t?this._releaseRenderTarget(t,e):e.off("destroy",this._onRenderTargetDestroy,this)}),this._renderSurfaceToRenderTargetHash.clear();for(const e of Object.values(this._gpuRenderTargetHash))e&&this.adaptor.destroyGpuRenderTarget(e);this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;if(V.test(e)&&(e=Ne(e).source),e instanceof D)t=e,e.once("destroy",this._onRenderTargetDestroy,this);else if(e instanceof w){const r=e.format;t=r.includes("depth")||r.includes("stencil")?new D({colorTextures:0,depthStencilTexture:e}):new D({colorTextures:[e]}),e.source instanceof V&&(t.isRoot=!0),e.once("destroy",this._onRenderSurfaceDestroy,this)}return this._renderSurfaceToRenderTargetHash.set(e,t),t}_onRenderSurfaceDestroy(e){const t=this._renderSurfaceToRenderTargetHash.get(e);t&&this._releaseRenderTarget(e,t)}_onRenderTargetDestroy(e){this._renderSurfaceToRenderTargetHash.delete(e),this._releaseGpuRenderTarget(e)}_releaseRenderTarget(e,t){t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e),e.off("destroy",this._onRenderSurfaceDestroy,this),this._releaseGpuRenderTarget(t)}_releaseGpuRenderTarget(e){const t=this._gpuRenderTargetHash[e.uid];t&&(this._gpuRenderTargetHash[e.uid]=null,this.adaptor.destroyGpuRenderTarget(t))}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this._bindState.target=null}}export{ke as A,Ge as B,we as C,Wt as R,zt as S,Se as a,Be as b,Pe as c,Ht as d};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import{D as g,a as M,l as d,J as O,e as y,w as b,g as Z,b as Ie,S as P,T as R,ao as Ge,V as J,ap as Ue,d as A,ae as C,v as D,Q as T,E as Fe,f as Me,W as L,aq as Oe,x as S,M as Q,ar as ee,as as Pe,at as te,au as Le,av as we,A as He,R as Ve}from"./index-Do5XwO_P.js";import{e as Xe,G as ke,c as We,b as je,U as Ke,B as re,d as N,f as ne,g as Ye}from"./BufferResource-CHYsmqd5.js";import{R as $e,S as ze,d as qe}from"./RenderTargetSystem-CBR4meCp.js";import"./Filter-IrwvDh3w.js";function Ze(){const{userAgent:r}=g.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(r)}class se{constructor(){this._tempState=M.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,n){const s=e.renderer,a=this._didUploadHash[n.uid];s.shader.bind(n,a),a||(this._didUploadHash[n.uid]=!0),s.shader.updateUniformGroup(s.globalUniforms.uniformGroup),s.geometry.bind(t,n.glProgram)}execute(e,t){const n=e.renderer;this._tempState.blendMode=t.blendMode,n.state.set(this._tempState);const s=t.textures.textures;for(let a=0;a<t.textures.count;a++)n.texture.bind(s[a],a);n.geometry.draw(t.topology,t.size,t.start)}}se.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var B=(r=>(r[r.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",r[r.ARRAY_BUFFER=34962]="ARRAY_BUFFER",r[r.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",r))(B||{});class Je{constructor(e,t){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class ae{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:t}=this,n=this.getGlBuffer(e);t.bindBuffer(n.type,n.buffer)}bindBufferBase(e,t){const{_gl:n}=this;this._boundBufferBases[t]!==e&&(this._boundBufferBases[t]=e,e._lastBindBaseLocation=t,n.bindBufferBase(n.UNIFORM_BUFFER,t,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 t=this.getLastBindBaseLocation(e);if(t>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,t;let n=0,s=this._nextBindBaseIndex;for(;n<2;){s>=this._maxBindings&&(s=this._minBaseLocation,n++);const a=this._boundBufferBases[s];if(a&&a._lastBindCallId===this._bindCallId){s++;continue}break}return t=s,this._nextBindBaseIndex=s+1,n>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[t]=null,t)}getLastBindBaseLocation(e){const t=e._lastBindBaseLocation;return this._boundBufferBases[t]===e?t:-1}bindBufferRange(e,t,n,s){const{_gl:a}=this;n||(n=0),t||(t=0),this._boundBufferBases[t]=null,a.bindBufferRange(a.UNIFORM_BUFFER,t||0,e.buffer,n*256,s||256)}updateBuffer(e){const{_gl:t}=this,n=this.getGlBuffer(e);if(e._updateID===n.updateID)return n;n.updateID=e._updateID,t.bindBuffer(n.type,n.buffer);const s=e.data,a=e.descriptor.usage&y.STATIC?t.STATIC_DRAW:t.DYNAMIC_DRAW;return s?n.byteLength>=s.byteLength?t.bufferSubData(n.type,e._updateOffset,s,e._updateOffset/s.BYTES_PER_ELEMENT,(e._updateSize||s.byteLength)/s.BYTES_PER_ELEMENT):(n.byteLength=s.byteLength,t.bufferData(n.type,s,a)):(n.byteLength=e.descriptor.size,t.bufferData(n.type,n.byteLength,a)),n}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,t=!1){const n=e._gpuData[this._renderer.uid];n&&(t||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){const{_gl:t}=this;let n=B.ARRAY_BUFFER;e.descriptor.usage&y.INDEX?n=B.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&y.UNIFORM&&(n=B.UNIFORM_BUFFER);const s=new Je(t.createBuffer(),n);return e._gpuData[this._renderer.uid]=s,this._managedBuffers.add(e),s}resetState(){this._boundBufferBases=Object.create(null)}}ae.extension={type:[d.WebGLSystem],name:"buffer"};const w=class ie{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={...ie.defaultOptions,...e};let t=this.multiView=e.multiView;if(e.context&&t&&(b("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),t=!1),t?this.canvas=g.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,a=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:n,premultipliedAlpha:s,antialias:a,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&b("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:t}=this;(t.width<e.width||t.height<e.height)&&(t.width=Math.max(e.width,e.width),t.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof g.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const t=this._renderer.view.canvas;t.addEventListener("webglcontextlost",this.handleContextLost,!1),t.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,t){let n;const s=this.canvas;if(e===2&&(n=s.getContext("webgl2",t)),!n&&(n=s.getContext("webgl",t),!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,t={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={...t,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={...t,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 t;this.gl.isContextLost()&&((t=this.extensions.loseContext)==null||t.restoreContext())},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){var t;const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),(t=this.extensions.loseContext)==null||t.loseContext()}forceContextLoss(){var e;(e=this.extensions.loseContext)==null||e.loseContext(),this._contextLossForced=!0}validateContext(e){const t=e.getContextAttributes();t&&!t.stencil&&b("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const n=this.supports,s=this.webGLVersion===2,a=this.extensions;n.uint32Indices=s||!!a.uint32ElementIndex,n.uniformBufferObject=s,n.vertexArrayObject=s||!!a.vertexArrayObject,n.srgbTextures=s||!!a.srgb,n.nonPowOf2wrapping=s,n.nonPowOf2mipmaps=s,n.msaa=s,n.uint32Indices||b("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};w.extension={type:[d.WebGLSystem],name:"context"};w.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Qe=w;var U=(r=>(r[r.RGBA=6408]="RGBA",r[r.RGB=6407]="RGB",r[r.RG=33319]="RG",r[r.RED=6403]="RED",r[r.RGBA_INTEGER=36249]="RGBA_INTEGER",r[r.RGB_INTEGER=36248]="RGB_INTEGER",r[r.RG_INTEGER=33320]="RG_INTEGER",r[r.RED_INTEGER=36244]="RED_INTEGER",r[r.ALPHA=6406]="ALPHA",r[r.LUMINANCE=6409]="LUMINANCE",r[r.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",r[r.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",r[r.DEPTH_STENCIL=34041]="DEPTH_STENCIL",r))(U||{}),H=(r=>(r[r.TEXTURE_2D=3553]="TEXTURE_2D",r[r.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",r[r.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",r[r.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",r[r.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",r[r.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",r[r.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",r))(H||{}),f=(r=>(r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",r[r.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",r[r.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",r[r.UNSIGNED_INT=5125]="UNSIGNED_INT",r[r.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",r[r.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",r[r.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",r[r.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",r[r.BYTE=5120]="BYTE",r[r.SHORT=5122]="SHORT",r[r.INT=5124]="INT",r[r.FLOAT=5126]="FLOAT",r[r.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",r[r.HALF_FLOAT=36193]="HALF_FLOAT",r))(f||{});const k={uint8x2:f.UNSIGNED_BYTE,uint8x4:f.UNSIGNED_BYTE,sint8x2:f.BYTE,sint8x4:f.BYTE,unorm8x2:f.UNSIGNED_BYTE,unorm8x4:f.UNSIGNED_BYTE,snorm8x2:f.BYTE,snorm8x4:f.BYTE,uint16x2:f.UNSIGNED_SHORT,uint16x4:f.UNSIGNED_SHORT,sint16x2:f.SHORT,sint16x4:f.SHORT,unorm16x2:f.UNSIGNED_SHORT,unorm16x4:f.UNSIGNED_SHORT,snorm16x2:f.SHORT,snorm16x4:f.SHORT,float16x2:f.HALF_FLOAT,float16x4:f.HALF_FLOAT,float32:f.FLOAT,float32x2:f.FLOAT,float32x3:f.FLOAT,float32x4:f.FLOAT,uint32:f.UNSIGNED_INT,uint32x2:f.UNSIGNED_INT,uint32x3:f.UNSIGNED_INT,uint32x4:f.UNSIGNED_INT,sint32:f.INT,sint32x2:f.INT,sint32x3:f.INT,sint32x4:f.INT};function et(r){return k[r]??k.float32}const tt={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class rt{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class oe{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 t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=s=>t.bindVertexArrayOES(s),e.deleteVertexArray=s=>t.deleteVertexArrayOES(s));const n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(s,a,i,c)=>{n.drawArraysInstancedANGLE(s,a,i,c)},e.drawElementsInstanced=(s,a,i,c,o)=>{n.drawElementsInstancedANGLE(s,a,i,c,o)},e.vertexAttribDivisor=(s,a)=>n.vertexAttribDivisorANGLE(s,a)),this._activeGeometry=null,this._activeVao=null}bind(e,t){const n=this.gl;this._activeGeometry=e;const s=this.getVao(e,t);this._activeVao!==s&&(this._activeVao=s,n.bindVertexArray(s)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,t=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){const s=e.buffers[n];t.updateBuffer(s)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,t){const n=e.attributes,s=t._attributeData;for(const a in s)if(!n[a])throw new Error(`shader and geometry incompatible, geometry missing the "${a}" attribute`)}getSignature(e,t){const n=e.attributes,s=t._attributeData,a=["g",e.uid];for(const i in n)s[i]&&a.push(i,s[i].location);return a.join("-")}getVao(e,t){var n;return((n=e._gpuData[this._renderer.uid])==null?void 0:n.vaoCache[t._key])||this.initGeometryVao(e,t)}initGeometryVao(e,t,n=!0){const s=this._renderer.gl,a=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);const i=this.getSignature(e,t);let c=e._gpuData[this._renderer.uid];c||(c=new rt,e._gpuData[this._renderer.uid]=c,this._managedGeometries.add(e));const o=c.vaoCache;let u=o[i];if(u)return o[t._key]=u,u;Xe(e,t._attributeData);const _=e.buffers;u=s.createVertexArray(),s.bindVertexArray(u);for(let h=0;h<_.length;h++){const l=_[h];a.bind(l)}return this.activateVao(e,t),o[t._key]=u,o[i]=u,s.bindVertexArray(null),u}onGeometryUnload(e,t=!1){const n=e._gpuData[this._renderer.uid];if(!n)return;const s=n.vaoCache;if(!t)for(const a in s)this._activeVao===s[a]&&this.resetState(),this.gl.deleteVertexArray(s[a])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,t){var c;const n=this._renderer.gl,s=this._renderer.buffer,a=e.attributes;e.indexBuffer&&s.bind(e.indexBuffer);let i=null;for(const o in a){const u=a[o],_=u.buffer,h=s.getGlBuffer(_),l=t._attributeData[o];if(l){i!==h&&(s.bind(_),i=h);const m=l.location;n.enableVertexAttribArray(m);const p=Z(u.format),E=et(u.format);if(((c=l.format)==null?void 0:c.substring(1,4))==="int"?n.vertexAttribIPointer(m,p.size,E,u.stride,u.offset):n.vertexAttribPointer(m,p.size,E,p.normalised,u.stride,u.offset),u.instance)if(this.hasInstance){const Ne=u.divisor??1;n.vertexAttribDivisor(m,Ne)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,t,n,s){const{gl:a}=this._renderer,i=this._activeGeometry,c=tt[e||i.topology];if(s??(s=i.instanceCount),i.indexBuffer){const o=i.indexBuffer.data.BYTES_PER_ELEMENT,u=o===2?a.UNSIGNED_SHORT:a.UNSIGNED_INT,_=t||i.indexCount||i.indexBuffer.data.length,h=(n||0)*o;s!==1?a.drawElementsInstanced(c,_,u,h,s):a.drawElements(c,_,u,h)}else s!==1?a.drawArraysInstanced(c,n||0,t||i.vertexCount,s):a.drawArrays(c,n||0,t||i.vertexCount);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}}oe.extension={type:[d.WebGLSystem],name:"geometry"};const nt=new Ge({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),V=class ce{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:t,antialias:n}={...ce.defaultOptions,...e};this.useBackBuffer=t,this._antialias=n,this._renderer.context.supports.msaa||(b("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=M.for2d();const s=new Ie({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:R.WHITE.source}})}renderStart(e){const t=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!t.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({target:this._targetTexture,clear:!1}),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:nt,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new R({source:new J({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)}};V.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};V.defaultOptions={useBackBuffer:!1};let st=V;class ue{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)))}}ue.extension={type:[d.WebGLSystem],name:"colorMask"};class _e{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,t){this._renderer.geometry.bind(e,t.glProgram)}finishRenderPass(){}draw(e){const t=this._renderer,{geometry:n,shader:s,state:a,skipSync:i,topology:c,size:o,start:u,instanceCount:_}=e;t.shader.bind(s,i),t.geometry.bind(n,t.shader._activeProgram),a&&t.state.set(a),t.geometry.draw(c,o,u,_??n.instanceCount)}destroy(){this._renderer=null}}_e.extension={type:[d.WebGLSystem],name:"encoder"};class he{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ue(this.maxTextures,e);const t=this._renderer.context.webGLVersion===2;this.maxUniformBindings=t?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}he.extension={type:[d.WebGLSystem],name:"limits"};class at{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[],this.stencilMode=A.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}class fe{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:A.NONE},this._renderer=e,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._activeGpuRenderTarget=null,this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;const t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=A.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,t){const n=this._activeGpuRenderTarget??(this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget)),s=this._gl,a=ke[e],i=this._stencilCache;if(n.stencilMode=e,n.stencilReference=t,e===A.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!==i.stencilMode||i.stencilReference!==t)&&(i.stencilMode=e,i.stencilReference=t,s.stencilFunc(this._comparisonFuncMapping[a.stencilBack.compare],t,255),s.stencilOp(s.KEEP,s.KEEP,this._stencilOpsMapping[a.stencilBack.passOp]))}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._gl=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}fe.extension={type:[d.WebGLSystem],name:"stencil"};const le={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,u32:4,"vec2<u32>":8,"vec3<u32>":12,"vec4<u32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function it(r){const e=r.map(a=>({data:a,offset:0,size:0})),t=16;let n=0,s=0;for(let a=0;a<e.length;a++){const i=e[a];if(n=le[i.data.type],!n)throw new Error(`Unknown type ${i.data.type}`);i.data.size>1&&(n=Math.max(n,t)*i.data.size);const c=n===12?16:n;i.size=n;const o=s%t;o>0&&t-o<c?s+=(t-o)%16:s+=(n-o%n)%n,i.offset=s,s+=n}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function ot(r,e){const t=Math.max(le[r.data.type]/16,1),n=r.data.value.length/r.data.size,s=(4-n%4)%4,a=r.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
|
|
21
|
+
v = uv.${r.data.name};
|
|
22
|
+
offset += ${e};
|
|
23
|
+
|
|
24
|
+
arrayOffset = offset;
|
|
25
|
+
|
|
26
|
+
t = 0;
|
|
27
|
+
|
|
28
|
+
for(var i=0; i < ${r.data.size*t}; i++)
|
|
29
|
+
{
|
|
30
|
+
for(var j = 0; j < ${n}; j++)
|
|
31
|
+
{
|
|
32
|
+
${a}[arrayOffset++] = v[t++];
|
|
33
|
+
}
|
|
34
|
+
${s!==0?`arrayOffset += ${s};`:""}
|
|
35
|
+
}
|
|
36
|
+
`}function ct(r){return We(r,je,ot)}class de extends Ke{constructor(){super({createUboElements:it,generateUboSync:ct})}}de.extension={type:[d.WebGLSystem],name:"ubo"};class ut{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new C,this._boundFramebuffer=void 0}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new C,this._boundFramebuffer=void 0;const e=this._renderer.gl;this._drawBuffersCache=[];for(let t=1;t<=16;t++)this._drawBuffersCache[t]=Array.from({length:t},(n,s)=>e.COLOR_ATTACHMENT0+s)}copyToTexture(e,t,n,s,a){const i=this._renderTargetSystem,c=this._renderer,o=i.getGpuRenderTarget(e),u=c.gl;return this.finishRenderPass(e),u.bindFramebuffer(u.FRAMEBUFFER,o.resolveTargetFramebuffer),this._boundFramebuffer=o.resolveTargetFramebuffer,c.texture.bind(t,0),u.copyTexSubImage2D(u.TEXTURE_2D,0,a.x,a.y,n.x,n.y,s.width,s.height),t}copyDepthTexture(e,t,n,s,a){const i=this._renderTargetSystem,c=this._renderer.gl;this.finishRenderPass(e);const o=i.getRenderTarget(t),u=i.getGpuRenderTarget(e),_=i.getGpuRenderTarget(o);c.bindFramebuffer(c.READ_FRAMEBUFFER,u.framebuffer),c.bindFramebuffer(c.DRAW_FRAMEBUFFER,_.framebuffer),this._boundFramebuffer=void 0,c.blitFramebuffer(n.x,n.y,n.x+s.width,n.y+s.height,a.x,a.y,a.x+s.width,a.y+s.height,c.DEPTH_BUFFER_BIT,c.NEAREST)}startRenderPass(e,t=!0,n,s,a=0,i=0){const o=this._renderTargetSystem.getGpuRenderTarget(e);if(i!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(a>0){if(o.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.")}e.colorAttachments.forEach(l=>{this._renderer.texture.unbind(l.texture)});const u=this._renderer.gl;this.bindFramebuffer(o.framebuffer),!e.isRoot&&e.colorAttachments.length>0&&(o._attachedMipLevel!==a||o._attachedLayer!==i)&&(e.colorAttachments.forEach((l,m)=>{const p=l.texture,E=this._renderer.texture.getGlSource(p);if(E.target===u.TEXTURE_2D){if(i!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0+m,u.TEXTURE_2D,E.texture,a)}else if(E.target===u.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");u.framebufferTextureLayer(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0+m,E.texture,a,i)}else if(E.target===u.TEXTURE_CUBE_MAP){if(i<0||i>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");u.framebufferTexture2D(u.FRAMEBUFFER,u.COLOR_ATTACHMENT0+m,u.TEXTURE_CUBE_MAP_POSITIVE_X+i,E.texture,a)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),o._attachedMipLevel=a,o._attachedLayer=i),o.framebuffer&&(e.depthStencilAttachment?this._attachDepthStencilTexture(e,a,i):!o.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(o)),e.colorAttachments.length>1&&this._setDrawBuffers(e,u);let _=s.y;e.isRoot&&(_=e.pixelHeight-s.height-s.y);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,u.viewport(s.x,_,s.width,s.height)),this.clear(e,t,n)}finishRenderPass(e){const n=this._renderTargetSystem.getGpuRenderTarget(e);if(!n.msaa||e.colorAttachments.length===0)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),this._boundFramebuffer=n.framebuffer}initGpuRenderTarget(e){const n=this._renderer.gl,s=new at;s._attachedMipLevel=0,s._attachedLayer=0;const a=e.colorTexture;return a instanceof D?(this._renderer.context.ensureCanvasSize(a.resource),s.framebuffer=null,s):(s.width=e.pixelWidth,s.height=e.pixelHeight,e.colorAttachments.length===0?this._initDepth(e,s):this._initColor(e,s),e.depthStencilAttachment&&this._attachDepthStencilTexture(e,0,0),n.bindFramebuffer(n.FRAMEBUFFER,null),this._boundFramebuffer=null,s)}destroyGpuRenderTarget(e){const t=this._renderer.gl;e.framebuffer&&(t.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(t.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(t.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(n=>{t.deleteRenderbuffer(n)}),e.msaaRenderBuffer.length=0}clear(e,t,n,s,a=0,i=0){if(!t)return;if(i!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const c=this._renderTargetSystem;if(typeof t=="boolean"&&(t=t?T.ALL:T.NONE),e.colorAttachments.length===0&&(t&=~T.COLOR,!t))return;const o=this._renderer.gl,u=!!(t&T.DEPTH)&&!this._renderer.state.depthMaskEnabled;if(t&T.COLOR){n??(n=c.defaultClearColor);const _=this._clearColorCache,h=n;(_[0]!==h[0]||_[1]!==h[1]||_[2]!==h[2]||_[3]!==h[3])&&(_[0]=h[0],_[1]=h[1],_[2]=h[2],_[3]=h[3],o.clearColor(h[0],h[1],h[2],h[3]))}u&&o.depthMask(!0),o.clear(t),u&&o.depthMask(!1)}resizeGpuRenderTarget(e){if(e.isRoot)return;const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.pixelWidth,t.height=e.pixelHeight,e.colorAttachments.length>0&&this._resizeColor(e,t),t.depthStencilRenderBuffer&&this._resizeStencil(t),this._boundFramebuffer=void 0}_initColor(e,t){const n=this._renderer,s=n.gl,a=s.createFramebuffer();if(t.resolveTargetFramebuffer=a,s.bindFramebuffer(s.FRAMEBUFFER,a),e.colorAttachments.forEach((c,o)=>{const u=c.texture;u.antialias&&(n.context.supports.msaa?t.msaa=!0:b("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(u,0);const _=n.texture.getGlSource(u),h=_.texture;if(_.target===s.TEXTURE_2D)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+o,s.TEXTURE_2D,h,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+o,h,0,0)}else if(_.target===s.TEXTURE_CUBE_MAP)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+o,s.TEXTURE_CUBE_MAP_POSITIVE_X,h,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),t.msaa){const c=s.createFramebuffer();t.framebuffer=c,s.bindFramebuffer(s.FRAMEBUFFER,c),e.colorAttachments.forEach((o,u)=>{const _=s.createRenderbuffer();t.msaaRenderBuffer[u]=_})}else t.framebuffer=a;this._resizeColor(e,t)}_initDepth(e,t){const n=this._renderer;if(n.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Depth-only render targets require WebGL2.");const s=n.gl,a=s.createFramebuffer();t.resolveTargetFramebuffer=a,t.framebuffer=a,s.bindFramebuffer(s.FRAMEBUFFER,a),s.drawBuffers([s.NONE]),s.readBuffer(s.NONE)}_resizeColor(e,t){const n=e.colorAttachments[0].texture;if(t._attachedMipLevel=0,t._attachedLayer=0,e.colorAttachments.forEach((s,a)=>{a!==0&&s.texture.resize(n.width,n.height,n._resolution)}),t.msaa){const s=this._renderer,a=s.gl,i=t.framebuffer;a.bindFramebuffer(a.FRAMEBUFFER,i),e.colorAttachments.forEach((c,o)=>{const u=c.texture;s.texture.bindSource(u,0);const h=s.texture.getGlSource(u).internalFormat,l=t.msaaRenderBuffer[o];a.bindRenderbuffer(a.RENDERBUFFER,l),a.renderbufferStorageMultisample(a.RENDERBUFFER,4,h,u.pixelWidth,u.pixelHeight),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+o,a.RENDERBUFFER,l)})}}_attachDepthStencilTexture(e,t,n){const s=this._renderer,a=s.gl,i=e.depthStencilAttachment.texture,c=s.texture.getGlSource(i),o=c.texture,u=i.format;let _;u==="depth24plus-stencil8"||u==="depth32float-stencil8"?_=a.DEPTH_STENCIL_ATTACHMENT:u==="stencil8"?_=a.STENCIL_ATTACHMENT:_=a.DEPTH_ATTACHMENT,c.target===a.TEXTURE_2D?a.framebufferTexture2D(a.FRAMEBUFFER,_,a.TEXTURE_2D,o,t):c.target===a.TEXTURE_2D_ARRAY?a.framebufferTextureLayer(a.FRAMEBUFFER,_,o,t,n):c.target===a.TEXTURE_CUBE_MAP&&a.framebufferTexture2D(a.FRAMEBUFFER,_,a.TEXTURE_CUBE_MAP_POSITIVE_X+n,o,t)}_initStencil(e){if(e.framebuffer===null)return;const t=this._renderer.gl,n=t.createRenderbuffer();e.depthStencilRenderBuffer=n,t.bindRenderbuffer(t.RENDERBUFFER,n),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,n),this._resizeStencil(e)}_resizeStencil(e){const t=this._renderer.gl;t.bindRenderbuffer(t.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?t.renderbufferStorageMultisample(t.RENDERBUFFER,4,t.DEPTH24_STENCIL8,e.width,e.height):t.renderbufferStorage(t.RENDERBUFFER,this._renderer.context.webGLVersion===2?t.DEPTH24_STENCIL8:t.DEPTH_STENCIL,e.width,e.height)}prerender(e){if(e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture.resource;this._renderer.context.multiView&&D.test(t)&&this._renderer.context.ensureCanvasSize(t)}postrender(e){if(!this._renderer.context.multiView||e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture;if(D.test(t.resource)){const n=this._renderer.context.canvas,s=t;s.context2D.drawImage(n,0,s.pixelHeight-n.height)}}_setDrawBuffers(e,t){const n=e.colorAttachments.length,s=this._drawBuffersCache[n];if(this._renderer.context.webGLVersion===1){const a=this._renderer.context.extensions.drawBuffers;a?a.drawBuffersWEBGL(s):b("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else t.drawBuffers(s)}resetState(){this._boundFramebuffer=void 0,this._viewPortCache=new C,this._clearColorCache=[0,0,0,0]}bindFramebuffer(e){this._boundFramebuffer!==e&&(this._boundFramebuffer=e,this._renderer.gl.bindFramebuffer(this._renderer.gl.FRAMEBUFFER,e))}}class me extends $e{constructor(e){super(e),this.adaptor=new ut,this.adaptor.init(e,this)}resetState(){this.adaptor.resetState()}}me.extension={type:[d.WebGLSystem],name:"renderTarget"};class _t extends Fe{constructor(e,t){super(),this._resourceType="textureView",this._resourceId=Me("resource"),this.source=e,this.viewDescriptor=t,this._onChange=this._onChange.bind(this),this._onDestroy=this._onDestroy.bind(this),this.source.on("change",this._onChange),this.source.on("destroy",this._onDestroy)}_onChange(){this.emit("change",this)}_onDestroy(){this.destroy()}get destroyed(){return this.source.destroyed}destroy(){this.source&&(this.source.off("change",this._onChange),this.source.off("destroy",this._onDestroy)),this.emit("destroy",this),this.removeAllListeners()}}function ht(r,e){const t=[],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,a=0;const i=e._getProgramData(r.glProgram);for(const o in r.groups){const u=r.groups[o];t.push(`
|
|
43
|
+
resources = g[${o}].resources;
|
|
44
|
+
`);for(const _ in u.resources){const h=u.resources[_];if(h instanceof L)if(h.ubo){const l=r._uniformBindMap[o][Number(_)];t.push(`
|
|
45
|
+
sS.bindUniformBlock(
|
|
46
|
+
resources[${_}],
|
|
47
|
+
'${l}',
|
|
48
|
+
${r.glProgram._uniformBlockData[l].index}
|
|
49
|
+
);
|
|
50
|
+
`)}else t.push(`
|
|
51
|
+
ugS.updateUniformGroup(resources[${_}], p, sD);
|
|
52
|
+
`);else if(h instanceof re){const l=r._uniformBindMap[o][Number(_)];t.push(`
|
|
53
|
+
sS.bindUniformBlock(
|
|
54
|
+
resources[${_}],
|
|
55
|
+
'${l}',
|
|
56
|
+
${r.glProgram._uniformBlockData[l].index}
|
|
57
|
+
);
|
|
58
|
+
`)}else if(h instanceof J||h instanceof _t){const l=r._uniformBindMap[o][_],m=i.uniformData[l];m&&(s||(s=!0,n.push(`
|
|
59
|
+
var tS = r.texture;
|
|
60
|
+
`)),e._gl.uniform1i(m.location,a),t.push(`
|
|
61
|
+
tS.bind(resources[${_}], ${a});
|
|
62
|
+
`),a++)}}}const c=[...n,...t].join(`
|
|
63
|
+
`);return new Function("r","s","sD",c)}class ft{constructor(e,t){this.program=e,this.uniformData=t,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function W(r,e,t){const n=r.createShader(e);return r.shaderSource(n,t),r.compileShader(n),n}function I(r){const e=new Array(r);for(let t=0;t<e.length;t++)e[t]=!1;return e}function Ee(r,e){switch(r){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 I(2*e);case"bvec3":return I(3*e);case"bvec4":return I(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 x=null;const j={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_2D_SHADOW:"sampler2DShadow",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_CUBE_SHADOW:"samplerCubeShadow",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray",SAMPLER_2D_ARRAY_SHADOW:"sampler2DArrayShadow"},lt={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 be(r,e){if(!x){const t=Object.keys(j);x={};for(let n=0;n<t.length;++n){const s=t[n];x[r[s]]=j[s]}}return x[e]}function dt(r,e){const t=be(r,e);return lt[t]||"float32"}function mt(r,e,t=!1){const n={},s=e.getProgramParameter(r,e.ACTIVE_ATTRIBUTES);for(let i=0;i<s;i++){const c=e.getActiveAttrib(r,i);if(c.name.startsWith("gl_"))continue;const o=dt(e,c.type);n[c.name]={location:0,format:o,stride:Z(o).stride,offset:0,instance:!1,start:0}}const a=Object.keys(n);if(t){a.sort((i,c)=>i>c?1:-1);for(let i=0;i<a.length;i++)n[a[i]].location=i,e.bindAttribLocation(r,i,a[i]);e.linkProgram(r)}else for(let i=0;i<a.length;i++)n[a[i]].location=e.getAttribLocation(r,a[i]);return n}function Et(r,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const t={},n=e.getProgramParameter(r,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<n;s++){const a=e.getActiveUniformBlockName(r,s),i=e.getUniformBlockIndex(r,a),c=e.getActiveUniformBlockParameter(r,s,e.UNIFORM_BLOCK_DATA_SIZE);t[a]={name:a,index:i,size:c}}return t}function bt(r,e){const t={},n=e.getProgramParameter(r,e.ACTIVE_UNIFORMS);for(let s=0;s<n;s++){const a=e.getActiveUniform(r,s),i=a.name.replace(/\[.*?\]$/,""),c=!!a.name.match(/\[.*?\]$/),o=be(e,a.type);t[i]={name:i,index:s,type:o,size:a.size,isArray:c,value:Ee(o,a.size)}}return t}function K(r,e){const t=r.getShaderSource(e);if(t===null){console.error("PixiJS Error: Could not retrieve shader source (WebGL context may be lost).");return}const n=t.split(`
|
|
64
|
+
`).map((_,h)=>`${h}: ${_}`),s=r.getShaderInfoLog(e)??"",a=s.split(`
|
|
65
|
+
`),i={},c=a.map(_=>parseFloat(_.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(_=>_&&!i[_]?(i[_]=!0,!0):!1),o=[""];c.forEach(_=>{n[_-1]=`%c${n[_-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=n.join(`
|
|
66
|
+
`);o[0]=u,console.error(s),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function pt(r,e,t,n){r.getProgramParameter(e,r.LINK_STATUS)||(r.getShaderParameter(t,r.COMPILE_STATUS)||K(r,t),r.getShaderParameter(n,r.COMPILE_STATUS)||K(r,n),console.error("PixiJS Error: Could not initialize shader."),r.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",r.getProgramInfoLog(e)))}function Rt(r,e){const t=W(r,r.VERTEX_SHADER,e.vertex),n=W(r,r.FRAGMENT_SHADER,e.fragment),s=r.createProgram();r.attachShader(s,t),r.attachShader(s,n);const a=e.transformFeedbackVaryings;a&&(typeof r.transformFeedbackVaryings!="function"?b("TransformFeedback is not supported but TransformFeedbackVaryings are given."):r.transformFeedbackVaryings(s,a.names,a.bufferMode==="separate"?r.SEPARATE_ATTRIBS:r.INTERLEAVED_ATTRIBS)),r.linkProgram(s),r.getProgramParameter(s,r.LINK_STATUS)||pt(r,s,t,n),e._attributeData=mt(s,r,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=bt(s,r),e._uniformBlockData=Et(s,r),r.deleteShader(t),r.deleteShader(n);const i={};for(const o in e._uniformData){const u=e._uniformData[o];i[o]={location:r.getUniformLocation(s,o),value:Ee(u.type,u.size)}}return new ft(s,i)}const v={textureCount:0,blockIndex:0};class pe{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,t){if(this._setProgram(e.glProgram),t)return;v.textureCount=0,v.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,v)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,v)}bindUniformBlock(e,t,n=0){const s=this._renderer.buffer,a=this._getProgramData(this._activeProgram),i=e._bufferResource;i||this._renderer.ubo.updateUniformGroup(e);const c=e.buffer,o=s.updateBuffer(c),u=s.freeLocationForBufferBase(o);if(i){const{offset:h,size:l}=e;h===0&&l===c.data.byteLength?s.bindBufferBase(o,u):s.bindBufferRange(o,u,h)}else s.getLastBindBaseLocation(o)!==u&&s.bindBufferBase(o,u);const _=this._activeProgram._uniformBlockData[t].index;a.uniformBlockBindings[n]!==u&&(a.uniformBlockBindings[n]=u,this._renderer.gl.uniformBlockBinding(a.program,_,u))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const t=this._getProgramData(e);this._gl.useProgram(t.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const t=e._key;return this._programDataHash[t]=Rt(this._gl,e),this._programDataHash[t]}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,t){return ht(e,t)}resetState(){this._activeProgram=null}}pe.extension={type:[d.WebGLSystem],name:"shader"};const gt={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);"},St={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 Tt(r,e){const t=[`
|
|
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 r.uniforms){if(!e[n]){r.uniforms[n]instanceof L?r.uniforms[n].ubo?t.push(`
|
|
146
|
+
renderer.shader.bindUniformBlock(uv.${n}, "${n}");
|
|
147
|
+
`):t.push(`
|
|
148
|
+
renderer.shader.updateUniformGroup(uv.${n});
|
|
149
|
+
`):r.uniforms[n]instanceof re&&t.push(`
|
|
150
|
+
renderer.shader.bindBufferResource(uv.${n}, "${n}");
|
|
151
|
+
`);continue}const s=r.uniformStructures[n];let a=!1;for(let i=0;i<N.length;i++){const c=N[i];if(s.type===c.type&&c.test(s)){t.push(`name = "${n}";`,N[i].uniform),a=!0;break}}if(!a){const c=(s.size===1?gt:St)[s.type].replace("location",`ud["${n}"].location`);t.push(`
|
|
152
|
+
cu = ud["${n}"];
|
|
153
|
+
cv = cu.value;
|
|
154
|
+
v = uv["${n}"];
|
|
155
|
+
${c};`)}}return new Function("ud","uv","renderer","syncData",t.join(`
|
|
156
|
+
`))}class Re{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,t,n){const s=this._renderer.shader._getProgramData(t);(!e.isStatic||e._dirtyId!==s.uniformDirtyGroups[e.uid])&&(s.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,t)(s.uniformData,e.uniforms,this._renderer,n))}_getUniformSyncFunction(e,t){var n;return((n=this._uniformGroupSyncHash[e._signature])==null?void 0:n[t._key])||this._createUniformSyncFunction(e,t)}_createUniformSyncFunction(e,t){const n=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),s=this._getSignature(e,t._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(e,t._uniformData)),n[t._key]=this._cache[s],n[t._key]}_generateUniformsSync(e,t){return Tt(e,t)}_getSignature(e,t,n){const s=e.uniforms,a=[`${n}-`];for(const i in s)a.push(i),t[i]&&a.push(t[i].type);return a.join("-")}destroy(){this._renderer=null,this._cache=null}}Re.extension={type:[d.WebGLSystem],name:"uniformGroup"};function xt(r){const e={};if(e.normal=[r.ONE,r.ONE_MINUS_SRC_ALPHA],e.add=[r.ONE,r.ONE],e.multiply=[r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],e.screen=[r.ONE,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[r.SRC_ALPHA,r.ONE,r.ONE,r.ONE],e["screen-npm"]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],e.erase=[r.ZERO,r.ONE_MINUS_SRC_ALPHA],!(r instanceof g.get().getWebGLRenderingContext()))e.min=[r.ONE,r.ONE,r.ONE,r.ONE,r.MIN,r.MIN],e.max=[r.ONE,r.ONE,r.ONE,r.ONE,r.MAX,r.MAX];else{const n=r.getExtension("EXT_blend_minmax");n&&(e.min=[r.ONE,r.ONE,r.ONE,r.ONE,n.MIN_EXT,n.MIN_EXT],e.max=[r.ONE,r.ONE,r.ONE,r.ONE,n.MAX_EXT,n.MAX_EXT])}return e}const{BLEND:vt,OFFSET:At,CULLING:Bt,DEPTH_TEST:yt,WINDING:Ct,DEPTH_MASK:Y}=Oe,ge=class F{constructor(e){this._invertFrontFace=!1,this._renderer=e,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[vt]=this.setBlend,this.map[At]=this.setOffset,this.map[Bt]=this.setCullFace,this.map[yt]=this.setDepthTest,this.map[Ct]=this.setFrontFace,this.map[Y]=this.setDepthMask,this.checks=[],this.defaultState=M.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(e,e.flipY),this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=xt(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let t=this.stateId^e.data,n=0;for(;t;)t&1&&this.map[n].call(this,!!(e.data&1<<n)),t>>=1,n++;this.stateId=e.data}for(let t=0;t<this.checks.length;t++)this.checks[t](this,e)}forceState(e){e||(e=this.defaultState);for(let t=0;t<this.map.length;t++)this.map[t].call(this,!!(e.data&1<<t));for(let t=0;t<this.checks.length;t++)this.checks[t](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(F._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(F._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)}get depthMaskEnabled(){return!!(this.stateId&1<<Y)}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 t=this._invertFrontFace?!e:e;this._glFrontFace!==t&&(this._glFrontFace=t,this.gl.frontFace(this.gl[t?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const t=this.blendModesMap[e],n=this.gl;t.length===2?n.blendFunc(t[0],t[1]):n.blendFuncSeparate(t[0],t[1],t[2],t[3]),t.length===6?(this._blendEq=!0,n.blendEquationSeparate(t[4],t[5])):this._blendEq&&(this._blendEq=!1,n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD))}setPolygonOffset(e,t){this.gl.polygonOffset(e,t)}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,t){const n=this.checks.indexOf(e);t&&n===-1?this.checks.push(e):!t&&n!==-1&&this.checks.splice(n,1)}static _checkBlendMode(e,t){e.setBlendMode(t.blendMode)}static _checkPolygonOffset(e,t){e.setPolygonOffset(1,t.polygonOffset)}destroy(){this.gl=null,this.checks.length=0,this._renderer=null}};ge.extension={type:[d.WebGLSystem],name:"state"};let Dt=ge;class Nt{constructor(e){this.target=H.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=f.UNSIGNED_BYTE,this.internalFormat=U.RGBA,this.format=U.RGBA,this.samplerType=0}destroy(){}}const It={id:"buffer",upload(r,e,t,n,s,a=!1){const i=s||e.target;!a&&e.width===r.width&&e.height===r.height?t.texSubImage2D(i,0,0,0,r.width,r.height,e.format,e.type,r.resource):t.texImage2D(i,0,e.internalFormat,r.width,r.height,0,e.format,e.type,r.resource),e.width=r.width,e.height=r.height}},Gt={"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},Ut={id:"compressed",upload(r,e,t,n,s,a){const i=s??e.target;t.pixelStorei(t.UNPACK_ALIGNMENT,4);let c=r.pixelWidth,o=r.pixelHeight;const u=!!Gt[r.format];for(let _=0;_<r.resource.length;_++){const h=r.resource[_];u?t.compressedTexImage2D(i,_,e.internalFormat,c,o,0,h):t.texImage2D(i,_,e.internalFormat,c,o,0,e.format,e.type,h),c=Math.max(c>>1,1),o=Math.max(o>>1,1)}}},$=["right","left","top","bottom","front","back"];function Ft(r){return{id:"cube",upload(e,t,n,s){const a=e.faces;for(let i=0;i<$.length;i++){const c=$[i],o=a[c];if(!o.resource)continue;(r[o.uploadMethodId]||r.image).upload(o,t,n,s,H.TEXTURE_CUBE_MAP_POSITIVE_X+i,(t._layerInitMask&1<<i)===0),t._layerInitMask|=1<<i}t.width=e.pixelWidth,t.height=e.pixelHeight}}}const Se={id:"image",upload(r,e,t,n,s,a=!1){const i=s||e.target,c=r.pixelWidth,o=r.pixelHeight,u=r.resourceWidth,_=r.resourceHeight,h=n===2,l=a||e.width!==c||e.height!==o,m=u>=c&&_>=o,p=r.resource;(h?Mt:Ot)(t,i,e,c,o,u,_,p,l,m),e.width=c,e.height=o}};function Mt(r,e,t,n,s,a,i,c,o,u){if(!u){o&&r.texImage2D(e,0,t.internalFormat,n,s,0,t.format,t.type,null),r.texSubImage2D(e,0,0,0,a,i,t.format,t.type,c);return}if(!o){r.texSubImage2D(e,0,0,0,t.format,t.type,c);return}r.texImage2D(e,0,t.internalFormat,n,s,0,t.format,t.type,c)}function Ot(r,e,t,n,s,a,i,c,o,u){if(!u){o&&r.texImage2D(e,0,t.internalFormat,n,s,0,t.format,t.type,null),r.texSubImage2D(e,0,0,0,t.format,t.type,c);return}if(!o){r.texSubImage2D(e,0,0,0,t.format,t.type,c);return}r.texImage2D(e,0,t.internalFormat,t.format,t.type,c)}const Pt=Ze(),Lt={id:"video",upload(r,e,t,n,s,a=Pt){if(!r.isValid){const i=s??e.target;t.texImage2D(i,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Se.upload(r,e,t,n,s,a)}},z={linear:9729,nearest:9728},wt={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},G={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Ht={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function q(r,e,t,n,s,a,i,c){const o=a;if(!c||r.addressModeU!=="repeat"||r.addressModeV!=="repeat"||r.addressModeW!=="repeat"){const u=G[i?"clamp-to-edge":r.addressModeU],_=G[i?"clamp-to-edge":r.addressModeV],h=G[i?"clamp-to-edge":r.addressModeW];e[s](o,e.TEXTURE_WRAP_S,u),e[s](o,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[s](o,e.TEXTURE_WRAP_R,h)}if((!c||r.magFilter!=="linear")&&e[s](o,e.TEXTURE_MAG_FILTER,z[r.magFilter]),t){if(!c||r.mipmapFilter!=="linear"){const u=wt[r.minFilter][r.mipmapFilter];e[s](o,e.TEXTURE_MIN_FILTER,u)}}else e[s](o,e.TEXTURE_MIN_FILTER,z[r.minFilter]);if(n&&r.maxAnisotropy>1){const u=Math.min(r.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](o,n.TEXTURE_MAX_ANISOTROPY_EXT,u)}r.compare?(e[s](o,e.TEXTURE_COMPARE_FUNC,Ht[r.compare]),e[s](o,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE)):c||e[s](o,e.TEXTURE_COMPARE_MODE,e.NONE)}function Vt(r){return{r8unorm:r.RED,r8snorm:r.RED,r8uint:r.RED,r8sint:r.RED,r16uint:r.RED,r16sint:r.RED,r16float:r.RED,rg8unorm:r.RG,rg8snorm:r.RG,rg8uint:r.RG,rg8sint:r.RG,r32uint:r.RED,r32sint:r.RED,r32float:r.RED,rg16uint:r.RG,rg16sint:r.RG,rg16float:r.RG,rgba8unorm:r.RGBA,"rgba8unorm-srgb":r.RGBA,rgba8snorm:r.RGBA,rgba8uint:r.RGBA,rgba8sint:r.RGBA,bgra8unorm:r.RGBA,"bgra8unorm-srgb":r.RGBA,rgb9e5ufloat:r.RGB,rgb10a2unorm:r.RGBA,rg11b10ufloat:r.RGB,rg32uint:r.RG,rg32sint:r.RG,rg32float:r.RG,rgba16uint:r.RGBA,rgba16sint:r.RGBA,rgba16float:r.RGBA,rgba32uint:r.RGBA,rgba32sint:r.RGBA,rgba32float:r.RGBA,stencil8:r.STENCIL_INDEX8,depth16unorm:r.DEPTH_COMPONENT,depth24plus:r.DEPTH_COMPONENT,"depth24plus-stencil8":r.DEPTH_STENCIL,depth32float:r.DEPTH_COMPONENT,"depth32float-stencil8":r.DEPTH_STENCIL}}function Xt(r,e){let t={},n=r.RGBA;return r instanceof g.get().getWebGLRenderingContext()?e.srgb&&(t={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(t={"rgba8unorm-srgb":r.SRGB8_ALPHA8,"bgra8unorm-srgb":r.SRGB8_ALPHA8},n=r.RGBA8),{r8unorm:r.R8,r8snorm:r.R8_SNORM,r8uint:r.R8UI,r8sint:r.R8I,r16uint:r.R16UI,r16sint:r.R16I,r16float:r.R16F,rg8unorm:r.RG8,rg8snorm:r.RG8_SNORM,rg8uint:r.RG8UI,rg8sint:r.RG8I,r32uint:r.R32UI,r32sint:r.R32I,r32float:r.R32F,rg16uint:r.RG16UI,rg16sint:r.RG16I,rg16float:r.RG16F,rgba8unorm:r.RGBA,...t,rgba8snorm:r.RGBA8_SNORM,rgba8uint:r.RGBA8UI,rgba8sint:r.RGBA8I,bgra8unorm:n,rgb9e5ufloat:r.RGB9_E5,rgb10a2unorm:r.RGB10_A2,rg11b10ufloat:r.R11F_G11F_B10F,rg32uint:r.RG32UI,rg32sint:r.RG32I,rg32float:r.RG32F,rgba16uint:r.RGBA16UI,rgba16sint:r.RGBA16I,rgba16float:r.RGBA16F,rgba32uint:r.RGBA32UI,rgba32sint:r.RGBA32I,rgba32float:r.RGBA32F,stencil8:r.STENCIL_INDEX8,depth16unorm:r.DEPTH_COMPONENT16,depth24plus:r.DEPTH_COMPONENT24,"depth24plus-stencil8":r.DEPTH24_STENCIL8,depth32float:r.DEPTH_COMPONENT32F,"depth32float-stencil8":r.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 kt(r){return{r8unorm:r.UNSIGNED_BYTE,r8snorm:r.BYTE,r8uint:r.UNSIGNED_BYTE,r8sint:r.BYTE,r16uint:r.UNSIGNED_SHORT,r16sint:r.SHORT,r16float:r.HALF_FLOAT,rg8unorm:r.UNSIGNED_BYTE,rg8snorm:r.BYTE,rg8uint:r.UNSIGNED_BYTE,rg8sint:r.BYTE,r32uint:r.UNSIGNED_INT,r32sint:r.INT,r32float:r.FLOAT,rg16uint:r.UNSIGNED_SHORT,rg16sint:r.SHORT,rg16float:r.HALF_FLOAT,rgba8unorm:r.UNSIGNED_BYTE,"rgba8unorm-srgb":r.UNSIGNED_BYTE,rgba8snorm:r.BYTE,rgba8uint:r.UNSIGNED_BYTE,rgba8sint:r.BYTE,bgra8unorm:r.UNSIGNED_BYTE,"bgra8unorm-srgb":r.UNSIGNED_BYTE,rgb9e5ufloat:r.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:r.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:r.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:r.UNSIGNED_INT,rg32sint:r.INT,rg32float:r.FLOAT,rgba16uint:r.UNSIGNED_SHORT,rgba16sint:r.SHORT,rgba16float:r.HALF_FLOAT,rgba32uint:r.UNSIGNED_INT,rgba32sint:r.INT,rgba32float:r.FLOAT,stencil8:r.UNSIGNED_BYTE,depth16unorm:r.UNSIGNED_SHORT,depth24plus:r.UNSIGNED_INT,"depth24plus-stencil8":r.UNSIGNED_INT_24_8,depth32float:r.FLOAT,"depth32float-stencil8":r.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Wt(r){return{"2d":r.TEXTURE_2D,cube:r.TEXTURE_CUBE_MAP,"1d":null,"3d":(r==null?void 0:r.TEXTURE_3D)||null,"2d-array":(r==null?void 0:r.TEXTURE_2D_ARRAY)||null,"cube-array":(r==null?void 0:r.TEXTURE_CUBE_MAP_ARRAY)||null}}const jt=4,X=class Te{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 t={image:Se,buffer:It,video:Lt,compressed:Ut,...Te.uploadExtensions};this._uploads={...t,cube:Ft(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Xt(e,this._renderer.context.extensions),this._mapFormatToType=kt(e),this._mapFormatToFormat=Vt(e),this._mapViewDimensionToGlTarget=Wt(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let t=0;t<16;t++)this.bind(R.EMPTY,t)}initSource(e){this.bind(e)}bind(e,t=0){const n=e.source;e?(this.bindSource(n,t),this._useSeparateSamplers&&this._bindSampler(n.style,t)):(this.bindSource(null,t),this._useSeparateSamplers&&this._bindSampler(null,t))}bindSource(e,t=0){const n=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[t]!==e){this._boundTextures[t]=e,this._activateLocation(t),e||(e=R.EMPTY.source);const s=this.getGlSource(e);n.bindTexture(s.target,s.texture)}}_bindSampler(e,t=0){const n=this._gl;if(!e){this._boundSamplers[t]=null,n.bindSampler(t,null);return}const s=this._getGlSampler(e);this._boundSamplers[t]!==s&&(this._boundSamplers[t]=s,n.bindSampler(t,s))}unbind(e){const t=e.source,n=this._boundTextures,s=this._gl;for(let a=0;a<n.length;a++)if(n[a]===t){this._activateLocation(a);const i=this.getGlSource(t);s.bindTexture(i.target,null),n[a]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const t=this._gl,n=new Nt(t.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.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const a=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(a))+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,t){const n=this._gl,s=this.getGlSource(e);n.bindTexture(s.target,s.texture),this._boundTextures[this._activeTextureLocation]=e,q(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,t)}onSourceUnload(e,t=!1){const n=e._gpuData[this._renderer.uid];n&&(t||(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 t=this._gl,n=this.getGlSource(e);t.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,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,n,t,this._renderer.context.webGLVersion);else if(n.target===t.TEXTURE_2D)this._initEmptyTexture2D(n,e);else if(n.target===t.TEXTURE_2D_ARRAY)this._initEmptyTexture2DArray(n,e);else if(n.target===t.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,t=!0){t&&this.bindSource(e,0);const n=this.getGlSource(e);this._gl.generateMipmap(n.target)}_initEmptyTexture2D(e,t){const n=this._gl;n.texImage2D(n.TEXTURE_2D,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let s=Math.max(t.pixelWidth>>1,1),a=Math.max(t.pixelHeight>>1,1);for(let i=1;i<t.mipLevelCount;i++)n.texImage2D(n.TEXTURE_2D,i,e.internalFormat,s,a,0,e.format,e.type,null),s=Math.max(s>>1,1),a=Math.max(a>>1,1)}_initEmptyTexture2DArray(e,t){if(this._renderer.context.webGLVersion!==2)throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");const n=this._gl,s=Math.max(t.arrayLayerCount|0,1);n.texImage3D(n.TEXTURE_2D_ARRAY,0,e.internalFormat,t.pixelWidth,t.pixelHeight,s,0,e.format,e.type,null);let a=Math.max(t.pixelWidth>>1,1),i=Math.max(t.pixelHeight>>1,1);for(let c=1;c<t.mipLevelCount;c++)n.texImage3D(n.TEXTURE_2D_ARRAY,c,e.internalFormat,a,i,s,0,e.format,e.type,null),a=Math.max(a>>1,1),i=Math.max(i>>1,1)}_initEmptyTextureCube(e,t){const n=this._gl,s=6;for(let c=0;c<s;c++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let a=Math.max(t.pixelWidth>>1,1),i=Math.max(t.pixelHeight>>1,1);for(let c=1;c<t.mipLevelCount;c++){for(let o=0;o<s;o++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+o,c,e.internalFormat,a,i,0,e.format,e.type,null);a=Math.max(a>>1,1),i=Math.max(i>>1,1)}}_applyMipRange(e,t){if(this._renderer.context.webGLVersion!==2||t.mipLevelCount<=1)return;const n=this._gl,s=Math.max((t.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 t=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,q(e,t,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:t,width:n,height:s}=this.getPixels(e),a=g.get().createCanvas();a.width=n,a.height=s;const i=a.getContext("2d");if(i){const c=i.createImageData(n,s);c.data.set(t),i.putImageData(c,0,0)}return a}getPixels(e){const t=e.source.resolution,n=e.frame,s=Math.max(Math.round(n.width*t),1),a=Math.max(Math.round(n.height*t),1),i=new Uint8Array(jt*s*a),c=this._renderer,o=c.renderTarget.getRenderTarget(e),u=c.renderTarget.getGpuRenderTarget(o),_=c.gl;return c.renderTarget.adaptor.bindFramebuffer(u.resolveTargetFramebuffer),_.readPixels(Math.round(n.x*t),Math.round(n.y*t),s,a,_.RGBA,_.UNSIGNED_BYTE,i),{pixels:new Uint8ClampedArray(i.buffer),width:s,height:a}}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(R.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}};X.extension={type:[d.WebGLSystem],name:"texture"};X.uploadExtensions=Object.create(null);let xe=X;S.handleByMap(d.TextureUploaderWebGL,xe.uploadExtensions);class ve{contextChange(e){const t=new L({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new Q,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),n=e.limits.maxBatchableTextures,s=ee({name:"graphics",bits:[Pe,Le(n),ne,te]});this.shader=new P({glProgram:s,resources:{localUniforms:t,batchSamplers:we(n)}})}execute(e,t){const n=t.context,s=n.customShader||this.shader,a=e.renderer,i=a.graphicsContext,{batcher:c,instructions:o}=i.getContextRenderData(n);s.groups[0]=a.globalUniforms.bindGroup,a.state.set(e.state),a.shader.bind(s),a.geometry.bind(c.geometry,s.glProgram);const u=o.instructions;for(let _=0;_<o.instructionSize;_++){const h=u[_];if(h.size){for(let l=0;l<h.textures.count;l++)a.texture.bind(h.textures.textures[l],l);a.geometry.draw(h.topology,h.size,h.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}ve.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class Ae{init(){const e=ee({name:"mesh",bits:[ne,Ye,te]});this._shader=new P({glProgram:e,resources:{uTexture:R.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new Q}}}})}execute(e,t){const n=e.renderer;let s=t._shader;if(s){if(!s.glProgram){b("Mesh shader has no glProgram",t.shader);return}}else{s=this._shader;const a=t.texture,i=a.source;s.resources.uTexture=i,s.resources.uSampler=i.style,s.resources.textureUniforms.uniforms.uTextureMatrix=a.textureMatrix.mapCoord}s.groups[100]=n.globalUniforms.bindGroup,s.groups[101]=e.localUniformsBindGroup,n.encoder.draw({geometry:t._geometry,shader:s,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Ae.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const Kt=[...ze,de,st,Qe,he,ae,xe,me,oe,Re,pe,_e,Dt,fe,ue],Yt=[...qe],$t=[se,Ae,ve],Be=[],ye=[],Ce=[],De=[];S.handleByNamedList(d.WebGLSystem,Be);S.handleByNamedList(d.WebGLPipes,ye);S.handleByNamedList(d.WebGLPipesAdaptor,Ce);S.handleByNamedList(d.WebGLLoader,De);S.add(...Kt,...Yt,...$t);class Qt extends He{constructor(){const e={name:"webgl",type:Ve.WEBGL,systems:Be,renderPipes:ye,renderPipeAdaptors:Ce,loaders:De};super(e)}}export{Qt as WebGLRenderer};
|