@vivi2d/web 0.1.0-alpha.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.
Files changed (37) hide show
  1. package/LICENSE +160 -0
  2. package/README.md +201 -0
  3. package/dist/CanvasPool-CASccukD.js +48 -0
  4. package/dist/CanvasPool-CASccukD.js.map +1 -0
  5. package/dist/CanvasRenderer-BWDoXN0L.js +5750 -0
  6. package/dist/CanvasRenderer-BWDoXN0L.js.map +1 -0
  7. package/dist/GpuStencilModesToPixi-c2lsBIrd.js +221 -0
  8. package/dist/GpuStencilModesToPixi-c2lsBIrd.js.map +1 -0
  9. package/dist/RenderTargetSystem-BCowAg_f.js +3493 -0
  10. package/dist/RenderTargetSystem-BCowAg_f.js.map +1 -0
  11. package/dist/WebGLRenderer-KKZauisz.js +2236 -0
  12. package/dist/WebGLRenderer-KKZauisz.js.map +1 -0
  13. package/dist/WebGPURenderer-xmqgPtcF.js +1632 -0
  14. package/dist/WebGPURenderer-xmqgPtcF.js.map +1 -0
  15. package/dist/auto-register.d.ts +1 -0
  16. package/dist/auto-register.js +3 -0
  17. package/dist/auto-register.js.map +1 -0
  18. package/dist/browserAll-DQ0eWekj.js +1872 -0
  19. package/dist/browserAll-DQ0eWekj.js.map +1 -0
  20. package/dist/canvasUtils-BSaR9Fot.js +210 -0
  21. package/dist/canvasUtils-BSaR9Fot.js.map +1 -0
  22. package/dist/errors.d.ts +12 -0
  23. package/dist/getTextureBatchBindGroup-BYhXfZM4.js +22 -0
  24. package/dist/getTextureBatchBindGroup-BYhXfZM4.js.map +1 -0
  25. package/dist/index-CW8mx7yF.js +18805 -0
  26. package/dist/index-CW8mx7yF.js.map +1 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/model-loader.d.ts +42 -0
  29. package/dist/player.d.ts +85 -0
  30. package/dist/vivi-model-element.d.ts +65 -0
  31. package/dist/vivi2d.es.js +11 -0
  32. package/dist/vivi2d.es.js.map +1 -0
  33. package/dist/vivi2d.umd.js +1020 -0
  34. package/dist/vivi2d.umd.js.map +1 -0
  35. package/dist/webworkerAll-oTmmI2Qm.js +694 -0
  36. package/dist/webworkerAll-oTmmI2Qm.js.map +1 -0
  37. package/package.json +56 -0
