@designcombo/video 0.0.0

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