@openspecui/web 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/{dist-ssg/client/assets/BufferResource-DdnZHNU-.js → dist/assets/BufferResource-Bn1UWy0D.js} +1 -1
- package/{dist-ssg/client/assets/CanvasRenderer-W0-8maEY.js → dist/assets/CanvasRenderer-D8NiU8la.js} +1 -1
- package/dist/assets/{Filter-BCHzFO9X.js → Filter-CRwq487x.js} +1 -1
- package/dist/assets/{RenderTargetSystem-QYja7U1C.js → RenderTargetSystem-CtoB_qTm.js} +1 -1
- package/{dist-ssg/client/assets/WebGLRenderer-CN6ngwpu.js → dist/assets/WebGLRenderer-BgKO8R0a.js} +1 -1
- package/dist/assets/{WebGPURenderer-CSfhxPBR.js → WebGPURenderer-CQeL2efC.js} +1 -1
- package/dist/assets/{browserAll-CChvoSPa.js → browserAll-DP6sOYev.js} +1 -1
- package/dist/assets/ghostty-web-evxujSxm.js +13 -0
- package/dist/assets/{index-DSkiV8t7.js → index-4MAU81Qk.js} +1 -1
- package/{dist-ssg/client/assets/index-D2pLblyv.js → dist/assets/index-B0IbsqHi.js} +1 -1
- package/{dist-ssg/client/assets/index-fWg8Cn9O.js → dist/assets/index-B147AOgf.js} +1 -1
- package/{dist-ssg/client/assets/index-Do3bWt1y.js → dist/assets/index-BMashGQn.js} +1 -1
- package/{dist-ssg/client/assets/index-Ca41ecb5.js → dist/assets/index-BPZ3nG0r.js} +1 -1
- package/dist/assets/{index-DS0kz2NM.js → index-BejnsZfY.js} +1 -1
- package/dist/assets/{index-a4zt_8am.js → index-BnT52DZ8.js} +1 -1
- package/{dist-ssg/client/assets/index-DXb6uuwe.js → dist/assets/index-CBCPR3Qb.js} +1 -1
- package/dist/assets/{index-BPuO-i8p.js → index-D2Tp4F9B.js} +1 -1
- package/dist/assets/{index-hysFimNk.js → index-D6ardy54.js} +1 -1
- package/dist/assets/{index-8kjDfgtP.js → index-DJqmTRAR.js} +1 -1
- package/{dist-ssg/client/assets/index-DWh8uDpX.js → dist/assets/index-DTeOcXKn.js} +1 -1
- package/{dist-ssg/client/assets/index-CWB6CIXv.js → dist/assets/index-DcXyAs0z.js} +1 -1
- package/{dist-ssg/client/assets/index-BcA9ozYL.js → dist/assets/index-T8xoxmUb.js} +227 -220
- package/dist/assets/index-Ys2MTD3W.css +1 -0
- package/dist/assets/{index-CoF0ewHZ.js → index-dSf1u0YV.js} +1 -1
- package/{dist-ssg/client/assets/index-BTVg5Nau.js → dist/assets/index-f0QdJSzm.js} +1 -1
- package/{dist-ssg/client/assets/webworkerAll-T10QBdIL.js → dist/assets/webworkerAll-DA2HufNb.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-ssg/client/.vite/ssr-manifest.json +599 -3107
- package/dist-ssg/client/assets/index-42NXIrUL.css +1 -0
- package/dist-ssg/client/assets/index-BKuRbAoU.js +3 -0
- package/dist-ssg/client/assets/index-BNvK4AuA.js +1 -0
- package/dist-ssg/client/assets/index-BPqe-tty.js +1 -0
- package/dist-ssg/client/assets/index-Bts5PKwE.js +1 -0
- package/{dist/assets/index-CWB6CIXv.js → dist-ssg/client/assets/index-C1d9Zuhl.js} +1 -1
- package/dist-ssg/client/assets/index-CfKJRsCY.js +7 -0
- package/dist-ssg/client/assets/index-CkIJT9VM.js +1 -0
- package/dist-ssg/client/assets/index-CsRZVfC5.js +1 -0
- package/dist-ssg/client/assets/index-DaAYjM02.js +1 -0
- package/dist-ssg/client/assets/index-DoT0nwXT.js +1 -0
- package/dist-ssg/client/assets/index-DuI28swy.js +1 -0
- package/dist-ssg/client/assets/index-Qc9PpyXL.js +1 -0
- package/dist-ssg/client/assets/index-lmUf9UYl.js +1 -0
- package/dist-ssg/client/assets/index-nXK46PJX.js +1 -0
- package/dist-ssg/client/assets/index-neDlRvdc.js +1 -0
- package/dist-ssg/client/assets/index.ssg-B7Yw_6vy.js +600 -0
- package/dist-ssg/client/{index.html → index.ssg.html} +2 -4
- package/dist-ssg/server/assets/{index-C3RtR5EA.js → index-85lrvP9c.js} +1 -1
- package/dist-ssg/server/assets/{index-BvURgefh.js → index-8B1WJzeR.js} +1 -1
- package/dist-ssg/server/assets/{index-BvGNqnLD.js → index-B4YlAmAc.js} +1 -1
- package/dist-ssg/server/assets/{index-DBYODvy4.js → index-BGh-0lci.js} +1 -1
- package/dist-ssg/server/assets/{index-8uE7RyRi.js → index-CmaTLdHp.js} +1 -1
- package/dist-ssg/server/assets/{index-DL23PkQi.js → index-Cv9QdO7F.js} +1 -1
- package/dist-ssg/server/assets/{index-C2CuXbSQ.js → index-DEVS1pbk.js} +1 -1
- package/dist-ssg/server/assets/{index-CZtnphnE.js → index-Dr8hGWNq.js} +1 -1
- package/dist-ssg/server/assets/{index-DfcLdBOi.js → index-MmnHcNid.js} +1 -1
- package/dist-ssg/server/assets/{index-BkJYfA64.js → index-Uo0092kH.js} +1 -1
- package/dist-ssg/server/assets/{index-D0DRToHj.js → index-cD9YNBBl.js} +1 -1
- package/dist-ssg/server/assets/{index-O2XMojWG.js → index-gsGirPQZ.js} +1 -1
- package/dist-ssg/server/assets/{index-3uSTc-o9.js → index-nz5WUxV1.js} +1 -1
- package/dist-ssg/server/assets/{index-D5MdLWau.js → index-p0cUlQgG.js} +1 -1
- package/dist-ssg/server/entry-server.js +104995 -144562
- package/package.json +12 -11
- package/dist/assets/BufferResource-DdnZHNU-.js +0 -185
- package/dist/assets/CanvasRenderer-W0-8maEY.js +0 -1
- package/dist/assets/WebGLRenderer-CN6ngwpu.js +0 -156
- package/dist/assets/index-BBa-UOW9.css +0 -1
- package/dist/assets/index-BTVg5Nau.js +0 -1
- package/dist/assets/index-BcA9ozYL.js +0 -1509
- package/dist/assets/index-Ca41ecb5.js +0 -1
- package/dist/assets/index-D2pLblyv.js +0 -1
- package/dist/assets/index-DWh8uDpX.js +0 -1
- package/dist/assets/index-DXb6uuwe.js +0 -1
- package/dist/assets/index-Do3bWt1y.js +0 -1
- package/dist/assets/index-fWg8Cn9O.js +0 -1
- package/dist/assets/webworkerAll-T10QBdIL.js +0 -83
- package/dist-ssg/client/assets/Filter-BCHzFO9X.js +0 -1
- package/dist-ssg/client/assets/RenderTargetSystem-QYja7U1C.js +0 -172
- package/dist-ssg/client/assets/WebGPURenderer-CSfhxPBR.js +0 -41
- package/dist-ssg/client/assets/browserAll-CChvoSPa.js +0 -14
- package/dist-ssg/client/assets/gemini-Bk-V9kKu.png +0 -0
- package/dist-ssg/client/assets/index-8kjDfgtP.js +0 -1
- package/dist-ssg/client/assets/index-BBa-UOW9.css +0 -1
- package/dist-ssg/client/assets/index-BPuO-i8p.js +0 -1
- package/dist-ssg/client/assets/index-CoF0ewHZ.js +0 -1
- package/dist-ssg/client/assets/index-DS0kz2NM.js +0 -1
- package/dist-ssg/client/assets/index-DSkiV8t7.js +0 -7
- package/dist-ssg/client/assets/index-a4zt_8am.js +0 -3
- package/dist-ssg/client/assets/index-hysFimNk.js +0 -1
- package/dist-ssg/server/assets/BufferResource-BXrsGVSz.js +0 -592
- package/dist-ssg/server/assets/CanvasRenderer-D9aMd7WV.js +0 -1530
- package/dist-ssg/server/assets/Filter-ClU0-pLL.js +0 -80
- package/dist-ssg/server/assets/RenderTargetSystem-CVz6i60H.js +0 -3037
- package/dist-ssg/server/assets/WebGLRenderer-B0I5TP5d.js +0 -3887
- package/dist-ssg/server/assets/WebGPURenderer-DCgUFny7.js +0 -2146
- package/dist-ssg/server/assets/browserAll-BixK1BYs.js +0 -2691
- package/dist-ssg/server/assets/init-CnkBvt-J.js +0 -666
- package/dist-ssg/server/assets/webworkerAll-DNiMFaVV.js +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openspecui/web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"openspecui-ssg": "./dist-ssg/ssg-cli.mjs"
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"@vitejs/plugin-react": "^5.1.3",
|
|
40
40
|
"@vitest/browser": "^4.0.18",
|
|
41
41
|
"@vitest/browser-playwright": "^4.0.18",
|
|
42
|
-
"@xterm/addon-fit": "0.12.0-beta.
|
|
43
|
-
"@xterm/addon-web-links": "0.13.0-beta.
|
|
44
|
-
"@xterm/xterm": "6.1.0-beta.
|
|
42
|
+
"@xterm/addon-fit": "0.12.0-beta.167",
|
|
43
|
+
"@xterm/addon-web-links": "0.13.0-beta.167",
|
|
44
|
+
"@xterm/xterm": "6.1.0-beta.167",
|
|
45
45
|
"baseline-browser-mapping": "^2.9.19",
|
|
46
46
|
"clsx": "^2.1.1",
|
|
47
|
+
"ghostty-web": "^0.4.0",
|
|
47
48
|
"jsdom": "^25.0.1",
|
|
48
49
|
"lucide-react": "^0.472.0",
|
|
49
50
|
"playwright": "^1.58.2",
|
|
@@ -61,22 +62,22 @@
|
|
|
61
62
|
"vitest": "^4.0.18",
|
|
62
63
|
"yaml": "^2.8.0",
|
|
63
64
|
"yargs": "^18.0.0",
|
|
64
|
-
"@openspecui/
|
|
65
|
-
"
|
|
66
|
-
"
|
|
65
|
+
"@openspecui/search": "1.1.0",
|
|
66
|
+
"@openspecui/server": "1.5.0",
|
|
67
|
+
"xterm-input-panel": "1.2.0"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
69
70
|
"dev": "vite --host=0.0.0.0",
|
|
70
71
|
"build": "tsc && vite build && pnpm run build:ssg && pnpm run build:ssg-cli",
|
|
71
72
|
"build:ssg": "pnpm build:ssg-client && pnpm build:ssg-server",
|
|
72
|
-
"build:ssg-client": "vite build --ssrManifest .vite/ssr-manifest.json --outDir dist-ssg/client",
|
|
73
|
+
"build:ssg-client": "vite build --config vite.ssg-client.config.ts --ssrManifest .vite/ssr-manifest.json --outDir dist-ssg/client",
|
|
73
74
|
"build:ssg-server": "vite build --ssr src/ssg/entry-server.tsx --outDir dist-ssg/server",
|
|
74
75
|
"build:ssg-cli": "vite build --config vite.ssg-cli.config.ts --outDir dist-ssg",
|
|
75
76
|
"typecheck": "tsc --noEmit",
|
|
76
77
|
"preview": "vite preview",
|
|
77
|
-
"test": "vitest run",
|
|
78
|
-
"test:watch": "vitest",
|
|
79
|
-
"test:browser": "vitest --project storybook",
|
|
78
|
+
"test": "vitest run --project unit",
|
|
79
|
+
"test:watch": "vitest --project unit",
|
|
80
|
+
"test:browser": "vitest --retry 2 --project storybook",
|
|
80
81
|
"storybook": "storybook dev -p 6006",
|
|
81
82
|
"build-storybook": "storybook build"
|
|
82
83
|
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import{y as U,z as g,A as c,B as S,D as _,F as m,H as I,J as p}from"./index-BcA9ozYL.js";const x={name:"local-uniform-bit",vertex:{header:`
|
|
2
|
-
|
|
3
|
-
struct LocalUniforms {
|
|
4
|
-
uTransformMatrix:mat3x3<f32>,
|
|
5
|
-
uColor:vec4<f32>,
|
|
6
|
-
uRound:f32,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
10
|
-
`,main:`
|
|
11
|
-
vColor *= localUniforms.uColor;
|
|
12
|
-
modelMatrix *= localUniforms.uTransformMatrix;
|
|
13
|
-
`,end:`
|
|
14
|
-
if(localUniforms.uRound == 1)
|
|
15
|
-
{
|
|
16
|
-
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
17
|
-
}
|
|
18
|
-
`}},D={...x,vertex:{...x.vertex,header:x.vertex.header.replace("group(1)","group(2)")}},A={name:"local-uniform-bit",vertex:{header:`
|
|
19
|
-
|
|
20
|
-
uniform mat3 uTransformMatrix;
|
|
21
|
-
uniform vec4 uColor;
|
|
22
|
-
uniform float uRound;
|
|
23
|
-
`,main:`
|
|
24
|
-
vColor *= uColor;
|
|
25
|
-
modelMatrix = uTransformMatrix;
|
|
26
|
-
`,end:`
|
|
27
|
-
if(uRound == 1.)
|
|
28
|
-
{
|
|
29
|
-
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
30
|
-
}
|
|
31
|
-
`}},C={name:"texture-bit",vertex:{header:`
|
|
32
|
-
|
|
33
|
-
struct TextureUniforms {
|
|
34
|
-
uTextureMatrix:mat3x3<f32>,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
|
|
38
|
-
`,main:`
|
|
39
|
-
uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
40
|
-
`},fragment:{header:`
|
|
41
|
-
@group(2) @binding(0) var uTexture: texture_2d<f32>;
|
|
42
|
-
@group(2) @binding(1) var uSampler: sampler;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`,main:`
|
|
46
|
-
outColor = textureSample(uTexture, uSampler, vUV);
|
|
47
|
-
`}},O={name:"texture-bit",vertex:{header:`
|
|
48
|
-
uniform mat3 uTextureMatrix;
|
|
49
|
-
`,main:`
|
|
50
|
-
uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
51
|
-
`},fragment:{header:`
|
|
52
|
-
uniform sampler2D uTexture;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
`,main:`
|
|
56
|
-
outColor = texture(uTexture, vUV);
|
|
57
|
-
`}};function R(e,t){for(const a in e.attributes){const s=e.attributes[a],r=t[a];r?(s.format??(s.format=r.format),s.offset??(s.offset=r.offset),s.instance??(s.instance=r.instance)):U(`Attribute ${a} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}M(e)}function M(e){const{buffers:t,attributes:a}=e,s={},r={};for(const n in t){const o=t[n];s[o.uid]=0,r[o.uid]=0}for(const n in a){const o=a[n];s[o.buffer.uid]+=g(o.format).stride}for(const n in a){const o=a[n];o.stride??(o.stride=s[o.buffer.uid]),o.start??(o.start=r[o.buffer.uid]),r[o.buffer.uid]+=g(o.format).stride}}const l=[];l[c.NONE]=void 0;l[c.DISABLED]={stencilWriteMask:0,stencilReadMask:0};l[c.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}};l[c.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}};l[c.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};l[c.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class B{constructor(t){this._syncFunctionHash=Object.create(null),this._adaptor=t,this._systemCheck()}_systemCheck(){if(!S())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}ensureUniformGroup(t){const a=this.getUniformGroupData(t);t.buffer||(t.buffer=new _({data:new Float32Array(a.layout.size/4),usage:m.UNIFORM|m.COPY_DST}))}getUniformGroupData(t){return this._syncFunctionHash[t._signature]||this._initUniformGroup(t)}_initUniformGroup(t){const a=t._signature;let s=this._syncFunctionHash[a];if(!s){const r=Object.keys(t.uniformStructures).map(d=>t.uniformStructures[d]),n=this._adaptor.createUboElements(r),o=this._generateUboSync(n.uboElements);s=this._syncFunctionHash[a]={layout:n,syncFunction:o}}return this._syncFunctionHash[a]}_generateUboSync(t){return this._adaptor.generateUboSync(t)}syncUniformGroup(t,a,s){const r=this.getUniformGroupData(t);t.buffer||(t.buffer=new _({data:new Float32Array(r.layout.size/4),usage:m.UNIFORM|m.COPY_DST}));let n=null;return a||(a=t.buffer.data,n=t.buffer.dataInt32),s||(s=0),r.syncFunction(t.uniforms,a,n,s),!0}updateUniformGroup(t){if(t.isStatic&&!t._dirtyId)return!1;t._dirtyId=0;const a=this.syncUniformGroup(t);return t.buffer.update(),a}destroy(){this._syncFunctionHash=null}}const h=[{type:"mat3x3<f32>",test:e=>e.value.a!==void 0,ubo:`
|
|
58
|
-
var matrix = uv[name].toArray(true);
|
|
59
|
-
data[offset] = matrix[0];
|
|
60
|
-
data[offset + 1] = matrix[1];
|
|
61
|
-
data[offset + 2] = matrix[2];
|
|
62
|
-
data[offset + 4] = matrix[3];
|
|
63
|
-
data[offset + 5] = matrix[4];
|
|
64
|
-
data[offset + 6] = matrix[5];
|
|
65
|
-
data[offset + 8] = matrix[6];
|
|
66
|
-
data[offset + 9] = matrix[7];
|
|
67
|
-
data[offset + 10] = matrix[8];
|
|
68
|
-
`,uniform:`
|
|
69
|
-
gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
|
|
70
|
-
`},{type:"vec4<f32>",test:e=>e.type==="vec4<f32>"&&e.size===1&&e.value.width!==void 0,ubo:`
|
|
71
|
-
v = uv[name];
|
|
72
|
-
data[offset] = v.x;
|
|
73
|
-
data[offset + 1] = v.y;
|
|
74
|
-
data[offset + 2] = v.width;
|
|
75
|
-
data[offset + 3] = v.height;
|
|
76
|
-
`,uniform:`
|
|
77
|
-
cv = ud[name].value;
|
|
78
|
-
v = uv[name];
|
|
79
|
-
if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
|
|
80
|
-
cv[0] = v.x;
|
|
81
|
-
cv[1] = v.y;
|
|
82
|
-
cv[2] = v.width;
|
|
83
|
-
cv[3] = v.height;
|
|
84
|
-
gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
|
|
85
|
-
}
|
|
86
|
-
`},{type:"vec2<f32>",test:e=>e.type==="vec2<f32>"&&e.size===1&&e.value.x!==void 0,ubo:`
|
|
87
|
-
v = uv[name];
|
|
88
|
-
data[offset] = v.x;
|
|
89
|
-
data[offset + 1] = v.y;
|
|
90
|
-
`,uniform:`
|
|
91
|
-
cv = ud[name].value;
|
|
92
|
-
v = uv[name];
|
|
93
|
-
if (cv[0] !== v.x || cv[1] !== v.y) {
|
|
94
|
-
cv[0] = v.x;
|
|
95
|
-
cv[1] = v.y;
|
|
96
|
-
gl.uniform2f(ud[name].location, v.x, v.y);
|
|
97
|
-
}
|
|
98
|
-
`},{type:"vec4<f32>",test:e=>e.type==="vec4<f32>"&&e.size===1&&e.value.red!==void 0,ubo:`
|
|
99
|
-
v = uv[name];
|
|
100
|
-
data[offset] = v.red;
|
|
101
|
-
data[offset + 1] = v.green;
|
|
102
|
-
data[offset + 2] = v.blue;
|
|
103
|
-
data[offset + 3] = v.alpha;
|
|
104
|
-
`,uniform:`
|
|
105
|
-
cv = ud[name].value;
|
|
106
|
-
v = uv[name];
|
|
107
|
-
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
|
|
108
|
-
cv[0] = v.red;
|
|
109
|
-
cv[1] = v.green;
|
|
110
|
-
cv[2] = v.blue;
|
|
111
|
-
cv[3] = v.alpha;
|
|
112
|
-
gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
|
|
113
|
-
}
|
|
114
|
-
`},{type:"vec3<f32>",test:e=>e.type==="vec3<f32>"&&e.size===1&&e.value.red!==void 0,ubo:`
|
|
115
|
-
v = uv[name];
|
|
116
|
-
data[offset] = v.red;
|
|
117
|
-
data[offset + 1] = v.green;
|
|
118
|
-
data[offset + 2] = v.blue;
|
|
119
|
-
`,uniform:`
|
|
120
|
-
cv = ud[name].value;
|
|
121
|
-
v = uv[name];
|
|
122
|
-
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
|
|
123
|
-
cv[0] = v.red;
|
|
124
|
-
cv[1] = v.green;
|
|
125
|
-
cv[2] = v.blue;
|
|
126
|
-
gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
|
|
127
|
-
}
|
|
128
|
-
`}];function k(e,t,a,s){const r=[`
|
|
129
|
-
var v = null;
|
|
130
|
-
var v2 = null;
|
|
131
|
-
var t = 0;
|
|
132
|
-
var index = 0;
|
|
133
|
-
var name = null;
|
|
134
|
-
var arrayOffset = null;
|
|
135
|
-
`];let n=0;for(let d=0;d<e.length;d++){const f=e[d],b=f.data.name;let y=!1,i=0;for(let u=0;u<h.length;u++)if(h[u].test(f.data)){i=f.offset/4,r.push(`name = "${b}";`,`offset += ${i-n};`,h[u][t]||h[u].ubo),y=!0;break}if(!y)if(f.data.size>1)i=f.offset/4,r.push(a(f,i-n));else{const u=s[f.data.type];i=f.offset/4,r.push(`
|
|
136
|
-
v = uv.${b};
|
|
137
|
-
offset += ${i-n};
|
|
138
|
-
${u};
|
|
139
|
-
`)}n=i}const o=r.join(`
|
|
140
|
-
`);return new Function("uv","data","dataInt32","offset",o)}function v(e,t){return`
|
|
141
|
-
for (let i = 0; i < ${e*t}; i++) {
|
|
142
|
-
data[offset + (((i / ${e})|0) * 4) + (i % ${e})] = v[i];
|
|
143
|
-
}
|
|
144
|
-
`}const F={f32:`
|
|
145
|
-
data[offset] = v;`,i32:`
|
|
146
|
-
dataInt32[offset] = v;`,"vec2<f32>":`
|
|
147
|
-
data[offset] = v[0];
|
|
148
|
-
data[offset + 1] = v[1];`,"vec3<f32>":`
|
|
149
|
-
data[offset] = v[0];
|
|
150
|
-
data[offset + 1] = v[1];
|
|
151
|
-
data[offset + 2] = v[2];`,"vec4<f32>":`
|
|
152
|
-
data[offset] = v[0];
|
|
153
|
-
data[offset + 1] = v[1];
|
|
154
|
-
data[offset + 2] = v[2];
|
|
155
|
-
data[offset + 3] = v[3];`,"vec2<i32>":`
|
|
156
|
-
dataInt32[offset] = v[0];
|
|
157
|
-
dataInt32[offset + 1] = v[1];`,"vec3<i32>":`
|
|
158
|
-
dataInt32[offset] = v[0];
|
|
159
|
-
dataInt32[offset + 1] = v[1];
|
|
160
|
-
dataInt32[offset + 2] = v[2];`,"vec4<i32>":`
|
|
161
|
-
dataInt32[offset] = v[0];
|
|
162
|
-
dataInt32[offset + 1] = v[1];
|
|
163
|
-
dataInt32[offset + 2] = v[2];
|
|
164
|
-
dataInt32[offset + 3] = v[3];`,"mat2x2<f32>":`
|
|
165
|
-
data[offset] = v[0];
|
|
166
|
-
data[offset + 1] = v[1];
|
|
167
|
-
data[offset + 4] = v[2];
|
|
168
|
-
data[offset + 5] = v[3];`,"mat3x3<f32>":`
|
|
169
|
-
data[offset] = v[0];
|
|
170
|
-
data[offset + 1] = v[1];
|
|
171
|
-
data[offset + 2] = v[2];
|
|
172
|
-
data[offset + 4] = v[3];
|
|
173
|
-
data[offset + 5] = v[4];
|
|
174
|
-
data[offset + 6] = v[5];
|
|
175
|
-
data[offset + 8] = v[6];
|
|
176
|
-
data[offset + 9] = v[7];
|
|
177
|
-
data[offset + 10] = v[8];`,"mat4x4<f32>":`
|
|
178
|
-
for (let i = 0; i < 16; i++) {
|
|
179
|
-
data[offset + i] = v[i];
|
|
180
|
-
}`,"mat3x2<f32>":v(3,2),"mat4x2<f32>":v(4,2),"mat2x3<f32>":v(2,3),"mat4x3<f32>":v(4,3),"mat2x4<f32>":v(2,4),"mat3x4<f32>":v(3,4)},w={...F,"mat2x2<f32>":`
|
|
181
|
-
data[offset] = v[0];
|
|
182
|
-
data[offset + 1] = v[1];
|
|
183
|
-
data[offset + 2] = v[2];
|
|
184
|
-
data[offset + 3] = v[3];
|
|
185
|
-
`};class P extends I{constructor({buffer:t,offset:a,size:s}){super(),this.uid=p("buffer"),this._resourceType="bufferResource",this._touched=0,this._resourceId=p("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=t,this.offset=a|0,this.size=s,this.buffer.on("change",this.onBufferChange,this)}onBufferChange(){this._resourceId=p("resource"),this.emit("change",this)}destroy(t=!1){this.destroyed=!0,t&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}export{P as B,l as G,B as U,x as a,F as b,k as c,h as d,R as e,A as f,O as g,D as l,C as t,w as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{K as U,M as A,O as K,P as be,Q as ne,R as O,T as S,U as qe,y as Le,V as we,W as Ye,X as Ne,Y as Xe,Z as je,_ as $e,$ as Ke,a0 as Qe,a1 as ze,a2 as se}from"./index-BcA9ozYL.js";import{R as Je,S as Ze,B as et,a as tt,b as nt,c as at,A as st,C as ot}from"./RenderTargetSystem-QYja7U1C.js";import"./Filter-BCHzFO9X.js";let $;function Me(s){const e=U.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=s,t.fillRect(0,0,6,1),e}function Se(){if($!==void 0)return $;try{const s=Me("#ff00ff"),e=Me("#ffff00"),a=U.get().createCanvas(6,1).getContext("2d");a.globalCompositeOperation="multiply",a.drawImage(s,0,0),a.drawImage(e,2,0);const n=a.getImageData(2,0,1,1);if(!n)$=!1;else{const o=n.data;$=o[0]===255&&o[1]===0&&o[2]===0}}catch{$=!1}return $}const d={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,canUseMultiply:Se(),tintMethod:null,_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:s=>{const e=s.source,t=e?.resource;if(!t)return null;const a=e.alphaMode==="premultiplied-alpha",n=e.resourceWidth??e.pixelWidth,o=e.resourceHeight??e.pixelHeight,r=n!==e.pixelWidth||o!==e.pixelHeight;if(a){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!r)return t;const i=d._unpremultipliedCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d"),l=h.createImageData(e.pixelWidth,e.pixelHeight),u=l.data,m=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let v=0;v<u.length&&v+3<m.length;v+=4)u[v]=m[v+2],u[v+1]=m[v+1],u[v+2]=m[v],u[v+3]=m[v+3];else u.set(m.subarray(0,u.length));return h.putImageData(l,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}if(a){const i=U.get().createCanvas(e.pixelWidth,e.pixelHeight),c=i.getContext("2d",{willReadFrequently:!0});i.width=e.pixelWidth,i.height=e.pixelHeight,c.drawImage(t,0,0);const h=c.getImageData(0,0,i.width,i.height),l=h.data;for(let u=0;u<l.length;u+=4){const m=l[u+3];if(m>0){const v=255/m;l[u]=Math.min(255,l[u]*v+.5),l[u+1]=Math.min(255,l[u+1]*v+.5),l[u+2]=Math.min(255,l[u+2]*v+.5)}}return c.putImageData(h,0,0),d._unpremultipliedCache.set(e,{canvas:i,resourceId:e._resourceId}),i}if(r){const i=d._canvasSourceCache.get(e);if(i?.resourceId===e._resourceId)return i.canvas;const c=U.get().createCanvas(e.pixelWidth,e.pixelHeight),h=c.getContext("2d");return c.width=e.pixelWidth,c.height=e.pixelHeight,h.drawImage(t,0,0),d._canvasSourceCache.set(e,{canvas:c,resourceId:e._resourceId}),c}return t},getTintedCanvas:(s,e)=>{const t=s.texture,a=K.shared.setValue(e).toHex(),n=t.tintCache||(t.tintCache={}),o=n[a],r=t.source._resourceId;if(o?.tintId===r)return o;const i=o&&"getContext"in o?o:U.get().createCanvas();return d.tintMethod(t,e,i),i.tintId=r,n[a]=i,n[a]},getTintedPattern:(s,e)=>{const t=K.shared.setValue(e).toHex(),a=s.patternCache||(s.patternCache={}),n=s.source._resourceId;let o=a[t];return o?.tintId===n||(d.canvas||(d.canvas=U.get().createCanvas()),d.tintMethod(s,e,d.canvas),o=d.canvas.getContext("2d").createPattern(d.canvas,"repeat"),o.tintId=n,a[t]=o),o},applyPatternTransform:(s,e,t=!0)=>{if(!e)return;const a=s;if(!a.setTransform)return;const n=globalThis.DOMMatrix;if(!n)return;const o=new n([e.a,e.b,e.c,e.d,e.tx,e.ty]);a.setTransform(t?o.inverse():o)},tintWithMultiply:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="multiply";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.globalCompositeOperation="destination-atop",a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithOverlay:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy",a.fillStyle=K.shared.setValue(e).toHex(),a.fillRect(0,0,c,h),a.globalCompositeOperation="destination-atop";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore()},tintWithPerPixel:(s,e,t)=>{const a=t.getContext("2d"),n=s.frame.clone(),o=s.source._resolution??s.source.resolution??1,r=s.rotate;n.x*=o,n.y*=o,n.width*=o,n.height*=o;const i=A.isVertical(r),c=i?n.height:n.width,h=i?n.width:n.height;t.width=Math.ceil(c),t.height=Math.ceil(h),a.save(),a.globalCompositeOperation="copy";const l=d.getCanvasSource(s);if(!l){a.restore();return}r&&d._applyInverseRotation(a,r,n.width,n.height),a.drawImage(l,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a.restore();const u=e>>16&255,m=e>>8&255,v=e&255,k=a.getImageData(0,0,c,h),T=k.data;for(let C=0;C<T.length;C+=4)T[C]=T[C]*u/255,T[C+1]=T[C+1]*m/255,T[C+2]=T[C+2]*v/255;a.putImageData(k,0,0)},_applyInverseRotation:(s,e,t,a)=>{const n=A.inv(e),o=A.uX(n),r=A.uY(n),i=A.vX(n),c=A.vY(n),h=-Math.min(0,o*t,i*a,o*t+i*a),l=-Math.min(0,r*t,c*a,r*t+c*a);s.transform(o,r,i,c,h,l)}};d.tintMethod=d.canUseMultiply?d.tintWithMultiply:d.tintWithPerPixel;const fe=class L{static _getPatternRepeat(e,t){const a=e&&e!=="clamp-to-edge",n=t&&t!=="clamp-to-edge";return a&&n?"repeat":a?"repeat-x":n?"repeat-y":"no-repeat"}start(e,t,a){}execute(e,t){const a=t.elements;if(!a||!a.length)return;const n=e.renderer,o=n.canvasContext,r=o.activeContext;for(let i=0;i<a.length;i++){const c=a[i];if(!c.packAsQuad)continue;const h=c,l=h.texture,u=l?d.getCanvasSource(l):null;if(!u)continue;const m=l.source.style,v=o.smoothProperty,k=m.scaleMode!=="nearest";r[v]!==k&&(r[v]=k),o.setBlendMode(t.blendMode);const T=n.globalUniforms.globalUniformData?.worldColor??4294967295,C=h.color,B=(T>>>24&255)/255,P=(C>>>24&255)/255,H=n.filter?.alphaMultiplier??1,V=B*P*H;if(V<=0)continue;r.globalAlpha=V;const J=T&16777215,b=C&16777215,F=be(ne(b,J)),W=l.frame,Q=m.addressModeU??m.addressMode,Y=m.addressModeV??m.addressMode,g=L._getPatternRepeat(Q,Y),y=l.source._resolution??l.source.resolution??1,x=h.renderable?.renderGroup?.isCachedAsTexture,G=W.x*y,N=W.y*y,w=W.width*y,E=W.height*y,_=h.bounds,I=n.renderTarget.renderTarget.isRoot,R=_.minX,z=_.minY,q=_.maxX-_.minX,D=_.maxY-_.minY,M=l.rotate,p=l.uvs,oe=Math.min(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),Ee=Math.max(p.x0,p.x1,p.x2,p.x3,p.y0,p.y1,p.y2,p.y3),ge=g!=="no-repeat"&&(oe<0||Ee>1),re=M&&!(!ge&&(F!==16777215||M));re?(L._tempPatternMatrix.copyFrom(h.transform),A.matrixAppendRotationInv(L._tempPatternMatrix,M,R,z,q,D),o.setContextTransform(L._tempPatternMatrix,h.roundPixels===1,void 0,x&&I)):o.setContextTransform(h.transform,h.roundPixels===1,void 0,x&&I);const Z=re?0:R,ee=re?0:z,ie=q,ce=D;if(ge){let le=u;const X=F!==16777215&&!M,j=W.width<=l.source.width&&W.height<=l.source.height;X&&j&&(le=d.getTintedCanvas({texture:l},F));const he=r.createPattern(le,g);if(!he)continue;const me=ie,ve=ce;if(me===0||ve===0)continue;const ye=1/me,Ce=1/ve,xe=(p.x1-p.x0)*ye,Te=(p.y1-p.y0)*ye,Pe=(p.x3-p.x0)*Ce,_e=(p.y3-p.y0)*Ce,Ve=p.x0-xe*Z-Pe*ee,Fe=p.y0-Te*Z-_e*ee,de=l.source.pixelWidth,pe=l.source.pixelHeight;L._tempPatternMatrix.set(xe*de,Te*pe,Pe*de,_e*pe,Ve*de,Fe*pe),d.applyPatternTransform(he,L._tempPatternMatrix),r.fillStyle=he,r.fillRect(Z,ee,ie,ce)}else{const X=F!==16777215||M?d.getTintedCanvas({texture:l},F):u,j=X!==u;r.drawImage(X,j?0:G,j?0:N,j?X.width:w,j?X.height:E,Z,ee,ie,ce)}}}};fe._tempPatternMatrix=new O;fe.extension={type:[S.CanvasPipesAdaptor],name:"batch"};let rt=fe;class ke{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,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,a){this._renderer.renderPipes.batch.break(a);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,a.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}ke.extension={type:[S.CanvasPipes],name:"colorMask"};function it(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function Ie(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;it(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.moveTo(t.x+t.radius,t.y),s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?(s.moveTo(t.x+t.halfWidth,t.y),s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.moveTo(1,0),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function ct(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),Ie(s,a.shape),o&&s.restore()}return!0}class Re{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,a){this._renderer.renderPipes.batch.break(a),a.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,a=t.canvasContext,n=a?.activeContext;if(!n)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&n.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const o=e.mask.mask;if(!(o instanceof qe)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const r=o,i=r.context?.instructions;if(!i?.length){this._canvasMaskStack.push(!1);return}n.save(),a.setContextTransform(r.groupTransform,(t._roundPixels|r._roundPixels)===1),n.beginPath();let c=!1,h=!1;for(let l=0;l<i.length;l++){const u=i[l],m=u.action;if(m!=="fill"&&m!=="stroke")continue;const k=u.data?.path?.shapePath;if(!k?.shapePrimitives?.length)continue;const T=k.shapePrimitives;for(let C=0;C<T.length;C++){const B=T[C];if(!B?.shape)continue;const P=B.transform,H=P&&!P.isIdentity();H&&(n.save(),n.transform(P.a,P.b,P.c,P.d,P.tx,P.ty)),Ie(n,B.shape),h=ct(n,B.holes)||h,c=!0,H&&n.restore()}}if(!c){n.restore(),this._canvasMaskStack.push(!1);return}h?n.clip("evenodd"):n.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),Le(t))}}Re.extension={type:[S.CanvasPipes],name:"stencilMask"};const f="source-over";function lt(){const s=Se(),e=Object.create(null);return e.inherit=f,e.none=f,e.normal="source-over",e.add="lighter",e.multiply=s?"multiply":f,e.screen=s?"screen":f,e.overlay=s?"overlay":f,e.darken=s?"darken":f,e.lighten=s?"lighten":f,e["color-dodge"]=s?"color-dodge":f,e["color-burn"]=s?"color-burn":f,e["hard-light"]=s?"hard-light":f,e["soft-light"]=s?"soft-light":f,e.difference=s?"difference":f,e.exclusion=s?"exclusion":f,e.saturation=s?"saturation":f,e.color=s?"color":f,e.luminosity=s?"luminosity":f,e["linear-burn"]=s?"color-burn":f,e["linear-dodge"]=s?"color-dodge":f,e["linear-light"]=s?"hard-light":f,e["pin-light"]=s?"hard-light":f,e["vivid-light"]=s?"hard-light":f,e["hard-mix"]=f,e.negation=s?"difference":f,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=f,e.divide=f,e.min=f,e.max=f,e}const ht=new O;class Ae{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=lt(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,a,n){const o=n?O.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||O.IDENTITY;let r=ht;r.copyFrom(o),r.append(e);const i=this._projTransform,c=this.activeResolution;if(a=a||c,i){const h=O.shared;h.copyFrom(r),h.prepend(i),r=h}t?this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c|0,r.ty*c|0):this.activeContext.setTransform(r.a*a,r.b*a,r.c*a,r.d*a,r.tx*c,r.ty*c)}clear(e,t){const a=this.activeContext,n=this._renderer;if(a.clearRect(0,0,n.width,n.height),e){const o=K.shared.setValue(e);a.globalAlpha=t??o.alpha,a.fillStyle=o.toHex(),a.fillRect(0,0,n.width,n.height),a.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}Ae.extension={type:[S.CanvasSystem],name:"canvasContext"};class Be{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}Be.extension={type:[S.CanvasSystem],name:"limits"};const dt="#808080",te=new O,pt=new O,ut=new O,ue=new O;function ft(s,e,t){s.beginPath();for(let a=0;a<t.length;a+=3){const n=t[a]*2,o=t[a+1]*2,r=t[a+2]*2;s.moveTo(e[n],e[n+1]),s.lineTo(e[o],e[o+1]),s.lineTo(e[r],e[r+1]),s.closePath()}s.fill()}function gt(s){return`#${(s&16777215).toString(16).padStart(6,"0")}`}function mt(s,e,t,a,n,o){o=Math.max(0,Math.min(o,Math.min(a,n)/2)),s.moveTo(e+o,t),s.lineTo(e+a-o,t),s.quadraticCurveTo(e+a,t,e+a,t+o),s.lineTo(e+a,t+n-o),s.quadraticCurveTo(e+a,t+n,e+a-o,t+n),s.lineTo(e+o,t+n),s.quadraticCurveTo(e,t+n,e,t+n-o),s.lineTo(e,t+o),s.quadraticCurveTo(e,t,e+o,t)}function ae(s,e){switch(e.type){case"rectangle":{const t=e;s.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;mt(s,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;s.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;s.ellipse?s.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(s.save(),s.translate(t.x,t.y),s.scale(t.halfWidth,t.halfHeight),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{const t=e;s.moveTo(t.x,t.y),s.lineTo(t.x2,t.y2),s.lineTo(t.x3,t.y3),s.closePath();break}default:{const t=e,a=t.points;if(!a?.length)break;s.moveTo(a[0],a[1]);for(let n=2;n<a.length;n+=2)s.lineTo(a[n],a[n+1]);t.closePath&&s.closePath();break}}}function vt(s,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const a=e[t];if(!a?.shape)continue;const n=a.transform,o=n&&!n.isIdentity();o&&(s.save(),s.transform(n.a,n.b,n.c,n.d,n.tx,n.ty)),ae(s,a.shape),o&&s.restore()}return!0}function yt(s,e,t,a){const n=s.fill;if(n instanceof je){n.buildGradient();const r=n.texture;if(r){const i=d.getTintedPattern(r,e),c=t?ue.copyFrom(t).scale(r.source.pixelWidth,r.source.pixelHeight):ue.copyFrom(n.transform);return a&&!s.textureSpace&&c.append(a),d.applyPatternTransform(i,c),i}}if(n instanceof $e){const r=d.getTintedPattern(n.texture,e);return d.applyPatternTransform(r,n.transform),r}const o=s.texture;if(o&&o!==we.WHITE){if(!o.source.resource)return dt;const r=d.getTintedPattern(o,e),i=t?ue.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):s.matrix;return d.applyPatternTransform(r,i),r}return gt(e)}class He{constructor(){this.shader=null}contextChange(e){}execute(e,t){const a=e.renderer,n=a.canvasContext,o=n.activeContext,r=t.groupTransform,i=a.globalUniforms.globalUniformData?.worldColor??4294967295,c=t.groupColorAlpha,h=(i>>>24&255)/255,l=(c>>>24&255)/255,u=a.filter?.alphaMultiplier??1,m=h*l*u;if(m<=0)return;const v=i&16777215,k=c&16777215,T=be(ne(k,v)),C=a._roundPixels|t._roundPixels;o.save(),n.setContextTransform(r,C===1),n.setBlendMode(t.groupBlendMode);const B=t.context.instructions;for(let P=0;P<B.length;P++){const H=B[P];if(H.action==="texture"){const g=H.data,y=g.image,x=y?d.getCanvasSource(y):null;if(!x)continue;const G=g.alpha*m;if(G<=0)continue;const N=ne(g.style,T);o.globalAlpha=G;let w=x;N!==16777215&&(w=d.getTintedCanvas({texture:y},N));const E=y.frame,_=y.source._resolution??y.source.resolution??1;let I=E.x*_,R=E.y*_;const z=E.width*_,q=E.height*_;w!==x&&(I=0,R=0);const D=g.transform,M=D&&!D.isIdentity(),p=y.rotate;M||p?(te.copyFrom(r),M&&te.append(D),p&&A.matrixAppendRotationInv(te,p,g.dx,g.dy,g.dw,g.dh),n.setContextTransform(te,C===1)):n.setContextTransform(r,C===1),o.drawImage(w,I,R,w===x?z:w.width,w===x?q:w.height,p?0:g.dx,p?0:g.dy,g.dw,g.dh),(M||p)&&n.setContextTransform(r,C===1);continue}const V=H.data,J=V?.path?.shapePath;if(!J?.shapePrimitives?.length)continue;const b=V.style,F=ne(b.color,T),W=b.alpha*m;if(W<=0)continue;const Q=H.action==="stroke";if(o.globalAlpha=W,Q){const g=b;o.lineWidth=g.width,o.lineCap=g.cap,o.lineJoin=g.join,o.miterLimit=g.miterLimit}const Y=J.shapePrimitives;if(!Q&&V.hole?.shapePath?.shapePrimitives?.length){const g=Y[Y.length-1];g.holes=V.hole.shapePath.shapePrimitives}for(let g=0;g<Y.length;g++){const y=Y[g];if(!y?.shape)continue;const x=y.transform,G=x&&!x.isIdentity(),N=b.texture&&b.texture!==we.WHITE,w=b.textureSpace==="global"?x:null,E=N?Ye(pt,b,y.shape,w):null,_=G?ut.copyFrom(r).append(x):r,I=yt(b,F,E,_);if(G&&(o.save(),o.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),Q){const R=b;if(R.alignment!==.5&&!R.pixelLine){const q=[],D=[],M=[];if(Ne[y.shape.type]?.build(y.shape,q)){const oe=y.shape.closePath??!0;Xe(q,R,!1,oe,D,M),o.fillStyle=I,ft(o,D,M)}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.strokeStyle=I,o.beginPath(),ae(o,y.shape),o.stroke()}else o.fillStyle=I,o.beginPath(),ae(o,y.shape),vt(o,y.holes)?o.fill("evenodd"):o.fill();G&&o.restore()}}o.restore()}destroy(){this.shader=null}}He.extension={type:[S.CanvasPipesAdaptor],name:"graphics"};class Ct{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:a,context:n}=this._ensureCanvas(t);return{canvas:a,context:n,width:a.width,height:a.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:a}=this._ensureCanvas(t);a.width=e.pixelWidth,a.height=e.pixelHeight}startRenderPass(e,t,a,n){const o=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=o.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,a,n)}clear(e,t,a,n){const r=this._renderTargetSystem.getGpuRenderTarget(e).context,i=n||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(r.setTransform(1,0,0,1,0,0),r.clearRect(i.x,i.y,i.width,i.height),a){const c=K.shared.setValue(a);c.alpha>0&&(r.globalAlpha=c.alpha,r.fillStyle=c.toHex(),r.fillRect(i.x,i.y,i.width,i.height),r.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,a,n,o){const i=this._renderTargetSystem.getGpuRenderTarget(e).canvas,c=t.source,{context:h}=this._ensureCanvas(c),l=o?.x??0,u=o?.y??0;return h.drawImage(i,a.x,a.y,n.width,n.height,l,u,n.width,n.height),c.update(),t}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Ke.test(t))&&(t=U.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const a=t.getContext("2d");return{canvas:t,context:a}}}class We extends Je{constructor(e){super(e),this.adaptor=new Ct,this.adaptor.init(e,this)}}We.extension={type:[S.CanvasSystem],name:"renderTarget"};class De{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=U.get().createCanvas(),a=t.getContext("2d"),n=d.getCanvasSource(e);if(!n)return t;const o=e.frame,r=e.source._resolution??e.source.resolution??1,i=o.x*r,c=o.y*r,h=o.width*r,l=o.height*r;return t.width=Math.ceil(h),t.height=Math.ceil(l),a.drawImage(n,i,c,h,l,0,0,h,l),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}De.extension={type:[S.CanvasSystem],name:"texture"};const xt=[...Ze,Ae,Be,De,We],Tt=[et,tt,nt,at,st,Re,ke,ot],Pt=[rt,He],Ue=[],Oe=[],Ge=[];se.handleByNamedList(S.CanvasSystem,Ue);se.handleByNamedList(S.CanvasPipes,Oe);se.handleByNamedList(S.CanvasPipesAdaptor,Ge);se.add(...xt,...Tt,...Pt);class St extends Qe{constructor(){const e={name:"canvas",type:ze.CANVAS,systems:Ue,renderPipes:Oe,renderPipeAdaptors:Ge};super(e)}}export{St as CanvasRenderer};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import{K as R,r as F,T as d,a9 as P,F as B,y as b,z,u as Be,S as O,V as S,aJ as ye,ae as q,aK as Ne,A as g,aA as V,$ as y,ad as N,af as M,R as Z,aL as J,aM as Ce,aN as De,aO as Q,aP as Ie,a0 as Ge,a1 as Ue,a2 as A}from"./index-BcA9ozYL.js";import{e as Fe,G as Pe,c as Oe,b as Me,U as Le,B as ee,d as C,f as te,g as we}from"./BufferResource-DdnZHNU-.js";import{R as He,S as Ve,d as Xe}from"./RenderTargetSystem-QYja7U1C.js";import"./Filter-BCHzFO9X.js";function ke(){const{userAgent:t}=R.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}class re{constructor(){this._tempState=F.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,r,n){const s=e.renderer,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(r,n.glProgram)}execute(e,r){const n=e.renderer;this._tempState.blendMode=r.blendMode,n.state.set(this._tempState);const s=r.textures.textures;for(let a=0;a<r.textures.count;a++)n.texture.bind(s[a],a);n.geometry.draw(r.topology,r.size,r.start)}}re.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var v=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(v||{});class We{constructor(e,r){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class ne{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new P({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:r}=this,n=this.getGlBuffer(e);r.bindBuffer(n.type,n.buffer)}bindBufferBase(e,r){const{_gl:n}=this;this._boundBufferBases[r]!==e&&(this._boundBufferBases[r]=e,e._lastBindBaseLocation=r,n.bindBufferBase(n.UNIFORM_BUFFER,r,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let r=this.getLastBindBaseLocation(e);if(r>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,r;let n=0,s=this._nextBindBaseIndex;for(;n<2;){s>=this._maxBindings&&(s=this._minBaseLocation,n++);const a=this._boundBufferBases[s];if(a&&a._lastBindCallId===this._bindCallId){s++;continue}break}return r=s,this._nextBindBaseIndex=s+1,n>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[r]=null,r)}getLastBindBaseLocation(e){const r=e._lastBindBaseLocation;return this._boundBufferBases[r]===e?r:-1}bindBufferRange(e,r,n,s){const{_gl:a}=this;n||(n=0),r||(r=0),this._boundBufferBases[r]=null,a.bindBufferRange(a.UNIFORM_BUFFER,r||0,e.buffer,n*256,s||256)}updateBuffer(e){const{_gl:r}=this,n=this.getGlBuffer(e);if(e._updateID===n.updateID)return n;n.updateID=e._updateID,r.bindBuffer(n.type,n.buffer);const s=e.data,a=e.descriptor.usage&B.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;return s?n.byteLength>=s.byteLength?r.bufferSubData(n.type,0,s,0,e._updateSize/s.BYTES_PER_ELEMENT):(n.byteLength=s.byteLength,r.bufferData(n.type,s,a)):(n.byteLength=e.descriptor.size,r.bufferData(n.type,n.byteLength,a)),n}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){const{_gl:r}=this;let n=v.ARRAY_BUFFER;e.descriptor.usage&B.INDEX?n=v.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&B.UNIFORM&&(n=v.UNIFORM_BUFFER);const s=new We(r.createBuffer(),n);return e._gpuData[this._renderer.uid]=s,this._managedBuffers.add(e),s}resetState(){this._boundBufferBases=Object.create(null)}}ne.extension={type:[d.WebGLSystem],name:"buffer"};const L=class se{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...se.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(b("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=R.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const n=this._renderer.background.alpha<1,s=e.premultipliedAlpha??!0,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:r}=this;(r.width<e.width||r.height<e.height)&&(r.width=Math.max(e.width,e.width),r.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof R.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const r=this._renderer.view.canvas;r.addEventListener("webglcontextlost",this.handleContextLost,!1),r.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,r){let n;const s=this.canvas;if(e===2&&(n=s.getContext("webgl2",r)),!n&&(n=s.getContext("webgl",r),!n))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=n,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,r={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...r,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...r,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const n=e.getExtension("WEBGL_provoking_vertex");n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext?.restoreContext()},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext?.loseContext()}forceContextLoss(){this.extensions.loseContext?.loseContext(),this._contextLossForced=!0}validateContext(e){const r=e.getContextAttributes();r&&!r.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")}};L.extension={type:[d.WebGLSystem],name:"context"};L.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let je=L;var G=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(G||{}),w=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(w||{}),l=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(l||{});const X={uint8x2:l.UNSIGNED_BYTE,uint8x4:l.UNSIGNED_BYTE,sint8x2:l.BYTE,sint8x4:l.BYTE,unorm8x2:l.UNSIGNED_BYTE,unorm8x4:l.UNSIGNED_BYTE,snorm8x2:l.BYTE,snorm8x4:l.BYTE,uint16x2:l.UNSIGNED_SHORT,uint16x4:l.UNSIGNED_SHORT,sint16x2:l.SHORT,sint16x4:l.SHORT,unorm16x2:l.UNSIGNED_SHORT,unorm16x4:l.UNSIGNED_SHORT,snorm16x2:l.SHORT,snorm16x4:l.SHORT,float16x2:l.HALF_FLOAT,float16x4:l.HALF_FLOAT,float32:l.FLOAT,float32x2:l.FLOAT,float32x3:l.FLOAT,float32x4:l.FLOAT,uint32:l.UNSIGNED_INT,uint32x2:l.UNSIGNED_INT,uint32x3:l.UNSIGNED_INT,uint32x4:l.UNSIGNED_INT,sint32:l.INT,sint32x2:l.INT,sint32x3:l.INT,sint32x4:l.INT};function Ke(t){return X[t]??X.float32}const $e={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class Ye{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class ae{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new P({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const r=this._renderer.context.extensions.vertexArrayObject;r&&(e.createVertexArray=()=>r.createVertexArrayOES(),e.bindVertexArray=s=>r.bindVertexArrayOES(s),e.deleteVertexArray=s=>r.deleteVertexArrayOES(s));const n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(s,a,i,o)=>{n.drawArraysInstancedANGLE(s,a,i,o)},e.drawElementsInstanced=(s,a,i,o,c)=>{n.drawElementsInstancedANGLE(s,a,i,o,c)},e.vertexAttribDivisor=(s,a)=>n.vertexAttribDivisorANGLE(s,a)),this._activeGeometry=null,this._activeVao=null}bind(e,r){const n=this.gl;this._activeGeometry=e;const s=this.getVao(e,r);this._activeVao!==s&&(this._activeVao=s,n.bindVertexArray(s)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,r=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){const s=e.buffers[n];r.updateBuffer(s)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,r){const n=e.attributes,s=r._attributeData;for(const a in s)if(!n[a])throw new Error(`shader and geometry incompatible, geometry missing the "${a}" attribute`)}getSignature(e,r){const n=e.attributes,s=r._attributeData,a=["g",e.uid];for(const i in n)s[i]&&a.push(i,s[i].location);return a.join("-")}getVao(e,r){return e._gpuData[this._renderer.uid]?.vaoCache[r._key]||this.initGeometryVao(e,r)}initGeometryVao(e,r,n=!0){const s=this._renderer.gl,a=this._renderer.buffer;this._renderer.shader._getProgramData(r),this.checkCompatibility(e,r);const i=this.getSignature(e,r);let o=e._gpuData[this._renderer.uid];o||(o=new Ye,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));const c=o.vaoCache;let u=c[i];if(u)return c[r._key]=u,u;Fe(e,r._attributeData);const _=e.buffers;u=s.createVertexArray(),s.bindVertexArray(u);for(let f=0;f<_.length;f++){const h=_[f];a.bind(h)}return this.activateVao(e,r),c[r._key]=u,c[i]=u,s.bindVertexArray(null),u}onGeometryUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];if(!n)return;const s=n.vaoCache;if(!r)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,r){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 c=a[o],u=c.buffer,_=s.getGlBuffer(u),f=r._attributeData[o];if(f){i!==_&&(s.bind(u),i=_);const h=f.location;n.enableVertexAttribArray(h);const m=z(c.format),p=Ke(c.format);if(f.format?.substring(1,4)==="int"?n.vertexAttribIPointer(h,m.size,p,c.stride,c.offset):n.vertexAttribPointer(h,m.size,p,m.normalised,c.stride,c.offset),c.instance)if(this.hasInstance){const E=c.divisor??1;n.vertexAttribDivisor(h,E)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,r,n,s){const{gl:a}=this._renderer,i=this._activeGeometry,o=$e[e||i.topology];if(s??(s=i.instanceCount),i.indexBuffer){const c=i.indexBuffer.data.BYTES_PER_ELEMENT,u=c===2?a.UNSIGNED_SHORT:a.UNSIGNED_INT;s!==1?a.drawElementsInstanced(o,r||i.indexBuffer.data.length,u,(n||0)*c,s):a.drawElements(o,r||i.indexBuffer.data.length,u,(n||0)*c)}else s!==1?a.drawArraysInstanced(o,n||0,r||i.getSize(),s):a.drawArrays(o,n||0,r||i.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}ae.extension={type:[d.WebGLSystem],name:"geometry"};const ze=new ye({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),H=class ie{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:n}={...ie.defaultOptions,...e};this.useBackBuffer=r,this._antialias=n,this._renderer.context.supports.msaa||(b("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=F.for2d();const s=new Be({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 O({glProgram:s,resources:{uTexture:S.WHITE.source}})}renderStart(e){const r=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!r.isRoot,this._useBackBufferThisRender){const n=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=n.colorTexture,e.target=this._getBackBufferTexture(n.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:ze,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new S({source:new q({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};H.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};H.defaultOptions={useBackBuffer:!1};let qe=H;class oe{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}oe.extension={type:[d.WebGLSystem],name:"colorMask"};class ce{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,r){this._renderer.geometry.bind(e,r.glProgram)}finishRenderPass(){}draw(e){const r=this._renderer,{geometry:n,shader:s,state:a,skipSync:i,topology:o,size:c,start:u,instanceCount:_}=e;r.shader.bind(s,i),r.geometry.bind(n,r.shader._activeProgram),a&&r.state.set(a),r.geometry.draw(o,c,u,_??n.instanceCount)}destroy(){this._renderer=null}}ce.extension={type:[d.WebGLSystem],name:"encoder"};class ue{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ne(this.maxTextures,e);const r=this._renderer.context.webGLVersion===2;this.maxUniformBindings=r?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}ue.extension={type:[d.WebGLSystem],name:"limits"};class Ze{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[]}}class _e{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:g.NONE},this._renderTargetStencilState=Object.create(null),e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:g.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=g.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,r){const n=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,a=Pe[e],i=this._stencilCache;if(n.stencilMode=e,n.stencilReference=r,e===g.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,s.disable(s.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,s.enable(s.STENCIL_TEST)),(e!==i.stencilMode||i.stencilReference!==r)&&(i.stencilMode=e,i.stencilReference=r,s.stencilFunc(this._comparisonFuncMapping[a.stencilBack.compare],r,255),s.stencilOp(s.KEEP,s.KEEP,this._stencilOpsMapping[a.stencilBack.passOp]))}}_e.extension={type:[d.WebGLSystem],name:"stencil"};const fe={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function Je(t){const e=t.map(a=>({data:a,offset:0,size:0})),r=16;let n=0,s=0;for(let a=0;a<e.length;a++){const i=e[a];if(n=fe[i.data.type],!n)throw new Error(`Unknown type ${i.data.type}`);i.data.size>1&&(n=Math.max(n,r)*i.data.size);const o=n===12?16:n;i.size=n;const c=s%r;c>0&&r-c<o?s+=(r-c)%16:s+=(n-c%n)%n,i.offset=s,s+=n}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function Qe(t,e){const r=Math.max(fe[t.data.type]/16,1),n=t.data.value.length/t.data.size,s=(4-n%4)%4,a=t.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
|
|
21
|
-
v = uv.${t.data.name};
|
|
22
|
-
offset += ${e};
|
|
23
|
-
|
|
24
|
-
arrayOffset = offset;
|
|
25
|
-
|
|
26
|
-
t = 0;
|
|
27
|
-
|
|
28
|
-
for(var i=0; i < ${t.data.size*r}; i++)
|
|
29
|
-
{
|
|
30
|
-
for(var j = 0; j < ${n}; j++)
|
|
31
|
-
{
|
|
32
|
-
${a}[arrayOffset++] = v[t++];
|
|
33
|
-
}
|
|
34
|
-
${s!==0?`arrayOffset += ${s};`:""}
|
|
35
|
-
}
|
|
36
|
-
`}function et(t){return Oe(t,"uboStd40",Qe,Me)}class he extends Le{constructor(){super({createUboElements:Je,generateUboSync:et})}}he.extension={type:[d.WebGLSystem],name:"ubo"};class tt{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V;const e=this._renderer.gl;this._drawBuffersCache=[];for(let r=1;r<=16;r++)this._drawBuffersCache[r]=Array.from({length:r},(n,s)=>e.COLOR_ATTACHMENT0+s)}copyToTexture(e,r,n,s,a){const i=this._renderTargetSystem,o=this._renderer,c=i.getGpuRenderTarget(e),u=o.gl;return this.finishRenderPass(e),u.bindFramebuffer(u.FRAMEBUFFER,c.resolveTargetFramebuffer),o.texture.bind(r,0),u.copyTexSubImage2D(u.TEXTURE_2D,0,a.x,a.y,n.x,n.y,s.width,s.height),r}startRenderPass(e,r=!0,n,s,a=0,i=0){const o=this._renderTargetSystem,c=e.colorTexture,u=o.getGpuRenderTarget(e);if(i!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(a>0){if(u.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}let _=s.y;e.isRoot&&(_=c.pixelHeight-s.height-s.y),e.colorTextures.forEach(m=>{this._renderer.texture.unbind(m)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,u.framebuffer),!e.isRoot&&(u._attachedMipLevel!==a||u._attachedLayer!==i)&&(e.colorTextures.forEach((m,p)=>{const E=this._renderer.texture.getGlSource(m);if(E.target===f.TEXTURE_2D){if(i!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+p,f.TEXTURE_2D,E.texture,a)}else if(E.target===f.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");f.framebufferTextureLayer(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+p,E.texture,a,i)}else if(E.target===f.TEXTURE_CUBE_MAP){if(i<0||i>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+p,f.TEXTURE_CUBE_MAP_POSITIVE_X+i,E.texture,a)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),u._attachedMipLevel=a,u._attachedLayer=i),e.colorTextures.length>1&&this._setDrawBuffers(e,f);const h=this._viewPortCache;(h.x!==s.x||h.y!==_||h.width!==s.width||h.height!==s.height)&&(h.x=s.x,h.y=_,h.width=s.width,h.height=s.height,f.viewport(s.x,_,s.width,s.height)),!u.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(u),this.clear(e,r,n)}finishRenderPass(e){const n=this._renderTargetSystem.getGpuRenderTarget(e);if(!n.msaa)return;const s=this._renderer.gl;s.bindFramebuffer(s.FRAMEBUFFER,n.resolveTargetFramebuffer),s.bindFramebuffer(s.READ_FRAMEBUFFER,n.framebuffer),s.blitFramebuffer(0,0,n.width,n.height,0,0,n.width,n.height,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.FRAMEBUFFER,n.framebuffer)}initGpuRenderTarget(e){const n=this._renderer.gl,s=new Ze;return s._attachedMipLevel=0,s._attachedLayer=0,e.colorTexture instanceof y?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),s.framebuffer=null,s):(this._initColor(e,s),n.bindFramebuffer(n.FRAMEBUFFER,null),s)}destroyGpuRenderTarget(e){const r=this._renderer.gl;e.framebuffer&&(r.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(r.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(r.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(n=>{r.deleteRenderbuffer(n)}),e.msaaRenderBuffer=null}clear(e,r,n,s,a=0,i=0){if(!r)return;if(i!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const o=this._renderTargetSystem;typeof r=="boolean"&&(r=r?N.ALL:N.NONE);const c=this._renderer.gl;if(r&N.COLOR){n??(n=o.defaultClearColor);const u=this._clearColorCache,_=n;(u[0]!==_[0]||u[1]!==_[1]||u[2]!==_[2]||u[3]!==_[3])&&(u[0]=_[0],u[1]=_[1],u[2]=_[2],u[3]=_[3],c.clearColor(_[0],_[1],_[2],_[3]))}c.clear(r)}resizeGpuRenderTarget(e){if(e.isRoot)return;const n=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,n),(e.stencil||e.depth)&&this._resizeStencil(n)}_initColor(e,r){const n=this._renderer,s=n.gl,a=s.createFramebuffer();if(r.resolveTargetFramebuffer=a,s.bindFramebuffer(s.FRAMEBUFFER,a),r.width=e.colorTexture.source.pixelWidth,r.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((o,c)=>{const u=o.source;u.antialias&&(n.context.supports.msaa?r.msaa=!0:b("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(u,0);const _=n.texture.getGlSource(u),f=_.texture;if(_.target===s.TEXTURE_2D)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+c,s.TEXTURE_2D,f,0);else if(_.target===s.TEXTURE_2D_ARRAY){if(n.context.webGLVersion<2)throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");s.framebufferTextureLayer(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+c,f,0,0)}else if(_.target===s.TEXTURE_CUBE_MAP)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+c,s.TEXTURE_CUBE_MAP_POSITIVE_X,f,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),r.msaa){const o=s.createFramebuffer();r.framebuffer=o,s.bindFramebuffer(s.FRAMEBUFFER,o),e.colorTextures.forEach((c,u)=>{const _=s.createRenderbuffer();r.msaaRenderBuffer[u]=_})}else r.framebuffer=a;this._resizeColor(e,r)}_resizeColor(e,r){const n=e.colorTexture.source;if(r.width=n.pixelWidth,r.height=n.pixelHeight,r._attachedMipLevel=0,r._attachedLayer=0,e.colorTextures.forEach((s,a)=>{a!==0&&s.source.resize(n.width,n.height,n._resolution)}),r.msaa){const s=this._renderer,a=s.gl,i=r.framebuffer;a.bindFramebuffer(a.FRAMEBUFFER,i),e.colorTextures.forEach((o,c)=>{const u=o.source;s.texture.bindSource(u,0);const f=s.texture.getGlSource(u).internalFormat,h=r.msaaRenderBuffer[c];a.bindRenderbuffer(a.RENDERBUFFER,h),a.renderbufferStorageMultisample(a.RENDERBUFFER,4,f,u.pixelWidth,u.pixelHeight),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0+c,a.RENDERBUFFER,h)})}}_initStencil(e){if(e.framebuffer===null)return;const r=this._renderer.gl,n=r.createRenderbuffer();e.depthStencilRenderBuffer=n,r.bindRenderbuffer(r.RENDERBUFFER,n),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,n),this._resizeStencil(e)}_resizeStencil(e){const r=this._renderer.gl;r.bindRenderbuffer(r.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?r.renderbufferStorageMultisample(r.RENDERBUFFER,4,r.DEPTH24_STENCIL8,e.width,e.height):r.renderbufferStorage(r.RENDERBUFFER,this._renderer.context.webGLVersion===2?r.DEPTH24_STENCIL8:r.DEPTH_STENCIL,e.width,e.height)}prerender(e){const r=e.colorTexture.resource;this._renderer.context.multiView&&y.test(r)&&this._renderer.context.ensureCanvasSize(r)}postrender(e){if(this._renderer.context.multiView&&y.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,n=e.colorTexture;n.context2D.drawImage(r,0,n.pixelHeight-r.height)}}_setDrawBuffers(e,r){const n=e.colorTextures.length,s=this._drawBuffersCache[n];if(this._renderer.context.webGLVersion===1){const a=this._renderer.context.extensions.drawBuffers;a?a.drawBuffersWEBGL(s):b("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else r.drawBuffers(s)}}class le extends He{constructor(e){super(e),this.adaptor=new tt,this.adaptor.init(e,this)}}le.extension={type:[d.WebGLSystem],name:"renderTarget"};function rt(t,e){const r=[],n=[`
|
|
37
|
-
var g = s.groups;
|
|
38
|
-
var sS = r.shader;
|
|
39
|
-
var p = s.glProgram;
|
|
40
|
-
var ugS = r.uniformGroup;
|
|
41
|
-
var resources;
|
|
42
|
-
`];let s=!1,a=0;const i=e._getProgramData(t.glProgram);for(const c in t.groups){const u=t.groups[c];r.push(`
|
|
43
|
-
resources = g[${c}].resources;
|
|
44
|
-
`);for(const _ in u.resources){const f=u.resources[_];if(f instanceof M)if(f.ubo){const h=t._uniformBindMap[c][Number(_)];r.push(`
|
|
45
|
-
sS.bindUniformBlock(
|
|
46
|
-
resources[${_}],
|
|
47
|
-
'${h}',
|
|
48
|
-
${t.glProgram._uniformBlockData[h].index}
|
|
49
|
-
);
|
|
50
|
-
`)}else r.push(`
|
|
51
|
-
ugS.updateUniformGroup(resources[${_}], p, sD);
|
|
52
|
-
`);else if(f instanceof ee){const h=t._uniformBindMap[c][Number(_)];r.push(`
|
|
53
|
-
sS.bindUniformBlock(
|
|
54
|
-
resources[${_}],
|
|
55
|
-
'${h}',
|
|
56
|
-
${t.glProgram._uniformBlockData[h].index}
|
|
57
|
-
);
|
|
58
|
-
`)}else if(f instanceof q){const h=t._uniformBindMap[c][_],m=i.uniformData[h];m&&(s||(s=!0,n.push(`
|
|
59
|
-
var tS = r.texture;
|
|
60
|
-
`)),e._gl.uniform1i(m.location,a),r.push(`
|
|
61
|
-
tS.bind(resources[${_}], ${a});
|
|
62
|
-
`),a++)}}}const o=[...n,...r].join(`
|
|
63
|
-
`);return new Function("r","s","sD",o)}class nt{constructor(e,r){this.program=e,this.uniformData=r,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function k(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function D(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function de(t,e){switch(t){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return D(2*e);case"bvec3":return D(3*e);case"bvec4":return D(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let T=null;const W={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},st={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function me(t,e){if(!T){const r=Object.keys(W);T={};for(let n=0;n<r.length;++n){const s=r[n];T[t[s]]=W[s]}}return T[e]}function at(t,e){const r=me(t,e);return st[r]||"float32"}function it(t,e,r=!1){const n={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let i=0;i<s;i++){const o=e.getActiveAttrib(t,i);if(o.name.startsWith("gl_"))continue;const c=at(e,o.type);n[o.name]={location:0,format:c,stride:z(c).stride,offset:0,instance:!1,start:0}}const a=Object.keys(n);if(r){a.sort((i,o)=>i>o?1:-1);for(let i=0;i<a.length;i++)n[a[i]].location=i,e.bindAttribLocation(t,i,a[i]);e.linkProgram(t)}else for(let i=0;i<a.length;i++)n[a[i]].location=e.getAttribLocation(t,a[i]);return n}function ot(t,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<n;s++){const a=e.getActiveUniformBlockName(t,s),i=e.getUniformBlockIndex(t,a),o=e.getActiveUniformBlockParameter(t,s,e.UNIFORM_BLOCK_DATA_SIZE);r[a]={name:a,index:i,size:o}}return r}function ct(t,e){const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let s=0;s<n;s++){const a=e.getActiveUniform(t,s),i=a.name.replace(/\[.*?\]$/,""),o=!!a.name.match(/\[.*?\]$/),c=me(e,a.type);r[i]={name:i,index:s,type:c,size:a.size,isArray:o,value:de(c,a.size)}}return r}function j(t,e){const r=t.getShaderSource(e).split(`
|
|
64
|
-
`).map((u,_)=>`${_}: ${u}`),n=t.getShaderInfoLog(e),s=n.split(`
|
|
65
|
-
`),a={},i=s.map(u=>parseFloat(u.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(u=>u&&!a[u]?(a[u]=!0,!0):!1),o=[""];i.forEach(u=>{r[u-1]=`%c${r[u-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const c=r.join(`
|
|
66
|
-
`);o[0]=c,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function ut(t,e,r,n){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||j(t,r),t.getShaderParameter(n,t.COMPILE_STATUS)||j(t,n),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function _t(t,e){const r=k(t,t.VERTEX_SHADER,e.vertex),n=k(t,t.FRAGMENT_SHADER,e.fragment),s=t.createProgram();t.attachShader(s,r),t.attachShader(s,n);const a=e.transformFeedbackVaryings;a&&(typeof t.transformFeedbackVaryings!="function"?b("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(s,a.names,a.bufferMode==="separate"?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)||ut(t,s,r,n),e._attributeData=it(s,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=ct(s,t),e._uniformBlockData=ot(s,t),t.deleteShader(r),t.deleteShader(n);const i={};for(const c in e._uniformData){const u=e._uniformData[c];i[c]={location:t.getUniformLocation(s,c),value:de(u.type,u.size)}}return new nt(s,i)}const x={textureCount:0,blockIndex:0};class Ee{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,r){if(this._setProgram(e.glProgram),r)return;x.textureCount=0,x.blockIndex=0;let n=this._shaderSyncFunctions[e.glProgram._key];n||(n=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),n(this._renderer,e,x)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,x)}bindUniformBlock(e,r,n=0){const s=this._renderer.buffer,a=this._getProgramData(this._activeProgram),i=e._bufferResource;i||this._renderer.ubo.updateUniformGroup(e);const o=e.buffer,c=s.updateBuffer(o),u=s.freeLocationForBufferBase(c);if(i){const{offset:f,size:h}=e;f===0&&h===o.data.byteLength?s.bindBufferBase(c,u):s.bindBufferRange(c,u,f)}else s.getLastBindBaseLocation(c)!==u&&s.bindBufferBase(c,u);const _=this._activeProgram._uniformBlockData[r].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 r=this._getProgramData(e);this._gl.useProgram(r.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const r=e._key;return this._programDataHash[r]=_t(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,r){return rt(e,r)}resetState(){this._activeProgram=null}}Ee.extension={type:[d.WebGLSystem],name:"shader"};const ft={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);"},ht={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 lt(t,e){const r=[`
|
|
139
|
-
var v = null;
|
|
140
|
-
var cv = null;
|
|
141
|
-
var cu = null;
|
|
142
|
-
var t = 0;
|
|
143
|
-
var gl = renderer.gl;
|
|
144
|
-
var name = null;
|
|
145
|
-
`];for(const n in t.uniforms){if(!e[n]){t.uniforms[n]instanceof M?t.uniforms[n].ubo?r.push(`
|
|
146
|
-
renderer.shader.bindUniformBlock(uv.${n}, "${n}");
|
|
147
|
-
`):r.push(`
|
|
148
|
-
renderer.shader.updateUniformGroup(uv.${n});
|
|
149
|
-
`):t.uniforms[n]instanceof ee&&r.push(`
|
|
150
|
-
renderer.shader.bindBufferResource(uv.${n}, "${n}");
|
|
151
|
-
`);continue}const s=t.uniformStructures[n];let a=!1;for(let i=0;i<C.length;i++){const o=C[i];if(s.type===o.type&&o.test(s)){r.push(`name = "${n}";`,C[i].uniform),a=!0;break}}if(!a){const o=(s.size===1?ft:ht)[s.type].replace("location",`ud["${n}"].location`);r.push(`
|
|
152
|
-
cu = ud["${n}"];
|
|
153
|
-
cv = cu.value;
|
|
154
|
-
v = uv["${n}"];
|
|
155
|
-
${o};`)}}return new Function("ud","uv","renderer","syncData",r.join(`
|
|
156
|
-
`))}class be{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,r,n){const s=this._renderer.shader._getProgramData(r);(!e.isStatic||e._dirtyId!==s.uniformDirtyGroups[e.uid])&&(s.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,r)(s.uniformData,e.uniforms,this._renderer,n))}_getUniformSyncFunction(e,r){return this._uniformGroupSyncHash[e._signature]?.[r._key]||this._createUniformSyncFunction(e,r)}_createUniformSyncFunction(e,r){const n=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),s=this._getSignature(e,r._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(e,r._uniformData)),n[r._key]=this._cache[s],n[r._key]}_generateUniformsSync(e,r){return lt(e,r)}_getSignature(e,r,n){const s=e.uniforms,a=[`${n}-`];for(const i in s)a.push(i),r[i]&&a.push(r[i].type);return a.join("-")}destroy(){this._renderer=null,this._cache=null}}be.extension={type:[d.WebGLSystem],name:"uniformGroup"};function dt(t){const e={};if(e.normal=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e.add=[t.ONE,t.ONE],e.multiply=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.screen=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e["screen-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.erase=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],!(t instanceof R.get().getWebGLRenderingContext()))e.min=[t.ONE,t.ONE,t.ONE,t.ONE,t.MIN,t.MIN],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,t.MAX,t.MAX];else{const n=t.getExtension("EXT_blend_minmax");n&&(e.min=[t.ONE,t.ONE,t.ONE,t.ONE,n.MIN_EXT,n.MIN_EXT],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,n.MAX_EXT,n.MAX_EXT])}return e}const mt=0,Et=1,bt=2,pt=3,St=4,Rt=5,pe=class U{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[mt]=this.setBlend,this.map[Et]=this.setOffset,this.map[bt]=this.setCullFace,this.map[pt]=this.setDepthTest,this.map[St]=this.setFrontFace,this.map[Rt]=this.setDepthMask,this.checks=[],this.defaultState=F.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=dt(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let r=this.stateId^e.data,n=0;for(;r;)r&1&&this.map[n].call(this,!!(e.data&1<<n)),r>>=1,n++;this.stateId=e.data}for(let r=0;r<this.checks.length;r++)this.checks[r](this,e)}forceState(e){e||(e=this.defaultState);for(let r=0;r<this.map.length;r++)this.map[r].call(this,!!(e.data&1<<r));for(let r=0;r<this.checks.length;r++)this.checks[r](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(U._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(U._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const r=this._invertFrontFace?!e:e;this._glFrontFace!==r&&(this._glFrontFace=r,this.gl.frontFace(this.gl[r?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const r=this.blendModesMap[e],n=this.gl;r.length===2?n.blendFunc(r[0],r[1]):n.blendFuncSeparate(r[0],r[1],r[2],r[3]),r.length===6?(this._blendEq=!0,n.blendEquationSeparate(r[4],r[5])):this._blendEq&&(this._blendEq=!1,n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD))}setPolygonOffset(e,r){this.gl.polygonOffset(e,r)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,r){const n=this.checks.indexOf(e);r&&n===-1?this.checks.push(e):!r&&n!==-1&&this.checks.splice(n,1)}static _checkBlendMode(e,r){e.setBlendMode(r.blendMode)}static _checkPolygonOffset(e,r){e.setPolygonOffset(1,r.polygonOffset)}destroy(){this.gl=null,this.checks.length=0}};pe.extension={type:[d.WebGLSystem],name:"state"};let gt=pe;class Tt{constructor(e){this.target=w.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=l.UNSIGNED_BYTE,this.internalFormat=G.RGBA,this.format=G.RGBA,this.samplerType=0}destroy(){}}const xt={id:"buffer",upload(t,e,r,n,s,a=!1){const i=s||e.target;!a&&e.width===t.width&&e.height===t.height?r.texSubImage2D(i,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(i,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},vt={"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},At={id:"compressed",upload(t,e,r,n,s,a){const i=s??e.target;r.pixelStorei(r.UNPACK_ALIGNMENT,4);let o=t.pixelWidth,c=t.pixelHeight;const u=!!vt[t.format];for(let _=0;_<t.resource.length;_++){const f=t.resource[_];u?r.compressedTexImage2D(i,_,e.internalFormat,o,c,0,f):r.texImage2D(i,_,e.internalFormat,o,c,0,e.format,e.type,f),o=Math.max(o>>1,1),c=Math.max(c>>1,1)}}},K=["right","left","top","bottom","front","back"];function Bt(t){return{id:"cube",upload(e,r,n,s){const a=e.faces;for(let i=0;i<K.length;i++){const o=K[i],c=a[o];(t[c.uploadMethodId]||t.image).upload(c,r,n,s,w.TEXTURE_CUBE_MAP_POSITIVE_X+i,(r._layerInitMask&1<<i)===0),r._layerInitMask|=1<<i}r.width=e.pixelWidth,r.height=e.pixelHeight}}}const Se={id:"image",upload(t,e,r,n,s,a=!1){const i=s||e.target,o=t.pixelWidth,c=t.pixelHeight,u=t.resourceWidth,_=t.resourceHeight,f=n===2,h=a||e.width!==o||e.height!==c,m=u>=o&&_>=c,p=t.resource;(f?yt:Nt)(r,i,e,o,c,u,_,p,h,m),e.width=o,e.height=c}};function yt(t,e,r,n,s,a,i,o,c,u){if(!u){c&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,a,i,r.format,r.type,o);return}if(!c){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,o)}function Nt(t,e,r,n,s,a,i,o,c,u){if(!u){c&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}if(!c){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,r.format,r.type,o)}const Ct=ke(),Dt={id:"video",upload(t,e,r,n,s,a=Ct){if(!t.isValid){const i=s??e.target;r.texImage2D(i,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Se.upload(t,e,r,n,s,a)}},$={linear:9729,nearest:9728},It={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},I={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Gt={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Y(t,e,r,n,s,a,i,o){const c=a;if(!o||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const u=I[i?"clamp-to-edge":t.addressModeU],_=I[i?"clamp-to-edge":t.addressModeV],f=I[i?"clamp-to-edge":t.addressModeW];e[s](c,e.TEXTURE_WRAP_S,u),e[s](c,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[s](c,e.TEXTURE_WRAP_R,f)}if((!o||t.magFilter!=="linear")&&e[s](c,e.TEXTURE_MAG_FILTER,$[t.magFilter]),r){if(!o||t.mipmapFilter!=="linear"){const u=It[t.minFilter][t.mipmapFilter];e[s](c,e.TEXTURE_MIN_FILTER,u)}}else e[s](c,e.TEXTURE_MIN_FILTER,$[t.minFilter]);if(n&&t.maxAnisotropy>1){const u=Math.min(t.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](c,n.TEXTURE_MAX_ANISOTROPY_EXT,u)}t.compare&&e[s](c,e.TEXTURE_COMPARE_FUNC,Gt[t.compare])}function Ut(t){return{r8unorm:t.RED,r8snorm:t.RED,r8uint:t.RED,r8sint:t.RED,r16uint:t.RED,r16sint:t.RED,r16float:t.RED,rg8unorm:t.RG,rg8snorm:t.RG,rg8uint:t.RG,rg8sint:t.RG,r32uint:t.RED,r32sint:t.RED,r32float:t.RED,rg16uint:t.RG,rg16sint:t.RG,rg16float:t.RG,rgba8unorm:t.RGBA,"rgba8unorm-srgb":t.RGBA,rgba8snorm:t.RGBA,rgba8uint:t.RGBA,rgba8sint:t.RGBA,bgra8unorm:t.RGBA,"bgra8unorm-srgb":t.RGBA,rgb9e5ufloat:t.RGB,rgb10a2unorm:t.RGBA,rg11b10ufloat:t.RGB,rg32uint:t.RG,rg32sint:t.RG,rg32float:t.RG,rgba16uint:t.RGBA,rgba16sint:t.RGBA,rgba16float:t.RGBA,rgba32uint:t.RGBA,rgba32sint:t.RGBA,rgba32float:t.RGBA,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT,depth24plus:t.DEPTH_COMPONENT,"depth24plus-stencil8":t.DEPTH_STENCIL,depth32float:t.DEPTH_COMPONENT,"depth32float-stencil8":t.DEPTH_STENCIL}}function Ft(t,e){let r={},n=t.RGBA;return t instanceof R.get().getWebGLRenderingContext()?e.srgb&&(r={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(r={"rgba8unorm-srgb":t.SRGB8_ALPHA8,"bgra8unorm-srgb":t.SRGB8_ALPHA8},n=t.RGBA8),{r8unorm:t.R8,r8snorm:t.R8_SNORM,r8uint:t.R8UI,r8sint:t.R8I,r16uint:t.R16UI,r16sint:t.R16I,r16float:t.R16F,rg8unorm:t.RG8,rg8snorm:t.RG8_SNORM,rg8uint:t.RG8UI,rg8sint:t.RG8I,r32uint:t.R32UI,r32sint:t.R32I,r32float:t.R32F,rg16uint:t.RG16UI,rg16sint:t.RG16I,rg16float:t.RG16F,rgba8unorm:t.RGBA,...r,rgba8snorm:t.RGBA8_SNORM,rgba8uint:t.RGBA8UI,rgba8sint:t.RGBA8I,bgra8unorm:n,rgb9e5ufloat:t.RGB9_E5,rgb10a2unorm:t.RGB10_A2,rg11b10ufloat:t.R11F_G11F_B10F,rg32uint:t.RG32UI,rg32sint:t.RG32I,rg32float:t.RG32F,rgba16uint:t.RGBA16UI,rgba16sint:t.RGBA16I,rgba16float:t.RGBA16F,rgba32uint:t.RGBA32UI,rgba32sint:t.RGBA32I,rgba32float:t.RGBA32F,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT16,depth24plus:t.DEPTH_COMPONENT24,"depth24plus-stencil8":t.DEPTH24_STENCIL8,depth32float:t.DEPTH_COMPONENT32F,"depth32float-stencil8":t.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function Pt(t){return{r8unorm:t.UNSIGNED_BYTE,r8snorm:t.BYTE,r8uint:t.UNSIGNED_BYTE,r8sint:t.BYTE,r16uint:t.UNSIGNED_SHORT,r16sint:t.SHORT,r16float:t.HALF_FLOAT,rg8unorm:t.UNSIGNED_BYTE,rg8snorm:t.BYTE,rg8uint:t.UNSIGNED_BYTE,rg8sint:t.BYTE,r32uint:t.UNSIGNED_INT,r32sint:t.INT,r32float:t.FLOAT,rg16uint:t.UNSIGNED_SHORT,rg16sint:t.SHORT,rg16float:t.HALF_FLOAT,rgba8unorm:t.UNSIGNED_BYTE,"rgba8unorm-srgb":t.UNSIGNED_BYTE,rgba8snorm:t.BYTE,rgba8uint:t.UNSIGNED_BYTE,rgba8sint:t.BYTE,bgra8unorm:t.UNSIGNED_BYTE,"bgra8unorm-srgb":t.UNSIGNED_BYTE,rgb9e5ufloat:t.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:t.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:t.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:t.UNSIGNED_INT,rg32sint:t.INT,rg32float:t.FLOAT,rgba16uint:t.UNSIGNED_SHORT,rgba16sint:t.SHORT,rgba16float:t.HALF_FLOAT,rgba32uint:t.UNSIGNED_INT,rgba32sint:t.INT,rgba32float:t.FLOAT,stencil8:t.UNSIGNED_BYTE,depth16unorm:t.UNSIGNED_SHORT,depth24plus:t.UNSIGNED_INT,"depth24plus-stencil8":t.UNSIGNED_INT_24_8,depth32float:t.FLOAT,"depth32float-stencil8":t.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Ot(t){return{"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP,"1d":null,"3d":t?.TEXTURE_3D||null,"2d-array":t?.TEXTURE_2D_ARRAY||null,"cube-array":t?.TEXTURE_CUBE_MAP_ARRAY||null}}const Mt=4;class Re{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new P({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const r={image:Se,buffer:xt,video:Dt,compressed:At};this._uploads={...r,cube:Bt(r)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Ft(e,this._renderer.context.extensions),this._mapFormatToType=Pt(e),this._mapFormatToFormat=Ut(e),this._mapViewDimensionToGlTarget=Ot(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let r=0;r<16;r++)this.bind(S.EMPTY,r)}initSource(e){this.bind(e)}bind(e,r=0){const n=e.source;e?(this.bindSource(n,r),this._useSeparateSamplers&&this._bindSampler(n.style,r)):(this.bindSource(null,r),this._useSeparateSamplers&&this._bindSampler(null,r))}bindSource(e,r=0){const n=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e||(e=S.EMPTY.source);const s=this.getGlSource(e);n.bindTexture(s.target,s.texture)}}_bindSampler(e,r=0){const n=this._gl;if(!e){this._boundSamplers[r]=null,n.bindSampler(r,null);return}const s=this._getGlSampler(e);this._boundSamplers[r]!==s&&(this._boundSamplers[r]=s,n.bindSampler(r,s))}unbind(e){const r=e.source,n=this._boundTextures,s=this._gl;for(let a=0;a<n.length;a++)if(n[a]===r){this._activateLocation(a);const i=this.getGlSource(r);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 r=this._gl,n=new Tt(r.createTexture());if(n.type=this._mapFormatToType[e.format],n.internalFormat=this._mapFormatToInternalFormat[e.format],n.format=this._mapFormatToFormat[e.format],n.target=this._mapViewDimensionToGlTarget[e.viewDimension],n.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.uploadMethodId==="cube"&&(n.target=r.TEXTURE_CUBE_MAP),e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const 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,r){const n=this._gl,s=this.getGlSource(e);n.bindTexture(s.target,s.texture),this._boundTextures[this._activeTextureLocation]=e,Y(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||(this.unbind(e),this._gl.deleteTexture(n.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const r=this._gl,n=this.getGlSource(e);r.bindTexture(n.target,n.texture),this._boundTextures[this._activeTextureLocation]=e;const s=e.alphaMode==="premultiply-alpha-on-upload";if(this._premultiplyAlpha!==s&&(this._premultiplyAlpha=s,r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,n,r,this._renderer.context.webGLVersion);else if(n.target===r.TEXTURE_2D)this._initEmptyTexture2D(n,e);else if(n.target===r.TEXTURE_2D_ARRAY)this._initEmptyTexture2DArray(n,e);else if(n.target===r.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(n,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(n,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,r=!0){r&&this.bindSource(e,0);const n=this.getGlSource(e);this._gl.generateMipmap(n.target)}_initEmptyTexture2D(e,r){const n=this._gl;n.texImage2D(n.TEXTURE_2D,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let s=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let i=1;i<r.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,r){if(this._renderer.context.webGLVersion!==2)throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");const n=this._gl,s=Math.max(r.arrayLayerCount|0,1);n.texImage3D(n.TEXTURE_2D_ARRAY,0,e.internalFormat,r.pixelWidth,r.pixelHeight,s,0,e.format,e.type,null);let a=Math.max(r.pixelWidth>>1,1),i=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++)n.texImage3D(n.TEXTURE_2D_ARRAY,o,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,r){const n=this._gl,s=6;for(let o=0;o<s;o++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let a=Math.max(r.pixelWidth>>1,1),i=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++){for(let c=0;c<s;c++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+c,o,e.internalFormat,a,i,0,e.format,e.type,null);a=Math.max(a>>1,1),i=Math.max(i>>1,1)}}_applyMipRange(e,r){if(this._renderer.context.webGLVersion!==2)return;const n=this._gl,s=Math.max((r.mipLevelCount|0)-1,0);n.texParameteri(e.target,n.TEXTURE_BASE_LEVEL,0),n.texParameteri(e.target,n.TEXTURE_MAX_LEVEL,s)}_initSampler(e){const r=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,Y(e,r,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",n,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:n,height:s}=this.getPixels(e),a=R.get().createCanvas();a.width=n,a.height=s;const i=a.getContext("2d");if(i){const o=i.createImageData(n,s);o.data.set(r),i.putImageData(o,0,0)}return a}getPixels(e){const r=e.source.resolution,n=e.frame,s=Math.max(Math.round(n.width*r),1),a=Math.max(Math.round(n.height*r),1),i=new Uint8Array(Mt*s*a),o=this._renderer,c=o.renderTarget.getRenderTarget(e),u=o.renderTarget.getGpuRenderTarget(c),_=o.gl;return _.bindFramebuffer(_.FRAMEBUFFER,u.resolveTargetFramebuffer),_.readPixels(Math.round(n.x*r),Math.round(n.y*r),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(S.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Re.extension={type:[d.WebGLSystem],name:"texture"};class ge{contextChange(e){const r=new M({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new Z,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),n=e.limits.maxBatchableTextures,s=J({name:"graphics",bits:[Ce,De(n),te,Q]});this.shader=new O({glProgram:s,resources:{localUniforms:r,batchSamplers:Ie(n)}})}execute(e,r){const n=r.context,s=n.customShader||this.shader,a=e.renderer,i=a.graphicsContext,{batcher:o,instructions:c}=i.getContextRenderData(n);s.groups[0]=a.globalUniforms.bindGroup,a.state.set(e.state),a.shader.bind(s),a.geometry.bind(o.geometry,s.glProgram);const u=c.instructions;for(let _=0;_<c.instructionSize;_++){const f=u[_];if(f.size){for(let h=0;h<f.textures.count;h++)a.texture.bind(f.textures.textures[h],h);a.geometry.draw(f.topology,f.size,f.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}ge.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class Te{init(){const e=J({name:"mesh",bits:[te,we,Q]});this._shader=new O({glProgram:e,resources:{uTexture:S.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new Z}}}})}execute(e,r){const n=e.renderer;let s=r._shader;if(s){if(!s.glProgram){b("Mesh shader has no glProgram",r.shader);return}}else{s=this._shader;const a=r.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:r._geometry,shader:s,state:r.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Te.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const Lt=[...Ve,he,qe,je,ue,ne,Re,le,ae,be,Ee,ce,gt,_e,oe],wt=[...Xe],Ht=[re,Te,ge],xe=[],ve=[],Ae=[];A.handleByNamedList(d.WebGLSystem,xe);A.handleByNamedList(d.WebGLPipes,ve);A.handleByNamedList(d.WebGLPipesAdaptor,Ae);A.add(...Lt,...wt,...Ht);class jt extends Ge{constructor(){const e={name:"webgl",type:Ue.WEBGL,systems:xe,renderPipes:ve,renderPipeAdaptors:Ae};super(e)}}export{jt as WebGLRenderer};
|