holostaff-widget 3.0.2 → 3.0.4

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-DtJMGjQ-.js} +50 -50
  2. package/dist/{CanvasRenderer-BL1L0Zug.js.map → CanvasRenderer-DtJMGjQ-.js.map} +1 -1
  3. package/dist/Filter-BZ0p_cLc.js +670 -0
  4. package/dist/Filter-BZ0p_cLc.js.map +1 -0
  5. package/dist/GpuStencilModesToPixi-BhdxrQzF.js +222 -0
  6. package/dist/GpuStencilModesToPixi-BhdxrQzF.js.map +1 -0
  7. package/dist/{RenderTargetSystem-CahYKOD4.js → RenderTargetSystem-Cbru8Ci0.js} +327 -391
  8. package/dist/RenderTargetSystem-Cbru8Ci0.js.map +1 -0
  9. package/dist/WebGLRenderer--845IaSu.js +2237 -0
  10. package/dist/WebGLRenderer--845IaSu.js.map +1 -0
  11. package/dist/{WebGPURenderer-SF1OSYpo.js → WebGPURenderer-DBDzoMAw.js} +281 -374
  12. package/dist/WebGPURenderer-DBDzoMAw.js.map +1 -0
  13. package/dist/{browserAll-B97ymwYI.js → browserAll-CIOBMh08.js} +3 -3
  14. package/dist/{browserAll-B97ymwYI.js.map → browserAll-CIOBMh08.js.map} +1 -1
  15. package/dist/{getTextureBatchBindGroup-BPB_9pp9.js → getTextureBatchBindGroup-DCKtteRk.js} +3 -3
  16. package/dist/{getTextureBatchBindGroup-BPB_9pp9.js.map → getTextureBatchBindGroup-DCKtteRk.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-BbQvHSpa.js} +11198 -9102
  21. package/dist/index-BbQvHSpa.js.map +1 -0
  22. package/dist/{webworkerAll-DYG_wBG4.js → webworkerAll-EB5JX-2r.js} +12 -12
  23. package/dist/{webworkerAll-DYG_wBG4.js.map → webworkerAll-EB5JX-2r.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
@@ -1,2939 +0,0 @@
1
- import { D as R, c as d, w as p, T as S, g as z, R as V, f as B, d as y, M as q, A as ye, e as A } from "./index-qJyFW51-.js";
2
- import { G as F, e as Ce, S as g, R as Ne, h as Z, i as De, j as Q, k as Ie, l as Ge, b as Ue, d as Fe } from "./RenderTargetSystem-CahYKOD4.js";
3
- import { e as Pe, G as Oe, c as Me, b as Le, U as we, B as J, d as C, f as ee, g as He } from "./BufferResource-6mO-PO_c.js";
4
- import { S as P, b as N, g as te, G as Ve, d as O, e as Xe, U as M, R as ke } from "./Geometry-B-K9I6MO.js";
5
- function We() {
6
- const { userAgent: t } = R.get().getNavigator();
7
- return /^((?!chrome|android).)*safari/i.test(t);
8
- }
9
- class re {
10
- constructor() {
11
- this._tempState = P.for2d(), this._didUploadHash = {};
12
- }
13
- init(e) {
14
- e.renderer.runners.contextChange.add(this);
15
- }
16
- contextChange() {
17
- this._didUploadHash = {};
18
- }
19
- start(e, r, n) {
20
- const s = e.renderer, i = this._didUploadHash[n.uid];
21
- s.shader.bind(n, i), i || (this._didUploadHash[n.uid] = !0), s.shader.updateUniformGroup(s.globalUniforms.uniformGroup), s.geometry.bind(r, n.glProgram);
22
- }
23
- execute(e, r) {
24
- const n = e.renderer;
25
- this._tempState.blendMode = r.blendMode, n.state.set(this._tempState);
26
- const s = r.textures.textures;
27
- for (let i = 0; i < r.textures.count; i++)
28
- n.texture.bind(s[i], i);
29
- n.geometry.draw(r.topology, r.size, r.start);
30
- }
31
- }
32
- re.extension = {
33
- type: [
34
- d.WebGLPipesAdaptor
35
- ],
36
- name: "batch"
37
- };
38
- var v = /* @__PURE__ */ ((t) => (t[t.ELEMENT_ARRAY_BUFFER = 34963] = "ELEMENT_ARRAY_BUFFER", t[t.ARRAY_BUFFER = 34962] = "ARRAY_BUFFER", t[t.UNIFORM_BUFFER = 35345] = "UNIFORM_BUFFER", t))(v || {});
39
- class je {
40
- constructor(e, r) {
41
- this._lastBindBaseLocation = -1, this._lastBindCallId = -1, this.buffer = e || null, this.updateID = -1, this.byteLength = -1, this.type = r;
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 ne {
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 F({
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: r } = this, n = this.getGlBuffer(e);
76
- r.bindBuffer(n.type, n.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, r) {
86
- const { _gl: n } = this;
87
- this._boundBufferBases[r] !== e && (this._boundBufferBases[r] = e, e._lastBindBaseLocation = r, n.bindBufferBase(n.UNIFORM_BUFFER, r, 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 r = this.getLastBindBaseLocation(e);
94
- if (r >= this._minBaseLocation)
95
- return e._lastBindCallId = this._bindCallId, r;
96
- let n = 0, s = this._nextBindBaseIndex;
97
- for (; n < 2; ) {
98
- s >= this._maxBindings && (s = this._minBaseLocation, n++);
99
- const i = this._boundBufferBases[s];
100
- if (i && i._lastBindCallId === this._bindCallId) {
101
- s++;
102
- continue;
103
- }
104
- break;
105
- }
106
- return r = s, this._nextBindBaseIndex = s + 1, n >= 2 ? -1 : (e._lastBindCallId = this._bindCallId, this._boundBufferBases[r] = null, r);
107
- }
108
- getLastBindBaseLocation(e) {
109
- const r = e._lastBindBaseLocation;
110
- return this._boundBufferBases[r] === e ? r : -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, r, n, s) {
121
- const { _gl: i } = this;
122
- n || (n = 0), r || (r = 0), this._boundBufferBases[r] = null, i.bindBufferRange(i.UNIFORM_BUFFER, r || 0, e.buffer, n * 256, s || 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: r } = this, n = this.getGlBuffer(e);
130
- if (e._updateID === n.updateID)
131
- return n;
132
- n.updateID = e._updateID, r.bindBuffer(n.type, n.buffer);
133
- const s = e.data, i = e.descriptor.usage & N.STATIC ? r.STATIC_DRAW : r.DYNAMIC_DRAW;
134
- return s ? n.byteLength >= s.byteLength ? r.bufferSubData(n.type, 0, s, 0, e._updateSize / s.BYTES_PER_ELEMENT) : (n.byteLength = s.byteLength, r.bufferData(n.type, s, i)) : (n.byteLength = e.descriptor.size, r.bufferData(n.type, n.byteLength, i)), n;
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, r = !1) {
144
- const n = e._gpuData[this._renderer.uid];
145
- n && (r || this._gl.deleteBuffer(n.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: r } = this;
154
- let n = v.ARRAY_BUFFER;
155
- e.descriptor.usage & N.INDEX ? n = v.ELEMENT_ARRAY_BUFFER : e.descriptor.usage & N.UNIFORM && (n = v.UNIFORM_BUFFER);
156
- const s = new je(r.createBuffer(), n);
157
- return e._gpuData[this._renderer.uid] = s, this._managedBuffers.add(e), s;
158
- }
159
- resetState() {
160
- this._boundBufferBases = /* @__PURE__ */ Object.create(null);
161
- }
162
- }
163
- ne.extension = {
164
- type: [
165
- d.WebGLSystem
166
- ],
167
- name: "buffer"
168
- };
169
- const L = class se {
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 = { ...se.defaultOptions, ...e };
205
- let r = this.multiView = e.multiView;
206
- if (e.context && r && (p("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."), r = !1), r ? this.canvas = R.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 n = this._renderer.background.alpha < 1, s = e.premultipliedAlpha ?? !0, i = e.antialias && !this._renderer.backBuffer.useBackBuffer;
210
- this.createContext(e.preferWebGLVersion, {
211
- alpha: n,
212
- premultipliedAlpha: s,
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: r } = this;
226
- (r.width < e.width || r.height < e.height) && (r.width = Math.max(e.width, e.width), r.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 R.get().getWebGLRenderingContext() ? 1 : 2, this.getExtensions(), this.validateContext(e), this._renderer.runners.contextChange.emit(e);
235
- const r = this._renderer.view.canvas;
236
- r.addEventListener("webglcontextlost", this.handleContextLost, !1), r.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, r) {
246
- let n;
247
- const s = this.canvas;
248
- if (e === 2 && (n = s.getContext("webgl2", r)), !n && (n = s.getContext("webgl", r), !n))
249
- throw new Error("This browser does not support WebGL. Try using the canvas renderer");
250
- this.gl = n, this.initFromContext(this.gl);
251
- }
252
- /** Auto-populate the {@link GlContextSystem.extensions extensions}. */
253
- getExtensions() {
254
- const { gl: e } = this, r = {
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
- ...r,
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
- ...r,
287
- colorBufferFloat: e.getExtension("EXT_color_buffer_float")
288
- };
289
- const n = e.getExtension("WEBGL_provoking_vertex");
290
- n && n.provokingVertexWEBGL(n.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 r;
300
- this.gl.isContextLost() && ((r = this.extensions.loseContext) == null || r.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 r;
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), (r = this.extensions.loseContext) == null || r.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 r = e.getContextAttributes();
329
- r && !r.stencil && p("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
330
- const n = this.supports, s = this.webGLVersion === 2, i = this.extensions;
331
- n.uint32Indices = s || !!i.uint32ElementIndex, n.uniformBufferObject = s, n.vertexArrayObject = s || !!i.vertexArrayObject, n.srgbTextures = s || !!i.srgb, n.nonPowOf2wrapping = s, n.nonPowOf2mipmaps = s, n.msaa = s, n.uint32Indices || p("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
332
- }
333
- };
334
- L.extension = {
335
- type: [
336
- d.WebGLSystem
337
- ],
338
- name: "context"
339
- };
340
- L.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 $e = L;
373
- var G = /* @__PURE__ */ ((t) => (t[t.RGBA = 6408] = "RGBA", t[t.RGB = 6407] = "RGB", t[t.RG = 33319] = "RG", t[t.RED = 6403] = "RED", t[t.RGBA_INTEGER = 36249] = "RGBA_INTEGER", t[t.RGB_INTEGER = 36248] = "RGB_INTEGER", t[t.RG_INTEGER = 33320] = "RG_INTEGER", t[t.RED_INTEGER = 36244] = "RED_INTEGER", t[t.ALPHA = 6406] = "ALPHA", t[t.LUMINANCE = 6409] = "LUMINANCE", t[t.LUMINANCE_ALPHA = 6410] = "LUMINANCE_ALPHA", t[t.DEPTH_COMPONENT = 6402] = "DEPTH_COMPONENT", t[t.DEPTH_STENCIL = 34041] = "DEPTH_STENCIL", t))(G || {}), w = /* @__PURE__ */ ((t) => (t[t.TEXTURE_2D = 3553] = "TEXTURE_2D", t[t.TEXTURE_CUBE_MAP = 34067] = "TEXTURE_CUBE_MAP", t[t.TEXTURE_2D_ARRAY = 35866] = "TEXTURE_2D_ARRAY", t[t.TEXTURE_CUBE_MAP_POSITIVE_X = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X", t[t.TEXTURE_CUBE_MAP_NEGATIVE_X = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X", t[t.TEXTURE_CUBE_MAP_POSITIVE_Y = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y", t[t.TEXTURE_CUBE_MAP_POSITIVE_Z = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z", t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z", t))(w || {}), l = /* @__PURE__ */ ((t) => (t[t.UNSIGNED_BYTE = 5121] = "UNSIGNED_BYTE", t[t.UNSIGNED_SHORT = 5123] = "UNSIGNED_SHORT", t[t.UNSIGNED_SHORT_5_6_5 = 33635] = "UNSIGNED_SHORT_5_6_5", t[t.UNSIGNED_SHORT_4_4_4_4 = 32819] = "UNSIGNED_SHORT_4_4_4_4", t[t.UNSIGNED_SHORT_5_5_5_1 = 32820] = "UNSIGNED_SHORT_5_5_5_1", t[t.UNSIGNED_INT = 5125] = "UNSIGNED_INT", t[t.UNSIGNED_INT_10F_11F_11F_REV = 35899] = "UNSIGNED_INT_10F_11F_11F_REV", t[t.UNSIGNED_INT_2_10_10_10_REV = 33640] = "UNSIGNED_INT_2_10_10_10_REV", t[t.UNSIGNED_INT_24_8 = 34042] = "UNSIGNED_INT_24_8", t[t.UNSIGNED_INT_5_9_9_9_REV = 35902] = "UNSIGNED_INT_5_9_9_9_REV", t[t.BYTE = 5120] = "BYTE", t[t.SHORT = 5122] = "SHORT", t[t.INT = 5124] = "INT", t[t.FLOAT = 5126] = "FLOAT", t[t.FLOAT_32_UNSIGNED_INT_24_8_REV = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV", t[t.HALF_FLOAT = 36193] = "HALF_FLOAT", t))(l || {});
374
- const X = {
375
- uint8x2: l.UNSIGNED_BYTE,
376
- uint8x4: l.UNSIGNED_BYTE,
377
- sint8x2: l.BYTE,
378
- sint8x4: l.BYTE,
379
- unorm8x2: l.UNSIGNED_BYTE,
380
- unorm8x4: l.UNSIGNED_BYTE,
381
- snorm8x2: l.BYTE,
382
- snorm8x4: l.BYTE,
383
- uint16x2: l.UNSIGNED_SHORT,
384
- uint16x4: l.UNSIGNED_SHORT,
385
- sint16x2: l.SHORT,
386
- sint16x4: l.SHORT,
387
- unorm16x2: l.UNSIGNED_SHORT,
388
- unorm16x4: l.UNSIGNED_SHORT,
389
- snorm16x2: l.SHORT,
390
- snorm16x4: l.SHORT,
391
- float16x2: l.HALF_FLOAT,
392
- float16x4: l.HALF_FLOAT,
393
- float32: l.FLOAT,
394
- float32x2: l.FLOAT,
395
- float32x3: l.FLOAT,
396
- float32x4: l.FLOAT,
397
- uint32: l.UNSIGNED_INT,
398
- uint32x2: l.UNSIGNED_INT,
399
- uint32x3: l.UNSIGNED_INT,
400
- uint32x4: l.UNSIGNED_INT,
401
- sint32: l.INT,
402
- sint32x2: l.INT,
403
- sint32x3: l.INT,
404
- sint32x4: l.INT
405
- };
406
- function Ke(t) {
407
- return X[t] ?? X.float32;
408
- }
409
- const Ye = {
410
- "point-list": 0,
411
- "line-list": 1,
412
- "line-strip": 3,
413
- "triangle-list": 4,
414
- "triangle-strip": 5
415
- };
416
- class ze {
417
- constructor() {
418
- this.vaoCache = /* @__PURE__ */ Object.create(null);
419
- }
420
- destroy() {
421
- this.vaoCache = /* @__PURE__ */ Object.create(null);
422
- }
423
- }
424
- class ie {
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 F({
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 r = this._renderer.context.extensions.vertexArrayObject;
441
- r && (e.createVertexArray = () => r.createVertexArrayOES(), e.bindVertexArray = (s) => r.bindVertexArrayOES(s), e.deleteVertexArray = (s) => r.deleteVertexArrayOES(s));
442
- const n = this._renderer.context.extensions.vertexAttribDivisorANGLE;
443
- n && (e.drawArraysInstanced = (s, i, a, o) => {
444
- n.drawArraysInstancedANGLE(s, i, a, o);
445
- }, e.drawElementsInstanced = (s, i, a, o, u) => {
446
- n.drawElementsInstancedANGLE(s, i, a, o, u);
447
- }, e.vertexAttribDivisor = (s, i) => n.vertexAttribDivisorANGLE(s, 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, r) {
455
- const n = this.gl;
456
- this._activeGeometry = e;
457
- const s = this.getVao(e, r);
458
- this._activeVao !== s && (this._activeVao = s, n.bindVertexArray(s)), 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, r = this._renderer.buffer;
467
- for (let n = 0; n < e.buffers.length; n++) {
468
- const s = e.buffers[n];
469
- r.updateBuffer(s);
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, r) {
479
- const n = e.attributes, s = r._attributeData;
480
- for (const i in s)
481
- if (!n[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, r) {
491
- const n = e.attributes, s = r._attributeData, i = ["g", e.uid];
492
- for (const a in n)
493
- s[a] && i.push(a, s[a].location);
494
- return i.join("-");
495
- }
496
- getVao(e, r) {
497
- var n;
498
- return ((n = e._gpuData[this._renderer.uid]) == null ? void 0 : n.vaoCache[r._key]) || this.initGeometryVao(e, r);
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, r, n = !0) {
509
- const s = this._renderer.gl, i = this._renderer.buffer;
510
- this._renderer.shader._getProgramData(r), this.checkCompatibility(e, r);
511
- const a = this.getSignature(e, r);
512
- let o = e._gpuData[this._renderer.uid];
513
- o || (o = new ze(), e._gpuData[this._renderer.uid] = o, this._managedGeometries.add(e));
514
- const u = o.vaoCache;
515
- let c = u[a];
516
- if (c)
517
- return u[r._key] = c, c;
518
- Pe(e, r._attributeData);
519
- const _ = e.buffers;
520
- c = s.createVertexArray(), s.bindVertexArray(c);
521
- for (let f = 0; f < _.length; f++) {
522
- const h = _[f];
523
- i.bind(h);
524
- }
525
- return this.activateVao(e, r), u[r._key] = c, u[a] = c, s.bindVertexArray(null), c;
526
- }
527
- onGeometryUnload(e, r = !1) {
528
- const n = e._gpuData[this._renderer.uid];
529
- if (!n) return;
530
- const s = n.vaoCache;
531
- if (!r)
532
- for (const i in s)
533
- this._activeVao !== s[i] && this.resetState(), this.gl.deleteVertexArray(s[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, r) {
548
- var o;
549
- const n = this._renderer.gl, s = this._renderer.buffer, i = e.attributes;
550
- e.indexBuffer && s.bind(e.indexBuffer);
551
- let a = null;
552
- for (const u in i) {
553
- const c = i[u], _ = c.buffer, f = s.getGlBuffer(_), h = r._attributeData[u];
554
- if (h) {
555
- a !== f && (s.bind(_), a = f);
556
- const m = h.location;
557
- n.enableVertexAttribArray(m);
558
- const b = te(c.format), E = Ke(c.format);
559
- if (((o = h.format) == null ? void 0 : o.substring(1, 4)) === "int" ? n.vertexAttribIPointer(
560
- m,
561
- b.size,
562
- E,
563
- c.stride,
564
- c.offset
565
- ) : n.vertexAttribPointer(
566
- m,
567
- b.size,
568
- E,
569
- b.normalised,
570
- c.stride,
571
- c.offset
572
- ), c.instance)
573
- if (this.hasInstance) {
574
- const Be = c.divisor ?? 1;
575
- n.vertexAttribDivisor(m, Be);
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, r, n, s) {
593
- const { gl: i } = this._renderer, a = this._activeGeometry, o = Ye[e || a.topology];
594
- if (s ?? (s = a.instanceCount), a.indexBuffer) {
595
- const u = a.indexBuffer.data.BYTES_PER_ELEMENT, c = u === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
596
- s !== 1 ? i.drawElementsInstanced(o, r || a.indexBuffer.data.length, c, (n || 0) * u, s) : i.drawElements(o, r || a.indexBuffer.data.length, c, (n || 0) * u);
597
- } else s !== 1 ? i.drawArraysInstanced(o, n || 0, r || a.getSize(), s) : i.drawArrays(o, n || 0, r || 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
- ie.extension = {
609
- type: [
610
- d.WebGLSystem
611
- ],
612
- name: "geometry"
613
- };
614
- const qe = new Xe({
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
- }), H = class ae {
629
- constructor(e) {
630
- this.useBackBuffer = !1, this._useBackBufferThisRender = !1, this._renderer = e;
631
- }
632
- init(e = {}) {
633
- const { useBackBuffer: r, antialias: n } = { ...ae.defaultOptions, ...e };
634
- this.useBackBuffer = r, this._antialias = n, this._renderer.context.supports.msaa || (p("antialiasing, is not supported on when using the back buffer"), this._antialias = !1), this._state = P.for2d();
635
- const s = new Ve({
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 O({
660
- glProgram: s,
661
- resources: {
662
- uTexture: S.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 r = this._renderer.renderTarget.getRenderTarget(e.target);
673
- if (this._useBackBufferThisRender = this.useBackBuffer && !!r.isRoot, this._useBackBufferThisRender) {
674
- const n = this._renderer.renderTarget.getRenderTarget(e.target);
675
- this._targetTexture = n.colorTexture, e.target = this._getBackBufferTexture(n.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: qe,
685
- shader: this._bigTriangleShader,
686
- state: this._state
687
- }));
688
- }
689
- _getBackBufferTexture(e) {
690
- return this._backBufferTexture = this._backBufferTexture || new S({
691
- source: new z({
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
- H.extension = {
709
- type: [
710
- d.WebGLSystem
711
- ],
712
- name: "backBuffer",
713
- priority: 1
714
- };
715
- H.defaultOptions = {
716
- /** if true will use the back buffer where required */
717
- useBackBuffer: !1
718
- };
719
- let Ze = H;
720
- class oe {
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
- oe.extension = {
734
- type: [
735
- d.WebGLSystem
736
- ],
737
- name: "colorMask"
738
- };
739
- class ce {
740
- constructor(e) {
741
- this.commandFinished = Promise.resolve(), this._renderer = e;
742
- }
743
- setGeometry(e, r) {
744
- this._renderer.geometry.bind(e, r.glProgram);
745
- }
746
- finishRenderPass() {
747
- }
748
- draw(e) {
749
- const r = this._renderer, { geometry: n, shader: s, state: i, skipSync: a, topology: o, size: u, start: c, instanceCount: _ } = e;
750
- r.shader.bind(s, a), r.geometry.bind(n, r.shader._activeProgram), i && r.state.set(i), r.geometry.draw(o, u, c, _ ?? n.instanceCount);
751
- }
752
- destroy() {
753
- this._renderer = null;
754
- }
755
- }
756
- ce.extension = {
757
- type: [
758
- d.WebGLSystem
759
- ],
760
- name: "encoder"
761
- };
762
- class ue {
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 = Ce(this.maxTextures, e);
769
- const r = this._renderer.context.webGLVersion === 2;
770
- this.maxUniformBindings = r ? e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS) : 0;
771
- }
772
- destroy() {
773
- }
774
- }
775
- ue.extension = {
776
- type: [
777
- d.WebGLSystem
778
- ],
779
- name: "limits"
780
- };
781
- class Qe {
782
- constructor() {
783
- this.width = -1, this.height = -1, this.msaa = !1, this._attachedMipLevel = 0, this._attachedLayer = 0, this.msaaRenderBuffer = [];
784
- }
785
- }
786
- class _e {
787
- constructor(e) {
788
- this._stencilCache = {
789
- enabled: !1,
790
- stencilReference: 0,
791
- stencilMode: g.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 r = this._renderTargetStencilState[e.uid];
819
- r || (r = this._renderTargetStencilState[e.uid] = {
820
- stencilMode: g.DISABLED,
821
- stencilReference: 0
822
- }), this.setStencilMode(r.stencilMode, r.stencilReference);
823
- }
824
- resetState() {
825
- this._stencilCache.enabled = !1, this._stencilCache.stencilMode = g.NONE, this._stencilCache.stencilReference = 0;
826
- }
827
- setStencilMode(e, r) {
828
- const n = this._renderTargetStencilState[this._activeRenderTarget.uid], s = this._gl, i = Oe[e], a = this._stencilCache;
829
- if (n.stencilMode = e, n.stencilReference = r, e === g.DISABLED) {
830
- this._stencilCache.enabled && (this._stencilCache.enabled = !1, s.disable(s.STENCIL_TEST));
831
- return;
832
- }
833
- this._stencilCache.enabled || (this._stencilCache.enabled = !0, s.enable(s.STENCIL_TEST)), (e !== a.stencilMode || a.stencilReference !== r) && (a.stencilMode = e, a.stencilReference = r, s.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare], r, 255), s.stencilOp(s.KEEP, s.KEEP, this._stencilOpsMapping[i.stencilBack.passOp]));
834
- }
835
- }
836
- _e.extension = {
837
- type: [
838
- d.WebGLSystem
839
- ],
840
- name: "stencil"
841
- };
842
- const fe = {
843
- f32: 4,
844
- i32: 4,
845
- "vec2<f32>": 8,
846
- "vec3<f32>": 12,
847
- "vec4<f32>": 16,
848
- "vec2<i32>": 8,
849
- "vec3<i32>": 12,
850
- "vec4<i32>": 16,
851
- "mat2x2<f32>": 32,
852
- "mat3x3<f32>": 48,
853
- "mat4x4<f32>": 64
854
- // TODO - not essential for now but support these in the future
855
- // int: 4,
856
- // ivec2: 8,
857
- // ivec3: 12,
858
- // ivec4: 16,
859
- // uint: 4,
860
- // uvec2: 8,
861
- // uvec3: 12,
862
- // uvec4: 16,
863
- // bool: 4,
864
- // bvec2: 8,
865
- // bvec3: 12,
866
- // bvec4: 16,
867
- // mat2: 16 * 2,
868
- // mat3: 16 * 3,
869
- // mat4: 16 * 4,
870
- };
871
- function Je(t) {
872
- const e = t.map((i) => ({
873
- data: i,
874
- offset: 0,
875
- size: 0
876
- })), r = 16;
877
- let n = 0, s = 0;
878
- for (let i = 0; i < e.length; i++) {
879
- const a = e[i];
880
- if (n = fe[a.data.type], !n)
881
- throw new Error(`Unknown type ${a.data.type}`);
882
- a.data.size > 1 && (n = Math.max(n, r) * a.data.size);
883
- const o = n === 12 ? 16 : n;
884
- a.size = n;
885
- const u = s % r;
886
- u > 0 && r - u < o ? s += (r - u) % 16 : s += (n - u % n) % n, a.offset = s, s += n;
887
- }
888
- return s = Math.ceil(s / 16) * 16, { uboElements: e, size: s };
889
- }
890
- function et(t, e) {
891
- const r = Math.max(fe[t.data.type] / 16, 1), n = t.data.value.length / t.data.size, s = (4 - n % 4) % 4, i = t.data.type.indexOf("i32") >= 0 ? "dataInt32" : "data";
892
- return `
893
- v = uv.${t.data.name};
894
- offset += ${e};
895
-
896
- arrayOffset = offset;
897
-
898
- t = 0;
899
-
900
- for(var i=0; i < ${t.data.size * r}; i++)
901
- {
902
- for(var j = 0; j < ${n}; j++)
903
- {
904
- ${i}[arrayOffset++] = v[t++];
905
- }
906
- ${s !== 0 ? `arrayOffset += ${s};` : ""}
907
- }
908
- `;
909
- }
910
- function tt(t) {
911
- return Me(
912
- t,
913
- "uboStd40",
914
- et,
915
- Le
916
- );
917
- }
918
- class he extends we {
919
- constructor() {
920
- super({
921
- createUboElements: Je,
922
- generateUboSync: tt
923
- });
924
- }
925
- }
926
- he.extension = {
927
- type: [d.WebGLSystem],
928
- name: "ubo"
929
- };
930
- class rt {
931
- constructor() {
932
- this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new V();
933
- }
934
- init(e, r) {
935
- this._renderer = e, this._renderTargetSystem = r, e.runners.contextChange.add(this);
936
- }
937
- contextChange() {
938
- this._clearColorCache = [0, 0, 0, 0], this._viewPortCache = new V();
939
- const e = this._renderer.gl;
940
- this._drawBuffersCache = [];
941
- for (let r = 1; r <= 16; r++)
942
- this._drawBuffersCache[r] = Array.from({ length: r }, (n, s) => e.COLOR_ATTACHMENT0 + s);
943
- }
944
- copyToTexture(e, r, n, s, i) {
945
- const a = this._renderTargetSystem, o = this._renderer, u = a.getGpuRenderTarget(e), c = o.gl;
946
- return this.finishRenderPass(e), c.bindFramebuffer(c.FRAMEBUFFER, u.resolveTargetFramebuffer), o.texture.bind(r, 0), c.copyTexSubImage2D(
947
- c.TEXTURE_2D,
948
- 0,
949
- i.x,
950
- i.y,
951
- n.x,
952
- n.y,
953
- s.width,
954
- s.height
955
- ), r;
956
- }
957
- startRenderPass(e, r = !0, n, s, i = 0, a = 0) {
958
- const o = this._renderTargetSystem, u = e.colorTexture, c = o.getGpuRenderTarget(e);
959
- if (a !== 0 && this._renderer.context.webGLVersion < 2)
960
- throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");
961
- if (i > 0) {
962
- if (c.msaa)
963
- throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");
964
- if (this._renderer.context.webGLVersion < 2)
965
- throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.");
966
- }
967
- let _ = s.y;
968
- e.isRoot && (_ = u.pixelHeight - s.height - s.y), e.colorTextures.forEach((m) => {
969
- this._renderer.texture.unbind(m);
970
- });
971
- const f = this._renderer.gl;
972
- f.bindFramebuffer(f.FRAMEBUFFER, c.framebuffer), !e.isRoot && (c._attachedMipLevel !== i || c._attachedLayer !== a) && (e.colorTextures.forEach((m, b) => {
973
- const E = this._renderer.texture.getGlSource(m);
974
- if (E.target === f.TEXTURE_2D) {
975
- if (a !== 0)
976
- throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");
977
- f.framebufferTexture2D(
978
- f.FRAMEBUFFER,
979
- f.COLOR_ATTACHMENT0 + b,
980
- f.TEXTURE_2D,
981
- E.texture,
982
- i
983
- );
984
- } else if (E.target === f.TEXTURE_2D_ARRAY) {
985
- if (this._renderer.context.webGLVersion < 2)
986
- throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");
987
- f.framebufferTextureLayer(
988
- f.FRAMEBUFFER,
989
- f.COLOR_ATTACHMENT0 + b,
990
- E.texture,
991
- i,
992
- a
993
- );
994
- } else if (E.target === f.TEXTURE_CUBE_MAP) {
995
- if (a < 0 || a > 5)
996
- throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");
997
- f.framebufferTexture2D(
998
- f.FRAMEBUFFER,
999
- f.COLOR_ATTACHMENT0 + b,
1000
- f.TEXTURE_CUBE_MAP_POSITIVE_X + a,
1001
- E.texture,
1002
- i
1003
- );
1004
- } else
1005
- throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.");
1006
- }), c._attachedMipLevel = i, c._attachedLayer = a), e.colorTextures.length > 1 && this._setDrawBuffers(e, f);
1007
- const h = this._viewPortCache;
1008
- (h.x !== s.x || h.y !== _ || h.width !== s.width || h.height !== s.height) && (h.x = s.x, h.y = _, h.width = s.width, h.height = s.height, f.viewport(
1009
- s.x,
1010
- _,
1011
- s.width,
1012
- s.height
1013
- )), !c.depthStencilRenderBuffer && (e.stencil || e.depth) && this._initStencil(c), this.clear(e, r, n);
1014
- }
1015
- finishRenderPass(e) {
1016
- const n = this._renderTargetSystem.getGpuRenderTarget(e);
1017
- if (!n.msaa) return;
1018
- const s = this._renderer.gl;
1019
- s.bindFramebuffer(s.FRAMEBUFFER, n.resolveTargetFramebuffer), s.bindFramebuffer(s.READ_FRAMEBUFFER, n.framebuffer), s.blitFramebuffer(
1020
- 0,
1021
- 0,
1022
- n.width,
1023
- n.height,
1024
- 0,
1025
- 0,
1026
- n.width,
1027
- n.height,
1028
- s.COLOR_BUFFER_BIT,
1029
- s.NEAREST
1030
- ), s.bindFramebuffer(s.FRAMEBUFFER, n.framebuffer);
1031
- }
1032
- initGpuRenderTarget(e) {
1033
- const n = this._renderer.gl, s = new Qe();
1034
- return s._attachedMipLevel = 0, s._attachedLayer = 0, e.colorTexture instanceof B ? (this._renderer.context.ensureCanvasSize(e.colorTexture.resource), s.framebuffer = null, s) : (this._initColor(e, s), n.bindFramebuffer(n.FRAMEBUFFER, null), s);
1035
- }
1036
- destroyGpuRenderTarget(e) {
1037
- const r = this._renderer.gl;
1038
- e.framebuffer && (r.deleteFramebuffer(e.framebuffer), e.framebuffer = null), e.resolveTargetFramebuffer && (r.deleteFramebuffer(e.resolveTargetFramebuffer), e.resolveTargetFramebuffer = null), e.depthStencilRenderBuffer && (r.deleteRenderbuffer(e.depthStencilRenderBuffer), e.depthStencilRenderBuffer = null), e.msaaRenderBuffer.forEach((n) => {
1039
- r.deleteRenderbuffer(n);
1040
- }), e.msaaRenderBuffer = null;
1041
- }
1042
- clear(e, r, n, s, i = 0, a = 0) {
1043
- if (!r) return;
1044
- if (a !== 0)
1045
- throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");
1046
- const o = this._renderTargetSystem;
1047
- typeof r == "boolean" && (r = r ? y.ALL : y.NONE);
1048
- const u = this._renderer.gl;
1049
- if (r & y.COLOR) {
1050
- n ?? (n = o.defaultClearColor);
1051
- const c = this._clearColorCache, _ = n;
1052
- (c[0] !== _[0] || c[1] !== _[1] || c[2] !== _[2] || c[3] !== _[3]) && (c[0] = _[0], c[1] = _[1], c[2] = _[2], c[3] = _[3], u.clearColor(_[0], _[1], _[2], _[3]));
1053
- }
1054
- u.clear(r);
1055
- }
1056
- resizeGpuRenderTarget(e) {
1057
- if (e.isRoot) return;
1058
- const n = this._renderTargetSystem.getGpuRenderTarget(e);
1059
- this._resizeColor(e, n), (e.stencil || e.depth) && this._resizeStencil(n);
1060
- }
1061
- _initColor(e, r) {
1062
- const n = this._renderer, s = n.gl, i = s.createFramebuffer();
1063
- if (r.resolveTargetFramebuffer = i, s.bindFramebuffer(s.FRAMEBUFFER, i), r.width = e.colorTexture.source.pixelWidth, r.height = e.colorTexture.source.pixelHeight, e.colorTextures.forEach((o, u) => {
1064
- const c = o.source;
1065
- c.antialias && (n.context.supports.msaa ? r.msaa = !0 : p("[RenderTexture] Antialiasing on textures is not supported in WebGL1")), n.texture.bindSource(c, 0);
1066
- const _ = n.texture.getGlSource(c), f = _.texture;
1067
- if (_.target === s.TEXTURE_2D)
1068
- s.framebufferTexture2D(
1069
- s.FRAMEBUFFER,
1070
- s.COLOR_ATTACHMENT0 + u,
1071
- s.TEXTURE_2D,
1072
- f,
1073
- 0
1074
- );
1075
- else if (_.target === s.TEXTURE_2D_ARRAY) {
1076
- if (n.context.webGLVersion < 2)
1077
- throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");
1078
- s.framebufferTextureLayer(
1079
- s.FRAMEBUFFER,
1080
- s.COLOR_ATTACHMENT0 + u,
1081
- f,
1082
- 0,
1083
- 0
1084
- );
1085
- } else if (_.target === s.TEXTURE_CUBE_MAP)
1086
- s.framebufferTexture2D(
1087
- s.FRAMEBUFFER,
1088
- s.COLOR_ATTACHMENT0 + u,
1089
- s.TEXTURE_CUBE_MAP_POSITIVE_X,
1090
- f,
1091
- 0
1092
- );
1093
- else
1094
- throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.");
1095
- }), r.msaa) {
1096
- const o = s.createFramebuffer();
1097
- r.framebuffer = o, s.bindFramebuffer(s.FRAMEBUFFER, o), e.colorTextures.forEach((u, c) => {
1098
- const _ = s.createRenderbuffer();
1099
- r.msaaRenderBuffer[c] = _;
1100
- });
1101
- } else
1102
- r.framebuffer = i;
1103
- this._resizeColor(e, r);
1104
- }
1105
- _resizeColor(e, r) {
1106
- const n = e.colorTexture.source;
1107
- if (r.width = n.pixelWidth, r.height = n.pixelHeight, r._attachedMipLevel = 0, r._attachedLayer = 0, e.colorTextures.forEach((s, i) => {
1108
- i !== 0 && s.source.resize(n.width, n.height, n._resolution);
1109
- }), r.msaa) {
1110
- const s = this._renderer, i = s.gl, a = r.framebuffer;
1111
- i.bindFramebuffer(i.FRAMEBUFFER, a), e.colorTextures.forEach((o, u) => {
1112
- const c = o.source;
1113
- s.texture.bindSource(c, 0);
1114
- const f = s.texture.getGlSource(c).internalFormat, h = r.msaaRenderBuffer[u];
1115
- i.bindRenderbuffer(
1116
- i.RENDERBUFFER,
1117
- h
1118
- ), i.renderbufferStorageMultisample(
1119
- i.RENDERBUFFER,
1120
- 4,
1121
- f,
1122
- c.pixelWidth,
1123
- c.pixelHeight
1124
- ), i.framebufferRenderbuffer(
1125
- i.FRAMEBUFFER,
1126
- i.COLOR_ATTACHMENT0 + u,
1127
- i.RENDERBUFFER,
1128
- h
1129
- );
1130
- });
1131
- }
1132
- }
1133
- _initStencil(e) {
1134
- if (e.framebuffer === null) return;
1135
- const r = this._renderer.gl, n = r.createRenderbuffer();
1136
- e.depthStencilRenderBuffer = n, r.bindRenderbuffer(
1137
- r.RENDERBUFFER,
1138
- n
1139
- ), r.framebufferRenderbuffer(
1140
- r.FRAMEBUFFER,
1141
- r.DEPTH_STENCIL_ATTACHMENT,
1142
- r.RENDERBUFFER,
1143
- n
1144
- ), this._resizeStencil(e);
1145
- }
1146
- _resizeStencil(e) {
1147
- const r = this._renderer.gl;
1148
- r.bindRenderbuffer(
1149
- r.RENDERBUFFER,
1150
- e.depthStencilRenderBuffer
1151
- ), e.msaa ? r.renderbufferStorageMultisample(
1152
- r.RENDERBUFFER,
1153
- 4,
1154
- r.DEPTH24_STENCIL8,
1155
- e.width,
1156
- e.height
1157
- ) : r.renderbufferStorage(
1158
- r.RENDERBUFFER,
1159
- this._renderer.context.webGLVersion === 2 ? r.DEPTH24_STENCIL8 : r.DEPTH_STENCIL,
1160
- e.width,
1161
- e.height
1162
- );
1163
- }
1164
- prerender(e) {
1165
- const r = e.colorTexture.resource;
1166
- this._renderer.context.multiView && B.test(r) && this._renderer.context.ensureCanvasSize(r);
1167
- }
1168
- postrender(e) {
1169
- if (this._renderer.context.multiView && B.test(e.colorTexture.resource)) {
1170
- const r = this._renderer.context.canvas, n = e.colorTexture;
1171
- n.context2D.drawImage(
1172
- r,
1173
- 0,
1174
- n.pixelHeight - r.height
1175
- );
1176
- }
1177
- }
1178
- _setDrawBuffers(e, r) {
1179
- const n = e.colorTextures.length, s = this._drawBuffersCache[n];
1180
- if (this._renderer.context.webGLVersion === 1) {
1181
- const i = this._renderer.context.extensions.drawBuffers;
1182
- i ? i.drawBuffersWEBGL(s) : p("[RenderTexture] This WebGL1 context does not support rendering to multiple targets");
1183
- } else
1184
- r.drawBuffers(s);
1185
- }
1186
- }
1187
- class le extends Ne {
1188
- constructor(e) {
1189
- super(e), this.adaptor = new rt(), this.adaptor.init(e, this);
1190
- }
1191
- }
1192
- le.extension = {
1193
- type: [d.WebGLSystem],
1194
- name: "renderTarget"
1195
- };
1196
- function nt(t, e) {
1197
- const r = [], n = [`
1198
- var g = s.groups;
1199
- var sS = r.shader;
1200
- var p = s.glProgram;
1201
- var ugS = r.uniformGroup;
1202
- var resources;
1203
- `];
1204
- let s = !1, i = 0;
1205
- const a = e._getProgramData(t.glProgram);
1206
- for (const u in t.groups) {
1207
- const c = t.groups[u];
1208
- r.push(`
1209
- resources = g[${u}].resources;
1210
- `);
1211
- for (const _ in c.resources) {
1212
- const f = c.resources[_];
1213
- if (f instanceof M)
1214
- if (f.ubo) {
1215
- const h = t._uniformBindMap[u][Number(_)];
1216
- r.push(`
1217
- sS.bindUniformBlock(
1218
- resources[${_}],
1219
- '${h}',
1220
- ${t.glProgram._uniformBlockData[h].index}
1221
- );
1222
- `);
1223
- } else
1224
- r.push(`
1225
- ugS.updateUniformGroup(resources[${_}], p, sD);
1226
- `);
1227
- else if (f instanceof J) {
1228
- const h = t._uniformBindMap[u][Number(_)];
1229
- r.push(`
1230
- sS.bindUniformBlock(
1231
- resources[${_}],
1232
- '${h}',
1233
- ${t.glProgram._uniformBlockData[h].index}
1234
- );
1235
- `);
1236
- } else if (f instanceof z) {
1237
- const h = t._uniformBindMap[u][_], m = a.uniformData[h];
1238
- m && (s || (s = !0, n.push(`
1239
- var tS = r.texture;
1240
- `)), e._gl.uniform1i(m.location, i), r.push(`
1241
- tS.bind(resources[${_}], ${i});
1242
- `), i++);
1243
- }
1244
- }
1245
- }
1246
- const o = [...n, ...r].join(`
1247
- `);
1248
- return new Function("r", "s", "sD", o);
1249
- }
1250
- class st {
1251
- /**
1252
- * Makes a new Pixi program.
1253
- * @param program - webgl program
1254
- * @param uniformData - uniforms
1255
- */
1256
- constructor(e, r) {
1257
- this.program = e, this.uniformData = r, this.uniformGroups = {}, this.uniformDirtyGroups = {}, this.uniformBlockBindings = {};
1258
- }
1259
- /** Destroys this program. */
1260
- destroy() {
1261
- this.uniformData = null, this.uniformGroups = null, this.uniformDirtyGroups = null, this.uniformBlockBindings = null, this.program = null;
1262
- }
1263
- }
1264
- function k(t, e, r) {
1265
- const n = t.createShader(e);
1266
- return t.shaderSource(n, r), t.compileShader(n), n;
1267
- }
1268
- function D(t) {
1269
- const e = new Array(t);
1270
- for (let r = 0; r < e.length; r++)
1271
- e[r] = !1;
1272
- return e;
1273
- }
1274
- function de(t, e) {
1275
- switch (t) {
1276
- case "float":
1277
- return 0;
1278
- case "vec2":
1279
- return new Float32Array(2 * e);
1280
- case "vec3":
1281
- return new Float32Array(3 * e);
1282
- case "vec4":
1283
- return new Float32Array(4 * e);
1284
- case "int":
1285
- case "uint":
1286
- case "sampler2D":
1287
- case "sampler2DArray":
1288
- return 0;
1289
- case "ivec2":
1290
- return new Int32Array(2 * e);
1291
- case "ivec3":
1292
- return new Int32Array(3 * e);
1293
- case "ivec4":
1294
- return new Int32Array(4 * e);
1295
- case "uvec2":
1296
- return new Uint32Array(2 * e);
1297
- case "uvec3":
1298
- return new Uint32Array(3 * e);
1299
- case "uvec4":
1300
- return new Uint32Array(4 * e);
1301
- case "bool":
1302
- return !1;
1303
- case "bvec2":
1304
- return D(2 * e);
1305
- case "bvec3":
1306
- return D(3 * e);
1307
- case "bvec4":
1308
- return D(4 * e);
1309
- case "mat2":
1310
- return new Float32Array([
1311
- 1,
1312
- 0,
1313
- 0,
1314
- 1
1315
- ]);
1316
- case "mat3":
1317
- return new Float32Array([
1318
- 1,
1319
- 0,
1320
- 0,
1321
- 0,
1322
- 1,
1323
- 0,
1324
- 0,
1325
- 0,
1326
- 1
1327
- ]);
1328
- case "mat4":
1329
- return new Float32Array([
1330
- 1,
1331
- 0,
1332
- 0,
1333
- 0,
1334
- 0,
1335
- 1,
1336
- 0,
1337
- 0,
1338
- 0,
1339
- 0,
1340
- 1,
1341
- 0,
1342
- 0,
1343
- 0,
1344
- 0,
1345
- 1
1346
- ]);
1347
- }
1348
- return null;
1349
- }
1350
- let T = null;
1351
- const W = {
1352
- FLOAT: "float",
1353
- FLOAT_VEC2: "vec2",
1354
- FLOAT_VEC3: "vec3",
1355
- FLOAT_VEC4: "vec4",
1356
- INT: "int",
1357
- INT_VEC2: "ivec2",
1358
- INT_VEC3: "ivec3",
1359
- INT_VEC4: "ivec4",
1360
- UNSIGNED_INT: "uint",
1361
- UNSIGNED_INT_VEC2: "uvec2",
1362
- UNSIGNED_INT_VEC3: "uvec3",
1363
- UNSIGNED_INT_VEC4: "uvec4",
1364
- BOOL: "bool",
1365
- BOOL_VEC2: "bvec2",
1366
- BOOL_VEC3: "bvec3",
1367
- BOOL_VEC4: "bvec4",
1368
- FLOAT_MAT2: "mat2",
1369
- FLOAT_MAT3: "mat3",
1370
- FLOAT_MAT4: "mat4",
1371
- SAMPLER_2D: "sampler2D",
1372
- INT_SAMPLER_2D: "sampler2D",
1373
- UNSIGNED_INT_SAMPLER_2D: "sampler2D",
1374
- SAMPLER_CUBE: "samplerCube",
1375
- INT_SAMPLER_CUBE: "samplerCube",
1376
- UNSIGNED_INT_SAMPLER_CUBE: "samplerCube",
1377
- SAMPLER_2D_ARRAY: "sampler2DArray",
1378
- INT_SAMPLER_2D_ARRAY: "sampler2DArray",
1379
- UNSIGNED_INT_SAMPLER_2D_ARRAY: "sampler2DArray"
1380
- }, it = {
1381
- float: "float32",
1382
- vec2: "float32x2",
1383
- vec3: "float32x3",
1384
- vec4: "float32x4",
1385
- int: "sint32",
1386
- ivec2: "sint32x2",
1387
- ivec3: "sint32x3",
1388
- ivec4: "sint32x4",
1389
- uint: "uint32",
1390
- uvec2: "uint32x2",
1391
- uvec3: "uint32x3",
1392
- uvec4: "uint32x4",
1393
- bool: "uint32",
1394
- bvec2: "uint32x2",
1395
- bvec3: "uint32x3",
1396
- bvec4: "uint32x4"
1397
- };
1398
- function me(t, e) {
1399
- if (!T) {
1400
- const r = Object.keys(W);
1401
- T = {};
1402
- for (let n = 0; n < r.length; ++n) {
1403
- const s = r[n];
1404
- T[t[s]] = W[s];
1405
- }
1406
- }
1407
- return T[e];
1408
- }
1409
- function at(t, e) {
1410
- const r = me(t, e);
1411
- return it[r] || "float32";
1412
- }
1413
- function ot(t, e, r = !1) {
1414
- const n = {}, s = e.getProgramParameter(t, e.ACTIVE_ATTRIBUTES);
1415
- for (let a = 0; a < s; a++) {
1416
- const o = e.getActiveAttrib(t, a);
1417
- if (o.name.startsWith("gl_"))
1418
- continue;
1419
- const u = at(e, o.type);
1420
- n[o.name] = {
1421
- location: 0,
1422
- // set further down..
1423
- format: u,
1424
- stride: te(u).stride,
1425
- offset: 0,
1426
- instance: !1,
1427
- start: 0
1428
- };
1429
- }
1430
- const i = Object.keys(n);
1431
- if (r) {
1432
- i.sort((a, o) => a > o ? 1 : -1);
1433
- for (let a = 0; a < i.length; a++)
1434
- n[i[a]].location = a, e.bindAttribLocation(t, a, i[a]);
1435
- e.linkProgram(t);
1436
- } else
1437
- for (let a = 0; a < i.length; a++)
1438
- n[i[a]].location = e.getAttribLocation(t, i[a]);
1439
- return n;
1440
- }
1441
- function ct(t, e) {
1442
- if (!e.ACTIVE_UNIFORM_BLOCKS) return {};
1443
- const r = {}, n = e.getProgramParameter(t, e.ACTIVE_UNIFORM_BLOCKS);
1444
- for (let s = 0; s < n; s++) {
1445
- const i = e.getActiveUniformBlockName(t, s), a = e.getUniformBlockIndex(t, i), o = e.getActiveUniformBlockParameter(t, s, e.UNIFORM_BLOCK_DATA_SIZE);
1446
- r[i] = {
1447
- name: i,
1448
- index: a,
1449
- size: o
1450
- };
1451
- }
1452
- return r;
1453
- }
1454
- function ut(t, e) {
1455
- const r = {}, n = e.getProgramParameter(t, e.ACTIVE_UNIFORMS);
1456
- for (let s = 0; s < n; s++) {
1457
- const i = e.getActiveUniform(t, s), a = i.name.replace(/\[.*?\]$/, ""), o = !!i.name.match(/\[.*?\]$/), u = me(e, i.type);
1458
- r[a] = {
1459
- name: a,
1460
- index: s,
1461
- type: u,
1462
- size: i.size,
1463
- isArray: o,
1464
- value: de(u, i.size)
1465
- };
1466
- }
1467
- return r;
1468
- }
1469
- function j(t, e) {
1470
- const r = t.getShaderSource(e).split(`
1471
- `).map((c, _) => `${_}: ${c}`), n = t.getShaderInfoLog(e), s = n.split(`
1472
- `), i = {}, a = s.map((c) => parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/, "$1"))).filter((c) => c && !i[c] ? (i[c] = !0, !0) : !1), o = [""];
1473
- a.forEach((c) => {
1474
- r[c - 1] = `%c${r[c - 1]}%c`, o.push("background: #FF0000; color:#FFFFFF; font-size: 10px", "font-size: 10px");
1475
- });
1476
- const u = r.join(`
1477
- `);
1478
- o[0] = u, console.error(n), console.groupCollapsed("click to view full shader code"), console.warn(...o), console.groupEnd();
1479
- }
1480
- function _t(t, e, r, n) {
1481
- t.getProgramParameter(e, t.LINK_STATUS) || (t.getShaderParameter(r, t.COMPILE_STATUS) || j(t, r), t.getShaderParameter(n, t.COMPILE_STATUS) || j(t, n), console.error("PixiJS Error: Could not initialize shader."), t.getProgramInfoLog(e) !== "" && console.warn("PixiJS Warning: gl.getProgramInfoLog()", t.getProgramInfoLog(e)));
1482
- }
1483
- function ft(t, e) {
1484
- const r = k(t, t.VERTEX_SHADER, e.vertex), n = k(t, t.FRAGMENT_SHADER, e.fragment), s = t.createProgram();
1485
- t.attachShader(s, r), t.attachShader(s, n);
1486
- const i = e.transformFeedbackVaryings;
1487
- i && (typeof t.transformFeedbackVaryings != "function" ? p("TransformFeedback is not supported but TransformFeedbackVaryings are given.") : t.transformFeedbackVaryings(
1488
- s,
1489
- i.names,
1490
- i.bufferMode === "separate" ? t.SEPARATE_ATTRIBS : t.INTERLEAVED_ATTRIBS
1491
- )), t.linkProgram(s), t.getProgramParameter(s, t.LINK_STATUS) || _t(t, s, r, n), e._attributeData = ot(
1492
- s,
1493
- t,
1494
- !/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)
1495
- ), e._uniformData = ut(s, t), e._uniformBlockData = ct(s, t), t.deleteShader(r), t.deleteShader(n);
1496
- const a = {};
1497
- for (const u in e._uniformData) {
1498
- const c = e._uniformData[u];
1499
- a[u] = {
1500
- location: t.getUniformLocation(s, u),
1501
- value: de(c.type, c.size)
1502
- };
1503
- }
1504
- return new st(s, a);
1505
- }
1506
- const x = {
1507
- textureCount: 0,
1508
- blockIndex: 0
1509
- };
1510
- class Ee {
1511
- constructor(e) {
1512
- this._activeProgram = null, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._renderer = e;
1513
- }
1514
- contextChange(e) {
1515
- this._gl = e, this._programDataHash = /* @__PURE__ */ Object.create(null), this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null), this._activeProgram = null;
1516
- }
1517
- /**
1518
- * Changes the current shader to the one given in parameter.
1519
- * @param shader - the new shader
1520
- * @param skipSync - false if the shader should automatically sync its uniforms.
1521
- * @returns the glProgram that belongs to the shader.
1522
- */
1523
- bind(e, r) {
1524
- if (this._setProgram(e.glProgram), r) return;
1525
- x.textureCount = 0, x.blockIndex = 0;
1526
- let n = this._shaderSyncFunctions[e.glProgram._key];
1527
- n || (n = this._shaderSyncFunctions[e.glProgram._key] = this._generateShaderSync(e, this)), this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings), n(this._renderer, e, x);
1528
- }
1529
- /**
1530
- * Updates the uniform group.
1531
- * @param uniformGroup - the uniform group to update
1532
- */
1533
- updateUniformGroup(e) {
1534
- this._renderer.uniformGroup.updateUniformGroup(e, this._activeProgram, x);
1535
- }
1536
- /**
1537
- * Binds a uniform block to the shader.
1538
- * @param uniformGroup - the uniform group to bind
1539
- * @param name - the name of the uniform block
1540
- * @param index - the index of the uniform block
1541
- */
1542
- bindUniformBlock(e, r, n = 0) {
1543
- const s = this._renderer.buffer, i = this._getProgramData(this._activeProgram), a = e._bufferResource;
1544
- a || this._renderer.ubo.updateUniformGroup(e);
1545
- const o = e.buffer, u = s.updateBuffer(o), c = s.freeLocationForBufferBase(u);
1546
- if (a) {
1547
- const { offset: f, size: h } = e;
1548
- f === 0 && h === o.data.byteLength ? s.bindBufferBase(u, c) : s.bindBufferRange(u, c, f);
1549
- } else s.getLastBindBaseLocation(u) !== c && s.bindBufferBase(u, c);
1550
- const _ = this._activeProgram._uniformBlockData[r].index;
1551
- i.uniformBlockBindings[n] !== c && (i.uniformBlockBindings[n] = c, this._renderer.gl.uniformBlockBinding(i.program, _, c));
1552
- }
1553
- _setProgram(e) {
1554
- if (this._activeProgram === e) return;
1555
- this._activeProgram = e;
1556
- const r = this._getProgramData(e);
1557
- this._gl.useProgram(r.program);
1558
- }
1559
- /**
1560
- * @param program - the program to get the data for
1561
- * @internal
1562
- */
1563
- _getProgramData(e) {
1564
- return this._programDataHash[e._key] || this._createProgramData(e);
1565
- }
1566
- _createProgramData(e) {
1567
- const r = e._key;
1568
- return this._programDataHash[r] = ft(this._gl, e), this._programDataHash[r];
1569
- }
1570
- destroy() {
1571
- for (const e of Object.keys(this._programDataHash))
1572
- this._programDataHash[e].destroy();
1573
- this._programDataHash = null, this._shaderSyncFunctions = null, this._activeProgram = null, this._renderer = null, this._gl = null;
1574
- }
1575
- /**
1576
- * Creates a function that can be executed that will sync the shader as efficiently as possible.
1577
- * Overridden by the unsafe eval package if you don't want eval used in your project.
1578
- * @param shader - the shader to generate the sync function for
1579
- * @param shaderSystem - the shader system to use
1580
- * @returns - the generated sync function
1581
- * @ignore
1582
- */
1583
- _generateShaderSync(e, r) {
1584
- return nt(e, r);
1585
- }
1586
- resetState() {
1587
- this._activeProgram = null;
1588
- }
1589
- }
1590
- Ee.extension = {
1591
- type: [
1592
- d.WebGLSystem
1593
- ],
1594
- name: "shader"
1595
- };
1596
- const ht = {
1597
- f32: `if (cv !== v) {
1598
- cu.value = v;
1599
- gl.uniform1f(location, v);
1600
- }`,
1601
- "vec2<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1602
- cv[0] = v[0];
1603
- cv[1] = v[1];
1604
- gl.uniform2f(location, v[0], v[1]);
1605
- }`,
1606
- "vec3<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1607
- cv[0] = v[0];
1608
- cv[1] = v[1];
1609
- cv[2] = v[2];
1610
- gl.uniform3f(location, v[0], v[1], v[2]);
1611
- }`,
1612
- "vec4<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1613
- cv[0] = v[0];
1614
- cv[1] = v[1];
1615
- cv[2] = v[2];
1616
- cv[3] = v[3];
1617
- gl.uniform4f(location, v[0], v[1], v[2], v[3]);
1618
- }`,
1619
- i32: `if (cv !== v) {
1620
- cu.value = v;
1621
- gl.uniform1i(location, v);
1622
- }`,
1623
- "vec2<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1624
- cv[0] = v[0];
1625
- cv[1] = v[1];
1626
- gl.uniform2i(location, v[0], v[1]);
1627
- }`,
1628
- "vec3<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1629
- cv[0] = v[0];
1630
- cv[1] = v[1];
1631
- cv[2] = v[2];
1632
- gl.uniform3i(location, v[0], v[1], v[2]);
1633
- }`,
1634
- "vec4<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1635
- cv[0] = v[0];
1636
- cv[1] = v[1];
1637
- cv[2] = v[2];
1638
- cv[3] = v[3];
1639
- gl.uniform4i(location, v[0], v[1], v[2], v[3]);
1640
- }`,
1641
- u32: `if (cv !== v) {
1642
- cu.value = v;
1643
- gl.uniform1ui(location, v);
1644
- }`,
1645
- "vec2<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1646
- cv[0] = v[0];
1647
- cv[1] = v[1];
1648
- gl.uniform2ui(location, v[0], v[1]);
1649
- }`,
1650
- "vec3<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1651
- cv[0] = v[0];
1652
- cv[1] = v[1];
1653
- cv[2] = v[2];
1654
- gl.uniform3ui(location, v[0], v[1], v[2]);
1655
- }`,
1656
- "vec4<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1657
- cv[0] = v[0];
1658
- cv[1] = v[1];
1659
- cv[2] = v[2];
1660
- cv[3] = v[3];
1661
- gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
1662
- }`,
1663
- bool: `if (cv !== v) {
1664
- cu.value = v;
1665
- gl.uniform1i(location, v);
1666
- }`,
1667
- "vec2<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
1668
- cv[0] = v[0];
1669
- cv[1] = v[1];
1670
- gl.uniform2i(location, v[0], v[1]);
1671
- }`,
1672
- "vec3<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
1673
- cv[0] = v[0];
1674
- cv[1] = v[1];
1675
- cv[2] = v[2];
1676
- gl.uniform3i(location, v[0], v[1], v[2]);
1677
- }`,
1678
- "vec4<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
1679
- cv[0] = v[0];
1680
- cv[1] = v[1];
1681
- cv[2] = v[2];
1682
- cv[3] = v[3];
1683
- gl.uniform4i(location, v[0], v[1], v[2], v[3]);
1684
- }`,
1685
- "mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
1686
- "mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
1687
- "mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);"
1688
- }, lt = {
1689
- f32: "gl.uniform1fv(location, v);",
1690
- "vec2<f32>": "gl.uniform2fv(location, v);",
1691
- "vec3<f32>": "gl.uniform3fv(location, v);",
1692
- "vec4<f32>": "gl.uniform4fv(location, v);",
1693
- "mat2x2<f32>": "gl.uniformMatrix2fv(location, false, v);",
1694
- "mat3x3<f32>": "gl.uniformMatrix3fv(location, false, v);",
1695
- "mat4x4<f32>": "gl.uniformMatrix4fv(location, false, v);",
1696
- i32: "gl.uniform1iv(location, v);",
1697
- "vec2<i32>": "gl.uniform2iv(location, v);",
1698
- "vec3<i32>": "gl.uniform3iv(location, v);",
1699
- "vec4<i32>": "gl.uniform4iv(location, v);",
1700
- u32: "gl.uniform1iv(location, v);",
1701
- "vec2<u32>": "gl.uniform2iv(location, v);",
1702
- "vec3<u32>": "gl.uniform3iv(location, v);",
1703
- "vec4<u32>": "gl.uniform4iv(location, v);",
1704
- bool: "gl.uniform1iv(location, v);",
1705
- "vec2<bool>": "gl.uniform2iv(location, v);",
1706
- "vec3<bool>": "gl.uniform3iv(location, v);",
1707
- "vec4<bool>": "gl.uniform4iv(location, v);"
1708
- };
1709
- function dt(t, e) {
1710
- const r = [`
1711
- var v = null;
1712
- var cv = null;
1713
- var cu = null;
1714
- var t = 0;
1715
- var gl = renderer.gl;
1716
- var name = null;
1717
- `];
1718
- for (const n in t.uniforms) {
1719
- if (!e[n]) {
1720
- t.uniforms[n] instanceof M ? t.uniforms[n].ubo ? r.push(`
1721
- renderer.shader.bindUniformBlock(uv.${n}, "${n}");
1722
- `) : r.push(`
1723
- renderer.shader.updateUniformGroup(uv.${n});
1724
- `) : t.uniforms[n] instanceof J && r.push(`
1725
- renderer.shader.bindBufferResource(uv.${n}, "${n}");
1726
- `);
1727
- continue;
1728
- }
1729
- const s = t.uniformStructures[n];
1730
- let i = !1;
1731
- for (let a = 0; a < C.length; a++) {
1732
- const o = C[a];
1733
- if (s.type === o.type && o.test(s)) {
1734
- r.push(`name = "${n}";`, C[a].uniform), i = !0;
1735
- break;
1736
- }
1737
- }
1738
- if (!i) {
1739
- const o = (s.size === 1 ? ht : lt)[s.type].replace("location", `ud["${n}"].location`);
1740
- r.push(`
1741
- cu = ud["${n}"];
1742
- cv = cu.value;
1743
- v = uv["${n}"];
1744
- ${o};`);
1745
- }
1746
- }
1747
- return new Function("ud", "uv", "renderer", "syncData", r.join(`
1748
- `));
1749
- }
1750
- class be {
1751
- /** @param renderer - The renderer this System works for. */
1752
- constructor(e) {
1753
- this._cache = {}, this._uniformGroupSyncHash = {}, this._renderer = e, this.gl = null, this._cache = {};
1754
- }
1755
- contextChange(e) {
1756
- this.gl = e;
1757
- }
1758
- /**
1759
- * Uploads the uniforms values to the currently bound shader.
1760
- * @param group - the uniforms values that be applied to the current shader
1761
- * @param program
1762
- * @param syncData
1763
- * @param syncData.textureCount
1764
- */
1765
- updateUniformGroup(e, r, n) {
1766
- const s = this._renderer.shader._getProgramData(r);
1767
- (!e.isStatic || e._dirtyId !== s.uniformDirtyGroups[e.uid]) && (s.uniformDirtyGroups[e.uid] = e._dirtyId, this._getUniformSyncFunction(e, r)(s.uniformData, e.uniforms, this._renderer, n));
1768
- }
1769
- /**
1770
- * Overridable by the pixi.js/unsafe-eval package to use static syncUniforms instead.
1771
- * @param group
1772
- * @param program
1773
- */
1774
- _getUniformSyncFunction(e, r) {
1775
- var n;
1776
- return ((n = this._uniformGroupSyncHash[e._signature]) == null ? void 0 : n[r._key]) || this._createUniformSyncFunction(e, r);
1777
- }
1778
- _createUniformSyncFunction(e, r) {
1779
- const n = this._uniformGroupSyncHash[e._signature] || (this._uniformGroupSyncHash[e._signature] = {}), s = this._getSignature(e, r._uniformData, "u");
1780
- return this._cache[s] || (this._cache[s] = this._generateUniformsSync(e, r._uniformData)), n[r._key] = this._cache[s], n[r._key];
1781
- }
1782
- _generateUniformsSync(e, r) {
1783
- return dt(e, r);
1784
- }
1785
- /**
1786
- * Takes a uniform group and data and generates a unique signature for them.
1787
- * @param group - The uniform group to get signature of
1788
- * @param group.uniforms
1789
- * @param uniformData - Uniform information generated by the shader
1790
- * @param preFix
1791
- * @returns Unique signature of the uniform group
1792
- */
1793
- _getSignature(e, r, n) {
1794
- const s = e.uniforms, i = [`${n}-`];
1795
- for (const a in s)
1796
- i.push(a), r[a] && i.push(r[a].type);
1797
- return i.join("-");
1798
- }
1799
- /** Destroys this System and removes all its textures. */
1800
- destroy() {
1801
- this._renderer = null, this._cache = null;
1802
- }
1803
- }
1804
- be.extension = {
1805
- type: [
1806
- d.WebGLSystem
1807
- ],
1808
- name: "uniformGroup"
1809
- };
1810
- function mt(t) {
1811
- const e = {};
1812
- if (e.normal = [t.ONE, t.ONE_MINUS_SRC_ALPHA], e.add = [t.ONE, t.ONE], e.multiply = [t.DST_COLOR, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.screen = [t.ONE, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.none = [0, 0], e["normal-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_ALPHA, t.ONE, t.ONE_MINUS_SRC_ALPHA], e["add-npm"] = [t.SRC_ALPHA, t.ONE, t.ONE, t.ONE], e["screen-npm"] = [t.SRC_ALPHA, t.ONE_MINUS_SRC_COLOR, t.ONE, t.ONE_MINUS_SRC_ALPHA], e.erase = [t.ZERO, t.ONE_MINUS_SRC_ALPHA], !(t instanceof R.get().getWebGLRenderingContext()))
1813
- e.min = [t.ONE, t.ONE, t.ONE, t.ONE, t.MIN, t.MIN], e.max = [t.ONE, t.ONE, t.ONE, t.ONE, t.MAX, t.MAX];
1814
- else {
1815
- const n = t.getExtension("EXT_blend_minmax");
1816
- n && (e.min = [t.ONE, t.ONE, t.ONE, t.ONE, n.MIN_EXT, n.MIN_EXT], e.max = [t.ONE, t.ONE, t.ONE, t.ONE, n.MAX_EXT, n.MAX_EXT]);
1817
- }
1818
- return e;
1819
- }
1820
- const Et = 0, bt = 1, pt = 2, St = 3, Rt = 4, gt = 5, pe = class U {
1821
- constructor(e) {
1822
- this._invertFrontFace = !1, this.gl = null, this.stateId = 0, this.polygonOffset = 0, this.blendMode = "none", this._blendEq = !1, this.map = [], this.map[Et] = this.setBlend, this.map[bt] = this.setOffset, this.map[pt] = this.setCullFace, this.map[St] = this.setDepthTest, this.map[Rt] = this.setFrontFace, this.map[gt] = this.setDepthMask, this.checks = [], this.defaultState = P.for2d(), e.renderTarget.onRenderTargetChange.add(this);
1823
- }
1824
- onRenderTargetChange(e) {
1825
- this._invertFrontFace = !e.isRoot, this._cullFace ? this.setFrontFace(this._frontFace) : this._frontFaceDirty = !0;
1826
- }
1827
- contextChange(e) {
1828
- this.gl = e, this.blendModesMap = mt(e), this.resetState();
1829
- }
1830
- /**
1831
- * Sets the current state
1832
- * @param {*} state - The state to set.
1833
- */
1834
- set(e) {
1835
- if (e || (e = this.defaultState), this.stateId !== e.data) {
1836
- let r = this.stateId ^ e.data, n = 0;
1837
- for (; r; )
1838
- r & 1 && this.map[n].call(this, !!(e.data & 1 << n)), r >>= 1, n++;
1839
- this.stateId = e.data;
1840
- }
1841
- for (let r = 0; r < this.checks.length; r++)
1842
- this.checks[r](this, e);
1843
- }
1844
- /**
1845
- * Sets the state, when previous state is unknown.
1846
- * @param {*} state - The state to set
1847
- */
1848
- forceState(e) {
1849
- e || (e = this.defaultState);
1850
- for (let r = 0; r < this.map.length; r++)
1851
- this.map[r].call(this, !!(e.data & 1 << r));
1852
- for (let r = 0; r < this.checks.length; r++)
1853
- this.checks[r](this, e);
1854
- this.stateId = e.data;
1855
- }
1856
- /**
1857
- * Sets whether to enable or disable blending.
1858
- * @param value - Turn on or off WebGl blending.
1859
- */
1860
- setBlend(e) {
1861
- this._updateCheck(U._checkBlendMode, e), this.gl[e ? "enable" : "disable"](this.gl.BLEND);
1862
- }
1863
- /**
1864
- * Sets whether to enable or disable polygon offset fill.
1865
- * @param value - Turn on or off webgl polygon offset testing.
1866
- */
1867
- setOffset(e) {
1868
- this._updateCheck(U._checkPolygonOffset, e), this.gl[e ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
1869
- }
1870
- /**
1871
- * Sets whether to enable or disable depth test.
1872
- * @param value - Turn on or off webgl depth testing.
1873
- */
1874
- setDepthTest(e) {
1875
- this.gl[e ? "enable" : "disable"](this.gl.DEPTH_TEST);
1876
- }
1877
- /**
1878
- * Sets whether to enable or disable depth mask.
1879
- * @param value - Turn on or off webgl depth mask.
1880
- */
1881
- setDepthMask(e) {
1882
- this.gl.depthMask(e);
1883
- }
1884
- /**
1885
- * Sets whether to enable or disable cull face.
1886
- * @param {boolean} value - Turn on or off webgl cull face.
1887
- */
1888
- setCullFace(e) {
1889
- this._cullFace = e, this.gl[e ? "enable" : "disable"](this.gl.CULL_FACE), this._cullFace && this._frontFaceDirty && this.setFrontFace(this._frontFace);
1890
- }
1891
- /**
1892
- * Sets the gl front face.
1893
- * @param {boolean} value - true is clockwise and false is counter-clockwise
1894
- */
1895
- setFrontFace(e) {
1896
- this._frontFace = e, this._frontFaceDirty = !1;
1897
- const r = this._invertFrontFace ? !e : e;
1898
- this._glFrontFace !== r && (this._glFrontFace = r, this.gl.frontFace(this.gl[r ? "CW" : "CCW"]));
1899
- }
1900
- /**
1901
- * Sets the blend mode.
1902
- * @param {number} value - The blend mode to set to.
1903
- */
1904
- setBlendMode(e) {
1905
- if (this.blendModesMap[e] || (e = "normal"), e === this.blendMode)
1906
- return;
1907
- this.blendMode = e;
1908
- const r = this.blendModesMap[e], n = this.gl;
1909
- r.length === 2 ? n.blendFunc(r[0], r[1]) : n.blendFuncSeparate(r[0], r[1], r[2], r[3]), r.length === 6 ? (this._blendEq = !0, n.blendEquationSeparate(r[4], r[5])) : this._blendEq && (this._blendEq = !1, n.blendEquationSeparate(n.FUNC_ADD, n.FUNC_ADD));
1910
- }
1911
- /**
1912
- * Sets the polygon offset.
1913
- * @param {number} value - the polygon offset
1914
- * @param {number} scale - the polygon offset scale
1915
- */
1916
- setPolygonOffset(e, r) {
1917
- this.gl.polygonOffset(e, r);
1918
- }
1919
- /** Resets all the logic and disables the VAOs. */
1920
- resetState() {
1921
- 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");
1922
- }
1923
- /**
1924
- * Checks to see which updates should be checked based on which settings have been activated.
1925
- *
1926
- * For example, if blend is enabled then we should check the blend modes each time the state is changed
1927
- * or if polygon fill is activated then we need to check if the polygon offset changes.
1928
- * The idea is that we only check what we have too.
1929
- * @param func - the checking function to add or remove
1930
- * @param value - should the check function be added or removed.
1931
- */
1932
- _updateCheck(e, r) {
1933
- const n = this.checks.indexOf(e);
1934
- r && n === -1 ? this.checks.push(e) : !r && n !== -1 && this.checks.splice(n, 1);
1935
- }
1936
- /**
1937
- * A private little wrapper function that we call to check the blend mode.
1938
- * @param system - the System to perform the state check on
1939
- * @param state - the state that the blendMode will pulled from
1940
- */
1941
- static _checkBlendMode(e, r) {
1942
- e.setBlendMode(r.blendMode);
1943
- }
1944
- /**
1945
- * A private little wrapper function that we call to check the polygon offset.
1946
- * @param system - the System to perform the state check on
1947
- * @param state - the state that the blendMode will pulled from
1948
- */
1949
- static _checkPolygonOffset(e, r) {
1950
- e.setPolygonOffset(1, r.polygonOffset);
1951
- }
1952
- /** @ignore */
1953
- destroy() {
1954
- this.gl = null, this.checks.length = 0;
1955
- }
1956
- };
1957
- pe.extension = {
1958
- type: [
1959
- d.WebGLSystem
1960
- ],
1961
- name: "state"
1962
- };
1963
- let Tt = pe;
1964
- class xt {
1965
- constructor(e) {
1966
- this.target = w.TEXTURE_2D, this._layerInitMask = 0, this.texture = e, this.width = -1, this.height = -1, this.type = l.UNSIGNED_BYTE, this.internalFormat = G.RGBA, this.format = G.RGBA, this.samplerType = 0;
1967
- }
1968
- destroy() {
1969
- }
1970
- }
1971
- const vt = {
1972
- id: "buffer",
1973
- upload(t, e, r, n, s, i = !1) {
1974
- const a = s || e.target;
1975
- !i && e.width === t.width && e.height === t.height ? r.texSubImage2D(
1976
- a,
1977
- 0,
1978
- 0,
1979
- 0,
1980
- t.width,
1981
- t.height,
1982
- e.format,
1983
- e.type,
1984
- t.resource
1985
- ) : r.texImage2D(
1986
- a,
1987
- 0,
1988
- e.internalFormat,
1989
- t.width,
1990
- t.height,
1991
- 0,
1992
- e.format,
1993
- e.type,
1994
- t.resource
1995
- ), e.width = t.width, e.height = t.height;
1996
- }
1997
- }, At = {
1998
- "bc1-rgba-unorm": !0,
1999
- "bc1-rgba-unorm-srgb": !0,
2000
- "bc2-rgba-unorm": !0,
2001
- "bc2-rgba-unorm-srgb": !0,
2002
- "bc3-rgba-unorm": !0,
2003
- "bc3-rgba-unorm-srgb": !0,
2004
- "bc4-r-unorm": !0,
2005
- "bc4-r-snorm": !0,
2006
- "bc5-rg-unorm": !0,
2007
- "bc5-rg-snorm": !0,
2008
- "bc6h-rgb-ufloat": !0,
2009
- "bc6h-rgb-float": !0,
2010
- "bc7-rgba-unorm": !0,
2011
- "bc7-rgba-unorm-srgb": !0,
2012
- // ETC2 compressed formats usable if "texture-compression-etc2" is both
2013
- // supported by the device/user agent and enabled in requestDevice.
2014
- "etc2-rgb8unorm": !0,
2015
- "etc2-rgb8unorm-srgb": !0,
2016
- "etc2-rgb8a1unorm": !0,
2017
- "etc2-rgb8a1unorm-srgb": !0,
2018
- "etc2-rgba8unorm": !0,
2019
- "etc2-rgba8unorm-srgb": !0,
2020
- "eac-r11unorm": !0,
2021
- "eac-r11snorm": !0,
2022
- "eac-rg11unorm": !0,
2023
- "eac-rg11snorm": !0,
2024
- // ASTC compressed formats usable if "texture-compression-astc" is both
2025
- // supported by the device/user agent and enabled in requestDevice.
2026
- "astc-4x4-unorm": !0,
2027
- "astc-4x4-unorm-srgb": !0,
2028
- "astc-5x4-unorm": !0,
2029
- "astc-5x4-unorm-srgb": !0,
2030
- "astc-5x5-unorm": !0,
2031
- "astc-5x5-unorm-srgb": !0,
2032
- "astc-6x5-unorm": !0,
2033
- "astc-6x5-unorm-srgb": !0,
2034
- "astc-6x6-unorm": !0,
2035
- "astc-6x6-unorm-srgb": !0,
2036
- "astc-8x5-unorm": !0,
2037
- "astc-8x5-unorm-srgb": !0,
2038
- "astc-8x6-unorm": !0,
2039
- "astc-8x6-unorm-srgb": !0,
2040
- "astc-8x8-unorm": !0,
2041
- "astc-8x8-unorm-srgb": !0,
2042
- "astc-10x5-unorm": !0,
2043
- "astc-10x5-unorm-srgb": !0,
2044
- "astc-10x6-unorm": !0,
2045
- "astc-10x6-unorm-srgb": !0,
2046
- "astc-10x8-unorm": !0,
2047
- "astc-10x8-unorm-srgb": !0,
2048
- "astc-10x10-unorm": !0,
2049
- "astc-10x10-unorm-srgb": !0,
2050
- "astc-12x10-unorm": !0,
2051
- "astc-12x10-unorm-srgb": !0,
2052
- "astc-12x12-unorm": !0,
2053
- "astc-12x12-unorm-srgb": !0
2054
- }, Bt = {
2055
- id: "compressed",
2056
- upload(t, e, r, n, s, i) {
2057
- const a = s ?? e.target;
2058
- r.pixelStorei(r.UNPACK_ALIGNMENT, 4);
2059
- let o = t.pixelWidth, u = t.pixelHeight;
2060
- const c = !!At[t.format];
2061
- for (let _ = 0; _ < t.resource.length; _++) {
2062
- const f = t.resource[_];
2063
- c ? r.compressedTexImage2D(
2064
- a,
2065
- _,
2066
- e.internalFormat,
2067
- o,
2068
- u,
2069
- 0,
2070
- f
2071
- ) : r.texImage2D(
2072
- a,
2073
- _,
2074
- e.internalFormat,
2075
- o,
2076
- u,
2077
- 0,
2078
- e.format,
2079
- e.type,
2080
- f
2081
- ), o = Math.max(o >> 1, 1), u = Math.max(u >> 1, 1);
2082
- }
2083
- }
2084
- }, $ = ["right", "left", "top", "bottom", "front", "back"];
2085
- function yt(t) {
2086
- return {
2087
- id: "cube",
2088
- upload(e, r, n, s) {
2089
- const i = e.faces;
2090
- for (let a = 0; a < $.length; a++) {
2091
- const o = $[a], u = i[o];
2092
- (t[u.uploadMethodId] || t.image).upload(
2093
- u,
2094
- r,
2095
- n,
2096
- s,
2097
- // Use the face target for the current face. cube faces ids go up 1 so
2098
- // GL_TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + i addresses the i'th face target.
2099
- w.TEXTURE_CUBE_MAP_POSITIVE_X + a,
2100
- // Force allocation for the first upload of each face.
2101
- (r._layerInitMask & 1 << a) === 0
2102
- ), r._layerInitMask |= 1 << a;
2103
- }
2104
- r.width = e.pixelWidth, r.height = e.pixelHeight;
2105
- }
2106
- };
2107
- }
2108
- const Se = {
2109
- id: "image",
2110
- upload(t, e, r, n, s, i = !1) {
2111
- const a = s || e.target, o = t.pixelWidth, u = t.pixelHeight, c = t.resourceWidth, _ = t.resourceHeight, f = n === 2, h = i || e.width !== o || e.height !== u, m = c >= o && _ >= u, b = t.resource;
2112
- (f ? Ct : Nt)(
2113
- r,
2114
- a,
2115
- e,
2116
- o,
2117
- u,
2118
- c,
2119
- _,
2120
- b,
2121
- h,
2122
- m
2123
- ), e.width = o, e.height = u;
2124
- }
2125
- };
2126
- function Ct(t, e, r, n, s, i, a, o, u, c) {
2127
- if (!c) {
2128
- u && t.texImage2D(
2129
- e,
2130
- 0,
2131
- r.internalFormat,
2132
- n,
2133
- s,
2134
- 0,
2135
- r.format,
2136
- r.type,
2137
- null
2138
- ), t.texSubImage2D(
2139
- e,
2140
- 0,
2141
- 0,
2142
- 0,
2143
- i,
2144
- a,
2145
- r.format,
2146
- r.type,
2147
- o
2148
- );
2149
- return;
2150
- }
2151
- if (!u) {
2152
- t.texSubImage2D(
2153
- e,
2154
- 0,
2155
- 0,
2156
- 0,
2157
- r.format,
2158
- r.type,
2159
- o
2160
- );
2161
- return;
2162
- }
2163
- t.texImage2D(
2164
- e,
2165
- 0,
2166
- r.internalFormat,
2167
- n,
2168
- s,
2169
- 0,
2170
- r.format,
2171
- r.type,
2172
- o
2173
- );
2174
- }
2175
- function Nt(t, e, r, n, s, i, a, o, u, c) {
2176
- if (!c) {
2177
- u && t.texImage2D(
2178
- e,
2179
- 0,
2180
- r.internalFormat,
2181
- n,
2182
- s,
2183
- 0,
2184
- r.format,
2185
- r.type,
2186
- null
2187
- ), t.texSubImage2D(
2188
- e,
2189
- 0,
2190
- 0,
2191
- 0,
2192
- r.format,
2193
- r.type,
2194
- o
2195
- );
2196
- return;
2197
- }
2198
- if (!u) {
2199
- t.texSubImage2D(
2200
- e,
2201
- 0,
2202
- 0,
2203
- 0,
2204
- r.format,
2205
- r.type,
2206
- o
2207
- );
2208
- return;
2209
- }
2210
- t.texImage2D(
2211
- e,
2212
- 0,
2213
- r.internalFormat,
2214
- r.format,
2215
- r.type,
2216
- o
2217
- );
2218
- }
2219
- const Dt = We(), It = {
2220
- id: "video",
2221
- upload(t, e, r, n, s, i = Dt) {
2222
- if (!t.isValid) {
2223
- const a = s ?? e.target;
2224
- r.texImage2D(
2225
- a,
2226
- 0,
2227
- e.internalFormat,
2228
- 1,
2229
- 1,
2230
- 0,
2231
- e.format,
2232
- e.type,
2233
- null
2234
- );
2235
- return;
2236
- }
2237
- Se.upload(t, e, r, n, s, i);
2238
- }
2239
- }, K = {
2240
- linear: 9729,
2241
- nearest: 9728
2242
- }, Gt = {
2243
- linear: {
2244
- linear: 9987,
2245
- nearest: 9985
2246
- },
2247
- nearest: {
2248
- linear: 9986,
2249
- nearest: 9984
2250
- }
2251
- }, I = {
2252
- "clamp-to-edge": 33071,
2253
- repeat: 10497,
2254
- "mirror-repeat": 33648
2255
- }, Ut = {
2256
- never: 512,
2257
- less: 513,
2258
- equal: 514,
2259
- "less-equal": 515,
2260
- greater: 516,
2261
- "not-equal": 517,
2262
- "greater-equal": 518,
2263
- always: 519
2264
- };
2265
- function Y(t, e, r, n, s, i, a, o) {
2266
- const u = i;
2267
- if (!o || t.addressModeU !== "repeat" || t.addressModeV !== "repeat" || t.addressModeW !== "repeat") {
2268
- const c = I[a ? "clamp-to-edge" : t.addressModeU], _ = I[a ? "clamp-to-edge" : t.addressModeV], f = I[a ? "clamp-to-edge" : t.addressModeW];
2269
- e[s](u, e.TEXTURE_WRAP_S, c), e[s](u, e.TEXTURE_WRAP_T, _), e.TEXTURE_WRAP_R && e[s](u, e.TEXTURE_WRAP_R, f);
2270
- }
2271
- if ((!o || t.magFilter !== "linear") && e[s](u, e.TEXTURE_MAG_FILTER, K[t.magFilter]), r) {
2272
- if (!o || t.mipmapFilter !== "linear") {
2273
- const c = Gt[t.minFilter][t.mipmapFilter];
2274
- e[s](u, e.TEXTURE_MIN_FILTER, c);
2275
- }
2276
- } else
2277
- e[s](u, e.TEXTURE_MIN_FILTER, K[t.minFilter]);
2278
- if (n && t.maxAnisotropy > 1) {
2279
- const c = Math.min(t.maxAnisotropy, e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
2280
- e[s](u, n.TEXTURE_MAX_ANISOTROPY_EXT, c);
2281
- }
2282
- t.compare && e[s](u, e.TEXTURE_COMPARE_FUNC, Ut[t.compare]);
2283
- }
2284
- function Ft(t) {
2285
- return {
2286
- // 8-bit formats
2287
- r8unorm: t.RED,
2288
- r8snorm: t.RED,
2289
- r8uint: t.RED,
2290
- r8sint: t.RED,
2291
- // 16-bit formats
2292
- r16uint: t.RED,
2293
- r16sint: t.RED,
2294
- r16float: t.RED,
2295
- rg8unorm: t.RG,
2296
- rg8snorm: t.RG,
2297
- rg8uint: t.RG,
2298
- rg8sint: t.RG,
2299
- // 32-bit formats
2300
- r32uint: t.RED,
2301
- r32sint: t.RED,
2302
- r32float: t.RED,
2303
- rg16uint: t.RG,
2304
- rg16sint: t.RG,
2305
- rg16float: t.RG,
2306
- rgba8unorm: t.RGBA,
2307
- "rgba8unorm-srgb": t.RGBA,
2308
- // Packed 32-bit formats
2309
- rgba8snorm: t.RGBA,
2310
- rgba8uint: t.RGBA,
2311
- rgba8sint: t.RGBA,
2312
- bgra8unorm: t.RGBA,
2313
- "bgra8unorm-srgb": t.RGBA,
2314
- rgb9e5ufloat: t.RGB,
2315
- rgb10a2unorm: t.RGBA,
2316
- rg11b10ufloat: t.RGB,
2317
- // 64-bit formats
2318
- rg32uint: t.RG,
2319
- rg32sint: t.RG,
2320
- rg32float: t.RG,
2321
- rgba16uint: t.RGBA,
2322
- rgba16sint: t.RGBA,
2323
- rgba16float: t.RGBA,
2324
- // 128-bit formats
2325
- rgba32uint: t.RGBA,
2326
- rgba32sint: t.RGBA,
2327
- rgba32float: t.RGBA,
2328
- // Depth/stencil formats
2329
- stencil8: t.STENCIL_INDEX8,
2330
- depth16unorm: t.DEPTH_COMPONENT,
2331
- depth24plus: t.DEPTH_COMPONENT,
2332
- "depth24plus-stencil8": t.DEPTH_STENCIL,
2333
- depth32float: t.DEPTH_COMPONENT,
2334
- "depth32float-stencil8": t.DEPTH_STENCIL
2335
- };
2336
- }
2337
- function Pt(t, e) {
2338
- let r = {}, n = t.RGBA;
2339
- return t instanceof R.get().getWebGLRenderingContext() ? e.srgb && (r = {
2340
- "rgba8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT,
2341
- "bgra8unorm-srgb": e.srgb.SRGB8_ALPHA8_EXT
2342
- }) : (r = {
2343
- "rgba8unorm-srgb": t.SRGB8_ALPHA8,
2344
- "bgra8unorm-srgb": t.SRGB8_ALPHA8
2345
- }, n = t.RGBA8), {
2346
- // 8-bit formats
2347
- r8unorm: t.R8,
2348
- r8snorm: t.R8_SNORM,
2349
- r8uint: t.R8UI,
2350
- r8sint: t.R8I,
2351
- // 16-bit formats
2352
- r16uint: t.R16UI,
2353
- r16sint: t.R16I,
2354
- r16float: t.R16F,
2355
- rg8unorm: t.RG8,
2356
- rg8snorm: t.RG8_SNORM,
2357
- rg8uint: t.RG8UI,
2358
- rg8sint: t.RG8I,
2359
- // 32-bit formats
2360
- r32uint: t.R32UI,
2361
- r32sint: t.R32I,
2362
- r32float: t.R32F,
2363
- rg16uint: t.RG16UI,
2364
- rg16sint: t.RG16I,
2365
- rg16float: t.RG16F,
2366
- rgba8unorm: t.RGBA,
2367
- ...r,
2368
- // Packed 32-bit formats
2369
- rgba8snorm: t.RGBA8_SNORM,
2370
- rgba8uint: t.RGBA8UI,
2371
- rgba8sint: t.RGBA8I,
2372
- bgra8unorm: n,
2373
- rgb9e5ufloat: t.RGB9_E5,
2374
- rgb10a2unorm: t.RGB10_A2,
2375
- rg11b10ufloat: t.R11F_G11F_B10F,
2376
- // 64-bit formats
2377
- rg32uint: t.RG32UI,
2378
- rg32sint: t.RG32I,
2379
- rg32float: t.RG32F,
2380
- rgba16uint: t.RGBA16UI,
2381
- rgba16sint: t.RGBA16I,
2382
- rgba16float: t.RGBA16F,
2383
- // 128-bit formats
2384
- rgba32uint: t.RGBA32UI,
2385
- rgba32sint: t.RGBA32I,
2386
- rgba32float: t.RGBA32F,
2387
- // Depth/stencil formats
2388
- stencil8: t.STENCIL_INDEX8,
2389
- depth16unorm: t.DEPTH_COMPONENT16,
2390
- depth24plus: t.DEPTH_COMPONENT24,
2391
- "depth24plus-stencil8": t.DEPTH24_STENCIL8,
2392
- depth32float: t.DEPTH_COMPONENT32F,
2393
- "depth32float-stencil8": t.DEPTH32F_STENCIL8,
2394
- // Compressed formats
2395
- ...e.s3tc ? {
2396
- "bc1-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,
2397
- "bc2-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,
2398
- "bc3-rgba-unorm": e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
2399
- } : {},
2400
- ...e.s3tc_sRGB ? {
2401
- "bc1-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
2402
- "bc2-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
2403
- "bc3-rgba-unorm-srgb": e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
2404
- } : {},
2405
- ...e.rgtc ? {
2406
- "bc4-r-unorm": e.rgtc.COMPRESSED_RED_RGTC1_EXT,
2407
- "bc4-r-snorm": e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,
2408
- "bc5-rg-unorm": e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,
2409
- "bc5-rg-snorm": e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
2410
- } : {},
2411
- ...e.bptc ? {
2412
- "bc6h-rgb-float": e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
2413
- "bc6h-rgb-ufloat": e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
2414
- "bc7-rgba-unorm": e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,
2415
- "bc7-rgba-unorm-srgb": e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT
2416
- } : {},
2417
- ...e.etc ? {
2418
- "etc2-rgb8unorm": e.etc.COMPRESSED_RGB8_ETC2,
2419
- "etc2-rgb8unorm-srgb": e.etc.COMPRESSED_SRGB8_ETC2,
2420
- "etc2-rgb8a1unorm": e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
2421
- "etc2-rgb8a1unorm-srgb": e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
2422
- "etc2-rgba8unorm": e.etc.COMPRESSED_RGBA8_ETC2_EAC,
2423
- "etc2-rgba8unorm-srgb": e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
2424
- "eac-r11unorm": e.etc.COMPRESSED_R11_EAC,
2425
- // 'eac-r11snorm'
2426
- "eac-rg11unorm": e.etc.COMPRESSED_SIGNED_RG11_EAC
2427
- // 'eac-rg11snorm'
2428
- } : {},
2429
- ...e.astc ? {
2430
- "astc-4x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,
2431
- "astc-4x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
2432
- "astc-5x4-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,
2433
- "astc-5x4-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
2434
- "astc-5x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,
2435
- "astc-5x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
2436
- "astc-6x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,
2437
- "astc-6x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
2438
- "astc-6x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,
2439
- "astc-6x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
2440
- "astc-8x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,
2441
- "astc-8x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
2442
- "astc-8x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,
2443
- "astc-8x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
2444
- "astc-8x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,
2445
- "astc-8x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
2446
- "astc-10x5-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,
2447
- "astc-10x5-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
2448
- "astc-10x6-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,
2449
- "astc-10x6-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
2450
- "astc-10x8-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,
2451
- "astc-10x8-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
2452
- "astc-10x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,
2453
- "astc-10x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
2454
- "astc-12x10-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,
2455
- "astc-12x10-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
2456
- "astc-12x12-unorm": e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,
2457
- "astc-12x12-unorm-srgb": e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
2458
- } : {}
2459
- };
2460
- }
2461
- function Ot(t) {
2462
- return {
2463
- // 8-bit formats
2464
- r8unorm: t.UNSIGNED_BYTE,
2465
- r8snorm: t.BYTE,
2466
- r8uint: t.UNSIGNED_BYTE,
2467
- r8sint: t.BYTE,
2468
- // 16-bit formats
2469
- r16uint: t.UNSIGNED_SHORT,
2470
- r16sint: t.SHORT,
2471
- r16float: t.HALF_FLOAT,
2472
- rg8unorm: t.UNSIGNED_BYTE,
2473
- rg8snorm: t.BYTE,
2474
- rg8uint: t.UNSIGNED_BYTE,
2475
- rg8sint: t.BYTE,
2476
- // 32-bit formats
2477
- r32uint: t.UNSIGNED_INT,
2478
- r32sint: t.INT,
2479
- r32float: t.FLOAT,
2480
- rg16uint: t.UNSIGNED_SHORT,
2481
- rg16sint: t.SHORT,
2482
- rg16float: t.HALF_FLOAT,
2483
- rgba8unorm: t.UNSIGNED_BYTE,
2484
- "rgba8unorm-srgb": t.UNSIGNED_BYTE,
2485
- // Packed 32-bit formats
2486
- rgba8snorm: t.BYTE,
2487
- rgba8uint: t.UNSIGNED_BYTE,
2488
- rgba8sint: t.BYTE,
2489
- bgra8unorm: t.UNSIGNED_BYTE,
2490
- "bgra8unorm-srgb": t.UNSIGNED_BYTE,
2491
- rgb9e5ufloat: t.UNSIGNED_INT_5_9_9_9_REV,
2492
- rgb10a2unorm: t.UNSIGNED_INT_2_10_10_10_REV,
2493
- rg11b10ufloat: t.UNSIGNED_INT_10F_11F_11F_REV,
2494
- // 64-bit formats
2495
- rg32uint: t.UNSIGNED_INT,
2496
- rg32sint: t.INT,
2497
- rg32float: t.FLOAT,
2498
- rgba16uint: t.UNSIGNED_SHORT,
2499
- rgba16sint: t.SHORT,
2500
- rgba16float: t.HALF_FLOAT,
2501
- // 128-bit formats
2502
- rgba32uint: t.UNSIGNED_INT,
2503
- rgba32sint: t.INT,
2504
- rgba32float: t.FLOAT,
2505
- // Depth/stencil formats
2506
- stencil8: t.UNSIGNED_BYTE,
2507
- depth16unorm: t.UNSIGNED_SHORT,
2508
- depth24plus: t.UNSIGNED_INT,
2509
- "depth24plus-stencil8": t.UNSIGNED_INT_24_8,
2510
- depth32float: t.FLOAT,
2511
- "depth32float-stencil8": t.FLOAT_32_UNSIGNED_INT_24_8_REV
2512
- };
2513
- }
2514
- function Mt(t) {
2515
- return {
2516
- "2d": t.TEXTURE_2D,
2517
- cube: t.TEXTURE_CUBE_MAP,
2518
- "1d": null,
2519
- // WebGL2 only
2520
- "3d": (t == null ? void 0 : t.TEXTURE_3D) || null,
2521
- "2d-array": (t == null ? void 0 : t.TEXTURE_2D_ARRAY) || null,
2522
- "cube-array": (t == null ? void 0 : t.TEXTURE_CUBE_MAP_ARRAY) || null
2523
- };
2524
- }
2525
- const Lt = 4;
2526
- class Re {
2527
- constructor(e) {
2528
- 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 F({
2529
- renderer: e,
2530
- type: "resource",
2531
- onUnload: this.onSourceUnload.bind(this),
2532
- name: "glTexture"
2533
- });
2534
- const r = {
2535
- image: Se,
2536
- buffer: vt,
2537
- video: It,
2538
- compressed: Bt
2539
- };
2540
- this._uploads = {
2541
- ...r,
2542
- cube: yt(r)
2543
- };
2544
- }
2545
- /**
2546
- * @deprecated since 8.15.0
2547
- */
2548
- get managedTextures() {
2549
- return Object.values(this._managedTextures.items);
2550
- }
2551
- contextChange(e) {
2552
- this._gl = e, this._mapFormatToInternalFormat || (this._mapFormatToInternalFormat = Pt(e, this._renderer.context.extensions), this._mapFormatToType = Ot(e), this._mapFormatToFormat = Ft(e), this._mapViewDimensionToGlTarget = Mt(e)), this._managedTextures.removeAll(!0), this._glSamplers = /* @__PURE__ */ Object.create(null), this._boundSamplers = /* @__PURE__ */ Object.create(null), this._premultiplyAlpha = !1;
2553
- for (let r = 0; r < 16; r++)
2554
- this.bind(S.EMPTY, r);
2555
- }
2556
- /**
2557
- * Initializes a texture source, if it has already been initialized nothing will happen.
2558
- * @param source - The texture source to initialize.
2559
- * @returns The initialized texture source.
2560
- */
2561
- initSource(e) {
2562
- this.bind(e);
2563
- }
2564
- bind(e, r = 0) {
2565
- const n = e.source;
2566
- e ? (this.bindSource(n, r), this._useSeparateSamplers && this._bindSampler(n.style, r)) : (this.bindSource(null, r), this._useSeparateSamplers && this._bindSampler(null, r));
2567
- }
2568
- bindSource(e, r = 0) {
2569
- const n = this._gl;
2570
- if (e._gcLastUsed = this._renderer.gc.now, this._boundTextures[r] !== e) {
2571
- this._boundTextures[r] = e, this._activateLocation(r), e || (e = S.EMPTY.source);
2572
- const s = this.getGlSource(e);
2573
- n.bindTexture(s.target, s.texture);
2574
- }
2575
- }
2576
- _bindSampler(e, r = 0) {
2577
- const n = this._gl;
2578
- if (!e) {
2579
- this._boundSamplers[r] = null, n.bindSampler(r, null);
2580
- return;
2581
- }
2582
- const s = this._getGlSampler(e);
2583
- this._boundSamplers[r] !== s && (this._boundSamplers[r] = s, n.bindSampler(r, s));
2584
- }
2585
- unbind(e) {
2586
- const r = e.source, n = this._boundTextures, s = this._gl;
2587
- for (let i = 0; i < n.length; i++)
2588
- if (n[i] === r) {
2589
- this._activateLocation(i);
2590
- const a = this.getGlSource(r);
2591
- s.bindTexture(a.target, null), n[i] = null;
2592
- }
2593
- }
2594
- _activateLocation(e) {
2595
- this._activeTextureLocation !== e && (this._activeTextureLocation = e, this._gl.activeTexture(this._gl.TEXTURE0 + e));
2596
- }
2597
- _initSource(e) {
2598
- const r = this._gl, n = new xt(r.createTexture());
2599
- if (n.type = this._mapFormatToType[e.format], n.internalFormat = this._mapFormatToInternalFormat[e.format], n.format = this._mapFormatToFormat[e.format], n.target = this._mapViewDimensionToGlTarget[e.viewDimension], n.target === null)
2600
- throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);
2601
- if (e.uploadMethodId === "cube" && (n.target = r.TEXTURE_CUBE_MAP), e.autoGenerateMipmaps && (this._renderer.context.supports.nonPowOf2mipmaps || e.isPowerOfTwo)) {
2602
- const i = Math.max(e.width, e.height);
2603
- e.mipLevelCount = Math.floor(Math.log2(i)) + 1;
2604
- }
2605
- return e._gpuData[this._renderer.uid] = n, 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), n;
2606
- }
2607
- onStyleChange(e) {
2608
- this.updateStyle(e, !1);
2609
- }
2610
- updateStyle(e, r) {
2611
- const n = this._gl, s = this.getGlSource(e);
2612
- n.bindTexture(s.target, s.texture), this._boundTextures[this._activeTextureLocation] = e, Y(
2613
- e.style,
2614
- n,
2615
- e.mipLevelCount > 1,
2616
- this._renderer.context.extensions.anisotropicFiltering,
2617
- "texParameteri",
2618
- s.target,
2619
- // will force a clamp to edge if the texture is not a power of two
2620
- !this._renderer.context.supports.nonPowOf2wrapping && !e.isPowerOfTwo,
2621
- r
2622
- );
2623
- }
2624
- onSourceUnload(e, r = !1) {
2625
- const n = e._gpuData[this._renderer.uid];
2626
- n && (r || (this.unbind(e), this._gl.deleteTexture(n.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));
2627
- }
2628
- onSourceUpdate(e) {
2629
- const r = this._gl, n = this.getGlSource(e);
2630
- r.bindTexture(n.target, n.texture), this._boundTextures[this._activeTextureLocation] = e;
2631
- const s = e.alphaMode === "premultiply-alpha-on-upload";
2632
- if (this._premultiplyAlpha !== s && (this._premultiplyAlpha = s, r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, s)), this._uploads[e.uploadMethodId])
2633
- this._uploads[e.uploadMethodId].upload(e, n, r, this._renderer.context.webGLVersion);
2634
- else if (n.target === r.TEXTURE_2D)
2635
- this._initEmptyTexture2D(n, e);
2636
- else if (n.target === r.TEXTURE_2D_ARRAY)
2637
- this._initEmptyTexture2DArray(n, e);
2638
- else if (n.target === r.TEXTURE_CUBE_MAP)
2639
- this._initEmptyTextureCube(n, e);
2640
- else
2641
- throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");
2642
- this._applyMipRange(n, e), e.autoGenerateMipmaps && e.mipLevelCount > 1 && this.onUpdateMipmaps(e, !1);
2643
- }
2644
- onUpdateMipmaps(e, r = !0) {
2645
- r && this.bindSource(e, 0);
2646
- const n = this.getGlSource(e);
2647
- this._gl.generateMipmap(n.target);
2648
- }
2649
- _initEmptyTexture2D(e, r) {
2650
- const n = this._gl;
2651
- n.texImage2D(
2652
- n.TEXTURE_2D,
2653
- 0,
2654
- e.internalFormat,
2655
- r.pixelWidth,
2656
- r.pixelHeight,
2657
- 0,
2658
- e.format,
2659
- e.type,
2660
- null
2661
- );
2662
- let s = Math.max(r.pixelWidth >> 1, 1), i = Math.max(r.pixelHeight >> 1, 1);
2663
- for (let a = 1; a < r.mipLevelCount; a++)
2664
- n.texImage2D(
2665
- n.TEXTURE_2D,
2666
- a,
2667
- e.internalFormat,
2668
- s,
2669
- i,
2670
- 0,
2671
- e.format,
2672
- e.type,
2673
- null
2674
- ), s = Math.max(s >> 1, 1), i = Math.max(i >> 1, 1);
2675
- }
2676
- _initEmptyTexture2DArray(e, r) {
2677
- if (this._renderer.context.webGLVersion !== 2)
2678
- throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");
2679
- const n = this._gl, s = Math.max(r.arrayLayerCount | 0, 1);
2680
- n.texImage3D(
2681
- n.TEXTURE_2D_ARRAY,
2682
- 0,
2683
- e.internalFormat,
2684
- r.pixelWidth,
2685
- r.pixelHeight,
2686
- s,
2687
- 0,
2688
- e.format,
2689
- e.type,
2690
- null
2691
- );
2692
- let i = Math.max(r.pixelWidth >> 1, 1), a = Math.max(r.pixelHeight >> 1, 1);
2693
- for (let o = 1; o < r.mipLevelCount; o++)
2694
- n.texImage3D(
2695
- n.TEXTURE_2D_ARRAY,
2696
- o,
2697
- e.internalFormat,
2698
- i,
2699
- a,
2700
- s,
2701
- 0,
2702
- e.format,
2703
- e.type,
2704
- null
2705
- ), i = Math.max(i >> 1, 1), a = Math.max(a >> 1, 1);
2706
- }
2707
- _initEmptyTextureCube(e, r) {
2708
- const n = this._gl, s = 6;
2709
- for (let o = 0; o < s; o++)
2710
- n.texImage2D(
2711
- n.TEXTURE_CUBE_MAP_POSITIVE_X + o,
2712
- 0,
2713
- e.internalFormat,
2714
- r.pixelWidth,
2715
- r.pixelHeight,
2716
- 0,
2717
- e.format,
2718
- e.type,
2719
- null
2720
- );
2721
- let i = Math.max(r.pixelWidth >> 1, 1), a = Math.max(r.pixelHeight >> 1, 1);
2722
- for (let o = 1; o < r.mipLevelCount; o++) {
2723
- for (let u = 0; u < s; u++)
2724
- n.texImage2D(
2725
- n.TEXTURE_CUBE_MAP_POSITIVE_X + u,
2726
- o,
2727
- e.internalFormat,
2728
- i,
2729
- a,
2730
- 0,
2731
- e.format,
2732
- e.type,
2733
- null
2734
- );
2735
- i = Math.max(i >> 1, 1), a = Math.max(a >> 1, 1);
2736
- }
2737
- }
2738
- /**
2739
- * Applies a mip range to the currently-bound texture so WebGL2 considers the texture "mipmap complete"
2740
- * for the declared `mipLevelCount` (especially important for partial mip chains rendered via FBO).
2741
- * @param glTexture - The GL texture wrapper.
2742
- * @param source - The texture source describing mipLevelCount.
2743
- */
2744
- _applyMipRange(e, r) {
2745
- if (this._renderer.context.webGLVersion !== 2) return;
2746
- const n = this._gl, s = Math.max((r.mipLevelCount | 0) - 1, 0);
2747
- n.texParameteri(e.target, n.TEXTURE_BASE_LEVEL, 0), n.texParameteri(e.target, n.TEXTURE_MAX_LEVEL, s);
2748
- }
2749
- _initSampler(e) {
2750
- const r = this._gl, n = this._gl.createSampler();
2751
- return this._glSamplers[e._resourceId] = n, Y(
2752
- e,
2753
- r,
2754
- this._boundTextures[this._activeTextureLocation].mipLevelCount > 1,
2755
- this._renderer.context.extensions.anisotropicFiltering,
2756
- "samplerParameteri",
2757
- n,
2758
- !1,
2759
- !0
2760
- ), this._glSamplers[e._resourceId];
2761
- }
2762
- _getGlSampler(e) {
2763
- return this._glSamplers[e._resourceId] || this._initSampler(e);
2764
- }
2765
- getGlSource(e) {
2766
- return e._gcLastUsed = this._renderer.gc.now, e._gpuData[this._renderer.uid] || this._initSource(e);
2767
- }
2768
- generateCanvas(e) {
2769
- const { pixels: r, width: n, height: s } = this.getPixels(e), i = R.get().createCanvas();
2770
- i.width = n, i.height = s;
2771
- const a = i.getContext("2d");
2772
- if (a) {
2773
- const o = a.createImageData(n, s);
2774
- o.data.set(r), a.putImageData(o, 0, 0);
2775
- }
2776
- return i;
2777
- }
2778
- getPixels(e) {
2779
- const r = e.source.resolution, n = e.frame, s = Math.max(Math.round(n.width * r), 1), i = Math.max(Math.round(n.height * r), 1), a = new Uint8Array(Lt * s * i), o = this._renderer, u = o.renderTarget.getRenderTarget(e), c = o.renderTarget.getGpuRenderTarget(u), _ = o.gl;
2780
- return _.bindFramebuffer(_.FRAMEBUFFER, c.resolveTargetFramebuffer), _.readPixels(
2781
- Math.round(n.x * r),
2782
- Math.round(n.y * r),
2783
- s,
2784
- i,
2785
- _.RGBA,
2786
- _.UNSIGNED_BYTE,
2787
- a
2788
- ), { pixels: new Uint8ClampedArray(a.buffer), width: s, height: i };
2789
- }
2790
- destroy() {
2791
- 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;
2792
- }
2793
- resetState() {
2794
- this._activeTextureLocation = -1, this._boundTextures.fill(S.EMPTY.source), this._boundSamplers = /* @__PURE__ */ Object.create(null);
2795
- const e = this._gl;
2796
- this._premultiplyAlpha = !1, e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._premultiplyAlpha);
2797
- }
2798
- }
2799
- Re.extension = {
2800
- type: [
2801
- d.WebGLSystem
2802
- ],
2803
- name: "texture"
2804
- };
2805
- class ge {
2806
- contextChange(e) {
2807
- const r = new M({
2808
- uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
2809
- uTransformMatrix: { value: new q(), type: "mat3x3<f32>" },
2810
- uRound: { value: 0, type: "f32" }
2811
- }), n = e.limits.maxBatchableTextures, s = Z({
2812
- name: "graphics",
2813
- bits: [
2814
- De,
2815
- Ie(n),
2816
- ee,
2817
- Q
2818
- ]
2819
- });
2820
- this.shader = new O({
2821
- glProgram: s,
2822
- resources: {
2823
- localUniforms: r,
2824
- batchSamplers: Ge(n)
2825
- }
2826
- });
2827
- }
2828
- execute(e, r) {
2829
- const n = r.context, s = n.customShader || this.shader, i = e.renderer, a = i.graphicsContext, {
2830
- batcher: o,
2831
- instructions: u
2832
- } = a.getContextRenderData(n);
2833
- s.groups[0] = i.globalUniforms.bindGroup, i.state.set(e.state), i.shader.bind(s), i.geometry.bind(o.geometry, s.glProgram);
2834
- const c = u.instructions;
2835
- for (let _ = 0; _ < u.instructionSize; _++) {
2836
- const f = c[_];
2837
- if (f.size) {
2838
- for (let h = 0; h < f.textures.count; h++)
2839
- i.texture.bind(f.textures.textures[h], h);
2840
- i.geometry.draw(f.topology, f.size, f.start);
2841
- }
2842
- }
2843
- }
2844
- destroy() {
2845
- this.shader.destroy(!0), this.shader = null;
2846
- }
2847
- }
2848
- ge.extension = {
2849
- type: [
2850
- d.WebGLPipesAdaptor
2851
- ],
2852
- name: "graphics"
2853
- };
2854
- class Te {
2855
- init() {
2856
- const e = Z({
2857
- name: "mesh",
2858
- bits: [
2859
- ee,
2860
- He,
2861
- Q
2862
- ]
2863
- });
2864
- this._shader = new O({
2865
- glProgram: e,
2866
- resources: {
2867
- uTexture: S.EMPTY.source,
2868
- textureUniforms: {
2869
- uTextureMatrix: { type: "mat3x3<f32>", value: new q() }
2870
- }
2871
- }
2872
- });
2873
- }
2874
- execute(e, r) {
2875
- const n = e.renderer;
2876
- let s = r._shader;
2877
- if (s) {
2878
- if (!s.glProgram) {
2879
- p("Mesh shader has no glProgram", r.shader);
2880
- return;
2881
- }
2882
- } else {
2883
- s = this._shader;
2884
- const i = r.texture, a = i.source;
2885
- s.resources.uTexture = a, s.resources.uSampler = a.style, s.resources.textureUniforms.uniforms.uTextureMatrix = i.textureMatrix.mapCoord;
2886
- }
2887
- s.groups[100] = n.globalUniforms.bindGroup, s.groups[101] = e.localUniformsBindGroup, n.encoder.draw({
2888
- geometry: r._geometry,
2889
- shader: s,
2890
- state: r.state
2891
- });
2892
- }
2893
- destroy() {
2894
- this._shader.destroy(!0), this._shader = null;
2895
- }
2896
- }
2897
- Te.extension = {
2898
- type: [
2899
- d.WebGLPipesAdaptor
2900
- ],
2901
- name: "mesh"
2902
- };
2903
- const wt = [
2904
- ...Ue,
2905
- he,
2906
- Ze,
2907
- $e,
2908
- ue,
2909
- ne,
2910
- Re,
2911
- le,
2912
- ie,
2913
- be,
2914
- Ee,
2915
- ce,
2916
- Tt,
2917
- _e,
2918
- oe
2919
- ], Ht = [...Fe], Vt = [re, Te, ge], xe = [], ve = [], Ae = [];
2920
- A.handleByNamedList(d.WebGLSystem, xe);
2921
- A.handleByNamedList(d.WebGLPipes, ve);
2922
- A.handleByNamedList(d.WebGLPipesAdaptor, Ae);
2923
- A.add(...wt, ...Ht, ...Vt);
2924
- class $t extends ye {
2925
- constructor() {
2926
- const e = {
2927
- name: "webgl",
2928
- type: ke.WEBGL,
2929
- systems: xe,
2930
- renderPipes: ve,
2931
- renderPipeAdaptors: Ae
2932
- };
2933
- super(e);
2934
- }
2935
- }
2936
- export {
2937
- $t as WebGLRenderer
2938
- };
2939
- //# sourceMappingURL=WebGLRenderer-Ci14rIHw.js.map