evotars 0.0.11 → 0.0.13

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.
@@ -0,0 +1,2564 @@
1
+ import { m as $, E as l, B as A, D as G, w as b, N as Be, j as S, i as z, S as g, R as w, d as B, M as Y, e as v, A as Ne } from "./index-RgERw5ms.js";
2
+ import { S as U, j as O, k as q, m as Z, n as P, b as x, h as Q, f as Ie, U as F, o as J, R as De } from "./colorToUniform-ZnVvWd8z.js";
3
+ import { g as ee } from "./getBatchSamplersUniformGroup-DIigPB-W.js";
4
+ import { e as ye, G as Ce, c as Ge, b as Ue, U as Oe, R as Pe, B as te, d as N, f as Fe, S as Me, a as Le } from "./SharedSystems-CpNLwPlr.js";
5
+ class re {
6
+ constructor() {
7
+ this._didUpload = !1, this._tempState = U.for2d();
8
+ }
9
+ init(e) {
10
+ const r = $(), s = O({
11
+ name: "batch",
12
+ bits: [
13
+ q,
14
+ Z(r),
15
+ P
16
+ ]
17
+ });
18
+ this._shader = new x({
19
+ glProgram: s,
20
+ resources: {
21
+ batchSamplers: ee(r)
22
+ }
23
+ }), e.renderer.runners.contextChange.add(this);
24
+ }
25
+ contextChange() {
26
+ this._didUpload = !1;
27
+ }
28
+ start(e, r) {
29
+ const s = e.renderer;
30
+ s.shader.bind(this._shader, this._didUpload), s.shader.updateUniformGroup(s.globalUniforms.uniformGroup), s.geometry.bind(r, this._shader.glProgram);
31
+ }
32
+ execute(e, r) {
33
+ const s = e.renderer;
34
+ this._didUpload = !0, this._tempState.blendMode = r.blendMode, s.state.set(this._tempState);
35
+ const n = r.textures.textures;
36
+ for (let i = 0; i < n.length; i++)
37
+ s.texture.bind(n[i], i);
38
+ s.geometry.draw("triangle-list", r.size, r.start);
39
+ }
40
+ destroy() {
41
+ this._shader.destroy(!0), this._shader = null;
42
+ }
43
+ }
44
+ re.extension = {
45
+ type: [
46
+ l.WebGLPipesAdaptor
47
+ ],
48
+ name: "batch"
49
+ };
50
+ var T = /* @__PURE__ */ ((t) => (t[t.ELEMENT_ARRAY_BUFFER = 34963] = "ELEMENT_ARRAY_BUFFER", t[t.ARRAY_BUFFER = 34962] = "ARRAY_BUFFER", t[t.UNIFORM_BUFFER = 35345] = "UNIFORM_BUFFER", t))(T || {});
51
+ class He {
52
+ constructor(e, r) {
53
+ this.buffer = e || null, this.updateID = -1, this.byteLength = -1, this.type = r;
54
+ }
55
+ }
56
+ class se {
57
+ /**
58
+ * @param {Renderer} renderer - The renderer this System works for.
59
+ */
60
+ constructor(e) {
61
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null), this._boundBufferBases = /* @__PURE__ */ Object.create(null), this._renderer = e;
62
+ }
63
+ /**
64
+ * @ignore
65
+ */
66
+ destroy() {
67
+ this._renderer = null, this._gl = null, this._gpuBuffers = null, this._boundBufferBases = null;
68
+ }
69
+ /** Sets up the renderer context and necessary buffers. */
70
+ contextChange() {
71
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null), this._gl = this._renderer.gl;
72
+ }
73
+ getGlBuffer(e) {
74
+ return this._gpuBuffers[e.uid] || this.createGLBuffer(e);
75
+ }
76
+ /**
77
+ * This binds specified buffer. On first run, it will create the webGL buffers for the context too
78
+ * @param buffer - the buffer to bind to the renderer
79
+ */
80
+ bind(e) {
81
+ const { _gl: r } = this, s = this.getGlBuffer(e);
82
+ r.bindBuffer(s.type, s.buffer);
83
+ }
84
+ /**
85
+ * Binds an uniform buffer to at the given index.
86
+ *
87
+ * A cache is used so a buffer will not be bound again if already bound.
88
+ * @param buffer - the buffer to bind
89
+ * @param index - the base index to bind it to.
90
+ */
91
+ bindBufferBase(e, r) {
92
+ const { _gl: s } = this;
93
+ if (this._boundBufferBases[r] !== e) {
94
+ const n = this.getGlBuffer(e);
95
+ this._boundBufferBases[r] = e, s.bindBufferBase(s.UNIFORM_BUFFER, r, n.buffer);
96
+ }
97
+ }
98
+ /**
99
+ * Binds a buffer whilst also binding its range.
100
+ * This will make the buffer start from the offset supplied rather than 0 when it is read.
101
+ * @param buffer - the buffer to bind
102
+ * @param index - the base index to bind at, defaults to 0
103
+ * @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
104
+ */
105
+ bindBufferRange(e, r, s) {
106
+ const { _gl: n } = this;
107
+ s = s || 0;
108
+ const i = this.getGlBuffer(e);
109
+ n.bindBufferRange(n.UNIFORM_BUFFER, r || 0, i.buffer, s * 256, 256);
110
+ }
111
+ /**
112
+ * Will ensure the data in the buffer is uploaded to the GPU.
113
+ * @param {Buffer} buffer - the buffer to update
114
+ */
115
+ updateBuffer(e) {
116
+ const { _gl: r } = this, s = this.getGlBuffer(e);
117
+ if (e._updateID === s.updateID)
118
+ return s;
119
+ s.updateID = e._updateID, r.bindBuffer(s.type, s.buffer);
120
+ const n = e.data;
121
+ if (s.byteLength >= e.data.byteLength)
122
+ r.bufferSubData(s.type, 0, n, 0, e._updateSize / n.BYTES_PER_ELEMENT);
123
+ else {
124
+ const i = e.descriptor.usage & A.STATIC ? r.STATIC_DRAW : r.DYNAMIC_DRAW;
125
+ s.byteLength = n.byteLength, r.bufferData(s.type, n, i);
126
+ }
127
+ return s;
128
+ }
129
+ /** dispose all WebGL resources of all managed buffers */
130
+ destroyAll() {
131
+ const e = this._gl;
132
+ for (const r in this._gpuBuffers)
133
+ e.deleteBuffer(this._gpuBuffers[r].buffer);
134
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null);
135
+ }
136
+ /**
137
+ * Disposes buffer
138
+ * @param {Buffer} buffer - buffer with data
139
+ * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
140
+ */
141
+ onBufferDestroy(e, r) {
142
+ const s = this._gpuBuffers[e.uid], n = this._gl;
143
+ r || n.deleteBuffer(s.buffer), this._gpuBuffers[e.uid] = null;
144
+ }
145
+ /**
146
+ * creates and attaches a GLBuffer object tied to the current context.
147
+ * @param buffer
148
+ * @protected
149
+ */
150
+ createGLBuffer(e) {
151
+ const { _gl: r } = this;
152
+ let s = T.ARRAY_BUFFER;
153
+ e.descriptor.usage & A.INDEX ? s = T.ELEMENT_ARRAY_BUFFER : e.descriptor.usage & A.UNIFORM && (s = T.UNIFORM_BUFFER);
154
+ const n = new He(r.createBuffer(), s);
155
+ return this._gpuBuffers[e.uid] = n, e.on("destroy", this.onBufferDestroy, this), n;
156
+ }
157
+ }
158
+ se.extension = {
159
+ type: [
160
+ l.WebGLSystem
161
+ ],
162
+ name: "buffer"
163
+ };
164
+ const M = class ne {
165
+ /** @param renderer - The renderer this System works for. */
166
+ constructor(e) {
167
+ this.supports = {
168
+ /** Support for 32-bit indices buffer. */
169
+ uint32Indices: !0,
170
+ /** Support for UniformBufferObjects */
171
+ uniformBufferObject: !0,
172
+ /** Support for VertexArrayObjects */
173
+ vertexArrayObject: !0,
174
+ /** Support for SRGB texture format */
175
+ srgbTextures: !0,
176
+ /** Support for wrapping modes if a texture is non-power of two */
177
+ nonPowOf2wrapping: !0,
178
+ /** Support for MSAA (antialiasing of dynamic textures) */
179
+ msaa: !0,
180
+ /** Support for mipmaps if a texture is non-power of two */
181
+ nonPowOf2mipmaps: !0
182
+ }, this._renderer = e, this.extensions = /* @__PURE__ */ Object.create(null), this.handleContextLost = this.handleContextLost.bind(this), this.handleContextRestored = this.handleContextRestored.bind(this);
183
+ }
184
+ /**
185
+ * `true` if the context is lost
186
+ * @readonly
187
+ */
188
+ get isLost() {
189
+ return !this.gl || this.gl.isContextLost();
190
+ }
191
+ /**
192
+ * Handles the context change event.
193
+ * @param {WebGLRenderingContext} gl - New WebGL context.
194
+ */
195
+ contextChange(e) {
196
+ this.gl = e, this._renderer.gl = e;
197
+ }
198
+ init(e) {
199
+ if (e = { ...ne.defaultOptions, ...e }, e.context)
200
+ this.initFromContext(e.context);
201
+ else {
202
+ const r = this._renderer.background.alpha < 1, s = e.premultipliedAlpha ?? !0, n = e.antialias && !this._renderer.backBuffer.useBackBuffer;
203
+ this.createContext(e.preferWebGLVersion, {
204
+ alpha: r,
205
+ premultipliedAlpha: s,
206
+ antialias: n,
207
+ stencil: !0,
208
+ preserveDrawingBuffer: e.preserveDrawingBuffer,
209
+ powerPreference: e.powerPreference ?? "default"
210
+ });
211
+ }
212
+ }
213
+ /**
214
+ * Initializes the context.
215
+ * @protected
216
+ * @param {WebGLRenderingContext} gl - WebGL context
217
+ */
218
+ initFromContext(e) {
219
+ this.gl = e, this.webGLVersion = e instanceof G.get().getWebGLRenderingContext() ? 1 : 2, this.getExtensions(), this.validateContext(e), this._renderer.runners.contextChange.emit(e);
220
+ const r = this._renderer.view.canvas;
221
+ r.addEventListener("webglcontextlost", this.handleContextLost, !1), r.addEventListener("webglcontextrestored", this.handleContextRestored, !1);
222
+ }
223
+ /**
224
+ * Initialize from context options
225
+ * @protected
226
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
227
+ * @param preferWebGLVersion
228
+ * @param {object} options - context attributes
229
+ */
230
+ createContext(e, r) {
231
+ let s;
232
+ const n = this._renderer.view.canvas;
233
+ if (e === 2 && (s = n.getContext("webgl2", r)), !s && (s = n.getContext("webgl", r), !s))
234
+ throw new Error("This browser does not support WebGL. Try using the canvas renderer");
235
+ this.gl = s, this.initFromContext(this.gl);
236
+ }
237
+ /** Auto-populate the {@link GlContextSystem.extensions extensions}. */
238
+ getExtensions() {
239
+ const { gl: e } = this, r = {
240
+ anisotropicFiltering: e.getExtension("EXT_texture_filter_anisotropic"),
241
+ floatTextureLinear: e.getExtension("OES_texture_float_linear"),
242
+ s3tc: e.getExtension("WEBGL_compressed_texture_s3tc"),
243
+ s3tc_sRGB: e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
244
+ // eslint-disable-line camelcase
245
+ etc: e.getExtension("WEBGL_compressed_texture_etc"),
246
+ etc1: e.getExtension("WEBGL_compressed_texture_etc1"),
247
+ pvrtc: e.getExtension("WEBGL_compressed_texture_pvrtc") || e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
248
+ atc: e.getExtension("WEBGL_compressed_texture_atc"),
249
+ astc: e.getExtension("WEBGL_compressed_texture_astc"),
250
+ bptc: e.getExtension("EXT_texture_compression_bptc"),
251
+ rgtc: e.getExtension("EXT_texture_compression_rgtc"),
252
+ loseContext: e.getExtension("WEBGL_lose_context")
253
+ };
254
+ if (this.webGLVersion === 1)
255
+ this.extensions = {
256
+ ...r,
257
+ drawBuffers: e.getExtension("WEBGL_draw_buffers"),
258
+ depthTexture: e.getExtension("WEBGL_depth_texture"),
259
+ vertexArrayObject: e.getExtension("OES_vertex_array_object") || e.getExtension("MOZ_OES_vertex_array_object") || e.getExtension("WEBKIT_OES_vertex_array_object"),
260
+ uint32ElementIndex: e.getExtension("OES_element_index_uint"),
261
+ // Floats and half-floats
262
+ floatTexture: e.getExtension("OES_texture_float"),
263
+ floatTextureLinear: e.getExtension("OES_texture_float_linear"),
264
+ textureHalfFloat: e.getExtension("OES_texture_half_float"),
265
+ textureHalfFloatLinear: e.getExtension("OES_texture_half_float_linear"),
266
+ vertexAttribDivisorANGLE: e.getExtension("ANGLE_instanced_arrays"),
267
+ srgb: e.getExtension("EXT_sRGB")
268
+ };
269
+ else {
270
+ this.extensions = {
271
+ ...r,
272
+ colorBufferFloat: e.getExtension("EXT_color_buffer_float")
273
+ };
274
+ const s = e.getExtension("WEBGL_provoking_vertex");
275
+ s && s.provokingVertexWEBGL(s.FIRST_VERTEX_CONVENTION_WEBGL);
276
+ }
277
+ }
278
+ /**
279
+ * Handles a lost webgl context
280
+ * @param {WebGLContextEvent} event - The context lost event.
281
+ */
282
+ handleContextLost(e) {
283
+ e.preventDefault(), this._contextLossForced && (this._contextLossForced = !1, setTimeout(() => {
284
+ var r;
285
+ this.gl.isContextLost() && ((r = this.extensions.loseContext) == null || r.restoreContext());
286
+ }, 0));
287
+ }
288
+ /** Handles a restored webgl context. */
289
+ handleContextRestored() {
290
+ this._renderer.runners.contextChange.emit(this.gl);
291
+ }
292
+ destroy() {
293
+ var r;
294
+ const e = this._renderer.view.canvas;
295
+ this._renderer = null, e.removeEventListener("webglcontextlost", this.handleContextLost), e.removeEventListener("webglcontextrestored", this.handleContextRestored), this.gl.useProgram(null), (r = this.extensions.loseContext) == null || r.loseContext();
296
+ }
297
+ /**
298
+ * this function can be called to force a webGL context loss
299
+ * this will release all resources on the GPU.
300
+ * Useful if you need to put Pixi to sleep, and save some GPU memory
301
+ *
302
+ * As soon as render is called - all resources will be created again.
303
+ */
304
+ forceContextLoss() {
305
+ var e;
306
+ (e = this.extensions.loseContext) == null || e.loseContext(), this._contextLossForced = !0;
307
+ }
308
+ /**
309
+ * Validate context.
310
+ * @param {WebGLRenderingContext} gl - Render context.
311
+ */
312
+ validateContext(e) {
313
+ const r = e.getContextAttributes();
314
+ r && !r.stencil && b("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
315
+ const s = this.supports, n = this.webGLVersion === 2, i = this.extensions;
316
+ s.uint32Indices = n || !!i.uint32ElementIndex, s.uniformBufferObject = n, s.vertexArrayObject = n || !!i.vertexArrayObject, s.srgbTextures = n || !!i.srgb, s.nonPowOf2wrapping = n, s.nonPowOf2mipmaps = n, s.msaa = n, s.uint32Indices || b("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
317
+ }
318
+ };
319
+ M.extension = {
320
+ type: [
321
+ l.WebGLSystem
322
+ ],
323
+ name: "context"
324
+ };
325
+ M.defaultOptions = {
326
+ /**
327
+ * {@link WebGLOptions.context}
328
+ * @default null
329
+ */
330
+ context: null,
331
+ /**
332
+ * {@link WebGLOptions.premultipliedAlpha}
333
+ * @default true
334
+ */
335
+ premultipliedAlpha: !0,
336
+ /**
337
+ * {@link WebGLOptions.preserveDrawingBuffer}
338
+ * @default false
339
+ */
340
+ preserveDrawingBuffer: !1,
341
+ /**
342
+ * {@link WebGLOptions.powerPreference}
343
+ * @default default
344
+ */
345
+ powerPreference: void 0,
346
+ /**
347
+ * {@link WebGLOptions.webGLVersion}
348
+ * @default 2
349
+ */
350
+ preferWebGLVersion: 2
351
+ };
352
+ let we = M;
353
+ var y = /* @__PURE__ */ ((t) => (t[t.RGBA = 6408] = "RGBA", t[t.RGB = 6407] = "RGB", t[t.RG = 33319] = "RG", t[t.RED = 6403] = "RED", t[t.RGBA_INTEGER = 36249] = "RGBA_INTEGER", t[t.RGB_INTEGER = 36248] = "RGB_INTEGER", t[t.RG_INTEGER = 33320] = "RG_INTEGER", t[t.RED_INTEGER = 36244] = "RED_INTEGER", t[t.ALPHA = 6406] = "ALPHA", t[t.LUMINANCE = 6409] = "LUMINANCE", t[t.LUMINANCE_ALPHA = 6410] = "LUMINANCE_ALPHA", t[t.DEPTH_COMPONENT = 6402] = "DEPTH_COMPONENT", t[t.DEPTH_STENCIL = 34041] = "DEPTH_STENCIL", t))(y || {}), ie = /* @__PURE__ */ ((t) => (t[t.TEXTURE_2D = 3553] = "TEXTURE_2D", t[t.TEXTURE_CUBE_MAP = 34067] = "TEXTURE_CUBE_MAP", t[t.TEXTURE_2D_ARRAY = 35866] = "TEXTURE_2D_ARRAY", t[t.TEXTURE_CUBE_MAP_POSITIVE_X = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X", t[t.TEXTURE_CUBE_MAP_NEGATIVE_X = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X", t[t.TEXTURE_CUBE_MAP_POSITIVE_Y = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y", t[t.TEXTURE_CUBE_MAP_POSITIVE_Z = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z", t))(ie || {}), f = /* @__PURE__ */ ((t) => (t[t.UNSIGNED_BYTE = 5121] = "UNSIGNED_BYTE", t[t.UNSIGNED_SHORT = 5123] = "UNSIGNED_SHORT", t[t.UNSIGNED_SHORT_5_6_5 = 33635] = "UNSIGNED_SHORT_5_6_5", t[t.UNSIGNED_SHORT_4_4_4_4 = 32819] = "UNSIGNED_SHORT_4_4_4_4", t[t.UNSIGNED_SHORT_5_5_5_1 = 32820] = "UNSIGNED_SHORT_5_5_5_1", t[t.UNSIGNED_INT = 5125] = "UNSIGNED_INT", t[t.UNSIGNED_INT_10F_11F_11F_REV = 35899] = "UNSIGNED_INT_10F_11F_11F_REV", t[t.UNSIGNED_INT_2_10_10_10_REV = 33640] = "UNSIGNED_INT_2_10_10_10_REV", t[t.UNSIGNED_INT_24_8 = 34042] = "UNSIGNED_INT_24_8", t[t.UNSIGNED_INT_5_9_9_9_REV = 35902] = "UNSIGNED_INT_5_9_9_9_REV", t[t.BYTE = 5120] = "BYTE", t[t.SHORT = 5122] = "SHORT", t[t.INT = 5124] = "INT", t[t.FLOAT = 5126] = "FLOAT", t[t.FLOAT_32_UNSIGNED_INT_24_8_REV = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV", t[t.HALF_FLOAT = 36193] = "HALF_FLOAT", t))(f || {});
354
+ const V = {
355
+ uint8x2: f.UNSIGNED_BYTE,
356
+ uint8x4: f.UNSIGNED_BYTE,
357
+ sint8x2: f.BYTE,
358
+ sint8x4: f.BYTE,
359
+ unorm8x2: f.UNSIGNED_BYTE,
360
+ unorm8x4: f.UNSIGNED_BYTE,
361
+ snorm8x2: f.BYTE,
362
+ snorm8x4: f.BYTE,
363
+ uint16x2: f.UNSIGNED_SHORT,
364
+ uint16x4: f.UNSIGNED_SHORT,
365
+ sint16x2: f.SHORT,
366
+ sint16x4: f.SHORT,
367
+ unorm16x2: f.UNSIGNED_SHORT,
368
+ unorm16x4: f.UNSIGNED_SHORT,
369
+ snorm16x2: f.SHORT,
370
+ snorm16x4: f.SHORT,
371
+ float16x2: f.HALF_FLOAT,
372
+ float16x4: f.HALF_FLOAT,
373
+ float32: f.FLOAT,
374
+ float32x2: f.FLOAT,
375
+ float32x3: f.FLOAT,
376
+ float32x4: f.FLOAT,
377
+ uint32: f.UNSIGNED_INT,
378
+ uint32x2: f.UNSIGNED_INT,
379
+ uint32x3: f.UNSIGNED_INT,
380
+ uint32x4: f.UNSIGNED_INT,
381
+ sint32: f.INT,
382
+ sint32x2: f.INT,
383
+ sint32x3: f.INT,
384
+ sint32x4: f.INT
385
+ };
386
+ function Ve(t) {
387
+ return V[t] ?? V.float32;
388
+ }
389
+ const ke = {
390
+ "point-list": 0,
391
+ "line-list": 1,
392
+ "line-strip": 3,
393
+ "triangle-list": 4,
394
+ "triangle-strip": 5
395
+ };
396
+ class ae {
397
+ /** @param renderer - The renderer this System works for. */
398
+ constructor(e) {
399
+ this._geometryVaoHash = /* @__PURE__ */ Object.create(null), this._renderer = e, this._activeGeometry = null, this._activeVao = null, this.hasVao = !0, this.hasInstance = !0;
400
+ }
401
+ /** Sets up the renderer context and necessary buffers. */
402
+ contextChange() {
403
+ const e = this.gl = this._renderer.gl;
404
+ if (!this._renderer.context.supports.vertexArrayObject)
405
+ throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
406
+ const r = this._renderer.context.extensions.vertexArrayObject;
407
+ r && (e.createVertexArray = () => r.createVertexArrayOES(), e.bindVertexArray = (n) => r.bindVertexArrayOES(n), e.deleteVertexArray = (n) => r.deleteVertexArrayOES(n));
408
+ const s = this._renderer.context.extensions.vertexAttribDivisorANGLE;
409
+ s && (e.drawArraysInstanced = (n, i, a, o) => {
410
+ s.drawArraysInstancedANGLE(n, i, a, o);
411
+ }, e.drawElementsInstanced = (n, i, a, o, c) => {
412
+ s.drawElementsInstancedANGLE(n, i, a, o, c);
413
+ }, e.vertexAttribDivisor = (n, i) => s.vertexAttribDivisorANGLE(n, i)), this._activeGeometry = null, this._activeVao = null, this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
414
+ }
415
+ /**
416
+ * Binds geometry so that is can be drawn. Creating a Vao if required
417
+ * @param geometry - Instance of geometry to bind.
418
+ * @param program - Instance of program to use vao for.
419
+ */
420
+ bind(e, r) {
421
+ const s = this.gl;
422
+ this._activeGeometry = e;
423
+ const n = this.getVao(e, r);
424
+ this._activeVao !== n && (this._activeVao = n, s.bindVertexArray(n)), this.updateBuffers();
425
+ }
426
+ /** Reset and unbind any active VAO and geometry. */
427
+ reset() {
428
+ this.unbind();
429
+ }
430
+ /** Update buffers of the currently bound geometry. */
431
+ updateBuffers() {
432
+ const e = this._activeGeometry, r = this._renderer.buffer;
433
+ for (let s = 0; s < e.buffers.length; s++) {
434
+ const n = e.buffers[s];
435
+ r.updateBuffer(n);
436
+ }
437
+ }
438
+ /**
439
+ * Check compatibility between a geometry and a program
440
+ * @param geometry - Geometry instance.
441
+ * @param program - Program instance.
442
+ */
443
+ checkCompatibility(e, r) {
444
+ const s = e.attributes, n = r._attributeData;
445
+ for (const i in n)
446
+ if (!s[i])
447
+ throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`);
448
+ }
449
+ /**
450
+ * Takes a geometry and program and generates a unique signature for them.
451
+ * @param geometry - To get signature from.
452
+ * @param program - To test geometry against.
453
+ * @returns - Unique signature of the geometry and program
454
+ */
455
+ getSignature(e, r) {
456
+ const s = e.attributes, n = r._attributeData, i = ["g", e.uid];
457
+ for (const a in s)
458
+ n[a] && i.push(a, n[a].location);
459
+ return i.join("-");
460
+ }
461
+ getVao(e, r) {
462
+ var s;
463
+ return ((s = this._geometryVaoHash[e.uid]) == null ? void 0 : s[r._key]) || this.initGeometryVao(e, r);
464
+ }
465
+ /**
466
+ * Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
467
+ * If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
468
+ * attribute locations.
469
+ * @param geometry - Instance of geometry to to generate Vao for.
470
+ * @param program
471
+ * @param _incRefCount - Increment refCount of all geometry buffers.
472
+ */
473
+ initGeometryVao(e, r, s = !0) {
474
+ const n = this._renderer.gl, i = this._renderer.buffer;
475
+ this._renderer.shader._getProgramData(r), this.checkCompatibility(e, r);
476
+ const a = this.getSignature(e, r);
477
+ this._geometryVaoHash[e.uid] || (this._geometryVaoHash[e.uid] = /* @__PURE__ */ Object.create(null), e.on("destroy", this.onGeometryDestroy, this));
478
+ const o = this._geometryVaoHash[e.uid];
479
+ let c = o[a];
480
+ if (c)
481
+ return o[r._key] = c, c;
482
+ ye(e, r._attributeData);
483
+ const u = e.buffers;
484
+ c = n.createVertexArray(), n.bindVertexArray(c);
485
+ for (let _ = 0; _ < u.length; _++) {
486
+ const h = u[_];
487
+ i.bind(h);
488
+ }
489
+ return this.activateVao(e, r), o[r._key] = c, o[a] = c, n.bindVertexArray(null), c;
490
+ }
491
+ /**
492
+ * Disposes geometry.
493
+ * @param geometry - Geometry with buffers. Only VAO will be disposed
494
+ * @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
495
+ */
496
+ onGeometryDestroy(e, r) {
497
+ const s = this._geometryVaoHash[e.uid], n = this.gl;
498
+ if (s) {
499
+ if (r)
500
+ for (const i in s)
501
+ this._activeVao !== s[i] && this.unbind(), n.deleteVertexArray(s[i]);
502
+ this._geometryVaoHash[e.uid] = null;
503
+ }
504
+ }
505
+ /**
506
+ * Dispose all WebGL resources of all managed geometries.
507
+ * @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
508
+ */
509
+ destroyAll(e = !1) {
510
+ const r = this.gl;
511
+ for (const s in this._geometryVaoHash) {
512
+ if (e)
513
+ for (const n in this._geometryVaoHash[s]) {
514
+ const i = this._geometryVaoHash[s];
515
+ this._activeVao !== i && this.unbind(), r.deleteVertexArray(i[n]);
516
+ }
517
+ this._geometryVaoHash[s] = null;
518
+ }
519
+ }
520
+ /**
521
+ * Activate vertex array object.
522
+ * @param geometry - Geometry instance.
523
+ * @param program - Shader program instance.
524
+ */
525
+ activateVao(e, r) {
526
+ var o;
527
+ const s = this._renderer.gl, n = this._renderer.buffer, i = e.attributes;
528
+ e.indexBuffer && n.bind(e.indexBuffer);
529
+ let a = null;
530
+ for (const c in i) {
531
+ const u = i[c], _ = u.buffer, h = n.getGlBuffer(_), d = r._attributeData[c];
532
+ if (d) {
533
+ a !== h && (n.bind(_), a = h);
534
+ const m = u.location;
535
+ s.enableVertexAttribArray(m);
536
+ const E = Q(u.format), H = Ve(u.format);
537
+ if (((o = d.format) == null ? void 0 : o.substring(1, 4)) === "int" ? s.vertexAttribIPointer(
538
+ m,
539
+ E.size,
540
+ H,
541
+ u.stride,
542
+ u.offset
543
+ ) : s.vertexAttribPointer(
544
+ m,
545
+ E.size,
546
+ H,
547
+ E.normalised,
548
+ u.stride,
549
+ u.offset
550
+ ), u.instance)
551
+ if (this.hasInstance)
552
+ s.vertexAttribDivisor(m, 1);
553
+ else
554
+ throw new Error("geometry error, GPU Instancing is not supported on this device");
555
+ }
556
+ }
557
+ }
558
+ /**
559
+ * Draws the currently bound geometry.
560
+ * @param topology - The type primitive to render.
561
+ * @param size - The number of elements to be rendered. If not specified, all vertices after the
562
+ * starting vertex will be drawn.
563
+ * @param start - The starting vertex in the geometry to start drawing from. If not specified,
564
+ * drawing will start from the first vertex.
565
+ * @param instanceCount - The number of instances of the set of elements to execute. If not specified,
566
+ * all instances will be drawn.
567
+ */
568
+ draw(e, r, s, n) {
569
+ const { gl: i } = this._renderer, a = this._activeGeometry, o = ke[a.topology || e];
570
+ if (n || (n = a.instanceCount), a.indexBuffer) {
571
+ const c = a.indexBuffer.data.BYTES_PER_ELEMENT, u = c === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
572
+ n > 1 ? i.drawElementsInstanced(o, r || a.indexBuffer.data.length, u, (s || 0) * c, n) : i.drawElements(o, r || a.indexBuffer.data.length, u, (s || 0) * c);
573
+ } else
574
+ n > 1 ? i.drawArraysInstanced(o, s || 0, r || a.getSize(), n) : i.drawArrays(o, s || 0, r || a.getSize());
575
+ return this;
576
+ }
577
+ /** Unbind/reset everything. */
578
+ unbind() {
579
+ this.gl.bindVertexArray(null), this._activeVao = null, this._activeGeometry = null;
580
+ }
581
+ destroy() {
582
+ this._renderer = null, this.gl = null, this._activeVao = null, this._activeGeometry = null;
583
+ }
584
+ }
585
+ ae.extension = {
586
+ type: [
587
+ l.WebGLSystem
588
+ ],
589
+ name: "geometry"
590
+ };
591
+ const Xe = new Be({
592
+ attributes: {
593
+ aPosition: [
594
+ -1,
595
+ -1,
596
+ // Bottom left corner
597
+ 3,
598
+ -1,
599
+ // Bottom right corner, extending beyond right edge
600
+ -1,
601
+ 3
602
+ // Top left corner, extending beyond top edge
603
+ ]
604
+ }
605
+ }), L = class oe {
606
+ constructor(e) {
607
+ this.useBackBuffer = !1, this._useBackBufferThisRender = !1, this._renderer = e;
608
+ }
609
+ init(e = {}) {
610
+ const { useBackBuffer: r, antialias: s } = { ...oe.defaultOptions, ...e };
611
+ this.useBackBuffer = r, this._antialias = s, this._renderer.context.supports.msaa || (b("antialiasing, is not supported on when using the back buffer"), this._antialias = !1), this._state = U.for2d();
612
+ const n = new Ie({
613
+ vertex: `
614
+ attribute vec2 aPosition;
615
+ out vec2 vUv;
616
+
617
+ void main() {
618
+ gl_Position = vec4(aPosition, 0.0, 1.0);
619
+
620
+ vUv = (aPosition + 1.0) / 2.0;
621
+
622
+ // flip dem UVs
623
+ vUv.y = 1.0 - vUv.y;
624
+ }`,
625
+ fragment: `
626
+ in vec2 vUv;
627
+ out vec4 finalColor;
628
+
629
+ uniform sampler2D uTexture;
630
+
631
+ void main() {
632
+ finalColor = texture(uTexture, vUv);
633
+ }`,
634
+ name: "big-triangle"
635
+ });
636
+ this._bigTriangleShader = new x({
637
+ glProgram: n,
638
+ resources: {
639
+ uTexture: S.WHITE.source
640
+ }
641
+ });
642
+ }
643
+ /**
644
+ * This is called before the RenderTargetSystem is started. This is where
645
+ * we replace the target with the back buffer if required.
646
+ * @param options - The options for this render.
647
+ */
648
+ renderStart(e) {
649
+ const r = this._renderer.renderTarget.getRenderTarget(e.target);
650
+ if (this._useBackBufferThisRender = this.useBackBuffer && !!r.isRoot, this._useBackBufferThisRender) {
651
+ const s = this._renderer.renderTarget.getRenderTarget(e.target);
652
+ this._targetTexture = s.colorTexture, e.target = this._getBackBufferTexture(s.colorTexture);
653
+ }
654
+ }
655
+ renderEnd() {
656
+ this._presentBackBuffer();
657
+ }
658
+ _presentBackBuffer() {
659
+ const e = this._renderer;
660
+ e.renderTarget.finishRenderPass(), this._useBackBufferThisRender && (e.renderTarget.bind(this._targetTexture, !1), this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source, e.encoder.draw({
661
+ geometry: Xe,
662
+ shader: this._bigTriangleShader,
663
+ state: this._state
664
+ }));
665
+ }
666
+ _getBackBufferTexture(e) {
667
+ return this._backBufferTexture = this._backBufferTexture || new S({
668
+ source: new z({
669
+ width: e.width,
670
+ height: e.height,
671
+ resolution: e._resolution,
672
+ antialias: this._antialias
673
+ })
674
+ }), this._backBufferTexture.source.resize(
675
+ e.width,
676
+ e.height,
677
+ e._resolution
678
+ ), this._backBufferTexture;
679
+ }
680
+ /** destroys the back buffer */
681
+ destroy() {
682
+ this._backBufferTexture && (this._backBufferTexture.destroy(), this._backBufferTexture = null);
683
+ }
684
+ };
685
+ L.extension = {
686
+ type: [
687
+ l.WebGLSystem
688
+ ],
689
+ name: "backBuffer",
690
+ priority: 1
691
+ };
692
+ L.defaultOptions = {
693
+ /** if true will use the back buffer where required */
694
+ useBackBuffer: !1
695
+ };
696
+ let We = L;
697
+ class ce {
698
+ constructor(e) {
699
+ this._colorMaskCache = 15, this._renderer = e;
700
+ }
701
+ setMask(e) {
702
+ this._colorMaskCache !== e && (this._colorMaskCache = e, this._renderer.gl.colorMask(
703
+ !!(e & 8),
704
+ !!(e & 4),
705
+ !!(e & 2),
706
+ !!(e & 1)
707
+ ));
708
+ }
709
+ }
710
+ ce.extension = {
711
+ type: [
712
+ l.WebGLSystem
713
+ ],
714
+ name: "colorMask"
715
+ };
716
+ class ue {
717
+ constructor(e) {
718
+ this.commandFinished = Promise.resolve(), this._renderer = e;
719
+ }
720
+ setGeometry(e, r) {
721
+ this._renderer.geometry.bind(e, r.glProgram);
722
+ }
723
+ finishRenderPass() {
724
+ }
725
+ draw(e) {
726
+ const r = this._renderer, { geometry: s, shader: n, state: i, skipSync: a, topology: o, size: c, start: u, instanceCount: _ } = e;
727
+ r.shader.bind(n, a), r.geometry.bind(s, r.shader._activeProgram), i && r.state.set(i), r.geometry.draw(o, c, u, _ ?? s.instanceCount);
728
+ }
729
+ destroy() {
730
+ this._renderer = null;
731
+ }
732
+ }
733
+ ue.extension = {
734
+ type: [
735
+ l.WebGLSystem
736
+ ],
737
+ name: "encoder"
738
+ };
739
+ class je {
740
+ constructor() {
741
+ this.width = -1, this.height = -1, this.msaa = !1, this.msaaRenderBuffer = [];
742
+ }
743
+ }
744
+ class _e {
745
+ constructor(e) {
746
+ this._stencilCache = {
747
+ enabled: !1,
748
+ stencilReference: 0,
749
+ stencilMode: g.NONE
750
+ }, this._renderTargetStencilState = /* @__PURE__ */ Object.create(null), e.renderTarget.onRenderTargetChange.add(this);
751
+ }
752
+ contextChange(e) {
753
+ this._gl = e, this._comparisonFuncMapping = {
754
+ always: e.ALWAYS,
755
+ never: e.NEVER,
756
+ equal: e.EQUAL,
757
+ "not-equal": e.NOTEQUAL,
758
+ less: e.LESS,
759
+ "less-equal": e.LEQUAL,
760
+ greater: e.GREATER,
761
+ "greater-equal": e.GEQUAL
762
+ }, this._stencilOpsMapping = {
763
+ keep: e.KEEP,
764
+ zero: e.ZERO,
765
+ replace: e.REPLACE,
766
+ invert: e.INVERT,
767
+ "increment-clamp": e.INCR,
768
+ "decrement-clamp": e.DECR,
769
+ "increment-wrap": e.INCR_WRAP,
770
+ "decrement-wrap": e.DECR_WRAP
771
+ }, this._stencilCache.enabled = !1, this._stencilCache.stencilMode = g.NONE, this._stencilCache.stencilReference = 0;
772
+ }
773
+ onRenderTargetChange(e) {
774
+ if (this._activeRenderTarget === e)
775
+ return;
776
+ this._activeRenderTarget = e;
777
+ let r = this._renderTargetStencilState[e.uid];
778
+ r || (r = this._renderTargetStencilState[e.uid] = {
779
+ stencilMode: g.DISABLED,
780
+ stencilReference: 0
781
+ }), this.setStencilMode(r.stencilMode, r.stencilReference);
782
+ }
783
+ setStencilMode(e, r) {
784
+ const s = this._renderTargetStencilState[this._activeRenderTarget.uid], n = this._gl, i = Ce[e], a = this._stencilCache;
785
+ if (s.stencilMode = e, s.stencilReference = r, e === g.DISABLED) {
786
+ this._stencilCache.enabled && (this._stencilCache.enabled = !1, n.disable(n.STENCIL_TEST));
787
+ return;
788
+ }
789
+ this._stencilCache.enabled || (this._stencilCache.enabled = !0, n.enable(n.STENCIL_TEST)), (e !== a.stencilMode || a.stencilReference !== r) && (a.stencilMode = e, a.stencilReference = r, n.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare], r, 255), n.stencilOp(n.KEEP, n.KEEP, this._stencilOpsMapping[i.stencilBack.passOp]));
790
+ }
791
+ }
792
+ _e.extension = {
793
+ type: [
794
+ l.WebGLSystem
795
+ ],
796
+ name: "stencil"
797
+ };
798
+ const fe = {
799
+ f32: 4,
800
+ "vec2<f32>": 8,
801
+ "vec3<f32>": 12,
802
+ "vec4<f32>": 16,
803
+ "mat2x2<f32>": 16 * 2,
804
+ "mat3x3<f32>": 16 * 3,
805
+ "mat4x4<f32>": 16 * 4
806
+ // TODO - not essential for now but support these in the future
807
+ // int: 4,
808
+ // ivec2: 8,
809
+ // ivec3: 12,
810
+ // ivec4: 16,
811
+ // uint: 4,
812
+ // uvec2: 8,
813
+ // uvec3: 12,
814
+ // uvec4: 16,
815
+ // bool: 4,
816
+ // bvec2: 8,
817
+ // bvec3: 12,
818
+ // bvec4: 16,
819
+ // mat2: 16 * 2,
820
+ // mat3: 16 * 3,
821
+ // mat4: 16 * 4,
822
+ };
823
+ function Ke(t) {
824
+ const e = t.map((i) => ({
825
+ data: i,
826
+ offset: 0,
827
+ size: 0
828
+ }));
829
+ let r = 0, s = 0, n = 0;
830
+ for (let i = 0; i < e.length; i++) {
831
+ const a = e[i];
832
+ if (r = fe[a.data.type], !r)
833
+ throw new Error(`Unknown type ${a.data.type}`);
834
+ if (a.data.size > 1 && (r = Math.max(r, 16) * a.data.size), a.size = r, s % r !== 0 && s < 16) {
835
+ const o = s % r % 16;
836
+ s += o, n += o;
837
+ }
838
+ s + r > 16 ? (n = Math.ceil(n / 16) * 16, a.offset = n, n += r, s = r) : (a.offset = n, s += r, n += r);
839
+ }
840
+ return n = Math.ceil(n / 16) * 16, { uboElements: e, size: n };
841
+ }
842
+ function $e(t, e) {
843
+ const r = Math.max(fe[t.data.type] / 16, 1), s = t.data.value.length / t.data.size, n = (4 - s % 4) % 4;
844
+ return `
845
+ v = uv.${t.data.name};
846
+ offset += ${e};
847
+
848
+ arrayOffset = offset;
849
+
850
+ t = 0;
851
+
852
+ for(var i=0; i < ${t.data.size * r}; i++)
853
+ {
854
+ for(var j = 0; j < ${s}; j++)
855
+ {
856
+ data[arrayOffset++] = v[t++];
857
+ }
858
+ ${n !== 0 ? `arrayOffset += ${n};` : ""}
859
+ }
860
+ `;
861
+ }
862
+ function ze(t) {
863
+ return Ge(
864
+ t,
865
+ "uboStd40",
866
+ $e,
867
+ Ue
868
+ );
869
+ }
870
+ class he extends Oe {
871
+ constructor() {
872
+ super({
873
+ createUboElements: Ke,
874
+ generateUboSync: ze
875
+ });
876
+ }
877
+ }
878
+ he.extension = {
879
+ type: [l.WebGLSystem],
880
+ name: "ubo"
881
+ };
882
+ class Ye {
883
+ constructor() {
884
+ this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new w();
885
+ }
886
+ init(e, r) {
887
+ this._renderer = e, this._renderTargetSystem = r, e.runners.contextChange.add(this);
888
+ }
889
+ contextChange() {
890
+ this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new w();
891
+ }
892
+ copyToTexture(e, r, s, n, i) {
893
+ const a = this._renderTargetSystem, o = this._renderer, c = a.getGpuRenderTarget(e), u = o.gl;
894
+ return this.finishRenderPass(e), u.bindFramebuffer(u.FRAMEBUFFER, c.resolveTargetFramebuffer), o.texture.bind(r, 0), u.copyTexSubImage2D(
895
+ u.TEXTURE_2D,
896
+ 0,
897
+ i.x,
898
+ i.y,
899
+ s.x,
900
+ s.y,
901
+ n.width,
902
+ n.height
903
+ ), r;
904
+ }
905
+ startRenderPass(e, r = !0, s, n) {
906
+ const i = this._renderTargetSystem, a = e.colorTexture, o = i.getGpuRenderTarget(e);
907
+ let c = n.y;
908
+ e.isRoot && (c = a.pixelHeight - n.height), e.colorTextures.forEach((h) => {
909
+ this._renderer.texture.unbind(h);
910
+ });
911
+ const u = this._renderer.gl;
912
+ u.bindFramebuffer(u.FRAMEBUFFER, o.framebuffer);
913
+ const _ = this._viewPortCache;
914
+ (_.x !== n.x || _.y !== c || _.width !== n.width || _.height !== n.height) && (_.x = n.x, _.y = c, _.width = n.width, _.height = n.height, u.viewport(
915
+ n.x,
916
+ c,
917
+ n.width,
918
+ n.height
919
+ )), !o.depthStencilRenderBuffer && (e.stencil || e.depth) && this._initStencil(o), this.clear(e, r, s);
920
+ }
921
+ finishRenderPass(e) {
922
+ const s = this._renderTargetSystem.getGpuRenderTarget(e);
923
+ if (!s.msaa)
924
+ return;
925
+ const n = this._renderer.gl;
926
+ n.bindFramebuffer(n.FRAMEBUFFER, s.resolveTargetFramebuffer), n.bindFramebuffer(n.READ_FRAMEBUFFER, s.framebuffer), n.blitFramebuffer(
927
+ 0,
928
+ 0,
929
+ s.width,
930
+ s.height,
931
+ 0,
932
+ 0,
933
+ s.width,
934
+ s.height,
935
+ n.COLOR_BUFFER_BIT,
936
+ n.NEAREST
937
+ ), n.bindFramebuffer(n.FRAMEBUFFER, s.framebuffer);
938
+ }
939
+ initGpuRenderTarget(e) {
940
+ const r = this._renderer, s = r.gl, n = new je();
941
+ return e.colorTexture.resource === r.gl.canvas ? (n.framebuffer = null, n) : (this._initColor(e, n), s.bindFramebuffer(s.FRAMEBUFFER, null), n);
942
+ }
943
+ destroyGpuRenderTarget(e) {
944
+ const r = this._renderer.gl;
945
+ e.framebuffer && (r.deleteFramebuffer(e.framebuffer), e.framebuffer = null), e.resolveTargetFramebuffer && (r.deleteFramebuffer(e.resolveTargetFramebuffer), e.resolveTargetFramebuffer = null), e.depthStencilRenderBuffer && (r.deleteRenderbuffer(e.depthStencilRenderBuffer), e.depthStencilRenderBuffer = null), e.msaaRenderBuffer.forEach((s) => {
946
+ r.deleteRenderbuffer(s);
947
+ }), e.msaaRenderBuffer = null;
948
+ }
949
+ clear(e, r, s) {
950
+ if (!r)
951
+ return;
952
+ const n = this._renderTargetSystem;
953
+ typeof r == "boolean" && (r = r ? B.ALL : B.NONE);
954
+ const i = this._renderer.gl;
955
+ if (r & B.COLOR) {
956
+ s ?? (s = n.defaultClearColor);
957
+ const a = this._clearColorCache, o = s;
958
+ (a[0] !== o[0] || a[1] !== o[1] || a[2] !== o[2] || a[3] !== o[3]) && (a[0] = o[0], a[1] = o[1], a[2] = o[2], a[3] = o[3], i.clearColor(o[0], o[1], o[2], o[3]));
959
+ }
960
+ i.clear(r);
961
+ }
962
+ resizeGpuRenderTarget(e) {
963
+ if (e.isRoot)
964
+ return;
965
+ const s = this._renderTargetSystem.getGpuRenderTarget(e);
966
+ this._resizeColor(e, s), e.stencil && this._resizeStencil(s);
967
+ }
968
+ _initColor(e, r) {
969
+ const s = this._renderer, n = s.gl, i = n.createFramebuffer();
970
+ if (r.resolveTargetFramebuffer = i, n.bindFramebuffer(n.FRAMEBUFFER, i), r.width = e.colorTexture.source.pixelWidth, r.height = e.colorTexture.source.pixelHeight, e.colorTextures.forEach((a, o) => {
971
+ const c = a.source;
972
+ c.antialias && (s.context.supports.msaa ? r.msaa = !0 : b("[RenderTexture] Antialiasing on textures is not supported in WebGL1")), s.texture.bindSource(c, 0);
973
+ const _ = s.texture.getGlSource(c).texture;
974
+ n.framebufferTexture2D(
975
+ n.FRAMEBUFFER,
976
+ n.COLOR_ATTACHMENT0 + o,
977
+ 3553,
978
+ // texture.target,
979
+ _,
980
+ 0
981
+ );
982
+ }), r.msaa) {
983
+ const a = n.createFramebuffer();
984
+ r.framebuffer = a, n.bindFramebuffer(n.FRAMEBUFFER, a), e.colorTextures.forEach((o, c) => {
985
+ const u = n.createRenderbuffer();
986
+ r.msaaRenderBuffer[c] = u;
987
+ });
988
+ } else
989
+ r.framebuffer = i;
990
+ this._resizeColor(e, r);
991
+ }
992
+ _resizeColor(e, r) {
993
+ const s = e.colorTexture.source;
994
+ if (r.width = s.pixelWidth, r.height = s.pixelHeight, e.colorTextures.forEach((n, i) => {
995
+ i !== 0 && n.source.resize(s.width, s.height, s._resolution);
996
+ }), r.msaa) {
997
+ const n = this._renderer, i = n.gl, a = r.framebuffer;
998
+ i.bindFramebuffer(i.FRAMEBUFFER, a), e.colorTextures.forEach((o, c) => {
999
+ const u = o.source;
1000
+ n.texture.bindSource(u, 0);
1001
+ const h = n.texture.getGlSource(u).internalFormat, d = r.msaaRenderBuffer[c];
1002
+ i.bindRenderbuffer(
1003
+ i.RENDERBUFFER,
1004
+ d
1005
+ ), i.renderbufferStorageMultisample(
1006
+ i.RENDERBUFFER,
1007
+ 4,
1008
+ h,
1009
+ u.pixelWidth,
1010
+ u.pixelHeight
1011
+ ), i.framebufferRenderbuffer(
1012
+ i.FRAMEBUFFER,
1013
+ i.COLOR_ATTACHMENT0 + c,
1014
+ i.RENDERBUFFER,
1015
+ d
1016
+ );
1017
+ });
1018
+ }
1019
+ }
1020
+ _initStencil(e) {
1021
+ if (e.framebuffer === null)
1022
+ return;
1023
+ const r = this._renderer.gl, s = r.createRenderbuffer();
1024
+ e.depthStencilRenderBuffer = s, r.bindRenderbuffer(
1025
+ r.RENDERBUFFER,
1026
+ s
1027
+ ), r.framebufferRenderbuffer(
1028
+ r.FRAMEBUFFER,
1029
+ r.DEPTH_STENCIL_ATTACHMENT,
1030
+ r.RENDERBUFFER,
1031
+ s
1032
+ ), this._resizeStencil(e);
1033
+ }
1034
+ _resizeStencil(e) {
1035
+ const r = this._renderer.gl;
1036
+ r.bindRenderbuffer(
1037
+ r.RENDERBUFFER,
1038
+ e.depthStencilRenderBuffer
1039
+ ), e.msaa ? r.renderbufferStorageMultisample(
1040
+ r.RENDERBUFFER,
1041
+ 4,
1042
+ r.DEPTH24_STENCIL8,
1043
+ e.width,
1044
+ e.height
1045
+ ) : r.renderbufferStorage(
1046
+ r.RENDERBUFFER,
1047
+ this._renderer.context.webGLVersion === 2 ? r.DEPTH24_STENCIL8 : r.DEPTH_STENCIL,
1048
+ e.width,
1049
+ e.height
1050
+ );
1051
+ }
1052
+ }
1053
+ class le extends Pe {
1054
+ constructor(e) {
1055
+ super(e), this.adaptor = new Ye(), this.adaptor.init(e, this);
1056
+ }
1057
+ }
1058
+ le.extension = {
1059
+ type: [l.WebGLSystem],
1060
+ name: "renderTarget"
1061
+ };
1062
+ function qe(t, e) {
1063
+ const r = [], s = [`
1064
+ var g = s.groups;
1065
+ var sS = r.shader;
1066
+ var p = s.glProgram;
1067
+ var ugS = r.uniformGroup;
1068
+ var resources;
1069
+ `];
1070
+ let n = !1, i = 0, a = 0;
1071
+ const o = e._getProgramData(t.glProgram);
1072
+ for (const u in t.groups) {
1073
+ const _ = t.groups[u];
1074
+ r.push(`
1075
+ resources = g[${u}].resources;
1076
+ `);
1077
+ for (const h in _.resources) {
1078
+ const d = _.resources[h];
1079
+ if (d instanceof F)
1080
+ d.ubo ? r.push(`
1081
+ sS.bindUniformBlock(
1082
+ resources[${h}],
1083
+ sS._uniformBindMap[${u}[${h}],
1084
+ ${i++}
1085
+ );
1086
+ `) : r.push(`
1087
+ ugS.updateUniformGroup(resources[${h}], p, sD);
1088
+ `);
1089
+ else if (d instanceof te)
1090
+ r.push(`
1091
+ sS.bindUniformBlock(
1092
+ resources[${h}],
1093
+ sS._uniformBindMap[${u}[${h}],
1094
+ ${i++}
1095
+ );
1096
+ `);
1097
+ else if (d instanceof z) {
1098
+ const m = t._uniformBindMap[u][h], E = o.uniformData[m];
1099
+ E && (n || (n = !0, s.push(`
1100
+ var tS = r.texture;
1101
+ `)), e._gl.uniform1i(E.location, a), r.push(`
1102
+ tS.bind(resources[${h}], ${a});
1103
+ `), a++);
1104
+ }
1105
+ }
1106
+ }
1107
+ const c = [...s, ...r].join(`
1108
+ `);
1109
+ return new Function("r", "s", "sD", c);
1110
+ }
1111
+ class Ze {
1112
+ /**
1113
+ * Makes a new Pixi program.
1114
+ * @param program - webgl program
1115
+ * @param uniformData - uniforms
1116
+ */
1117
+ constructor(e, r) {
1118
+ this.program = e, this.uniformData = r, this.uniformGroups = {}, this.uniformDirtyGroups = {}, this.uniformBlockBindings = {};
1119
+ }
1120
+ /** Destroys this program. */
1121
+ destroy() {
1122
+ this.uniformData = null, this.uniformGroups = null, this.uniformDirtyGroups = null, this.uniformBlockBindings = null, this.program = null;
1123
+ }
1124
+ }
1125
+ function k(t, e, r) {
1126
+ const s = t.createShader(e);
1127
+ return t.shaderSource(s, r), t.compileShader(s), s;
1128
+ }
1129
+ function I(t) {
1130
+ const e = new Array(t);
1131
+ for (let r = 0; r < e.length; r++)
1132
+ e[r] = !1;
1133
+ return e;
1134
+ }
1135
+ function de(t, e) {
1136
+ switch (t) {
1137
+ case "float":
1138
+ return 0;
1139
+ case "vec2":
1140
+ return new Float32Array(2 * e);
1141
+ case "vec3":
1142
+ return new Float32Array(3 * e);
1143
+ case "vec4":
1144
+ return new Float32Array(4 * e);
1145
+ case "int":
1146
+ case "uint":
1147
+ case "sampler2D":
1148
+ case "sampler2DArray":
1149
+ return 0;
1150
+ case "ivec2":
1151
+ return new Int32Array(2 * e);
1152
+ case "ivec3":
1153
+ return new Int32Array(3 * e);
1154
+ case "ivec4":
1155
+ return new Int32Array(4 * e);
1156
+ case "uvec2":
1157
+ return new Uint32Array(2 * e);
1158
+ case "uvec3":
1159
+ return new Uint32Array(3 * e);
1160
+ case "uvec4":
1161
+ return new Uint32Array(4 * e);
1162
+ case "bool":
1163
+ return !1;
1164
+ case "bvec2":
1165
+ return I(2 * e);
1166
+ case "bvec3":
1167
+ return I(3 * e);
1168
+ case "bvec4":
1169
+ return I(4 * e);
1170
+ case "mat2":
1171
+ return new Float32Array([
1172
+ 1,
1173
+ 0,
1174
+ 0,
1175
+ 1
1176
+ ]);
1177
+ case "mat3":
1178
+ return new Float32Array([
1179
+ 1,
1180
+ 0,
1181
+ 0,
1182
+ 0,
1183
+ 1,
1184
+ 0,
1185
+ 0,
1186
+ 0,
1187
+ 1
1188
+ ]);
1189
+ case "mat4":
1190
+ return new Float32Array([
1191
+ 1,
1192
+ 0,
1193
+ 0,
1194
+ 0,
1195
+ 0,
1196
+ 1,
1197
+ 0,
1198
+ 0,
1199
+ 0,
1200
+ 0,
1201
+ 1,
1202
+ 0,
1203
+ 0,
1204
+ 0,
1205
+ 0,
1206
+ 1
1207
+ ]);
1208
+ }
1209
+ return null;
1210
+ }
1211
+ let p = null;
1212
+ const X = {
1213
+ FLOAT: "float",
1214
+ FLOAT_VEC2: "vec2",
1215
+ FLOAT_VEC3: "vec3",
1216
+ FLOAT_VEC4: "vec4",
1217
+ INT: "int",
1218
+ INT_VEC2: "ivec2",
1219
+ INT_VEC3: "ivec3",
1220
+ INT_VEC4: "ivec4",
1221
+ UNSIGNED_INT: "uint",
1222
+ UNSIGNED_INT_VEC2: "uvec2",
1223
+ UNSIGNED_INT_VEC3: "uvec3",
1224
+ UNSIGNED_INT_VEC4: "uvec4",
1225
+ BOOL: "bool",
1226
+ BOOL_VEC2: "bvec2",
1227
+ BOOL_VEC3: "bvec3",
1228
+ BOOL_VEC4: "bvec4",
1229
+ FLOAT_MAT2: "mat2",
1230
+ FLOAT_MAT3: "mat3",
1231
+ FLOAT_MAT4: "mat4",
1232
+ SAMPLER_2D: "sampler2D",
1233
+ INT_SAMPLER_2D: "sampler2D",
1234
+ UNSIGNED_INT_SAMPLER_2D: "sampler2D",
1235
+ SAMPLER_CUBE: "samplerCube",
1236
+ INT_SAMPLER_CUBE: "samplerCube",
1237
+ UNSIGNED_INT_SAMPLER_CUBE: "samplerCube",
1238
+ SAMPLER_2D_ARRAY: "sampler2DArray",
1239
+ INT_SAMPLER_2D_ARRAY: "sampler2DArray",
1240
+ UNSIGNED_INT_SAMPLER_2D_ARRAY: "sampler2DArray"
1241
+ }, Qe = {
1242
+ float: "float32",
1243
+ vec2: "float32x2",
1244
+ vec3: "float32x3",
1245
+ vec4: "float32x4",
1246
+ int: "sint32",
1247
+ ivec2: "sint32x2",
1248
+ ivec3: "sint32x3",
1249
+ ivec4: "sint32x4",
1250
+ uint: "uint32",
1251
+ uvec2: "uint32x2",
1252
+ uvec3: "uint32x3",
1253
+ uvec4: "uint32x4",
1254
+ bool: "uint32",
1255
+ bvec2: "uint32x2",
1256
+ bvec3: "uint32x3",
1257
+ bvec4: "uint32x4"
1258
+ };
1259
+ function me(t, e) {
1260
+ if (!p) {
1261
+ const r = Object.keys(X);
1262
+ p = {};
1263
+ for (let s = 0; s < r.length; ++s) {
1264
+ const n = r[s];
1265
+ p[t[n]] = X[n];
1266
+ }
1267
+ }
1268
+ return p[e];
1269
+ }
1270
+ function Je(t, e) {
1271
+ const r = me(t, e);
1272
+ return Qe[r] || "float32";
1273
+ }
1274
+ function et(t, e, r = !1) {
1275
+ const s = {}, n = e.getProgramParameter(t, e.ACTIVE_ATTRIBUTES);
1276
+ for (let a = 0; a < n; a++) {
1277
+ const o = e.getActiveAttrib(t, a);
1278
+ if (o.name.startsWith("gl_"))
1279
+ continue;
1280
+ const c = Je(e, o.type);
1281
+ s[o.name] = {
1282
+ location: 0,
1283
+ // set further down..
1284
+ format: c,
1285
+ stride: Q(c).stride,
1286
+ offset: 0,
1287
+ instance: !1,
1288
+ start: 0
1289
+ };
1290
+ }
1291
+ const i = Object.keys(s);
1292
+ if (r) {
1293
+ i.sort((a, o) => a > o ? 1 : -1);
1294
+ for (let a = 0; a < i.length; a++)
1295
+ s[i[a]].location = a, e.bindAttribLocation(t, a, i[a]);
1296
+ e.linkProgram(t);
1297
+ } else
1298
+ for (let a = 0; a < i.length; a++)
1299
+ s[i[a]].location = e.getAttribLocation(t, i[a]);
1300
+ return s;
1301
+ }
1302
+ function tt(t, e) {
1303
+ if (!e.ACTIVE_UNIFORM_BLOCKS)
1304
+ return {};
1305
+ const r = {}, s = e.getProgramParameter(t, e.ACTIVE_UNIFORM_BLOCKS);
1306
+ for (let n = 0; n < s; n++) {
1307
+ const i = e.getActiveUniformBlockName(t, n), a = e.getUniformBlockIndex(t, i), o = e.getActiveUniformBlockParameter(t, n, e.UNIFORM_BLOCK_DATA_SIZE);
1308
+ r[i] = {
1309
+ name: i,
1310
+ index: a,
1311
+ size: o
1312
+ };
1313
+ }
1314
+ return r;
1315
+ }
1316
+ function rt(t, e) {
1317
+ const r = {}, s = e.getProgramParameter(t, e.ACTIVE_UNIFORMS);
1318
+ for (let n = 0; n < s; n++) {
1319
+ const i = e.getActiveUniform(t, n), a = i.name.replace(/\[.*?\]$/, ""), o = !!i.name.match(/\[.*?\]$/), c = me(e, i.type);
1320
+ r[a] = {
1321
+ name: a,
1322
+ index: n,
1323
+ type: c,
1324
+ size: i.size,
1325
+ isArray: o,
1326
+ value: de(c, i.size)
1327
+ };
1328
+ }
1329
+ return r;
1330
+ }
1331
+ function W(t, e) {
1332
+ const r = t.getShaderSource(e).split(`
1333
+ `).map((u, _) => `${_}: ${u}`), s = t.getShaderInfoLog(e), n = s.split(`
1334
+ `), i = {}, a = n.map((u) => parseFloat(u.replace(/^ERROR\: 0\:([\d]+)\:.*$/, "$1"))).filter((u) => u && !i[u] ? (i[u] = !0, !0) : !1), o = [""];
1335
+ a.forEach((u) => {
1336
+ r[u - 1] = `%c${r[u - 1]}%c`, o.push("background: #FF0000; color:#FFFFFF; font-size: 10px", "font-size: 10px");
1337
+ });
1338
+ const c = r.join(`
1339
+ `);
1340
+ o[0] = c, console.error(s), console.groupCollapsed("click to view full shader code"), console.warn(...o), console.groupEnd();
1341
+ }
1342
+ function st(t, e, r, s) {
1343
+ t.getProgramParameter(e, t.LINK_STATUS) || (t.getShaderParameter(r, t.COMPILE_STATUS) || W(t, r), t.getShaderParameter(s, t.COMPILE_STATUS) || W(t, s), console.error("PixiJS Error: Could not initialize shader."), t.getProgramInfoLog(e) !== "" && console.warn("PixiJS Warning: gl.getProgramInfoLog()", t.getProgramInfoLog(e)));
1344
+ }
1345
+ function nt(t, e) {
1346
+ const r = k(t, t.VERTEX_SHADER, e.vertex), s = k(t, t.FRAGMENT_SHADER, e.fragment), n = t.createProgram();
1347
+ t.attachShader(n, r), t.attachShader(n, s);
1348
+ const i = e.transformFeedbackVaryings;
1349
+ i && (typeof t.transformFeedbackVaryings != "function" ? b("TransformFeedback is not supported but TransformFeedbackVaryings are given.") : t.transformFeedbackVaryings(
1350
+ n,
1351
+ i.names,
1352
+ i.bufferMode === "separate" ? t.SEPARATE_ATTRIBS : t.INTERLEAVED_ATTRIBS
1353
+ )), t.linkProgram(n), t.getProgramParameter(n, t.LINK_STATUS) || st(t, n, r, s), e._attributeData = et(
1354
+ n,
1355
+ t,
1356
+ !/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)
1357
+ ), e._uniformData = rt(n, t), e._uniformBlockData = tt(n, t), t.deleteShader(r), t.deleteShader(s);
1358
+ const a = {};
1359
+ for (const c in e._uniformData) {
1360
+ const u = e._uniformData[c];
1361
+ a[c] = {
1362
+ location: t.getUniformLocation(n, c),
1363
+ value: de(u.type, u.size)
1364
+ };
1365
+ }
1366
+ return new Ze(n, a);
1367
+ }
1368
+ const R = {
1369
+ textureCount: 0,
1370
+ blockIndex: 0
1371
+ };
1372
+ class Ee {
1373
+ constructor(e) {
1374
+ this._activeProgram = null, this._programDataHash = /* @__PURE__ */ Object.create(null), this._nextIndex = 0, this._boundUniformsIdsToIndexHash = /* @__PURE__ */ Object.create(null), this._boundIndexToUniformsHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._renderer = e;
1375
+ }
1376
+ contextChange(e) {
1377
+ this._gl = e, this._maxBindings = e.MAX_UNIFORM_BUFFER_BINDINGS ? e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS) : 0, this._programDataHash = /* @__PURE__ */ Object.create(null), this._boundUniformsIdsToIndexHash = /* @__PURE__ */ Object.create(null), this._boundIndexToUniformsHash = /* @__PURE__ */ Object.create(null), this._activeProgram = null;
1378
+ }
1379
+ /**
1380
+ * Changes the current shader to the one given in parameter.
1381
+ * @param shader - the new shader
1382
+ * @param skipSync - false if the shader should automatically sync its uniforms.
1383
+ * @returns the glProgram that belongs to the shader.
1384
+ */
1385
+ bind(e, r) {
1386
+ if (this._setProgram(e.glProgram), r)
1387
+ return;
1388
+ R.textureCount = 0, R.blockIndex = 0;
1389
+ let s = this._shaderSyncFunctions[e.glProgram._key];
1390
+ s || (s = this._shaderSyncFunctions[e.glProgram._key] = this._generateShaderSync(e, this)), s(this._renderer, e, R);
1391
+ }
1392
+ /**
1393
+ * Updates the uniform group.
1394
+ * @param uniformGroup - the uniform group to update
1395
+ */
1396
+ updateUniformGroup(e) {
1397
+ this._renderer.uniformGroup.updateUniformGroup(e, this._activeProgram, R);
1398
+ }
1399
+ /**
1400
+ * Binds a uniform block to the shader.
1401
+ * @param uniformGroup - the uniform group to bind
1402
+ * @param name - the name of the uniform block
1403
+ * @param index - the index of the uniform block
1404
+ */
1405
+ bindUniformBlock(e, r, s = 0) {
1406
+ const n = this._renderer.buffer, i = this._getProgramData(this._activeProgram), a = e._bufferResource;
1407
+ a && this._renderer.ubo.updateUniformGroup(e), n.updateBuffer(e.buffer);
1408
+ let o = this._boundUniformsIdsToIndexHash[e.uid];
1409
+ if (o === void 0) {
1410
+ const _ = this._nextIndex++ % this._maxBindings, h = this._boundIndexToUniformsHash[_];
1411
+ h && (this._boundUniformsIdsToIndexHash[h.uid] = void 0), o = this._boundUniformsIdsToIndexHash[e.uid] = _, this._boundIndexToUniformsHash[_] = e, a ? n.bindBufferRange(e.buffer, _, e.offset) : n.bindBufferBase(e.buffer, _);
1412
+ }
1413
+ const c = this._gl, u = this._activeProgram._uniformBlockData[r].index;
1414
+ i.uniformBlockBindings[s] !== o && (i.uniformBlockBindings[s] = o, c.uniformBlockBinding(i.program, u, o));
1415
+ }
1416
+ _setProgram(e) {
1417
+ if (this._activeProgram === e)
1418
+ return;
1419
+ this._activeProgram = e;
1420
+ const r = this._getProgramData(e);
1421
+ this._gl.useProgram(r.program);
1422
+ }
1423
+ /**
1424
+ * @param program - the program to get the data for
1425
+ * @internal
1426
+ * @private
1427
+ */
1428
+ _getProgramData(e) {
1429
+ return this._programDataHash[e._key] || this._createProgramData(e);
1430
+ }
1431
+ _createProgramData(e) {
1432
+ const r = e._key;
1433
+ return this._programDataHash[r] = nt(this._gl, e), this._programDataHash[r];
1434
+ }
1435
+ destroy() {
1436
+ for (const e of Object.keys(this._programDataHash))
1437
+ this._programDataHash[e].destroy(), this._programDataHash[e] = null;
1438
+ this._programDataHash = null, this._boundUniformsIdsToIndexHash = null;
1439
+ }
1440
+ /**
1441
+ * Creates a function that can be executed that will sync the shader as efficiently as possible.
1442
+ * Overridden by the unsafe eval package if you don't want eval used in your project.
1443
+ * @param shader - the shader to generate the sync function for
1444
+ * @param shaderSystem - the shader system to use
1445
+ * @returns - the generated sync function
1446
+ * @ignore
1447
+ */
1448
+ _generateShaderSync(e, r) {
1449
+ return qe(e, r);
1450
+ }
1451
+ }
1452
+ Ee.extension = {
1453
+ type: [
1454
+ l.WebGLSystem
1455
+ ],
1456
+ name: "shader"
1457
+ };
1458
+ const it = {
1459
+ f32: `if (cv !== v) {
1460
+ cu.value = v;
1461
+ gl.uniform1f(location, v);
1462
+ }`,
1463
+ "vec2<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1464
+ cv[0] = v[0];
1465
+ cv[1] = v[1];
1466
+ gl.uniform2f(location, v[0], v[1]);
1467
+ }`,
1468
+ "vec3<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1469
+ cv[0] = v[0];
1470
+ cv[1] = v[1];
1471
+ cv[2] = v[2];
1472
+ gl.uniform3f(location, v[0], v[1], v[2]);
1473
+ }`,
1474
+ "vec4<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1475
+ cv[0] = v[0];
1476
+ cv[1] = v[1];
1477
+ cv[2] = v[2];
1478
+ cv[3] = v[3];
1479
+ gl.uniform4f(location, v[0], v[1], v[2], v[3]);
1480
+ }`,
1481
+ i32: `if (cv !== v) {
1482
+ cu.value = v;
1483
+ gl.uniform1i(location, v);
1484
+ }`,
1485
+ "vec2<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1486
+ cv[0] = v[0];
1487
+ cv[1] = v[1];
1488
+ gl.uniform2i(location, v[0], v[1]);
1489
+ }`,
1490
+ "vec3<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1491
+ cv[0] = v[0];
1492
+ cv[1] = v[1];
1493
+ cv[2] = v[2];
1494
+ gl.uniform3i(location, v[0], v[1], v[2]);
1495
+ }`,
1496
+ "vec4<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1497
+ cv[0] = v[0];
1498
+ cv[1] = v[1];
1499
+ cv[2] = v[2];
1500
+ cv[3] = v[3];
1501
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
1502
+ }`,
1503
+ u32: `if (cv !== v) {
1504
+ cu.value = v;
1505
+ gl.uniform1ui(location, v);
1506
+ }`,
1507
+ "vec2<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1508
+ cv[0] = v[0];
1509
+ cv[1] = v[1];
1510
+ gl.uniform2ui(location, v[0], v[1]);
1511
+ }`,
1512
+ "vec3<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1513
+ cv[0] = v[0];
1514
+ cv[1] = v[1];
1515
+ cv[2] = v[2];
1516
+ gl.uniform3ui(location, v[0], v[1], v[2]);
1517
+ }`,
1518
+ "vec4<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1519
+ cv[0] = v[0];
1520
+ cv[1] = v[1];
1521
+ cv[2] = v[2];
1522
+ cv[3] = v[3];
1523
+ gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
1524
+ }`,
1525
+ bool: `if (cv !== v) {
1526
+ cu.value = v;
1527
+ gl.uniform1i(location, v);
1528
+ }`,
1529
+ "vec2<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1530
+ cv[0] = v[0];
1531
+ cv[1] = v[1];
1532
+ gl.uniform2i(location, v[0], v[1]);
1533
+ }`,
1534
+ "vec3<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1535
+ cv[0] = v[0];
1536
+ cv[1] = v[1];
1537
+ cv[2] = v[2];
1538
+ gl.uniform3i(location, v[0], v[1], v[2]);
1539
+ }`,
1540
+ "vec4<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1541
+ cv[0] = v[0];
1542
+ cv[1] = v[1];
1543
+ cv[2] = v[2];
1544
+ cv[3] = v[3];
1545
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
1546
+ }`,
1547
+ "mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
1548
+ "mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
1549
+ "mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);"
1550
+ }, at = {
1551
+ f32: "gl.uniform1fv(location, v);",
1552
+ "vec2<f32>": "gl.uniform2fv(location, v);",
1553
+ "vec3<f32>": "gl.uniform3fv(location, v);",
1554
+ "vec4<f32>": "gl.uniform4fv(location, v);",
1555
+ "mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
1556
+ "mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
1557
+ "mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);",
1558
+ i32: "gl.uniform1iv(location, v);",
1559
+ "vec2<i32>": "gl.uniform2iv(location, v);",
1560
+ "vec3<i32>": "gl.uniform3iv(location, v);",
1561
+ "vec4<i32>": "gl.uniform4iv(location, v);",
1562
+ u32: "gl.uniform1iv(location, v);",
1563
+ "vec2<u32>": "gl.uniform2iv(location, v);",
1564
+ "vec3<u32>": "gl.uniform3iv(location, v);",
1565
+ "vec4<u32>": "gl.uniform4iv(location, v);",
1566
+ bool: "gl.uniform1iv(location, v);",
1567
+ "vec2<bool>": "gl.uniform2iv(location, v);",
1568
+ "vec3<bool>": "gl.uniform3iv(location, v);",
1569
+ "vec4<bool>": "gl.uniform4iv(location, v);"
1570
+ };
1571
+ function ot(t, e) {
1572
+ const r = [`
1573
+ var v = null;
1574
+ var cv = null;
1575
+ var cu = null;
1576
+ var t = 0;
1577
+ var gl = renderer.gl;
1578
+ var name = null;
1579
+ `];
1580
+ for (const s in t.uniforms) {
1581
+ if (!e[s]) {
1582
+ t.uniforms[s] instanceof F ? t.uniforms[s].ubo ? r.push(`
1583
+ renderer.shader.bindUniformBlock(uv.${s}, "${s}");
1584
+ `) : r.push(`
1585
+ renderer.shader.updateUniformGroup(uv.${s});
1586
+ `) : t.uniforms[s] instanceof te && r.push(`
1587
+ renderer.shader.bindBufferResource(uv.${s}, "${s}");
1588
+ `);
1589
+ continue;
1590
+ }
1591
+ const n = t.uniformStructures[s];
1592
+ let i = !1;
1593
+ for (let a = 0; a < N.length; a++) {
1594
+ const o = N[a];
1595
+ if (n.type === o.type && o.test(n)) {
1596
+ r.push(`name = "${s}";`, N[a].uniform), i = !0;
1597
+ break;
1598
+ }
1599
+ }
1600
+ if (!i) {
1601
+ const o = (n.size === 1 ? it : at)[n.type].replace("location", `ud["${s}"].location`);
1602
+ r.push(`
1603
+ cu = ud["${s}"];
1604
+ cv = cu.value;
1605
+ v = uv["${s}"];
1606
+ ${o};`);
1607
+ }
1608
+ }
1609
+ return new Function("ud", "uv", "renderer", "syncData", r.join(`
1610
+ `));
1611
+ }
1612
+ class be {
1613
+ /** @param renderer - The renderer this System works for. */
1614
+ constructor(e) {
1615
+ this._cache = {}, this._uniformGroupSyncHash = {}, this._renderer = e, this.gl = null, this._cache = {};
1616
+ }
1617
+ contextChange(e) {
1618
+ this.gl = e;
1619
+ }
1620
+ /**
1621
+ * Uploads the uniforms values to the currently bound shader.
1622
+ * @param group - the uniforms values that be applied to the current shader
1623
+ * @param program
1624
+ * @param syncData
1625
+ * @param syncData.textureCount
1626
+ */
1627
+ updateUniformGroup(e, r, s) {
1628
+ const n = this._renderer.shader._getProgramData(r);
1629
+ (!e.isStatic || e._dirtyId !== n.uniformDirtyGroups[e.uid]) && (n.uniformDirtyGroups[e.uid] = e._dirtyId, this._getUniformSyncFunction(e, r)(n.uniformData, e.uniforms, this._renderer, s));
1630
+ }
1631
+ /**
1632
+ * Overrideable by the pixi.js/unsafe-eval package to use static syncUniforms instead.
1633
+ * @param group
1634
+ * @param program
1635
+ */
1636
+ _getUniformSyncFunction(e, r) {
1637
+ var s;
1638
+ return ((s = this._uniformGroupSyncHash[e._signature]) == null ? void 0 : s[r._key]) || this._createUniformSyncFunction(e, r);
1639
+ }
1640
+ _createUniformSyncFunction(e, r) {
1641
+ const s = this._uniformGroupSyncHash[e._signature] || (this._uniformGroupSyncHash[e._signature] = {}), n = this._getSignature(e, r._uniformData, "u");
1642
+ return this._cache[n] || (this._cache[n] = this._generateUniformsSync(e, r._uniformData)), s[r._key] = this._cache[n], s[r._key];
1643
+ }
1644
+ _generateUniformsSync(e, r) {
1645
+ return ot(e, r);
1646
+ }
1647
+ /**
1648
+ * Takes a uniform group and data and generates a unique signature for them.
1649
+ * @param group - The uniform group to get signature of
1650
+ * @param group.uniforms
1651
+ * @param uniformData - Uniform information generated by the shader
1652
+ * @param preFix
1653
+ * @returns Unique signature of the uniform group
1654
+ */
1655
+ _getSignature(e, r, s) {
1656
+ const n = e.uniforms, i = [`${s}-`];
1657
+ for (const a in n)
1658
+ i.push(a), r[a] && i.push(r[a].type);
1659
+ return i.join("-");
1660
+ }
1661
+ /** Destroys this System and removes all its textures. */
1662
+ destroy() {
1663
+ this._renderer = null, this._cache = null;
1664
+ }
1665
+ }
1666
+ be.extension = {
1667
+ type: [
1668
+ l.WebGLSystem
1669
+ ],
1670
+ name: "uniformGroup"
1671
+ };
1672
+ function ct(t) {
1673
+ const e = {};
1674
+ return e.normal = [t.ONE, t.ONE_MINUS_SRC_ALPHA], e.add = [t.ONE, t.ONE], e.multiply = [t.DST_COLOR, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.screen = [t.ONE, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.none = [0, 0], e["normal-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e["add-npm"] = [t.SRC_ALPHA, t.ONE, t.ONE, t.ONE], e["screen-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.erase = [t.ZERO, t.ONE_MINUS_SRC_ALPHA], e;
1675
+ }
1676
+ const ut = 0, _t = 1, ft = 2, ht = 3, lt = 4, dt = 5, Se = class C {
1677
+ constructor() {
1678
+ this.gl = null, this.stateId = 0, this.polygonOffset = 0, this.blendMode = "none", this._blendEq = !1, this.map = [], this.map[ut] = this.setBlend, this.map[_t] = this.setOffset, this.map[ft] = this.setCullFace, this.map[ht] = this.setDepthTest, this.map[lt] = this.setFrontFace, this.map[dt] = this.setDepthMask, this.checks = [], this.defaultState = U.for2d();
1679
+ }
1680
+ contextChange(e) {
1681
+ this.gl = e, this.blendModesMap = ct(e), this.reset();
1682
+ }
1683
+ /**
1684
+ * Sets the current state
1685
+ * @param {*} state - The state to set.
1686
+ */
1687
+ set(e) {
1688
+ if (e = e || this.defaultState, this.stateId !== e.data) {
1689
+ let r = this.stateId ^ e.data, s = 0;
1690
+ for (; r; )
1691
+ r & 1 && this.map[s].call(this, !!(e.data & 1 << s)), r = r >> 1, s++;
1692
+ this.stateId = e.data;
1693
+ }
1694
+ for (let r = 0; r < this.checks.length; r++)
1695
+ this.checks[r](this, e);
1696
+ }
1697
+ /**
1698
+ * Sets the state, when previous state is unknown.
1699
+ * @param {*} state - The state to set
1700
+ */
1701
+ forceState(e) {
1702
+ e = e || this.defaultState;
1703
+ for (let r = 0; r < this.map.length; r++)
1704
+ this.map[r].call(this, !!(e.data & 1 << r));
1705
+ for (let r = 0; r < this.checks.length; r++)
1706
+ this.checks[r](this, e);
1707
+ this.stateId = e.data;
1708
+ }
1709
+ /**
1710
+ * Sets whether to enable or disable blending.
1711
+ * @param value - Turn on or off WebGl blending.
1712
+ */
1713
+ setBlend(e) {
1714
+ this._updateCheck(C._checkBlendMode, e), this.gl[e ? "enable" : "disable"](this.gl.BLEND);
1715
+ }
1716
+ /**
1717
+ * Sets whether to enable or disable polygon offset fill.
1718
+ * @param value - Turn on or off webgl polygon offset testing.
1719
+ */
1720
+ setOffset(e) {
1721
+ this._updateCheck(C._checkPolygonOffset, e), this.gl[e ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
1722
+ }
1723
+ /**
1724
+ * Sets whether to enable or disable depth test.
1725
+ * @param value - Turn on or off webgl depth testing.
1726
+ */
1727
+ setDepthTest(e) {
1728
+ this.gl[e ? "enable" : "disable"](this.gl.DEPTH_TEST);
1729
+ }
1730
+ /**
1731
+ * Sets whether to enable or disable depth mask.
1732
+ * @param value - Turn on or off webgl depth mask.
1733
+ */
1734
+ setDepthMask(e) {
1735
+ this.gl.depthMask(e);
1736
+ }
1737
+ /**
1738
+ * Sets whether to enable or disable cull face.
1739
+ * @param {boolean} value - Turn on or off webgl cull face.
1740
+ */
1741
+ setCullFace(e) {
1742
+ this.gl[e ? "enable" : "disable"](this.gl.CULL_FACE);
1743
+ }
1744
+ /**
1745
+ * Sets the gl front face.
1746
+ * @param {boolean} value - true is clockwise and false is counter-clockwise
1747
+ */
1748
+ setFrontFace(e) {
1749
+ this.gl.frontFace(this.gl[e ? "CW" : "CCW"]);
1750
+ }
1751
+ /**
1752
+ * Sets the blend mode.
1753
+ * @param {number} value - The blend mode to set to.
1754
+ */
1755
+ setBlendMode(e) {
1756
+ if (this.blendModesMap[e] || (e = "normal"), e === this.blendMode)
1757
+ return;
1758
+ this.blendMode = e;
1759
+ const r = this.blendModesMap[e], s = this.gl;
1760
+ r.length === 2 ? s.blendFunc(r[0], r[1]) : s.blendFuncSeparate(r[0], r[1], r[2], r[3]), r.length === 6 ? (this._blendEq = !0, s.blendEquationSeparate(r[4], r[5])) : this._blendEq && (this._blendEq = !1, s.blendEquationSeparate(s.FUNC_ADD, s.FUNC_ADD));
1761
+ }
1762
+ /**
1763
+ * Sets the polygon offset.
1764
+ * @param {number} value - the polygon offset
1765
+ * @param {number} scale - the polygon offset scale
1766
+ */
1767
+ setPolygonOffset(e, r) {
1768
+ this.gl.polygonOffset(e, r);
1769
+ }
1770
+ // used
1771
+ /** Resets all the logic and disables the VAOs. */
1772
+ reset() {
1773
+ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, !1), this.forceState(this.defaultState), this._blendEq = !0, this.blendMode = "", this.setBlendMode("normal");
1774
+ }
1775
+ /**
1776
+ * Checks to see which updates should be checked based on which settings have been activated.
1777
+ *
1778
+ * For example, if blend is enabled then we should check the blend modes each time the state is changed
1779
+ * or if polygon fill is activated then we need to check if the polygon offset changes.
1780
+ * The idea is that we only check what we have too.
1781
+ * @param func - the checking function to add or remove
1782
+ * @param value - should the check function be added or removed.
1783
+ */
1784
+ _updateCheck(e, r) {
1785
+ const s = this.checks.indexOf(e);
1786
+ r && s === -1 ? this.checks.push(e) : !r && s !== -1 && this.checks.splice(s, 1);
1787
+ }
1788
+ /**
1789
+ * A private little wrapper function that we call to check the blend mode.
1790
+ * @param system - the System to perform the state check on
1791
+ * @param state - the state that the blendMode will pulled from
1792
+ */
1793
+ static _checkBlendMode(e, r) {
1794
+ e.setBlendMode(r.blendMode);
1795
+ }
1796
+ /**
1797
+ * A private little wrapper function that we call to check the polygon offset.
1798
+ * @param system - the System to perform the state check on
1799
+ * @param state - the state that the blendMode will pulled from
1800
+ */
1801
+ static _checkPolygonOffset(e, r) {
1802
+ e.setPolygonOffset(1, r.polygonOffset);
1803
+ }
1804
+ /**
1805
+ * @ignore
1806
+ */
1807
+ destroy() {
1808
+ this.gl = null, this.checks.length = 0;
1809
+ }
1810
+ };
1811
+ Se.extension = {
1812
+ type: [
1813
+ l.WebGLSystem
1814
+ ],
1815
+ name: "state"
1816
+ };
1817
+ let mt = Se;
1818
+ class Et {
1819
+ constructor(e) {
1820
+ this.target = ie.TEXTURE_2D, this.texture = e, this.width = -1, this.height = -1, this.type = f.UNSIGNED_BYTE, this.internalFormat = y.RGBA, this.format = y.RGBA, this.samplerType = 0;
1821
+ }
1822
+ }
1823
+ const bt = {
1824
+ id: "buffer",
1825
+ upload(t, e, r) {
1826
+ e.width === t.width || e.height === t.height ? r.texSubImage2D(
1827
+ r.TEXTURE_2D,
1828
+ 0,
1829
+ 0,
1830
+ 0,
1831
+ t.width,
1832
+ t.height,
1833
+ e.format,
1834
+ e.type,
1835
+ t.resource
1836
+ ) : r.texImage2D(
1837
+ e.target,
1838
+ 0,
1839
+ e.internalFormat,
1840
+ t.width,
1841
+ t.height,
1842
+ 0,
1843
+ e.format,
1844
+ e.type,
1845
+ t.resource
1846
+ ), e.width = t.width, e.height = t.height;
1847
+ }
1848
+ }, St = {
1849
+ "bc1-rgba-unorm": !0,
1850
+ "bc1-rgba-unorm-srgb": !0,
1851
+ "bc2-rgba-unorm": !0,
1852
+ "bc2-rgba-unorm-srgb": !0,
1853
+ "bc3-rgba-unorm": !0,
1854
+ "bc3-rgba-unorm-srgb": !0,
1855
+ "bc4-r-unorm": !0,
1856
+ "bc4-r-snorm": !0,
1857
+ "bc5-rg-unorm": !0,
1858
+ "bc5-rg-snorm": !0,
1859
+ "bc6h-rgb-ufloat": !0,
1860
+ "bc6h-rgb-float": !0,
1861
+ "bc7-rgba-unorm": !0,
1862
+ "bc7-rgba-unorm-srgb": !0,
1863
+ // ETC2 compressed formats usable if "texture-compression-etc2" is both
1864
+ // supported by the device/user agent and enabled in requestDevice.
1865
+ "etc2-rgb8unorm": !0,
1866
+ "etc2-rgb8unorm-srgb": !0,
1867
+ "etc2-rgb8a1unorm": !0,
1868
+ "etc2-rgb8a1unorm-srgb": !0,
1869
+ "etc2-rgba8unorm": !0,
1870
+ "etc2-rgba8unorm-srgb": !0,
1871
+ "eac-r11unorm": !0,
1872
+ "eac-r11snorm": !0,
1873
+ "eac-rg11unorm": !0,
1874
+ "eac-rg11snorm": !0,
1875
+ // ASTC compressed formats usable if "texture-compression-astc" is both
1876
+ // supported by the device/user agent and enabled in requestDevice.
1877
+ "astc-4x4-unorm": !0,
1878
+ "astc-4x4-unorm-srgb": !0,
1879
+ "astc-5x4-unorm": !0,
1880
+ "astc-5x4-unorm-srgb": !0,
1881
+ "astc-5x5-unorm": !0,
1882
+ "astc-5x5-unorm-srgb": !0,
1883
+ "astc-6x5-unorm": !0,
1884
+ "astc-6x5-unorm-srgb": !0,
1885
+ "astc-6x6-unorm": !0,
1886
+ "astc-6x6-unorm-srgb": !0,
1887
+ "astc-8x5-unorm": !0,
1888
+ "astc-8x5-unorm-srgb": !0,
1889
+ "astc-8x6-unorm": !0,
1890
+ "astc-8x6-unorm-srgb": !0,
1891
+ "astc-8x8-unorm": !0,
1892
+ "astc-8x8-unorm-srgb": !0,
1893
+ "astc-10x5-unorm": !0,
1894
+ "astc-10x5-unorm-srgb": !0,
1895
+ "astc-10x6-unorm": !0,
1896
+ "astc-10x6-unorm-srgb": !0,
1897
+ "astc-10x8-unorm": !0,
1898
+ "astc-10x8-unorm-srgb": !0,
1899
+ "astc-10x10-unorm": !0,
1900
+ "astc-10x10-unorm-srgb": !0,
1901
+ "astc-12x10-unorm": !0,
1902
+ "astc-12x10-unorm-srgb": !0,
1903
+ "astc-12x12-unorm": !0,
1904
+ "astc-12x12-unorm-srgb": !0
1905
+ }, gt = {
1906
+ id: "compressed",
1907
+ upload(t, e, r) {
1908
+ r.pixelStorei(r.UNPACK_ALIGNMENT, 4);
1909
+ let s = t.pixelWidth, n = t.pixelHeight;
1910
+ const i = !!St[t.format];
1911
+ for (let a = 0; a < t.resource.length; a++) {
1912
+ const o = t.resource[a];
1913
+ i ? r.compressedTexImage2D(
1914
+ r.TEXTURE_2D,
1915
+ a,
1916
+ e.internalFormat,
1917
+ s,
1918
+ n,
1919
+ 0,
1920
+ o
1921
+ ) : r.texImage2D(
1922
+ r.TEXTURE_2D,
1923
+ a,
1924
+ e.internalFormat,
1925
+ s,
1926
+ n,
1927
+ 0,
1928
+ e.format,
1929
+ e.type,
1930
+ o
1931
+ ), s = Math.max(s >> 1, 1), n = Math.max(n >> 1, 1);
1932
+ }
1933
+ }
1934
+ }, ge = {
1935
+ id: "image",
1936
+ upload(t, e, r, s) {
1937
+ const n = t.alphaMode === "premultiply-alpha-on-upload";
1938
+ r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, n);
1939
+ const i = e.width, a = e.height, o = t.pixelWidth, c = t.pixelHeight, u = t.resourceWidth, _ = t.resourceHeight;
1940
+ u < o || _ < c ? ((i !== o || a !== c) && r.texImage2D(
1941
+ e.target,
1942
+ 0,
1943
+ e.internalFormat,
1944
+ o,
1945
+ c,
1946
+ 0,
1947
+ e.format,
1948
+ e.type,
1949
+ null
1950
+ ), s === 2 ? r.texSubImage2D(
1951
+ r.TEXTURE_2D,
1952
+ 0,
1953
+ 0,
1954
+ 0,
1955
+ u,
1956
+ _,
1957
+ e.format,
1958
+ e.type,
1959
+ t.resource
1960
+ ) : r.texSubImage2D(
1961
+ r.TEXTURE_2D,
1962
+ 0,
1963
+ 0,
1964
+ 0,
1965
+ e.format,
1966
+ e.type,
1967
+ t.resource
1968
+ )) : i === o || a === c ? r.texSubImage2D(
1969
+ r.TEXTURE_2D,
1970
+ 0,
1971
+ 0,
1972
+ 0,
1973
+ e.format,
1974
+ e.type,
1975
+ t.resource
1976
+ ) : s === 2 ? r.texImage2D(
1977
+ e.target,
1978
+ 0,
1979
+ e.internalFormat,
1980
+ o,
1981
+ c,
1982
+ 0,
1983
+ e.format,
1984
+ e.type,
1985
+ t.resource
1986
+ ) : r.texImage2D(
1987
+ e.target,
1988
+ 0,
1989
+ e.internalFormat,
1990
+ e.format,
1991
+ e.type,
1992
+ t.resource
1993
+ ), e.width = o, e.height = c;
1994
+ }
1995
+ }, pt = {
1996
+ id: "video",
1997
+ upload(t, e, r, s) {
1998
+ if (!t.isValid) {
1999
+ r.texImage2D(
2000
+ e.target,
2001
+ 0,
2002
+ e.internalFormat,
2003
+ 1,
2004
+ 1,
2005
+ 0,
2006
+ e.format,
2007
+ e.type,
2008
+ null
2009
+ );
2010
+ return;
2011
+ }
2012
+ ge.upload(t, e, r, s);
2013
+ }
2014
+ }, j = {
2015
+ linear: 9729,
2016
+ nearest: 9728
2017
+ }, Rt = {
2018
+ linear: {
2019
+ linear: 9987,
2020
+ nearest: 9985
2021
+ },
2022
+ nearest: {
2023
+ linear: 9986,
2024
+ nearest: 9984
2025
+ }
2026
+ }, D = {
2027
+ "clamp-to-edge": 33071,
2028
+ repeat: 10497,
2029
+ "mirror-repeat": 33648
2030
+ }, Tt = {
2031
+ never: 512,
2032
+ less: 513,
2033
+ equal: 514,
2034
+ "less-equal": 515,
2035
+ greater: 516,
2036
+ "not-equal": 517,
2037
+ "greater-equal": 518,
2038
+ always: 519
2039
+ };
2040
+ function K(t, e, r, s, n, i, a, o) {
2041
+ const c = i;
2042
+ if (!o || t.addressModeU !== "repeat" || t.addressModeV !== "repeat" || t.addressModeW !== "repeat") {
2043
+ const u = D[a ? "clamp-to-edge" : t.addressModeU], _ = D[a ? "clamp-to-edge" : t.addressModeV], h = D[a ? "clamp-to-edge" : t.addressModeW];
2044
+ e[n](c, e.TEXTURE_WRAP_S, u), e[n](c, e.TEXTURE_WRAP_T, _), e.TEXTURE_WRAP_R && e[n](c, e.TEXTURE_WRAP_R, h);
2045
+ }
2046
+ if ((!o || t.magFilter !== "linear") && e[n](c, e.TEXTURE_MAG_FILTER, j[t.magFilter]), r) {
2047
+ if (!o || t.mipmapFilter !== "linear") {
2048
+ const u = Rt[t.minFilter][t.mipmapFilter];
2049
+ e[n](c, e.TEXTURE_MIN_FILTER, u);
2050
+ }
2051
+ } else
2052
+ e[n](c, e.TEXTURE_MIN_FILTER, j[t.minFilter]);
2053
+ if (s && t.maxAnisotropy > 1) {
2054
+ const u = Math.min(t.maxAnisotropy, e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
2055
+ e[n](c, s.TEXTURE_MAX_ANISOTROPY_EXT, u);
2056
+ }
2057
+ t.compare && e[n](c, e.TEXTURE_COMPARE_FUNC, Tt[t.compare]);
2058
+ }
2059
+ function vt(t) {
2060
+ return {
2061
+ // 8-bit formats
2062
+ r8unorm: t.RED,
2063
+ r8snorm: t.RED,
2064
+ r8uint: t.RED,
2065
+ r8sint: t.RED,
2066
+ // 16-bit formats
2067
+ r16uint: t.RED,
2068
+ r16sint: t.RED,
2069
+ r16float: t.RED,
2070
+ rg8unorm: t.RG,
2071
+ rg8snorm: t.RG,
2072
+ rg8uint: t.RG,
2073
+ rg8sint: t.RG,
2074
+ // 32-bit formats
2075
+ r32uint: t.RED,
2076
+ r32sint: t.RED,
2077
+ r32float: t.RED,
2078
+ rg16uint: t.RG,
2079
+ rg16sint: t.RG,
2080
+ rg16float: t.RG,
2081
+ rgba8unorm: t.RGBA,
2082
+ "rgba8unorm-srgb": t.RGBA,
2083
+ // Packed 32-bit formats
2084
+ rgba8snorm: t.RGBA,
2085
+ rgba8uint: t.RGBA,
2086
+ rgba8sint: t.RGBA,
2087
+ bgra8unorm: t.RGBA,
2088
+ "bgra8unorm-srgb": t.RGBA,
2089
+ rgb9e5ufloat: t.RGB,
2090
+ rgb10a2unorm: t.RGBA,
2091
+ rg11b10ufloat: t.RGB,
2092
+ // 64-bit formats
2093
+ rg32uint: t.RG,
2094
+ rg32sint: t.RG,
2095
+ rg32float: t.RG,
2096
+ rgba16uint: t.RGBA,
2097
+ rgba16sint: t.RGBA,
2098
+ rgba16float: t.RGBA,
2099
+ // 128-bit formats
2100
+ rgba32uint: t.RGBA,
2101
+ rgba32sint: t.RGBA,
2102
+ rgba32float: t.RGBA,
2103
+ // Depth/stencil formats
2104
+ stencil8: t.STENCIL_INDEX8,
2105
+ depth16unorm: t.DEPTH_COMPONENT,
2106
+ depth24plus: t.DEPTH_COMPONENT,
2107
+ "depth24plus-stencil8": t.DEPTH_STENCIL,
2108
+ depth32float: t.DEPTH_COMPONENT,
2109
+ "depth32float-stencil8": t.DEPTH_STENCIL
2110
+ };
2111
+ }
2112
+ function xt(t, e) {
2113
+ let r = {}, s = t.RGBA;
2114
+ return t instanceof G.get().getWebGLRenderingContext() ? e.srgb && (r = {
2115
+ "rgba8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT,
2116
+ "bgra8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT
2117
+ }) : (r = {
2118
+ "rgba8unorm-srgb": t.SRGB8_ALPHA8,
2119
+ "bgra8unorm-srgb": t.SRGB8_ALPHA8
2120
+ }, s = t.RGBA8), {
2121
+ // 8-bit formats
2122
+ r8unorm: t.R8,
2123
+ r8snorm: t.R8_SNORM,
2124
+ r8uint: t.R8UI,
2125
+ r8sint: t.R8I,
2126
+ // 16-bit formats
2127
+ r16uint: t.R16UI,
2128
+ r16sint: t.R16I,
2129
+ r16float: t.R16F,
2130
+ rg8unorm: t.RG8,
2131
+ rg8snorm: t.RG8_SNORM,
2132
+ rg8uint: t.RG8UI,
2133
+ rg8sint: t.RG8I,
2134
+ // 32-bit formats
2135
+ r32uint: t.R32UI,
2136
+ r32sint: t.R32I,
2137
+ r32float: t.R32F,
2138
+ rg16uint: t.RG16UI,
2139
+ rg16sint: t.RG16I,
2140
+ rg16float: t.RG16F,
2141
+ rgba8unorm: t.RGBA,
2142
+ ...r,
2143
+ // Packed 32-bit formats
2144
+ rgba8snorm: t.RGBA8_SNORM,
2145
+ rgba8uint: t.RGBA8UI,
2146
+ rgba8sint: t.RGBA8I,
2147
+ bgra8unorm: s,
2148
+ rgb9e5ufloat: t.RGB9_E5,
2149
+ rgb10a2unorm: t.RGB10_A2,
2150
+ rg11b10ufloat: t.R11F_G11F_B10F,
2151
+ // 64-bit formats
2152
+ rg32uint: t.RG32UI,
2153
+ rg32sint: t.RG32I,
2154
+ rg32float: t.RG32F,
2155
+ rgba16uint: t.RGBA16UI,
2156
+ rgba16sint: t.RGBA16I,
2157
+ rgba16float: t.RGBA16F,
2158
+ // 128-bit formats
2159
+ rgba32uint: t.RGBA32UI,
2160
+ rgba32sint: t.RGBA32I,
2161
+ rgba32float: t.RGBA32F,
2162
+ // Depth/stencil formats
2163
+ stencil8: t.STENCIL_INDEX8,
2164
+ depth16unorm: t.DEPTH_COMPONENT16,
2165
+ depth24plus: t.DEPTH_COMPONENT24,
2166
+ "depth24plus-stencil8": t.DEPTH24_STENCIL8,
2167
+ depth32float: t.DEPTH_COMPONENT32F,
2168
+ "depth32float-stencil8": t.DEPTH32F_STENCIL8,
2169
+ // Compressed formats
2170
+ ...e.s3tc ? {
2171
+ "bc1-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,
2172
+ "bc2-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,
2173
+ "bc3-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
2174
+ } : {},
2175
+ ...e.s3tc_sRGB ? {
2176
+ "bc1-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
2177
+ "bc2-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
2178
+ "bc3-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
2179
+ } : {},
2180
+ ...e.rgtc ? {
2181
+ "bc4-r-unorm": e.rgtc.COMPRESSED_RED_RGTC1_EXT,
2182
+ "bc4-r-snorm": e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,
2183
+ "bc5-rg-unorm": e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,
2184
+ "bc5-rg-snorm": e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
2185
+ } : {},
2186
+ ...e.bptc ? {
2187
+ "bc6h-rgb-float": e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
2188
+ "bc6h-rgb-ufloat": e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
2189
+ "bc7-rgba-unorm": e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,
2190
+ "bc7-rgba-unorm-srgb": e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT
2191
+ } : {},
2192
+ ...e.etc ? {
2193
+ "etc2-rgb8unorm": e.etc.COMPRESSED_RGB8_ETC2,
2194
+ "etc2-rgb8unorm-srgb": e.etc.COMPRESSED_SRGB8_ETC2,
2195
+ "etc2-rgb8a1unorm": e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
2196
+ "etc2-rgb8a1unorm-srgb": e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
2197
+ "etc2-rgba8unorm": e.etc.COMPRESSED_RGBA8_ETC2_EAC,
2198
+ "etc2-rgba8unorm-srgb": e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
2199
+ "eac-r11unorm": e.etc.COMPRESSED_R11_EAC,
2200
+ // 'eac-r11snorm'
2201
+ "eac-rg11unorm": e.etc.COMPRESSED_SIGNED_RG11_EAC
2202
+ // 'eac-rg11snorm'
2203
+ } : {},
2204
+ ...e.astc ? {
2205
+ "astc-4x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,
2206
+ "astc-4x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
2207
+ "astc-5x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,
2208
+ "astc-5x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
2209
+ "astc-5x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,
2210
+ "astc-5x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
2211
+ "astc-6x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,
2212
+ "astc-6x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
2213
+ "astc-6x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,
2214
+ "astc-6x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
2215
+ "astc-8x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,
2216
+ "astc-8x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
2217
+ "astc-8x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,
2218
+ "astc-8x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
2219
+ "astc-8x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,
2220
+ "astc-8x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
2221
+ "astc-10x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,
2222
+ "astc-10x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
2223
+ "astc-10x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,
2224
+ "astc-10x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
2225
+ "astc-10x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,
2226
+ "astc-10x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
2227
+ "astc-10x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,
2228
+ "astc-10x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
2229
+ "astc-12x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,
2230
+ "astc-12x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
2231
+ "astc-12x12-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,
2232
+ "astc-12x12-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
2233
+ } : {}
2234
+ };
2235
+ }
2236
+ function At(t) {
2237
+ return {
2238
+ // 8-bit formats
2239
+ r8unorm: t.UNSIGNED_BYTE,
2240
+ r8snorm: t.BYTE,
2241
+ r8uint: t.UNSIGNED_BYTE,
2242
+ r8sint: t.BYTE,
2243
+ // 16-bit formats
2244
+ r16uint: t.UNSIGNED_SHORT,
2245
+ r16sint: t.SHORT,
2246
+ r16float: t.HALF_FLOAT,
2247
+ rg8unorm: t.UNSIGNED_BYTE,
2248
+ rg8snorm: t.BYTE,
2249
+ rg8uint: t.UNSIGNED_BYTE,
2250
+ rg8sint: t.BYTE,
2251
+ // 32-bit formats
2252
+ r32uint: t.UNSIGNED_INT,
2253
+ r32sint: t.INT,
2254
+ r32float: t.FLOAT,
2255
+ rg16uint: t.UNSIGNED_SHORT,
2256
+ rg16sint: t.SHORT,
2257
+ rg16float: t.HALF_FLOAT,
2258
+ rgba8unorm: t.UNSIGNED_BYTE,
2259
+ "rgba8unorm-srgb": t.UNSIGNED_BYTE,
2260
+ // Packed 32-bit formats
2261
+ rgba8snorm: t.BYTE,
2262
+ rgba8uint: t.UNSIGNED_BYTE,
2263
+ rgba8sint: t.BYTE,
2264
+ bgra8unorm: t.UNSIGNED_BYTE,
2265
+ "bgra8unorm-srgb": t.UNSIGNED_BYTE,
2266
+ rgb9e5ufloat: t.UNSIGNED_INT_5_9_9_9_REV,
2267
+ rgb10a2unorm: t.UNSIGNED_INT_2_10_10_10_REV,
2268
+ rg11b10ufloat: t.UNSIGNED_INT_10F_11F_11F_REV,
2269
+ // 64-bit formats
2270
+ rg32uint: t.UNSIGNED_INT,
2271
+ rg32sint: t.INT,
2272
+ rg32float: t.FLOAT,
2273
+ rgba16uint: t.UNSIGNED_SHORT,
2274
+ rgba16sint: t.SHORT,
2275
+ rgba16float: t.HALF_FLOAT,
2276
+ // 128-bit formats
2277
+ rgba32uint: t.UNSIGNED_INT,
2278
+ rgba32sint: t.INT,
2279
+ rgba32float: t.FLOAT,
2280
+ // Depth/stencil formats
2281
+ stencil8: t.UNSIGNED_BYTE,
2282
+ depth16unorm: t.UNSIGNED_SHORT,
2283
+ depth24plus: t.UNSIGNED_INT,
2284
+ "depth24plus-stencil8": t.UNSIGNED_INT_24_8,
2285
+ depth32float: t.FLOAT,
2286
+ "depth32float-stencil8": t.FLOAT_32_UNSIGNED_INT_24_8_REV
2287
+ };
2288
+ }
2289
+ const Bt = 4;
2290
+ class pe {
2291
+ constructor(e) {
2292
+ this.managedTextures = [], this._glTextures = /* @__PURE__ */ Object.create(null), this._glSamplers = /* @__PURE__ */ Object.create(null), this._boundTextures = [], this._activeTextureLocation = -1, this._boundSamplers = /* @__PURE__ */ Object.create(null), this._uploads = {
2293
+ image: ge,
2294
+ buffer: bt,
2295
+ video: pt,
2296
+ compressed: gt
2297
+ }, this._useSeparateSamplers = !1, this._renderer = e;
2298
+ }
2299
+ contextChange(e) {
2300
+ this._gl = e, this._mapFormatToInternalFormat || (this._mapFormatToInternalFormat = xt(e, this._renderer.context.extensions), this._mapFormatToType = At(e), this._mapFormatToFormat = vt(e)), this._glTextures = /* @__PURE__ */ Object.create(null), this._glSamplers = /* @__PURE__ */ Object.create(null), this._boundSamplers = /* @__PURE__ */ Object.create(null);
2301
+ for (let r = 0; r < 16; r++)
2302
+ this.bind(S.EMPTY, r);
2303
+ }
2304
+ initSource(e) {
2305
+ this.bind(e);
2306
+ }
2307
+ bind(e, r = 0) {
2308
+ const s = e.source;
2309
+ e ? (this.bindSource(s, r), this._useSeparateSamplers && this._bindSampler(s.style, r)) : (this.bindSource(null, r), this._useSeparateSamplers && this._bindSampler(null, r));
2310
+ }
2311
+ bindSource(e, r = 0) {
2312
+ const s = this._gl;
2313
+ if (e._touched = this._renderer.textureGC.count, this._boundTextures[r] !== e) {
2314
+ this._boundTextures[r] = e, this._activateLocation(r), e = e || S.EMPTY.source;
2315
+ const n = this.getGlSource(e);
2316
+ s.bindTexture(n.target, n.texture);
2317
+ }
2318
+ }
2319
+ _bindSampler(e, r = 0) {
2320
+ const s = this._gl;
2321
+ if (!e) {
2322
+ this._boundSamplers[r] = null, s.bindSampler(r, null);
2323
+ return;
2324
+ }
2325
+ const n = this._getGlSampler(e);
2326
+ this._boundSamplers[r] !== n && (this._boundSamplers[r] = n, s.bindSampler(r, n));
2327
+ }
2328
+ unbind(e) {
2329
+ const r = e.source, s = this._boundTextures, n = this._gl;
2330
+ for (let i = 0; i < s.length; i++)
2331
+ if (s[i] === r) {
2332
+ this._activateLocation(i);
2333
+ const a = this.getGlSource(r);
2334
+ n.bindTexture(a.target, null), s[i] = null;
2335
+ }
2336
+ }
2337
+ _activateLocation(e) {
2338
+ this._activeTextureLocation !== e && (this._activeTextureLocation = e, this._gl.activeTexture(this._gl.TEXTURE0 + e));
2339
+ }
2340
+ _initSource(e) {
2341
+ const r = this._gl, s = new Et(r.createTexture());
2342
+ if (s.type = this._mapFormatToType[e.format], s.internalFormat = this._mapFormatToInternalFormat[e.format], s.format = this._mapFormatToFormat[e.format], e.autoGenerateMipmaps && (this._renderer.context.supports.nonPowOf2mipmaps || e.isPowerOfTwo)) {
2343
+ const n = Math.max(e.width, e.height);
2344
+ e.mipLevelCount = Math.floor(Math.log2(n)) + 1;
2345
+ }
2346
+ return this._glTextures[e.uid] = s, this.managedTextures.includes(e) || (e.on("update", this.onSourceUpdate, this), e.on("resize", this.onSourceUpdate, this), e.on("styleChange", this.onStyleChange, this), e.on("destroy", this.onSourceDestroy, this), e.on("unload", this.onSourceUnload, this), e.on("updateMipmaps", this.onUpdateMipmaps, this), this.managedTextures.push(e)), this.onSourceUpdate(e), this.updateStyle(e, !1), s;
2347
+ }
2348
+ onStyleChange(e) {
2349
+ this.updateStyle(e, !1);
2350
+ }
2351
+ updateStyle(e, r) {
2352
+ const s = this._gl, n = this.getGlSource(e);
2353
+ s.bindTexture(s.TEXTURE_2D, n.texture), this._boundTextures[this._activeTextureLocation] = e, K(
2354
+ e.style,
2355
+ s,
2356
+ e.mipLevelCount > 1,
2357
+ this._renderer.context.extensions.anisotropicFiltering,
2358
+ "texParameteri",
2359
+ s.TEXTURE_2D,
2360
+ // will force a clamp to edge if the texture is not a power of two
2361
+ !this._renderer.context.supports.nonPowOf2wrapping && !e.isPowerOfTwo,
2362
+ r
2363
+ );
2364
+ }
2365
+ onSourceUnload(e) {
2366
+ const r = this._glTextures[e.uid];
2367
+ r && (this.unbind(e), this._glTextures[e.uid] = null, this._gl.deleteTexture(r.texture));
2368
+ }
2369
+ onSourceUpdate(e) {
2370
+ const r = this._gl, s = this.getGlSource(e);
2371
+ r.bindTexture(r.TEXTURE_2D, s.texture), this._boundTextures[this._activeTextureLocation] = e, this._uploads[e.uploadMethodId] ? this._uploads[e.uploadMethodId].upload(e, s, r, this._renderer.context.webGLVersion) : r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e.pixelWidth, e.pixelHeight, 0, r.RGBA, r.UNSIGNED_BYTE, null), e.autoGenerateMipmaps && e.mipLevelCount > 1 && this.onUpdateMipmaps(e, !1);
2372
+ }
2373
+ onUpdateMipmaps(e, r = !0) {
2374
+ r && this.bindSource(e, 0);
2375
+ const s = this.getGlSource(e);
2376
+ this._gl.generateMipmap(s.target);
2377
+ }
2378
+ onSourceDestroy(e) {
2379
+ e.off("destroy", this.onSourceDestroy, this), e.off("update", this.onSourceUpdate, this), e.off("resize", this.onSourceUpdate, this), e.off("unload", this.onSourceUnload, this), e.off("styleChange", this.onStyleChange, this), e.off("updateMipmaps", this.onUpdateMipmaps, this), this.managedTextures.splice(this.managedTextures.indexOf(e), 1), this.onSourceUnload(e);
2380
+ }
2381
+ _initSampler(e) {
2382
+ const r = this._gl, s = this._gl.createSampler();
2383
+ return this._glSamplers[e._resourceId] = s, K(
2384
+ e,
2385
+ r,
2386
+ this._boundTextures[this._activeTextureLocation].mipLevelCount > 1,
2387
+ this._renderer.context.extensions.anisotropicFiltering,
2388
+ "samplerParameteri",
2389
+ s,
2390
+ !1,
2391
+ !0
2392
+ ), this._glSamplers[e._resourceId];
2393
+ }
2394
+ _getGlSampler(e) {
2395
+ return this._glSamplers[e._resourceId] || this._initSampler(e);
2396
+ }
2397
+ getGlSource(e) {
2398
+ return this._glTextures[e.uid] || this._initSource(e);
2399
+ }
2400
+ generateCanvas(e) {
2401
+ const { pixels: r, width: s, height: n } = this.getPixels(e), i = G.get().createCanvas();
2402
+ i.width = s, i.height = n;
2403
+ const a = i.getContext("2d");
2404
+ if (a) {
2405
+ const o = a.createImageData(s, n);
2406
+ o.data.set(r), a.putImageData(o, 0, 0);
2407
+ }
2408
+ return i;
2409
+ }
2410
+ getPixels(e) {
2411
+ const r = e.source.resolution, s = e.frame, n = Math.max(Math.round(s.width * r), 1), i = Math.max(Math.round(s.height * r), 1), a = new Uint8Array(Bt * n * i), o = this._renderer, c = o.renderTarget.getRenderTarget(e), u = o.renderTarget.getGpuRenderTarget(c), _ = o.gl;
2412
+ return _.bindFramebuffer(_.FRAMEBUFFER, u.resolveTargetFramebuffer), _.readPixels(
2413
+ Math.round(s.x * r),
2414
+ Math.round(s.y * r),
2415
+ n,
2416
+ i,
2417
+ _.RGBA,
2418
+ _.UNSIGNED_BYTE,
2419
+ a
2420
+ ), { pixels: new Uint8ClampedArray(a.buffer), width: n, height: i };
2421
+ }
2422
+ destroy() {
2423
+ this.managedTextures.slice().forEach((e) => this.onSourceDestroy(e)), this.managedTextures = null, this._renderer = null;
2424
+ }
2425
+ }
2426
+ pe.extension = {
2427
+ type: [
2428
+ l.WebGLSystem
2429
+ ],
2430
+ name: "texture"
2431
+ };
2432
+ class Re {
2433
+ init() {
2434
+ const e = new F({
2435
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
2436
+ uTransformMatrix: { value: new Y(), type: "mat3x3<f32>" },
2437
+ uRound: { value: 0, type: "f32" }
2438
+ }), r = $(), s = O({
2439
+ name: "graphics",
2440
+ bits: [
2441
+ q,
2442
+ Z(r),
2443
+ J,
2444
+ P
2445
+ ]
2446
+ });
2447
+ this.shader = new x({
2448
+ glProgram: s,
2449
+ resources: {
2450
+ localUniforms: e,
2451
+ batchSamplers: ee(r)
2452
+ }
2453
+ });
2454
+ }
2455
+ execute(e, r) {
2456
+ const s = r.context, n = s.customShader || this.shader, i = e.renderer, a = i.graphicsContext, {
2457
+ geometry: o,
2458
+ instructions: c
2459
+ } = a.getContextRenderData(s);
2460
+ n.groups[0] = i.globalUniforms.bindGroup, i.state.set(e.state), i.shader.bind(n), i.geometry.bind(o, n.glProgram);
2461
+ const u = c.instructions;
2462
+ for (let _ = 0; _ < c.instructionSize; _++) {
2463
+ const h = u[_];
2464
+ if (h.size) {
2465
+ for (let d = 0; d < h.textures.textures.length; d++)
2466
+ i.texture.bind(h.textures.textures[d], d);
2467
+ i.geometry.draw("triangle-list", h.size, h.start);
2468
+ }
2469
+ }
2470
+ }
2471
+ destroy() {
2472
+ this.shader.destroy(!0), this.shader = null;
2473
+ }
2474
+ }
2475
+ Re.extension = {
2476
+ type: [
2477
+ l.WebGLPipesAdaptor
2478
+ ],
2479
+ name: "graphics"
2480
+ };
2481
+ class Te {
2482
+ init() {
2483
+ const e = O({
2484
+ name: "mesh",
2485
+ bits: [
2486
+ J,
2487
+ Fe,
2488
+ P
2489
+ ]
2490
+ });
2491
+ this._shader = new x({
2492
+ glProgram: e,
2493
+ resources: {
2494
+ uTexture: S.EMPTY.source,
2495
+ textureUniforms: {
2496
+ uTextureMatrix: { type: "mat3x3<f32>", value: new Y() }
2497
+ }
2498
+ }
2499
+ });
2500
+ }
2501
+ execute(e, r) {
2502
+ const s = e.renderer;
2503
+ let n = r._shader;
2504
+ if (n) {
2505
+ if (!n.glProgram) {
2506
+ b("Mesh shader has no glProgram", r.shader);
2507
+ return;
2508
+ }
2509
+ } else {
2510
+ n = this._shader;
2511
+ const i = r.texture, a = i.source;
2512
+ n.resources.uTexture = a, n.resources.uSampler = a.style, n.resources.textureUniforms.uniforms.uTextureMatrix = i.textureMatrix.mapCoord;
2513
+ }
2514
+ n.groups[100] = s.globalUniforms.bindGroup, n.groups[101] = e.localUniformsBindGroup, s.encoder.draw({
2515
+ geometry: r._geometry,
2516
+ shader: n,
2517
+ state: r.state
2518
+ });
2519
+ }
2520
+ destroy() {
2521
+ this._shader.destroy(!0), this._shader = null;
2522
+ }
2523
+ }
2524
+ Te.extension = {
2525
+ type: [
2526
+ l.WebGLPipesAdaptor
2527
+ ],
2528
+ name: "mesh"
2529
+ };
2530
+ const Nt = [
2531
+ ...Me,
2532
+ he,
2533
+ We,
2534
+ we,
2535
+ se,
2536
+ pe,
2537
+ le,
2538
+ ae,
2539
+ be,
2540
+ Ee,
2541
+ ue,
2542
+ mt,
2543
+ _e,
2544
+ ce
2545
+ ], It = [...Le], Dt = [re, Te, Re], ve = [], xe = [], Ae = [];
2546
+ v.handleByNamedList(l.WebGLSystem, ve);
2547
+ v.handleByNamedList(l.WebGLPipes, xe);
2548
+ v.handleByNamedList(l.WebGLPipesAdaptor, Ae);
2549
+ v.add(...Nt, ...It, ...Dt);
2550
+ class Ot extends Ne {
2551
+ constructor() {
2552
+ const e = {
2553
+ name: "webgl",
2554
+ type: De.WEBGL,
2555
+ systems: ve,
2556
+ renderPipes: xe,
2557
+ renderPipeAdaptors: Ae
2558
+ };
2559
+ super(e);
2560
+ }
2561
+ }
2562
+ export {
2563
+ Ot as WebGLRenderer
2564
+ };