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