@micjanic/recursive-grid 1.0.2

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