holostaff-widget 3.0.2 → 3.0.3

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