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