@micjanic/recursive-grid 1.0.4 → 1.0.6

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.
@@ -1,2715 +0,0 @@
1
- import { F as Ee, u as De, l as ae, M as v, v as Oe, x as Fe, S as Le, y as ne, E as u, e as D, z as S, H as He, I as O, J as b, R as F, K as ie, L as ze, t as m, b as f, i as B, w as L, N as Y, O as We, c as J, B as k, j as U, G as Ve, Q as M, k as T, V as w, W as Ne, a as je, X as oe, Y as le, Z as ue, _ as de, C as P, $ as $e, a0 as A, a1 as X, D as H, a2 as qe, P as Ke, d as Ye, T as Q, a3 as Z, a4 as Je, a5 as Xe, a6 as Qe } from "./PixiApp-BHmY2ZMg.js";
2
- import { B as ce, c as Ze } from "./colorToUniform-C2jGzNe1.js";
3
- var et = `in vec2 vMaskCoord;
4
- in vec2 vTextureCoord;
5
-
6
- uniform sampler2D uTexture;
7
- uniform sampler2D uMaskTexture;
8
-
9
- uniform float uAlpha;
10
- uniform vec4 uMaskClamp;
11
- uniform float uInverse;
12
-
13
- out vec4 finalColor;
14
-
15
- void main(void)
16
- {
17
- float clip = step(3.5,
18
- step(uMaskClamp.x, vMaskCoord.x) +
19
- step(uMaskClamp.y, vMaskCoord.y) +
20
- step(vMaskCoord.x, uMaskClamp.z) +
21
- step(vMaskCoord.y, uMaskClamp.w));
22
-
23
- // TODO look into why this is needed
24
- float npmAlpha = uAlpha;
25
- vec4 original = texture(uTexture, vTextureCoord);
26
- vec4 masky = texture(uMaskTexture, vMaskCoord);
27
- float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
28
-
29
- float a = alphaMul * masky.r * npmAlpha * clip;
30
-
31
- if (uInverse == 1.0) {
32
- a = 1.0 - a;
33
- }
34
-
35
- finalColor = original * a;
36
- }
37
- `, tt = `in vec2 aPosition;
38
-
39
- out vec2 vTextureCoord;
40
- out vec2 vMaskCoord;
41
-
42
-
43
- uniform vec4 uInputSize;
44
- uniform vec4 uOutputFrame;
45
- uniform vec4 uOutputTexture;
46
- uniform mat3 uFilterMatrix;
47
-
48
- vec4 filterVertexPosition( vec2 aPosition )
49
- {
50
- vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
51
-
52
- position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
53
- position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
54
-
55
- return vec4(position, 0.0, 1.0);
56
- }
57
-
58
- vec2 filterTextureCoord( vec2 aPosition )
59
- {
60
- return aPosition * (uOutputFrame.zw * uInputSize.zw);
61
- }
62
-
63
- vec2 getFilterCoord( vec2 aPosition )
64
- {
65
- return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
66
- }
67
-
68
- void main(void)
69
- {
70
- gl_Position = filterVertexPosition(aPosition);
71
- vTextureCoord = filterTextureCoord(aPosition);
72
- vMaskCoord = getFilterCoord(aPosition);
73
- }
74
- `, ee = `struct GlobalFilterUniforms {
75
- uInputSize:vec4<f32>,
76
- uInputPixel:vec4<f32>,
77
- uInputClamp:vec4<f32>,
78
- uOutputFrame:vec4<f32>,
79
- uGlobalFrame:vec4<f32>,
80
- uOutputTexture:vec4<f32>,
81
- };
82
-
83
- struct MaskUniforms {
84
- uFilterMatrix:mat3x3<f32>,
85
- uMaskClamp:vec4<f32>,
86
- uAlpha:f32,
87
- uInverse:f32,
88
- };
89
-
90
- @group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
91
- @group(0) @binding(1) var uTexture: texture_2d<f32>;
92
- @group(0) @binding(2) var uSampler : sampler;
93
-
94
- @group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
95
- @group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
96
-
97
- struct VSOutput {
98
- @builtin(position) position: vec4<f32>,
99
- @location(0) uv : vec2<f32>,
100
- @location(1) filterUv : vec2<f32>,
101
- };
102
-
103
- fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
104
- {
105
- var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
106
-
107
- position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
108
- position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
109
-
110
- return vec4(position, 0.0, 1.0);
111
- }
112
-
113
- fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
114
- {
115
- return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
116
- }
117
-
118
- fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
119
- {
120
- return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
121
- }
122
-
123
- fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
124
- {
125
- return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
126
- }
127
-
128
- fn getSize() -> vec2<f32>
129
- {
130
- return gfu.uGlobalFrame.zw;
131
- }
132
-
133
- @vertex
134
- fn mainVertex(
135
- @location(0) aPosition : vec2<f32>,
136
- ) -> VSOutput {
137
- return VSOutput(
138
- filterVertexPosition(aPosition),
139
- filterTextureCoord(aPosition),
140
- getFilterCoord(aPosition)
141
- );
142
- }
143
-
144
- @fragment
145
- fn mainFragment(
146
- @location(0) uv: vec2<f32>,
147
- @location(1) filterUv: vec2<f32>,
148
- @builtin(position) position: vec4<f32>
149
- ) -> @location(0) vec4<f32> {
150
-
151
- var maskClamp = filterUniforms.uMaskClamp;
152
- var uAlpha = filterUniforms.uAlpha;
153
-
154
- var clip = step(3.5,
155
- step(maskClamp.x, filterUv.x) +
156
- step(maskClamp.y, filterUv.y) +
157
- step(filterUv.x, maskClamp.z) +
158
- step(filterUv.y, maskClamp.w));
159
-
160
- var mask = textureSample(uMaskTexture, uSampler, filterUv);
161
- var source = textureSample(uTexture, uSampler, uv);
162
- var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
163
-
164
- var a: f32 = alphaMul * mask.r * uAlpha * clip;
165
-
166
- if (filterUniforms.uInverse == 1.0) {
167
- a = 1.0 - a;
168
- }
169
-
170
- return source * a;
171
- }
172
- `;
173
- class rt extends Ee {
174
- constructor(e) {
175
- const { sprite: t, ...r } = e, s = new De(t.texture), n = new ae({
176
- uFilterMatrix: { value: new v(), type: "mat3x3<f32>" },
177
- uMaskClamp: { value: s.uClampFrame, type: "vec4<f32>" },
178
- uAlpha: { value: 1, type: "f32" },
179
- uInverse: { value: e.inverse ? 1 : 0, type: "f32" }
180
- }), i = Oe.from({
181
- vertex: {
182
- source: ee,
183
- entryPoint: "mainVertex"
184
- },
185
- fragment: {
186
- source: ee,
187
- entryPoint: "mainFragment"
188
- }
189
- }), o = Fe.from({
190
- vertex: tt,
191
- fragment: et,
192
- name: "mask-filter"
193
- });
194
- super({
195
- ...r,
196
- gpuProgram: i,
197
- glProgram: o,
198
- clipToViewport: !1,
199
- resources: {
200
- filterUniforms: n,
201
- uMaskTexture: t.texture.source
202
- }
203
- }), this.sprite = t, this._textureMatrix = s;
204
- }
205
- set inverse(e) {
206
- this.resources.filterUniforms.uniforms.uInverse = e ? 1 : 0;
207
- }
208
- get inverse() {
209
- return this.resources.filterUniforms.uniforms.uInverse === 1;
210
- }
211
- apply(e, t, r, s) {
212
- this._textureMatrix.texture = this.sprite.texture, e.calculateSpriteMatrix(
213
- this.resources.filterUniforms.uniforms.uFilterMatrix,
214
- this.sprite
215
- ).prepend(this._textureMatrix.mapCoord), this.resources.uMaskTexture = this.sprite.texture.source, e.applyFilter(this, t, r, s);
216
- }
217
- }
218
- const z = class he {
219
- constructor(e, t) {
220
- var r, s;
221
- this.state = Le.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);
222
- }
223
- static getBatcher(e) {
224
- return new this._availableBatchers[e]();
225
- }
226
- buildStart(e) {
227
- let t = this._batchersByInstructionSet[e.uid];
228
- t || (t = this._batchersByInstructionSet[e.uid] = /* @__PURE__ */ Object.create(null), t.default || (t.default = new ne({
229
- maxTextures: this.renderer.limits.maxBatchableTextures
230
- }))), this._activeBatches = t, this._activeBatch = this._activeBatches.default;
231
- for (const r in this._activeBatches)
232
- this._activeBatches[r].begin();
233
- }
234
- addToBatch(e, t) {
235
- if (this._activeBatch.name !== e.batcherName) {
236
- this._activeBatch.break(t);
237
- let r = this._activeBatches[e.batcherName];
238
- r || (r = this._activeBatches[e.batcherName] = he.getBatcher(e.batcherName), r.begin()), this._activeBatch = r;
239
- }
240
- this._activeBatch.add(e);
241
- }
242
- break(e) {
243
- this._activeBatch.break(e);
244
- }
245
- buildEnd(e) {
246
- this._activeBatch.break(e);
247
- const t = this._activeBatches;
248
- for (const r in t) {
249
- const s = t[r], n = s.geometry;
250
- n.indexBuffer.setDataWithSize(s.indexBuffer, s.indexSize, !0), n.buffers[0].setDataWithSize(s.attributeBuffer.float32View, s.attributeSize, !1);
251
- }
252
- }
253
- upload(e) {
254
- const t = this._batchersByInstructionSet[e.uid];
255
- for (const r in t) {
256
- const s = t[r], n = s.geometry;
257
- s.dirty && (s.dirty = !1, n.buffers[0].update(s.attributeSize * 4));
258
- }
259
- }
260
- execute(e) {
261
- if (e.action === "startBatch") {
262
- const t = e.batcher, r = t.geometry, s = t.shader;
263
- this._adaptor.start(this, r, s);
264
- }
265
- this._adaptor.execute(this, e);
266
- }
267
- destroy() {
268
- this.state = null, this.renderer = null, this._adaptor = null;
269
- for (const e in this._activeBatches)
270
- this._activeBatches[e].destroy();
271
- this._activeBatches = null;
272
- }
273
- };
274
- z.extension = {
275
- type: [
276
- u.WebGLPipes,
277
- u.WebGPUPipes,
278
- u.CanvasPipes
279
- ],
280
- name: "batch"
281
- };
282
- z._availableBatchers = /* @__PURE__ */ Object.create(null);
283
- let fe = z;
284
- D.handleByMap(u.Batcher, fe._availableBatchers);
285
- D.add(ne);
286
- const Bt = {
287
- name: "texture-bit",
288
- vertex: {
289
- header: (
290
- /* wgsl */
291
- `
292
-
293
- struct TextureUniforms {
294
- uTextureMatrix:mat3x3<f32>,
295
- }
296
-
297
- @group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
298
- `
299
- ),
300
- main: (
301
- /* wgsl */
302
- `
303
- uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
304
- `
305
- )
306
- },
307
- fragment: {
308
- header: (
309
- /* wgsl */
310
- `
311
- @group(2) @binding(0) var uTexture: texture_2d<f32>;
312
- @group(2) @binding(1) var uSampler: sampler;
313
-
314
-
315
- `
316
- ),
317
- main: (
318
- /* wgsl */
319
- `
320
- outColor = textureSample(uTexture, uSampler, vUV);
321
- `
322
- )
323
- }
324
- }, Ut = {
325
- name: "texture-bit",
326
- vertex: {
327
- header: (
328
- /* glsl */
329
- `
330
- uniform mat3 uTextureMatrix;
331
- `
332
- ),
333
- main: (
334
- /* glsl */
335
- `
336
- uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
337
- `
338
- )
339
- },
340
- fragment: {
341
- header: (
342
- /* glsl */
343
- `
344
- uniform sampler2D uTexture;
345
-
346
-
347
- `
348
- ),
349
- main: (
350
- /* glsl */
351
- `
352
- outColor = texture(uTexture, vUV);
353
- `
354
- )
355
- }
356
- }, st = new O();
357
- class at extends ie {
358
- constructor() {
359
- super(), this.filters = [new rt({
360
- sprite: new ze(m.EMPTY),
361
- inverse: !1,
362
- resolution: "inherit",
363
- antialias: "inherit"
364
- })];
365
- }
366
- get sprite() {
367
- return this.filters[0].sprite;
368
- }
369
- set sprite(e) {
370
- this.filters[0].sprite = e;
371
- }
372
- get inverse() {
373
- return this.filters[0].inverse;
374
- }
375
- set inverse(e) {
376
- this.filters[0].inverse = e;
377
- }
378
- }
379
- class pe {
380
- constructor(e) {
381
- this._activeMaskStage = [], this._renderer = e;
382
- }
383
- push(e, t, r) {
384
- const s = this._renderer;
385
- if (s.renderPipes.batch.break(r), r.add({
386
- renderPipeId: "alphaMask",
387
- action: "pushMaskBegin",
388
- mask: e,
389
- inverse: t._maskOptions.inverse,
390
- canBundle: !1,
391
- maskedContainer: t
392
- }), e.inverse = t._maskOptions.inverse, e.renderMaskToTexture) {
393
- const n = e.mask;
394
- n.includeInBuild = !0, n.collectRenderables(
395
- r,
396
- s,
397
- null
398
- ), n.includeInBuild = !1;
399
- }
400
- s.renderPipes.batch.break(r), r.add({
401
- renderPipeId: "alphaMask",
402
- action: "pushMaskEnd",
403
- mask: e,
404
- maskedContainer: t,
405
- inverse: t._maskOptions.inverse,
406
- canBundle: !1
407
- });
408
- }
409
- pop(e, t, r) {
410
- this._renderer.renderPipes.batch.break(r), r.add({
411
- renderPipeId: "alphaMask",
412
- action: "popMaskEnd",
413
- mask: e,
414
- inverse: t._maskOptions.inverse,
415
- canBundle: !1
416
- });
417
- }
418
- execute(e) {
419
- const t = this._renderer, r = e.mask.renderMaskToTexture;
420
- if (e.action === "pushMaskBegin") {
421
- const s = S.get(at);
422
- if (s.inverse = e.inverse, r) {
423
- e.mask.mask.measurable = !0;
424
- const n = He(e.mask.mask, !0, st);
425
- e.mask.mask.measurable = !1, n.ceil();
426
- const i = t.renderTarget.renderTarget.colorTexture.source, o = b.getOptimalTexture(
427
- n.width,
428
- n.height,
429
- i._resolution,
430
- i.antialias
431
- );
432
- t.renderTarget.push(o, !0), t.globalUniforms.push({
433
- offset: n,
434
- worldColor: 4294967295
435
- });
436
- const l = s.sprite;
437
- l.texture = o, l.worldTransform.tx = n.minX, l.worldTransform.ty = n.minY, this._activeMaskStage.push({
438
- filterEffect: s,
439
- maskedContainer: e.maskedContainer,
440
- filterTexture: o
441
- });
442
- } else
443
- s.sprite = e.mask.mask, this._activeMaskStage.push({
444
- filterEffect: s,
445
- maskedContainer: e.maskedContainer
446
- });
447
- } else if (e.action === "pushMaskEnd") {
448
- const s = this._activeMaskStage[this._activeMaskStage.length - 1];
449
- r && (t.type === F.WEBGL && t.renderTarget.finishRenderPass(), t.renderTarget.pop(), t.globalUniforms.pop()), t.filter.push({
450
- renderPipeId: "filter",
451
- action: "pushFilter",
452
- container: s.maskedContainer,
453
- filterEffect: s.filterEffect,
454
- canBundle: !1
455
- });
456
- } else if (e.action === "popMaskEnd") {
457
- t.filter.pop();
458
- const s = this._activeMaskStage.pop();
459
- r && b.returnTexture(s.filterTexture), S.return(s.filterEffect);
460
- }
461
- }
462
- destroy() {
463
- this._renderer = null, this._activeMaskStage = null;
464
- }
465
- }
466
- pe.extension = {
467
- type: [
468
- u.WebGLPipes,
469
- u.WebGPUPipes,
470
- u.CanvasPipes
471
- ],
472
- name: "alphaMask"
473
- };
474
- class me {
475
- constructor(e) {
476
- this._colorStack = [], this._colorStackIndex = 0, this._currentColor = 0, this._renderer = e;
477
- }
478
- buildStart() {
479
- this._colorStack[0] = 15, this._colorStackIndex = 1, this._currentColor = 15;
480
- }
481
- push(e, t, r) {
482
- this._renderer.renderPipes.batch.break(r);
483
- const n = this._colorStack;
484
- n[this._colorStackIndex] = n[this._colorStackIndex - 1] & e.mask;
485
- const i = this._colorStack[this._colorStackIndex];
486
- i !== this._currentColor && (this._currentColor = i, r.add({
487
- renderPipeId: "colorMask",
488
- colorMask: i,
489
- canBundle: !1
490
- })), this._colorStackIndex++;
491
- }
492
- pop(e, t, r) {
493
- this._renderer.renderPipes.batch.break(r);
494
- const n = this._colorStack;
495
- this._colorStackIndex--;
496
- const i = n[this._colorStackIndex - 1];
497
- i !== this._currentColor && (this._currentColor = i, r.add({
498
- renderPipeId: "colorMask",
499
- colorMask: i,
500
- canBundle: !1
501
- }));
502
- }
503
- execute(e) {
504
- this._renderer.colorMask.setMask(e.colorMask);
505
- }
506
- destroy() {
507
- this._renderer = null, this._colorStack = null;
508
- }
509
- }
510
- me.extension = {
511
- type: [
512
- u.WebGLPipes,
513
- u.WebGPUPipes,
514
- u.CanvasPipes
515
- ],
516
- name: "colorMask"
517
- };
518
- class ve {
519
- constructor(e) {
520
- this._maskStackHash = {}, this._maskHash = /* @__PURE__ */ new WeakMap(), this._renderer = e;
521
- }
522
- push(e, t, r) {
523
- var s;
524
- const n = e, i = this._renderer;
525
- i.renderPipes.batch.break(r), i.renderPipes.blendMode.setBlendMode(n.mask, "none", r), r.add({
526
- renderPipeId: "stencilMask",
527
- action: "pushMaskBegin",
528
- mask: e,
529
- inverse: t._maskOptions.inverse,
530
- canBundle: !1
531
- });
532
- const o = n.mask;
533
- o.includeInBuild = !0, this._maskHash.has(n) || this._maskHash.set(n, {
534
- instructionsStart: 0,
535
- instructionsLength: 0
536
- });
537
- const l = this._maskHash.get(n);
538
- l.instructionsStart = r.instructionSize, o.collectRenderables(
539
- r,
540
- i,
541
- null
542
- ), o.includeInBuild = !1, i.renderPipes.batch.break(r), r.add({
543
- renderPipeId: "stencilMask",
544
- action: "pushMaskEnd",
545
- mask: e,
546
- inverse: t._maskOptions.inverse,
547
- canBundle: !1
548
- });
549
- const d = r.instructionSize - l.instructionsStart - 1;
550
- l.instructionsLength = d;
551
- const c = i.renderTarget.renderTarget.uid;
552
- (s = this._maskStackHash)[c] ?? (s[c] = 0);
553
- }
554
- pop(e, t, r) {
555
- const s = e, n = this._renderer;
556
- n.renderPipes.batch.break(r), n.renderPipes.blendMode.setBlendMode(s.mask, "none", r), r.add({
557
- renderPipeId: "stencilMask",
558
- action: "popMaskBegin",
559
- inverse: t._maskOptions.inverse,
560
- canBundle: !1
561
- });
562
- const i = this._maskHash.get(e);
563
- for (let o = 0; o < i.instructionsLength; o++)
564
- r.instructions[r.instructionSize++] = r.instructions[i.instructionsStart++];
565
- r.add({
566
- renderPipeId: "stencilMask",
567
- action: "popMaskEnd",
568
- canBundle: !1
569
- });
570
- }
571
- execute(e) {
572
- var t;
573
- const r = this._renderer, s = r.renderTarget.renderTarget.uid;
574
- let n = (t = this._maskStackHash)[s] ?? (t[s] = 0);
575
- e.action === "pushMaskBegin" ? (r.renderTarget.ensureDepthStencil(), r.stencil.setStencilMode(f.RENDERING_MASK_ADD, n), n++, r.colorMask.setMask(0)) : e.action === "pushMaskEnd" ? (e.inverse ? r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE, n) : r.stencil.setStencilMode(f.MASK_ACTIVE, n), r.colorMask.setMask(15)) : e.action === "popMaskBegin" ? (r.colorMask.setMask(0), n !== 0 ? r.stencil.setStencilMode(f.RENDERING_MASK_REMOVE, n) : (r.renderTarget.clear(null, B.STENCIL), r.stencil.setStencilMode(f.DISABLED, n)), n--) : e.action === "popMaskEnd" && (e.inverse ? r.stencil.setStencilMode(f.INVERSE_MASK_ACTIVE, n) : r.stencil.setStencilMode(f.MASK_ACTIVE, n), r.colorMask.setMask(15)), this._maskStackHash[s] = n;
576
- }
577
- destroy() {
578
- this._renderer = null, this._maskStackHash = null, this._maskHash = null;
579
- }
580
- }
581
- ve.extension = {
582
- type: [
583
- u.WebGLPipes,
584
- u.WebGPUPipes,
585
- u.CanvasPipes
586
- ],
587
- name: "stencilMask"
588
- };
589
- function At(a, e) {
590
- for (const t in a.attributes) {
591
- const r = a.attributes[t], s = e[t];
592
- s ? (r.format ?? (r.format = s.format), r.offset ?? (r.offset = s.offset), r.instance ?? (r.instance = s.instance)) : L(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`);
593
- }
594
- nt(a);
595
- }
596
- function nt(a) {
597
- const { buffers: e, attributes: t } = a, r = {}, s = {};
598
- for (const n in e) {
599
- const i = e[n];
600
- r[i.uid] = 0, s[i.uid] = 0;
601
- }
602
- for (const n in t) {
603
- const i = t[n];
604
- r[i.buffer.uid] += Y(i.format).stride;
605
- }
606
- for (const n in t) {
607
- const i = t[n];
608
- i.stride ?? (i.stride = r[i.buffer.uid]), i.start ?? (i.start = s[i.buffer.uid]), s[i.buffer.uid] += Y(i.format).stride;
609
- }
610
- }
611
- const _ = [];
612
- _[f.NONE] = void 0;
613
- _[f.DISABLED] = {
614
- stencilWriteMask: 0,
615
- stencilReadMask: 0
616
- };
617
- _[f.RENDERING_MASK_ADD] = {
618
- stencilFront: {
619
- compare: "equal",
620
- passOp: "increment-clamp"
621
- },
622
- stencilBack: {
623
- compare: "equal",
624
- passOp: "increment-clamp"
625
- }
626
- };
627
- _[f.RENDERING_MASK_REMOVE] = {
628
- stencilFront: {
629
- compare: "equal",
630
- passOp: "decrement-clamp"
631
- },
632
- stencilBack: {
633
- compare: "equal",
634
- passOp: "decrement-clamp"
635
- }
636
- };
637
- _[f.MASK_ACTIVE] = {
638
- stencilWriteMask: 0,
639
- stencilFront: {
640
- compare: "equal",
641
- passOp: "keep"
642
- },
643
- stencilBack: {
644
- compare: "equal",
645
- passOp: "keep"
646
- }
647
- };
648
- _[f.INVERSE_MASK_ACTIVE] = {
649
- stencilWriteMask: 0,
650
- stencilFront: {
651
- compare: "not-equal",
652
- passOp: "keep"
653
- },
654
- stencilBack: {
655
- compare: "not-equal",
656
- passOp: "keep"
657
- }
658
- };
659
- class It {
660
- constructor(e) {
661
- this._syncFunctionHash = /* @__PURE__ */ Object.create(null), this._adaptor = e, this._systemCheck();
662
- }
663
- /**
664
- * Overridable function by `pixi.js/unsafe-eval` to silence
665
- * throwing an error if platform doesn't support unsafe-evals.
666
- * @private
667
- */
668
- _systemCheck() {
669
- if (!We())
670
- throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.");
671
- }
672
- ensureUniformGroup(e) {
673
- const t = this.getUniformGroupData(e);
674
- e.buffer || (e.buffer = new J({
675
- data: new Float32Array(t.layout.size / 4),
676
- usage: k.UNIFORM | k.COPY_DST
677
- }));
678
- }
679
- getUniformGroupData(e) {
680
- return this._syncFunctionHash[e._signature] || this._initUniformGroup(e);
681
- }
682
- _initUniformGroup(e) {
683
- const t = e._signature;
684
- let r = this._syncFunctionHash[t];
685
- if (!r) {
686
- const s = Object.keys(e.uniformStructures).map((o) => e.uniformStructures[o]), n = this._adaptor.createUboElements(s), i = this._generateUboSync(n.uboElements);
687
- r = this._syncFunctionHash[t] = {
688
- layout: n,
689
- syncFunction: i
690
- };
691
- }
692
- return this._syncFunctionHash[t];
693
- }
694
- _generateUboSync(e) {
695
- return this._adaptor.generateUboSync(e);
696
- }
697
- syncUniformGroup(e, t, r) {
698
- const s = this.getUniformGroupData(e);
699
- e.buffer || (e.buffer = new J({
700
- data: new Float32Array(s.layout.size / 4),
701
- usage: k.UNIFORM | k.COPY_DST
702
- }));
703
- let n = null;
704
- return t || (t = e.buffer.data, n = e.buffer.dataInt32), r || (r = 0), s.syncFunction(e.uniforms, t, n, r), !0;
705
- }
706
- updateUniformGroup(e) {
707
- if (e.isStatic && !e._dirtyId)
708
- return !1;
709
- e._dirtyId = 0;
710
- const t = this.syncUniformGroup(e);
711
- return e.buffer.update(), t;
712
- }
713
- destroy() {
714
- this._syncFunctionHash = null;
715
- }
716
- }
717
- const C = [
718
- // uploading pixi matrix object to mat3
719
- {
720
- type: "mat3x3<f32>",
721
- test: (a) => a.value.a !== void 0,
722
- ubo: `
723
- var matrix = uv[name].toArray(true);
724
- data[offset] = matrix[0];
725
- data[offset + 1] = matrix[1];
726
- data[offset + 2] = matrix[2];
727
- data[offset + 4] = matrix[3];
728
- data[offset + 5] = matrix[4];
729
- data[offset + 6] = matrix[5];
730
- data[offset + 8] = matrix[6];
731
- data[offset + 9] = matrix[7];
732
- data[offset + 10] = matrix[8];
733
- `,
734
- uniform: `
735
- gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
736
- `
737
- },
738
- // uploading a pixi rectangle as a vec4
739
- {
740
- type: "vec4<f32>",
741
- test: (a) => a.type === "vec4<f32>" && a.size === 1 && a.value.width !== void 0,
742
- ubo: `
743
- v = uv[name];
744
- data[offset] = v.x;
745
- data[offset + 1] = v.y;
746
- data[offset + 2] = v.width;
747
- data[offset + 3] = v.height;
748
- `,
749
- uniform: `
750
- cv = ud[name].value;
751
- v = uv[name];
752
- if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
753
- cv[0] = v.x;
754
- cv[1] = v.y;
755
- cv[2] = v.width;
756
- cv[3] = v.height;
757
- gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
758
- }
759
- `
760
- },
761
- // uploading a pixi point as a vec2
762
- {
763
- type: "vec2<f32>",
764
- test: (a) => a.type === "vec2<f32>" && a.size === 1 && a.value.x !== void 0,
765
- ubo: `
766
- v = uv[name];
767
- data[offset] = v.x;
768
- data[offset + 1] = v.y;
769
- `,
770
- uniform: `
771
- cv = ud[name].value;
772
- v = uv[name];
773
- if (cv[0] !== v.x || cv[1] !== v.y) {
774
- cv[0] = v.x;
775
- cv[1] = v.y;
776
- gl.uniform2f(ud[name].location, v.x, v.y);
777
- }
778
- `
779
- },
780
- // uploading a pixi color as a vec4
781
- {
782
- type: "vec4<f32>",
783
- test: (a) => a.type === "vec4<f32>" && a.size === 1 && a.value.red !== void 0,
784
- ubo: `
785
- v = uv[name];
786
- data[offset] = v.red;
787
- data[offset + 1] = v.green;
788
- data[offset + 2] = v.blue;
789
- data[offset + 3] = v.alpha;
790
- `,
791
- uniform: `
792
- cv = ud[name].value;
793
- v = uv[name];
794
- if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
795
- cv[0] = v.red;
796
- cv[1] = v.green;
797
- cv[2] = v.blue;
798
- cv[3] = v.alpha;
799
- gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
800
- }
801
- `
802
- },
803
- // uploading a pixi color as a vec3
804
- {
805
- type: "vec3<f32>",
806
- test: (a) => a.type === "vec3<f32>" && a.size === 1 && a.value.red !== void 0,
807
- ubo: `
808
- v = uv[name];
809
- data[offset] = v.red;
810
- data[offset + 1] = v.green;
811
- data[offset + 2] = v.blue;
812
- `,
813
- uniform: `
814
- cv = ud[name].value;
815
- v = uv[name];
816
- if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
817
- cv[0] = v.red;
818
- cv[1] = v.green;
819
- cv[2] = v.blue;
820
- gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
821
- }
822
- `
823
- }
824
- ];
825
- function Gt(a, e, t, r) {
826
- const s = [`
827
- var v = null;
828
- var v2 = null;
829
- var t = 0;
830
- var index = 0;
831
- var name = null;
832
- var arrayOffset = null;
833
- `];
834
- let n = 0;
835
- for (let o = 0; o < a.length; o++) {
836
- const l = a[o], d = l.data.name;
837
- let c = !1, h = 0;
838
- for (let p = 0; p < C.length; p++)
839
- if (C[p].test(l.data)) {
840
- h = l.offset / 4, s.push(
841
- `name = "${d}";`,
842
- `offset += ${h - n};`,
843
- C[p][e] || C[p].ubo
844
- ), c = !0;
845
- break;
846
- }
847
- if (!c)
848
- if (l.data.size > 1)
849
- h = l.offset / 4, s.push(t(l, h - n));
850
- else {
851
- const p = r[l.data.type];
852
- h = l.offset / 4, s.push(
853
- /* wgsl */
854
- `
855
- v = uv.${d};
856
- offset += ${h - n};
857
- ${p};
858
- `
859
- );
860
- }
861
- n = h;
862
- }
863
- const i = s.join(`
864
- `);
865
- return new Function(
866
- "uv",
867
- "data",
868
- "dataInt32",
869
- "offset",
870
- i
871
- );
872
- }
873
- function g(a, e) {
874
- return `
875
- for (let i = 0; i < ${a * e}; i++) {
876
- data[offset + (((i / ${a})|0) * 4) + (i % ${a})] = v[i];
877
- }
878
- `;
879
- }
880
- const it = {
881
- f32: `
882
- data[offset] = v;`,
883
- i32: `
884
- dataInt32[offset] = v;`,
885
- "vec2<f32>": `
886
- data[offset] = v[0];
887
- data[offset + 1] = v[1];`,
888
- "vec3<f32>": `
889
- data[offset] = v[0];
890
- data[offset + 1] = v[1];
891
- data[offset + 2] = v[2];`,
892
- "vec4<f32>": `
893
- data[offset] = v[0];
894
- data[offset + 1] = v[1];
895
- data[offset + 2] = v[2];
896
- data[offset + 3] = v[3];`,
897
- "vec2<i32>": `
898
- dataInt32[offset] = v[0];
899
- dataInt32[offset + 1] = v[1];`,
900
- "vec3<i32>": `
901
- dataInt32[offset] = v[0];
902
- dataInt32[offset + 1] = v[1];
903
- dataInt32[offset + 2] = v[2];`,
904
- "vec4<i32>": `
905
- dataInt32[offset] = v[0];
906
- dataInt32[offset + 1] = v[1];
907
- dataInt32[offset + 2] = v[2];
908
- dataInt32[offset + 3] = v[3];`,
909
- "mat2x2<f32>": `
910
- data[offset] = v[0];
911
- data[offset + 1] = v[1];
912
- data[offset + 4] = v[2];
913
- data[offset + 5] = v[3];`,
914
- "mat3x3<f32>": `
915
- data[offset] = v[0];
916
- data[offset + 1] = v[1];
917
- data[offset + 2] = v[2];
918
- data[offset + 4] = v[3];
919
- data[offset + 5] = v[4];
920
- data[offset + 6] = v[5];
921
- data[offset + 8] = v[6];
922
- data[offset + 9] = v[7];
923
- data[offset + 10] = v[8];`,
924
- "mat4x4<f32>": `
925
- for (let i = 0; i < 16; i++) {
926
- data[offset + i] = v[i];
927
- }`,
928
- "mat3x2<f32>": g(3, 2),
929
- "mat4x2<f32>": g(4, 2),
930
- "mat2x3<f32>": g(2, 3),
931
- "mat4x3<f32>": g(4, 3),
932
- "mat2x4<f32>": g(2, 4),
933
- "mat3x4<f32>": g(3, 4)
934
- }, Et = {
935
- ...it,
936
- "mat2x2<f32>": `
937
- data[offset] = v[0];
938
- data[offset + 1] = v[1];
939
- data[offset + 2] = v[2];
940
- data[offset + 3] = v[3];
941
- `
942
- };
943
- function ot(a, e, t, r, s, n) {
944
- const i = n ? 1 : -1;
945
- return a.identity(), a.a = 1 / r * 2, a.d = i * (1 / s * 2), a.tx = -1 - e * a.a, a.ty = -i - t * a.d, a;
946
- }
947
- const x = /* @__PURE__ */ new Map();
948
- Ve.register(x);
949
- function ge(a, e) {
950
- if (!x.has(a)) {
951
- const t = new m({
952
- source: new U({
953
- resource: a,
954
- ...e
955
- })
956
- }), r = () => {
957
- x.get(a) === t && x.delete(a);
958
- };
959
- t.once("destroy", r), t.source.once("destroy", r), x.set(a, t);
960
- }
961
- return x.get(a);
962
- }
963
- function lt(a) {
964
- const e = a.colorTexture.source.resource;
965
- return globalThis.HTMLCanvasElement && e instanceof HTMLCanvasElement && document.body.contains(e);
966
- }
967
- const xe = class _e {
968
- /**
969
- * @param [descriptor] - Options for creating a render target.
970
- */
971
- constructor(e = {}) {
972
- if (this.uid = M("renderTarget"), this.colorTextures = [], this.dirtyId = 0, this.isRoot = !1, this._size = new Float32Array(2), this._managedColorTextures = !1, e = { ..._e.defaultOptions, ...e }, this.stencil = e.stencil, this.depth = e.depth, this.isRoot = e.isRoot, typeof e.colorTextures == "number") {
973
- this._managedColorTextures = !0;
974
- for (let t = 0; t < e.colorTextures; t++)
975
- this.colorTextures.push(
976
- new T({
977
- width: e.width,
978
- height: e.height,
979
- resolution: e.resolution,
980
- antialias: e.antialias
981
- })
982
- );
983
- } else {
984
- this.colorTextures = [...e.colorTextures.map((r) => r.source)];
985
- const t = this.colorTexture.source;
986
- this.resize(t.width, t.height, t._resolution);
987
- }
988
- this.colorTexture.source.on("resize", this.onSourceResize, this), (e.depthStencilTexture || this.stencil) && (e.depthStencilTexture instanceof m || e.depthStencilTexture instanceof T ? this.depthStencilTexture = e.depthStencilTexture.source : this.ensureDepthStencilTexture());
989
- }
990
- get size() {
991
- const e = this._size;
992
- return e[0] = this.pixelWidth, e[1] = this.pixelHeight, e;
993
- }
994
- get width() {
995
- return this.colorTexture.source.width;
996
- }
997
- get height() {
998
- return this.colorTexture.source.height;
999
- }
1000
- get pixelWidth() {
1001
- return this.colorTexture.source.pixelWidth;
1002
- }
1003
- get pixelHeight() {
1004
- return this.colorTexture.source.pixelHeight;
1005
- }
1006
- get resolution() {
1007
- return this.colorTexture.source._resolution;
1008
- }
1009
- get colorTexture() {
1010
- return this.colorTextures[0];
1011
- }
1012
- onSourceResize(e) {
1013
- this.resize(e.width, e.height, e._resolution, !0);
1014
- }
1015
- /**
1016
- * This will ensure a depthStencil texture is created for this render target.
1017
- * Most likely called by the mask system to make sure we have stencil buffer added.
1018
- * @internal
1019
- */
1020
- ensureDepthStencilTexture() {
1021
- this.depthStencilTexture || (this.depthStencilTexture = new T({
1022
- width: this.width,
1023
- height: this.height,
1024
- resolution: this.resolution,
1025
- format: "depth24plus-stencil8",
1026
- autoGenerateMipmaps: !1,
1027
- antialias: !1,
1028
- mipLevelCount: 1
1029
- // sampleCount: handled by the render target system..
1030
- }));
1031
- }
1032
- resize(e, t, r = this.resolution, s = !1) {
1033
- this.dirtyId++, this.colorTextures.forEach((n, i) => {
1034
- s && i === 0 || n.source.resize(e, t, r);
1035
- }), this.depthStencilTexture && this.depthStencilTexture.source.resize(e, t, r);
1036
- }
1037
- destroy() {
1038
- this.colorTexture.source.off("resize", this.onSourceResize, this), this._managedColorTextures && this.colorTextures.forEach((e) => {
1039
- e.destroy();
1040
- }), this.depthStencilTexture && (this.depthStencilTexture.destroy(), delete this.depthStencilTexture);
1041
- }
1042
- };
1043
- xe.defaultOptions = {
1044
- /** the width of the RenderTarget */
1045
- width: 0,
1046
- /** the height of the RenderTarget */
1047
- height: 0,
1048
- /** the resolution of the RenderTarget */
1049
- resolution: 1,
1050
- /** an array of textures, or a number indicating how many color textures there should be */
1051
- colorTextures: 1,
1052
- /** should this render target have a stencil buffer? */
1053
- stencil: !1,
1054
- /** should this render target have a depth buffer? */
1055
- depth: !1,
1056
- /** should this render target be antialiased? */
1057
- antialias: !1,
1058
- // save on perf by default!
1059
- /** is this a root element, true if this is gl context owners render target */
1060
- isRoot: !1
1061
- };
1062
- let I = xe;
1063
- class Dt {
1064
- constructor(e) {
1065
- this.rootViewPort = new w(), this.viewport = new w(), this.onRenderTargetChange = new Ne("onRenderTargetChange"), this.projectionMatrix = new v(), this.defaultClearColor = [0, 0, 0, 0], this._renderSurfaceToRenderTargetHash = /* @__PURE__ */ new Map(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null), this._renderTargetStack = [], this._renderer = e, e.renderableGC.addManagedHash(this, "_gpuRenderTargetHash");
1066
- }
1067
- /** called when dev wants to finish a render pass */
1068
- finishRenderPass() {
1069
- this.adaptor.finishRenderPass(this.renderTarget);
1070
- }
1071
- /**
1072
- * called when the renderer starts to render a scene.
1073
- * @param options
1074
- * @param options.target - the render target to render to
1075
- * @param options.clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1076
- * @param options.clearColor - the color to clear to
1077
- * @param options.frame - the frame to render to
1078
- */
1079
- renderStart({
1080
- target: e,
1081
- clear: t,
1082
- clearColor: r,
1083
- frame: s
1084
- }) {
1085
- var n, i;
1086
- this._renderTargetStack.length = 0, this.push(
1087
- e,
1088
- t,
1089
- r,
1090
- s
1091
- ), this.rootViewPort.copyFrom(this.viewport), this.rootRenderTarget = this.renderTarget, this.renderingToScreen = lt(this.rootRenderTarget), (i = (n = this.adaptor).prerender) == null || i.call(n, this.rootRenderTarget);
1092
- }
1093
- postrender() {
1094
- var e, t;
1095
- (t = (e = this.adaptor).postrender) == null || t.call(e, this.rootRenderTarget);
1096
- }
1097
- /**
1098
- * Binding a render surface! This is the main function of the render target system.
1099
- * It will take the RenderSurface (which can be a texture, canvas, or render target) and bind it to the renderer.
1100
- * Once bound all draw calls will be rendered to the render surface.
1101
- *
1102
- * If a frame is not provide and the render surface is a texture, the frame of the texture will be used.
1103
- * @param renderSurface - the render surface to bind
1104
- * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1105
- * @param clearColor - the color to clear to
1106
- * @param frame - the frame to render to
1107
- * @returns the render target that was bound
1108
- */
1109
- bind(e, t = !0, r, s) {
1110
- const n = this.getRenderTarget(e), i = this.renderTarget !== n;
1111
- this.renderTarget = n, this.renderSurface = e;
1112
- const o = this.getGpuRenderTarget(n);
1113
- (n.pixelWidth !== o.width || n.pixelHeight !== o.height) && (this.adaptor.resizeGpuRenderTarget(n), o.width = n.pixelWidth, o.height = n.pixelHeight);
1114
- const l = n.colorTexture, d = this.viewport, c = l.pixelWidth, h = l.pixelHeight;
1115
- if (!s && e instanceof m && (s = e.frame), s) {
1116
- const p = l._resolution;
1117
- d.x = s.x * p + 0.5 | 0, d.y = s.y * p + 0.5 | 0, d.width = s.width * p + 0.5 | 0, d.height = s.height * p + 0.5 | 0;
1118
- } else
1119
- d.x = 0, d.y = 0, d.width = c, d.height = h;
1120
- return ot(
1121
- this.projectionMatrix,
1122
- 0,
1123
- 0,
1124
- d.width / l.resolution,
1125
- d.height / l.resolution,
1126
- !n.isRoot
1127
- ), this.adaptor.startRenderPass(n, t, r, d), i && this.onRenderTargetChange.emit(n), n;
1128
- }
1129
- clear(e, t = B.ALL, r) {
1130
- t && (e && (e = this.getRenderTarget(e)), this.adaptor.clear(
1131
- e || this.renderTarget,
1132
- t,
1133
- r,
1134
- this.viewport
1135
- ));
1136
- }
1137
- contextChange() {
1138
- this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
1139
- }
1140
- /**
1141
- * Push a render surface to the renderer. This will bind the render surface to the renderer,
1142
- * @param renderSurface - the render surface to push
1143
- * @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
1144
- * @param clearColor - the color to clear to
1145
- * @param frame - the frame to use when rendering to the render surface
1146
- */
1147
- push(e, t = B.ALL, r, s) {
1148
- const n = this.bind(e, t, r, s);
1149
- return this._renderTargetStack.push({
1150
- renderTarget: n,
1151
- frame: s
1152
- }), n;
1153
- }
1154
- /** Pops the current render target from the renderer and restores the previous render target. */
1155
- pop() {
1156
- this._renderTargetStack.pop();
1157
- const e = this._renderTargetStack[this._renderTargetStack.length - 1];
1158
- this.bind(e.renderTarget, !1, null, e.frame);
1159
- }
1160
- /**
1161
- * Gets the render target from the provide render surface. Eg if its a texture,
1162
- * it will return the render target for the texture.
1163
- * If its a render target, it will return the same render target.
1164
- * @param renderSurface - the render surface to get the render target for
1165
- * @returns the render target for the render surface
1166
- */
1167
- getRenderTarget(e) {
1168
- return e.isTexture && (e = e.source), this._renderSurfaceToRenderTargetHash.get(e) ?? this._initRenderTarget(e);
1169
- }
1170
- /**
1171
- * Copies a render surface to another texture.
1172
- *
1173
- * NOTE:
1174
- * for sourceRenderSurfaceTexture, The render target must be something that is written too by the renderer
1175
- *
1176
- * The following is not valid:
1177
- * @example
1178
- * const canvas = document.createElement('canvas')
1179
- * canvas.width = 200;
1180
- * canvas.height = 200;
1181
- *
1182
- * const ctx = canvas2.getContext('2d')!
1183
- * ctx.fillStyle = 'red'
1184
- * ctx.fillRect(0, 0, 200, 200);
1185
- *
1186
- * const texture = RenderTexture.create({
1187
- * width: 200,
1188
- * height: 200,
1189
- * })
1190
- * const renderTarget = renderer.renderTarget.getRenderTarget(canvas2);
1191
- *
1192
- * renderer.renderTarget.copyToTexture(renderTarget,texture, {x:0,y:0},{width:200,height:200},{x:0,y:0});
1193
- *
1194
- * The best way to copy a canvas is to create a texture from it. Then render with that.
1195
- *
1196
- * Parsing in a RenderTarget canvas context (with a 2d context)
1197
- * @param sourceRenderSurfaceTexture - the render surface to copy from
1198
- * @param destinationTexture - the texture to copy to
1199
- * @param originSrc - the origin of the copy
1200
- * @param originSrc.x - the x origin of the copy
1201
- * @param originSrc.y - the y origin of the copy
1202
- * @param size - the size of the copy
1203
- * @param size.width - the width of the copy
1204
- * @param size.height - the height of the copy
1205
- * @param originDest - the destination origin (top left to paste from!)
1206
- * @param originDest.x - the x origin of the paste
1207
- * @param originDest.y - the y origin of the paste
1208
- */
1209
- copyToTexture(e, t, r, s, n) {
1210
- r.x < 0 && (s.width += r.x, n.x -= r.x, r.x = 0), r.y < 0 && (s.height += r.y, n.y -= r.y, r.y = 0);
1211
- const { pixelWidth: i, pixelHeight: o } = e;
1212
- return s.width = Math.min(s.width, i - r.x), s.height = Math.min(s.height, o - r.y), this.adaptor.copyToTexture(
1213
- e,
1214
- t,
1215
- r,
1216
- s,
1217
- n
1218
- );
1219
- }
1220
- /**
1221
- * ensures that we have a depth stencil buffer available to render to
1222
- * This is used by the mask system to make sure we have a stencil buffer.
1223
- */
1224
- ensureDepthStencil() {
1225
- this.renderTarget.stencil || (this.renderTarget.stencil = !0, this.adaptor.startRenderPass(this.renderTarget, !1, null, this.viewport));
1226
- }
1227
- /** nukes the render target system */
1228
- destroy() {
1229
- this._renderer = null, this._renderSurfaceToRenderTargetHash.forEach((e, t) => {
1230
- e !== t && e.destroy();
1231
- }), this._renderSurfaceToRenderTargetHash.clear(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
1232
- }
1233
- _initRenderTarget(e) {
1234
- let t = null;
1235
- return U.test(e) && (e = ge(e).source), e instanceof I ? t = e : e instanceof T && (t = new I({
1236
- colorTextures: [e]
1237
- }), e.source instanceof U && (t.isRoot = !0), e.once("destroy", () => {
1238
- t.destroy(), this._renderSurfaceToRenderTargetHash.delete(e);
1239
- const r = this._gpuRenderTargetHash[t.uid];
1240
- r && (this._gpuRenderTargetHash[t.uid] = null, this.adaptor.destroyGpuRenderTarget(r));
1241
- })), this._renderSurfaceToRenderTargetHash.set(e, t), t;
1242
- }
1243
- getGpuRenderTarget(e) {
1244
- return this._gpuRenderTargetHash[e.uid] || (this._gpuRenderTargetHash[e.uid] = this.adaptor.initGpuRenderTarget(e));
1245
- }
1246
- resetState() {
1247
- this.renderTarget = null, this.renderSurface = null;
1248
- }
1249
- }
1250
- class Ot extends je {
1251
- /**
1252
- * Create a new Buffer Resource.
1253
- * @param options - The options for the buffer resource
1254
- * @param options.buffer - The underlying buffer that this resource is using
1255
- * @param options.offset - The offset of the buffer this resource is using.
1256
- * If not provided, then it will use the offset of the buffer.
1257
- * @param options.size - The size of the buffer this resource is using.
1258
- * If not provided, then it will use the size of the buffer.
1259
- */
1260
- constructor({ buffer: e, offset: t, size: r }) {
1261
- super(), this.uid = M("buffer"), this._resourceType = "bufferResource", this._touched = 0, this._resourceId = M("resource"), this._bufferResource = !0, this.destroyed = !1, this.buffer = e, this.offset = t | 0, this.size = r, this.buffer.on("change", this.onBufferChange, this);
1262
- }
1263
- onBufferChange() {
1264
- this._resourceId = M("resource"), this.emit("change", this);
1265
- }
1266
- /**
1267
- * Destroys this resource. Make sure the underlying buffer is not used anywhere else
1268
- * if you want to destroy it as well, or code will explode
1269
- * @param destroyBuffer - Should the underlying buffer be destroyed as well?
1270
- */
1271
- destroy(e = !1) {
1272
- this.destroyed = !0, e && this.buffer.destroy(), this.emit("change", this), this.buffer = null;
1273
- }
1274
- }
1275
- class be {
1276
- constructor(e) {
1277
- this._renderer = e;
1278
- }
1279
- updateRenderable() {
1280
- }
1281
- destroyRenderable() {
1282
- }
1283
- validateRenderable() {
1284
- return !1;
1285
- }
1286
- addRenderable(e, t) {
1287
- this._renderer.renderPipes.batch.break(t), t.add(e);
1288
- }
1289
- execute(e) {
1290
- e.isRenderable && e.render(this._renderer);
1291
- }
1292
- destroy() {
1293
- this._renderer = null;
1294
- }
1295
- }
1296
- be.extension = {
1297
- type: [
1298
- u.WebGLPipes,
1299
- u.WebGPUPipes,
1300
- u.CanvasPipes
1301
- ],
1302
- name: "customRender"
1303
- };
1304
- function G(a, e) {
1305
- const t = a.instructionSet, r = t.instructions;
1306
- for (let s = 0; s < t.instructionSize; s++) {
1307
- const n = r[s];
1308
- e[n.renderPipeId].execute(n);
1309
- }
1310
- }
1311
- const ut = new v();
1312
- class Te {
1313
- constructor(e) {
1314
- this._renderer = e;
1315
- }
1316
- addRenderGroup(e, t) {
1317
- e.isCachedAsTexture ? this._addRenderableCacheAsTexture(e, t) : this._addRenderableDirect(e, t);
1318
- }
1319
- execute(e) {
1320
- e.isRenderable && (e.isCachedAsTexture ? this._executeCacheAsTexture(e) : this._executeDirect(e));
1321
- }
1322
- destroy() {
1323
- this._renderer = null;
1324
- }
1325
- _addRenderableDirect(e, t) {
1326
- this._renderer.renderPipes.batch.break(t), e._batchableRenderGroup && (S.return(e._batchableRenderGroup), e._batchableRenderGroup = null), t.add(e);
1327
- }
1328
- _addRenderableCacheAsTexture(e, t) {
1329
- const r = e._batchableRenderGroup ?? (e._batchableRenderGroup = S.get(ce));
1330
- 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);
1331
- }
1332
- _executeCacheAsTexture(e) {
1333
- if (e.textureNeedsUpdate) {
1334
- e.textureNeedsUpdate = !1;
1335
- const t = ut.identity().translate(
1336
- -e._textureBounds.x,
1337
- -e._textureBounds.y
1338
- );
1339
- this._renderer.renderTarget.push(e.texture, !0, null, e.texture.frame), this._renderer.globalUniforms.push({
1340
- worldTransformMatrix: t,
1341
- worldColor: 4294967295,
1342
- offset: { x: 0, y: 0 }
1343
- }), G(e, this._renderer.renderPipes), this._renderer.renderTarget.finishRenderPass(), this._renderer.renderTarget.pop(), this._renderer.globalUniforms.pop();
1344
- }
1345
- e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup), e._batchableRenderGroup._batcher.geometry.buffers[0].update();
1346
- }
1347
- _executeDirect(e) {
1348
- this._renderer.globalUniforms.push({
1349
- worldTransformMatrix: e.inverseParentTextureTransform,
1350
- worldColor: e.worldColorAlpha
1351
- }), G(e, this._renderer.renderPipes), this._renderer.globalUniforms.pop();
1352
- }
1353
- }
1354
- Te.extension = {
1355
- type: [
1356
- u.WebGLPipes,
1357
- u.WebGPUPipes,
1358
- u.CanvasPipes
1359
- ],
1360
- name: "renderGroup"
1361
- };
1362
- function E(a, e) {
1363
- e || (e = 0);
1364
- for (let t = e; t < a.length && a[t]; t++)
1365
- a[t] = null;
1366
- }
1367
- const dt = new P(), te = le | ue | de;
1368
- function ye(a, e = !1) {
1369
- ct(a);
1370
- const t = a.childrenToUpdate, r = a.updateTick++;
1371
- for (const s in t) {
1372
- const n = Number(s), i = t[s], o = i.list, l = i.index;
1373
- for (let d = 0; d < l; d++) {
1374
- const c = o[d];
1375
- c.parentRenderGroup === a && c.relativeRenderGroupDepth === n && ke(c, r, 0);
1376
- }
1377
- E(o, l), i.index = 0;
1378
- }
1379
- if (e)
1380
- for (let s = 0; s < a.renderGroupChildren.length; s++)
1381
- ye(a.renderGroupChildren[s], e);
1382
- }
1383
- function ct(a) {
1384
- const e = a.root;
1385
- let t;
1386
- if (a.renderGroupParent) {
1387
- const r = a.renderGroupParent;
1388
- a.worldTransform.appendFrom(
1389
- e.relativeGroupTransform,
1390
- r.worldTransform
1391
- ), a.worldColor = oe(
1392
- e.groupColor,
1393
- r.worldColor
1394
- ), t = e.groupAlpha * r.worldAlpha;
1395
- } else
1396
- a.worldTransform.copyFrom(e.localTransform), a.worldColor = e.localColor, t = e.localAlpha;
1397
- t = t < 0 ? 0 : t > 1 ? 1 : t, a.worldAlpha = t, a.worldColorAlpha = a.worldColor + ((t * 255 | 0) << 24);
1398
- }
1399
- function ke(a, e, t) {
1400
- if (e === a.updateTick)
1401
- return;
1402
- a.updateTick = e, a.didChange = !1;
1403
- const r = a.localTransform;
1404
- a.updateLocalTransform();
1405
- const s = a.parent;
1406
- if (s && !s.renderGroup ? (t |= a._updateFlags, a.relativeGroupTransform.appendFrom(
1407
- r,
1408
- s.relativeGroupTransform
1409
- ), t & te && re(a, s, t)) : (t = a._updateFlags, a.relativeGroupTransform.copyFrom(r), t & te && re(a, dt, t)), !a.renderGroup) {
1410
- const n = a.children, i = n.length;
1411
- for (let d = 0; d < i; d++)
1412
- ke(n[d], e, t);
1413
- const o = a.parentRenderGroup, l = a;
1414
- l.renderPipeId && !o.structureDidChange && o.updateRenderable(l);
1415
- }
1416
- }
1417
- function re(a, e, t) {
1418
- if (t & ue) {
1419
- a.groupColor = oe(
1420
- a.localColor,
1421
- e.groupColor
1422
- );
1423
- let r = a.localAlpha * e.groupAlpha;
1424
- r = r < 0 ? 0 : r > 1 ? 1 : r, a.groupAlpha = r, a.groupColorAlpha = a.groupColor + ((r * 255 | 0) << 24);
1425
- }
1426
- t & de && (a.groupBlendMode = a.localBlendMode === "inherit" ? e.groupBlendMode : a.localBlendMode), t & le && (a.globalDisplayStatus = a.localDisplayStatus & e.globalDisplayStatus), a._updateFlags = 0;
1427
- }
1428
- function ht(a, e) {
1429
- const { list: t } = a.childrenRenderablesToUpdate;
1430
- let r = !1;
1431
- for (let s = 0; s < a.childrenRenderablesToUpdate.index; s++) {
1432
- const n = t[s];
1433
- if (r = e[n.renderPipeId].validateRenderable(n), r)
1434
- break;
1435
- }
1436
- return a.structureDidChange = r, r;
1437
- }
1438
- const ft = new v();
1439
- class Ce {
1440
- constructor(e) {
1441
- this._renderer = e;
1442
- }
1443
- render({ container: e, transform: t }) {
1444
- const r = e.parent, s = e.renderGroup.renderGroupParent;
1445
- e.parent = null, e.renderGroup.renderGroupParent = null;
1446
- const n = this._renderer, i = ft;
1447
- t && (i.copyFrom(e.renderGroup.localTransform), e.renderGroup.localTransform.copyFrom(t));
1448
- const o = n.renderPipes;
1449
- this._updateCachedRenderGroups(e.renderGroup, null), this._updateRenderGroups(e.renderGroup), n.globalUniforms.start({
1450
- worldTransformMatrix: t ? e.renderGroup.localTransform : e.renderGroup.worldTransform,
1451
- worldColor: e.renderGroup.worldColorAlpha
1452
- }), G(e.renderGroup, o), o.uniformBatch && o.uniformBatch.renderEnd(), t && e.renderGroup.localTransform.copyFrom(i), e.parent = r, e.renderGroup.renderGroupParent = s;
1453
- }
1454
- destroy() {
1455
- this._renderer = null;
1456
- }
1457
- _updateCachedRenderGroups(e, t) {
1458
- if (e._parentCacheAsTextureRenderGroup = t, e.isCachedAsTexture) {
1459
- if (!e.textureNeedsUpdate)
1460
- return;
1461
- t = e;
1462
- }
1463
- for (let r = e.renderGroupChildren.length - 1; r >= 0; r--)
1464
- this._updateCachedRenderGroups(e.renderGroupChildren[r], t);
1465
- if (e.invalidateMatrices(), e.isCachedAsTexture) {
1466
- if (e.textureNeedsUpdate) {
1467
- const r = e.root.getLocalBounds();
1468
- r.ceil();
1469
- const s = e.texture;
1470
- e.texture && b.returnTexture(e.texture, !0);
1471
- const n = this._renderer, i = e.textureOptions.resolution || n.view.resolution, o = e.textureOptions.antialias ?? n.view.antialias, l = e.textureOptions.scaleMode ?? "linear", d = b.getOptimalTexture(
1472
- r.width,
1473
- r.height,
1474
- i,
1475
- o
1476
- );
1477
- d._source.style = new $e({ scaleMode: l }), e.texture = d, e._textureBounds || (e._textureBounds = new O()), e._textureBounds.copyFrom(r), s !== e.texture && e.renderGroupParent && (e.renderGroupParent.structureDidChange = !0);
1478
- }
1479
- } else e.texture && (b.returnTexture(e.texture, !0), e.texture = null);
1480
- }
1481
- _updateRenderGroups(e) {
1482
- const t = this._renderer, r = t.renderPipes;
1483
- if (e.runOnRender(t), e.instructionSet.renderPipes = r, e.structureDidChange ? E(e.childrenRenderablesToUpdate.list, 0) : ht(e, r), ye(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))
1484
- for (let s = 0; s < e.renderGroupChildren.length; s++)
1485
- this._updateRenderGroups(e.renderGroupChildren[s]);
1486
- }
1487
- _updateRenderables(e) {
1488
- const { list: t, index: r } = e.childrenRenderablesToUpdate;
1489
- for (let s = 0; s < r; s++) {
1490
- const n = t[s];
1491
- n.didViewUpdate && e.updateRenderable(n);
1492
- }
1493
- E(t, r);
1494
- }
1495
- _buildInstructions(e, t) {
1496
- const r = e.root, s = e.instructionSet;
1497
- s.reset();
1498
- const n = t.renderPipes ? t : t.batch.renderer, i = n.renderPipes;
1499
- i.batch.buildStart(s), i.blendMode.buildStart(), i.colorMask.buildStart(), r.sortableChildren && r.sortChildren(), r.collectRenderablesWithEffects(s, n, null), i.batch.buildEnd(s), i.blendMode.buildEnd(s);
1500
- }
1501
- }
1502
- Ce.extension = {
1503
- type: [
1504
- u.WebGLSystem,
1505
- u.WebGPUSystem,
1506
- u.CanvasSystem
1507
- ],
1508
- name: "renderGroup"
1509
- };
1510
- class Me {
1511
- constructor(e) {
1512
- this._renderer = e;
1513
- }
1514
- addRenderable(e, t) {
1515
- const r = this._getGpuSprite(e);
1516
- e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
1517
- }
1518
- updateRenderable(e) {
1519
- const t = this._getGpuSprite(e);
1520
- e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
1521
- }
1522
- validateRenderable(e) {
1523
- const t = this._getGpuSprite(e);
1524
- return !t._batcher.checkAndUpdateTexture(
1525
- t,
1526
- e._texture
1527
- );
1528
- }
1529
- _updateBatchableSprite(e, t) {
1530
- t.bounds = e.visualBounds, t.texture = e._texture;
1531
- }
1532
- _getGpuSprite(e) {
1533
- return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
1534
- }
1535
- _initGPUSprite(e) {
1536
- const t = new ce();
1537
- 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;
1538
- }
1539
- destroy() {
1540
- this._renderer = null;
1541
- }
1542
- }
1543
- Me.extension = {
1544
- type: [
1545
- u.WebGLPipes,
1546
- u.WebGPUPipes,
1547
- u.CanvasPipes
1548
- ],
1549
- name: "sprite"
1550
- };
1551
- const W = class Se {
1552
- constructor() {
1553
- this.clearBeforeRender = !0, this._backgroundColor = new A(0), this.color = this._backgroundColor, this.alpha = 1;
1554
- }
1555
- /**
1556
- * initiates the background system
1557
- * @param options - the options for the background colors
1558
- */
1559
- init(e) {
1560
- e = { ...Se.defaultOptions, ...e }, this.clearBeforeRender = e.clearBeforeRender, this.color = e.background || e.backgroundColor || this._backgroundColor, this.alpha = e.backgroundAlpha, this._backgroundColor.setAlpha(e.backgroundAlpha);
1561
- }
1562
- /** The background color to fill if not transparent */
1563
- get color() {
1564
- return this._backgroundColor;
1565
- }
1566
- set color(e) {
1567
- A.shared.setValue(e).alpha < 1 && this._backgroundColor.alpha === 1 && L(
1568
- "Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."
1569
- ), this._backgroundColor.setValue(e);
1570
- }
1571
- /** The background color alpha. Setting this to 0 will make the canvas transparent. */
1572
- get alpha() {
1573
- return this._backgroundColor.alpha;
1574
- }
1575
- set alpha(e) {
1576
- this._backgroundColor.setAlpha(e);
1577
- }
1578
- /** The background color as an [R, G, B, A] array. */
1579
- get colorRgba() {
1580
- return this._backgroundColor.toArray();
1581
- }
1582
- /**
1583
- * destroys the background system
1584
- * @internal
1585
- */
1586
- destroy() {
1587
- }
1588
- };
1589
- W.extension = {
1590
- type: [
1591
- u.WebGLSystem,
1592
- u.WebGPUSystem,
1593
- u.CanvasSystem
1594
- ],
1595
- name: "background",
1596
- priority: 0
1597
- };
1598
- W.defaultOptions = {
1599
- /**
1600
- * {@link WebGLOptions.backgroundAlpha}
1601
- * @default 1
1602
- */
1603
- backgroundAlpha: 1,
1604
- /**
1605
- * {@link WebGLOptions.backgroundColor}
1606
- * @default 0x000000
1607
- */
1608
- backgroundColor: 0,
1609
- /**
1610
- * {@link WebGLOptions.clearBeforeRender}
1611
- * @default true
1612
- */
1613
- clearBeforeRender: !0
1614
- };
1615
- let pt = W;
1616
- const y = {};
1617
- D.handle(u.BlendMode, (a) => {
1618
- if (!a.name)
1619
- throw new Error("BlendMode extension must have a name property");
1620
- y[a.name] = a.ref;
1621
- }, (a) => {
1622
- delete y[a.name];
1623
- });
1624
- class we {
1625
- constructor(e) {
1626
- this._blendModeStack = [], this._isAdvanced = !1, this._filterHash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._renderer.runners.prerender.add(this);
1627
- }
1628
- prerender() {
1629
- this._activeBlendMode = "normal", this._isAdvanced = !1;
1630
- }
1631
- /**
1632
- * Push a blend mode onto the internal stack and apply it to the instruction set if needed.
1633
- * @param renderable - The renderable or {@link RenderGroup} associated with the change.
1634
- * @param blendMode - The blend mode to activate.
1635
- * @param instructionSet - The instruction set being built.
1636
- */
1637
- pushBlendMode(e, t, r) {
1638
- this._blendModeStack.push(t), this.setBlendMode(e, t, r);
1639
- }
1640
- /**
1641
- * Pop the last blend mode from the stack and apply the new top-of-stack mode.
1642
- * @param instructionSet - The instruction set being built.
1643
- */
1644
- popBlendMode(e) {
1645
- this._blendModeStack.pop();
1646
- const t = this._blendModeStack[this._activeBlendMode.length - 1] ?? "normal";
1647
- this.setBlendMode(null, t, e);
1648
- }
1649
- /**
1650
- * Ensure a blend mode switch is added to the instruction set when the mode changes.
1651
- * If an advanced blend mode is active, subsequent renderables will be collected so they can be
1652
- * rendered within a single filter pass.
1653
- * @param renderable - The renderable or {@link RenderGroup} to associate with the change, or null when unwinding.
1654
- * @param blendMode - The target blend mode.
1655
- * @param instructionSet - The instruction set being built.
1656
- */
1657
- setBlendMode(e, t, r) {
1658
- var n;
1659
- const s = e instanceof X;
1660
- if (this._activeBlendMode === t) {
1661
- this._isAdvanced && e && !s && ((n = this._renderableList) == null || n.push(e));
1662
- return;
1663
- }
1664
- this._isAdvanced && this._endAdvancedBlendMode(r), this._activeBlendMode = t, e && (this._isAdvanced = !!y[t], this._isAdvanced && this._beginAdvancedBlendMode(e, r));
1665
- }
1666
- _beginAdvancedBlendMode(e, t) {
1667
- this._renderer.renderPipes.batch.break(t);
1668
- const r = this._activeBlendMode;
1669
- if (!y[r]) {
1670
- L(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
1671
- return;
1672
- }
1673
- const s = this._ensureFilterEffect(r), n = e instanceof X, i = {
1674
- renderPipeId: "filter",
1675
- action: "pushFilter",
1676
- filterEffect: s,
1677
- renderables: n ? null : [e],
1678
- container: n ? e.root : null,
1679
- canBundle: !1
1680
- };
1681
- this._renderableList = i.renderables, t.add(i);
1682
- }
1683
- _ensureFilterEffect(e) {
1684
- let t = this._filterHash[e];
1685
- return t || (t = this._filterHash[e] = new ie(), t.filters = [new y[e]()]), t;
1686
- }
1687
- _endAdvancedBlendMode(e) {
1688
- this._isAdvanced = !1, this._renderableList = null, this._renderer.renderPipes.batch.break(e), e.add({
1689
- renderPipeId: "filter",
1690
- action: "popFilter",
1691
- canBundle: !1
1692
- });
1693
- }
1694
- /**
1695
- * called when the instruction build process is starting this will reset internally to the default blend mode
1696
- * @internal
1697
- */
1698
- buildStart() {
1699
- this._isAdvanced = !1;
1700
- }
1701
- /**
1702
- * called when the instruction build process is finished, ensuring that if there is an advanced blend mode
1703
- * active, we add the final render instructions added to the instruction set
1704
- * @param instructionSet - The instruction set we are adding to
1705
- * @internal
1706
- */
1707
- buildEnd(e) {
1708
- this._isAdvanced && this._endAdvancedBlendMode(e);
1709
- }
1710
- /** @internal */
1711
- destroy() {
1712
- this._renderer = null, this._renderableList = null;
1713
- for (const e in this._filterHash)
1714
- this._filterHash[e].destroy();
1715
- this._filterHash = null;
1716
- }
1717
- }
1718
- we.extension = {
1719
- type: [
1720
- u.WebGLPipes,
1721
- u.WebGPUPipes,
1722
- u.CanvasPipes
1723
- ],
1724
- name: "blendMode"
1725
- };
1726
- const R = {
1727
- png: "image/png",
1728
- jpg: "image/jpeg",
1729
- webp: "image/webp"
1730
- }, V = class Pe {
1731
- /** @param renderer - The renderer this System works for. */
1732
- constructor(e) {
1733
- this._renderer = e;
1734
- }
1735
- _normalizeOptions(e, t = {}) {
1736
- return e instanceof P || e instanceof m ? {
1737
- target: e,
1738
- ...t
1739
- } : {
1740
- ...t,
1741
- ...e
1742
- };
1743
- }
1744
- /**
1745
- * Creates an IImage from a display object or texture.
1746
- * @param options - Options for creating the image, or the target to extract
1747
- * @returns Promise that resolves with the generated IImage
1748
- * @example
1749
- * ```ts
1750
- * // Basic usage with a sprite
1751
- * const sprite = new Sprite(texture);
1752
- * const image = await renderer.extract.image(sprite);
1753
- * document.body.appendChild(image);
1754
- *
1755
- * // Advanced usage with options
1756
- * const image = await renderer.extract.image({
1757
- * target: container,
1758
- * format: 'webp',
1759
- * quality: 0.8,
1760
- * frame: new Rectangle(0, 0, 100, 100),
1761
- * resolution: 2,
1762
- * clearColor: '#ff0000',
1763
- * antialias: true
1764
- * });
1765
- *
1766
- * // Extract directly from a texture
1767
- * const texture = Texture.from('myTexture.png');
1768
- * const image = await renderer.extract.image(texture);
1769
- * ```
1770
- * @see {@link ExtractImageOptions} For detailed options
1771
- * @see {@link ExtractSystem.base64} For base64 string output
1772
- * @see {@link ExtractSystem.canvas} For canvas output
1773
- * @see {@link ImageLike} For the image interface
1774
- * @category rendering
1775
- */
1776
- async image(e) {
1777
- const t = H.get().createImage();
1778
- return t.src = await this.base64(e), t;
1779
- }
1780
- /**
1781
- * Converts the target into a base64 encoded string.
1782
- *
1783
- * This method works by first creating
1784
- * a canvas using `Extract.canvas` and then converting it to a base64 string.
1785
- * @param options - The options for creating the base64 string, or the target to extract
1786
- * @returns Promise that resolves with the base64 encoded string
1787
- * @example
1788
- * ```ts
1789
- * // Basic usage with a sprite
1790
- * const sprite = new Sprite(texture);
1791
- * const base64 = await renderer.extract.base64(sprite);
1792
- * console.log(base64); // data:image/png;base64,...
1793
- *
1794
- * // Advanced usage with options
1795
- * const base64 = await renderer.extract.base64({
1796
- * target: container,
1797
- * format: 'webp',
1798
- * quality: 0.8,
1799
- * frame: new Rectangle(0, 0, 100, 100),
1800
- * resolution: 2
1801
- * });
1802
- * ```
1803
- * @throws Will throw an error if the platform doesn't support any of:
1804
- * - ICanvas.toDataURL
1805
- * - ICanvas.toBlob
1806
- * - ICanvas.convertToBlob
1807
- * @see {@link ExtractImageOptions} For detailed options
1808
- * @see {@link ExtractSystem.canvas} For canvas output
1809
- * @see {@link ExtractSystem.image} For HTMLImage output
1810
- * @category rendering
1811
- */
1812
- async base64(e) {
1813
- e = this._normalizeOptions(
1814
- e,
1815
- Pe.defaultImageOptions
1816
- );
1817
- const { format: t, quality: r } = e, s = this.canvas(e);
1818
- if (s.toBlob !== void 0)
1819
- return new Promise((n, i) => {
1820
- s.toBlob((o) => {
1821
- if (!o) {
1822
- i(new Error("ICanvas.toBlob failed!"));
1823
- return;
1824
- }
1825
- const l = new FileReader();
1826
- l.onload = () => n(l.result), l.onerror = i, l.readAsDataURL(o);
1827
- }, R[t], r);
1828
- });
1829
- if (s.toDataURL !== void 0)
1830
- return s.toDataURL(R[t], r);
1831
- if (s.convertToBlob !== void 0) {
1832
- const n = await s.convertToBlob({ type: R[t], quality: r });
1833
- return new Promise((i, o) => {
1834
- const l = new FileReader();
1835
- l.onload = () => i(l.result), l.onerror = o, l.readAsDataURL(n);
1836
- });
1837
- }
1838
- throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
1839
- }
1840
- /**
1841
- * Creates a Canvas element, renders the target to it and returns it.
1842
- * This method is useful for creating static images or when you need direct canvas access.
1843
- * @param options - The options for creating the canvas, or the target to extract
1844
- * @returns A Canvas element with the texture rendered on
1845
- * @example
1846
- * ```ts
1847
- * // Basic canvas extraction from a sprite
1848
- * const sprite = new Sprite(texture);
1849
- * const canvas = renderer.extract.canvas(sprite);
1850
- * document.body.appendChild(canvas);
1851
- *
1852
- * // Extract with custom region
1853
- * const canvas = renderer.extract.canvas({
1854
- * target: container,
1855
- * frame: new Rectangle(0, 0, 100, 100)
1856
- * });
1857
- *
1858
- * // Extract with high resolution
1859
- * const canvas = renderer.extract.canvas({
1860
- * target: sprite,
1861
- * resolution: 2,
1862
- * clearColor: '#ff0000'
1863
- * });
1864
- *
1865
- * // Extract directly from a texture
1866
- * const texture = Texture.from('myTexture.png');
1867
- * const canvas = renderer.extract.canvas(texture);
1868
- *
1869
- * // Extract with anti-aliasing
1870
- * const canvas = renderer.extract.canvas({
1871
- * target: graphics,
1872
- * antialias: true
1873
- * });
1874
- * ```
1875
- * @see {@link ExtractOptions} For detailed options
1876
- * @see {@link ExtractSystem.image} For HTMLImage output
1877
- * @see {@link ExtractSystem.pixels} For raw pixel data
1878
- * @category rendering
1879
- */
1880
- canvas(e) {
1881
- e = this._normalizeOptions(e);
1882
- const t = e.target, r = this._renderer;
1883
- if (t instanceof m)
1884
- return r.texture.generateCanvas(t);
1885
- const s = r.textureGenerator.generateTexture(e), n = r.texture.generateCanvas(s);
1886
- return s.destroy(!0), n;
1887
- }
1888
- /**
1889
- * Returns a one-dimensional array containing the pixel data of the entire texture in RGBA order,
1890
- * with integer values between 0 and 255 (inclusive).
1891
- * > [!NOE] The returned array is a flat Uint8Array where every 4 values represent RGBA
1892
- * @param options - The options for extracting the image, or the target to extract
1893
- * @returns One-dimensional Uint8Array containing the pixel data in RGBA format
1894
- * @example
1895
- * ```ts
1896
- * // Basic pixel extraction
1897
- * const sprite = new Sprite(texture);
1898
- * const pixels = renderer.extract.pixels(sprite);
1899
- * console.log(pixels[0], pixels[1], pixels[2], pixels[3]); // R,G,B,A values
1900
- *
1901
- * // Extract with custom region
1902
- * const pixels = renderer.extract.pixels({
1903
- * target: sprite,
1904
- * frame: new Rectangle(0, 0, 100, 100)
1905
- * });
1906
- *
1907
- * // Extract with high resolution
1908
- * const pixels = renderer.extract.pixels({
1909
- * target: sprite,
1910
- * resolution: 2
1911
- * });
1912
- * ```
1913
- * @see {@link ExtractOptions} For detailed options
1914
- * @see {@link ExtractSystem.canvas} For canvas output
1915
- * @see {@link ExtractSystem.image} For image output
1916
- * @category rendering
1917
- */
1918
- pixels(e) {
1919
- e = this._normalizeOptions(e);
1920
- const t = e.target, r = this._renderer, s = t instanceof m ? t : r.textureGenerator.generateTexture(e), n = r.texture.getPixels(s);
1921
- return t instanceof P && s.destroy(!0), n;
1922
- }
1923
- /**
1924
- * Creates a texture from a display object or existing texture.
1925
- *
1926
- * This is useful for creating
1927
- * reusable textures from rendered content or making copies of existing textures.
1928
- * > [!NOTE] The returned texture should be destroyed when no longer needed
1929
- * @param options - The options for creating the texture, or the target to extract
1930
- * @returns A new texture containing the extracted content
1931
- * @example
1932
- * ```ts
1933
- * // Basic texture extraction from a sprite
1934
- * const sprite = new Sprite(texture);
1935
- * const extractedTexture = renderer.extract.texture(sprite);
1936
- *
1937
- * // Extract with custom region
1938
- * const regionTexture = renderer.extract.texture({
1939
- * target: container,
1940
- * frame: new Rectangle(0, 0, 100, 100)
1941
- * });
1942
- *
1943
- * // Extract with high resolution
1944
- * const hiResTexture = renderer.extract.texture({
1945
- * target: sprite,
1946
- * resolution: 2,
1947
- * clearColor: '#ff0000'
1948
- * });
1949
- *
1950
- * // Create a new sprite from extracted texture
1951
- * const newSprite = new Sprite(
1952
- * renderer.extract.texture({
1953
- * target: graphics,
1954
- * antialias: true
1955
- * })
1956
- * );
1957
- *
1958
- * // Clean up when done
1959
- * extractedTexture.destroy(true);
1960
- * ```
1961
- * @see {@link ExtractOptions} For detailed options
1962
- * @see {@link Texture} For texture management
1963
- * @see {@link GenerateTextureSystem} For texture generation
1964
- * @category rendering
1965
- */
1966
- texture(e) {
1967
- return e = this._normalizeOptions(e), e.target instanceof m ? e.target : this._renderer.textureGenerator.generateTexture(e);
1968
- }
1969
- /**
1970
- * Extracts and downloads content from the renderer as an image file.
1971
- * This is a convenient way to save screenshots or export rendered content.
1972
- * > [!NOTE] The download will use PNG format regardless of the filename extension
1973
- * @param options - The options for downloading and extracting the image, or the target to extract
1974
- * @example
1975
- * ```ts
1976
- * // Basic download with default filename
1977
- * const sprite = new Sprite(texture);
1978
- * renderer.extract.download(sprite); // Downloads as 'image.png'
1979
- *
1980
- * // Download with custom filename
1981
- * renderer.extract.download({
1982
- * target: sprite,
1983
- * filename: 'screenshot.png'
1984
- * });
1985
- *
1986
- * // Download with custom region
1987
- * renderer.extract.download({
1988
- * target: container,
1989
- * filename: 'region.png',
1990
- * frame: new Rectangle(0, 0, 100, 100)
1991
- * });
1992
- *
1993
- * // Download with high resolution and background
1994
- * renderer.extract.download({
1995
- * target: stage,
1996
- * filename: 'hd-screenshot.png',
1997
- * resolution: 2,
1998
- * clearColor: '#ff0000'
1999
- * });
2000
- *
2001
- * // Download with anti-aliasing
2002
- * renderer.extract.download({
2003
- * target: graphics,
2004
- * filename: 'smooth.png',
2005
- * antialias: true
2006
- * });
2007
- * ```
2008
- * @see {@link ExtractDownloadOptions} For detailed options
2009
- * @see {@link ExtractSystem.image} For creating images without download
2010
- * @see {@link ExtractSystem.canvas} For canvas output
2011
- * @category rendering
2012
- */
2013
- download(e) {
2014
- e = this._normalizeOptions(e);
2015
- const t = this.canvas(e), r = document.createElement("a");
2016
- r.download = e.filename ?? "image.png", r.href = t.toDataURL("image/png"), document.body.appendChild(r), r.click(), document.body.removeChild(r);
2017
- }
2018
- /**
2019
- * Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
2020
- * The image will be displayed in the browser's console using CSS background images.
2021
- * @param options - The options for logging the image, or the target to log
2022
- * @param options.width - The width of the logged image preview in the console (in pixels)
2023
- * @example
2024
- * ```ts
2025
- * // Basic usage
2026
- * const sprite = new Sprite(texture);
2027
- * renderer.extract.log(sprite);
2028
- * ```
2029
- * @see {@link ExtractSystem.canvas} For getting raw canvas output
2030
- * @see {@link ExtractSystem.pixels} For raw pixel data
2031
- * @category rendering
2032
- * @advanced
2033
- */
2034
- log(e) {
2035
- const t = e.width ?? 200;
2036
- e = this._normalizeOptions(e);
2037
- const r = this.canvas(e), s = r.toDataURL();
2038
- console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);
2039
- const n = [
2040
- "font-size: 1px;",
2041
- `padding: ${t}px 300px;`,
2042
- `background: url(${s}) no-repeat;`,
2043
- "background-size: contain;"
2044
- ].join(" ");
2045
- console.log("%c ", n);
2046
- }
2047
- destroy() {
2048
- this._renderer = null;
2049
- }
2050
- };
2051
- V.extension = {
2052
- type: [
2053
- u.WebGLSystem,
2054
- u.WebGPUSystem
2055
- ],
2056
- name: "extract"
2057
- };
2058
- V.defaultImageOptions = {
2059
- format: "png",
2060
- quality: 1
2061
- };
2062
- let mt = V;
2063
- class N extends m {
2064
- static create(e) {
2065
- return new N({
2066
- source: new T(e)
2067
- });
2068
- }
2069
- /**
2070
- * Resizes the render texture.
2071
- * @param width - The new width of the render texture.
2072
- * @param height - The new height of the render texture.
2073
- * @param resolution - The new resolution of the render texture.
2074
- * @returns This texture.
2075
- */
2076
- resize(e, t, r) {
2077
- return this.source.resize(e, t, r), this;
2078
- }
2079
- }
2080
- const vt = new w(), gt = new O(), xt = [0, 0, 0, 0];
2081
- class Re {
2082
- constructor(e) {
2083
- this._renderer = e;
2084
- }
2085
- /**
2086
- * Creates a texture from a display object that can be used for creating sprites and other textures.
2087
- * This is particularly useful for optimizing performance when a complex container needs to be reused.
2088
- * @param options - Generate texture options or a container to convert to texture
2089
- * @returns A new RenderTexture containing the rendered display object
2090
- * @example
2091
- * ```ts
2092
- * // Basic usage with a container
2093
- * const container = new Container();
2094
- * container.addChild(
2095
- * new Graphics()
2096
- * .circle(0, 0, 50)
2097
- * .fill('red')
2098
- * );
2099
- *
2100
- * const texture = renderer.textureGenerator.generateTexture(container);
2101
- *
2102
- * // Advanced usage with options
2103
- * const texture = renderer.textureGenerator.generateTexture({
2104
- * target: container,
2105
- * frame: new Rectangle(0, 0, 100, 100), // Specific region
2106
- * resolution: 2, // High DPI
2107
- * clearColor: '#ff0000', // Red background
2108
- * antialias: true // Smooth edges
2109
- * });
2110
- *
2111
- * // Create a sprite from the generated texture
2112
- * const sprite = new Sprite(texture);
2113
- *
2114
- * // Clean up when done
2115
- * texture.destroy(true);
2116
- * ```
2117
- * @see {@link GenerateTextureOptions} For detailed texture generation options
2118
- * @see {@link RenderTexture} For the type of texture created
2119
- * @category rendering
2120
- */
2121
- generateTexture(e) {
2122
- var d;
2123
- e instanceof P && (e = {
2124
- target: e,
2125
- frame: void 0,
2126
- textureSourceOptions: {},
2127
- resolution: void 0
2128
- });
2129
- const t = e.resolution || this._renderer.resolution, r = e.antialias || this._renderer.view.antialias, s = e.target;
2130
- let n = e.clearColor;
2131
- n ? n = Array.isArray(n) && n.length === 4 ? n : A.shared.setValue(n).toArray() : n = xt;
2132
- const i = ((d = e.frame) == null ? void 0 : d.copyTo(vt)) || qe(s, gt).rectangle;
2133
- i.width = Math.max(i.width, 1 / t) | 0, i.height = Math.max(i.height, 1 / t) | 0;
2134
- const o = N.create({
2135
- ...e.textureSourceOptions,
2136
- width: i.width,
2137
- height: i.height,
2138
- resolution: t,
2139
- antialias: r
2140
- }), l = v.shared.translate(-i.x, -i.y);
2141
- return this._renderer.render({
2142
- container: s,
2143
- transform: l,
2144
- target: o,
2145
- clearColor: n
2146
- }), o.source.updateMipmaps(), o;
2147
- }
2148
- destroy() {
2149
- this._renderer = null;
2150
- }
2151
- }
2152
- Re.extension = {
2153
- type: [
2154
- u.WebGLSystem,
2155
- u.WebGPUSystem
2156
- ],
2157
- name: "textureGenerator"
2158
- };
2159
- class Be {
2160
- constructor(e) {
2161
- this._stackIndex = 0, this._globalUniformDataStack = [], this._uniformsPool = [], this._activeUniforms = [], this._bindGroupPool = [], this._activeBindGroups = [], this._renderer = e;
2162
- }
2163
- reset() {
2164
- this._stackIndex = 0;
2165
- for (let e = 0; e < this._activeUniforms.length; e++)
2166
- this._uniformsPool.push(this._activeUniforms[e]);
2167
- for (let e = 0; e < this._activeBindGroups.length; e++)
2168
- this._bindGroupPool.push(this._activeBindGroups[e]);
2169
- this._activeUniforms.length = 0, this._activeBindGroups.length = 0;
2170
- }
2171
- start(e) {
2172
- this.reset(), this.push(e);
2173
- }
2174
- bind({
2175
- size: e,
2176
- projectionMatrix: t,
2177
- worldTransformMatrix: r,
2178
- worldColor: s,
2179
- offset: n
2180
- }) {
2181
- const i = this._renderer.renderTarget.renderTarget, o = this._stackIndex ? this._globalUniformDataStack[this._stackIndex - 1] : {
2182
- worldTransformMatrix: new v(),
2183
- worldColor: 4294967295,
2184
- offset: new Ke()
2185
- }, l = {
2186
- projectionMatrix: t || this._renderer.renderTarget.projectionMatrix,
2187
- resolution: e || i.size,
2188
- worldTransformMatrix: r || o.worldTransformMatrix,
2189
- worldColor: s || o.worldColor,
2190
- offset: n || o.offset,
2191
- bindGroup: null
2192
- }, d = this._uniformsPool.pop() || this._createUniforms();
2193
- this._activeUniforms.push(d);
2194
- const c = d.uniforms;
2195
- c.uProjectionMatrix = l.projectionMatrix, c.uResolution = l.resolution, c.uWorldTransformMatrix.copyFrom(l.worldTransformMatrix), c.uWorldTransformMatrix.tx -= l.offset.x, c.uWorldTransformMatrix.ty -= l.offset.y, Ze(
2196
- l.worldColor,
2197
- c.uWorldColorAlpha,
2198
- 0
2199
- ), d.update();
2200
- let h;
2201
- this._renderer.renderPipes.uniformBatch ? h = this._renderer.renderPipes.uniformBatch.getUniformBindGroup(d, !1) : (h = this._bindGroupPool.pop() || new Ye(), this._activeBindGroups.push(h), h.setResource(d, 0)), l.bindGroup = h, this._currentGlobalUniformData = l;
2202
- }
2203
- push(e) {
2204
- this.bind(e), this._globalUniformDataStack[this._stackIndex++] = this._currentGlobalUniformData;
2205
- }
2206
- pop() {
2207
- this._currentGlobalUniformData = this._globalUniformDataStack[--this._stackIndex - 1], this._renderer.type === F.WEBGL && this._currentGlobalUniformData.bindGroup.resources[0].update();
2208
- }
2209
- get bindGroup() {
2210
- return this._currentGlobalUniformData.bindGroup;
2211
- }
2212
- get globalUniformData() {
2213
- return this._currentGlobalUniformData;
2214
- }
2215
- get uniformGroup() {
2216
- return this._currentGlobalUniformData.bindGroup.resources[0];
2217
- }
2218
- _createUniforms() {
2219
- return new ae({
2220
- uProjectionMatrix: { value: new v(), type: "mat3x3<f32>" },
2221
- uWorldTransformMatrix: { value: new v(), type: "mat3x3<f32>" },
2222
- // TODO - someone smart - set this to be a unorm8x4 rather than a vec4<f32>
2223
- uWorldColorAlpha: { value: new Float32Array(4), type: "vec4<f32>" },
2224
- uResolution: { value: [0, 0], type: "vec2<f32>" }
2225
- }, {
2226
- isStatic: !0
2227
- });
2228
- }
2229
- destroy() {
2230
- 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;
2231
- }
2232
- }
2233
- Be.extension = {
2234
- type: [
2235
- u.WebGLSystem,
2236
- u.WebGPUSystem,
2237
- u.CanvasSystem
2238
- ],
2239
- name: "globalUniforms"
2240
- };
2241
- let _t = 1;
2242
- class Ue {
2243
- constructor() {
2244
- this._tasks = [], this._offset = 0;
2245
- }
2246
- /** Initializes the scheduler system and starts the ticker. */
2247
- init() {
2248
- Q.system.add(this._update, this);
2249
- }
2250
- /**
2251
- * Schedules a repeating task.
2252
- * @param func - The function to execute.
2253
- * @param duration - The interval duration in milliseconds.
2254
- * @param useOffset - this will spread out tasks so that they do not all run at the same time
2255
- * @returns The unique identifier for the scheduled task.
2256
- */
2257
- repeat(e, t, r = !0) {
2258
- const s = _t++;
2259
- let n = 0;
2260
- return r && (this._offset += 1e3, n = this._offset), this._tasks.push({
2261
- func: e,
2262
- duration: t,
2263
- start: performance.now(),
2264
- offset: n,
2265
- last: performance.now(),
2266
- repeat: !0,
2267
- id: s
2268
- }), s;
2269
- }
2270
- /**
2271
- * Cancels a scheduled task.
2272
- * @param id - The unique identifier of the task to cancel.
2273
- */
2274
- cancel(e) {
2275
- for (let t = 0; t < this._tasks.length; t++)
2276
- if (this._tasks[t].id === e) {
2277
- this._tasks.splice(t, 1);
2278
- return;
2279
- }
2280
- }
2281
- /**
2282
- * Updates and executes the scheduled tasks.
2283
- * @private
2284
- */
2285
- _update() {
2286
- const e = performance.now();
2287
- for (let t = 0; t < this._tasks.length; t++) {
2288
- const r = this._tasks[t];
2289
- if (e - r.offset - r.last >= r.duration) {
2290
- const s = e - r.start;
2291
- r.func(s), r.last = e;
2292
- }
2293
- }
2294
- }
2295
- /**
2296
- * Destroys the scheduler system and removes all tasks.
2297
- * @internal
2298
- */
2299
- destroy() {
2300
- Q.system.remove(this._update, this), this._tasks.length = 0;
2301
- }
2302
- }
2303
- Ue.extension = {
2304
- type: [
2305
- u.WebGLSystem,
2306
- u.WebGPUSystem,
2307
- u.CanvasSystem
2308
- ],
2309
- name: "scheduler",
2310
- priority: 0
2311
- };
2312
- let se = !1;
2313
- function bt(a) {
2314
- if (!se) {
2315
- if (H.get().getNavigator().userAgent.toLowerCase().indexOf("chrome") > -1) {
2316
- const e = [
2317
- `%c %c %c %c %c PixiJS %c v${Z} (${a}) http://www.pixijs.com/
2318
-
2319
- `,
2320
- "background: #E72264; padding:5px 0;",
2321
- "background: #6CA2EA; padding:5px 0;",
2322
- "background: #B5D33D; padding:5px 0;",
2323
- "background: #FED23F; padding:5px 0;",
2324
- "color: #FFFFFF; background: #E72264; padding:5px 0;",
2325
- "color: #E72264; background: #FFFFFF; padding:5px 0;"
2326
- ];
2327
- globalThis.console.log(...e);
2328
- } else globalThis.console && globalThis.console.log(`PixiJS ${Z} - ${a} - http://www.pixijs.com/`);
2329
- se = !0;
2330
- }
2331
- }
2332
- class j {
2333
- constructor(e) {
2334
- this._renderer = e;
2335
- }
2336
- /**
2337
- * It all starts here! This initiates every system, passing in the options for any system by name.
2338
- * @param options - the config for the renderer and all its systems
2339
- */
2340
- init(e) {
2341
- if (e.hello) {
2342
- let t = this._renderer.name;
2343
- this._renderer.type === F.WEBGL && (t += ` ${this._renderer.context.webGLVersion}`), bt(t);
2344
- }
2345
- }
2346
- }
2347
- j.extension = {
2348
- type: [
2349
- u.WebGLSystem,
2350
- u.WebGPUSystem,
2351
- u.CanvasSystem
2352
- ],
2353
- name: "hello",
2354
- priority: -2
2355
- };
2356
- j.defaultOptions = {
2357
- /** {@link WebGLOptions.hello} */
2358
- hello: !1
2359
- };
2360
- function Tt(a) {
2361
- let e = !1;
2362
- for (const r in a)
2363
- if (a[r] == null) {
2364
- e = !0;
2365
- break;
2366
- }
2367
- if (!e)
2368
- return a;
2369
- const t = /* @__PURE__ */ Object.create(null);
2370
- for (const r in a) {
2371
- const s = a[r];
2372
- s && (t[r] = s);
2373
- }
2374
- return t;
2375
- }
2376
- function yt(a) {
2377
- let e = 0;
2378
- for (let t = 0; t < a.length; t++)
2379
- a[t] == null ? e++ : a[t - e] = a[t];
2380
- return a.length -= e, a;
2381
- }
2382
- let kt = 0;
2383
- const $ = class Ae {
2384
- /**
2385
- * Creates a new RenderableGCSystem instance.
2386
- * @param renderer - The renderer this garbage collection system works for
2387
- */
2388
- constructor(e) {
2389
- this._managedRenderables = [], this._managedHashes = [], this._managedArrays = [], this._renderer = e;
2390
- }
2391
- /**
2392
- * Initializes the garbage collection system with the provided options.
2393
- * @param options - Configuration options for the renderer
2394
- */
2395
- init(e) {
2396
- e = { ...Ae.defaultOptions, ...e }, this.maxUnusedTime = e.renderableGCMaxUnusedTime, this._frequency = e.renderableGCFrequency, this.enabled = e.renderableGCActive;
2397
- }
2398
- /**
2399
- * Gets whether the garbage collection system is currently enabled.
2400
- * @returns True if GC is enabled, false otherwise
2401
- */
2402
- get enabled() {
2403
- return !!this._handler;
2404
- }
2405
- /**
2406
- * Enables or disables the garbage collection system.
2407
- * When enabled, schedules periodic cleanup of resources.
2408
- * When disabled, cancels all scheduled cleanups.
2409
- */
2410
- set enabled(e) {
2411
- this.enabled !== e && (e ? (this._handler = this._renderer.scheduler.repeat(
2412
- () => this.run(),
2413
- this._frequency,
2414
- !1
2415
- ), this._hashHandler = this._renderer.scheduler.repeat(
2416
- () => {
2417
- for (const t of this._managedHashes)
2418
- t.context[t.hash] = Tt(t.context[t.hash]);
2419
- },
2420
- this._frequency
2421
- ), this._arrayHandler = this._renderer.scheduler.repeat(
2422
- () => {
2423
- for (const t of this._managedArrays)
2424
- yt(t.context[t.hash]);
2425
- },
2426
- this._frequency
2427
- )) : (this._renderer.scheduler.cancel(this._handler), this._renderer.scheduler.cancel(this._hashHandler), this._renderer.scheduler.cancel(this._arrayHandler)));
2428
- }
2429
- /**
2430
- * Adds a hash table to be managed by the garbage collector.
2431
- * @param context - The object containing the hash table
2432
- * @param hash - The property name of the hash table
2433
- */
2434
- addManagedHash(e, t) {
2435
- this._managedHashes.push({ context: e, hash: t });
2436
- }
2437
- /**
2438
- * Adds an array to be managed by the garbage collector.
2439
- * @param context - The object containing the array
2440
- * @param hash - The property name of the array
2441
- */
2442
- addManagedArray(e, t) {
2443
- this._managedArrays.push({ context: e, hash: t });
2444
- }
2445
- /**
2446
- * Updates the GC timestamp and tracking before rendering.
2447
- * @param options - The render options
2448
- * @param options.container - The container to render
2449
- */
2450
- prerender({
2451
- container: e
2452
- }) {
2453
- this._now = performance.now(), e.renderGroup.gcTick = kt++, this._updateInstructionGCTick(e.renderGroup, e.renderGroup.gcTick);
2454
- }
2455
- /**
2456
- * Starts tracking a renderable for garbage collection.
2457
- * @param renderable - The renderable to track
2458
- */
2459
- addRenderable(e) {
2460
- this.enabled && (e._lastUsed === -1 && (this._managedRenderables.push(e), e.once("destroyed", this._removeRenderable, this)), e._lastUsed = this._now);
2461
- }
2462
- /**
2463
- * Performs garbage collection by cleaning up unused renderables.
2464
- * Removes renderables that haven't been used for longer than maxUnusedTime.
2465
- */
2466
- run() {
2467
- var n;
2468
- const e = this._now, t = this._managedRenderables, r = this._renderer.renderPipes;
2469
- let s = 0;
2470
- for (let i = 0; i < t.length; i++) {
2471
- const o = t[i];
2472
- if (o === null) {
2473
- s++;
2474
- continue;
2475
- }
2476
- const l = o.renderGroup ?? o.parentRenderGroup, d = ((n = l == null ? void 0 : l.instructionSet) == null ? void 0 : n.gcTick) ?? -1;
2477
- if (((l == null ? void 0 : l.gcTick) ?? 0) === d && (o._lastUsed = e), e - o._lastUsed > this.maxUnusedTime) {
2478
- if (!o.destroyed) {
2479
- const c = r;
2480
- l && (l.structureDidChange = !0), c[o.renderPipeId].destroyRenderable(o);
2481
- }
2482
- o._lastUsed = -1, s++, o.off("destroyed", this._removeRenderable, this);
2483
- } else
2484
- t[i - s] = o;
2485
- }
2486
- t.length -= s;
2487
- }
2488
- /** Cleans up the garbage collection system. Disables GC and removes all tracked resources. */
2489
- destroy() {
2490
- this.enabled = !1, this._renderer = null, this._managedRenderables.length = 0, this._managedHashes.length = 0, this._managedArrays.length = 0;
2491
- }
2492
- /**
2493
- * Removes a renderable from being tracked when it's destroyed.
2494
- * @param renderable - The renderable to stop tracking
2495
- */
2496
- _removeRenderable(e) {
2497
- const t = this._managedRenderables.indexOf(e);
2498
- t >= 0 && (e.off("destroyed", this._removeRenderable, this), this._managedRenderables[t] = null);
2499
- }
2500
- /**
2501
- * Updates the GC tick counter for a render group and its children.
2502
- * @param renderGroup - The render group to update
2503
- * @param gcTick - The new tick value
2504
- */
2505
- _updateInstructionGCTick(e, t) {
2506
- e.instructionSet.gcTick = t;
2507
- for (const r of e.renderGroupChildren)
2508
- this._updateInstructionGCTick(r, t);
2509
- }
2510
- };
2511
- $.extension = {
2512
- type: [
2513
- u.WebGLSystem,
2514
- u.WebGPUSystem
2515
- ],
2516
- name: "renderableGC",
2517
- priority: 0
2518
- };
2519
- $.defaultOptions = {
2520
- /** Enable/disable the garbage collector */
2521
- renderableGCActive: !0,
2522
- /** Time in ms before an unused resource is collected (default 1 minute) */
2523
- renderableGCMaxUnusedTime: 6e4,
2524
- /** How often to run garbage collection in ms (default 30 seconds) */
2525
- renderableGCFrequency: 3e4
2526
- };
2527
- let Ct = $;
2528
- const q = class Ie {
2529
- /** @param renderer - The renderer this System works for. */
2530
- constructor(e) {
2531
- this._renderer = e, this.count = 0, this.checkCount = 0;
2532
- }
2533
- init(e) {
2534
- e = { ...Ie.defaultOptions, ...e }, this.checkCountMax = e.textureGCCheckCountMax, this.maxIdle = e.textureGCAMaxIdle ?? e.textureGCMaxIdle, this.active = e.textureGCActive;
2535
- }
2536
- /**
2537
- * Checks to see when the last time a texture was used.
2538
- * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2539
- */
2540
- postrender() {
2541
- this._renderer.renderingToScreen && (this.count++, this.active && (this.checkCount++, this.checkCount > this.checkCountMax && (this.checkCount = 0, this.run())));
2542
- }
2543
- /**
2544
- * Checks to see when the last time a texture was used.
2545
- * If the texture has not been used for a specified amount of time, it will be removed from the GPU.
2546
- */
2547
- run() {
2548
- const e = this._renderer.texture.managedTextures;
2549
- for (let t = 0; t < e.length; t++) {
2550
- const r = e[t];
2551
- r.autoGarbageCollect && r.resource && r._touched > -1 && this.count - r._touched > this.maxIdle && (r._touched = -1, r.unload());
2552
- }
2553
- }
2554
- destroy() {
2555
- this._renderer = null;
2556
- }
2557
- };
2558
- q.extension = {
2559
- type: [
2560
- u.WebGLSystem,
2561
- u.WebGPUSystem
2562
- ],
2563
- name: "textureGC"
2564
- };
2565
- q.defaultOptions = {
2566
- /**
2567
- * If set to true, this will enable the garbage collector on the GPU.
2568
- * @default true
2569
- */
2570
- textureGCActive: !0,
2571
- /**
2572
- * @deprecated since 8.3.0
2573
- * @see {@link TextureGCSystemOptions.textureGCMaxIdle}
2574
- */
2575
- textureGCAMaxIdle: null,
2576
- /**
2577
- * The maximum idle frames before a texture is destroyed by garbage collection.
2578
- * @default 60 * 60
2579
- */
2580
- textureGCMaxIdle: 3600,
2581
- /**
2582
- * Frames between two garbage collections.
2583
- * @default 600
2584
- */
2585
- textureGCCheckCountMax: 600
2586
- };
2587
- let Mt = q;
2588
- const K = class Ge {
2589
- /**
2590
- * Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.
2591
- * This is only supported for HTMLCanvasElement and will be ignored if the canvas is an OffscreenCanvas.
2592
- * @type {boolean}
2593
- */
2594
- get autoDensity() {
2595
- return this.texture.source.autoDensity;
2596
- }
2597
- set autoDensity(e) {
2598
- this.texture.source.autoDensity = e;
2599
- }
2600
- /** The resolution / device pixel ratio of the renderer. */
2601
- get resolution() {
2602
- return this.texture.source._resolution;
2603
- }
2604
- set resolution(e) {
2605
- this.texture.source.resize(
2606
- this.texture.source.width,
2607
- this.texture.source.height,
2608
- e
2609
- );
2610
- }
2611
- /**
2612
- * initiates the view system
2613
- * @param options - the options for the view
2614
- */
2615
- init(e) {
2616
- e = {
2617
- ...Ge.defaultOptions,
2618
- ...e
2619
- }, e.view && (Je(Xe, "ViewSystem.view has been renamed to ViewSystem.canvas"), e.canvas = e.view), this.screen = new w(0, 0, e.width, e.height), this.canvas = e.canvas || H.get().createCanvas(), this.antialias = !!e.antialias, this.texture = ge(this.canvas, e), this.renderTarget = new I({
2620
- colorTextures: [this.texture],
2621
- depth: !!e.depth,
2622
- isRoot: !0
2623
- }), this.texture.source.transparent = e.backgroundAlpha < 1, this.resolution = e.resolution;
2624
- }
2625
- /**
2626
- * Resizes the screen and canvas to the specified dimensions.
2627
- * @param desiredScreenWidth - The new width of the screen.
2628
- * @param desiredScreenHeight - The new height of the screen.
2629
- * @param resolution
2630
- */
2631
- resize(e, t, r) {
2632
- this.texture.source.resize(e, t, r), this.screen.width = this.texture.frame.width, this.screen.height = this.texture.frame.height;
2633
- }
2634
- /**
2635
- * Destroys this System and optionally removes the canvas from the dom.
2636
- * @param {options | false} options - The options for destroying the view, or "false".
2637
- * @example
2638
- * viewSystem.destroy();
2639
- * viewSystem.destroy(true);
2640
- * viewSystem.destroy({ removeView: true });
2641
- */
2642
- destroy(e = !1) {
2643
- (typeof e == "boolean" ? e : !!(e != null && e.removeView)) && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas), this.texture.destroy();
2644
- }
2645
- };
2646
- K.extension = {
2647
- type: [
2648
- u.WebGLSystem,
2649
- u.WebGPUSystem,
2650
- u.CanvasSystem
2651
- ],
2652
- name: "view",
2653
- priority: 0
2654
- };
2655
- K.defaultOptions = {
2656
- /**
2657
- * {@link WebGLOptions.width}
2658
- * @default 800
2659
- */
2660
- width: 800,
2661
- /**
2662
- * {@link WebGLOptions.height}
2663
- * @default 600
2664
- */
2665
- height: 600,
2666
- /**
2667
- * {@link WebGLOptions.autoDensity}
2668
- * @default false
2669
- */
2670
- autoDensity: !1,
2671
- /**
2672
- * {@link WebGLOptions.antialias}
2673
- * @default false
2674
- */
2675
- antialias: !1
2676
- };
2677
- let St = K;
2678
- const Ft = [
2679
- pt,
2680
- Be,
2681
- j,
2682
- St,
2683
- Ce,
2684
- Mt,
2685
- Re,
2686
- mt,
2687
- Qe,
2688
- Ct,
2689
- Ue
2690
- ], Lt = [
2691
- we,
2692
- fe,
2693
- Me,
2694
- Te,
2695
- pe,
2696
- ve,
2697
- me,
2698
- be
2699
- ];
2700
- export {
2701
- Ot as B,
2702
- _ as G,
2703
- Dt as R,
2704
- Ft as S,
2705
- It as U,
2706
- Lt as a,
2707
- it as b,
2708
- Gt as c,
2709
- C as d,
2710
- At as e,
2711
- Ut as f,
2712
- Bt as t,
2713
- Et as u
2714
- };
2715
- //# sourceMappingURL=SharedSystems-D2AiAlOX.js.map