evotars 0.0.11 → 0.0.12
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/dist/CanvasPool-5ekdWScU.js +46 -0
- package/dist/SharedSystems-n7sA1Ui-.js +2134 -0
- package/dist/WebGLRenderer-BUvcWTmB.js +2564 -0
- package/dist/WebGPURenderer-BPb_585F.js +1561 -0
- package/dist/browserAll-DR-9ZkSp.js +1968 -0
- package/dist/colorToUniform-Cp4M-zOy.js +1308 -0
- package/dist/evotars.js +6 -26282
- package/dist/evotars.umd.cjs +902 -1069
- package/dist/getBatchSamplersUniformGroup-CIYh8OT7.js +16 -0
- package/dist/index-B5GUB2He.js +14036 -0
- package/dist/index.d.ts +9 -21
- package/dist/webworkerAll-Bg_9Ksbn.js +2661 -0
- package/package.json +3 -3
|
@@ -0,0 +1,2134 @@
|
|
|
1
|
+
import { l as Re, M as g, o as Be, p as Ue, E as u, q as b, s as Ae, t as q, F as K, v as Ie, j as m, S as p, d as B, w as Y, x as Fe, b as H, B as k, h as U, u as C, i as _, R as w, y as Ee, a as De, C as S, z as Oe, G as ze, H as He, I as J, e as X, J as Le, P as We, c as Ve, D as Q, K as je, L as $e } from "./index-B5GUB2He.js";
|
|
2
|
+
import { b as Ne, S as Z, G as ee, f as te, U as re, T as L, h as W, B as qe, i as Ke, R as se } from "./colorToUniform-Cp4M-zOy.js";
|
|
3
|
+
const ae = class A extends Ne {
|
|
4
|
+
/**
|
|
5
|
+
* @param options - The optional parameters of this filter.
|
|
6
|
+
*/
|
|
7
|
+
constructor(e) {
|
|
8
|
+
e = { ...A.defaultOptions, ...e }, super(e), this.enabled = !0, this._state = Z.for2d(), this.padding = e.padding, typeof e.antialias == "boolean" ? this.antialias = e.antialias ? "on" : "off" : this.antialias = e.antialias, this.resolution = e.resolution, this.blendRequired = e.blendRequired, this.addResource("uTexture", 0, 1);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Applies the filter
|
|
12
|
+
* @param filterManager - The renderer to retrieve the filter from
|
|
13
|
+
* @param input - The input render target.
|
|
14
|
+
* @param output - The target to output to.
|
|
15
|
+
* @param clearMode - Should the output be cleared before rendering to it
|
|
16
|
+
*/
|
|
17
|
+
apply(e, t, r, a) {
|
|
18
|
+
e.applyFilter(this, t, r, a);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the blend mode of the filter.
|
|
22
|
+
* @default "normal"
|
|
23
|
+
*/
|
|
24
|
+
get blendMode() {
|
|
25
|
+
return this._state.blendMode;
|
|
26
|
+
}
|
|
27
|
+
/** Sets the blend mode of the filter. */
|
|
28
|
+
set blendMode(e) {
|
|
29
|
+
this._state.blendMode = e;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A short hand function to create a filter based of a vertex and fragment shader src.
|
|
33
|
+
* @param options
|
|
34
|
+
* @returns A shiny new PixiJS filter!
|
|
35
|
+
*/
|
|
36
|
+
static from(e) {
|
|
37
|
+
const { gpu: t, gl: r, ...a } = e;
|
|
38
|
+
let n, i;
|
|
39
|
+
return t && (n = ee.from(t)), r && (i = te.from(r)), new A({
|
|
40
|
+
gpuProgram: n,
|
|
41
|
+
glProgram: i,
|
|
42
|
+
...a
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
ae.defaultOptions = {
|
|
47
|
+
blendMode: "normal",
|
|
48
|
+
resolution: 1,
|
|
49
|
+
padding: 0,
|
|
50
|
+
antialias: "off",
|
|
51
|
+
blendRequired: !1
|
|
52
|
+
};
|
|
53
|
+
let Ye = ae;
|
|
54
|
+
var Je = `in vec2 vMaskCoord;
|
|
55
|
+
in vec2 vTextureCoord;
|
|
56
|
+
|
|
57
|
+
uniform sampler2D uTexture;
|
|
58
|
+
uniform sampler2D uMaskTexture;
|
|
59
|
+
|
|
60
|
+
uniform float uAlpha;
|
|
61
|
+
uniform vec4 uMaskClamp;
|
|
62
|
+
|
|
63
|
+
out vec4 finalColor;
|
|
64
|
+
|
|
65
|
+
void main(void)
|
|
66
|
+
{
|
|
67
|
+
float clip = step(3.5,
|
|
68
|
+
step(uMaskClamp.x, vMaskCoord.x) +
|
|
69
|
+
step(uMaskClamp.y, vMaskCoord.y) +
|
|
70
|
+
step(vMaskCoord.x, uMaskClamp.z) +
|
|
71
|
+
step(vMaskCoord.y, uMaskClamp.w));
|
|
72
|
+
|
|
73
|
+
// TODO look into why this is needed
|
|
74
|
+
float npmAlpha = uAlpha;
|
|
75
|
+
vec4 original = texture(uTexture, vTextureCoord);
|
|
76
|
+
vec4 masky = texture(uMaskTexture, vMaskCoord);
|
|
77
|
+
float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
|
|
78
|
+
|
|
79
|
+
original *= (alphaMul * masky.r * uAlpha * clip);
|
|
80
|
+
|
|
81
|
+
finalColor = original;
|
|
82
|
+
}
|
|
83
|
+
`, Xe = `in vec2 aPosition;
|
|
84
|
+
|
|
85
|
+
out vec2 vTextureCoord;
|
|
86
|
+
out vec2 vMaskCoord;
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
uniform vec4 uInputSize;
|
|
90
|
+
uniform vec4 uOutputFrame;
|
|
91
|
+
uniform vec4 uOutputTexture;
|
|
92
|
+
uniform mat3 uFilterMatrix;
|
|
93
|
+
|
|
94
|
+
vec4 filterVertexPosition( vec2 aPosition )
|
|
95
|
+
{
|
|
96
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
97
|
+
|
|
98
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
99
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
100
|
+
|
|
101
|
+
return vec4(position, 0.0, 1.0);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
vec2 filterTextureCoord( vec2 aPosition )
|
|
105
|
+
{
|
|
106
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
vec2 getFilterCoord( vec2 aPosition )
|
|
110
|
+
{
|
|
111
|
+
return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
void main(void)
|
|
115
|
+
{
|
|
116
|
+
gl_Position = filterVertexPosition(aPosition);
|
|
117
|
+
vTextureCoord = filterTextureCoord(aPosition);
|
|
118
|
+
vMaskCoord = getFilterCoord(aPosition);
|
|
119
|
+
}
|
|
120
|
+
`, V = `struct GlobalFilterUniforms {
|
|
121
|
+
uInputSize:vec4<f32>,
|
|
122
|
+
uInputPixel:vec4<f32>,
|
|
123
|
+
uInputClamp:vec4<f32>,
|
|
124
|
+
uOutputFrame:vec4<f32>,
|
|
125
|
+
uGlobalFrame:vec4<f32>,
|
|
126
|
+
uOutputTexture:vec4<f32>,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
struct MaskUniforms {
|
|
130
|
+
uFilterMatrix:mat3x3<f32>,
|
|
131
|
+
uMaskClamp:vec4<f32>,
|
|
132
|
+
uAlpha:f32,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
137
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
138
|
+
@group(0) @binding(2) var uSampler : sampler;
|
|
139
|
+
|
|
140
|
+
@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
|
|
141
|
+
@group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
|
|
142
|
+
|
|
143
|
+
struct VSOutput {
|
|
144
|
+
@builtin(position) position: vec4<f32>,
|
|
145
|
+
@location(0) uv : vec2<f32>,
|
|
146
|
+
@location(1) filterUv : vec2<f32>,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
150
|
+
{
|
|
151
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
152
|
+
|
|
153
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
154
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
155
|
+
|
|
156
|
+
return vec4(position, 0.0, 1.0);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
160
|
+
{
|
|
161
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
165
|
+
{
|
|
166
|
+
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
|
|
170
|
+
{
|
|
171
|
+
return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn getSize() -> vec2<f32>
|
|
175
|
+
{
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
return gfu.uGlobalFrame.zw;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@vertex
|
|
182
|
+
fn mainVertex(
|
|
183
|
+
@location(0) aPosition : vec2<f32>,
|
|
184
|
+
) -> VSOutput {
|
|
185
|
+
return VSOutput(
|
|
186
|
+
filterVertexPosition(aPosition),
|
|
187
|
+
filterTextureCoord(aPosition),
|
|
188
|
+
getFilterCoord(aPosition)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@fragment
|
|
193
|
+
fn mainFragment(
|
|
194
|
+
@location(0) uv: vec2<f32>,
|
|
195
|
+
@location(1) filterUv: vec2<f32>,
|
|
196
|
+
@builtin(position) position: vec4<f32>
|
|
197
|
+
) -> @location(0) vec4<f32> {
|
|
198
|
+
|
|
199
|
+
var maskClamp = filterUniforms.uMaskClamp;
|
|
200
|
+
|
|
201
|
+
var clip = step(3.5,
|
|
202
|
+
step(maskClamp.x, filterUv.x) +
|
|
203
|
+
step(maskClamp.y, filterUv.y) +
|
|
204
|
+
step(filterUv.x, maskClamp.z) +
|
|
205
|
+
step(filterUv.y, maskClamp.w));
|
|
206
|
+
|
|
207
|
+
var mask = textureSample(uMaskTexture, uSampler, filterUv);
|
|
208
|
+
var source = textureSample(uTexture, uSampler, uv);
|
|
209
|
+
|
|
210
|
+
var npmAlpha = 0.0;
|
|
211
|
+
|
|
212
|
+
var alphaMul = 1.0 - npmAlpha * (1.0 - mask.a);
|
|
213
|
+
|
|
214
|
+
var a = (alphaMul * mask.r) * clip;
|
|
215
|
+
|
|
216
|
+
return vec4(source.rgb, source.a) * a;
|
|
217
|
+
}`;
|
|
218
|
+
class Qe extends Ye {
|
|
219
|
+
constructor(e) {
|
|
220
|
+
const { sprite: t, ...r } = e, a = new Re(t.texture), n = new re({
|
|
221
|
+
uFilterMatrix: { value: new g(), type: "mat3x3<f32>" },
|
|
222
|
+
uMaskClamp: { value: a.uClampFrame, type: "vec4<f32>" },
|
|
223
|
+
uAlpha: { value: 1, type: "f32" }
|
|
224
|
+
}), i = ee.from({
|
|
225
|
+
vertex: {
|
|
226
|
+
source: V,
|
|
227
|
+
entryPoint: "mainVertex"
|
|
228
|
+
},
|
|
229
|
+
fragment: {
|
|
230
|
+
source: V,
|
|
231
|
+
entryPoint: "mainFragment"
|
|
232
|
+
}
|
|
233
|
+
}), l = te.from({
|
|
234
|
+
vertex: Xe,
|
|
235
|
+
fragment: Je,
|
|
236
|
+
name: "mask-filter"
|
|
237
|
+
});
|
|
238
|
+
super({
|
|
239
|
+
...r,
|
|
240
|
+
gpuProgram: i,
|
|
241
|
+
glProgram: l,
|
|
242
|
+
resources: {
|
|
243
|
+
filterUniforms: n,
|
|
244
|
+
uMaskTexture: t.texture.source
|
|
245
|
+
}
|
|
246
|
+
}), this.sprite = t, this._textureMatrix = a;
|
|
247
|
+
}
|
|
248
|
+
apply(e, t, r, a) {
|
|
249
|
+
this._textureMatrix.texture = this.sprite.texture, e.calculateSpriteMatrix(
|
|
250
|
+
this.resources.filterUniforms.uniforms.uFilterMatrix,
|
|
251
|
+
this.sprite
|
|
252
|
+
).prepend(this._textureMatrix.mapCoord), this.resources.uMaskTexture = this.sprite.texture.source, e.applyFilter(this, t, r, a);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
class ne {
|
|
256
|
+
constructor(e, t) {
|
|
257
|
+
this.state = Z.for2d(), this._batches = /* @__PURE__ */ Object.create(null), this._geometries = /* @__PURE__ */ Object.create(null), this.renderer = e, this._adaptor = t, this._adaptor.init(this);
|
|
258
|
+
}
|
|
259
|
+
buildStart(e) {
|
|
260
|
+
if (!this._batches[e.uid]) {
|
|
261
|
+
const t = new Be();
|
|
262
|
+
this._batches[e.uid] = t, this._geometries[t.uid] = new Ue();
|
|
263
|
+
}
|
|
264
|
+
this._activeBatch = this._batches[e.uid], this._activeGeometry = this._geometries[this._activeBatch.uid], this._activeBatch.begin();
|
|
265
|
+
}
|
|
266
|
+
addToBatch(e) {
|
|
267
|
+
this._activeBatch.add(e);
|
|
268
|
+
}
|
|
269
|
+
break(e) {
|
|
270
|
+
this._activeBatch.break(e);
|
|
271
|
+
}
|
|
272
|
+
buildEnd(e) {
|
|
273
|
+
const t = this._activeBatch, r = this._activeGeometry;
|
|
274
|
+
t.finish(e), r.indexBuffer.setDataWithSize(t.indexBuffer, t.indexSize, !0), r.buffers[0].setDataWithSize(t.attributeBuffer.float32View, t.attributeSize, !1);
|
|
275
|
+
}
|
|
276
|
+
upload(e) {
|
|
277
|
+
const t = this._batches[e.uid], r = this._geometries[t.uid];
|
|
278
|
+
t.dirty && (t.dirty = !1, r.buffers[0].update(t.attributeSize * 4));
|
|
279
|
+
}
|
|
280
|
+
execute(e) {
|
|
281
|
+
if (e.action === "startBatch") {
|
|
282
|
+
const t = e.batcher, r = this._geometries[t.uid];
|
|
283
|
+
this._adaptor.start(this, r);
|
|
284
|
+
}
|
|
285
|
+
this._adaptor.execute(this, e);
|
|
286
|
+
}
|
|
287
|
+
destroy() {
|
|
288
|
+
this.state = null, this.renderer = null, this._adaptor.destroy(), this._adaptor = null;
|
|
289
|
+
for (const e in this._batches)
|
|
290
|
+
this._batches[e].destroy();
|
|
291
|
+
this._batches = null;
|
|
292
|
+
for (const e in this._geometries)
|
|
293
|
+
this._geometries[e].destroy();
|
|
294
|
+
this._geometries = null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
ne.extension = {
|
|
298
|
+
type: [
|
|
299
|
+
u.WebGLPipes,
|
|
300
|
+
u.WebGPUPipes,
|
|
301
|
+
u.CanvasPipes
|
|
302
|
+
],
|
|
303
|
+
name: "batch"
|
|
304
|
+
};
|
|
305
|
+
const Mt = {
|
|
306
|
+
name: "texture-bit",
|
|
307
|
+
vertex: {
|
|
308
|
+
header: (
|
|
309
|
+
/* wgsl */
|
|
310
|
+
`
|
|
311
|
+
|
|
312
|
+
struct TextureUniforms {
|
|
313
|
+
uTextureMatrix:mat3x3<f32>,
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
@group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
|
|
317
|
+
`
|
|
318
|
+
),
|
|
319
|
+
main: (
|
|
320
|
+
/* wgsl */
|
|
321
|
+
`
|
|
322
|
+
uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
323
|
+
`
|
|
324
|
+
)
|
|
325
|
+
},
|
|
326
|
+
fragment: {
|
|
327
|
+
header: (
|
|
328
|
+
/* wgsl */
|
|
329
|
+
`
|
|
330
|
+
@group(2) @binding(0) var uTexture: texture_2d<f32>;
|
|
331
|
+
@group(2) @binding(1) var uSampler: sampler;
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
`
|
|
335
|
+
),
|
|
336
|
+
main: (
|
|
337
|
+
/* wgsl */
|
|
338
|
+
`
|
|
339
|
+
outColor = textureSample(uTexture, uSampler, vUV);
|
|
340
|
+
`
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
}, Ct = {
|
|
344
|
+
name: "texture-bit",
|
|
345
|
+
vertex: {
|
|
346
|
+
header: (
|
|
347
|
+
/* glsl */
|
|
348
|
+
`
|
|
349
|
+
uniform mat3 uTextureMatrix;
|
|
350
|
+
`
|
|
351
|
+
),
|
|
352
|
+
main: (
|
|
353
|
+
/* glsl */
|
|
354
|
+
`
|
|
355
|
+
uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
356
|
+
`
|
|
357
|
+
)
|
|
358
|
+
},
|
|
359
|
+
fragment: {
|
|
360
|
+
header: (
|
|
361
|
+
/* glsl */
|
|
362
|
+
`
|
|
363
|
+
uniform sampler2D uTexture;
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
`
|
|
367
|
+
),
|
|
368
|
+
main: (
|
|
369
|
+
/* glsl */
|
|
370
|
+
`
|
|
371
|
+
outColor = texture(uTexture, vUV);
|
|
372
|
+
`
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
function Ze(s, e) {
|
|
377
|
+
const t = s.root, r = s.instructionSet;
|
|
378
|
+
r.reset(), e.batch.buildStart(r), e.blendMode.buildStart(), e.colorMask.buildStart(), t.sortableChildren && t.sortChildren(), ie(t, r, e, !0), e.batch.buildEnd(r), e.blendMode.buildEnd(r);
|
|
379
|
+
}
|
|
380
|
+
function P(s, e, t) {
|
|
381
|
+
s.globalDisplayStatus < 7 || !s.includeInBuild || (s.sortableChildren && s.sortChildren(), s.isSimple ? et(s, e, t) : ie(s, e, t, !1));
|
|
382
|
+
}
|
|
383
|
+
function et(s, e, t) {
|
|
384
|
+
if (s.renderPipeId && (t.blendMode.setBlendMode(s, s.groupBlendMode, e), s.didViewUpdate = !1, t[s.renderPipeId].addRenderable(s, e)), !s.renderGroup) {
|
|
385
|
+
const r = s.children, a = r.length;
|
|
386
|
+
for (let n = 0; n < a; n++)
|
|
387
|
+
P(r[n], e, t);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function ie(s, e, t, r) {
|
|
391
|
+
if (!r && s.renderGroup)
|
|
392
|
+
t.renderGroup.addRenderGroup(s.renderGroup, e);
|
|
393
|
+
else {
|
|
394
|
+
for (let i = 0; i < s.effects.length; i++) {
|
|
395
|
+
const l = s.effects[i];
|
|
396
|
+
t[l.pipe].push(l, s, e);
|
|
397
|
+
}
|
|
398
|
+
const a = s.renderPipeId;
|
|
399
|
+
a && (t.blendMode.setBlendMode(s, s.groupBlendMode, e), s.didViewUpdate = !1, t[a].addRenderable(s, e));
|
|
400
|
+
const n = s.children;
|
|
401
|
+
if (n.length)
|
|
402
|
+
for (let i = 0; i < n.length; i++)
|
|
403
|
+
P(n[i], e, t);
|
|
404
|
+
for (let i = s.effects.length - 1; i >= 0; i--) {
|
|
405
|
+
const l = s.effects[i];
|
|
406
|
+
t[l.pipe].pop(l, s, e);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const tt = new q();
|
|
411
|
+
class rt extends K {
|
|
412
|
+
constructor() {
|
|
413
|
+
super(), this.filters = [new Qe({
|
|
414
|
+
sprite: new Ie(m.EMPTY)
|
|
415
|
+
})];
|
|
416
|
+
}
|
|
417
|
+
get sprite() {
|
|
418
|
+
return this.filters[0].sprite;
|
|
419
|
+
}
|
|
420
|
+
set sprite(e) {
|
|
421
|
+
this.filters[0].sprite = e;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
class oe {
|
|
425
|
+
constructor(e) {
|
|
426
|
+
this._activeMaskStage = [], this._renderer = e;
|
|
427
|
+
}
|
|
428
|
+
push(e, t, r) {
|
|
429
|
+
const a = this._renderer;
|
|
430
|
+
if (a.renderPipes.batch.break(r), r.add({
|
|
431
|
+
renderPipeId: "alphaMask",
|
|
432
|
+
action: "pushMaskBegin",
|
|
433
|
+
mask: e,
|
|
434
|
+
canBundle: !1,
|
|
435
|
+
maskedContainer: t
|
|
436
|
+
}), e.renderMaskToTexture) {
|
|
437
|
+
const n = e.mask;
|
|
438
|
+
n.includeInBuild = !0, P(
|
|
439
|
+
n,
|
|
440
|
+
r,
|
|
441
|
+
a.renderPipes
|
|
442
|
+
), n.includeInBuild = !1;
|
|
443
|
+
}
|
|
444
|
+
a.renderPipes.batch.break(r), r.add({
|
|
445
|
+
renderPipeId: "alphaMask",
|
|
446
|
+
action: "pushMaskEnd",
|
|
447
|
+
mask: e,
|
|
448
|
+
maskedContainer: t,
|
|
449
|
+
canBundle: !1
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
pop(e, t, r) {
|
|
453
|
+
this._renderer.renderPipes.batch.break(r), r.add({
|
|
454
|
+
renderPipeId: "alphaMask",
|
|
455
|
+
action: "popMaskEnd",
|
|
456
|
+
mask: e,
|
|
457
|
+
canBundle: !1
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
execute(e) {
|
|
461
|
+
const t = this._renderer, r = e.mask.renderMaskToTexture;
|
|
462
|
+
if (e.action === "pushMaskBegin") {
|
|
463
|
+
const a = b.get(rt);
|
|
464
|
+
if (r) {
|
|
465
|
+
e.mask.mask.measurable = !0;
|
|
466
|
+
const n = Ae(e.mask.mask, !0, tt);
|
|
467
|
+
e.mask.mask.measurable = !1, n.ceil();
|
|
468
|
+
const i = L.getOptimalTexture(
|
|
469
|
+
n.width,
|
|
470
|
+
n.height,
|
|
471
|
+
1,
|
|
472
|
+
!1
|
|
473
|
+
);
|
|
474
|
+
t.renderTarget.push(i, !0), t.globalUniforms.push({
|
|
475
|
+
offset: n,
|
|
476
|
+
worldColor: 4294967295
|
|
477
|
+
});
|
|
478
|
+
const l = a.sprite;
|
|
479
|
+
l.texture = i, l.worldTransform.tx = n.minX, l.worldTransform.ty = n.minY, this._activeMaskStage.push({
|
|
480
|
+
filterEffect: a,
|
|
481
|
+
maskedContainer: e.maskedContainer,
|
|
482
|
+
filterTexture: i
|
|
483
|
+
});
|
|
484
|
+
} else
|
|
485
|
+
a.sprite = e.mask.mask, this._activeMaskStage.push({
|
|
486
|
+
filterEffect: a,
|
|
487
|
+
maskedContainer: e.maskedContainer
|
|
488
|
+
});
|
|
489
|
+
} else if (e.action === "pushMaskEnd") {
|
|
490
|
+
const a = this._activeMaskStage[this._activeMaskStage.length - 1];
|
|
491
|
+
r && (t.renderTarget.pop(), t.globalUniforms.pop()), t.filter.push({
|
|
492
|
+
renderPipeId: "filter",
|
|
493
|
+
action: "pushFilter",
|
|
494
|
+
container: a.maskedContainer,
|
|
495
|
+
filterEffect: a.filterEffect,
|
|
496
|
+
canBundle: !1
|
|
497
|
+
});
|
|
498
|
+
} else if (e.action === "popMaskEnd") {
|
|
499
|
+
t.filter.pop();
|
|
500
|
+
const a = this._activeMaskStage.pop();
|
|
501
|
+
r && L.returnTexture(a.filterTexture), b.return(a.filterEffect);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
destroy() {
|
|
505
|
+
this._renderer = null, this._activeMaskStage = null;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
oe.extension = {
|
|
509
|
+
type: [
|
|
510
|
+
u.WebGLPipes,
|
|
511
|
+
u.WebGPUPipes,
|
|
512
|
+
u.CanvasPipes
|
|
513
|
+
],
|
|
514
|
+
name: "alphaMask"
|
|
515
|
+
};
|
|
516
|
+
class le {
|
|
517
|
+
constructor(e) {
|
|
518
|
+
this._colorStack = [], this._colorStackIndex = 0, this._currentColor = 0, this._renderer = e;
|
|
519
|
+
}
|
|
520
|
+
buildStart() {
|
|
521
|
+
this._colorStack[0] = 15, this._colorStackIndex = 1, this._currentColor = 15;
|
|
522
|
+
}
|
|
523
|
+
push(e, t, r) {
|
|
524
|
+
this._renderer.renderPipes.batch.break(r);
|
|
525
|
+
const n = this._colorStack;
|
|
526
|
+
n[this._colorStackIndex] = n[this._colorStackIndex - 1] & e.mask;
|
|
527
|
+
const i = this._colorStack[this._colorStackIndex];
|
|
528
|
+
i !== this._currentColor && (this._currentColor = i, r.add({
|
|
529
|
+
renderPipeId: "colorMask",
|
|
530
|
+
colorMask: i,
|
|
531
|
+
canBundle: !1
|
|
532
|
+
})), this._colorStackIndex++;
|
|
533
|
+
}
|
|
534
|
+
pop(e, t, r) {
|
|
535
|
+
this._renderer.renderPipes.batch.break(r);
|
|
536
|
+
const n = this._colorStack;
|
|
537
|
+
this._colorStackIndex--;
|
|
538
|
+
const i = n[this._colorStackIndex - 1];
|
|
539
|
+
i !== this._currentColor && (this._currentColor = i, r.add({
|
|
540
|
+
renderPipeId: "colorMask",
|
|
541
|
+
colorMask: i,
|
|
542
|
+
canBundle: !1
|
|
543
|
+
}));
|
|
544
|
+
}
|
|
545
|
+
execute(e) {
|
|
546
|
+
this._renderer.colorMask.setMask(e.colorMask);
|
|
547
|
+
}
|
|
548
|
+
destroy() {
|
|
549
|
+
this._colorStack = null;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
le.extension = {
|
|
553
|
+
type: [
|
|
554
|
+
u.WebGLPipes,
|
|
555
|
+
u.WebGPUPipes,
|
|
556
|
+
u.CanvasPipes
|
|
557
|
+
],
|
|
558
|
+
name: "colorMask"
|
|
559
|
+
};
|
|
560
|
+
class ue {
|
|
561
|
+
constructor(e) {
|
|
562
|
+
this._maskStackHash = {}, this._maskHash = /* @__PURE__ */ new WeakMap(), this._renderer = e;
|
|
563
|
+
}
|
|
564
|
+
push(e, t, r) {
|
|
565
|
+
var a;
|
|
566
|
+
const n = e, i = this._renderer;
|
|
567
|
+
i.renderPipes.batch.break(r), i.renderPipes.blendMode.setBlendMode(n.mask, "none", r), r.add({
|
|
568
|
+
renderPipeId: "stencilMask",
|
|
569
|
+
action: "pushMaskBegin",
|
|
570
|
+
mask: e,
|
|
571
|
+
canBundle: !1
|
|
572
|
+
});
|
|
573
|
+
const l = n.mask;
|
|
574
|
+
l.includeInBuild = !0, this._maskHash.has(n) || this._maskHash.set(n, {
|
|
575
|
+
instructionsStart: 0,
|
|
576
|
+
instructionsLength: 0
|
|
577
|
+
});
|
|
578
|
+
const o = this._maskHash.get(n);
|
|
579
|
+
o.instructionsStart = r.instructionSize, P(
|
|
580
|
+
l,
|
|
581
|
+
r,
|
|
582
|
+
i.renderPipes
|
|
583
|
+
), l.includeInBuild = !1, i.renderPipes.batch.break(r), r.add({
|
|
584
|
+
renderPipeId: "stencilMask",
|
|
585
|
+
action: "pushMaskEnd",
|
|
586
|
+
mask: e,
|
|
587
|
+
canBundle: !1
|
|
588
|
+
});
|
|
589
|
+
const d = r.instructionSize - o.instructionsStart - 1;
|
|
590
|
+
o.instructionsLength = d;
|
|
591
|
+
const c = i.renderTarget.renderTarget.uid;
|
|
592
|
+
(a = this._maskStackHash)[c] ?? (a[c] = 0);
|
|
593
|
+
}
|
|
594
|
+
pop(e, t, r) {
|
|
595
|
+
const a = e, n = this._renderer;
|
|
596
|
+
n.renderPipes.batch.break(r), n.renderPipes.blendMode.setBlendMode(a.mask, "none", r), r.add({
|
|
597
|
+
renderPipeId: "stencilMask",
|
|
598
|
+
action: "popMaskBegin",
|
|
599
|
+
canBundle: !1
|
|
600
|
+
});
|
|
601
|
+
const i = this._maskHash.get(e);
|
|
602
|
+
for (let l = 0; l < i.instructionsLength; l++)
|
|
603
|
+
r.instructions[r.instructionSize++] = r.instructions[i.instructionsStart++];
|
|
604
|
+
r.add({
|
|
605
|
+
renderPipeId: "stencilMask",
|
|
606
|
+
action: "popMaskEnd",
|
|
607
|
+
canBundle: !1
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
execute(e) {
|
|
611
|
+
var t;
|
|
612
|
+
const r = this._renderer, a = r.renderTarget.renderTarget.uid;
|
|
613
|
+
let n = (t = this._maskStackHash)[a] ?? (t[a] = 0);
|
|
614
|
+
e.action === "pushMaskBegin" ? (r.renderTarget.ensureDepthStencil(), r.stencil.setStencilMode(p.RENDERING_MASK_ADD, n), n++, r.colorMask.setMask(0)) : e.action === "pushMaskEnd" ? (r.stencil.setStencilMode(p.MASK_ACTIVE, n), r.colorMask.setMask(15)) : e.action === "popMaskBegin" ? (r.colorMask.setMask(0), n !== 0 ? r.stencil.setStencilMode(p.RENDERING_MASK_REMOVE, n) : (r.renderTarget.clear(null, B.STENCIL), r.stencil.setStencilMode(p.DISABLED, n)), n--) : e.action === "popMaskEnd" && (r.stencil.setStencilMode(p.MASK_ACTIVE, n), r.colorMask.setMask(15)), this._maskStackHash[a] = n;
|
|
615
|
+
}
|
|
616
|
+
destroy() {
|
|
617
|
+
this._renderer = null, this._maskStackHash = null, this._maskHash = null;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
ue.extension = {
|
|
621
|
+
type: [
|
|
622
|
+
u.WebGLPipes,
|
|
623
|
+
u.WebGPUPipes,
|
|
624
|
+
u.CanvasPipes
|
|
625
|
+
],
|
|
626
|
+
name: "stencilMask"
|
|
627
|
+
};
|
|
628
|
+
function wt(s, e) {
|
|
629
|
+
for (const t in s.attributes) {
|
|
630
|
+
const r = s.attributes[t], a = e[t];
|
|
631
|
+
a ? (r.location ?? (r.location = a.location), r.format ?? (r.format = a.format), r.offset ?? (r.offset = a.offset), r.instance ?? (r.instance = a.instance)) : Y(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`);
|
|
632
|
+
}
|
|
633
|
+
st(s);
|
|
634
|
+
}
|
|
635
|
+
function st(s) {
|
|
636
|
+
const { buffers: e, attributes: t } = s, r = {}, a = {};
|
|
637
|
+
for (const n in e) {
|
|
638
|
+
const i = e[n];
|
|
639
|
+
r[i.uid] = 0, a[i.uid] = 0;
|
|
640
|
+
}
|
|
641
|
+
for (const n in t) {
|
|
642
|
+
const i = t[n];
|
|
643
|
+
r[i.buffer.uid] += W(i.format).stride;
|
|
644
|
+
}
|
|
645
|
+
for (const n in t) {
|
|
646
|
+
const i = t[n];
|
|
647
|
+
i.stride ?? (i.stride = r[i.buffer.uid]), i.start ?? (i.start = a[i.buffer.uid]), a[i.buffer.uid] += W(i.format).stride;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
const T = [];
|
|
651
|
+
T[p.NONE] = void 0;
|
|
652
|
+
T[p.DISABLED] = {
|
|
653
|
+
stencilWriteMask: 0,
|
|
654
|
+
stencilReadMask: 0
|
|
655
|
+
};
|
|
656
|
+
T[p.RENDERING_MASK_ADD] = {
|
|
657
|
+
stencilFront: {
|
|
658
|
+
compare: "equal",
|
|
659
|
+
passOp: "increment-clamp"
|
|
660
|
+
},
|
|
661
|
+
stencilBack: {
|
|
662
|
+
compare: "equal",
|
|
663
|
+
passOp: "increment-clamp"
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
T[p.RENDERING_MASK_REMOVE] = {
|
|
667
|
+
stencilFront: {
|
|
668
|
+
compare: "equal",
|
|
669
|
+
passOp: "decrement-clamp"
|
|
670
|
+
},
|
|
671
|
+
stencilBack: {
|
|
672
|
+
compare: "equal",
|
|
673
|
+
passOp: "decrement-clamp"
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
T[p.MASK_ACTIVE] = {
|
|
677
|
+
stencilWriteMask: 0,
|
|
678
|
+
stencilFront: {
|
|
679
|
+
compare: "equal",
|
|
680
|
+
passOp: "keep"
|
|
681
|
+
},
|
|
682
|
+
stencilBack: {
|
|
683
|
+
compare: "equal",
|
|
684
|
+
passOp: "keep"
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
class St {
|
|
688
|
+
constructor(e) {
|
|
689
|
+
this._syncFunctionHash = /* @__PURE__ */ Object.create(null), this._adaptor = e, this._systemCheck();
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Overrideable function by `pixi.js/unsafe-eval` to silence
|
|
693
|
+
* throwing an error if platform doesn't support unsafe-evals.
|
|
694
|
+
* @private
|
|
695
|
+
*/
|
|
696
|
+
_systemCheck() {
|
|
697
|
+
if (!Fe())
|
|
698
|
+
throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.");
|
|
699
|
+
}
|
|
700
|
+
ensureUniformGroup(e) {
|
|
701
|
+
const t = this.getUniformGroupData(e);
|
|
702
|
+
e.buffer || (e.buffer = new H({
|
|
703
|
+
data: new Float32Array(t.layout.size / 4),
|
|
704
|
+
usage: k.UNIFORM | k.COPY_DST
|
|
705
|
+
}));
|
|
706
|
+
}
|
|
707
|
+
getUniformGroupData(e) {
|
|
708
|
+
return this._syncFunctionHash[e._signature] || this._initUniformGroup(e);
|
|
709
|
+
}
|
|
710
|
+
_initUniformGroup(e) {
|
|
711
|
+
const t = e._signature;
|
|
712
|
+
let r = this._syncFunctionHash[t];
|
|
713
|
+
if (!r) {
|
|
714
|
+
const a = Object.keys(e.uniformStructures).map((l) => e.uniformStructures[l]), n = this._adaptor.createUboElements(a), i = this._generateUboSync(n.uboElements);
|
|
715
|
+
r = this._syncFunctionHash[t] = {
|
|
716
|
+
layout: n,
|
|
717
|
+
syncFunction: i
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
return this._syncFunctionHash[t];
|
|
721
|
+
}
|
|
722
|
+
_generateUboSync(e) {
|
|
723
|
+
return this._adaptor.generateUboSync(e);
|
|
724
|
+
}
|
|
725
|
+
syncUniformGroup(e, t, r) {
|
|
726
|
+
const a = this.getUniformGroupData(e);
|
|
727
|
+
return e.buffer || (e.buffer = new H({
|
|
728
|
+
data: new Float32Array(a.layout.size / 4),
|
|
729
|
+
usage: k.UNIFORM | k.COPY_DST
|
|
730
|
+
})), t || (t = e.buffer.data), r || (r = 0), a.syncFunction(e.uniforms, t, r), !0;
|
|
731
|
+
}
|
|
732
|
+
updateUniformGroup(e) {
|
|
733
|
+
if (e.isStatic && !e._dirtyId)
|
|
734
|
+
return !1;
|
|
735
|
+
e._dirtyId = 0;
|
|
736
|
+
const t = this.syncUniformGroup(e);
|
|
737
|
+
return e.buffer.update(), t;
|
|
738
|
+
}
|
|
739
|
+
destroy() {
|
|
740
|
+
this._syncFunctionHash = null;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const M = [
|
|
744
|
+
// uploading pixi matrix object to mat3
|
|
745
|
+
{
|
|
746
|
+
type: "mat3x3<f32>",
|
|
747
|
+
test: (s) => s.value.a !== void 0,
|
|
748
|
+
ubo: `
|
|
749
|
+
var matrix = uv[name].toArray(true);
|
|
750
|
+
data[offset] = matrix[0];
|
|
751
|
+
data[offset + 1] = matrix[1];
|
|
752
|
+
data[offset + 2] = matrix[2];
|
|
753
|
+
data[offset + 4] = matrix[3];
|
|
754
|
+
data[offset + 5] = matrix[4];
|
|
755
|
+
data[offset + 6] = matrix[5];
|
|
756
|
+
data[offset + 8] = matrix[6];
|
|
757
|
+
data[offset + 9] = matrix[7];
|
|
758
|
+
data[offset + 10] = matrix[8];
|
|
759
|
+
`,
|
|
760
|
+
uniform: `
|
|
761
|
+
gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
|
|
762
|
+
`
|
|
763
|
+
},
|
|
764
|
+
// uploading a pixi rectangle as a vec4
|
|
765
|
+
{
|
|
766
|
+
type: "vec4<f32>",
|
|
767
|
+
test: (s) => s.type === "vec4<f32>" && s.size === 1 && s.value.width !== void 0,
|
|
768
|
+
ubo: `
|
|
769
|
+
v = uv[name];
|
|
770
|
+
data[offset] = v.x;
|
|
771
|
+
data[offset + 1] = v.y;
|
|
772
|
+
data[offset + 2] = v.width;
|
|
773
|
+
data[offset + 3] = v.height;
|
|
774
|
+
`,
|
|
775
|
+
uniform: `
|
|
776
|
+
cv = ud[name].value;
|
|
777
|
+
v = uv[name];
|
|
778
|
+
if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
|
|
779
|
+
cv[0] = v.x;
|
|
780
|
+
cv[1] = v.y;
|
|
781
|
+
cv[2] = v.width;
|
|
782
|
+
cv[3] = v.height;
|
|
783
|
+
gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
|
|
784
|
+
}
|
|
785
|
+
`
|
|
786
|
+
},
|
|
787
|
+
// uploading a pixi point as a vec2
|
|
788
|
+
{
|
|
789
|
+
type: "vec2<f32>",
|
|
790
|
+
test: (s) => s.type === "vec2<f32>" && s.size === 1 && s.value.x !== void 0,
|
|
791
|
+
ubo: `
|
|
792
|
+
v = uv[name];
|
|
793
|
+
data[offset] = v.x;
|
|
794
|
+
data[offset + 1] = v.y;
|
|
795
|
+
`,
|
|
796
|
+
uniform: `
|
|
797
|
+
cv = ud[name].value;
|
|
798
|
+
v = uv[name];
|
|
799
|
+
if (cv[0] !== v.x || cv[1] !== v.y) {
|
|
800
|
+
cv[0] = v.x;
|
|
801
|
+
cv[1] = v.y;
|
|
802
|
+
gl.uniform2f(ud[name].location, v.x, v.y);
|
|
803
|
+
}
|
|
804
|
+
`
|
|
805
|
+
},
|
|
806
|
+
// uploading a pixi color as a vec4
|
|
807
|
+
{
|
|
808
|
+
type: "vec4<f32>",
|
|
809
|
+
test: (s) => s.type === "vec4<f32>" && s.size === 1 && s.value.red !== void 0,
|
|
810
|
+
ubo: `
|
|
811
|
+
v = uv[name];
|
|
812
|
+
data[offset] = v.red;
|
|
813
|
+
data[offset + 1] = v.green;
|
|
814
|
+
data[offset + 2] = v.blue;
|
|
815
|
+
data[offset + 3] = v.alpha;
|
|
816
|
+
`,
|
|
817
|
+
uniform: `
|
|
818
|
+
cv = ud[name].value;
|
|
819
|
+
v = uv[name];
|
|
820
|
+
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
|
|
821
|
+
cv[0] = v.red;
|
|
822
|
+
cv[1] = v.green;
|
|
823
|
+
cv[2] = v.blue;
|
|
824
|
+
cv[3] = v.alpha;
|
|
825
|
+
gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
|
|
826
|
+
}
|
|
827
|
+
`
|
|
828
|
+
},
|
|
829
|
+
// uploading a pixi color as a vec3
|
|
830
|
+
{
|
|
831
|
+
type: "vec3<f32>",
|
|
832
|
+
test: (s) => s.type === "vec3<f32>" && s.size === 1 && s.value.red !== void 0,
|
|
833
|
+
ubo: `
|
|
834
|
+
v = uv[name];
|
|
835
|
+
data[offset] = v.red;
|
|
836
|
+
data[offset + 1] = v.green;
|
|
837
|
+
data[offset + 2] = v.blue;
|
|
838
|
+
`,
|
|
839
|
+
uniform: `
|
|
840
|
+
cv = ud[name].value;
|
|
841
|
+
v = uv[name];
|
|
842
|
+
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
|
|
843
|
+
cv[0] = v.red;
|
|
844
|
+
cv[1] = v.green;
|
|
845
|
+
cv[2] = v.blue;
|
|
846
|
+
gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
|
|
847
|
+
}
|
|
848
|
+
`
|
|
849
|
+
}
|
|
850
|
+
];
|
|
851
|
+
function Pt(s, e, t, r) {
|
|
852
|
+
const a = [`
|
|
853
|
+
var v = null;
|
|
854
|
+
var v2 = null;
|
|
855
|
+
var t = 0;
|
|
856
|
+
var index = 0;
|
|
857
|
+
var name = null;
|
|
858
|
+
var arrayOffset = null;
|
|
859
|
+
`];
|
|
860
|
+
let n = 0;
|
|
861
|
+
for (let l = 0; l < s.length; l++) {
|
|
862
|
+
const o = s[l], d = o.data.name;
|
|
863
|
+
let c = !1, h = 0;
|
|
864
|
+
for (let f = 0; f < M.length; f++)
|
|
865
|
+
if (M[f].test(o.data)) {
|
|
866
|
+
h = o.offset / 4, a.push(
|
|
867
|
+
`name = "${d}";`,
|
|
868
|
+
`offset += ${h - n};`,
|
|
869
|
+
M[f][e] || M[f].ubo
|
|
870
|
+
), c = !0;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
if (!c)
|
|
874
|
+
if (o.data.size > 1)
|
|
875
|
+
h = o.offset / 4, a.push(t(o, h - n));
|
|
876
|
+
else {
|
|
877
|
+
const f = r[o.data.type];
|
|
878
|
+
h = o.offset / 4, a.push(
|
|
879
|
+
/* wgsl */
|
|
880
|
+
`
|
|
881
|
+
v = uv.${d};
|
|
882
|
+
offset += ${h - n};
|
|
883
|
+
${f};
|
|
884
|
+
`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
n = h;
|
|
888
|
+
}
|
|
889
|
+
const i = a.join(`
|
|
890
|
+
`);
|
|
891
|
+
return new Function(
|
|
892
|
+
"uv",
|
|
893
|
+
"data",
|
|
894
|
+
"offset",
|
|
895
|
+
i
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
function x(s, e) {
|
|
899
|
+
return `
|
|
900
|
+
for (let i = 0; i < ${s * e}; i++) {
|
|
901
|
+
data[offset + (((i / ${s})|0) * 4) + (i % ${s})] = v[i];
|
|
902
|
+
}
|
|
903
|
+
`;
|
|
904
|
+
}
|
|
905
|
+
const at = {
|
|
906
|
+
f32: `
|
|
907
|
+
data[offset] = v;`,
|
|
908
|
+
i32: `
|
|
909
|
+
data[offset] = v;`,
|
|
910
|
+
"vec2<f32>": `
|
|
911
|
+
data[offset] = v[0];
|
|
912
|
+
data[offset + 1] = v[1];`,
|
|
913
|
+
"vec3<f32>": `
|
|
914
|
+
data[offset] = v[0];
|
|
915
|
+
data[offset + 1] = v[1];
|
|
916
|
+
data[offset + 2] = v[2];`,
|
|
917
|
+
"vec4<f32>": `
|
|
918
|
+
data[offset] = v[0];
|
|
919
|
+
data[offset + 1] = v[1];
|
|
920
|
+
data[offset + 2] = v[2];
|
|
921
|
+
data[offset + 3] = v[3];`,
|
|
922
|
+
"mat2x2<f32>": `
|
|
923
|
+
data[offset] = v[0];
|
|
924
|
+
data[offset + 1] = v[1];
|
|
925
|
+
data[offset + 4] = v[2];
|
|
926
|
+
data[offset + 5] = v[3];`,
|
|
927
|
+
"mat3x3<f32>": `
|
|
928
|
+
data[offset] = v[0];
|
|
929
|
+
data[offset + 1] = v[1];
|
|
930
|
+
data[offset + 2] = v[2];
|
|
931
|
+
data[offset + 4] = v[3];
|
|
932
|
+
data[offset + 5] = v[4];
|
|
933
|
+
data[offset + 6] = v[5];
|
|
934
|
+
data[offset + 8] = v[6];
|
|
935
|
+
data[offset + 9] = v[7];
|
|
936
|
+
data[offset + 10] = v[8];`,
|
|
937
|
+
"mat4x4<f32>": `
|
|
938
|
+
for (let i = 0; i < 16; i++) {
|
|
939
|
+
data[offset + i] = v[i];
|
|
940
|
+
}`,
|
|
941
|
+
"mat3x2<f32>": x(3, 2),
|
|
942
|
+
"mat4x2<f32>": x(4, 2),
|
|
943
|
+
"mat2x3<f32>": x(2, 3),
|
|
944
|
+
"mat4x3<f32>": x(4, 3),
|
|
945
|
+
"mat2x4<f32>": x(2, 4),
|
|
946
|
+
"mat3x4<f32>": x(3, 4)
|
|
947
|
+
}, Gt = {
|
|
948
|
+
...at,
|
|
949
|
+
"mat2x2<f32>": `
|
|
950
|
+
data[offset] = v[0];
|
|
951
|
+
data[offset + 1] = v[1];
|
|
952
|
+
data[offset + 2] = v[2];
|
|
953
|
+
data[offset + 3] = v[3];
|
|
954
|
+
`
|
|
955
|
+
};
|
|
956
|
+
function nt(s, e, t, r, a, n) {
|
|
957
|
+
const i = n ? 1 : -1;
|
|
958
|
+
return s.identity(), s.a = 1 / r * 2, s.d = i * (1 / a * 2), s.tx = -1 - e * s.a, s.ty = -i - t * s.d, s;
|
|
959
|
+
}
|
|
960
|
+
const v = /* @__PURE__ */ new Map();
|
|
961
|
+
function de(s, e) {
|
|
962
|
+
if (!v.has(s)) {
|
|
963
|
+
const t = new m({
|
|
964
|
+
source: new U({
|
|
965
|
+
resource: s,
|
|
966
|
+
...e
|
|
967
|
+
})
|
|
968
|
+
}), r = () => {
|
|
969
|
+
v.get(s) === t && v.delete(s);
|
|
970
|
+
};
|
|
971
|
+
t.once("destroy", r), t.source.once("destroy", r), v.set(s, t);
|
|
972
|
+
}
|
|
973
|
+
return v.get(s);
|
|
974
|
+
}
|
|
975
|
+
function it(s) {
|
|
976
|
+
const e = s.colorTexture.source.resource;
|
|
977
|
+
return globalThis.HTMLCanvasElement && e instanceof HTMLCanvasElement && document.body.contains(e);
|
|
978
|
+
}
|
|
979
|
+
const ce = class he {
|
|
980
|
+
/**
|
|
981
|
+
* @param [descriptor] - Options for creating a render target.
|
|
982
|
+
*/
|
|
983
|
+
constructor(e = {}) {
|
|
984
|
+
if (this.uid = C("renderTarget"), this.colorTextures = [], this.dirtyId = 0, this.isRoot = !1, this._size = new Float32Array(2), this._managedColorTextures = !1, e = { ...he.defaultOptions, ...e }, this.stencil = e.stencil, this.depth = e.depth, this.isRoot = e.isRoot, typeof e.colorTextures == "number") {
|
|
985
|
+
this._managedColorTextures = !0;
|
|
986
|
+
for (let t = 0; t < e.colorTextures; t++)
|
|
987
|
+
this.colorTextures.push(
|
|
988
|
+
new _({
|
|
989
|
+
width: e.width,
|
|
990
|
+
height: e.height,
|
|
991
|
+
resolution: e.resolution,
|
|
992
|
+
antialias: e.antialias
|
|
993
|
+
})
|
|
994
|
+
);
|
|
995
|
+
} else {
|
|
996
|
+
this.colorTextures = [...e.colorTextures.map((r) => r.source)];
|
|
997
|
+
const t = this.colorTexture.source;
|
|
998
|
+
this.resize(t.width, t.height, t._resolution);
|
|
999
|
+
}
|
|
1000
|
+
this.colorTexture.source.on("resize", this.onSourceResize, this), (e.depthStencilTexture || this.stencil) && (e.depthStencilTexture instanceof m || e.depthStencilTexture instanceof _ ? this.depthStencilTexture = e.depthStencilTexture.source : this.ensureDepthStencilTexture());
|
|
1001
|
+
}
|
|
1002
|
+
get size() {
|
|
1003
|
+
const e = this._size;
|
|
1004
|
+
return e[0] = this.pixelWidth, e[1] = this.pixelHeight, e;
|
|
1005
|
+
}
|
|
1006
|
+
get width() {
|
|
1007
|
+
return this.colorTexture.source.width;
|
|
1008
|
+
}
|
|
1009
|
+
get height() {
|
|
1010
|
+
return this.colorTexture.source.height;
|
|
1011
|
+
}
|
|
1012
|
+
get pixelWidth() {
|
|
1013
|
+
return this.colorTexture.source.pixelWidth;
|
|
1014
|
+
}
|
|
1015
|
+
get pixelHeight() {
|
|
1016
|
+
return this.colorTexture.source.pixelHeight;
|
|
1017
|
+
}
|
|
1018
|
+
get resolution() {
|
|
1019
|
+
return this.colorTexture.source._resolution;
|
|
1020
|
+
}
|
|
1021
|
+
get colorTexture() {
|
|
1022
|
+
return this.colorTextures[0];
|
|
1023
|
+
}
|
|
1024
|
+
onSourceResize(e) {
|
|
1025
|
+
this.resize(e.width, e.height, e._resolution, !0);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* This will ensure a depthStencil texture is created for this render target.
|
|
1029
|
+
* Most likely called by the mask system to make sure we have stencil buffer added.
|
|
1030
|
+
* @internal
|
|
1031
|
+
* @ignore
|
|
1032
|
+
*/
|
|
1033
|
+
ensureDepthStencilTexture() {
|
|
1034
|
+
this.depthStencilTexture || (this.depthStencilTexture = new _({
|
|
1035
|
+
width: this.width,
|
|
1036
|
+
height: this.height,
|
|
1037
|
+
resolution: this.resolution,
|
|
1038
|
+
format: "depth24plus-stencil8",
|
|
1039
|
+
autoGenerateMipmaps: !1,
|
|
1040
|
+
antialias: !1,
|
|
1041
|
+
mipLevelCount: 1
|
|
1042
|
+
// sampleCount: handled by the render target system..
|
|
1043
|
+
}));
|
|
1044
|
+
}
|
|
1045
|
+
resize(e, t, r = this.resolution, a = !1) {
|
|
1046
|
+
this.dirtyId++, this.colorTextures.forEach((n, i) => {
|
|
1047
|
+
a && i === 0 || n.source.resize(e, t, r);
|
|
1048
|
+
}), this.depthStencilTexture && this.depthStencilTexture.source.resize(e, t, r);
|
|
1049
|
+
}
|
|
1050
|
+
destroy() {
|
|
1051
|
+
this.colorTexture.source.off("resize", this.onSourceResize, this), this._managedColorTextures && this.colorTextures.forEach((e) => {
|
|
1052
|
+
e.destroy();
|
|
1053
|
+
}), this.depthStencilTexture && (this.depthStencilTexture.destroy(), delete this.depthStencilTexture);
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
ce.defaultOptions = {
|
|
1057
|
+
/** the width of the RenderTarget */
|
|
1058
|
+
width: 0,
|
|
1059
|
+
/** the height of the RenderTarget */
|
|
1060
|
+
height: 0,
|
|
1061
|
+
/** the resolution of the RenderTarget */
|
|
1062
|
+
resolution: 1,
|
|
1063
|
+
/** an array of textures, or a number indicating how many color textures there should be */
|
|
1064
|
+
colorTextures: 1,
|
|
1065
|
+
/** should this render target have a stencil buffer? */
|
|
1066
|
+
stencil: !1,
|
|
1067
|
+
/** should this render target have a depth buffer? */
|
|
1068
|
+
depth: !1,
|
|
1069
|
+
/** should this render target be antialiased? */
|
|
1070
|
+
antialias: !1,
|
|
1071
|
+
// save on perf by default!
|
|
1072
|
+
/** is this a root element, true if this is gl context owners render target */
|
|
1073
|
+
isRoot: !1
|
|
1074
|
+
};
|
|
1075
|
+
let I = ce;
|
|
1076
|
+
class Rt {
|
|
1077
|
+
constructor(e) {
|
|
1078
|
+
this.rootViewPort = new w(), this.viewport = new w(), this.onRenderTargetChange = new Ee("onRenderTargetChange"), this.projectionMatrix = new g(), this.defaultClearColor = [0, 0, 0, 0], this._renderSurfaceToRenderTargetHash = /* @__PURE__ */ new Map(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null), this._renderTargetStack = [], this._renderer = e;
|
|
1079
|
+
}
|
|
1080
|
+
/** called when dev wants to finish a render pass */
|
|
1081
|
+
finishRenderPass() {
|
|
1082
|
+
this.adaptor.finishRenderPass(this.renderTarget);
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* called when the renderer starts to render a scene.
|
|
1086
|
+
* @param options
|
|
1087
|
+
* @param options.target - the render target to render to
|
|
1088
|
+
* @param options.clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
|
|
1089
|
+
* @param options.clearColor - the color to clear to
|
|
1090
|
+
* @param options.frame - the frame to render to
|
|
1091
|
+
*/
|
|
1092
|
+
renderStart({
|
|
1093
|
+
target: e,
|
|
1094
|
+
clear: t,
|
|
1095
|
+
clearColor: r,
|
|
1096
|
+
frame: a
|
|
1097
|
+
}) {
|
|
1098
|
+
this._renderTargetStack.length = 0, this.push(
|
|
1099
|
+
e,
|
|
1100
|
+
t,
|
|
1101
|
+
r,
|
|
1102
|
+
a
|
|
1103
|
+
), this.rootViewPort.copyFrom(this.viewport), this.rootRenderTarget = this.renderTarget, this.renderingToScreen = it(this.rootRenderTarget);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Binding a render surface! This is the main function of the render target system.
|
|
1107
|
+
* It will take the RenderSurface (which can be a texture, canvas, or render target) and bind it to the renderer.
|
|
1108
|
+
* Once bound all draw calls will be rendered to the render surface.
|
|
1109
|
+
*
|
|
1110
|
+
* If a frame is not provide and the render surface is a texture, the frame of the texture will be used.
|
|
1111
|
+
* @param renderSurface - the render surface to bind
|
|
1112
|
+
* @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
|
|
1113
|
+
* @param clearColor - the color to clear to
|
|
1114
|
+
* @param frame - the frame to render to
|
|
1115
|
+
* @returns the render target that was bound
|
|
1116
|
+
*/
|
|
1117
|
+
bind(e, t = !0, r, a) {
|
|
1118
|
+
const n = this.getRenderTarget(e), i = this.renderTarget !== n;
|
|
1119
|
+
this.renderTarget = n, this.renderSurface = e;
|
|
1120
|
+
const l = this.getGpuRenderTarget(n);
|
|
1121
|
+
(n.pixelWidth !== l.width || n.pixelHeight !== l.height) && (this.adaptor.resizeGpuRenderTarget(n), l.width = n.pixelWidth, l.height = n.pixelHeight);
|
|
1122
|
+
const o = n.colorTexture, d = this.viewport, c = o.pixelWidth, h = o.pixelHeight;
|
|
1123
|
+
if (!a && e instanceof m && (a = e.frame), a) {
|
|
1124
|
+
const f = o._resolution;
|
|
1125
|
+
d.x = a.x * f + 0.5 | 0, d.y = a.y * f + 0.5 | 0, d.width = a.width * f + 0.5 | 0, d.height = a.height * f + 0.5 | 0;
|
|
1126
|
+
} else
|
|
1127
|
+
d.x = 0, d.y = 0, d.width = c, d.height = h;
|
|
1128
|
+
return nt(
|
|
1129
|
+
this.projectionMatrix,
|
|
1130
|
+
0,
|
|
1131
|
+
0,
|
|
1132
|
+
d.width / o.resolution,
|
|
1133
|
+
d.height / o.resolution,
|
|
1134
|
+
!n.isRoot
|
|
1135
|
+
), this.adaptor.startRenderPass(n, t, r, d), i && this.onRenderTargetChange.emit(n), n;
|
|
1136
|
+
}
|
|
1137
|
+
clear(e, t = B.ALL, r) {
|
|
1138
|
+
t && (e && (e = this.getRenderTarget(e)), this.adaptor.clear(
|
|
1139
|
+
e || this.renderTarget,
|
|
1140
|
+
t,
|
|
1141
|
+
r,
|
|
1142
|
+
this.viewport
|
|
1143
|
+
));
|
|
1144
|
+
}
|
|
1145
|
+
contextChange() {
|
|
1146
|
+
this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Push a render surface to the renderer. This will bind the render surface to the renderer,
|
|
1150
|
+
* @param renderSurface - the render surface to push
|
|
1151
|
+
* @param clear - the clear mode to use. Can be true or a CLEAR number 'COLOR | DEPTH | STENCIL' 0b111
|
|
1152
|
+
* @param clearColor - the color to clear to
|
|
1153
|
+
* @param frame - the frame to use when rendering to the render surface
|
|
1154
|
+
*/
|
|
1155
|
+
push(e, t = B.ALL, r, a) {
|
|
1156
|
+
const n = this.bind(e, t, r, a);
|
|
1157
|
+
return this._renderTargetStack.push({
|
|
1158
|
+
renderTarget: n,
|
|
1159
|
+
frame: a
|
|
1160
|
+
}), n;
|
|
1161
|
+
}
|
|
1162
|
+
/** Pops the current render target from the renderer and restores the previous render target. */
|
|
1163
|
+
pop() {
|
|
1164
|
+
this._renderTargetStack.pop();
|
|
1165
|
+
const e = this._renderTargetStack[this._renderTargetStack.length - 1];
|
|
1166
|
+
this.bind(e.renderTarget, !1, null, e.frame);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Gets the render target from the provide render surface. Eg if its a texture,
|
|
1170
|
+
* it will return the render target for the texture.
|
|
1171
|
+
* If its a render target, it will return the same render target.
|
|
1172
|
+
* @param renderSurface - the render surface to get the render target for
|
|
1173
|
+
* @returns the render target for the render surface
|
|
1174
|
+
*/
|
|
1175
|
+
getRenderTarget(e) {
|
|
1176
|
+
return e.isTexture && (e = e.source), this._renderSurfaceToRenderTargetHash.get(e) ?? this._initRenderTarget(e);
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Copies a render surface to another texture
|
|
1180
|
+
* @param sourceRenderSurfaceTexture - the render surface to copy from
|
|
1181
|
+
* @param destinationTexture - the texture to copy to
|
|
1182
|
+
* @param originSrc - the origin of the copy
|
|
1183
|
+
* @param originSrc.x - the x origin of the copy
|
|
1184
|
+
* @param originSrc.y - the y origin of the copy
|
|
1185
|
+
* @param size - the size of the copy
|
|
1186
|
+
* @param size.width - the width of the copy
|
|
1187
|
+
* @param size.height - the height of the copy
|
|
1188
|
+
* @param originDest - the destination origin (top left to paste from!)
|
|
1189
|
+
* @param originDest.x - the x origin of the paste
|
|
1190
|
+
* @param originDest.y - the y origin of the paste
|
|
1191
|
+
*/
|
|
1192
|
+
copyToTexture(e, t, r, a, n) {
|
|
1193
|
+
r.x < 0 && (a.width += r.x, n.x -= r.x, r.x = 0), r.y < 0 && (a.height += r.y, n.y -= r.y, r.y = 0);
|
|
1194
|
+
const { pixelWidth: i, pixelHeight: l } = e;
|
|
1195
|
+
return a.width = Math.min(a.width, i - r.x), a.height = Math.min(a.height, l - r.y), this.adaptor.copyToTexture(
|
|
1196
|
+
e,
|
|
1197
|
+
t,
|
|
1198
|
+
r,
|
|
1199
|
+
a,
|
|
1200
|
+
n
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* ensures that we have a depth stencil buffer available to render to
|
|
1205
|
+
* This is used by the mask system to make sure we have a stencil buffer.
|
|
1206
|
+
*/
|
|
1207
|
+
ensureDepthStencil() {
|
|
1208
|
+
this.renderTarget.stencil || (this.renderTarget.stencil = !0, this.adaptor.startRenderPass(this.renderTarget, !1, null, this.viewport));
|
|
1209
|
+
}
|
|
1210
|
+
/** nukes the render target system */
|
|
1211
|
+
destroy() {
|
|
1212
|
+
this._renderer = null, this._renderSurfaceToRenderTargetHash.forEach((e, t) => {
|
|
1213
|
+
e !== t && e.destroy();
|
|
1214
|
+
}), this._renderSurfaceToRenderTargetHash.clear(), this._gpuRenderTargetHash = /* @__PURE__ */ Object.create(null);
|
|
1215
|
+
}
|
|
1216
|
+
_initRenderTarget(e) {
|
|
1217
|
+
let t = null;
|
|
1218
|
+
return U.test(e) && (e = de(e).source), e instanceof I ? t = e : e instanceof _ && (t = new I({
|
|
1219
|
+
colorTextures: [e]
|
|
1220
|
+
}), U.test(e.source.resource) && (t.isRoot = !0), e.once("destroy", () => {
|
|
1221
|
+
t.destroy();
|
|
1222
|
+
const r = this._gpuRenderTargetHash[t.uid];
|
|
1223
|
+
r && (this._gpuRenderTargetHash[t.uid] = null, this.adaptor.destroyGpuRenderTarget(r));
|
|
1224
|
+
})), this._renderSurfaceToRenderTargetHash.set(e, t), t;
|
|
1225
|
+
}
|
|
1226
|
+
getGpuRenderTarget(e) {
|
|
1227
|
+
return this._gpuRenderTargetHash[e.uid] || (this._gpuRenderTargetHash[e.uid] = this.adaptor.initGpuRenderTarget(e));
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
class Bt extends De {
|
|
1231
|
+
/**
|
|
1232
|
+
* Create a new Buffer Resource.
|
|
1233
|
+
* @param options - The options for the buffer resource
|
|
1234
|
+
* @param options.buffer - The underlying buffer that this resource is using
|
|
1235
|
+
* @param options.offset - The offset of the buffer this resource is using.
|
|
1236
|
+
* If not provided, then it will use the offset of the buffer.
|
|
1237
|
+
* @param options.size - The size of the buffer this resource is using.
|
|
1238
|
+
* If not provided, then it will use the size of the buffer.
|
|
1239
|
+
*/
|
|
1240
|
+
constructor({ buffer: e, offset: t, size: r }) {
|
|
1241
|
+
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);
|
|
1242
|
+
}
|
|
1243
|
+
onBufferChange() {
|
|
1244
|
+
this._resourceId = C("resource"), this.emit("change", this);
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
|
|
1248
|
+
* if you want to destroy it as well, or code will explode
|
|
1249
|
+
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
|
|
1250
|
+
*/
|
|
1251
|
+
destroy(e = !1) {
|
|
1252
|
+
this.destroyed = !0, e && this.buffer.destroy(), this.emit("change", this), this.buffer = null;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
class fe {
|
|
1256
|
+
constructor(e) {
|
|
1257
|
+
this._renderer = e;
|
|
1258
|
+
}
|
|
1259
|
+
addRenderable(e, t) {
|
|
1260
|
+
this._renderer.renderPipes.batch.break(t), t.add(e);
|
|
1261
|
+
}
|
|
1262
|
+
execute(e) {
|
|
1263
|
+
e.isRenderable && e.render(this._renderer);
|
|
1264
|
+
}
|
|
1265
|
+
destroy() {
|
|
1266
|
+
this._renderer = null;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
fe.extension = {
|
|
1270
|
+
type: [
|
|
1271
|
+
u.WebGLPipes,
|
|
1272
|
+
u.WebGPUPipes,
|
|
1273
|
+
u.CanvasPipes
|
|
1274
|
+
],
|
|
1275
|
+
name: "customRender"
|
|
1276
|
+
};
|
|
1277
|
+
function pe(s, e) {
|
|
1278
|
+
const t = s.instructionSet, r = t.instructions;
|
|
1279
|
+
for (let a = 0; a < t.instructionSize; a++) {
|
|
1280
|
+
const n = r[a];
|
|
1281
|
+
e[n.renderPipeId].execute(n);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
class me {
|
|
1285
|
+
constructor(e) {
|
|
1286
|
+
this._renderer = e;
|
|
1287
|
+
}
|
|
1288
|
+
addRenderGroup(e, t) {
|
|
1289
|
+
this._renderer.renderPipes.batch.break(t), t.add(e);
|
|
1290
|
+
}
|
|
1291
|
+
execute(e) {
|
|
1292
|
+
e.isRenderable && (this._renderer.globalUniforms.push({
|
|
1293
|
+
worldTransformMatrix: e.worldTransform,
|
|
1294
|
+
worldColor: e.worldColorAlpha
|
|
1295
|
+
}), pe(e, this._renderer.renderPipes), this._renderer.globalUniforms.pop());
|
|
1296
|
+
}
|
|
1297
|
+
destroy() {
|
|
1298
|
+
this._renderer = null;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
me.extension = {
|
|
1302
|
+
type: [
|
|
1303
|
+
u.WebGLPipes,
|
|
1304
|
+
u.WebGPUPipes,
|
|
1305
|
+
u.CanvasPipes
|
|
1306
|
+
],
|
|
1307
|
+
name: "renderGroup"
|
|
1308
|
+
};
|
|
1309
|
+
function ge(s, e = []) {
|
|
1310
|
+
e.push(s);
|
|
1311
|
+
for (let t = 0; t < s.renderGroupChildren.length; t++)
|
|
1312
|
+
ge(s.renderGroupChildren[t], e);
|
|
1313
|
+
return e;
|
|
1314
|
+
}
|
|
1315
|
+
function ot(s, e, t) {
|
|
1316
|
+
const r = s >> 16 & 255, a = s >> 8 & 255, n = s & 255, i = e >> 16 & 255, l = e >> 8 & 255, o = e & 255, d = r + (i - r) * t, c = a + (l - a) * t, h = n + (o - n) * t;
|
|
1317
|
+
return (d << 16) + (c << 8) + h;
|
|
1318
|
+
}
|
|
1319
|
+
const G = 16777215;
|
|
1320
|
+
function xe(s, e) {
|
|
1321
|
+
return s === G || e === G ? s + e - G : ot(s, e, 0.5);
|
|
1322
|
+
}
|
|
1323
|
+
const lt = new S();
|
|
1324
|
+
function ve(s, e = !1) {
|
|
1325
|
+
ut(s);
|
|
1326
|
+
const t = s.childrenToUpdate, r = s.updateTick++;
|
|
1327
|
+
for (const a in t) {
|
|
1328
|
+
const n = t[a], i = n.list, l = n.index;
|
|
1329
|
+
for (let o = 0; o < l; o++) {
|
|
1330
|
+
const d = i[o];
|
|
1331
|
+
d.parentRenderGroup === s && be(d, r, 0);
|
|
1332
|
+
}
|
|
1333
|
+
n.index = 0;
|
|
1334
|
+
}
|
|
1335
|
+
if (e)
|
|
1336
|
+
for (let a = 0; a < s.renderGroupChildren.length; a++)
|
|
1337
|
+
ve(s.renderGroupChildren[a], e);
|
|
1338
|
+
}
|
|
1339
|
+
function ut(s) {
|
|
1340
|
+
const e = s.root;
|
|
1341
|
+
let t;
|
|
1342
|
+
if (s.renderGroupParent) {
|
|
1343
|
+
const r = s.renderGroupParent;
|
|
1344
|
+
s.worldTransform.appendFrom(
|
|
1345
|
+
e.relativeGroupTransform,
|
|
1346
|
+
r.worldTransform
|
|
1347
|
+
), s.worldColor = xe(
|
|
1348
|
+
e.groupColor,
|
|
1349
|
+
r.worldColor
|
|
1350
|
+
), t = e.groupAlpha * r.worldAlpha;
|
|
1351
|
+
} else
|
|
1352
|
+
s.worldTransform.copyFrom(e.localTransform), s.worldColor = e.localColor, t = e.localAlpha;
|
|
1353
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t, s.worldAlpha = t, s.worldColorAlpha = s.worldColor + ((t * 255 | 0) << 24);
|
|
1354
|
+
}
|
|
1355
|
+
function be(s, e, t) {
|
|
1356
|
+
if (e === s.updateTick)
|
|
1357
|
+
return;
|
|
1358
|
+
s.updateTick = e, s.didChange = !1;
|
|
1359
|
+
const r = s.localTransform;
|
|
1360
|
+
s.updateLocalTransform();
|
|
1361
|
+
const a = s.parent;
|
|
1362
|
+
if (a && !a.renderGroup ? (t = t | s._updateFlags, s.relativeGroupTransform.appendFrom(
|
|
1363
|
+
r,
|
|
1364
|
+
a.relativeGroupTransform
|
|
1365
|
+
), t && j(s, a, t)) : (t = s._updateFlags, s.relativeGroupTransform.copyFrom(r), t && j(s, lt, t)), !s.renderGroup) {
|
|
1366
|
+
const n = s.children, i = n.length;
|
|
1367
|
+
for (let o = 0; o < i; o++)
|
|
1368
|
+
be(n[o], e, t);
|
|
1369
|
+
const l = s.parentRenderGroup;
|
|
1370
|
+
s.renderPipeId && !l.structureDidChange && l.updateRenderable(s);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
function j(s, e, t) {
|
|
1374
|
+
if (t & Oe) {
|
|
1375
|
+
s.groupColor = xe(
|
|
1376
|
+
s.localColor,
|
|
1377
|
+
e.groupColor
|
|
1378
|
+
);
|
|
1379
|
+
let r = s.localAlpha * e.groupAlpha;
|
|
1380
|
+
r = r < 0 ? 0 : r > 1 ? 1 : r, s.groupAlpha = r, s.groupColorAlpha = s.groupColor + ((r * 255 | 0) << 24);
|
|
1381
|
+
}
|
|
1382
|
+
t & ze && (s.groupBlendMode = s.localBlendMode === "inherit" ? e.groupBlendMode : s.localBlendMode), t & He && (s.globalDisplayStatus = s.localDisplayStatus & e.globalDisplayStatus), s._updateFlags = 0;
|
|
1383
|
+
}
|
|
1384
|
+
function dt(s, e) {
|
|
1385
|
+
const { list: t, index: r } = s.childrenRenderablesToUpdate;
|
|
1386
|
+
let a = !1;
|
|
1387
|
+
for (let n = 0; n < r; n++) {
|
|
1388
|
+
const i = t[n];
|
|
1389
|
+
if (a = e[i.renderPipeId].validateRenderable(i), a)
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
return s.structureDidChange = a, a;
|
|
1393
|
+
}
|
|
1394
|
+
const ct = new g();
|
|
1395
|
+
class _e {
|
|
1396
|
+
constructor(e) {
|
|
1397
|
+
this._renderer = e;
|
|
1398
|
+
}
|
|
1399
|
+
render({ container: e, transform: t }) {
|
|
1400
|
+
e.isRenderGroup = !0;
|
|
1401
|
+
const r = e.parent, a = e.renderGroup.renderGroupParent;
|
|
1402
|
+
e.parent = null, e.renderGroup.renderGroupParent = null;
|
|
1403
|
+
const n = this._renderer, i = ge(e.renderGroup, []);
|
|
1404
|
+
let l = ct;
|
|
1405
|
+
t && (l = l.copyFrom(e.renderGroup.localTransform), e.renderGroup.localTransform.copyFrom(t));
|
|
1406
|
+
const o = n.renderPipes;
|
|
1407
|
+
for (let d = 0; d < i.length; d++) {
|
|
1408
|
+
const c = i[d];
|
|
1409
|
+
c.runOnRender(), c.instructionSet.renderPipes = o, c.structureDidChange || dt(c, o), ve(c), c.structureDidChange ? (c.structureDidChange = !1, Ze(c, o)) : ht(c), c.childrenRenderablesToUpdate.index = 0, n.renderPipes.batch.upload(c.instructionSet);
|
|
1410
|
+
}
|
|
1411
|
+
n.globalUniforms.start({
|
|
1412
|
+
worldTransformMatrix: t ? e.renderGroup.localTransform : e.renderGroup.worldTransform,
|
|
1413
|
+
worldColor: e.renderGroup.worldColorAlpha
|
|
1414
|
+
}), pe(e.renderGroup, o), o.uniformBatch && o.uniformBatch.renderEnd(), t && e.renderGroup.localTransform.copyFrom(l), e.parent = r, e.renderGroup.renderGroupParent = a;
|
|
1415
|
+
}
|
|
1416
|
+
destroy() {
|
|
1417
|
+
this._renderer = null;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
_e.extension = {
|
|
1421
|
+
type: [
|
|
1422
|
+
u.WebGLSystem,
|
|
1423
|
+
u.WebGPUSystem,
|
|
1424
|
+
u.CanvasSystem
|
|
1425
|
+
],
|
|
1426
|
+
name: "renderGroup"
|
|
1427
|
+
};
|
|
1428
|
+
function ht(s) {
|
|
1429
|
+
const { list: e, index: t } = s.childrenRenderablesToUpdate;
|
|
1430
|
+
for (let r = 0; r < t; r++) {
|
|
1431
|
+
const a = e[r];
|
|
1432
|
+
a.didViewUpdate && s.updateRenderable(a);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
class ye {
|
|
1436
|
+
constructor(e) {
|
|
1437
|
+
this._gpuSpriteHash = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
1438
|
+
}
|
|
1439
|
+
addRenderable(e, t) {
|
|
1440
|
+
const r = this._getGpuSprite(e);
|
|
1441
|
+
e._didSpriteUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r);
|
|
1442
|
+
}
|
|
1443
|
+
updateRenderable(e) {
|
|
1444
|
+
const t = this._gpuSpriteHash[e.uid];
|
|
1445
|
+
e._didSpriteUpdate && this._updateBatchableSprite(e, t), t.batcher.updateElement(t);
|
|
1446
|
+
}
|
|
1447
|
+
validateRenderable(e) {
|
|
1448
|
+
const t = e._texture, r = this._getGpuSprite(e);
|
|
1449
|
+
return r.texture._source !== t._source ? !r.batcher.checkAndUpdateTexture(r, t) : !1;
|
|
1450
|
+
}
|
|
1451
|
+
destroyRenderable(e) {
|
|
1452
|
+
const t = this._gpuSpriteHash[e.uid];
|
|
1453
|
+
b.return(t), this._gpuSpriteHash[e.uid] = null;
|
|
1454
|
+
}
|
|
1455
|
+
_updateBatchableSprite(e, t) {
|
|
1456
|
+
e._didSpriteUpdate = !1, t.bounds = e.bounds, t.texture = e._texture;
|
|
1457
|
+
}
|
|
1458
|
+
_getGpuSprite(e) {
|
|
1459
|
+
return this._gpuSpriteHash[e.uid] || this._initGPUSprite(e);
|
|
1460
|
+
}
|
|
1461
|
+
_initGPUSprite(e) {
|
|
1462
|
+
const t = b.get(qe);
|
|
1463
|
+
return t.renderable = e, t.texture = e._texture, t.bounds = e.bounds, t.roundPixels = this._renderer._roundPixels | e._roundPixels, this._gpuSpriteHash[e.uid] = t, e._didSpriteUpdate = !1, e.on("destroyed", () => {
|
|
1464
|
+
this.destroyRenderable(e);
|
|
1465
|
+
}), t;
|
|
1466
|
+
}
|
|
1467
|
+
destroy() {
|
|
1468
|
+
for (const e in this._gpuSpriteHash)
|
|
1469
|
+
b.return(this._gpuSpriteHash[e]);
|
|
1470
|
+
this._gpuSpriteHash = null, this._renderer = null;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
ye.extension = {
|
|
1474
|
+
type: [
|
|
1475
|
+
u.WebGLPipes,
|
|
1476
|
+
u.WebGPUPipes,
|
|
1477
|
+
u.CanvasPipes
|
|
1478
|
+
],
|
|
1479
|
+
name: "sprite"
|
|
1480
|
+
};
|
|
1481
|
+
const F = class Te {
|
|
1482
|
+
constructor() {
|
|
1483
|
+
this.clearBeforeRender = !0, this._backgroundColor = new J(0), this.color = this._backgroundColor, this.alpha = 1;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* initiates the background system
|
|
1487
|
+
* @param options - the options for the background colors
|
|
1488
|
+
*/
|
|
1489
|
+
init(e) {
|
|
1490
|
+
e = { ...Te.defaultOptions, ...e }, this.clearBeforeRender = e.clearBeforeRender, this.color = e.background || e.backgroundColor || this._backgroundColor, this.alpha = e.backgroundAlpha, this._backgroundColor.setAlpha(e.backgroundAlpha);
|
|
1491
|
+
}
|
|
1492
|
+
/** The background color to fill if not transparent */
|
|
1493
|
+
get color() {
|
|
1494
|
+
return this._backgroundColor;
|
|
1495
|
+
}
|
|
1496
|
+
set color(e) {
|
|
1497
|
+
this._backgroundColor.setValue(e);
|
|
1498
|
+
}
|
|
1499
|
+
/** The background color alpha. Setting this to 0 will make the canvas transparent. */
|
|
1500
|
+
get alpha() {
|
|
1501
|
+
return this._backgroundColor.alpha;
|
|
1502
|
+
}
|
|
1503
|
+
set alpha(e) {
|
|
1504
|
+
this._backgroundColor.setAlpha(e);
|
|
1505
|
+
}
|
|
1506
|
+
/** The background color as an [R, G, B, A] array. */
|
|
1507
|
+
get colorRgba() {
|
|
1508
|
+
return this._backgroundColor.toArray();
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* destroys the background system
|
|
1512
|
+
* @internal
|
|
1513
|
+
* @ignore
|
|
1514
|
+
*/
|
|
1515
|
+
destroy() {
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
F.extension = {
|
|
1519
|
+
type: [
|
|
1520
|
+
u.WebGLSystem,
|
|
1521
|
+
u.WebGPUSystem,
|
|
1522
|
+
u.CanvasSystem
|
|
1523
|
+
],
|
|
1524
|
+
name: "background",
|
|
1525
|
+
priority: 0
|
|
1526
|
+
};
|
|
1527
|
+
F.defaultOptions = {
|
|
1528
|
+
/**
|
|
1529
|
+
* {@link WebGLOptions.backgroundAlpha}
|
|
1530
|
+
* @default 1
|
|
1531
|
+
*/
|
|
1532
|
+
backgroundAlpha: 1,
|
|
1533
|
+
/**
|
|
1534
|
+
* {@link WebGLOptions.backgroundColor}
|
|
1535
|
+
* @default 0x000000
|
|
1536
|
+
*/
|
|
1537
|
+
backgroundColor: 0,
|
|
1538
|
+
/**
|
|
1539
|
+
* {@link WebGLOptions.clearBeforeRender}
|
|
1540
|
+
* @default true
|
|
1541
|
+
*/
|
|
1542
|
+
clearBeforeRender: !0
|
|
1543
|
+
};
|
|
1544
|
+
let ft = F;
|
|
1545
|
+
const y = {};
|
|
1546
|
+
X.handle(u.BlendMode, (s) => {
|
|
1547
|
+
if (!s.name)
|
|
1548
|
+
throw new Error("BlendMode extension must have a name property");
|
|
1549
|
+
y[s.name] = s.ref;
|
|
1550
|
+
}, (s) => {
|
|
1551
|
+
delete y[s.name];
|
|
1552
|
+
});
|
|
1553
|
+
class ke {
|
|
1554
|
+
constructor(e) {
|
|
1555
|
+
this._isAdvanced = !1, this._filterHash = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* This ensures that a blendMode switch is added to the instruction set if the blend mode has changed.
|
|
1559
|
+
* @param renderable - The renderable we are adding to the instruction set
|
|
1560
|
+
* @param blendMode - The blend mode of the renderable
|
|
1561
|
+
* @param instructionSet - The instruction set we are adding to
|
|
1562
|
+
*/
|
|
1563
|
+
setBlendMode(e, t, r) {
|
|
1564
|
+
if (this._activeBlendMode === t) {
|
|
1565
|
+
this._isAdvanced && this._renderableList.push(e);
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
this._activeBlendMode = t, this._isAdvanced && this._endAdvancedBlendMode(r), this._isAdvanced = !!y[t], this._isAdvanced && (this._beginAdvancedBlendMode(r), this._renderableList.push(e));
|
|
1569
|
+
}
|
|
1570
|
+
_beginAdvancedBlendMode(e) {
|
|
1571
|
+
this._renderer.renderPipes.batch.break(e);
|
|
1572
|
+
const t = this._activeBlendMode;
|
|
1573
|
+
if (!y[t]) {
|
|
1574
|
+
Y(`Unable to assign BlendMode: '${t}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
let r = this._filterHash[t];
|
|
1578
|
+
r || (r = this._filterHash[t] = new K(), r.filters = [new y[t]()]);
|
|
1579
|
+
const a = {
|
|
1580
|
+
renderPipeId: "filter",
|
|
1581
|
+
action: "pushFilter",
|
|
1582
|
+
renderables: [],
|
|
1583
|
+
filterEffect: r,
|
|
1584
|
+
canBundle: !1
|
|
1585
|
+
};
|
|
1586
|
+
this._renderableList = a.renderables, e.add(a);
|
|
1587
|
+
}
|
|
1588
|
+
_endAdvancedBlendMode(e) {
|
|
1589
|
+
this._renderableList = null, this._renderer.renderPipes.batch.break(e), e.add({
|
|
1590
|
+
renderPipeId: "filter",
|
|
1591
|
+
action: "popFilter",
|
|
1592
|
+
canBundle: !1
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* called when the instruction build process is starting this will reset internally to the default blend mode
|
|
1597
|
+
* @internal
|
|
1598
|
+
* @ignore
|
|
1599
|
+
*/
|
|
1600
|
+
buildStart() {
|
|
1601
|
+
this._isAdvanced = !1;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* called when the instruction build process is finished, ensuring that if there is an advanced blend mode
|
|
1605
|
+
* active, we add the final render instructions added to the instruction set
|
|
1606
|
+
* @param instructionSet - The instruction set we are adding to
|
|
1607
|
+
* @internal
|
|
1608
|
+
* @ignore
|
|
1609
|
+
*/
|
|
1610
|
+
buildEnd(e) {
|
|
1611
|
+
this._isAdvanced && this._endAdvancedBlendMode(e);
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* @internal
|
|
1615
|
+
* @ignore
|
|
1616
|
+
*/
|
|
1617
|
+
destroy() {
|
|
1618
|
+
this._renderer = null, this._renderableList = null;
|
|
1619
|
+
for (const e in this._filterHash)
|
|
1620
|
+
this._filterHash[e].destroy();
|
|
1621
|
+
this._filterHash = null;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
ke.extension = {
|
|
1625
|
+
type: [
|
|
1626
|
+
u.WebGLPipes,
|
|
1627
|
+
u.WebGPUPipes,
|
|
1628
|
+
u.CanvasPipes
|
|
1629
|
+
],
|
|
1630
|
+
name: "blendMode"
|
|
1631
|
+
};
|
|
1632
|
+
const R = {
|
|
1633
|
+
png: "image/png",
|
|
1634
|
+
jpg: "image/jpeg",
|
|
1635
|
+
webp: "image/webp"
|
|
1636
|
+
}, E = class Me {
|
|
1637
|
+
/** @param renderer - The renderer this System works for. */
|
|
1638
|
+
constructor(e) {
|
|
1639
|
+
this._renderer = e;
|
|
1640
|
+
}
|
|
1641
|
+
_normalizeOptions(e, t = {}) {
|
|
1642
|
+
return e instanceof S || e instanceof m ? {
|
|
1643
|
+
target: e,
|
|
1644
|
+
...t
|
|
1645
|
+
} : {
|
|
1646
|
+
...t,
|
|
1647
|
+
...e
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Will return a HTML Image of the target
|
|
1652
|
+
* @param options - The options for creating the image, or the target to extract
|
|
1653
|
+
* @returns - HTML Image of the target
|
|
1654
|
+
*/
|
|
1655
|
+
async image(e) {
|
|
1656
|
+
const t = new Image();
|
|
1657
|
+
return t.src = await this.base64(e), t;
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Will return a base64 encoded string of this target. It works by calling
|
|
1661
|
+
* `Extract.canvas` and then running toDataURL on that.
|
|
1662
|
+
* @param options - The options for creating the image, or the target to extract
|
|
1663
|
+
*/
|
|
1664
|
+
async base64(e) {
|
|
1665
|
+
e = this._normalizeOptions(
|
|
1666
|
+
e,
|
|
1667
|
+
Me.defaultImageOptions
|
|
1668
|
+
);
|
|
1669
|
+
const { format: t, quality: r } = e, a = this.canvas(e);
|
|
1670
|
+
if (a.toBlob !== void 0)
|
|
1671
|
+
return new Promise((n, i) => {
|
|
1672
|
+
a.toBlob((l) => {
|
|
1673
|
+
if (!l) {
|
|
1674
|
+
i(new Error("ICanvas.toBlob failed!"));
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
const o = new FileReader();
|
|
1678
|
+
o.onload = () => n(o.result), o.onerror = i, o.readAsDataURL(l);
|
|
1679
|
+
}, R[t], r);
|
|
1680
|
+
});
|
|
1681
|
+
if (a.toDataURL !== void 0)
|
|
1682
|
+
return a.toDataURL(R[t], r);
|
|
1683
|
+
if (a.convertToBlob !== void 0) {
|
|
1684
|
+
const n = await a.convertToBlob({ type: R[t], quality: r });
|
|
1685
|
+
return new Promise((i, l) => {
|
|
1686
|
+
const o = new FileReader();
|
|
1687
|
+
o.onload = () => i(o.result), o.onerror = l, o.readAsDataURL(n);
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Creates a Canvas element, renders this target to it and then returns it.
|
|
1694
|
+
* @param options - The options for creating the canvas, or the target to extract
|
|
1695
|
+
* @returns - A Canvas element with the texture rendered on.
|
|
1696
|
+
*/
|
|
1697
|
+
canvas(e) {
|
|
1698
|
+
e = this._normalizeOptions(e);
|
|
1699
|
+
const t = e.target, r = this._renderer;
|
|
1700
|
+
if (t instanceof m)
|
|
1701
|
+
return r.texture.generateCanvas(t);
|
|
1702
|
+
const a = r.textureGenerator.generateTexture(e), n = r.texture.generateCanvas(a);
|
|
1703
|
+
return a.destroy(), n;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
|
|
1707
|
+
* order, with integer values between 0 and 255 (included).
|
|
1708
|
+
* @param options - The options for extracting the image, or the target to extract
|
|
1709
|
+
* @returns - One-dimensional array containing the pixel data of the entire texture
|
|
1710
|
+
*/
|
|
1711
|
+
pixels(e) {
|
|
1712
|
+
e = this._normalizeOptions(e);
|
|
1713
|
+
const t = e.target, r = this._renderer, a = t instanceof m ? t : r.textureGenerator.generateTexture(e), n = r.texture.getPixels(a);
|
|
1714
|
+
return t instanceof S && a.destroy(), n;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Will return a texture of the target
|
|
1718
|
+
* @param options - The options for creating the texture, or the target to extract
|
|
1719
|
+
* @returns - A texture of the target
|
|
1720
|
+
*/
|
|
1721
|
+
texture(e) {
|
|
1722
|
+
return e = this._normalizeOptions(e), e.target instanceof m ? e.target : this._renderer.textureGenerator.generateTexture(e);
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Will extract a HTMLImage of the target and download it
|
|
1726
|
+
* @param options - The options for downloading and extracting the image, or the target to extract
|
|
1727
|
+
*/
|
|
1728
|
+
download(e) {
|
|
1729
|
+
e = this._normalizeOptions(e);
|
|
1730
|
+
const t = this.canvas(e), r = document.createElement("a");
|
|
1731
|
+
r.download = e.filename ?? "image.png", r.href = t.toDataURL("image/png"), document.body.appendChild(r), r.click(), document.body.removeChild(r);
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
|
|
1735
|
+
* @param options - The options for logging the image, or the target to log
|
|
1736
|
+
*/
|
|
1737
|
+
log(e) {
|
|
1738
|
+
const t = e.width ?? 200;
|
|
1739
|
+
e = this._normalizeOptions(e);
|
|
1740
|
+
const r = this.canvas(e), a = r.toDataURL();
|
|
1741
|
+
console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);
|
|
1742
|
+
const n = [
|
|
1743
|
+
"font-size: 1px;",
|
|
1744
|
+
`padding: ${t}px 300px;`,
|
|
1745
|
+
`background: url(${a}) no-repeat;`,
|
|
1746
|
+
"background-size: contain;"
|
|
1747
|
+
].join(" ");
|
|
1748
|
+
console.log("%c ", n);
|
|
1749
|
+
}
|
|
1750
|
+
destroy() {
|
|
1751
|
+
this._renderer = null;
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
E.extension = {
|
|
1755
|
+
type: [
|
|
1756
|
+
u.WebGLSystem,
|
|
1757
|
+
u.WebGPUSystem
|
|
1758
|
+
],
|
|
1759
|
+
name: "extract"
|
|
1760
|
+
};
|
|
1761
|
+
E.defaultImageOptions = {
|
|
1762
|
+
/** The format of the image. */
|
|
1763
|
+
format: "png",
|
|
1764
|
+
/** The quality of the image. */
|
|
1765
|
+
quality: 1
|
|
1766
|
+
};
|
|
1767
|
+
let pt = E;
|
|
1768
|
+
class mt extends m {
|
|
1769
|
+
static create(e) {
|
|
1770
|
+
return new m({
|
|
1771
|
+
source: new _(e)
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Resizes the render texture.
|
|
1776
|
+
* @param width - The new width of the render texture.
|
|
1777
|
+
* @param height - The new height of the render texture.
|
|
1778
|
+
* @param resolution - The new resolution of the render texture.
|
|
1779
|
+
* @returns This texture.
|
|
1780
|
+
*/
|
|
1781
|
+
resize(e, t, r) {
|
|
1782
|
+
return this.source.resize(e, t, r), this;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
const gt = new w(), xt = new q(), vt = [0, 0, 0, 0];
|
|
1786
|
+
class Ce {
|
|
1787
|
+
constructor(e) {
|
|
1788
|
+
this._renderer = e;
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* A Useful function that returns a texture of the display object that can then be used to create sprites
|
|
1792
|
+
* This can be quite useful if your container is complicated and needs to be reused multiple times.
|
|
1793
|
+
* @param {GenerateTextureOptions | Container} options - Generate texture options.
|
|
1794
|
+
* @param {Container} [options.container] - If not given, the renderer's resolution is used.
|
|
1795
|
+
* @param {Rectangle} options.region - The region of the container, that shall be rendered,
|
|
1796
|
+
* @param {number} [options.resolution] - The resolution of the texture being generated.
|
|
1797
|
+
* if no region is specified, defaults to the local bounds of the container.
|
|
1798
|
+
* @param {GenerateTextureSourceOptions} [options.textureSourceOptions] - Texture options for GPU.
|
|
1799
|
+
* @returns a shiny new texture of the container passed in
|
|
1800
|
+
*/
|
|
1801
|
+
generateTexture(e) {
|
|
1802
|
+
var d;
|
|
1803
|
+
e instanceof S && (e = {
|
|
1804
|
+
target: e,
|
|
1805
|
+
frame: void 0,
|
|
1806
|
+
textureSourceOptions: {},
|
|
1807
|
+
resolution: void 0
|
|
1808
|
+
});
|
|
1809
|
+
const t = e.resolution || this._renderer.resolution, r = e.antialias || this._renderer.view.antialias, a = e.target;
|
|
1810
|
+
let n = e.clearColor;
|
|
1811
|
+
n ? n = Array.isArray(n) && n.length === 4 ? n : J.shared.setValue(n).toArray() : n = vt;
|
|
1812
|
+
const i = ((d = e.frame) == null ? void 0 : d.copyTo(gt)) || Le(a, xt).rectangle;
|
|
1813
|
+
i.width = Math.max(i.width, 1 / t) | 0, i.height = Math.max(i.height, 1 / t) | 0;
|
|
1814
|
+
const l = mt.create({
|
|
1815
|
+
...e.textureSourceOptions,
|
|
1816
|
+
width: i.width,
|
|
1817
|
+
height: i.height,
|
|
1818
|
+
resolution: t,
|
|
1819
|
+
antialias: r
|
|
1820
|
+
}), o = g.shared.translate(-i.x, -i.y);
|
|
1821
|
+
return this._renderer.render({
|
|
1822
|
+
container: a,
|
|
1823
|
+
transform: o,
|
|
1824
|
+
target: l,
|
|
1825
|
+
clearColor: n
|
|
1826
|
+
}), l;
|
|
1827
|
+
}
|
|
1828
|
+
destroy() {
|
|
1829
|
+
this._renderer = null;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
Ce.extension = {
|
|
1833
|
+
type: [
|
|
1834
|
+
u.WebGLSystem,
|
|
1835
|
+
u.WebGPUSystem
|
|
1836
|
+
],
|
|
1837
|
+
name: "textureGenerator"
|
|
1838
|
+
};
|
|
1839
|
+
class we {
|
|
1840
|
+
constructor(e) {
|
|
1841
|
+
this._stackIndex = 0, this._globalUniformDataStack = [], this._uniformsPool = [], this._activeUniforms = [], this._bindGroupPool = [], this._activeBindGroups = [], this._renderer = e;
|
|
1842
|
+
}
|
|
1843
|
+
reset() {
|
|
1844
|
+
this._stackIndex = 0;
|
|
1845
|
+
for (let e = 0; e < this._activeUniforms.length; e++)
|
|
1846
|
+
this._uniformsPool.push(this._activeUniforms[e]);
|
|
1847
|
+
for (let e = 0; e < this._activeBindGroups.length; e++)
|
|
1848
|
+
this._bindGroupPool.push(this._activeBindGroups[e]);
|
|
1849
|
+
this._activeUniforms.length = 0, this._activeBindGroups.length = 0;
|
|
1850
|
+
}
|
|
1851
|
+
start(e) {
|
|
1852
|
+
this.reset(), this.push(e);
|
|
1853
|
+
}
|
|
1854
|
+
bind({
|
|
1855
|
+
size: e,
|
|
1856
|
+
projectionMatrix: t,
|
|
1857
|
+
worldTransformMatrix: r,
|
|
1858
|
+
worldColor: a,
|
|
1859
|
+
offset: n
|
|
1860
|
+
}) {
|
|
1861
|
+
const i = this._renderer.renderTarget.renderTarget, l = this._stackIndex ? this._globalUniformDataStack[this._stackIndex - 1] : {
|
|
1862
|
+
projectionData: i,
|
|
1863
|
+
worldTransformMatrix: new g(),
|
|
1864
|
+
worldColor: 4294967295,
|
|
1865
|
+
offset: new We()
|
|
1866
|
+
}, o = {
|
|
1867
|
+
projectionMatrix: t || this._renderer.renderTarget.projectionMatrix,
|
|
1868
|
+
resolution: e || i.size,
|
|
1869
|
+
worldTransformMatrix: r || l.worldTransformMatrix,
|
|
1870
|
+
worldColor: a || l.worldColor,
|
|
1871
|
+
offset: n || l.offset,
|
|
1872
|
+
bindGroup: null
|
|
1873
|
+
}, d = this._uniformsPool.pop() || this._createUniforms();
|
|
1874
|
+
this._activeUniforms.push(d);
|
|
1875
|
+
const c = d.uniforms;
|
|
1876
|
+
c.uProjectionMatrix = o.projectionMatrix, c.uResolution = o.resolution, c.uWorldTransformMatrix.copyFrom(o.worldTransformMatrix), c.uWorldTransformMatrix.tx -= o.offset.x, c.uWorldTransformMatrix.ty -= o.offset.y, Ke(
|
|
1877
|
+
o.worldColor,
|
|
1878
|
+
c.uWorldColorAlpha,
|
|
1879
|
+
0
|
|
1880
|
+
), d.update();
|
|
1881
|
+
let h;
|
|
1882
|
+
this._renderer.renderPipes.uniformBatch ? h = this._renderer.renderPipes.uniformBatch.getUniformBindGroup(d, !1) : (h = this._bindGroupPool.pop() || new Ve(), this._activeBindGroups.push(h), h.setResource(d, 0)), o.bindGroup = h, this._currentGlobalUniformData = o;
|
|
1883
|
+
}
|
|
1884
|
+
push(e) {
|
|
1885
|
+
this.bind(e), this._globalUniformDataStack[this._stackIndex++] = this._currentGlobalUniformData;
|
|
1886
|
+
}
|
|
1887
|
+
pop() {
|
|
1888
|
+
this._currentGlobalUniformData = this._globalUniformDataStack[--this._stackIndex - 1], this._renderer.type === se.WEBGL && this._currentGlobalUniformData.bindGroup.resources[0].update();
|
|
1889
|
+
}
|
|
1890
|
+
get bindGroup() {
|
|
1891
|
+
return this._currentGlobalUniformData.bindGroup;
|
|
1892
|
+
}
|
|
1893
|
+
get uniformGroup() {
|
|
1894
|
+
return this._currentGlobalUniformData.bindGroup.resources[0];
|
|
1895
|
+
}
|
|
1896
|
+
_createUniforms() {
|
|
1897
|
+
return new re({
|
|
1898
|
+
uProjectionMatrix: { value: new g(), type: "mat3x3<f32>" },
|
|
1899
|
+
uWorldTransformMatrix: { value: new g(), type: "mat3x3<f32>" },
|
|
1900
|
+
// TODO - someone smart - set this to be a unorm8x4 rather than a vec4<f32>
|
|
1901
|
+
uWorldColorAlpha: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
1902
|
+
uResolution: { value: [0, 0], type: "vec2<f32>" }
|
|
1903
|
+
}, {
|
|
1904
|
+
isStatic: !0
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
destroy() {
|
|
1908
|
+
this._renderer = null;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
we.extension = {
|
|
1912
|
+
type: [
|
|
1913
|
+
u.WebGLSystem,
|
|
1914
|
+
u.WebGPUSystem,
|
|
1915
|
+
u.CanvasSystem
|
|
1916
|
+
],
|
|
1917
|
+
name: "globalUniforms"
|
|
1918
|
+
};
|
|
1919
|
+
let $ = !1;
|
|
1920
|
+
const N = "8.1.5";
|
|
1921
|
+
function bt(s) {
|
|
1922
|
+
if (!$) {
|
|
1923
|
+
if (Q.get().getNavigator().userAgent.toLowerCase().indexOf("chrome") > -1) {
|
|
1924
|
+
const e = [
|
|
1925
|
+
`%c %c %c %c %c PixiJS %c v${N} (${s}) http://www.pixijs.com/
|
|
1926
|
+
|
|
1927
|
+
`,
|
|
1928
|
+
"background: #E72264; padding:5px 0;",
|
|
1929
|
+
"background: #6CA2EA; padding:5px 0;",
|
|
1930
|
+
"background: #B5D33D; padding:5px 0;",
|
|
1931
|
+
"background: #FED23F; padding:5px 0;",
|
|
1932
|
+
"color: #FFFFFF; background: #E72264; padding:5px 0;",
|
|
1933
|
+
"color: #E72264; background: #FFFFFF; padding:5px 0;"
|
|
1934
|
+
];
|
|
1935
|
+
globalThis.console.log(...e);
|
|
1936
|
+
} else
|
|
1937
|
+
globalThis.console && globalThis.console.log(`PixiJS ${N} - ${s} - http://www.pixijs.com/`);
|
|
1938
|
+
$ = !0;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
class D {
|
|
1942
|
+
constructor(e) {
|
|
1943
|
+
this._renderer = e;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* It all starts here! This initiates every system, passing in the options for any system by name.
|
|
1947
|
+
* @param options - the config for the renderer and all its systems
|
|
1948
|
+
*/
|
|
1949
|
+
init(e) {
|
|
1950
|
+
if (e.hello) {
|
|
1951
|
+
let t = this._renderer.name;
|
|
1952
|
+
this._renderer.type === se.WEBGL && (t += ` ${this._renderer.context.webGLVersion}`), bt(t);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
D.extension = {
|
|
1957
|
+
type: [
|
|
1958
|
+
u.WebGLSystem,
|
|
1959
|
+
u.WebGPUSystem,
|
|
1960
|
+
u.CanvasSystem
|
|
1961
|
+
],
|
|
1962
|
+
name: "hello",
|
|
1963
|
+
priority: -2
|
|
1964
|
+
};
|
|
1965
|
+
D.defaultOptions = {
|
|
1966
|
+
/** {@link WebGLOptions.hello} */
|
|
1967
|
+
hello: !1
|
|
1968
|
+
};
|
|
1969
|
+
const O = class Se {
|
|
1970
|
+
/** @param renderer - The renderer this System works for. */
|
|
1971
|
+
constructor(e) {
|
|
1972
|
+
this._renderer = e, this.count = 0, this.checkCount = 0;
|
|
1973
|
+
}
|
|
1974
|
+
init(e) {
|
|
1975
|
+
e = { ...Se.defaultOptions, ...e }, this.checkCountMax = e.textureGCCheckCountMax, this.maxIdle = e.textureGCAMaxIdle, this.active = e.textureGCActive;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Checks to see when the last time a texture was used.
|
|
1979
|
+
* If the texture has not been used for a specified amount of time, it will be removed from the GPU.
|
|
1980
|
+
*/
|
|
1981
|
+
postrender() {
|
|
1982
|
+
this._renderer.renderingToScreen && (this.count++, this.active && (this.checkCount++, this.checkCount > this.checkCountMax && (this.checkCount = 0, this.run())));
|
|
1983
|
+
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Checks to see when the last time a texture was used.
|
|
1986
|
+
* If the texture has not been used for a specified amount of time, it will be removed from the GPU.
|
|
1987
|
+
*/
|
|
1988
|
+
run() {
|
|
1989
|
+
const e = this._renderer.texture.managedTextures;
|
|
1990
|
+
for (let t = 0; t < e.length; t++) {
|
|
1991
|
+
const r = e[t];
|
|
1992
|
+
r.autoGarbageCollect && r.resource && r._touched > -1 && this.count - r._touched > this.maxIdle && (r._touched = -1, r.unload());
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
destroy() {
|
|
1996
|
+
this._renderer = null;
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
O.extension = {
|
|
2000
|
+
type: [
|
|
2001
|
+
u.WebGLSystem,
|
|
2002
|
+
u.WebGPUSystem
|
|
2003
|
+
],
|
|
2004
|
+
name: "textureGC"
|
|
2005
|
+
};
|
|
2006
|
+
O.defaultOptions = {
|
|
2007
|
+
/**
|
|
2008
|
+
* If set to true, this will enable the garbage collector on the GPU.
|
|
2009
|
+
* @default true
|
|
2010
|
+
*/
|
|
2011
|
+
textureGCActive: !0,
|
|
2012
|
+
/**
|
|
2013
|
+
* The maximum idle frames before a texture is destroyed by garbage collection.
|
|
2014
|
+
* @default 60 * 60
|
|
2015
|
+
*/
|
|
2016
|
+
textureGCAMaxIdle: 60 * 60,
|
|
2017
|
+
/**
|
|
2018
|
+
* Frames between two garbage collections.
|
|
2019
|
+
* @default 600
|
|
2020
|
+
*/
|
|
2021
|
+
textureGCCheckCountMax: 600
|
|
2022
|
+
};
|
|
2023
|
+
let Pe = O;
|
|
2024
|
+
X.add(Pe);
|
|
2025
|
+
const z = class Ge {
|
|
2026
|
+
/** The resolution / device pixel ratio of the renderer. */
|
|
2027
|
+
get resolution() {
|
|
2028
|
+
return this.texture.source._resolution;
|
|
2029
|
+
}
|
|
2030
|
+
set resolution(e) {
|
|
2031
|
+
this.texture.source.resize(
|
|
2032
|
+
this.texture.source.width,
|
|
2033
|
+
this.texture.source.height,
|
|
2034
|
+
e
|
|
2035
|
+
);
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* initiates the view system
|
|
2039
|
+
* @param options - the options for the view
|
|
2040
|
+
*/
|
|
2041
|
+
init(e) {
|
|
2042
|
+
e = {
|
|
2043
|
+
...Ge.defaultOptions,
|
|
2044
|
+
...e
|
|
2045
|
+
}, e.view && (je($e, "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 || Q.get().createCanvas(), this.antialias = !!e.antialias, this.texture = de(this.canvas, e), this.renderTarget = new I({
|
|
2046
|
+
colorTextures: [this.texture],
|
|
2047
|
+
depth: !!e.depth,
|
|
2048
|
+
isRoot: !0
|
|
2049
|
+
}), this.texture.source.transparent = e.backgroundAlpha < 1, this.multiView = !!e.multiView, this.autoDensity && (this.canvas.style.width = `${this.texture.width}px`, this.canvas.style.height = `${this.texture.height}px`), this.resolution = e.resolution;
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Resizes the screen and canvas to the specified dimensions.
|
|
2053
|
+
* @param desiredScreenWidth - The new width of the screen.
|
|
2054
|
+
* @param desiredScreenHeight - The new height of the screen.
|
|
2055
|
+
* @param resolution
|
|
2056
|
+
*/
|
|
2057
|
+
resize(e, t, r) {
|
|
2058
|
+
this.texture.source.resize(e, t, r), this.screen.width = this.texture.frame.width, this.screen.height = this.texture.frame.height, this.autoDensity && (this.canvas.style.width = `${e}px`, this.canvas.style.height = `${t}px`);
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Destroys this System and optionally removes the canvas from the dom.
|
|
2062
|
+
* @param {options | false} options - The options for destroying the view, or "false".
|
|
2063
|
+
* @param options.removeView - Whether to remove the view element from the DOM. Defaults to `false`.
|
|
2064
|
+
*/
|
|
2065
|
+
destroy(e = !1) {
|
|
2066
|
+
(typeof e == "boolean" ? e : !!(e != null && e.removeView)) && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
z.extension = {
|
|
2070
|
+
type: [
|
|
2071
|
+
u.WebGLSystem,
|
|
2072
|
+
u.WebGPUSystem,
|
|
2073
|
+
u.CanvasSystem
|
|
2074
|
+
],
|
|
2075
|
+
name: "view",
|
|
2076
|
+
priority: 0
|
|
2077
|
+
};
|
|
2078
|
+
z.defaultOptions = {
|
|
2079
|
+
/**
|
|
2080
|
+
* {@link WebGLOptions.width}
|
|
2081
|
+
* @default 800
|
|
2082
|
+
*/
|
|
2083
|
+
width: 800,
|
|
2084
|
+
/**
|
|
2085
|
+
* {@link WebGLOptions.height}
|
|
2086
|
+
* @default 600
|
|
2087
|
+
*/
|
|
2088
|
+
height: 600,
|
|
2089
|
+
/**
|
|
2090
|
+
* {@link WebGLOptions.autoDensity}
|
|
2091
|
+
* @default false
|
|
2092
|
+
*/
|
|
2093
|
+
autoDensity: !1,
|
|
2094
|
+
/**
|
|
2095
|
+
* {@link WebGLOptions.antialias}
|
|
2096
|
+
* @default false
|
|
2097
|
+
*/
|
|
2098
|
+
antialias: !1
|
|
2099
|
+
};
|
|
2100
|
+
let _t = z;
|
|
2101
|
+
const Ut = [
|
|
2102
|
+
ft,
|
|
2103
|
+
we,
|
|
2104
|
+
D,
|
|
2105
|
+
_t,
|
|
2106
|
+
_e,
|
|
2107
|
+
Pe,
|
|
2108
|
+
Ce,
|
|
2109
|
+
pt
|
|
2110
|
+
], At = [
|
|
2111
|
+
ke,
|
|
2112
|
+
ne,
|
|
2113
|
+
ye,
|
|
2114
|
+
me,
|
|
2115
|
+
oe,
|
|
2116
|
+
ue,
|
|
2117
|
+
le,
|
|
2118
|
+
fe
|
|
2119
|
+
];
|
|
2120
|
+
export {
|
|
2121
|
+
Bt as B,
|
|
2122
|
+
T as G,
|
|
2123
|
+
Rt as R,
|
|
2124
|
+
Ut as S,
|
|
2125
|
+
St as U,
|
|
2126
|
+
At as a,
|
|
2127
|
+
at as b,
|
|
2128
|
+
Pt as c,
|
|
2129
|
+
M as d,
|
|
2130
|
+
wt as e,
|
|
2131
|
+
Ct as f,
|
|
2132
|
+
Mt as t,
|
|
2133
|
+
Gt as u
|
|
2134
|
+
};
|