@@ -0,0 +1,3493 @@
1
+ import { ac as Ct, al as De, a5 as T, Y as xe, a7 as ge, o as Le, G as St, c as _e, e as D, ao as te, k as He, p as Oe, V as re, v as kt, i as u, F as Mt, z as Pt, M, x as Bt, a6 as se, B as H, aa as Rt, b as ne, H as A, u as ae, j as Fe, w as wt, T as S, S as B, C as Y, s as be, ah as We, Q as $e, N as Ve, U as je, h as O, K as Ut, g as K, D as ie, J as I, R as F, ab as Gt, P as At, a0 as It, a as Et, L as ve, W as ye, f as X, am as zt, t as Dt, y as Lt } from "./index-CW8mx7yF.js";
2
+ function Te(n, e, t, r) {
3
+ if (t ?? (t = 0), r ?? (r = Math.min(n.byteLength - t, e.byteLength)), !(t & 7) && !(r & 7)) {
4
+ const s = r / 8;
5
+ new Float64Array(e, 0, s).set(new Float64Array(n, t, s));
6
+ } else if (!(t & 3) && !(r & 3)) {
7
+ const s = r / 4;
8
+ new Float32Array(e, 0, s).set(new Float32Array(n, t, s));
9
+ } else
10
+ new Uint8Array(e).set(new Uint8Array(n, t, r));
11
+ }
12
+ const Ht = [
13
+ "precision mediump float;",
14
+ "void main(void){",
15
+ "float test = 0.1;",
16
+ "%forloop%",
17
+ "gl_FragColor = vec4(0.0);",
18
+ "}"
19
+ ].join(`
20
+ `);
21
+ function Ot(n) {
22
+ let e = "";
23
+ for (let t = 0; t < n; ++t)
24
+ t > 0 && (e += `
25
+ else `), t < n - 1 && (e += `if(test == ${t}.0){}`);
26
+ return e;
27
+ }
28
+ function Ft(n, e) {
29
+ if (n === 0)
30
+ throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");
31
+ const t = e.createShader(e.FRAGMENT_SHADER);
32
+ try {
33
+ for (; ; ) {
34
+ const r = Ht.replace(/%forloop%/gi, Ot(n));
35
+ if (e.shaderSource(t, r), e.compileShader(t), !e.getShaderParameter(t, e.COMPILE_STATUS))
36
+ n = n / 2 | 0;
37
+ else
38
+ break;
39
+ }
40
+ } finally {
41
+ e.deleteShader(t);
42
+ }
43
+ return n;
44
+ }
45
+ let R = null;
46
+ function Wt() {
47
+ var e;
48
+ if (R) return R;
49
+ const n = Ct();
50
+ return R = n.getParameter(n.MAX_TEXTURE_IMAGE_UNITS), R = Ft(
51
+ R,
52
+ n
53
+ ), (e = n.getExtension("WEBGL_lose_context")) == null || e.loseContext(), R;
54
+ }
55
+ class $t {
56
+ constructor() {
57
+ this.ids = /* @__PURE__ */ Object.create(null), this.textures = [], this.count = 0;
58
+ }
59
+ /** Clear the textures and their locations. */
60
+ clear() {
61
+ for (let e = 0; e < this.count; e++) {
62
+ const t = this.textures[e];
63
+ this.textures[e] = null, this.ids[t.uid] = null;
64
+ }
65
+ this.count = 0;
66
+ }
67
+ }
68
+ class Vt {
69
+ constructor() {
70
+ this.renderPipeId = "batch", this.action = "startBatch", this.start = 0, this.size = 0, this.textures = new $t(), this.blendMode = "normal", this.topology = "triangle-strip", this.canBundle = !0;
71
+ }
72
+ destroy() {
73
+ this.textures = null, this.gpuBindGroup = null, this.bindGroup = null, this.batcher = null, this.elements = null;
74
+ }
75
+ }
76
+ const E = [];
77
+ let W = 0;
78
+ Le.register({
79
+ clear: () => {
80
+ if (E.length > 0)
81
+ for (const n of E)
82
+ n && n.destroy();
83
+ E.length = 0, W = 0;
84
+ }
85
+ });
86
+ function Ce() {
87
+ return W > 0 ? E[--W] : new Vt();
88
+ }
89
+ function Se(n) {
90
+ n.elements = null, E[W++] = n;
91
+ }
92
+ let U = 0;
93
+ const Ne = class qe {
94
+ constructor(e) {
95
+ this.uid = De("batcher"), this.dirty = !0, this.batchIndex = 0, this.batches = [], this._elements = [], e = { ...qe.defaultOptions, ...e }, e.maxTextures || (T("v8.8.0", "maxTextures is a required option for Batcher now, please pass it in the options"), e.maxTextures = Wt());
96
+ const { maxTextures: t, attributesInitialSize: r, indicesInitialSize: s } = e;
97
+ this.attributeBuffer = new xe(r * 4), this.indexBuffer = new Uint16Array(s), this.maxTextures = t;
98
+ }
99
+ begin() {
100
+ this.elementSize = 0, this.elementStart = 0, this.indexSize = 0, this.attributeSize = 0;
101
+ for (let e = 0; e < this.batchIndex; e++)
102
+ Se(this.batches[e]);
103
+ this.batchIndex = 0, this._batchIndexStart = 0, this._batchIndexSize = 0, this.dirty = !0;
104
+ }
105
+ add(e) {
106
+ this._elements[this.elementSize++] = e, e._indexStart = this.indexSize, e._attributeStart = this.attributeSize, e._batcher = this, this.indexSize += e.indexSize, this.attributeSize += e.attributeSize * this.vertexSize;
107
+ }
108
+ checkAndUpdateTexture(e, t) {
109
+ const r = e._batch.textures.ids[t._source.uid];
110
+ return !r && r !== 0 ? !1 : (e._textureId = r, e.texture = t, !0);
111
+ }
112
+ updateElement(e) {
113
+ this.dirty = !0;
114
+ const t = this.attributeBuffer;
115
+ e.packAsQuad ? this.packQuadAttributes(
116
+ e,
117
+ t.float32View,
118
+ t.uint32View,
119
+ e._attributeStart,
120
+ e._textureId
121
+ ) : this.packAttributes(
122
+ e,
123
+ t.float32View,
124
+ t.uint32View,
125
+ e._attributeStart,
126
+ e._textureId
127
+ );
128
+ }
129
+ /**
130
+ * breaks the batcher. This happens when a batch gets too big,
131
+ * or we need to switch to a different type of rendering (a filter for example)
132
+ * @param instructionSet
133
+ */
134
+ break(e) {
135
+ const t = this._elements;
136
+ if (!t[this.elementStart]) return;
137
+ let r = Ce(), s = r.textures;
138
+ s.clear();
139
+ const a = t[this.elementStart];
140
+ let i = ge(a.blendMode, a.texture._source), o = a.topology;
141
+ this.attributeSize * 4 > this.attributeBuffer.size && this._resizeAttributeBuffer(this.attributeSize * 4), this.indexSize > this.indexBuffer.length && this._resizeIndexBuffer(this.indexSize);
142
+ const l = this.attributeBuffer.float32View, d = this.attributeBuffer.uint32View, f = this.indexBuffer;
143
+ let c = this._batchIndexSize, x = this._batchIndexStart, g = "startBatch", m = [];
144
+ const v = this.maxTextures;
145
+ for (let _ = this.elementStart; _ < this.elementSize; ++_) {
146
+ const h = t[_];
147
+ t[_] = null;
148
+ const p = h.texture._source, y = ge(h.blendMode, p), b = i !== y || o !== h.topology;
149
+ if (p._batchTick === U && !b) {
150
+ h._textureId = p._textureBindLocation, c += h.indexSize, h.packAsQuad ? (this.packQuadAttributes(
151
+ h,
152
+ l,
153
+ d,
154
+ h._attributeStart,
155
+ h._textureId
156
+ ), this.packQuadIndex(
157
+ f,
158
+ h._indexStart,
159
+ h._attributeStart / this.vertexSize
160
+ )) : (this.packAttributes(
161
+ h,
162
+ l,
163
+ d,
164
+ h._attributeStart,
165
+ h._textureId
166
+ ), this.packIndex(
167
+ h,
168
+ f,
169
+ h._indexStart,
170
+ h._attributeStart / this.vertexSize
171
+ )), h._batch = r, m.push(h);
172
+ continue;
173
+ }
174
+ p._batchTick = U, (s.count >= v || b) && (this._finishBatch(
175
+ r,
176
+ x,
177
+ c - x,
178
+ s,
179
+ i,
180
+ o,
181
+ e,
182
+ g,
183
+ m
184
+ ), g = "renderBatch", x = c, i = y, o = h.topology, r = Ce(), s = r.textures, s.clear(), m = [], ++U), h._textureId = p._textureBindLocation = s.count, s.ids[p.uid] = s.count, s.textures[s.count++] = p, h._batch = r, m.push(h), c += h.indexSize, h.packAsQuad ? (this.packQuadAttributes(
185
+ h,
186
+ l,
187
+ d,
188
+ h._attributeStart,
189
+ h._textureId
190
+ ), this.packQuadIndex(
191
+ f,
192
+ h._indexStart,
193
+ h._attributeStart / this.vertexSize
194
+ )) : (this.packAttributes(
195
+ h,
196
+ l,
197
+ d,
198
+ h._attributeStart,
199
+ h._textureId
200
+ ), this.packIndex(
201
+ h,
202
+ f,
203
+ h._indexStart,
204
+ h._attributeStart / this.vertexSize
205
+ ));
206
+ }
207
+ s.count > 0 && (this._finishBatch(
208
+ r,
209
+ x,
210
+ c - x,
211
+ s,
212
+ i,
213
+ o,
214
+ e,
215
+ g,
216
+ m
217
+ ), x = c, ++U), this.elementStart = this.elementSize, this._batchIndexStart = x, this._batchIndexSize = c;
218
+ }
219
+ _finishBatch(e, t, r, s, a, i, o, l, d) {
220
+ e.gpuBindGroup = null, e.bindGroup = null, e.action = l, e.batcher = this, e.textures = s, e.blendMode = a, e.topology = i, e.start = t, e.size = r, e.elements = d, ++U, this.batches[this.batchIndex++] = e, o.add(e);
221
+ }
222
+ finish(e) {
223
+ this.break(e);
224
+ }
225
+ /**
226
+ * Resizes the attribute buffer to the given size (1 = 1 float32)
227
+ * @param size - the size in vertices to ensure (not bytes!)
228
+ */
229
+ ensureAttributeBuffer(e) {
230
+ e * 4 <= this.attributeBuffer.size || this._resizeAttributeBuffer(e * 4);
231
+ }
232
+ /**
233
+ * Resizes the index buffer to the given size (1 = 1 float32)
234
+ * @param size - the size in vertices to ensure (not bytes!)
235
+ */
236
+ ensureIndexBuffer(e) {
237
+ e <= this.indexBuffer.length || this._resizeIndexBuffer(e);
238
+ }
239
+ _resizeAttributeBuffer(e) {
240
+ const t = Math.max(e, this.attributeBuffer.size * 2), r = new xe(t);
241
+ Te(this.attributeBuffer.rawBinaryData, r.rawBinaryData), this.attributeBuffer = r;
242
+ }
243
+ _resizeIndexBuffer(e) {
244
+ const t = this.indexBuffer;
245
+ let r = Math.max(e, t.length * 1.5);
246
+ r += r % 2;
247
+ const s = r > 65535 ? new Uint32Array(r) : new Uint16Array(r);
248
+ if (s.BYTES_PER_ELEMENT !== t.BYTES_PER_ELEMENT)
249
+ for (let a = 0; a < t.length; a++)
250
+ s[a] = t[a];
251
+ else
252
+ Te(t.buffer, s.buffer);
253
+ this.indexBuffer = s;
254
+ }
255
+ packQuadIndex(e, t, r) {
256
+ e[t] = r + 0, e[t + 1] = r + 1, e[t + 2] = r + 2, e[t + 3] = r + 0, e[t + 4] = r + 2, e[t + 5] = r + 3;
257
+ }
258
+ packIndex(e, t, r, s) {
259
+ const a = e.indices, i = e.indexSize, o = e.indexOffset, l = e.attributeOffset;
260
+ for (let d = 0; d < i; d++)
261
+ t[r++] = s + a[d + o] - l;
262
+ }
263
+ /**
264
+ * Destroys the batch and its resources.
265
+ * @param options - destruction options
266
+ * @param options.shader - whether to destroy the associated shader
267
+ */
268
+ destroy(e = {}) {
269
+ var t;
270
+ if (this.batches !== null) {
271
+ for (let r = 0; r < this.batchIndex; r++)
272
+ Se(this.batches[r]);
273
+ this.batches = null, this.geometry.destroy(!0), this.geometry = null, e.shader && ((t = this.shader) == null || t.destroy(), this.shader = null);
274
+ for (let r = 0; r < this._elements.length; r++)
275
+ this._elements[r] && (this._elements[r]._batch = null);
276
+ this._elements = null, this.indexBuffer = null, this.attributeBuffer.destroy(), this.attributeBuffer = null;
277
+ }
278
+ }
279
+ };
280
+ Ne.defaultOptions = {
281
+ maxTextures: null,
282
+ attributesInitialSize: 4,
283
+ indicesInitialSize: 6
284
+ };
285
+ let jt = Ne;
286
+ const Nt = new Float32Array(1), qt = new Uint32Array(1);
287
+ class Qt extends St {
288
+ constructor() {
289
+ const t = new _e({
290
+ data: Nt,
291
+ label: "attribute-batch-buffer",
292
+ usage: D.VERTEX | D.COPY_DST,
293
+ shrinkToFit: !1
294
+ }), r = new _e({
295
+ data: qt,
296
+ label: "index-batch-buffer",
297
+ usage: D.INDEX | D.COPY_DST,
298
+ // | BufferUsage.STATIC,
299
+ shrinkToFit: !1
300
+ }), s = 24;
301
+ super({
302
+ attributes: {
303
+ aPosition: {
304
+ buffer: t,
305
+ format: "float32x2",
306
+ stride: s,
307
+ offset: 0
308
+ },
309
+ aUV: {
310
+ buffer: t,
311
+ format: "float32x2",
312
+ stride: s,
313
+ offset: 8
314
+ },
315
+ aColor: {
316
+ buffer: t,
317
+ format: "unorm8x4",
318
+ stride: s,
319
+ offset: 16
320
+ },
321
+ aTextureIdAndRound: {
322
+ buffer: t,
323
+ format: "uint16x2",
324
+ stride: s,
325
+ offset: 20
326
+ }
327
+ },
328
+ indexBuffer: r
329
+ });
330
+ }
331
+ }
332
+ function ke(n, e, t) {
333
+ if (n)
334
+ for (const r in n) {
335
+ const s = r.toLocaleLowerCase(), a = e[s];
336
+ if (a) {
337
+ let i = n[r];
338
+ r === "header" && (i = i.replace(/@in\s+[^;]+;\s*/g, "").replace(/@out\s+[^;]+;\s*/g, "")), t && a.push(`//----${t}----//`), a.push(i);
339
+ } else
340
+ te(`${r} placement hook does not exist in shader`);
341
+ }
342
+ }
343
+ const Yt = /\{\{(.*?)\}\}/g;
344
+ function Me(n) {
345
+ var r;
346
+ const e = {};
347
+ return (((r = n.match(Yt)) == null ? void 0 : r.map((s) => s.replace(/[{()}]/g, ""))) ?? []).forEach((s) => {
348
+ e[s] = [];
349
+ }), e;
350
+ }
351
+ function Pe(n, e) {
352
+ let t;
353
+ const r = /@in\s+([^;]+);/g;
354
+ for (; (t = r.exec(n)) !== null; )
355
+ e.push(t[1]);
356
+ }
357
+ function Be(n, e, t = !1) {
358
+ const r = [];
359
+ Pe(e, r), n.forEach((o) => {
360
+ o.header && Pe(o.header, r);
361
+ });
362
+ const s = r;
363
+ t && s.sort();
364
+ const a = s.map((o, l) => ` @location(${l}) ${o},`).join(`
365
+ `);
366
+ let i = e.replace(/@in\s+[^;]+;\s*/g, "");
367
+ return i = i.replace("{{in}}", `
368
+ ${a}
369
+ `), i;
370
+ }
371
+ function Re(n, e) {
372
+ let t;
373
+ const r = /@out\s+([^;]+);/g;
374
+ for (; (t = r.exec(n)) !== null; )
375
+ e.push(t[1]);
376
+ }
377
+ function Kt(n) {
378
+ const t = /\b(\w+)\s*:/g.exec(n);
379
+ return t ? t[1] : "";
380
+ }
381
+ function Xt(n) {
382
+ const e = /@.*?\s+/g;
383
+ return n.replace(e, "");
384
+ }
385
+ function Jt(n, e) {
386
+ const t = [];
387
+ Re(e, t), n.forEach((l) => {
388
+ l.header && Re(l.header, t);
389
+ });
390
+ let r = 0;
391
+ const s = t.sort().map((l) => l.indexOf("builtin") > -1 ? l : `@location(${r++}) ${l}`).join(`,
392
+ `), a = t.sort().map((l) => ` var ${Xt(l)};`).join(`
393
+ `), i = `return VSOutput(
394
+ ${t.sort().map((l) => ` ${Kt(l)}`).join(`,
395
+ `)});`;
396
+ let o = e.replace(/@out\s+[^;]+;\s*/g, "");
397
+ return o = o.replace("{{struct}}", `
398
+ ${s}
399
+ `), o = o.replace("{{start}}", `
400
+ ${a}
401
+ `), o = o.replace("{{return}}", `
402
+ ${i}
403
+ `), o;
404
+ }
405
+ function we(n, e) {
406
+ let t = n;
407
+ for (const r in e) {
408
+ const s = e[r];
409
+ s.join(`
410
+ `).length ? t = t.replace(`{{${r}}}`, `//-----${r} START-----//
411
+ ${s.join(`
412
+ `)}
413
+ //----${r} FINISH----//`) : t = t.replace(`{{${r}}}`, "");
414
+ }
415
+ return t;
416
+ }
417
+ const k = /* @__PURE__ */ Object.create(null), j = /* @__PURE__ */ new Map();
418
+ let Zt = 0;
419
+ function er({
420
+ template: n,
421
+ bits: e
422
+ }) {
423
+ const t = Qe(n, e);
424
+ if (k[t]) return k[t];
425
+ const { vertex: r, fragment: s } = rr(n, e);
426
+ return k[t] = Ye(r, s, e), k[t];
427
+ }
428
+ function tr({
429
+ template: n,
430
+ bits: e
431
+ }) {
432
+ const t = Qe(n, e);
433
+ return k[t] || (k[t] = Ye(n.vertex, n.fragment, e)), k[t];
434
+ }
435
+ function rr(n, e) {
436
+ const t = e.map((i) => i.vertex).filter((i) => !!i), r = e.map((i) => i.fragment).filter((i) => !!i);
437
+ let s = Be(t, n.vertex, !0);
438
+ s = Jt(t, s);
439
+ const a = Be(r, n.fragment, !0);
440
+ return {
441
+ vertex: s,
442
+ fragment: a
443
+ };
444
+ }
445
+ function Qe(n, e) {
446
+ return e.map((t) => (j.has(t) || j.set(t, Zt++), j.get(t))).sort((t, r) => t - r).join("-") + n.vertex + n.fragment;
447
+ }
448
+ function Ye(n, e, t) {
449
+ const r = Me(n), s = Me(e);
450
+ return t.forEach((a) => {
451
+ ke(a.vertex, r, a.name), ke(a.fragment, s, a.name);
452
+ }), {
453
+ vertex: we(n, r),
454
+ fragment: we(e, s)
455
+ };
456
+ }
457
+ const sr = (
458
+ /* wgsl */
459
+ `
460
+ @in aPosition: vec2<f32>;
461
+ @in aUV: vec2<f32>;
462
+
463
+ @out @builtin(position) vPosition: vec4<f32>;
464
+ @out vUV : vec2<f32>;
465
+ @out vColor : vec4<f32>;
466
+
467
+ {{header}}
468
+
469
+ struct VSOutput {
470
+ {{struct}}
471
+ };
472
+
473
+ @vertex
474
+ fn main( {{in}} ) -> VSOutput {
475
+
476
+ var worldTransformMatrix = globalUniforms.uWorldTransformMatrix;
477
+ var modelMatrix = mat3x3<f32>(
478
+ 1.0, 0.0, 0.0,
479
+ 0.0, 1.0, 0.0,
480
+ 0.0, 0.0, 1.0
481
+ );
482
+ var position = aPosition;
483
+ var uv = aUV;
484
+
485
+ {{start}}
486
+
487
+ vColor = vec4<f32>(1., 1., 1., 1.);
488
+
489
+ {{main}}
490
+
491
+ vUV = uv;
492
+
493
+ var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix;
494
+
495
+ vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0);
496
+
497
+ vColor *= globalUniforms.uWorldColorAlpha;
498
+
499
+ {{end}}
500
+
501
+ {{return}}
502
+ };
503
+ `
504
+ ), nr = (
505
+ /* wgsl */
506
+ `
507
+ @in vUV : vec2<f32>;
508
+ @in vColor : vec4<f32>;
509
+
510
+ {{header}}
511
+
512
+ @fragment
513
+ fn main(
514
+ {{in}}
515
+ ) -> @location(0) vec4<f32> {
516
+
517
+ {{start}}
518
+
519
+ var outColor:vec4<f32>;
520
+
521
+ {{main}}
522
+
523
+ var finalColor:vec4<f32> = outColor * vColor;
524
+
525
+ {{end}}
526
+
527
+ return finalColor;
528
+ };
529
+ `
530
+ ), ar = (
531
+ /* glsl */
532
+ `
533
+ in vec2 aPosition;
534
+ in vec2 aUV;
535
+
536
+ out vec4 vColor;
537
+ out vec2 vUV;
538
+
539
+ {{header}}
540
+
541
+ void main(void){
542
+
543
+ mat3 worldTransformMatrix = uWorldTransformMatrix;
544
+ mat3 modelMatrix = mat3(
545
+ 1.0, 0.0, 0.0,
546
+ 0.0, 1.0, 0.0,
547
+ 0.0, 0.0, 1.0
548
+ );
549
+ vec2 position = aPosition;
550
+ vec2 uv = aUV;
551
+
552
+ {{start}}
553
+
554
+ vColor = vec4(1.);
555
+
556
+ {{main}}
557
+
558
+ vUV = uv;
559
+
560
+ mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix;
561
+
562
+ gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
563
+
564
+ vColor *= uWorldColorAlpha;
565
+
566
+ {{end}}
567
+ }
568
+ `
569
+ ), ir = (
570
+ /* glsl */
571
+ `
572
+
573
+ in vec4 vColor;
574
+ in vec2 vUV;
575
+
576
+ out vec4 finalColor;
577
+
578
+ {{header}}
579
+
580
+ void main(void) {
581
+
582
+ {{start}}
583
+
584
+ vec4 outColor;
585
+
586
+ {{main}}
587
+
588
+ finalColor = outColor * vColor;
589
+
590
+ {{end}}
591
+ }
592
+ `
593
+ ), or = {
594
+ name: "global-uniforms-bit",
595
+ vertex: {
596
+ header: (
597
+ /* wgsl */
598
+ `
599
+ struct GlobalUniforms {
600
+ uProjectionMatrix:mat3x3<f32>,
601
+ uWorldTransformMatrix:mat3x3<f32>,
602
+ uWorldColorAlpha: vec4<f32>,
603
+ uResolution: vec2<f32>,
604
+ }
605
+
606
+ @group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
607
+ `
608
+ )
609
+ }
610
+ }, lr = {
611
+ name: "global-uniforms-bit",
612
+ vertex: {
613
+ header: (
614
+ /* glsl */
615
+ `
616
+ uniform mat3 uProjectionMatrix;
617
+ uniform mat3 uWorldTransformMatrix;
618
+ uniform vec4 uWorldColorAlpha;
619
+ uniform vec2 uResolution;
620
+ `
621
+ )
622
+ }
623
+ };
624
+ function ur({ bits: n, name: e }) {
625
+ const t = er({
626
+ template: {
627
+ fragment: nr,
628
+ vertex: sr
629
+ },
630
+ bits: [
631
+ or,
632
+ ...n
633
+ ]
634
+ });
635
+ return Oe.from({
636
+ name: e,
637
+ vertex: {
638
+ source: t.vertex,
639
+ entryPoint: "main"
640
+ },
641
+ fragment: {
642
+ source: t.fragment,
643
+ entryPoint: "main"
644
+ }
645
+ });
646
+ }
647
+ function cr({ bits: n, name: e }) {
648
+ return new He({
649
+ name: e,
650
+ ...tr({
651
+ template: {
652
+ vertex: ar,
653
+ fragment: ir
654
+ },
655
+ bits: [
656
+ lr,
657
+ ...n
658
+ ]
659
+ })
660
+ });
661
+ }
662
+ const dr = {
663
+ name: "color-bit",
664
+ vertex: {
665
+ header: (
666
+ /* wgsl */
667
+ `
668
+ @in aColor: vec4<f32>;
669
+ `
670
+ ),
671
+ main: (
672
+ /* wgsl */
673
+ `
674
+ vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
675
+ `
676
+ )
677
+ }
678
+ }, hr = {
679
+ name: "color-bit",
680
+ vertex: {
681
+ header: (
682
+ /* glsl */
683
+ `
684
+ in vec4 aColor;
685
+ `
686
+ ),
687
+ main: (
688
+ /* glsl */
689
+ `
690
+ vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
691
+ `
692
+ )
693
+ }
694
+ }, N = {};
695
+ function fr(n) {
696
+ const e = [];
697
+ if (n === 1)
698
+ e.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"), e.push("@group(1) @binding(1) var textureSampler1: sampler;");
699
+ else {
700
+ let t = 0;
701
+ for (let r = 0; r < n; r++)
702
+ e.push(`@group(1) @binding(${t++}) var textureSource${r + 1}: texture_2d<f32>;`), e.push(`@group(1) @binding(${t++}) var textureSampler${r + 1}: sampler;`);
703
+ }
704
+ return e.join(`
705
+ `);
706
+ }
707
+ function pr(n) {
708
+ const e = [];
709
+ if (n === 1)
710
+ e.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");
711
+ else {
712
+ e.push("switch vTextureId {");
713
+ for (let t = 0; t < n; t++)
714
+ t === n - 1 ? e.push(" default:{") : e.push(` case ${t}:{`), e.push(` outColor = textureSampleGrad(textureSource${t + 1}, textureSampler${t + 1}, vUV, uvDx, uvDy);`), e.push(" break;}");
715
+ e.push("}");
716
+ }
717
+ return e.join(`
718
+ `);
719
+ }
720
+ function mr(n) {
721
+ return N[n] || (N[n] = {
722
+ name: "texture-batch-bit",
723
+ vertex: {
724
+ header: `
725
+ @in aTextureIdAndRound: vec2<u32>;
726
+ @out @interpolate(flat) vTextureId : u32;
727
+ `,
728
+ main: `
729
+ vTextureId = aTextureIdAndRound.y;
730
+ `,
731
+ end: `
732
+ if(aTextureIdAndRound.x == 1)
733
+ {
734
+ vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
735
+ }
736
+ `
737
+ },
738
+ fragment: {
739
+ header: `
740
+ @in @interpolate(flat) vTextureId: u32;
741
+
742
+ ${fr(n)}
743
+ `,
744
+ main: `
745
+ var uvDx = dpdx(vUV);
746
+ var uvDy = dpdy(vUV);
747
+
748
+ ${pr(n)}
749
+ `
750
+ }
751
+ }), N[n];
752
+ }
753
+ const q = {};
754
+ function xr(n) {
755
+ const e = [];
756
+ for (let t = 0; t < n; t++)
757
+ t > 0 && e.push("else"), t < n - 1 && e.push(`if(vTextureId < ${t}.5)`), e.push("{"), e.push(` outColor = texture(uTextures[${t}], vUV);`), e.push("}");
758
+ return e.join(`
759
+ `);
760
+ }
761
+ function gr(n) {
762
+ return q[n] || (q[n] = {
763
+ name: "texture-batch-bit",
764
+ vertex: {
765
+ header: `
766
+ in vec2 aTextureIdAndRound;
767
+ out float vTextureId;
768
+
769
+ `,
770
+ main: `
771
+ vTextureId = aTextureIdAndRound.y;
772
+ `,
773
+ end: `
774
+ if(aTextureIdAndRound.x == 1.)
775
+ {
776
+ gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
777
+ }
778
+ `
779
+ },
780
+ fragment: {
781
+ header: `
782
+ in float vTextureId;
783
+
784
+ uniform sampler2D uTextures[${n}];
785
+
786
+ `,
787
+ main: `
788
+
789
+ ${xr(n)}
790
+ `
791
+ }
792
+ }), q[n];
793
+ }
794
+ const _r = {
795
+ name: "round-pixels-bit",
796
+ vertex: {
797
+ header: (
798
+ /* wgsl */
799
+ `
800
+ fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
801
+ {
802
+ return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
803
+ }
804
+ `
805
+ )
806
+ }
807
+ }, br = {
808
+ name: "round-pixels-bit",
809
+ vertex: {
810
+ header: (
811
+ /* glsl */
812
+ `
813
+ vec2 roundPixels(vec2 position, vec2 targetSize)
814
+ {
815
+ return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
816
+ }
817
+ `
818
+ )
819
+ }
820
+ }, Ue = {};
821
+ function vr(n) {
822
+ let e = Ue[n];
823
+ if (e) return e;
824
+ const t = new Int32Array(n);
825
+ for (let r = 0; r < n; r++)
826
+ t[r] = r;
827
+ return e = Ue[n] = new re({
828
+ uTextures: { value: t, type: "i32", size: n }
829
+ }, { isStatic: !0 }), e;
830
+ }
831
+ class Ge extends kt {
832
+ constructor(e) {
833
+ const t = cr({
834
+ name: "batch",
835
+ bits: [
836
+ hr,
837
+ gr(e),
838
+ br
839
+ ]
840
+ }), r = ur({
841
+ name: "batch",
842
+ bits: [
843
+ dr,
844
+ mr(e),
845
+ _r
846
+ ]
847
+ });
848
+ super({
849
+ glProgram: t,
850
+ gpuProgram: r,
851
+ resources: {
852
+ batchSamplers: vr(e)
853
+ }
854
+ }), this.maxTextures = e;
855
+ }
856
+ }
857
+ let G = null;
858
+ const Ke = class Xe extends jt {
859
+ constructor(e) {
860
+ super(e), this.geometry = new Qt(), this.name = Xe.extension.name, this.vertexSize = 6, G ?? (G = new Ge(e.maxTextures)), this.shader = G;
861
+ }
862
+ /**
863
+ * Packs the attributes of a DefaultBatchableMeshElement into the provided views.
864
+ * @param element - The DefaultBatchableMeshElement to pack.
865
+ * @param float32View - The Float32Array view to pack into.
866
+ * @param uint32View - The Uint32Array view to pack into.
867
+ * @param index - The starting index in the views.
868
+ * @param textureId - The texture ID to use.
869
+ */
870
+ packAttributes(e, t, r, s, a) {
871
+ const i = a << 16 | e.roundPixels & 65535, o = e.transform, l = o.a, d = o.b, f = o.c, c = o.d, x = o.tx, g = o.ty, { positions: m, uvs: v } = e, _ = e.color, h = e.attributeOffset, C = h + e.attributeSize;
872
+ for (let p = h; p < C; p++) {
873
+ const y = p * 2, b = m[y], P = m[y + 1];
874
+ t[s++] = l * b + f * P + x, t[s++] = c * P + d * b + g, t[s++] = v[y], t[s++] = v[y + 1], r[s++] = _, r[s++] = i;
875
+ }
876
+ }
877
+ /**
878
+ * Packs the attributes of a DefaultBatchableQuadElement into the provided views.
879
+ * @param element - The DefaultBatchableQuadElement to pack.
880
+ * @param float32View - The Float32Array view to pack into.
881
+ * @param uint32View - The Uint32Array view to pack into.
882
+ * @param index - The starting index in the views.
883
+ * @param textureId - The texture ID to use.
884
+ */
885
+ packQuadAttributes(e, t, r, s, a) {
886
+ const i = e.texture, o = e.transform, l = o.a, d = o.b, f = o.c, c = o.d, x = o.tx, g = o.ty, m = e.bounds, v = m.maxX, _ = m.minX, h = m.maxY, C = m.minY, p = i.uvs, y = e.color, b = a << 16 | e.roundPixels & 65535;
887
+ t[s + 0] = l * _ + f * C + x, t[s + 1] = c * C + d * _ + g, t[s + 2] = p.x0, t[s + 3] = p.y0, r[s + 4] = y, r[s + 5] = b, t[s + 6] = l * v + f * C + x, t[s + 7] = c * C + d * v + g, t[s + 8] = p.x1, t[s + 9] = p.y1, r[s + 10] = y, r[s + 11] = b, t[s + 12] = l * v + f * h + x, t[s + 13] = c * h + d * v + g, t[s + 14] = p.x2, t[s + 15] = p.y2, r[s + 16] = y, r[s + 17] = b, t[s + 18] = l * _ + f * h + x, t[s + 19] = c * h + d * _ + g, t[s + 20] = p.x3, t[s + 21] = p.y3, r[s + 22] = y, r[s + 23] = b;
888
+ }
889
+ /**
890
+ * Updates the maximum number of textures that can be used in the shader.
891
+ * @param maxTextures - The maximum number of textures that can be used in the shader.
892
+ * @internal
893
+ */
894
+ _updateMaxTextures(e) {
895
+ this.shader.maxTextures !== e && (G = new Ge(e), this.shader = G);
896
+ }
897
+ destroy() {
898
+ this.shader = null, super.destroy();
899
+ }
900
+ };
901
+ Ke.extension = {
902
+ type: [
903
+ u.Batcher
904
+ ],
905
+ name: "default"
906
+ };
907
+ let Je = Ke;
908
+ class Nr {
909
+ constructor(e) {
910
+ this.items = /* @__PURE__ */ Object.create(null);
911
+ const { renderer: t, type: r, onUnload: s, priority: a, name: i } = e;
912
+ this._renderer = t, t.gc.addResourceHash(this, "items", r, a ?? 0), this._onUnload = s, this.name = i;
913
+ }
914
+ /**
915
+ * Add an item to the hash. No-op if already added.
916
+ * @param item
917
+ * @returns true if the item was added, false if it was already in the hash
918
+ */
919
+ add(e) {
920
+ return this.items[e.uid] ? !1 : (this.items[e.uid] = e, e.once("unload", this.remove, this), e._gcLastUsed = this._renderer.gc.now, !0);
921
+ }
922
+ remove(e, ...t) {
923
+ var s;
924
+ if (!this.items[e.uid]) return;
925
+ const r = e._gpuData[this._renderer.uid];
926
+ r && ((s = this._onUnload) == null || s.call(this, e, ...t), r.destroy(), e._gpuData[this._renderer.uid] = null, this.items[e.uid] = null);
927
+ }
928
+ removeAll(...e) {
929
+ Object.values(this.items).forEach((t) => t && this.remove(t, ...e));
930
+ }
931
+ destroy(...e) {
932
+ this.removeAll(...e), this.items = /* @__PURE__ */ Object.create(null), this._renderer = null, this._onUnload = null;
933
+ }
934
+ }
935
+ var yr = `in vec2 vMaskCoord;
936
+ in vec2 vTextureCoord;
937
+
938
+ uniform sampler2D uTexture;
939
+ uniform sampler2D uMaskTexture;
940
+
941
+ uniform float uAlpha;
942
+ uniform vec4 uMaskClamp;
943
+ uniform float uInverse;
944
+ uniform float uChannel;
945
+
946
+ out vec4 finalColor;
947
+
948
+ void main(void)
949
+ {
950
+ float clip = step(3.5,
951
+ step(uMaskClamp.x, vMaskCoord.x) +
952
+ step(uMaskClamp.y, vMaskCoord.y) +
953
+ step(vMaskCoord.x, uMaskClamp.z) +
954
+ step(vMaskCoord.y, uMaskClamp.w));
955
+
956
+ // TODO look into why this is needed
957
+ float npmAlpha = uAlpha;
958
+ vec4 original = texture(uTexture, vTextureCoord);
959
+ vec4 masky = texture(uMaskTexture, vMaskCoord);
960
+
961
+ float a;
962
+ if (uChannel == 1.0) {
963
+ a = masky.a * npmAlpha * clip;
964
+ } else {
965
+ float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
966
+ a = alphaMul * masky.r * npmAlpha * clip;
967
+ }
968
+
969
+ if (uInverse == 1.0) {
970
+ a = 1.0 - a;
971
+ }
972
+
973
+ finalColor = original * a;
974
+ }
975
+ `, Tr = `in vec2 aPosition;
976
+
977
+ out vec2 vTextureCoord;
978
+ out vec2 vMaskCoord;
979
+
980
+
981
+ uniform vec4 uInputSize;
982
+ uniform vec4 uOutputFrame;
983
+ uniform vec4 uOutputTexture;
984
+ uniform mat3 uFilterMatrix;
985
+
986
+ vec4 filterVertexPosition( vec2 aPosition )
987
+ {
988
+ vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
989
+
990
+ position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
991
+ position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
992
+
993
+ return vec4(position, 0.0, 1.0);
994
+ }
995
+
996
+ vec2 filterTextureCoord( vec2 aPosition )
997
+ {
998
+ return aPosition * (uOutputFrame.zw * uInputSize.zw);
999
+ }
1000
+
1001
+ vec2 getFilterCoord( vec2 aPosition )
1002
+ {
1003
+ return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
1004
+ }
1005
+
1006
+ void main(void)
1007
+ {
1008
+ gl_Position = filterVertexPosition(aPosition);
1009
+ vTextureCoord = filterTextureCoord(aPosition);
1010
+ vMaskCoord = getFilterCoord(aPosition);
1011
+ }
1012
+ `, Ae = `struct GlobalFilterUniforms {
1013
+ uInputSize:vec4<f32>,
1014
+ uInputPixel:vec4<f32>,
1015
+ uInputClamp:vec4<f32>,
1016
+ uOutputFrame:vec4<f32>,
1017
+ uGlobalFrame:vec4<f32>,
1018
+ uOutputTexture:vec4<f32>,
1019
+ };
1020
+
1021
+ struct MaskUniforms {
1022
+ uFilterMatrix:mat3x3<f32>,
1023
+ uMaskClamp:vec4<f32>,
1024
+ uAlpha:f32,
1025
+ uInverse:f32,
1026
+ uChannel:f32,
1027
+ };
1028
+
1029
+ @group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
1030
+ @group(0) @binding(1) var uTexture: texture_2d<f32>;
1031
+ @group(0) @binding(2) var uSampler : sampler;
1032
+
1033
+ @group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
1034
+ @group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
1035
+
1036
+ struct VSOutput {
1037
+ @builtin(position) position: vec4<f32>,
1038
+ @location(0) uv : vec2<f32>,
1039
+ @location(1) filterUv : vec2<f32>,
1040
+ };
1041
+
1042
+ fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
1043
+ {
1044
+ var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
1045
+
1046
+ position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
1047
+ position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
1048
+
1049
+ return vec4(position, 0.0, 1.0);
1050
+ }
1051
+
1052
+ fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
1053
+ {
1054
+ return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
1055
+ }
1056
+
1057
+ fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
1058
+ {
1059
+ return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
1060
+ }
1061
+
1062
+ fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
1063
+ {
1064
+ return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
1065
+ }
1066
+
1067
+ fn getSize() -> vec2<f32>
1068
+ {
1069
+ return gfu.uGlobalFrame.zw;
1070
+ }
1071
+
1072
+ @vertex
1073
+ fn mainVertex(
1074
+ @location(0) aPosition : vec2<f32>,
1075
+ ) -> VSOutput {
1076
+ return VSOutput(
1077
+ filterVertexPosition(aPosition),
1078
+ filterTextureCoord(aPosition),
1079
+ getFilterCoord(aPosition)
1080
+ );
1081
+ }
1082
+
1083
+ @fragment
1084
+ fn mainFragment(
1085
+ @location(0) uv: vec2<f32>,
1086
+ @location(1) filterUv: vec2<f32>,
1087
+ @builtin(position) position: vec4<f32>
1088
+ ) -> @location(0) vec4<f32> {
1089
+
1090
+ var maskClamp = filterUniforms.uMaskClamp;
1091
+ var uAlpha = filterUniforms.uAlpha;
1092
+
1093
+ var clip = step(3.5,
1094
+ step(maskClamp.x, filterUv.x) +
1095
+ step(maskClamp.y, filterUv.y) +
1096
+ step(filterUv.x, maskClamp.z) +
1097
+ step(filterUv.y, maskClamp.w));
1098
+
1099
+ var mask = textureSample(uMaskTexture, uSampler, filterUv);
1100
+ var source = textureSample(uTexture, uSampler, uv);
1101
+
1102
+ var a: f32;
1103
+ if (filterUniforms.uChannel == 1.0) {
1104
+ a = mask.a * uAlpha * clip;
1105
+ } else {
1106
+ var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
1107
+ a = alphaMul * mask.r * uAlpha * clip;
1108
+ }
1109
+
1110
+ if (filterUniforms.uInverse == 1.0) {
1111
+ a = 1.0 - a;
1112
+ }
1113
+
1114
+ return source * a;
1115
+ }
1116
+ `;
1117
+ class Cr extends Mt {
1118
+ constructor(e) {
1119
+ const { sprite: t, ...r } = e, s = new Pt(t.texture), a = new re({
1120
+ uFilterMatrix: { value: new M(), type: "mat3x3<f32>" },
1121
+ uMaskClamp: { value: s.uClampFrame, type: "vec4<f32>" },
1122
+ uAlpha: { value: 1, type: "f32" },
1123
+ uInverse: { value: e.inverse ? 1 : 0, type: "f32" },
1124
+ uChannel: { value: e.channel === "alpha" ? 1 : 0, type: "f32" }
1125
+ }), i = Oe.from({
1126
+ vertex: {
1127
+ source: Ae,
1128
+ entryPoint: "mainVertex"
1129
+ },
1130
+ fragment: {
1131
+ source: Ae,
1132
+ entryPoint: "mainFragment"
1133
+ }
1134
+ }), o = He.from({
1135
+ vertex: Tr,
1136
+ fragment: yr,
1137
+ name: "mask-filter"
1138
+ });
1139
+ super({
1140
+ ...r,
1141
+ gpuProgram: i,
1142
+ glProgram: o,
1143
+ clipToViewport: !1,
1144
+ resources: {
1145
+ filterUniforms: a,
1146
+ uMaskTexture: t.texture.source
1147
+ }
1148
+ }), this.sprite = t, this._textureMatrix = s;
1149
+ }
1150
+ set inverse(e) {
1151
+ this.resources.filterUniforms.uniforms.uInverse = e ? 1 : 0;
1152
+ }
1153
+ get inverse() {
1154
+ return this.resources.filterUniforms.uniforms.uInverse === 1;
1155
+ }
1156
+ set channel(e) {
1157
+ this.resources.filterUniforms.uniforms.uChannel = e === "alpha" ? 1 : 0;
1158
+ }
1159
+ get channel() {
1160
+ return this.resources.filterUniforms.uniforms.uChannel === 1 ? "alpha" : "red";
1161
+ }
1162
+ apply(e, t, r, s) {
1163
+ this._textureMatrix.texture = this.sprite.texture, e.calculateSpriteMatrix(
1164
+ this.resources.filterUniforms.uniforms.uFilterMatrix,
1165
+ this.sprite
1166
+ ).prepend(this._textureMatrix.mapCoord), this.resources.uMaskTexture = this.sprite.texture.source, e.applyFilter(this, t, r, s);
1167
+ }
1168
+ }
1169
+ class Ze {
1170
+ constructor() {
1171
+ this.batcherName = "default", this.topology = "triangle-list", this.attributeSize = 4, this.indexSize = 6, this.packAsQuad = !0, this.roundPixels = 0, this._attributeStart = 0, this._batcher = null, this._batch = null;
1172
+ }
1173
+ get blendMode() {
1174
+ return this.renderable.groupBlendMode;
1175
+ }
1176
+ get color() {
1177
+ return this.renderable.groupColorAlpha;
1178
+ }
1179
+ reset() {
1180
+ this.renderable = null, this.texture = null, this._batcher = null, this._batch = null, this.bounds = null;
1181
+ }
1182
+ destroy() {
1183
+ this.reset();
1184
+ }
1185
+ }
1186
+ const oe = class et {
1187
+ constructor(e, t) {
1188
+ var r, s;
1189
+ this.state = Bt.for2d(), this._batchersByInstructionSet = /* @__PURE__ */ Object.create(null), this._activeBatches = /* @__PURE__ */ Object.create(null), this.renderer = e, this._adaptor = t, (s = (r = this._adaptor).init) == null || s.call(r, this);
1190
+ }
1191
+ static getBatcher(e) {
1192
+ return new this._availableBatchers[e]();
1193
+ }
1194
+ buildStart(e) {
1195
+ let t = this._batchersByInstructionSet[e.uid];
1196
+ t || (t = this._batchersByInstructionSet[e.uid] = /* @__PURE__ */ Object.create(null), t.default || (t.default = new Je({
1197
+ maxTextures: this.renderer.limits.maxBatchableTextures
1198
+ }))), this._activeBatches = t, this._activeBatch = this._activeBatches.default;
1199
+ for (const r in this._activeBatches)
1200
+ this._activeBatches[r].begin();
1201
+ }
1202
+ addToBatch(e, t) {
1203
+ if (this._activeBatch.name !== e.batcherName) {
1204
+ this._activeBatch.break(t);
1205
+ let r = this._activeBatches[e.batcherName];
1206
+ r || (r = this._activeBatches[e.batcherName] = et.getBatcher(e.batcherName), r.begin()), this._activeBatch = r;
1207
+ }
1208
+ this._activeBatch.add(e);
1209
+ }
1210
+ break(e) {
1211
+ this._activeBatch.break(e);
1212
+ }
1213
+ buildEnd(e) {
1214
+ this._activeBatch.break(e);
1215
+ const t = this._activeBatches;
1216
+ for (const r in t) {
1217
+ const s = t[r], a = s.geometry;
1218
+ a.indexBuffer.setDataWithSize(s.indexBuffer, s.indexSize, !0), a.buffers[0].setDataWithSize(s.attributeBuffer.float32View, s.attributeSize, !1);
1219
+ }
1220
+ }
1221
+ upload(e) {
1222
+ const t = this._batchersByInstructionSet[e.uid];
1223
+ for (const r in t) {
1224
+ const s = t[r], a = s.geometry;
1225
+ s.dirty && (s.dirty = !1, a.buffers[0].update(s.attributeSize * 4));
1226
+ }
1227
+ }
1228
+ execute(e) {
1229
+ if (e.action === "startBatch") {
1230
+ const t = e.batcher, r = t.geometry, s = t.shader;
1231
+ this._adaptor.start(this, r, s);
1232
+ }
1233
+ this._adaptor.execute(this, e);
1234
+ }
1235
+ destroy() {
1236
+ this.state = null, this.renderer = null, this._adaptor = null;
1237
+ for (const e in this._activeBatches)
1238
+ this._activeBatches[e].destroy();
1239
+ this._activeBatches = null;
1240
+ }
1241
+ };
1242
+ oe.extension = {
1243
+ type: [
1244
+ u.WebGLPipes,
1245
+ u.WebGPUPipes,
1246
+ u.CanvasPipes
1247
+ ],
1248
+ name: "batch"
1249
+ };
1250
+ oe._availableBatchers = /* @__PURE__ */ Object.create(null);
1251
+ let tt = oe;
1252
+ se.handleByMap(u.Batcher, tt._availableBatchers);
1253
+ se.add(Je);
1254
+ const Sr = new ne();
1255
+ class kr extends Fe {
1256
+ constructor() {
1257
+ super(), this.filters = [new Cr({
1258
+ sprite: new wt(S.EMPTY),
1259
+ inverse: !1,
1260
+ resolution: "inherit",
1261
+ antialias: "inherit"
1262
+ })];
1263
+ }
1264
+ get sprite() {
1265
+ return this.filters[0].sprite;
1266
+ }
1267
+ set sprite(e) {
1268
+ this.filters[0].sprite = e;
1269
+ }
1270
+ get inverse() {
1271
+ return this.filters[0].inverse;
1272
+ }
1273
+ set inverse(e) {
1274
+ this.filters[0].inverse = e;
1275
+ }
1276
+ get channel() {
1277
+ return this.filters[0].channel;
1278
+ }
1279
+ set channel(e) {
1280
+ this.filters[0].channel = e;
1281
+ }
1282
+ }
1283
+ class rt {
1284
+ constructor(e) {
1285
+ this._activeMaskStage = [], this._renderer = e;
1286
+ }
1287
+ push(e, t, r) {
1288
+ const s = this._renderer;
1289
+ if (s.renderPipes.batch.break(r), r.add({
1290
+ renderPipeId: "alphaMask",
1291
+ action: "pushMaskBegin",
1292
+ mask: e,
1293
+ inverse: t._maskOptions.inverse,
1294
+ canBundle: !1,
1295
+ maskedContainer: t
1296
+ }), e.inverse = t._maskOptions.inverse, e.channel = t._maskOptions.channel ?? "red", e.renderMaskToTexture) {
1297
+ const a = e.mask;
1298
+ a.includeInBuild = !0, a.collectRenderables(
1299
+ r,
1300
+ s,
1301
+ null
1302
+ ), a.includeInBuild = !1;
1303
+ }
1304
+ s.renderPipes.batch.break(r), r.add({
1305
+ renderPipeId: "alphaMask",
1306
+ action: "pushMaskEnd",
1307
+ mask: e,
1308
+ maskedContainer: t,
1309
+ inverse: t._maskOptions.inverse,
1310
+ canBundle: !1
1311
+ });
1312
+ }
1313
+ pop(e, t, r) {
1314
+ this._renderer.renderPipes.batch.break(r), r.add({
1315
+ renderPipeId: "alphaMask",
1316
+ action: "popMaskEnd",
1317
+ mask: e,
1318
+ inverse: t._maskOptions.inverse,
1319
+ canBundle: !1
1320
+ });
1321
+ }
1322
+ execute(e) {
1323
+ const t = this._renderer, r = e.mask.renderMaskToTexture;
1324
+ if (e.action === "pushMaskBegin") {
1325
+ const s = H.get(kr);
1326
+ if (s.inverse = e.inverse, s.channel = e.mask.channel, r) {
1327
+ e.mask.mask.measurable = !0;
1328
+ const a = Rt(e.mask.mask, !0, Sr);
1329
+ e.mask.mask.measurable = !1, a.ceil();
1330
+ const i = t.renderTarget.renderTarget.colorTexture.source, o = A.getOptimalTexture(
1331
+ a.width,
1332
+ a.height,
1333
+ i._resolution,
1334
+ i.antialias
1335
+ );
1336
+ t.renderTarget.push(o, !0), t.globalUniforms.push({
1337
+ offset: a,
1338
+ worldColor: 4294967295
1339
+ });
1340
+ const l = s.sprite;
1341
+ l.texture = o, l.worldTransform.tx = a.minX, l.worldTransform.ty = a.minY, this._activeMaskStage.push({
1342
+ filterEffect: s,
1343
+ maskedContainer: e.maskedContainer,
1344
+ filterTexture: o
1345
+ });
1346
+ } else
1347
+ s.sprite = e.mask.mask, this._activeMaskStage.push({
1348
+ filterEffect: s,
1349
+ maskedContainer: e.maskedContainer
1350
+ });
1351
+ } else if (e.action === "pushMaskEnd") {
1352
+ const s = this._activeMaskStage[this._activeMaskStage.length - 1];
1353
+ r && (t.type === ae.WEBGL && t.renderTarget.finishRenderPass(), t.renderTarget.pop(), t.globalUniforms.pop()), t.filter.push({
1354
+ renderPipeId: "filter",
1355
+ action: "pushFilter",
1356
+ container: s.maskedContainer,
1357
+ filterEffect: s.filterEffect,
1358
+ canBundle: !1
1359
+ });
1360
+ } else if (e.action === "popMaskEnd") {
1361
+ t.filter.pop();
1362
+ const s = this._activeMaskStage.pop();
1363
+ r && A.returnTexture(s.filterTexture), H.return(s.filterEffect);
1364
+ }
1365
+ }
1366
+ destroy() {
1367
+ this._renderer = null, this._activeMaskStage = null;
1368
+ }
1369
+ }
1370
+ rt.extension = {
1371
+ type: [
1372
+ u.WebGLPipes,
1373
+ u.WebGPUPipes,
1374
+ u.CanvasPipes
1375
+ ],
1376
+ name: "alphaMask"
1377
+ };
1378
+ class st {
1379
+ constructor(e) {
1380
+ this._colorStack = [], this._colorStackIndex = 0, this._currentColor = 0, this._renderer = e;
1381
+ }
1382
+ buildStart() {
1383
+ this._colorStack[0] = 15, this._colorStackIndex = 1, this._currentColor = 15;
1384
+ }
1385
+ push(e, t, r) {
1386
+ this._renderer.renderPipes.batch.break(r);
1387
+ const a = this._colorStack;
1388
+ a[this._colorStackIndex] = a[this._colorStackIndex - 1] & e.mask;
1389
+ const i = this._colorStack[this._colorStackIndex];
1390
+ i !== this._currentColor && (this._currentColor = i, r.add({
1391
+ renderPipeId: "colorMask",
1392
+ colorMask: i,
1393
+ canBundle: !1
1394
+ })), this._colorStackIndex++;
1395
+ }
1396
+ pop(e, t, r) {
1397
+ this._renderer.renderPipes.batch.break(r);
1398
+ const a = this._colorStack;
1399
+ this._colorStackIndex--;
1400
+ const i = a[this._colorStackIndex - 1];
1401
+ i !== this._currentColor && (this._currentColor = i, r.add({
1402
+ renderPipeId: "colorMask",
1403
+ colorMask: i,
1404
+ canBundle: !1
1405
+ }));
1406
+ }
1407
+ execute(e) {
1408
+ this._renderer.colorMask.setMask(e.colorMask);
1409
+ }
1410
+ destroy() {
1411
+ this._renderer = null, this._colorStack = null;
1412
+ }
1413
+ }
1414
+ st.extension = {
1415
+ type: [
1416
+ u.WebGLPipes,
1417
+ u.WebGPUPipes
1418
+ ],
1419
+ name: "colorMask"
1420
+ };
1421
+ class nt {
1422
+ constructor(e) {
1423
+ this._maskStackHash = {}, this._maskHash = /* @__PURE__ */ new WeakMap(), this._renderer = e;
1424
+ }
1425
+ push(e, t, r) {
1426
+ var s;
1427
+ const a = e, i = this._renderer;
1428
+ i.renderPipes.batch.break(r), i.renderPipes.blendMode.setBlendMode(a.mask, "none", r), r.add({
1429
+ renderPipeId: "stencilMask",
1430
+ action: "pushMaskBegin",
1431
+ mask: e,
1432
+ inverse: t._maskOptions.inverse,
1433
+ canBundle: !1
1434
+ });
1435
+ const o = a.mask;
1436
+ o.includeInBuild = !0, this._maskHash.has(a) || this._maskHash.set(a, {
1437
+ instructionsStart: 0,
1438
+ instructionsLength: 0
1439
+ });
1440
+ const l = this._maskHash.get(a);
1441
+ l.instructionsStart = r.instructionSize, o.collectRenderables(
1442
+ r,
1443
+ i,
1444
+ null
1445
+ ), o.includeInBuild = !1, i.renderPipes.batch.break(r), r.add({
1446
+ renderPipeId: "stencilMask",
1447
+ action: "pushMaskEnd",
1448
+ mask: e,
1449
+ inverse: t._maskOptions.inverse,
1450
+ canBundle: !1
1451
+ });
1452
+ const d = r.instructionSize - l.instructionsStart - 1;
1453
+ l.instructionsLength = d;
1454
+ const f = i.renderTarget.renderTarget.uid;
1455
+ (s = this._maskStackHash)[f] ?? (s[f] = 0);
1456
+ }
1457
+ pop(e, t, r) {
1458
+ const s = e, a = this._renderer;
1459
+ a.renderPipes.batch.break(r), a.renderPipes.blendMode.setBlendMode(s.mask, "none", r), r.add({
1460
+ renderPipeId: "stencilMask",
1461
+ action: "popMaskBegin",
1462
+ inverse: t._maskOptions.inverse,
1463
+ canBundle: !1
1464
+ });
1465
+ const i = this._maskHash.get(e);
1466
+ for (let o = 0; o < i.instructionsLength; o++)
1467
+ r.instructions[r.instructionSize++] = r.instructions[i.instructionsStart++];
1468
+ r.add({
1469
+ renderPipeId: "stencilMask",
1470
+ action: "popMaskEnd",
1471
+ canBundle: !1
1472
+ });
1473
+ }
1474
+ execute(e) {
1475
+ var t;
1476
+ const r = this._renderer, s = r, a = r.renderTarget.renderTarget.uid;
1477
+ let i = (t = this._maskStackHash)[a] ?? (t[a] = 0);
1478
+ e.action === "pushMaskBegin" ? (s.renderTarget.ensureDepthStencil(), s.stencil.setStencilMode(B.RENDERING_MASK_ADD, i), i++, s.colorMask.setMask(0)) : e.action === "pushMaskEnd" ? (e.inverse ? s.stencil.setStencilMode(B.INVERSE_MASK_ACTIVE, i) : s.stencil.setStencilMode(B.MASK_ACTIVE, i), s.colorMask.setMask(15)) : e.action === "popMaskBegin" ? (s.colorMask.setMask(0), i !== 0 ? s.stencil.setStencilMode(B.RENDERING_MASK_REMOVE, i) : (s.renderTarget.clear(null, Y.STENCIL), s.stencil.setStencilMode(B.DISABLED, i)), i--) : e.action === "popMaskEnd" && (e.inverse ? s.stencil.setStencilMode(B.INVERSE_MASK_ACTIVE, i) : s.stencil.setStencilMode(B.MASK_ACTIVE, i), s.colorMask.setMask(15)), this._maskStackHash[a] = i;
1479
+ }
1480
+ destroy() {
1481
+ this._renderer = null, this._maskStackHash = null, this._maskHash = null;
1482
+ }
1483
+ }
1484
+ nt.extension = {
1485
+ type: [
1486
+ u.WebGLPipes,
1487
+ u.WebGPUPipes
1488
+ ],
1489
+ name: "stencilMask"
1490
+ };
1491
+ class at {
1492
+ constructor(e) {
1493
+ this._renderer = e;
1494
+ }
1495
+ updateRenderable() {
1496
+ }
1497
+ destroyRenderable() {
1498
+ }
1499
+ validateRenderable() {
1500
+ return !1;
1501
+ }
1502
+ addRenderable(e, t) {
1503
+ this._renderer.renderPipes.batch.break(t), t.add(e);
1504
+ }
1505
+ execute(e) {
1506
+ e.isRenderable && e.render(this._renderer);
1507
+ }
1508
+ destroy() {
1509
+ this._renderer = null;
1510
+ }
1511
+ }
1512
+ at.extension = {
1513
+ type: [
1514
+ u.WebGLPipes,
1515
+ u.WebGPUPipes,
1516
+ u.CanvasPipes
1517
+ ],
1518
+ name: "customRender"
1519
+ };
1520
+ function J(n, e) {
1521
+ const t = n.instructionSet, r = t.instructions;
1522
+ for (let s = 0; s < t.instructionSize; s++) {
1523
+ const a = r[s];
1524
+ e[a.renderPipeId].execute(a);
1525
+ }
1526
+ }
1527
+ class it {
1528
+ constructor(e) {
1529
+ this._renderer = e;
1530
+ }
1531
+ addRenderGroup(e, t) {
1532
+ e.isCachedAsTexture ? this._addRenderableCacheAsTexture(e, t) : this._addRenderableDirect(e, t);
1533
+ }
1534
+ execute(e) {
1535
+ e.isRenderable && (e.isCachedAsTexture ? this._executeCacheAsTexture(e) : this._executeDirect(e));
1536
+ }
1537
+ destroy() {
1538
+ this._renderer = null;
1539
+ }
1540
+ _addRenderableDirect(e, t) {
1541
+ this._renderer.renderPipes.batch.break(t), e._batchableRenderGroup && (H.return(e._batchableRenderGroup), e._batchableRenderGroup = null), t.add(e);
1542
+ }
1543
+ _addRenderableCacheAsTexture(e, t) {
1544
+ const r = e._batchableRenderGroup ?? (e._batchableRenderGroup = H.get(Ze));
1545
+ r.renderable = e.root, r.transform = e.root.relativeGroupTransform, r.texture = e.texture, r.bounds = e._textureBounds, t.add(e), this._renderer.renderPipes.blendMode.pushBlendMode(e, e.root.groupBlendMode, t), this._renderer.renderPipes.batch.addToBatch(r, t), this._renderer.renderPipes.blendMode.popBlendMode(t);
1546
+ }
1547
+ _executeCacheAsTexture(e) {
1548
+ if (e.textureNeedsUpdate) {
1549
+ e.textureNeedsUpdate = !1;
1550
+ const t = new M().translate(
1551
+ -e._textureBounds.x,
1552
+ -e._textureBounds.y
1553
+ );
1554
+ this._renderer.renderTarget.push(e.texture, !0, null, e.texture.frame), this._renderer.globalUniforms.push({
1555
+ worldTransformMatrix: t,
1556
+ worldColor: 4294967295,
1557
+ offset: { x: 0, y: 0 }
1558
+ }), J(e, this._renderer.renderPipes), this._renderer.renderTarget.finishRenderPass(), this._renderer.renderTarget.pop(), this._renderer.globalUniforms.pop();
1559
+ }
1560
+ e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup), e._batchableRenderGroup._batcher.geometry.buffers[0].update();
1561
+ }
1562
+ _executeDirect(e) {
1563
+ this._renderer.globalUniforms.push({
1564
+ worldTransformMatrix: e.inverseParentTextureTransform,
1565
+ worldColor: e.worldColorAlpha
1566
+ }), J(e, this._renderer.renderPipes), this._renderer.globalUniforms.pop();
1567
+ }
1568
+ }
1569
+ it.extension = {
1570
+ type: [
1571
+ u.WebGLPipes,
1572
+ u.WebGPUPipes,
1573
+ u.CanvasPipes
1574
+ ],
1575
+ name: "renderGroup"
1576
+ };
1577
+ class ot {
1578
+ constructor(e) {
1579
+ this._renderer = e;
1580
+ }
1581
+ addRenderable(e, t) {
1582
+ const r = this._getGpuSprite(e);
1583
+ e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
1584
+ }
1585
+ updateRenderable(e) {
1586
+ const t = this._getGpuSprite(e);
1587
+ e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
1588
+ }
1589
+ validateRenderable(e) {
1590
+ const t = this._getGpuSprite(e);
1591
+ return !t._batcher.checkAndUpdateTexture(
1592
+ t,
1593
+ e._texture
1594
+ );
1595
+ }
1596
+ _updateBatchableSprite(e, t) {
1597
+ t.bounds = e.visualBounds, t.texture = e._texture;
1598
+ }
1599
+ _getGpuSprite(e) {
1600
+ return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
1601
+ }
1602
+ _initGPUSprite(e) {
1603
+ const t = new Ze();
1604
+ return t.renderable = e, t.transform = e.groupTransform, t.texture = e._texture, t.bounds = e.visualBounds, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._gpuData[this._renderer.uid] = t, t;
1605
+ }
1606
+ destroy() {
1607
+ this._renderer = null;
1608
+ }
1609
+ }
1610
+ ot.extension = {
1611
+ type: [
1612
+ u.WebGLPipes,
1613
+ u.WebGPUPipes,
1614
+ u.CanvasPipes
1615
+ ],
1616
+ name: "sprite"
1617
+ };
1618
+ const z = {};
1619
+ se.handle(u.BlendMode, (n) => {
1620
+ if (!n.name)
1621
+ throw new Error("BlendMode extension must have a name property");
1622
+ z[n.name] = n.ref;
1623
+ }, (n) => {
1624
+ delete z[n.name];
1625
+ });
1626
+ class lt {
1627
+ constructor(e) {
1628
+ this._blendModeStack = [], this._isAdvanced = !1, this._filterHash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._renderer.runners.prerender.add(this);
1629
+ }
1630
+ prerender() {
1631
+ this._activeBlendMode = "normal", this._isAdvanced = !1;
1632
+ }
1633
+ /**
1634
+ * Push a blend mode onto the internal stack and apply it to the instruction set if needed.
1635
+ * @param renderable - The renderable or {@link RenderGroup} associated with the change.
1636
+ * @param blendMode - The blend mode to activate.
1637
+ * @param instructionSet - The instruction set being built.
1638
+ */
1639
+ pushBlendMode(e, t, r) {
1640
+ this._blendModeStack.push(t), this.setBlendMode(e, t, r);
1641
+ }
1642
+ /**
1643
+ * Pop the last blend mode from the stack and apply the new top-of-stack mode.
1644
+ * @param instructionSet - The instruction set being built.
1645
+ */
1646
+ popBlendMode(e) {
1647
+ this._blendModeStack.pop();
1648
+ const t = this._blendModeStack[this._activeBlendMode.length - 1] ?? "normal";
1649
+ this.setBlendMode(null, t, e);
1650
+ }
1651
+ /**
1652
+ * Ensure a blend mode switch is added to the instruction set when the mode changes.
1653
+ * If an advanced blend mode is active, subsequent renderables will be collected so they can be
1654
+ * rendered within a single filter pass.
1655
+ * @param renderable - The renderable or {@link RenderGroup} to associate with the change, or null when unwinding.
1656
+ * @param blendMode - The target blend mode.
1657
+ * @param instructionSet - The instruction set being built.
1658
+ */
1659
+ setBlendMode(e, t, r) {
1660
+ var a;
1661
+ const s = e instanceof be;
1662
+ if (this._activeBlendMode === t) {
1663
+ this._isAdvanced && e && !s && ((a = this._renderableList) == null || a.push(e));
1664
+ return;
1665
+ }
1666
+ this._isAdvanced && this._endAdvancedBlendMode(r), this._activeBlendMode = t, e && (this._isAdvanced = !!z[t], this._isAdvanced && this._beginAdvancedBlendMode(e, r));
1667
+ }
1668
+ _beginAdvancedBlendMode(e, t) {
1669
+ this._renderer.renderPipes.batch.break(t);
1670
+ const r = this._activeBlendMode;
1671
+ if (!z[r]) {
1672
+ te(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
1673
+ return;
1674
+ }
1675
+ const s = this._ensureFilterEffect(r), a = e instanceof be, i = {
1676
+ renderPipeId: "filter",
1677
+ action: "pushFilter",
1678
+ filterEffect: s,
1679
+ renderables: a ? null : [e],
1680
+ container: a ? e.root : null,
1681
+ canBundle: !1
1682
+ };
1683
+ this._renderableList = i.renderables, t.add(i);
1684
+ }
1685
+ _ensureFilterEffect(e) {
1686
+ let t = this._filterHash[e];
1687
+ return t || (t = this._filterHash[e] = new Fe(), t.filters = [new z[e]()]), t;
1688
+ }
1689
+ _endAdvancedBlendMode(e) {
1690
+ this._isAdvanced = !1, this._renderableList = null, this._renderer.renderPipes.batch.break(e), e.add({
1691
+ renderPipeId: "filter",
1692
+ action: "popFilter",
1693
+ canBundle: !1
1694
+ });
1695
+ }
1696
+ /**
1697
+ * called when the instruction build process is starting this will reset internally to the default blend mode
1698
+ * @internal
1699
+ */
1700
+ buildStart() {
1701
+ this._isAdvanced = !1;
1702
+ }
1703
+ /**
1704
+ * called when the instruction build process is finished, ensuring that if there is an advanced blend mode
1705
+ * active, we add the final render instructions added to the instruction set
1706
+ * @param instructionSet - The instruction set we are adding to
1707
+ * @internal
1708
+ */
1709
+ buildEnd(e) {
1710
+ this._isAdvanced && this._endAdvancedBlendMode(e);
1711
+ }
1712
+ /** @internal */
1713
+ destroy() {
1714
+ this._renderer = null, this._renderableList = null;
1715
+ for (const e in this._filterHash)
1716
+ this._filterHash[e].destroy();
1717
+ this._filterHash = null;
1718
+ }
1719
+ }
1720
+ lt.extension = {
1721
+ type: [
1722
+ u.WebGLPipes,
1723
+ u.WebGPUPipes,
1724
+ u.CanvasPipes
1725
+ ],
1726
+ name: "blendMode"
1727
+ };
1728
+ function Z(n, e) {
1729
+ e || (e = 0);
1730
+ for (let t = e; t < n.length && n[t]; t++)
1731
+ n[t] = null;
1732
+ }
1733
+ const Mr = new O(), Ie = $e | Ve | je;
1734
+ function ut(n, e = !1) {
1735
+ Pr(n);
1736
+ const t = n.childrenToUpdate, r = n.updateTick++;
1737
+ for (const s in t) {
1738
+ const a = Number(s), i = t[s], o = i.list, l = i.index;
1739
+ for (let d = 0; d < l; d++) {
1740
+ const f = o[d];
1741
+ f.parentRenderGroup === n && f.relativeRenderGroupDepth === a && ct(f, r, 0);
1742
+ }
1743
+ Z(o, l), i.index = 0;
1744
+ }
1745
+ if (e)
1746
+ for (let s = 0; s < n.renderGroupChildren.length; s++)
1747
+ ut(n.renderGroupChildren[s], e);
1748
+ }
1749
+ function Pr(n) {
1750
+ const e = n.root;
1751
+ let t;
1752
+ if (n.renderGroupParent) {
1753
+ const r = n.renderGroupParent;
1754
+ n.worldTransform.appendFrom(
1755
+ e.relativeGroupTransform,
1756
+ r.worldTransform
1757
+ ), n.worldColor = We(
1758
+ e.groupColor,
1759
+ r.worldColor
1760
+ ), t = e.groupAlpha * r.worldAlpha;
1761
+ } else
1762
+ n.worldTransform.copyFrom(e.localTransform), n.worldColor = e.localColor, t = e.localAlpha;
1763
+ t = t < 0 ? 0 : t > 1 ? 1 : t, n.worldAlpha = t, n.worldColorAlpha = n.worldColor + ((t * 255 | 0) << 24);
1764
+ }
1765
+ function ct(n, e, t) {
1766
+ if (e === n.updateTick) return;
1767
+ n.updateTick = e, n.didChange = !1;
1768
+ const r = n.localTransform;
1769
+ n.updateLocalTransform();
1770
+ const s = n.parent;
1771
+ if (s && !s.renderGroup ? (t |= n._updateFlags, n.relativeGroupTransform.appendFrom(
1772
+ r,
1773
+ s.relativeGroupTransform
1774
+ ), t & Ie && Ee(n, s, t)) : (t = n._updateFlags, n.relativeGroupTransform.copyFrom(r), t & Ie && Ee(n, Mr, t)), !n.renderGroup) {
1775
+ const a = n.children, i = a.length;
1776
+ for (let d = 0; d < i; d++)
1777
+ ct(a[d], e, t);
1778
+ const o = n.parentRenderGroup, l = n;
1779
+ l.renderPipeId && !o.structureDidChange && o.updateRenderable(l);
1780
+ }
1781
+ }
1782
+ function Ee(n, e, t) {
1783
+ if (t & Ve) {
1784
+ n.groupColor = We(
1785
+ n.localColor,
1786
+ e.groupColor
1787
+ );
1788
+ let r = n.localAlpha * e.groupAlpha;
1789
+ r = r < 0 ? 0 : r > 1 ? 1 : r, n.groupAlpha = r, n.groupColorAlpha = n.groupColor + ((r * 255 | 0) << 24);
1790
+ }
1791
+ t & je && (n.groupBlendMode = n.localBlendMode === "inherit" ? e.groupBlendMode : n.localBlendMode), t & $e && (n.globalDisplayStatus = n.localDisplayStatus & e.globalDisplayStatus), n._updateFlags = 0;
1792
+ }
1793
+ function Br(n, e) {
1794
+ const { list: t } = n.childrenRenderablesToUpdate;
1795
+ let r = !1;
1796
+ for (let s = 0; s < n.childrenRenderablesToUpdate.index; s++) {
1797
+ const a = t[s];
1798
+ if (r = e[a.renderPipeId].validateRenderable(a), r)
1799
+ break;
1800
+ }
1801
+ return n.structureDidChange = r, r;
1802
+ }
1803
+ const Rr = new M();
1804
+ class dt {
1805
+ constructor(e) {
1806
+ this._renderer = e;
1807
+ }
1808
+ render({ container: e, transform: t }) {
1809
+ const r = e.parent, s = e.renderGroup.renderGroupParent;
1810
+ e.parent = null, e.renderGroup.renderGroupParent = null;
1811
+ const a = this._renderer, i = Rr;
1812
+ t && (i.copyFrom(e.renderGroup.localTransform), e.renderGroup.localTransform.copyFrom(t));
1813
+ const o = a.renderPipes;
1814
+ this._updateCachedRenderGroups(e.renderGroup, null), this._updateRenderGroups(e.renderGroup), a.globalUniforms.start({
1815
+ worldTransformMatrix: t ? e.renderGroup.localTransform : e.renderGroup.worldTransform,
1816
+ worldColor: e.renderGroup.worldColorAlpha
1817
+ }), J(e.renderGroup, o), o.uniformBatch && o.uniformBatch.renderEnd(), t && e.renderGroup.localTransform.copyFrom(i), e.parent = r, e.renderGroup.renderGroupParent = s;
1818
+ }
1819
+ destroy() {
1820
+ this._renderer = null;
1821
+ }
1822
+ _updateCachedRenderGroups(e, t) {
1823
+ if (e._parentCacheAsTextureRenderGroup = t, e.isCachedAsTexture) {
1824
+ if (!e.textureNeedsUpdate) return;
1825
+ t = e;
1826
+ }
1827
+ for (let r = e.renderGroupChildren.length - 1; r >= 0; r--)
1828
+ this._updateCachedRenderGroups(e.renderGroupChildren[r], t);
1829
+ if (e.invalidateMatrices(), e.isCachedAsTexture) {
1830
+ if (e.textureNeedsUpdate) {
1831
+ const r = e.root.getLocalBounds(), s = this._renderer, a = e.textureOptions.resolution || s.view.resolution, i = e.textureOptions.antialias ?? s.view.antialias, o = e.textureOptions.scaleMode ?? "linear", l = e.texture;
1832
+ r.ceil(), e.texture && A.returnTexture(e.texture, !0);
1833
+ const d = A.getOptimalTexture(
1834
+ r.width,
1835
+ r.height,
1836
+ a,
1837
+ i
1838
+ );
1839
+ d._source.style = new Ut({ scaleMode: o }), e.texture = d, e._textureBounds || (e._textureBounds = new ne()), e._textureBounds.copyFrom(r), l !== e.texture && e.renderGroupParent && (e.renderGroupParent.structureDidChange = !0);
1840
+ }
1841
+ } else e.texture && (A.returnTexture(e.texture, !0), e.texture = null);
1842
+ }
1843
+ _updateRenderGroups(e) {
1844
+ const t = this._renderer, r = t.renderPipes;
1845
+ if (e.runOnRender(t), e.instructionSet.renderPipes = r, e.structureDidChange ? Z(e.childrenRenderablesToUpdate.list, 0) : Br(e, r), ut(e), e.structureDidChange ? (e.structureDidChange = !1, this._buildInstructions(e, t)) : this._updateRenderables(e), e.childrenRenderablesToUpdate.index = 0, t.renderPipes.batch.upload(e.instructionSet), !(e.isCachedAsTexture && !e.textureNeedsUpdate))
1846
+ for (let s = 0; s < e.renderGroupChildren.length; s++)
1847
+ this._updateRenderGroups(e.renderGroupChildren[s]);
1848
+ }
1849
+ _updateRenderables(e) {
1850
+ const { list: t, index: r } = e.childrenRenderablesToUpdate;
1851
+ for (let s = 0; s < r; s++) {
1852
+ const a = t[s];
1853
+ a.didViewUpdate && e.updateRenderable(a);
1854
+ }
1855
+ Z(t, r);
1856
+ }
1857
+ _buildInstructions(e, t) {
1858
+ const r = e.root, s = e.instructionSet;
1859
+ s.reset();
1860
+ const a = t.renderPipes ? t : t.batch.renderer, i = a.renderPipes;
1861
+ i.batch.buildStart(s), i.blendMode.buildStart(), i.colorMask.buildStart(), r.sortableChildren && r.sortChildren(), r.collectRenderablesWithEffects(s, a, null), i.batch.buildEnd(s), i.blendMode.buildEnd(s);
1862
+ }
1863
+ }
1864
+ dt.extension = {
1865
+ type: [
1866
+ u.WebGLSystem,
1867
+ u.WebGPUSystem,
1868
+ u.CanvasSystem
1869
+ ],
1870
+ name: "renderGroup"
1871
+ };
1872
+ const le = class ht {
1873
+ constructor() {
1874
+ this.clearBeforeRender = !0, this._backgroundColor = new K(0), this.color = this._backgroundColor, this.alpha = 1;
1875
+ }
1876
+ /**
1877
+ * initiates the background system
1878
+ * @param options - the options for the background colors
1879
+ */
1880
+ init(e) {
1881
+ e = { ...ht.defaultOptions, ...e }, this.clearBeforeRender = e.clearBeforeRender, this.color = e.background || e.backgroundColor || this._backgroundColor, this.alpha = e.backgroundAlpha, this._backgroundColor.setAlpha(e.backgroundAlpha);
1882
+ }
1883
+ /** The background color to fill if not transparent */
1884
+ get color() {
1885
+ return this._backgroundColor;
1886
+ }
1887
+ set color(e) {
1888
+ K.shared.setValue(e).alpha < 1 && this._backgroundColor.alpha === 1 && te(
1889
+ "Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."
1890
+ ), this._backgroundColor.setValue(e);
1891
+ }
1892
+ /** The background color alpha. Setting this to 0 will make the canvas transparent. */
1893
+ get alpha() {
1894
+ return this._backgroundColor.alpha;
1895
+ }
1896
+ set alpha(e) {
1897
+ this._backgroundColor.setAlpha(e);
1898
+ }
1899
+ /** The background color as an [R, G, B, A] array. */
1900
+ get colorRgba() {
1901
+ return this._backgroundColor.toArray();
1902
+ }
1903
+ /**
1904
+ * destroys the background system
1905
+ * @internal
1906
+ */
1907
+ destroy() {
1908
+ }
1909
+ };
1910
+ le.extension = {
1911
+ type: [
1912
+ u.WebGLSystem,
1913
+ u.WebGPUSystem,
1914
+ u.CanvasSystem
1915
+ ],
1916
+ name: "background",
1917
+ priority: 0
1918
+ };
1919
+ le.defaultOptions = {
1920
+ /**
1921
+ * {@link WebGLOptions.backgroundAlpha}
1922
+ * @default 1
1923
+ */
1924
+ backgroundAlpha: 1,
1925
+ /**
1926
+ * {@link WebGLOptions.backgroundColor}
1927
+ * @default 0x000000
1928
+ */
1929
+ backgroundColor: 0,
1930
+ /**
1931
+ * {@link WebGLOptions.clearBeforeRender}
1932
+ * @default true
1933
+ */
1934
+ clearBeforeRender: !0
1935
+ };
1936
+ let wr = le;
1937
+ const Q = {
1938
+ png: "image/png",
1939
+ jpg: "image/jpeg",
1940
+ webp: "image/webp"
1941
+ }, ue = class ft {
1942
+ /** @param renderer - The renderer this System works for. */
1943
+ constructor(e) {
1944
+ this._renderer = e;
1945
+ }
1946
+ _normalizeOptions(e, t = {}) {
1947
+ return e instanceof O || e instanceof S ? {
1948
+ target: e,
1949
+ ...t
1950
+ } : {
1951
+ ...t,
1952
+ ...e
1953
+ };
1954
+ }
1955
+ /**
1956
+ * Creates an IImage from a display object or texture.
1957
+ * @param options - Options for creating the image, or the target to extract
1958
+ * @returns Promise that resolves with the generated IImage
1959
+ * @example
1960
+ * ```ts
1961
+ * // Basic usage with a sprite
1962
+ * const sprite = new Sprite(texture);
1963
+ * const image = await renderer.extract.image(sprite);
1964
+ * document.body.appendChild(image);
1965
+ *
1966
+ * // Advanced usage with options
1967
+ * const image = await renderer.extract.image({
1968
+ * target: container,
1969
+ * format: 'webp',
1970
+ * quality: 0.8,
1971
+ * frame: new Rectangle(0, 0, 100, 100),
1972
+ * resolution: 2,
1973
+ * clearColor: '#ff0000',
1974
+ * antialias: true
1975
+ * });
1976
+ *
1977
+ * // Extract directly from a texture
1978
+ * const texture = Texture.from('myTexture.png');
1979
+ * const image = await renderer.extract.image(texture);
1980
+ * ```
1981
+ * @see {@link ExtractImageOptions} For detailed options
1982
+ * @see {@link ExtractSystem.base64} For base64 string output
1983
+ * @see {@link ExtractSystem.canvas} For canvas output
1984
+ * @see {@link ImageLike} For the image interface
1985
+ * @category rendering
1986
+ */
1987
+ async image(e) {
1988
+ const t = ie.get().createImage();
1989
+ return t.src = await this.base64(e), t;
1990
+ }
1991
+ /**
1992
+ * Converts the target into a base64 encoded string.
1993
+ *
1994
+ * This method works by first creating
1995
+ * a canvas using `Extract.canvas` and then converting it to a base64 string.
1996
+ * @param options - The options for creating the base64 string, or the target to extract
1997
+ * @returns Promise that resolves with the base64 encoded string
1998
+ * @example
1999
+ * ```ts
2000
+ * // Basic usage with a sprite
2001
+ * const sprite = new Sprite(texture);
2002
+ * const base64 = await renderer.extract.base64(sprite);
2003
+ * console.log(base64); // data:image/png;base64,...
2004
+ *
2005
+ * // Advanced usage with options
2006
+ * const base64 = await renderer.extract.base64({
2007
+ * target: container,
2008
+ * format: 'webp',
2009
+ * quality: 0.8,
2010
+ * frame: new Rectangle(0, 0, 100, 100),
2011
+ * resolution: 2
2012
+ * });
2013
+ * ```
2014
+ * @throws Will throw an error if the platform doesn't support any of:
2015
+ * - ICanvas.toDataURL
2016
+ * - ICanvas.toBlob
2017
+ * - ICanvas.convertToBlob
2018
+ * @see {@link ExtractImageOptions} For detailed options
2019
+ * @see {@link ExtractSystem.canvas} For canvas output
2020
+ * @see {@link ExtractSystem.image} For HTMLImage output
2021
+ * @category rendering
2022
+ */
2023
+ async base64(e) {
2024
+ e = this._normalizeOptions(
2025
+ e,
2026
+ ft.defaultImageOptions
2027
+ );
2028
+ const { format: t, quality: r } = e, s = this.canvas(e);
2029
+ if (s.toBlob !== void 0)
2030
+ return new Promise((a, i) => {
2031
+ s.toBlob((o) => {
2032
+ if (!o) {
2033
+ i(new Error("ICanvas.toBlob failed!"));
2034
+ return;
2035
+ }
2036
+ const l = new FileReader();
2037
+ l.onload = () => a(l.result), l.onerror = i, l.readAsDataURL(o);
2038
+ }, Q[t], r);
2039
+ });
2040
+ if (s.toDataURL !== void 0)
2041
+ return s.toDataURL(Q[t], r);
2042
+ if (s.convertToBlob !== void 0) {
2043
+ const a = await s.convertToBlob({ type: Q[t], quality: r });
2044
+ return new Promise((i, o) => {
2045
+ const l = new FileReader();
2046
+ l.onload = () => i(l.result), l.onerror = o, l.readAsDataURL(a);
2047
+ });
2048
+ }
2049
+ throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
2050
+ }
2051
+ /**
2052
+ * Creates a Canvas element, renders the target to it and returns it.
2053
+ * This method is useful for creating static images or when you need direct canvas access.
2054
+ * @param options - The options for creating the canvas, or the target to extract
2055
+ * @returns A Canvas element with the texture rendered on
2056
+ * @example
2057
+ * ```ts
2058
+ * // Basic canvas extraction from a sprite
2059
+ * const sprite = new Sprite(texture);
2060
+ * const canvas = renderer.extract.canvas(sprite);
2061
+ * document.body.appendChild(canvas);
2062
+ *
2063
+ * // Extract with custom region
2064
+ * const canvas = renderer.extract.canvas({
2065
+ * target: container,
2066
+ * frame: new Rectangle(0, 0, 100, 100)
2067
+ * });
2068
+ *
2069
+ * // Extract with high resolution
2070
+ * const canvas = renderer.extract.canvas({
2071
+ * target: sprite,
2072
+ * resolution: 2,
2073
+ * clearColor: '#ff0000'
2074
+ * });
2075
+ *
2076
+ * // Extract directly from a texture
2077
+ * const texture = Texture.from('myTexture.png');
2078
+ * const canvas = renderer.extract.canvas(texture);
2079
+ *
2080
+ * // Extract with anti-aliasing
2081
+ * const canvas = renderer.extract.canvas({
2082
+ * target: graphics,
2083
+ * antialias: true
2084
+ * });
2085
+ * ```
2086
+ * @see {@link ExtractOptions} For detailed options
2087
+ * @see {@link ExtractSystem.image} For HTMLImage output
2088
+ * @see {@link ExtractSystem.pixels} For raw pixel data
2089
+ * @category rendering
2090
+ */
2091
+ canvas(e) {
2092
+ e = this._normalizeOptions(e);
2093
+ const t = e.target, r = this._renderer;
2094
+ if (t instanceof S)
2095
+ return r.texture.generateCanvas(t);
2096
+ const s = r.textureGenerator.generateTexture(e), a = r.texture.generateCanvas(s);
2097
+ return s.destroy(!0), a;
2098
+ }
2099
+ /**
2100
+ * Returns a one-dimensional array containing the pixel data of the entire texture in RGBA order,
2101
+ * with integer values between 0 and 255 (inclusive).
2102
+ * > [!NOE] The returned array is a flat Uint8Array where every 4 values represent RGBA
2103
+ * @param options - The options for extracting the image, or the target to extract
2104
+ * @returns One-dimensional Uint8Array containing the pixel data in RGBA format
2105
+ * @example
2106
+ * ```ts
2107
+ * // Basic pixel extraction
2108
+ * const sprite = new Sprite(texture);
2109
+ * const pixels = renderer.extract.pixels(sprite);
2110
+ * console.log(pixels[0], pixels[1], pixels[2], pixels[3]); // R,G,B,A values
2111
+ *
2112
+ * // Extract with custom region
2113
+ * const pixels = renderer.extract.pixels({
2114
+ * target: sprite,
2115
+ * frame: new Rectangle(0, 0, 100, 100)
2116
+ * });
2117
+ *
2118
+ * // Extract with high resolution
2119
+ * const pixels = renderer.extract.pixels({
2120
+ * target: sprite,
2121
+ * resolution: 2
2122
+ * });
2123
+ * ```
2124
+ * @see {@link ExtractOptions} For detailed options
2125
+ * @see {@link ExtractSystem.canvas} For canvas output
2126
+ * @see {@link ExtractSystem.image} For image output
2127
+ * @category rendering
2128
+ */
2129
+ pixels(e) {
2130
+ e = this._normalizeOptions(e);
2131
+ const t = e.target, r = this._renderer, s = t instanceof S ? t : r.textureGenerator.generateTexture(e), a = r.texture.getPixels(s);
2132
+ return t instanceof O && s.destroy(!0), a;
2133
+ }
2134
+ /**
2135
+ * Creates a texture from a display object or existing texture.
2136
+ *
2137
+ * This is useful for creating
2138
+ * reusable textures from rendered content or making copies of existing textures.
2139
+ * > [!NOTE] The returned texture should be destroyed when no longer needed
2140
+ * @param options - The options for creating the texture, or the target to extract
2141
+ * @returns A new texture containing the extracted content
2142
+ * @example
2143
+ * ```ts
2144
+ * // Basic texture extraction from a sprite
2145
+ * const sprite = new Sprite(texture);
2146
+ * const extractedTexture = renderer.extract.texture(sprite);
2147
+ *
2148
+ * // Extract with custom region
2149
+ * const regionTexture = renderer.extract.texture({
2150
+ * target: container,
2151
+ * frame: new Rectangle(0, 0, 100, 100)
2152
+ * });
2153
+ *
2154
+ * // Extract with high resolution
2155
+ * const hiResTexture = renderer.extract.texture({
2156
+ * target: sprite,
2157
+ * resolution: 2,
2158
+ * clearColor: '#ff0000'
2159
+ * });
2160
+ *
2161
+ * // Create a new sprite from extracted texture
2162
+ * const newSprite = new Sprite(
2163
+ * renderer.extract.texture({
2164
+ * target: graphics,
2165
+ * antialias: true
2166
+ * })
2167
+ * );
2168
+ *
2169
+ * // Clean up when done
2170
+ * extractedTexture.destroy(true);
2171
+ * ```
2172
+ * @see {@link ExtractOptions} For detailed options
2173
+ * @see {@link Texture} For texture management
2174
+ * @see {@link GenerateTextureSystem} For texture generation
2175
+ * @category rendering
2176
+ */
2177
+ texture(e) {
2178
+ return e = this._normalizeOptions(e), e.target instanceof S ? e.target : this._renderer.textureGenerator.generateTexture(e);
2179
+ }
2180
+ /**
2181
+ * Extracts and downloads content from the renderer as an image file.
2182
+ * This is a convenient way to save screenshots or export rendered content.
2183
+ * > [!NOTE] The download will use PNG format regardless of the filename extension
2184
+ * @param options - The options for downloading and extracting the image, or the target to extract
2185
+ * @example
2186
+ * ```ts
2187
+ * // Basic download with default filename
2188
+ * const sprite = new Sprite(texture);
2189
+ * renderer.extract.download(sprite); // Downloads as 'image.png'
2190
+ *
2191
+ * // Download with custom filename
2192
+ * renderer.extract.download({
2193
+ * target: sprite,
2194
+ * filename: 'screenshot.png'
2195
+ * });
2196
+ *
2197
+ * // Download with custom region
2198
+ * renderer.extract.download({
2199
+ * target: container,
2200
+ * filename: 'region.png',
2201
+ * frame: new Rectangle(0, 0, 100, 100)
2202
+ * });
2203
+ *
2204
+ * // Download with high resolution and background
2205
+ * renderer.extract.download({
2206
+ * target: stage,
2207
+ * filename: 'hd-screenshot.png',
2208
+ * resolution: 2,
2209
+ * clearColor: '#ff0000'
2210
+ * });
2211
+ *
2212
+ * // Download with anti-aliasing
2213
+ * renderer.extract.download({
2214
+ * target: graphics,
2215
+ * filename: 'smooth.png',
2216
+ * antialias: true
2217
+ * });
2218
+ * ```
2219
+ * @see {@link ExtractDownloadOptions} For detailed options
2220
+ * @see {@link ExtractSystem.image} For creating images without download
2221
+ * @see {@link ExtractSystem.canvas} For canvas output
2222
+ * @category rendering
2223
+ */
2224
+ download(e) {
2225
+ e = this._normalizeOptions(e);
2226
+ const t = this.canvas(e), r = document.createElement("a");
2227
+ r.download = e.filename ?? "image.png", r.href = t.toDataURL("image/png"), document.body.appendChild(r), r.click(), document.body.removeChild(r);
2228
+ }
2229
+ /**
2230
+ * Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
2231
+ * The image will be displayed in the browser's console using CSS background images.
2232
+ * @param options - The options for logging the image, or the target to log
2233
+ * @param options.width - The width of the logged image preview in the console (in pixels)
2234
+ * @example
2235
+ * ```ts
2236
+ * // Basic usage
2237
+ * const sprite = new Sprite(texture);
2238
+ * renderer.extract.log(sprite);
2239
+ * ```
2240
+ * @see {@link ExtractSystem.canvas} For getting raw canvas output
2241
+ * @see {@link ExtractSystem.pixels} For raw pixel data
2242
+ * @category rendering
2243
+ * @advanced
2244
+ */
2245
+ log(e) {
2246
+ const t = e.width ?? 200;
2247
+ e = this._normalizeOptions(e);
2248
+ const r = this.canvas(e), s = r.toDataURL();
2249
+ console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);
2250
+ const a = [
2251
+ "font-size: 1px;",
2252
+ `padding: ${t}px 300px;`,
2253
+ `background: url(${s}) no-repeat;`,
2254
+ "background-size: contain;"
2255
+ ].join(" ");
2256
+ console.log("%c ", a);
2257
+ }
2258
+ destroy() {
2259
+ this._renderer = null;
2260
+ }
2261
+ };
2262
+ ue.extension = {
2263
+ type: [
2264
+ u.WebGLSystem,
2265
+ u.WebGPUSystem,
2266
+ u.CanvasSystem
2267
+ ],
2268
+ name: "extract"
2269
+ };
2270
+ ue.defaultImageOptions = {
2271
+ format: "png",
2272
+ quality: 1
2273
+ };
2274
+ let Ur = ue;
2275
+ class ce extends S {
2276
+ /**
2277
+ * Creates a RenderTexture. Pass `dynamic: true` in options to allow resizing after creation.
2278
+ * @param options - Options for the RenderTexture, including width, height, textureOptions, and dynamic.
2279
+ * @returns A new RenderTexture instance.
2280
+ * @example
2281
+ * const textureOptions = { defaultAnchor: { x: 0.5, y: 0.5 } };
2282
+ * const rt = RenderTexture.create({ width: 100, height: 100, dynamic: true, textureOptions });
2283
+ * rt.resize(500, 500);
2284
+ */
2285
+ static create(e) {
2286
+ const { dynamic: t, textureOptions: r, ...s } = e;
2287
+ return new ce({
2288
+ ...r,
2289
+ source: new I(s),
2290
+ dynamic: t ?? !1
2291
+ });
2292
+ }
2293
+ /**
2294
+ * Resizes the render texture.
2295
+ * @param width - The new width of the render texture.
2296
+ * @param height - The new height of the render texture.
2297
+ * @param resolution - The new resolution of the render texture.
2298
+ * @returns This texture.
2299
+ */
2300
+ resize(e, t, r) {
2301
+ return this.source.resize(e, t, r), this;
2302
+ }
2303
+ }
2304
+ const Gr = new F(), Ar = new ne(), Ir = [0, 0, 0, 0];
2305
+ class pt {
2306
+ constructor(e) {
2307
+ this._renderer = e;
2308
+ }
2309
+ /**
2310
+ * Creates a texture from a display object that can be used for creating sprites and other textures.
2311
+ * This is particularly useful for optimizing performance when a complex container needs to be reused.
2312
+ * @param options - Generate texture options or a container to convert to texture
2313
+ * @returns A new RenderTexture containing the rendered display object
2314
+ * @example
2315
+ * ```ts
2316
+ * // Basic usage with a container
2317
+ * const container = new Container();
2318
+ * container.addChild(
2319
+ * new Graphics()
2320
+ * .circle(0, 0, 50)
2321
+ * .fill('red')
2322
+ * );
2323
+ *
2324
+ * const texture = renderer.textureGenerator.generateTexture(container);
2325
+ *
2326
+ * // Advanced usage with options
2327
+ * const texture = renderer.textureGenerator.generateTexture({
2328
+ * target: container,
2329
+ * frame: new Rectangle(0, 0, 100, 100), // Specific region
2330
+ * resolution: 2, // High DPI
2331
+ * clearColor: '#ff0000', // Red background
2332
+ * antialias: true // Smooth edges
2333
+ * });
2334
+ *
2335
+ * // Create a sprite from the generated texture
2336
+ * const sprite = new Sprite(texture);
2337
+ *
2338
+ * // Clean up when done
2339
+ * texture.destroy(true);
2340
+ * ```
2341
+ * @see {@link GenerateTextureOptions} For detailed texture generation options
2342
+ * @see {@link RenderTexture} For the type of texture created
2343
+ * @category rendering
2344
+ */
2345
+ generateTexture(e) {
2346
+ var f;
2347
+ e instanceof O && (e = {
2348
+ target: e,
2349
+ frame: void 0,
2350
+ textureSourceOptions: {},
2351
+ resolution: void 0
2352
+ });
2353
+ const t = e.resolution || this._renderer.resolution, r = e.antialias || this._renderer.view.antialias, s = e.target;
2354
+ let a = e.clearColor;
2355
+ a ? a = Array.isArray(a) && a.length === 4 ? a : K.shared.setValue(a).toArray() : a = Ir;
2356
+ const i = ((f = e.frame) == null ? void 0 : f.copyTo(Gr)) || Gt(s, Ar).rectangle, o = e.defaultAnchor && {
2357
+ defaultAnchor: e.defaultAnchor
2358
+ };
2359
+ i.width = Math.max(i.width, 1 / t) | 0, i.height = Math.max(i.height, 1 / t) | 0;
2360
+ const l = ce.create({
2361
+ ...e.textureSourceOptions,
2362
+ width: i.width,
2363
+ height: i.height,
2364
+ resolution: t,
2365
+ antialias: r,
2366
+ textureOptions: o
2367
+ }), d = M.shared.translate(-i.x, -i.y);
2368
+ return this._renderer.render({
2369
+ container: s,
2370
+ transform: d,
2371
+ target: l,
2372
+ clearColor: a
2373
+ }), l.source.updateMipmaps(), l;
2374
+ }
2375
+ destroy() {
2376
+ this._renderer = null;
2377
+ }
2378
+ }
2379
+ pt.extension = {
2380
+ type: [
2381
+ u.WebGLSystem,
2382
+ u.WebGPUSystem,
2383
+ u.CanvasSystem
2384
+ ],
2385
+ name: "textureGenerator"
2386
+ };
2387
+ function Er(n) {
2388
+ let e = !1;
2389
+ for (const r in n)
2390
+ if (n[r] == null) {
2391
+ e = !0;
2392
+ break;
2393
+ }
2394
+ if (!e) return n;
2395
+ const t = /* @__PURE__ */ Object.create(null);
2396
+ for (const r in n) {
2397
+ const s = n[r];
2398
+ s && (t[r] = s);
2399
+ }
2400
+ return t;
2401
+ }
2402
+ function zr(n) {
2403
+ let e = 0;
2404
+ for (let t = 0; t < n.length; t++)
2405
+ n[t] == null ? e++ : n[t - e] = n[t];
2406
+ return n.length -= e, n;
2407
+ }
2408
+ const de = class mt {
2409
+ /**
2410
+ * Creates a new GCSystem instance.
2411
+ * @param renderer - The renderer this garbage collection system works for
2412
+ */
2413
+ constructor(e) {
2414
+ this._managedResources = [], this._managedResourceHashes = [], this._managedCollections = [], this._ready = !1, this._renderer = e;
2415
+ }
2416
+ /**
2417
+ * Initializes the garbage collection system with the provided options.
2418
+ * @param options - Configuration options
2419
+ */
2420
+ init(e) {
2421
+ e = { ...mt.defaultOptions, ...e }, this.maxUnusedTime = e.gcMaxUnusedTime, this._frequency = e.gcFrequency, this.enabled = e.gcActive, this.now = performance.now();
2422
+ }
2423
+ /**
2424
+ * Gets whether the garbage collection system is currently enabled.
2425
+ * @returns True if GC is enabled, false otherwise
2426
+ */
2427
+ get enabled() {
2428
+ return !!this._handler;
2429
+ }
2430
+ /**
2431
+ * Enables or disables the garbage collection system.
2432
+ * When enabled, schedules periodic cleanup of resources.
2433
+ * When disabled, cancels all scheduled cleanups.
2434
+ */
2435
+ set enabled(e) {
2436
+ this.enabled !== e && (e ? (this._handler = this._renderer.scheduler.repeat(
2437
+ () => {
2438
+ this._ready = !0;
2439
+ },
2440
+ this._frequency,
2441
+ !1
2442
+ ), this._collectionsHandler = this._renderer.scheduler.repeat(
2443
+ () => {
2444
+ for (const t of this._managedCollections) {
2445
+ const { context: r, collection: s, type: a } = t;
2446
+ a === "hash" ? r[s] = Er(r[s]) : r[s] = zr(r[s]);
2447
+ }
2448
+ },
2449
+ this._frequency
2450
+ )) : (this._renderer.scheduler.cancel(this._handler), this._renderer.scheduler.cancel(this._collectionsHandler), this._handler = 0, this._collectionsHandler = 0));
2451
+ }
2452
+ /**
2453
+ * Called before rendering. Updates the current timestamp.
2454
+ * @param options - The render options
2455
+ * @param options.container - The container to render
2456
+ */
2457
+ prerender({ container: e }) {
2458
+ this.now = performance.now(), e.renderGroup.gcTick = this._renderer.tick++, this._updateInstructionGCTick(e.renderGroup, e.renderGroup.gcTick);
2459
+ }
2460
+ /** Performs garbage collection after rendering. */
2461
+ postrender() {
2462
+ !this._ready || !this.enabled || (this.run(), this._ready = !1);
2463
+ }
2464
+ /**
2465
+ * Updates the GC tick counter for a render group and its children.
2466
+ * @param renderGroup - The render group to update
2467
+ * @param gcTick - The new tick value
2468
+ */
2469
+ _updateInstructionGCTick(e, t) {
2470
+ e.instructionSet.gcTick = t, e.gcTick = t;
2471
+ for (const r of e.renderGroupChildren)
2472
+ this._updateInstructionGCTick(r, t);
2473
+ }
2474
+ /**
2475
+ * Registers a collection for garbage collection tracking.
2476
+ * @param context - The object containing the collection
2477
+ * @param collection - The property name on context that holds the collection
2478
+ * @param type - The type of collection to track ('hash' or 'array')
2479
+ */
2480
+ addCollection(e, t, r) {
2481
+ this._managedCollections.push({
2482
+ context: e,
2483
+ collection: t,
2484
+ type: r
2485
+ });
2486
+ }
2487
+ /**
2488
+ * Registers a resource for garbage collection tracking.
2489
+ * @param resource - The resource to track
2490
+ * @param type - The type of resource to track
2491
+ */
2492
+ addResource(e, t) {
2493
+ var s, a;
2494
+ if (e._gcLastUsed !== -1) {
2495
+ e._gcLastUsed = this.now, (s = e._onTouch) == null || s.call(e, this.now);
2496
+ return;
2497
+ }
2498
+ const r = this._managedResources.length;
2499
+ e._gcData = {
2500
+ index: r,
2501
+ type: t
2502
+ }, e._gcLastUsed = this.now, (a = e._onTouch) == null || a.call(e, this.now), e.once("unload", this.removeResource, this), this._managedResources.push(e);
2503
+ }
2504
+ /**
2505
+ * Removes a resource from garbage collection tracking.
2506
+ * Call this when manually destroying a resource.
2507
+ * @param resource - The resource to stop tracking
2508
+ */
2509
+ removeResource(e) {
2510
+ const t = e._gcData;
2511
+ if (!t) return;
2512
+ const r = t.index, s = this._managedResources.length - 1;
2513
+ if (r !== s) {
2514
+ const a = this._managedResources[s];
2515
+ this._managedResources[r] = a, a._gcData.index = r;
2516
+ }
2517
+ this._managedResources.length--, e._gcData = null, e._gcLastUsed = -1;
2518
+ }
2519
+ /**
2520
+ * Registers a hash-based resource collection for garbage collection tracking.
2521
+ * Resources in the hash will be automatically tracked and cleaned up when unused.
2522
+ * @param context - The object containing the hash property
2523
+ * @param hash - The property name on context that holds the resource hash
2524
+ * @param type - The type of resources in the hash ('resource' or 'renderable')
2525
+ * @param priority - Processing priority (lower values are processed first)
2526
+ */
2527
+ addResourceHash(e, t, r, s = 0) {
2528
+ this._managedResourceHashes.push({
2529
+ context: e,
2530
+ hash: t,
2531
+ type: r,
2532
+ priority: s
2533
+ }), this._managedResourceHashes.sort((a, i) => a.priority - i.priority);
2534
+ }
2535
+ /**
2536
+ * Performs garbage collection by cleaning up unused resources.
2537
+ * Removes resources that haven't been used for longer than maxUnusedTime.
2538
+ */
2539
+ run() {
2540
+ const e = performance.now(), t = this._managedResourceHashes;
2541
+ for (const s of t)
2542
+ this.runOnHash(s, e);
2543
+ let r = 0;
2544
+ for (let s = 0; s < this._managedResources.length; s++) {
2545
+ const a = this._managedResources[s];
2546
+ r = this.runOnResource(a, e, r);
2547
+ }
2548
+ this._managedResources.length = r;
2549
+ }
2550
+ updateRenderableGCTick(e, t) {
2551
+ var a, i;
2552
+ const r = e.renderGroup ?? e.parentRenderGroup, s = ((a = r == null ? void 0 : r.instructionSet) == null ? void 0 : a.gcTick) ?? -1;
2553
+ ((r == null ? void 0 : r.gcTick) ?? 0) === s && (e._gcLastUsed = t, (i = e._onTouch) == null || i.call(e, t));
2554
+ }
2555
+ runOnResource(e, t, r) {
2556
+ const s = e._gcData;
2557
+ return s.type === "renderable" && this.updateRenderableGCTick(e, t), t - e._gcLastUsed < this.maxUnusedTime || !e.autoGarbageCollect ? (this._managedResources[r] = e, s.index = r, r++) : (e.unload(), e._gcData = null, e._gcLastUsed = -1, e.off("unload", this.removeResource, this)), r;
2558
+ }
2559
+ /**
2560
+ * Creates a clone of the hash, copying all non-null entries up to (but not including) the stop key.
2561
+ * @param hashValue - The original hash to clone from
2562
+ * @param stopKey - The key to stop at (exclusive)
2563
+ * @returns A new hash object with copied entries
2564
+ */
2565
+ _createHashClone(e, t) {
2566
+ const r = /* @__PURE__ */ Object.create(null);
2567
+ for (const s in e) {
2568
+ if (s === t) break;
2569
+ e[s] !== null && (r[s] = e[s]);
2570
+ }
2571
+ return r;
2572
+ }
2573
+ runOnHash(e, t) {
2574
+ var d;
2575
+ const { context: r, hash: s, type: a } = e, i = r[s];
2576
+ let o = null, l = 0;
2577
+ for (const f in i) {
2578
+ const c = i[f];
2579
+ if (c === null) {
2580
+ l++, l === 1e4 && !o && (o = this._createHashClone(i, f));
2581
+ continue;
2582
+ }
2583
+ if (c._gcLastUsed === -1) {
2584
+ c._gcLastUsed = t, (d = c._onTouch) == null || d.call(c, t), o && (o[f] = c);
2585
+ continue;
2586
+ }
2587
+ if (a === "renderable" && this.updateRenderableGCTick(c, t), !(t - c._gcLastUsed < this.maxUnusedTime) && c.autoGarbageCollect) {
2588
+ if (o || (l + 1 !== 1e4 ? (i[f] = null, l++) : o = this._createHashClone(i, f)), a === "renderable") {
2589
+ const g = c, m = g.renderGroup ?? g.parentRenderGroup;
2590
+ m && (m.structureDidChange = !0);
2591
+ }
2592
+ c.unload(), c._gcData = null, c._gcLastUsed = -1;
2593
+ } else o && (o[f] = c);
2594
+ }
2595
+ o && (r[s] = o);
2596
+ }
2597
+ /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
2598
+ destroy() {
2599
+ this.enabled = !1, this._managedResources.forEach((e) => {
2600
+ e.off("unload", this.removeResource, this);
2601
+ }), this._managedResources.length = 0, this._managedResourceHashes.length = 0, this._managedCollections.length = 0, this._renderer = null;
2602
+ }
2603
+ };
2604
+ de.extension = {
2605
+ type: [
2606
+ u.WebGLSystem,
2607
+ u.WebGPUSystem,
2608
+ u.CanvasSystem
2609
+ ],
2610
+ name: "gc",
2611
+ priority: 0
2612
+ };
2613
+ de.defaultOptions = {
2614
+ /** Enable/disable the garbage collector */
2615
+ gcActive: !0,
2616
+ /** Time in ms before an unused resource is collected (default 1 minute) */
2617
+ gcMaxUnusedTime: 6e4,
2618
+ /** How often to run garbage collection in ms (default 30 seconds) */
2619
+ gcFrequency: 3e4
2620
+ };
2621
+ let Dr = de;
2622
+ class xt {
2623
+ constructor(e) {
2624
+ this._stackIndex = 0, this._globalUniformDataStack = [], this._uniformsPool = [], this._activeUniforms = [], this._bindGroupPool = [], this._activeBindGroups = [], this._renderer = e;
2625
+ }
2626
+ reset() {
2627
+ this._stackIndex = 0;
2628
+ for (let e = 0; e < this._activeUniforms.length; e++)
2629
+ this._uniformsPool.push(this._activeUniforms[e]);
2630
+ for (let e = 0; e < this._activeBindGroups.length; e++)
2631
+ this._bindGroupPool.push(this._activeBindGroups[e]);
2632
+ this._activeUniforms.length = 0, this._activeBindGroups.length = 0;
2633
+ }
2634
+ start(e) {
2635
+ this.reset(), this.push(e);
2636
+ }
2637
+ bind({
2638
+ size: e,
2639
+ projectionMatrix: t,
2640
+ worldTransformMatrix: r,
2641
+ worldColor: s,
2642
+ offset: a
2643
+ }) {
2644
+ const i = this._renderer.renderTarget.renderTarget, o = this._stackIndex ? this._globalUniformDataStack[this._stackIndex - 1] : {
2645
+ worldTransformMatrix: new M(),
2646
+ worldColor: 4294967295,
2647
+ offset: new At()
2648
+ }, l = {
2649
+ projectionMatrix: t || this._renderer.renderTarget.projectionMatrix,
2650
+ resolution: e || i.size,
2651
+ worldTransformMatrix: r || o.worldTransformMatrix,
2652
+ worldColor: s || o.worldColor,
2653
+ offset: a || o.offset,
2654
+ bindGroup: null
2655
+ }, d = this._uniformsPool.pop() || this._createUniforms();
2656
+ this._activeUniforms.push(d);
2657
+ const f = d.uniforms;
2658
+ f.uProjectionMatrix = l.projectionMatrix, f.uResolution = l.resolution, f.uWorldTransformMatrix.copyFrom(l.worldTransformMatrix), f.uWorldTransformMatrix.tx -= l.offset.x, f.uWorldTransformMatrix.ty -= l.offset.y, It(
2659
+ l.worldColor,
2660
+ f.uWorldColorAlpha,
2661
+ 0
2662
+ ), d.update();
2663
+ let c;
2664
+ this._renderer.renderPipes.uniformBatch ? c = this._renderer.renderPipes.uniformBatch.getUniformBindGroup(d, !1) : (c = this._bindGroupPool.pop() || new Et(), this._activeBindGroups.push(c), c.setResource(d, 0)), l.bindGroup = c, this._currentGlobalUniformData = l;
2665
+ }
2666
+ push(e) {
2667
+ this.bind(e), this._globalUniformDataStack[this._stackIndex++] = this._currentGlobalUniformData;
2668
+ }
2669
+ pop() {
2670
+ this._currentGlobalUniformData = this._globalUniformDataStack[--this._stackIndex - 1], this._renderer.type === ae.WEBGL && this._currentGlobalUniformData.bindGroup.resources[0].update();
2671
+ }
2672
+ get bindGroup() {
2673
+ return this._currentGlobalUniformData.bindGroup;
2674
+ }
2675
+ get globalUniformData() {
2676
+ return this._currentGlobalUniformData;
2677
+ }
2678
+ get uniformGroup() {
2679
+ return this._currentGlobalUniformData.bindGroup.resources[0];
2680
+ }
2681
+ _createUniforms() {
2682
+ return new re({
2683
+ uProjectionMatrix: { value: new M(), type: "mat3x3<f32>" },
2684
+ uWorldTransformMatrix: { value: new M(), type: "mat3x3<f32>" },
2685
+ // TODO - someone smart - set this to be a unorm8x4 rather than a vec4<f32>
2686
+ uWorldColorAlpha: { value: new Float32Array(4), type: "vec4<f32>" },
2687
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
2688
+ }, {
2689
+ isStatic: !0
2690
+ });
2691
+ }
2692
+ destroy() {
2693
+ this._renderer = null, this._globalUniformDataStack.length = 0, this._uniformsPool.length = 0, this._activeUniforms.length = 0, this._bindGroupPool.length = 0, this._activeBindGroups.length = 0, this._currentGlobalUniformData = null;
2694
+ }
2695
+ }
2696
+ xt.extension = {
2697
+ type: [
2698
+ u.WebGLSystem,
2699
+ u.WebGPUSystem,
2700
+ u.CanvasSystem
2701
+ ],
2702
+ name: "globalUniforms"
2703
+ };
2704
+ let Lr = 1;
2705
+ class gt {
2706
+ constructor() {
2707
+ this._tasks = [], this._offset = 0;
2708
+ }
2709
+ /** Initializes the scheduler system and starts the ticker. */
2710
+ init() {
2711
+ ve.system.add(this._update, this);
2712
+ }
2713
+ /**
2714
+ * Schedules a repeating task.
2715
+ * @param func - The function to execute.
2716
+ * @param duration - The interval duration in milliseconds.
2717
+ * @param useOffset - this will spread out tasks so that they do not all run at the same time
2718
+ * @returns The unique identifier for the scheduled task.
2719
+ */
2720
+ repeat(e, t, r = !0) {
2721
+ const s = Lr++;
2722
+ let a = 0;
2723
+ return r && (this._offset += 1e3, a = this._offset), this._tasks.push({
2724
+ func: e,
2725
+ duration: t,
2726
+ start: performance.now(),
2727
+ offset: a,
2728
+ last: performance.now(),
2729
+ repeat: !0,
2730
+ id: s
2731
+ }), s;
2732
+ }
2733
+ /**
2734
+ * Cancels a scheduled task.
2735
+ * @param id - The unique identifier of the task to cancel.
2736
+ */
2737
+ cancel(e) {
2738
+ for (let t = 0; t < this._tasks.length; t++)
2739
+ if (this._tasks[t].id === e) {
2740
+ this._tasks.splice(t, 1);
2741
+ return;
2742
+ }
2743
+ }
2744
+ /**
2745
+ * Updates and executes the scheduled tasks.
2746
+ * @private
2747
+ */
2748
+ _update() {
2749
+ const e = performance.now();
2750
+ for (let t = 0; t < this._tasks.length; t++) {
2751
+ const r = this._tasks[t];
2752
+ if (e - r.offset - r.last >= r.duration) {
2753
+ const s = e - r.start;
2754
+ r.func(s), r.last = e;
2755
+ }
2756
+ }
2757
+ }
2758
+ /**
2759
+ * Destroys the scheduler system and removes all tasks.
2760
+ * @internal
2761
+ */
2762
+ destroy() {
2763
+ ve.system.remove(this._update, this), this._tasks.length = 0;
2764
+ }
2765
+ }
2766
+ gt.extension = {
2767
+ type: [
2768
+ u.WebGLSystem,
2769
+ u.WebGPUSystem,
2770
+ u.CanvasSystem
2771
+ ],
2772
+ name: "scheduler",
2773
+ priority: 0
2774
+ };
2775
+ let ze = !1;
2776
+ function Hr(n) {
2777
+ if (!ze) {
2778
+ if (ie.get().getNavigator().userAgent.toLowerCase().indexOf("chrome") > -1) {
2779
+ const e = [
2780
+ `%c %c %c %c %c PixiJS %c v${ye} (${n}) http://www.pixijs.com/
2781
+
2782
+ `,
2783
+ "background: #E72264; padding:5px 0;",
2784
+ "background: #6CA2EA; padding:5px 0;",
2785
+ "background: #B5D33D; padding:5px 0;",
2786
+ "background: #FED23F; padding:5px 0;",
2787
+ "color: #FFFFFF; background: #E72264; padding:5px 0;",
2788
+ "color: #E72264; background: #FFFFFF; padding:5px 0;"
2789
+ ];
2790
+ globalThis.console.log(...e);
2791
+ } else globalThis.console && globalThis.console.log(`PixiJS ${ye} - ${n} - http://www.pixijs.com/`);
2792
+ ze = !0;
2793
+ }
2794
+ }
2795
+ class he {
2796
+ constructor(e) {
2797
+ this._renderer = e;
2798
+ }
2799
+ /**
2800
+ * It all starts here! This initiates every system, passing in the options for any system by name.
2801
+ * @param options - the config for the renderer and all its systems
2802
+ */
2803
+ init(e) {
2804
+ if (e.hello) {
2805
+ let t = this._renderer.name;
2806
+ this._renderer.type === ae.WEBGL && (t += ` ${this._renderer.context.webGLVersion}`), Hr(t);
2807
+ }
2808
+ }
2809
+ }
2810
+ he.extension = {
2811
+ type: [
2812
+ u.WebGLSystem,
2813
+ u.WebGPUSystem,
2814
+ u.CanvasSystem
2815
+ ],
2816
+ name: "hello",
2817
+ priority: -2
2818
+ };
2819
+ he.defaultOptions = {
2820
+ /** {@link WebGLOptions.hello} */
2821
+ hello: !1
2822
+ };
2823
+ const fe = class _t {
2824
+ /**
2825
+ * Creates a new RenderableGCSystem instance.
2826
+ * @param renderer - The renderer this garbage collection system works for
2827
+ */
2828
+ constructor(e) {
2829
+ this._renderer = e;
2830
+ }
2831
+ /**
2832
+ * Initializes the garbage collection system with the provided options.
2833
+ * @param options - Configuration options for the renderer
2834
+ */
2835
+ init(e) {
2836
+ e = { ..._t.defaultOptions, ...e }, this.maxUnusedTime = e.renderableGCMaxUnusedTime;
2837
+ }
2838
+ /**
2839
+ * Gets whether the garbage collection system is currently enabled.
2840
+ * @returns True if GC is enabled, false otherwise
2841
+ */
2842
+ get enabled() {
2843
+ return T("8.15.0", "RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."), this._renderer.gc.enabled;
2844
+ }
2845
+ /**
2846
+ * Enables or disables the garbage collection system.
2847
+ * When enabled, schedules periodic cleanup of resources.
2848
+ * When disabled, cancels all scheduled cleanups.
2849
+ */
2850
+ set enabled(e) {
2851
+ T("8.15.0", "RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."), this._renderer.gc.enabled = e;
2852
+ }
2853
+ /**
2854
+ * Adds a hash table to be managed by the garbage collector.
2855
+ * @param context - The object containing the hash table
2856
+ * @param hash - The property name of the hash table
2857
+ */
2858
+ addManagedHash(e, t) {
2859
+ T("8.15.0", "RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead."), this._renderer.gc.addCollection(e, t, "hash");
2860
+ }
2861
+ /**
2862
+ * Adds an array to be managed by the garbage collector.
2863
+ * @param context - The object containing the array
2864
+ * @param hash - The property name of the array
2865
+ */
2866
+ addManagedArray(e, t) {
2867
+ T("8.15.0", "RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead."), this._renderer.gc.addCollection(e, t, "array");
2868
+ }
2869
+ /**
2870
+ * Starts tracking a renderable for garbage collection.
2871
+ * @param _renderable - The renderable to track
2872
+ * @deprecated since 8.15.0
2873
+ */
2874
+ addRenderable(e) {
2875
+ T("8.15.0", "RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead."), this._renderer.gc.addResource(e, "renderable");
2876
+ }
2877
+ /**
2878
+ * Performs garbage collection by cleaning up unused renderables.
2879
+ * Removes renderables that haven't been used for longer than maxUnusedTime.
2880
+ */
2881
+ run() {
2882
+ T("8.15.0", "RenderableGCSystem.run is deprecated, please use the GCSystem instead."), this._renderer.gc.run();
2883
+ }
2884
+ /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
2885
+ destroy() {
2886
+ this._renderer = null;
2887
+ }
2888
+ };
2889
+ fe.extension = {
2890
+ type: [
2891
+ u.WebGLSystem,
2892
+ u.WebGPUSystem,
2893
+ u.CanvasSystem
2894
+ ],
2895
+ name: "renderableGC",
2896
+ priority: 0
2897
+ };
2898
+ fe.defaultOptions = {
2899
+ /** Enable/disable the garbage collector */
2900
+ renderableGCActive: !0,
2901
+ /** Time in ms before an unused resource is collected (default 1 minute) */
2902
+ renderableGCMaxUnusedTime: 6e4,
2903
+ /** How often to run garbage collection in ms (default 30 seconds) */
2904
+ renderableGCFrequency: 3e4
2905
+ };
2906
+ let Or = fe;
2907
+ const pe = class L {
2908
+ /**
2909
+ * Frame count since started.
2910
+ * @readonly
2911
+ * @deprecated since 8.15.0
2912
+ */
2913
+ get count() {
2914
+ return this._renderer.tick;
2915
+ }
2916
+ /**
2917
+ * Frame count since last garbage collection.
2918
+ * @readonly
2919
+ * @deprecated since 8.15.0
2920
+ */
2921
+ get checkCount() {
2922
+ return this._checkCount;
2923
+ }
2924
+ set checkCount(e) {
2925
+ T("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead."), this._checkCount = e;
2926
+ }
2927
+ /**
2928
+ * Maximum idle frames before a texture is destroyed by garbage collection.
2929
+ * @see TextureGCSystem.defaultMaxIdle
2930
+ * @deprecated since 8.15.0
2931
+ */
2932
+ get maxIdle() {
2933
+ return this._renderer.gc.maxUnusedTime / 1e3 * 60;
2934
+ }
2935
+ set maxIdle(e) {
2936
+ T("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead."), this._renderer.gc.maxUnusedTime = e / 60 * 1e3;
2937
+ }
2938
+ /**
2939
+ * Frames between two garbage collections.
2940
+ * @see TextureGCSystem.defaultCheckCountMax
2941
+ * @deprecated since 8.15.0
2942
+ */
2943
+ // eslint-disable-next-line dot-notation
2944
+ get checkCountMax() {
2945
+ return Math.floor(this._renderer.gc._frequency / 1e3);
2946
+ }
2947
+ set checkCountMax(e) {
2948
+ T("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead.");
2949
+ }
2950
+ /**
2951
+ * Current garbage collection mode.
2952
+ * @see TextureGCSystem.defaultMode
2953
+ * @deprecated since 8.15.0
2954
+ */
2955
+ get active() {
2956
+ return this._renderer.gc.enabled;
2957
+ }
2958
+ set active(e) {
2959
+ T("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead."), this._renderer.gc.enabled = e;
2960
+ }
2961
+ /** @param renderer - The renderer this System works for. */
2962
+ constructor(e) {
2963
+ this._renderer = e, this._checkCount = 0;
2964
+ }
2965
+ init(e) {
2966
+ e.textureGCActive !== L.defaultOptions.textureGCActive && (this.active = e.textureGCActive), e.textureGCMaxIdle !== L.defaultOptions.textureGCMaxIdle && (this.maxIdle = e.textureGCMaxIdle), e.textureGCCheckCountMax !== L.defaultOptions.textureGCCheckCountMax && (this.checkCountMax = e.textureGCCheckCountMax);
2967
+ }
2968
+ /**
2969
+ * Checks to see when the last time a texture was used.
2970
+ * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2971
+ * @deprecated since 8.15.0
2972
+ */
2973
+ run() {
2974
+ T("8.15.0", "TextureGCSystem.run is deprecated, please use the GCSystem instead."), this._renderer.gc.run();
2975
+ }
2976
+ destroy() {
2977
+ this._renderer = null;
2978
+ }
2979
+ };
2980
+ pe.extension = {
2981
+ type: [
2982
+ u.WebGLSystem,
2983
+ u.WebGPUSystem
2984
+ ],
2985
+ name: "textureGC"
2986
+ };
2987
+ pe.defaultOptions = {
2988
+ /**
2989
+ * If set to true, this will enable the garbage collector on the GPU.
2990
+ * @default true
2991
+ */
2992
+ textureGCActive: !0,
2993
+ /**
2994
+ * @deprecated since 8.3.0
2995
+ * @see {@link TextureGCSystemOptions.textureGCMaxIdle}
2996
+ */
2997
+ textureGCAMaxIdle: null,
2998
+ /**
2999
+ * The maximum idle frames before a texture is destroyed by garbage collection.
3000
+ * @default 60 * 60
3001
+ */
3002
+ textureGCMaxIdle: 3600,
3003
+ /**
3004
+ * Frames between two garbage collections.
3005
+ * @default 600
3006
+ */
3007
+ textureGCCheckCountMax: 600
3008
+ };
3009
+ let Fr = pe;
3010
+ const bt = class vt {
3011
+ /**
3012
+ * @param [descriptor] - Options for creating a render target.
3013
+ */
3014
+ constructor(e = {}) {
3015
+ if (this.uid = De("renderTarget"), this.colorTextures = [], this.dirtyId = 0, this.isRoot = !1, this._size = new Float32Array(2), this._managedColorTextures = !1, e = { ...vt.defaultOptions, ...e }, this.stencil = e.stencil, this.depth = e.depth, this.isRoot = e.isRoot, typeof e.colorTextures == "number") {
3016
+ this._managedColorTextures = !0;
3017
+ for (let t = 0; t < e.colorTextures; t++)
3018
+ this.colorTextures.push(
3019
+ new I({
3020
+ width: e.width,
3021
+ height: e.height,
3022
+ resolution: e.resolution,
3023
+ antialias: e.antialias
3024
+ })
3025
+ );
3026
+ } else {
3027
+ this.colorTextures = [...e.colorTextures.map((r) => r.source)];
3028
+ const t = this.colorTexture.source;
3029
+ this.resize(t.width, t.height, t._resolution);
3030
+ }
3031
+ this.colorTexture.source.on("resize", this.onSourceResize, this), (e.depthStencilTexture || this.stencil) && (e.depthStencilTexture instanceof S || e.depthStencilTexture instanceof I ? this.depthStencilTexture = e.depthStencilTexture.source : this.ensureDepthStencilTexture());
3032
+ }
3033
+ get size() {
3034
+ const e = this._size;
3035
+ return e[0] = this.pixelWidth, e[1] = this.pixelHeight, e;
3036
+ }
3037
+ get width() {
3038
+ return this.colorTexture.source.width;
3039
+ }
3040
+ get height() {
3041
+ return this.colorTexture.source.height;
3042
+ }
3043
+ get pixelWidth() {
3044
+ return this.colorTexture.source.pixelWidth;
3045
+ }
3046
+ get pixelHeight() {
3047
+ return this.colorTexture.source.pixelHeight;
3048
+ }
3049
+ get resolution() {
3050
+ return this.colorTexture.source._resolution;
3051
+ }
3052
+ get colorTexture() {
3053
+ return this.colorTextures[0];
3054
+ }
3055
+ onSourceResize(e) {
3056
+ this.resize(e.width, e.height, e._resolution, !0);
3057
+ }
3058
+ /**
3059
+ * This will ensure a depthStencil texture is created for this render target.
3060
+ * Most likely called by the mask system to make sure we have stencil buffer added.
3061
+ * @internal
3062
+ */
3063
+ ensureDepthStencilTexture() {
3064
+ this.depthStencilTexture || (this.depthStencilTexture = new I({
3065
+ width: this.width,
3066
+ height: this.height,
3067
+ resolution: this.resolution,
3068
+ format: "depth24plus-stencil8",
3069
+ autoGenerateMipmaps: !1,
3070
+ antialias: !1,
3071
+ mipLevelCount: 1
3072
+ // sampleCount: handled by the render target system..
3073
+ }));
3074
+ }
3075
+ resize(e, t, r = this.resolution, s = !1) {
3076
+ this.dirtyId++, this.colorTextures.forEach((a, i) => {
3077
+ s && i === 0 || a.source.resize(e, t, r);
3078
+ }), this.depthStencilTexture && this.depthStencilTexture.source.resize(e, t, r);
3079
+ }
3080
+ destroy() {
3081
+ this.colorTexture.source.off("resize", this.onSourceResize, this), this._managedColorTextures && this.colorTextures.forEach((e) => {
3082
+ e.destroy();
3083
+ }), this.depthStencilTexture && (this.depthStencilTexture.destroy(), delete this.depthStencilTexture);
3084
+ }
3085
+ };
3086
+ bt.defaultOptions = {
3087
+ /** the width of the RenderTarget */
3088
+ width: 0,
3089
+ /** the height of the RenderTarget */
3090
+ height: 0,
3091
+ /** the resolution of the RenderTarget */
3092
+ resolution: 1,
3093
+ /** an array of textures, or a number indicating how many color textures there should be */
3094
+ colorTextures: 1,
3095
+ /** should this render target have a stencil buffer? */
3096
+ stencil: !1,
3097
+ /** should this render target have a depth buffer? */
3098
+ depth: !1,
3099
+ /** should this render target be antialiased? */
3100
+ antialias: !1,
3101
+ // save on perf by default!
3102
+ /** is this a root element, true if this is gl context owners render target */
3103
+ isRoot: !1
3104
+ };
3105
+ let ee = bt;
3106
+ const w = /* @__PURE__ */ new Map();
3107
+ Le.register(w);
3108
+ function yt(n, e) {
3109
+ if (!w.has(n)) {
3110
+ const t = new S({
3111
+ source: new X({
3112
+ resource: n,
3113
+ ...e
3114
+ })
3115
+ }), r = () => {
3116
+ w.get(n) === t && w.delete(n);
3117
+ };
3118
+ t.once("destroy", r), t.source.once("destroy", r), w.set(n, t);
3119
+ }
3120
+ return w.get(n);
3121
+ }
3122
+ const me = class Tt {
3123
+ /**
3124
+ * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.
3125
+ * This is only supported for HTMLCanvasElement and will be ignored if the canvas is an OffscreenCanvas.
3126
+ * @type {boolean}
3127
+ */
3128
+ get autoDensity() {
3129
+ return this.texture.source.autoDensity;
3130
+ }
3131
+ set autoDensity(e) {
3132
+ this.texture.source.autoDensity = e;
3133
+ }
3134
+ /** The resolution / device pixel ratio of the renderer. */
3135
+ get resolution() {
3136
+ return this.texture.source._resolution;
3137
+ }
3138
+ set resolution(e) {
3139
+ this.texture.source.resize(
3140
+ this.texture.source.width,
3141
+ this.texture.source.height,
3142
+ e
3143
+ );
3144
+ }
3145
+ /**
3146
+ * initiates the view system
3147
+ * @param options - the options for the view
3148
+ */
3149
+ init(e) {
3150
+ e = {
3151
+ ...Tt.defaultOptions,
3152
+ ...e
3153
+ }, e.view && (T(zt, "ViewSystem.view has been renamed to ViewSystem.canvas"), e.canvas = e.view), this.screen = new F(0, 0, e.width, e.height), this.canvas = e.canvas || ie.get().createCanvas(), this.antialias = !!e.antialias, this.texture = yt(this.canvas, e), this.renderTarget = new ee({
3154
+ colorTextures: [this.texture],
3155
+ depth: !!e.depth,
3156
+ isRoot: !0
3157
+ }), this.texture.source.transparent = e.backgroundAlpha < 1, this.resolution = e.resolution;
3158
+ }
3159
+ /**
3160
+ * Resizes the screen and canvas to the specified dimensions.
3161
+ * @param desiredScreenWidth - The new width of the screen.
3162
+ * @param desiredScreenHeight - The new height of the screen.
3163
+ * @param resolution
3164
+ */
3165
+ resize(e, t, r) {
3166
+ this.texture.source.resize(e, t, r), this.screen.width = this.texture.frame.width, this.screen.height = this.texture.frame.height;
3167
+ }
3168
+ /**
3169
+ * Destroys this System and optionally removes the canvas from the dom.
3170
+ * @param {options | false} options - The options for destroying the view, or "false".
3171
+ * @example
3172
+ * viewSystem.destroy();
3173
+ * viewSystem.destroy(true);
3174
+ * viewSystem.destroy({ removeView: true });
3175
+ */
3176
+ destroy(e = !1) {
3177
+ (typeof e == "boolean" ? e : !!(e != null && e.removeView)) && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas), this.texture.destroy();
3178
+ }
3179
+ };
3180
+ me.extension = {
3181
+ type: [
3182
+ u.WebGLSystem,
3183
+ u.WebGPUSystem,
3184
+ u.CanvasSystem
3185
+ ],
3186
+ name: "view",
3187
+ priority: 0
3188
+ };
3189
+ me.defaultOptions = {
3190
+ /**
3191
+ * {@link WebGLOptions.width}
3192
+ * @default 800
3193
+ */
3194
+ width: 800,
3195
+ /**
3196
+ * {@link WebGLOptions.height}
3197
+ * @default 600
3198
+ */
3199
+ height: 600,
3200
+ /**
3201
+ * {@link WebGLOptions.autoDensity}
3202
+ * @default false
3203
+ */
3204
+ autoDensity: !1,
3205
+ /**
3206
+ * {@link WebGLOptions.antialias}
3207
+ * @default false
3208
+ */
3209
+ antialias: !1
3210
+ };
3211
+ let Wr = me;
3212
+ const qr = [
3213
+ wr,
3214
+ xt,
3215
+ he,
3216
+ Wr,
3217
+ dt,
3218
+ Dr,
3219
+ Fr,
3220
+ pt,
3221
+ Ur,
3222
+ Dt,
3223
+ Or,
3224
+ gt
3225
+ ], Qr = [
3226
+ lt,
3227
+ tt,
3228
+ ot,
3229
+ it,
3230
+ rt,
3231
+ nt,
3232
+ st,
3233
+ at
3234
+ ];
3235
+ function $r(n, e, t, r, s, a) {
3236
+ const i = a ? 1 : -1;
3237
+ return n.identity(), n.a = 1 / r * 2, n.d = i * (1 / s * 2), n.tx = -1 - e * n.a, n.ty = -i - t * n.d, n;
3238
+ }
3239
+ function Vr(n) {
3240
+ const e = n.colorTexture.source.resource;
3241
+ return globalThis.HTMLCanvasElement && e instanceof HTMLCanvasElement && document.body.contains(e);
3242
+ }
3243
+ class Yr {
3244
+ constructor(e) {
3245
+ this.rootViewPort = new F(), this.viewport = new F(), this.mipLevel = 0, this.layer = 0, this.onRenderTargetChange = new Lt("onRenderTargetChange"), this.projectionMatrix = new M(), this.defaultClearColor = [0, 0, 0, 0], this._renderSurfaceToRenderTargetHash = /* @__PURE__ */ new Map(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null), this._renderTargetStack = [], this._renderer = e, e.gc.addCollection(this, "_gpuRenderTargetHash", "hash");
3246
+ }
3247
+ /** called when dev wants to finish a render pass */
3248
+ finishRenderPass() {
3249
+ this.adaptor.finishRenderPass(this.renderTarget);
3250
+ }
3251
+ /**
3252
+ * called when the renderer starts to render a scene.
3253
+ * @param options
3254
+ * @param options.target - the render target to render to
3255
+ * @param options.clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
3256
+ * @param options.clearColor - the color to clear to
3257
+ * @param options.frame - the frame to render to
3258
+ * @param options.mipLevel - the mip level to render to
3259
+ * @param options.layer - The layer of the render target to render to. Used for array or 3D textures, or when rendering
3260
+ * to a specific layer of a layered render target. Optional.
3261
+ */
3262
+ renderStart({
3263
+ target: e,
3264
+ clear: t,
3265
+ clearColor: r,
3266
+ frame: s,
3267
+ mipLevel: a,
3268
+ layer: i
3269
+ }) {
3270
+ var o, l;
3271
+ this._renderTargetStack.length = 0, this.push(
3272
+ e,
3273
+ t,
3274
+ r,
3275
+ s,
3276
+ a ?? 0,
3277
+ i ?? 0
3278
+ ), this.rootViewPort.copyFrom(this.viewport), this.rootRenderTarget = this.renderTarget, this.renderingToScreen = Vr(this.rootRenderTarget), (l = (o = this.adaptor).prerender) == null || l.call(o, this.rootRenderTarget);
3279
+ }
3280
+ postrender() {
3281
+ var e, t;
3282
+ (t = (e = this.adaptor).postrender) == null || t.call(e, this.rootRenderTarget);
3283
+ }
3284
+ /**
3285
+ * Binding a render surface! This is the main function of the render target system.
3286
+ * It will take the RenderSurface (which can be a texture, canvas, or render target) and bind it to the renderer.
3287
+ * Once bound all draw calls will be rendered to the render surface.
3288
+ *
3289
+ * If a frame is not provided and the render surface is a {@link Texture}, the frame of the texture will be used.
3290
+ *
3291
+ * IMPORTANT:
3292
+ * - `frame` is treated as **base mip (mip 0) pixel space**.
3293
+ * - When `mipLevel > 0`, the viewport derived from `frame` is scaled by \(2^{mipLevel}\) and clamped to the
3294
+ * mip dimensions. This keeps "render the same region" semantics consistent across mip levels.
3295
+ * - When `renderSurface` is a {@link Texture}, `renderer.render({ container, target: texture, mipLevel })` will
3296
+ * render into
3297
+ * the underlying {@link TextureSource} (Pixi will create/use a {@link RenderTarget} for the source) using the
3298
+ * texture's frame to define the region (in mip 0 space).
3299
+ * @param renderSurface - the render surface to bind
3300
+ * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
3301
+ * @param clearColor - the color to clear to
3302
+ * @param frame - the frame to render to
3303
+ * @param mipLevel - the mip level to render to
3304
+ * @param layer - the layer (or slice) of the render surface to render to. For array textures,
3305
+ * 3D textures, or cubemaps, this specifies the target layer or face. Defaults to 0 (the first layer/face).
3306
+ * Ignored for surfaces that do not support layers.
3307
+ * @returns the render target that was bound
3308
+ */
3309
+ bind(e, t = !0, r, s, a = 0, i = 0) {
3310
+ const o = this.getRenderTarget(e), l = this.renderTarget !== o;
3311
+ this.renderTarget = o, this.renderSurface = e;
3312
+ const d = this.getGpuRenderTarget(o);
3313
+ (o.pixelWidth !== d.width || o.pixelHeight !== d.height) && (this.adaptor.resizeGpuRenderTarget(o), d.width = o.pixelWidth, d.height = o.pixelHeight);
3314
+ const f = o.colorTexture, c = this.viewport, x = f.arrayLayerCount || 1;
3315
+ if ((i | 0) !== i && (i |= 0), i < 0 || i >= x)
3316
+ throw new Error(`[RenderTargetSystem] layer ${i} is out of bounds (arrayLayerCount=${x}).`);
3317
+ this.mipLevel = a | 0, this.layer = i | 0;
3318
+ const g = Math.max(f.pixelWidth >> a, 1), m = Math.max(f.pixelHeight >> a, 1);
3319
+ if (!s && e instanceof S && (s = e.frame), s) {
3320
+ const v = f._resolution, _ = 1 << Math.max(a | 0, 0), h = s.x * v + 0.5 | 0, C = s.y * v + 0.5 | 0, p = s.width * v + 0.5 | 0, y = s.height * v + 0.5 | 0;
3321
+ let b = Math.floor(h / _), P = Math.floor(C / _), $ = Math.ceil(p / _), V = Math.ceil(y / _);
3322
+ b = Math.min(Math.max(b, 0), g - 1), P = Math.min(Math.max(P, 0), m - 1), $ = Math.min(Math.max($, 1), g - b), V = Math.min(Math.max(V, 1), m - P), c.x = b, c.y = P, c.width = $, c.height = V;
3323
+ } else
3324
+ c.x = 0, c.y = 0, c.width = g, c.height = m;
3325
+ return $r(
3326
+ this.projectionMatrix,
3327
+ 0,
3328
+ 0,
3329
+ c.width / f.resolution,
3330
+ c.height / f.resolution,
3331
+ !o.isRoot
3332
+ ), this.adaptor.startRenderPass(o, t, r, c, a, i), l && this.onRenderTargetChange.emit(o), o;
3333
+ }
3334
+ clear(e, t = Y.ALL, r, s = this.mipLevel, a = this.layer) {
3335
+ t && (e && (e = this.getRenderTarget(e)), this.adaptor.clear(
3336
+ e || this.renderTarget,
3337
+ t,
3338
+ r,
3339
+ this.viewport,
3340
+ s,
3341
+ a
3342
+ ));
3343
+ }
3344
+ contextChange() {
3345
+ this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
3346
+ }
3347
+ /**
3348
+ * Push a render surface to the renderer. This will bind the render surface to the renderer,
3349
+ * @param renderSurface - the render surface to push
3350
+ * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
3351
+ * @param clearColor - the color to clear to
3352
+ * @param frame - the frame to use when rendering to the render surface
3353
+ * @param mipLevel - the mip level to render to
3354
+ * @param layer - The layer of the render surface to render to. For array textures or cube maps, this specifies
3355
+ * which layer or face to target. Defaults to 0 (the first layer).
3356
+ */
3357
+ push(e, t = Y.ALL, r, s, a = 0, i = 0) {
3358
+ const o = this.bind(e, t, r, s, a, i);
3359
+ return this._renderTargetStack.push({
3360
+ renderTarget: o,
3361
+ frame: s,
3362
+ mipLevel: a,
3363
+ layer: i
3364
+ }), o;
3365
+ }
3366
+ /** Pops the current render target from the renderer and restores the previous render target. */
3367
+ pop() {
3368
+ this._renderTargetStack.pop();
3369
+ const e = this._renderTargetStack[this._renderTargetStack.length - 1];
3370
+ this.bind(
3371
+ e.renderTarget,
3372
+ !1,
3373
+ null,
3374
+ e.frame,
3375
+ e.mipLevel,
3376
+ e.layer
3377
+ );
3378
+ }
3379
+ /**
3380
+ * Gets the render target from the provide render surface. Eg if its a texture,
3381
+ * it will return the render target for the texture.
3382
+ * If its a render target, it will return the same render target.
3383
+ * @param renderSurface - the render surface to get the render target for
3384
+ * @returns the render target for the render surface
3385
+ */
3386
+ getRenderTarget(e) {
3387
+ return e.isTexture && (e = e.source), this._renderSurfaceToRenderTargetHash.get(e) ?? this._initRenderTarget(e);
3388
+ }
3389
+ /**
3390
+ * Copies a render surface to another texture.
3391
+ *
3392
+ * NOTE:
3393
+ * for sourceRenderSurfaceTexture, The render target must be something that is written too by the renderer
3394
+ *
3395
+ * The following is not valid:
3396
+ * @example
3397
+ * const canvas = document.createElement('canvas')
3398
+ * canvas.width = 200;
3399
+ * canvas.height = 200;
3400
+ *
3401
+ * const ctx = canvas2.getContext('2d')!
3402
+ * ctx.fillStyle = 'red'
3403
+ * ctx.fillRect(0, 0, 200, 200);
3404
+ *
3405
+ * const texture = RenderTexture.create({
3406
+ * width: 200,
3407
+ * height: 200,
3408
+ * })
3409
+ * const renderTarget = renderer.renderTarget.getRenderTarget(canvas2);
3410
+ *
3411
+ * renderer.renderTarget.copyToTexture(renderTarget,texture, {x:0,y:0},{width:200,height:200},{x:0,y:0});
3412
+ *
3413
+ * The best way to copy a canvas is to create a texture from it. Then render with that.
3414
+ *
3415
+ * Parsing in a RenderTarget canvas context (with a 2d context)
3416
+ * @param sourceRenderSurfaceTexture - the render surface to copy from
3417
+ * @param {Texture} destinationTexture - the texture to copy to
3418
+ * @param {object} originSrc - the origin of the copy
3419
+ * @param {number} originSrc.x - the x origin of the copy
3420
+ * @param {number} originSrc.y - the y origin of the copy
3421
+ * @param {object} size - the size of the copy
3422
+ * @param {number} size.width - the width of the copy
3423
+ * @param {number} size.height - the height of the copy
3424
+ * @param {object} originDest - the destination origin (top left to paste from!)
3425
+ * @param {number} originDest.x - the x origin of the paste
3426
+ * @param {number} originDest.y - the y origin of the paste
3427
+ */
3428
+ copyToTexture(e, t, r, s, a) {
3429
+ r.x < 0 && (s.width += r.x, a.x -= r.x, r.x = 0), r.y < 0 && (s.height += r.y, a.y -= r.y, r.y = 0);
3430
+ const { pixelWidth: i, pixelHeight: o } = e;
3431
+ return s.width = Math.min(s.width, i - r.x), s.height = Math.min(s.height, o - r.y), this.adaptor.copyToTexture(
3432
+ e,
3433
+ t,
3434
+ r,
3435
+ s,
3436
+ a
3437
+ );
3438
+ }
3439
+ /**
3440
+ * ensures that we have a depth stencil buffer available to render to
3441
+ * This is used by the mask system to make sure we have a stencil buffer.
3442
+ */
3443
+ ensureDepthStencil() {
3444
+ this.renderTarget.stencil || (this.renderTarget.stencil = !0, this.adaptor.startRenderPass(this.renderTarget, !1, null, this.viewport, 0, this.layer));
3445
+ }
3446
+ /** nukes the render target system */
3447
+ destroy() {
3448
+ this._renderer = null, this._renderSurfaceToRenderTargetHash.forEach((e, t) => {
3449
+ e !== t && e.destroy();
3450
+ }), this._renderSurfaceToRenderTargetHash.clear(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
3451
+ }
3452
+ _initRenderTarget(e) {
3453
+ let t = null;
3454
+ return X.test(e) && (e = yt(e).source), e instanceof ee ? t = e : e instanceof I && (t = new ee({
3455
+ colorTextures: [e]
3456
+ }), e.source instanceof X && (t.isRoot = !0), e.once("destroy", () => {
3457
+ t.destroy(), this._renderSurfaceToRenderTargetHash.delete(e);
3458
+ const r = this._gpuRenderTargetHash[t.uid];
3459
+ r && (this._gpuRenderTargetHash[t.uid] = null, this.adaptor.destroyGpuRenderTarget(r));
3460
+ })), this._renderSurfaceToRenderTargetHash.set(e, t), t;
3461
+ }
3462
+ getGpuRenderTarget(e) {
3463
+ return this._gpuRenderTargetHash[e.uid] || (this._gpuRenderTargetHash[e.uid] = this.adaptor.initGpuRenderTarget(e));
3464
+ }
3465
+ resetState() {
3466
+ this.renderTarget = null, this.renderSurface = null;
3467
+ }
3468
+ }
3469
+ export {
3470
+ rt as A,
3471
+ tt as B,
3472
+ at as C,
3473
+ Je as D,
3474
+ Nr as G,
3475
+ it as R,
3476
+ Qr as S,
3477
+ lt as a,
3478
+ Yr as b,
3479
+ qr as c,
3480
+ ot as d,
3481
+ Ft as e,
3482
+ dr as f,
3483
+ hr as g,
3484
+ cr as h,
3485
+ ur as i,
3486
+ Te as j,
3487
+ mr as k,
3488
+ gr as l,
3489
+ vr as m,
3490
+ br as n,
3491
+ _r as r
3492
+ };
3493
+ //# sourceMappingURL=RenderTargetSystem-BCowAg_f.js.map