@annotorious/openseadragon 3.2.0 → 3.2.1

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