@micjanic/recursive-grid 1.0.4 → 1.0.6

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