@vunk/plus 1.3.11 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/components/SharedSystems.mjs +3195 -0
  2. package/components/WebGLRenderer.mjs +3617 -0
  3. package/components/WebGPURenderer.mjs +2103 -0
  4. package/components/_commonjsHelpers.mjs +7 -0
  5. package/components/agent-chat-provider/src/types.d.ts +2 -1
  6. package/components/broadcasting-markdown/index.d.ts +2 -0
  7. package/components/broadcasting-markdown/index.mjs +238 -306
  8. package/components/broadcasting-markdown/src/const.d.ts +2 -7
  9. package/components/broadcasting-markdown/src/ctx.d.ts +28 -15
  10. package/components/broadcasting-markdown/src/howler-speech.vue.d.ts +24 -44
  11. package/components/broadcasting-markdown/src/index.vue.d.ts +31 -167
  12. package/components/broadcasting-markdown/src/paragraph.vue.d.ts +1 -14
  13. package/components/broadcasting-markdown/src/types.d.ts +10 -2
  14. package/components/broadcasting-markdown/src/use.d.ts +18 -0
  15. package/components/browserAll.mjs +3187 -0
  16. package/components/bubble-list/index.mjs +2 -1
  17. package/components/bubble-list/src/index.vue.d.ts +27 -161
  18. package/components/bubble-templates/src/index.vue.d.ts +27 -161
  19. package/components/bubble-templates/src/types.d.ts +6 -0
  20. package/components/chat-independent/index.mjs +3 -0
  21. package/components/chat-independent/src/index.vue.d.ts +27 -161
  22. package/components/colorToUniform.mjs +266 -0
  23. package/components/index2.mjs +21220 -0
  24. package/components/init.mjs +3779 -0
  25. package/components/pixi-frame/index.css +4 -0
  26. package/components/pixi-frame/index.d.ts +8 -0
  27. package/components/pixi-frame/index.mjs +6 -0
  28. package/components/pixi-frame/src/core.vue.d.ts +122 -0
  29. package/components/pixi-frame/src/ctx.d.ts +40 -0
  30. package/components/pixi-frame/src/index.vue.d.ts +215 -0
  31. package/components/pixi-frame/src/provider.vue.d.ts +2 -0
  32. package/components/pixi-frame/src/types.d.ts +1 -0
  33. package/components/pixi-frame/src/use.d.ts +3 -0
  34. package/components/pixi-frame/src/view.vue.d.ts +25 -0
  35. package/components/tables-v1/src/ctx.d.ts +1 -1
  36. package/components/tables-v1/src/el-ctx.d.ts +1 -1
  37. package/components/tables-v1-checkbox/src/ctx.d.ts +1 -1
  38. package/components/tables-v1-checkbox/src/index.vue.d.ts +1 -1
  39. package/components/webworkerAll.mjs +8 -0
  40. package/index.css +5 -4
  41. package/package.json +8 -4
  42. package/components/broadcasting-markdown/index.css +0 -3
  43. package/components/broadcasting-markdown/src/custom-speech.vue.d.ts +0 -117
  44. package/components/broadcasting-markdown/src/web-speech.vue.d.ts +0 -110
@@ -0,0 +1,3617 @@
1
+ import { E as ExtensionType, B as BufferUsage, w as warn, D as DOMAdapter, K as getAttributeInfoFromFormat, u as GlProgram, s as Shader, t as Texture, a3 as Geometry, j as TextureSource, S as STENCIL_MODES, O as Rectangle, i as CanvasSource, h as CLEAR, k as UniformGroup, q as getMaxTexturesPerBatch, M as Matrix, a4 as compileHighShaderGlProgram, a5 as colorBitGl, a6 as generateTextureBatchBitGl, a7 as roundPixelsBitGl, a8 as getBatchSamplersUniformGroup, A as AbstractRenderer, R as RendererType, e as extensions } from './index2.mjs';
2
+ import { S as State, b as localUniformBitGl } from './colorToUniform.mjs';
3
+ import { e as ensureAttributes, G as GpuStencilModesToPixi, c as createUboSyncFunction, b as uboSyncFunctionsSTD40, U as UboSystem, R as RenderTargetSystem, B as BufferResource, d as uniformParsers, f as textureBitGl, S as SharedSystems, a as SharedRenderPipes } from './SharedSystems.mjs';
4
+ import 'vue';
5
+ import '@vunk/shared/enum';
6
+ import './browser.mjs';
7
+ import './_commonjsHelpers.mjs';
8
+ import './_plugin-vue_export-helper.mjs';
9
+
10
+ class GlBatchAdaptor {
11
+ constructor() {
12
+ this._tempState = State.for2d();
13
+ /**
14
+ * We only want to sync the a batched shaders uniforms once on first use
15
+ * this is a hash of shader uids to a boolean value. When the shader is first bound
16
+ * we set the value to true. When the shader is bound again we check the value and
17
+ * if it is true we know that the uniforms have already been synced and we skip it.
18
+ */
19
+ this._didUploadHash = {};
20
+ }
21
+ init(batcherPipe) {
22
+ batcherPipe.renderer.runners.contextChange.add(this);
23
+ }
24
+ contextChange() {
25
+ this._didUploadHash = {};
26
+ }
27
+ start(batchPipe, geometry, shader) {
28
+ const renderer = batchPipe.renderer;
29
+ const didUpload = this._didUploadHash[shader.uid];
30
+ renderer.shader.bind(shader, didUpload);
31
+ if (!didUpload) {
32
+ this._didUploadHash[shader.uid] = true;
33
+ }
34
+ renderer.shader.updateUniformGroup(renderer.globalUniforms.uniformGroup);
35
+ renderer.geometry.bind(geometry, shader.glProgram);
36
+ }
37
+ execute(batchPipe, batch) {
38
+ const renderer = batchPipe.renderer;
39
+ this._tempState.blendMode = batch.blendMode;
40
+ renderer.state.set(this._tempState);
41
+ const textures = batch.textures.textures;
42
+ for (let i = 0; i < batch.textures.count; i++) {
43
+ renderer.texture.bind(textures[i], i);
44
+ }
45
+ renderer.geometry.draw(batch.topology, batch.size, batch.start);
46
+ }
47
+ }
48
+ /** @ignore */
49
+ GlBatchAdaptor.extension = {
50
+ type: [
51
+ ExtensionType.WebGLPipesAdaptor
52
+ ],
53
+ name: "batch"
54
+ };
55
+
56
+ var BUFFER_TYPE = /* @__PURE__ */ ((BUFFER_TYPE2) => {
57
+ BUFFER_TYPE2[BUFFER_TYPE2["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
58
+ BUFFER_TYPE2[BUFFER_TYPE2["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
59
+ BUFFER_TYPE2[BUFFER_TYPE2["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
60
+ return BUFFER_TYPE2;
61
+ })(BUFFER_TYPE || {});
62
+
63
+ class GlBuffer {
64
+ constructor(buffer, type) {
65
+ this._lastBindBaseLocation = -1;
66
+ this._lastBindCallId = -1;
67
+ this.buffer = buffer || null;
68
+ this.updateID = -1;
69
+ this.byteLength = -1;
70
+ this.type = type;
71
+ }
72
+ }
73
+
74
+ class GlBufferSystem {
75
+ /**
76
+ * @param {Renderer} renderer - The renderer this System works for.
77
+ */
78
+ constructor(renderer) {
79
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null);
80
+ /** Cache keeping track of the base bound buffer bases */
81
+ this._boundBufferBases = /* @__PURE__ */ Object.create(null);
82
+ this._minBaseLocation = 0;
83
+ this._nextBindBaseIndex = this._minBaseLocation;
84
+ this._bindCallId = 0;
85
+ this._renderer = renderer;
86
+ this._renderer.renderableGC.addManagedHash(this, "_gpuBuffers");
87
+ }
88
+ /**
89
+ * @ignore
90
+ */
91
+ destroy() {
92
+ this._renderer = null;
93
+ this._gl = null;
94
+ this._gpuBuffers = null;
95
+ this._boundBufferBases = null;
96
+ }
97
+ /** Sets up the renderer context and necessary buffers. */
98
+ contextChange() {
99
+ const gl = this._gl = this._renderer.gl;
100
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null);
101
+ this._maxBindings = gl.MAX_UNIFORM_BUFFER_BINDINGS ? gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS) : 0;
102
+ }
103
+ getGlBuffer(buffer) {
104
+ return this._gpuBuffers[buffer.uid] || this.createGLBuffer(buffer);
105
+ }
106
+ /**
107
+ * This binds specified buffer. On first run, it will create the webGL buffers for the context too
108
+ * @param buffer - the buffer to bind to the renderer
109
+ */
110
+ bind(buffer) {
111
+ const { _gl: gl } = this;
112
+ const glBuffer = this.getGlBuffer(buffer);
113
+ gl.bindBuffer(glBuffer.type, glBuffer.buffer);
114
+ }
115
+ /**
116
+ * Binds an uniform buffer to at the given index.
117
+ *
118
+ * A cache is used so a buffer will not be bound again if already bound.
119
+ * @param glBuffer - the buffer to bind
120
+ * @param index - the base index to bind it to.
121
+ */
122
+ bindBufferBase(glBuffer, index) {
123
+ const { _gl: gl } = this;
124
+ if (this._boundBufferBases[index] !== glBuffer) {
125
+ this._boundBufferBases[index] = glBuffer;
126
+ glBuffer._lastBindBaseLocation = index;
127
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, index, glBuffer.buffer);
128
+ }
129
+ }
130
+ nextBindBase(hasTransformFeedback) {
131
+ this._bindCallId++;
132
+ this._minBaseLocation = 0;
133
+ if (hasTransformFeedback) {
134
+ this._boundBufferBases[0] = null;
135
+ this._minBaseLocation = 1;
136
+ if (this._nextBindBaseIndex < 1) {
137
+ this._nextBindBaseIndex = 1;
138
+ }
139
+ }
140
+ }
141
+ freeLocationForBufferBase(glBuffer) {
142
+ let freeIndex = this.getLastBindBaseLocation(glBuffer);
143
+ if (freeIndex >= this._minBaseLocation) {
144
+ glBuffer._lastBindCallId = this._bindCallId;
145
+ return freeIndex;
146
+ }
147
+ let loop = 0;
148
+ let nextIndex = this._nextBindBaseIndex;
149
+ while (loop < 2) {
150
+ if (nextIndex >= this._maxBindings) {
151
+ nextIndex = this._minBaseLocation;
152
+ loop++;
153
+ }
154
+ const curBuf = this._boundBufferBases[nextIndex];
155
+ if (curBuf && curBuf._lastBindCallId === this._bindCallId) {
156
+ nextIndex++;
157
+ continue;
158
+ }
159
+ break;
160
+ }
161
+ freeIndex = nextIndex;
162
+ this._nextBindBaseIndex = nextIndex + 1;
163
+ if (loop >= 2) {
164
+ return -1;
165
+ }
166
+ glBuffer._lastBindCallId = this._bindCallId;
167
+ this._boundBufferBases[freeIndex] = null;
168
+ return freeIndex;
169
+ }
170
+ getLastBindBaseLocation(glBuffer) {
171
+ const index = glBuffer._lastBindBaseLocation;
172
+ if (this._boundBufferBases[index] === glBuffer) {
173
+ return index;
174
+ }
175
+ return -1;
176
+ }
177
+ /**
178
+ * Binds a buffer whilst also binding its range.
179
+ * This will make the buffer start from the offset supplied rather than 0 when it is read.
180
+ * @param glBuffer - the buffer to bind
181
+ * @param index - the base index to bind at, defaults to 0
182
+ * @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
183
+ * @param size - the size to bind at (this is blocks of 256).
184
+ */
185
+ bindBufferRange(glBuffer, index, offset, size) {
186
+ const { _gl: gl } = this;
187
+ offset || (offset = 0);
188
+ index || (index = 0);
189
+ this._boundBufferBases[index] = null;
190
+ gl.bindBufferRange(gl.UNIFORM_BUFFER, index || 0, glBuffer.buffer, offset * 256, size || 256);
191
+ }
192
+ /**
193
+ * Will ensure the data in the buffer is uploaded to the GPU.
194
+ * @param {Buffer} buffer - the buffer to update
195
+ */
196
+ updateBuffer(buffer) {
197
+ const { _gl: gl } = this;
198
+ const glBuffer = this.getGlBuffer(buffer);
199
+ if (buffer._updateID === glBuffer.updateID) {
200
+ return glBuffer;
201
+ }
202
+ glBuffer.updateID = buffer._updateID;
203
+ gl.bindBuffer(glBuffer.type, glBuffer.buffer);
204
+ const data = buffer.data;
205
+ const drawType = buffer.descriptor.usage & BufferUsage.STATIC ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW;
206
+ if (data) {
207
+ if (glBuffer.byteLength >= data.byteLength) {
208
+ gl.bufferSubData(glBuffer.type, 0, data, 0, buffer._updateSize / data.BYTES_PER_ELEMENT);
209
+ } else {
210
+ glBuffer.byteLength = data.byteLength;
211
+ gl.bufferData(glBuffer.type, data, drawType);
212
+ }
213
+ } else {
214
+ glBuffer.byteLength = buffer.descriptor.size;
215
+ gl.bufferData(glBuffer.type, glBuffer.byteLength, drawType);
216
+ }
217
+ return glBuffer;
218
+ }
219
+ /** dispose all WebGL resources of all managed buffers */
220
+ destroyAll() {
221
+ const gl = this._gl;
222
+ for (const id in this._gpuBuffers) {
223
+ gl.deleteBuffer(this._gpuBuffers[id].buffer);
224
+ }
225
+ this._gpuBuffers = /* @__PURE__ */ Object.create(null);
226
+ }
227
+ /**
228
+ * Disposes buffer
229
+ * @param {Buffer} buffer - buffer with data
230
+ * @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
231
+ */
232
+ onBufferDestroy(buffer, contextLost) {
233
+ const glBuffer = this._gpuBuffers[buffer.uid];
234
+ const gl = this._gl;
235
+ if (!contextLost) {
236
+ gl.deleteBuffer(glBuffer.buffer);
237
+ }
238
+ this._gpuBuffers[buffer.uid] = null;
239
+ }
240
+ /**
241
+ * creates and attaches a GLBuffer object tied to the current context.
242
+ * @param buffer
243
+ * @protected
244
+ */
245
+ createGLBuffer(buffer) {
246
+ const { _gl: gl } = this;
247
+ let type = BUFFER_TYPE.ARRAY_BUFFER;
248
+ if (buffer.descriptor.usage & BufferUsage.INDEX) {
249
+ type = BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
250
+ } else if (buffer.descriptor.usage & BufferUsage.UNIFORM) {
251
+ type = BUFFER_TYPE.UNIFORM_BUFFER;
252
+ }
253
+ const glBuffer = new GlBuffer(gl.createBuffer(), type);
254
+ this._gpuBuffers[buffer.uid] = glBuffer;
255
+ buffer.on("destroy", this.onBufferDestroy, this);
256
+ return glBuffer;
257
+ }
258
+ resetState() {
259
+ this._boundBufferBases = /* @__PURE__ */ Object.create(null);
260
+ }
261
+ }
262
+ /** @ignore */
263
+ GlBufferSystem.extension = {
264
+ type: [
265
+ ExtensionType.WebGLSystem
266
+ ],
267
+ name: "buffer"
268
+ };
269
+
270
+ const _GlContextSystem = class _GlContextSystem {
271
+ /** @param renderer - The renderer this System works for. */
272
+ constructor(renderer) {
273
+ /**
274
+ * Features supported by current renderer.
275
+ * @type {object}
276
+ * @readonly
277
+ */
278
+ this.supports = {
279
+ /** Support for 32-bit indices buffer. */
280
+ uint32Indices: true,
281
+ /** Support for UniformBufferObjects */
282
+ uniformBufferObject: true,
283
+ /** Support for VertexArrayObjects */
284
+ vertexArrayObject: true,
285
+ /** Support for SRGB texture format */
286
+ srgbTextures: true,
287
+ /** Support for wrapping modes if a texture is non-power of two */
288
+ nonPowOf2wrapping: true,
289
+ /** Support for MSAA (antialiasing of dynamic textures) */
290
+ msaa: true,
291
+ /** Support for mipmaps if a texture is non-power of two */
292
+ nonPowOf2mipmaps: true
293
+ };
294
+ this._renderer = renderer;
295
+ this.extensions = /* @__PURE__ */ Object.create(null);
296
+ this.handleContextLost = this.handleContextLost.bind(this);
297
+ this.handleContextRestored = this.handleContextRestored.bind(this);
298
+ }
299
+ /**
300
+ * `true` if the context is lost
301
+ * @readonly
302
+ */
303
+ get isLost() {
304
+ return !this.gl || this.gl.isContextLost();
305
+ }
306
+ /**
307
+ * Handles the context change event.
308
+ * @param {WebGLRenderingContext} gl - New WebGL context.
309
+ */
310
+ contextChange(gl) {
311
+ this.gl = gl;
312
+ this._renderer.gl = gl;
313
+ }
314
+ init(options) {
315
+ options = { ..._GlContextSystem.defaultOptions, ...options };
316
+ let multiView = this.multiView = options.multiView;
317
+ if (options.context && multiView) {
318
+ warn("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together.");
319
+ multiView = false;
320
+ }
321
+ if (multiView) {
322
+ this.canvas = DOMAdapter.get().createCanvas(this._renderer.canvas.width, this._renderer.canvas.height);
323
+ } else {
324
+ this.canvas = this._renderer.view.canvas;
325
+ }
326
+ if (options.context) {
327
+ this.initFromContext(options.context);
328
+ } else {
329
+ const alpha = this._renderer.background.alpha < 1;
330
+ const premultipliedAlpha = options.premultipliedAlpha ?? true;
331
+ const antialias = options.antialias && !this._renderer.backBuffer.useBackBuffer;
332
+ this.createContext(options.preferWebGLVersion, {
333
+ alpha,
334
+ premultipliedAlpha,
335
+ antialias,
336
+ stencil: true,
337
+ preserveDrawingBuffer: options.preserveDrawingBuffer,
338
+ powerPreference: options.powerPreference ?? "default"
339
+ });
340
+ }
341
+ }
342
+ ensureCanvasSize(targetCanvas) {
343
+ if (!this.multiView) {
344
+ if (targetCanvas !== this.canvas) {
345
+ warn("multiView is disabled, but targetCanvas is not the main canvas");
346
+ }
347
+ return;
348
+ }
349
+ const { canvas } = this;
350
+ if (canvas.width < targetCanvas.width || canvas.height < targetCanvas.height) {
351
+ canvas.width = Math.max(targetCanvas.width, targetCanvas.width);
352
+ canvas.height = Math.max(targetCanvas.height, targetCanvas.height);
353
+ }
354
+ }
355
+ /**
356
+ * Initializes the context.
357
+ * @protected
358
+ * @param {WebGLRenderingContext} gl - WebGL context
359
+ */
360
+ initFromContext(gl) {
361
+ this.gl = gl;
362
+ this.webGLVersion = gl instanceof DOMAdapter.get().getWebGLRenderingContext() ? 1 : 2;
363
+ this.getExtensions();
364
+ this.validateContext(gl);
365
+ this._renderer.runners.contextChange.emit(gl);
366
+ const element = this._renderer.view.canvas;
367
+ element.addEventListener("webglcontextlost", this.handleContextLost, false);
368
+ element.addEventListener("webglcontextrestored", this.handleContextRestored, false);
369
+ }
370
+ /**
371
+ * Initialize from context options
372
+ * @protected
373
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
374
+ * @param preferWebGLVersion
375
+ * @param {object} options - context attributes
376
+ */
377
+ createContext(preferWebGLVersion, options) {
378
+ let gl;
379
+ const canvas = this.canvas;
380
+ if (preferWebGLVersion === 2) {
381
+ gl = canvas.getContext("webgl2", options);
382
+ }
383
+ if (!gl) {
384
+ gl = canvas.getContext("webgl", options);
385
+ if (!gl) {
386
+ throw new Error("This browser does not support WebGL. Try using the canvas renderer");
387
+ }
388
+ }
389
+ this.gl = gl;
390
+ this.initFromContext(this.gl);
391
+ }
392
+ /** Auto-populate the {@link GlContextSystem.extensions extensions}. */
393
+ getExtensions() {
394
+ const { gl } = this;
395
+ const common = {
396
+ anisotropicFiltering: gl.getExtension("EXT_texture_filter_anisotropic"),
397
+ floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
398
+ s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc"),
399
+ s3tc_sRGB: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
400
+ // eslint-disable-line camelcase
401
+ etc: gl.getExtension("WEBGL_compressed_texture_etc"),
402
+ etc1: gl.getExtension("WEBGL_compressed_texture_etc1"),
403
+ pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
404
+ atc: gl.getExtension("WEBGL_compressed_texture_atc"),
405
+ astc: gl.getExtension("WEBGL_compressed_texture_astc"),
406
+ bptc: gl.getExtension("EXT_texture_compression_bptc"),
407
+ rgtc: gl.getExtension("EXT_texture_compression_rgtc"),
408
+ loseContext: gl.getExtension("WEBGL_lose_context")
409
+ };
410
+ if (this.webGLVersion === 1) {
411
+ this.extensions = {
412
+ ...common,
413
+ drawBuffers: gl.getExtension("WEBGL_draw_buffers"),
414
+ depthTexture: gl.getExtension("WEBGL_depth_texture"),
415
+ vertexArrayObject: gl.getExtension("OES_vertex_array_object") || gl.getExtension("MOZ_OES_vertex_array_object") || gl.getExtension("WEBKIT_OES_vertex_array_object"),
416
+ uint32ElementIndex: gl.getExtension("OES_element_index_uint"),
417
+ // Floats and half-floats
418
+ floatTexture: gl.getExtension("OES_texture_float"),
419
+ floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
420
+ textureHalfFloat: gl.getExtension("OES_texture_half_float"),
421
+ textureHalfFloatLinear: gl.getExtension("OES_texture_half_float_linear"),
422
+ vertexAttribDivisorANGLE: gl.getExtension("ANGLE_instanced_arrays"),
423
+ srgb: gl.getExtension("EXT_sRGB")
424
+ };
425
+ } else {
426
+ this.extensions = {
427
+ ...common,
428
+ colorBufferFloat: gl.getExtension("EXT_color_buffer_float")
429
+ };
430
+ const provokeExt = gl.getExtension("WEBGL_provoking_vertex");
431
+ if (provokeExt) {
432
+ provokeExt.provokingVertexWEBGL(provokeExt.FIRST_VERTEX_CONVENTION_WEBGL);
433
+ }
434
+ }
435
+ }
436
+ /**
437
+ * Handles a lost webgl context
438
+ * @param {WebGLContextEvent} event - The context lost event.
439
+ */
440
+ handleContextLost(event) {
441
+ event.preventDefault();
442
+ if (this._contextLossForced) {
443
+ this._contextLossForced = false;
444
+ setTimeout(() => {
445
+ if (this.gl.isContextLost()) {
446
+ this.extensions.loseContext?.restoreContext();
447
+ }
448
+ }, 0);
449
+ }
450
+ }
451
+ /** Handles a restored webgl context. */
452
+ handleContextRestored() {
453
+ this.getExtensions();
454
+ this._renderer.runners.contextChange.emit(this.gl);
455
+ }
456
+ destroy() {
457
+ const element = this._renderer.view.canvas;
458
+ this._renderer = null;
459
+ element.removeEventListener("webglcontextlost", this.handleContextLost);
460
+ element.removeEventListener("webglcontextrestored", this.handleContextRestored);
461
+ this.gl.useProgram(null);
462
+ this.extensions.loseContext?.loseContext();
463
+ }
464
+ /**
465
+ * this function can be called to force a webGL context loss
466
+ * this will release all resources on the GPU.
467
+ * Useful if you need to put Pixi to sleep, and save some GPU memory
468
+ *
469
+ * As soon as render is called - all resources will be created again.
470
+ */
471
+ forceContextLoss() {
472
+ this.extensions.loseContext?.loseContext();
473
+ this._contextLossForced = true;
474
+ }
475
+ /**
476
+ * Validate context.
477
+ * @param {WebGLRenderingContext} gl - Render context.
478
+ */
479
+ validateContext(gl) {
480
+ const attributes = gl.getContextAttributes();
481
+ if (attributes && !attributes.stencil) {
482
+ warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
483
+ }
484
+ const supports = this.supports;
485
+ const isWebGl2 = this.webGLVersion === 2;
486
+ const extensions = this.extensions;
487
+ supports.uint32Indices = isWebGl2 || !!extensions.uint32ElementIndex;
488
+ supports.uniformBufferObject = isWebGl2;
489
+ supports.vertexArrayObject = isWebGl2 || !!extensions.vertexArrayObject;
490
+ supports.srgbTextures = isWebGl2 || !!extensions.srgb;
491
+ supports.nonPowOf2wrapping = isWebGl2;
492
+ supports.nonPowOf2mipmaps = isWebGl2;
493
+ supports.msaa = isWebGl2;
494
+ if (!supports.uint32Indices) {
495
+ warn("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
496
+ }
497
+ }
498
+ };
499
+ /** @ignore */
500
+ _GlContextSystem.extension = {
501
+ type: [
502
+ ExtensionType.WebGLSystem
503
+ ],
504
+ name: "context"
505
+ };
506
+ /** The default options for the system. */
507
+ _GlContextSystem.defaultOptions = {
508
+ /**
509
+ * {@link WebGLOptions.context}
510
+ * @default null
511
+ */
512
+ context: null,
513
+ /**
514
+ * {@link WebGLOptions.premultipliedAlpha}
515
+ * @default true
516
+ */
517
+ premultipliedAlpha: true,
518
+ /**
519
+ * {@link WebGLOptions.preserveDrawingBuffer}
520
+ * @default false
521
+ */
522
+ preserveDrawingBuffer: false,
523
+ /**
524
+ * {@link WebGLOptions.powerPreference}
525
+ * @default default
526
+ */
527
+ powerPreference: void 0,
528
+ /**
529
+ * {@link WebGLOptions.webGLVersion}
530
+ * @default 2
531
+ */
532
+ preferWebGLVersion: 2,
533
+ /**
534
+ * {@link WebGLOptions.multiView}
535
+ * @default false
536
+ */
537
+ multiView: false
538
+ };
539
+ let GlContextSystem = _GlContextSystem;
540
+
541
+ var GL_FORMATS = /* @__PURE__ */ ((GL_FORMATS2) => {
542
+ GL_FORMATS2[GL_FORMATS2["RGBA"] = 6408] = "RGBA";
543
+ GL_FORMATS2[GL_FORMATS2["RGB"] = 6407] = "RGB";
544
+ GL_FORMATS2[GL_FORMATS2["RG"] = 33319] = "RG";
545
+ GL_FORMATS2[GL_FORMATS2["RED"] = 6403] = "RED";
546
+ GL_FORMATS2[GL_FORMATS2["RGBA_INTEGER"] = 36249] = "RGBA_INTEGER";
547
+ GL_FORMATS2[GL_FORMATS2["RGB_INTEGER"] = 36248] = "RGB_INTEGER";
548
+ GL_FORMATS2[GL_FORMATS2["RG_INTEGER"] = 33320] = "RG_INTEGER";
549
+ GL_FORMATS2[GL_FORMATS2["RED_INTEGER"] = 36244] = "RED_INTEGER";
550
+ GL_FORMATS2[GL_FORMATS2["ALPHA"] = 6406] = "ALPHA";
551
+ GL_FORMATS2[GL_FORMATS2["LUMINANCE"] = 6409] = "LUMINANCE";
552
+ GL_FORMATS2[GL_FORMATS2["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
553
+ GL_FORMATS2[GL_FORMATS2["DEPTH_COMPONENT"] = 6402] = "DEPTH_COMPONENT";
554
+ GL_FORMATS2[GL_FORMATS2["DEPTH_STENCIL"] = 34041] = "DEPTH_STENCIL";
555
+ return GL_FORMATS2;
556
+ })(GL_FORMATS || {});
557
+ var GL_TARGETS = /* @__PURE__ */ ((GL_TARGETS2) => {
558
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_2D"] = 3553] = "TEXTURE_2D";
559
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP"] = 34067] = "TEXTURE_CUBE_MAP";
560
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_2D_ARRAY"] = 35866] = "TEXTURE_2D_ARRAY";
561
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_POSITIVE_X"] = 34069] = "TEXTURE_CUBE_MAP_POSITIVE_X";
562
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_NEGATIVE_X"] = 34070] = "TEXTURE_CUBE_MAP_NEGATIVE_X";
563
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_POSITIVE_Y"] = 34071] = "TEXTURE_CUBE_MAP_POSITIVE_Y";
564
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 34072] = "TEXTURE_CUBE_MAP_NEGATIVE_Y";
565
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_POSITIVE_Z"] = 34073] = "TEXTURE_CUBE_MAP_POSITIVE_Z";
566
+ GL_TARGETS2[GL_TARGETS2["TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 34074] = "TEXTURE_CUBE_MAP_NEGATIVE_Z";
567
+ return GL_TARGETS2;
568
+ })(GL_TARGETS || {});
569
+ var GL_TYPES = /* @__PURE__ */ ((GL_TYPES2) => {
570
+ GL_TYPES2[GL_TYPES2["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
571
+ GL_TYPES2[GL_TYPES2["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
572
+ GL_TYPES2[GL_TYPES2["UNSIGNED_SHORT_5_6_5"] = 33635] = "UNSIGNED_SHORT_5_6_5";
573
+ GL_TYPES2[GL_TYPES2["UNSIGNED_SHORT_4_4_4_4"] = 32819] = "UNSIGNED_SHORT_4_4_4_4";
574
+ GL_TYPES2[GL_TYPES2["UNSIGNED_SHORT_5_5_5_1"] = 32820] = "UNSIGNED_SHORT_5_5_5_1";
575
+ GL_TYPES2[GL_TYPES2["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
576
+ GL_TYPES2[GL_TYPES2["UNSIGNED_INT_10F_11F_11F_REV"] = 35899] = "UNSIGNED_INT_10F_11F_11F_REV";
577
+ GL_TYPES2[GL_TYPES2["UNSIGNED_INT_2_10_10_10_REV"] = 33640] = "UNSIGNED_INT_2_10_10_10_REV";
578
+ GL_TYPES2[GL_TYPES2["UNSIGNED_INT_24_8"] = 34042] = "UNSIGNED_INT_24_8";
579
+ GL_TYPES2[GL_TYPES2["UNSIGNED_INT_5_9_9_9_REV"] = 35902] = "UNSIGNED_INT_5_9_9_9_REV";
580
+ GL_TYPES2[GL_TYPES2["BYTE"] = 5120] = "BYTE";
581
+ GL_TYPES2[GL_TYPES2["SHORT"] = 5122] = "SHORT";
582
+ GL_TYPES2[GL_TYPES2["INT"] = 5124] = "INT";
583
+ GL_TYPES2[GL_TYPES2["FLOAT"] = 5126] = "FLOAT";
584
+ GL_TYPES2[GL_TYPES2["FLOAT_32_UNSIGNED_INT_24_8_REV"] = 36269] = "FLOAT_32_UNSIGNED_INT_24_8_REV";
585
+ GL_TYPES2[GL_TYPES2["HALF_FLOAT"] = 36193] = "HALF_FLOAT";
586
+ return GL_TYPES2;
587
+ })(GL_TYPES || {});
588
+
589
+ const infoMap = {
590
+ uint8x2: GL_TYPES.UNSIGNED_BYTE,
591
+ uint8x4: GL_TYPES.UNSIGNED_BYTE,
592
+ sint8x2: GL_TYPES.BYTE,
593
+ sint8x4: GL_TYPES.BYTE,
594
+ unorm8x2: GL_TYPES.UNSIGNED_BYTE,
595
+ unorm8x4: GL_TYPES.UNSIGNED_BYTE,
596
+ snorm8x2: GL_TYPES.BYTE,
597
+ snorm8x4: GL_TYPES.BYTE,
598
+ uint16x2: GL_TYPES.UNSIGNED_SHORT,
599
+ uint16x4: GL_TYPES.UNSIGNED_SHORT,
600
+ sint16x2: GL_TYPES.SHORT,
601
+ sint16x4: GL_TYPES.SHORT,
602
+ unorm16x2: GL_TYPES.UNSIGNED_SHORT,
603
+ unorm16x4: GL_TYPES.UNSIGNED_SHORT,
604
+ snorm16x2: GL_TYPES.SHORT,
605
+ snorm16x4: GL_TYPES.SHORT,
606
+ float16x2: GL_TYPES.HALF_FLOAT,
607
+ float16x4: GL_TYPES.HALF_FLOAT,
608
+ float32: GL_TYPES.FLOAT,
609
+ float32x2: GL_TYPES.FLOAT,
610
+ float32x3: GL_TYPES.FLOAT,
611
+ float32x4: GL_TYPES.FLOAT,
612
+ uint32: GL_TYPES.UNSIGNED_INT,
613
+ uint32x2: GL_TYPES.UNSIGNED_INT,
614
+ uint32x3: GL_TYPES.UNSIGNED_INT,
615
+ uint32x4: GL_TYPES.UNSIGNED_INT,
616
+ sint32: GL_TYPES.INT,
617
+ sint32x2: GL_TYPES.INT,
618
+ sint32x3: GL_TYPES.INT,
619
+ sint32x4: GL_TYPES.INT
620
+ };
621
+ function getGlTypeFromFormat(format) {
622
+ return infoMap[format] ?? infoMap.float32;
623
+ }
624
+
625
+ const topologyToGlMap = {
626
+ "point-list": 0,
627
+ "line-list": 1,
628
+ "line-strip": 3,
629
+ "triangle-list": 4,
630
+ "triangle-strip": 5
631
+ };
632
+ class GlGeometrySystem {
633
+ /** @param renderer - The renderer this System works for. */
634
+ constructor(renderer) {
635
+ this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
636
+ this._renderer = renderer;
637
+ this._activeGeometry = null;
638
+ this._activeVao = null;
639
+ this.hasVao = true;
640
+ this.hasInstance = true;
641
+ this._renderer.renderableGC.addManagedHash(this, "_geometryVaoHash");
642
+ }
643
+ /** Sets up the renderer context and necessary buffers. */
644
+ contextChange() {
645
+ const gl = this.gl = this._renderer.gl;
646
+ if (!this._renderer.context.supports.vertexArrayObject) {
647
+ throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
648
+ }
649
+ const nativeVaoExtension = this._renderer.context.extensions.vertexArrayObject;
650
+ if (nativeVaoExtension) {
651
+ gl.createVertexArray = () => nativeVaoExtension.createVertexArrayOES();
652
+ gl.bindVertexArray = (vao) => nativeVaoExtension.bindVertexArrayOES(vao);
653
+ gl.deleteVertexArray = (vao) => nativeVaoExtension.deleteVertexArrayOES(vao);
654
+ }
655
+ const nativeInstancedExtension = this._renderer.context.extensions.vertexAttribDivisorANGLE;
656
+ if (nativeInstancedExtension) {
657
+ gl.drawArraysInstanced = (a, b, c, d) => {
658
+ nativeInstancedExtension.drawArraysInstancedANGLE(a, b, c, d);
659
+ };
660
+ gl.drawElementsInstanced = (a, b, c, d, e) => {
661
+ nativeInstancedExtension.drawElementsInstancedANGLE(a, b, c, d, e);
662
+ };
663
+ gl.vertexAttribDivisor = (a, b) => nativeInstancedExtension.vertexAttribDivisorANGLE(a, b);
664
+ }
665
+ this._activeGeometry = null;
666
+ this._activeVao = null;
667
+ this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
668
+ }
669
+ /**
670
+ * Binds geometry so that is can be drawn. Creating a Vao if required
671
+ * @param geometry - Instance of geometry to bind.
672
+ * @param program - Instance of program to use vao for.
673
+ */
674
+ bind(geometry, program) {
675
+ const gl = this.gl;
676
+ this._activeGeometry = geometry;
677
+ const vao = this.getVao(geometry, program);
678
+ if (this._activeVao !== vao) {
679
+ this._activeVao = vao;
680
+ gl.bindVertexArray(vao);
681
+ }
682
+ this.updateBuffers();
683
+ }
684
+ /** Reset and unbind any active VAO and geometry. */
685
+ resetState() {
686
+ this.unbind();
687
+ }
688
+ /** Update buffers of the currently bound geometry. */
689
+ updateBuffers() {
690
+ const geometry = this._activeGeometry;
691
+ const bufferSystem = this._renderer.buffer;
692
+ for (let i = 0; i < geometry.buffers.length; i++) {
693
+ const buffer = geometry.buffers[i];
694
+ bufferSystem.updateBuffer(buffer);
695
+ }
696
+ }
697
+ /**
698
+ * Check compatibility between a geometry and a program
699
+ * @param geometry - Geometry instance.
700
+ * @param program - Program instance.
701
+ */
702
+ checkCompatibility(geometry, program) {
703
+ const geometryAttributes = geometry.attributes;
704
+ const shaderAttributes = program._attributeData;
705
+ for (const j in shaderAttributes) {
706
+ if (!geometryAttributes[j]) {
707
+ throw new Error(`shader and geometry incompatible, geometry missing the "${j}" attribute`);
708
+ }
709
+ }
710
+ }
711
+ /**
712
+ * Takes a geometry and program and generates a unique signature for them.
713
+ * @param geometry - To get signature from.
714
+ * @param program - To test geometry against.
715
+ * @returns - Unique signature of the geometry and program
716
+ */
717
+ getSignature(geometry, program) {
718
+ const attribs = geometry.attributes;
719
+ const shaderAttributes = program._attributeData;
720
+ const strings = ["g", geometry.uid];
721
+ for (const i in attribs) {
722
+ if (shaderAttributes[i]) {
723
+ strings.push(i, shaderAttributes[i].location);
724
+ }
725
+ }
726
+ return strings.join("-");
727
+ }
728
+ getVao(geometry, program) {
729
+ return this._geometryVaoHash[geometry.uid]?.[program._key] || this.initGeometryVao(geometry, program);
730
+ }
731
+ /**
732
+ * Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
733
+ * If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
734
+ * attribute locations.
735
+ * @param geometry - Instance of geometry to to generate Vao for.
736
+ * @param program
737
+ * @param _incRefCount - Increment refCount of all geometry buffers.
738
+ */
739
+ initGeometryVao(geometry, program, _incRefCount = true) {
740
+ const gl = this._renderer.gl;
741
+ const bufferSystem = this._renderer.buffer;
742
+ this._renderer.shader._getProgramData(program);
743
+ this.checkCompatibility(geometry, program);
744
+ const signature = this.getSignature(geometry, program);
745
+ if (!this._geometryVaoHash[geometry.uid]) {
746
+ this._geometryVaoHash[geometry.uid] = /* @__PURE__ */ Object.create(null);
747
+ geometry.on("destroy", this.onGeometryDestroy, this);
748
+ }
749
+ const vaoObjectHash = this._geometryVaoHash[geometry.uid];
750
+ let vao = vaoObjectHash[signature];
751
+ if (vao) {
752
+ vaoObjectHash[program._key] = vao;
753
+ return vao;
754
+ }
755
+ ensureAttributes(geometry, program._attributeData);
756
+ const buffers = geometry.buffers;
757
+ vao = gl.createVertexArray();
758
+ gl.bindVertexArray(vao);
759
+ for (let i = 0; i < buffers.length; i++) {
760
+ const buffer = buffers[i];
761
+ bufferSystem.bind(buffer);
762
+ }
763
+ this.activateVao(geometry, program);
764
+ vaoObjectHash[program._key] = vao;
765
+ vaoObjectHash[signature] = vao;
766
+ gl.bindVertexArray(null);
767
+ return vao;
768
+ }
769
+ /**
770
+ * Disposes geometry.
771
+ * @param geometry - Geometry with buffers. Only VAO will be disposed
772
+ * @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
773
+ */
774
+ onGeometryDestroy(geometry, contextLost) {
775
+ const vaoObjectHash = this._geometryVaoHash[geometry.uid];
776
+ const gl = this.gl;
777
+ if (vaoObjectHash) {
778
+ if (contextLost) {
779
+ for (const i in vaoObjectHash) {
780
+ if (this._activeVao !== vaoObjectHash[i]) {
781
+ this.unbind();
782
+ }
783
+ gl.deleteVertexArray(vaoObjectHash[i]);
784
+ }
785
+ }
786
+ this._geometryVaoHash[geometry.uid] = null;
787
+ }
788
+ }
789
+ /**
790
+ * Dispose all WebGL resources of all managed geometries.
791
+ * @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
792
+ */
793
+ destroyAll(contextLost = false) {
794
+ const gl = this.gl;
795
+ for (const i in this._geometryVaoHash) {
796
+ if (contextLost) {
797
+ for (const j in this._geometryVaoHash[i]) {
798
+ const vaoObjectHash = this._geometryVaoHash[i];
799
+ if (this._activeVao !== vaoObjectHash) {
800
+ this.unbind();
801
+ }
802
+ gl.deleteVertexArray(vaoObjectHash[j]);
803
+ }
804
+ }
805
+ this._geometryVaoHash[i] = null;
806
+ }
807
+ }
808
+ /**
809
+ * Activate vertex array object.
810
+ * @param geometry - Geometry instance.
811
+ * @param program - Shader program instance.
812
+ */
813
+ activateVao(geometry, program) {
814
+ const gl = this._renderer.gl;
815
+ const bufferSystem = this._renderer.buffer;
816
+ const attributes = geometry.attributes;
817
+ if (geometry.indexBuffer) {
818
+ bufferSystem.bind(geometry.indexBuffer);
819
+ }
820
+ let lastBuffer = null;
821
+ for (const j in attributes) {
822
+ const attribute = attributes[j];
823
+ const buffer = attribute.buffer;
824
+ const glBuffer = bufferSystem.getGlBuffer(buffer);
825
+ const programAttrib = program._attributeData[j];
826
+ if (programAttrib) {
827
+ if (lastBuffer !== glBuffer) {
828
+ bufferSystem.bind(buffer);
829
+ lastBuffer = glBuffer;
830
+ }
831
+ const location = programAttrib.location;
832
+ gl.enableVertexAttribArray(location);
833
+ const attributeInfo = getAttributeInfoFromFormat(attribute.format);
834
+ const type = getGlTypeFromFormat(attribute.format);
835
+ if (programAttrib.format?.substring(1, 4) === "int") {
836
+ gl.vertexAttribIPointer(
837
+ location,
838
+ attributeInfo.size,
839
+ type,
840
+ attribute.stride,
841
+ attribute.offset
842
+ );
843
+ } else {
844
+ gl.vertexAttribPointer(
845
+ location,
846
+ attributeInfo.size,
847
+ type,
848
+ attributeInfo.normalised,
849
+ attribute.stride,
850
+ attribute.offset
851
+ );
852
+ }
853
+ if (attribute.instance) {
854
+ if (this.hasInstance) {
855
+ const divisor = attribute.divisor ?? 1;
856
+ gl.vertexAttribDivisor(location, divisor);
857
+ } else {
858
+ throw new Error("geometry error, GPU Instancing is not supported on this device");
859
+ }
860
+ }
861
+ }
862
+ }
863
+ }
864
+ /**
865
+ * Draws the currently bound geometry.
866
+ * @param topology - The type primitive to render.
867
+ * @param size - The number of elements to be rendered. If not specified, all vertices after the
868
+ * starting vertex will be drawn.
869
+ * @param start - The starting vertex in the geometry to start drawing from. If not specified,
870
+ * drawing will start from the first vertex.
871
+ * @param instanceCount - The number of instances of the set of elements to execute. If not specified,
872
+ * all instances will be drawn.
873
+ */
874
+ draw(topology, size, start, instanceCount) {
875
+ const { gl } = this._renderer;
876
+ const geometry = this._activeGeometry;
877
+ const glTopology = topologyToGlMap[topology || geometry.topology];
878
+ instanceCount ?? (instanceCount = geometry.instanceCount);
879
+ if (geometry.indexBuffer) {
880
+ const byteSize = geometry.indexBuffer.data.BYTES_PER_ELEMENT;
881
+ const glType = byteSize === 2 ? gl.UNSIGNED_SHORT : gl.UNSIGNED_INT;
882
+ if (instanceCount > 1) {
883
+ gl.drawElementsInstanced(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize, instanceCount);
884
+ } else {
885
+ gl.drawElements(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize);
886
+ }
887
+ } else if (instanceCount > 1) {
888
+ gl.drawArraysInstanced(glTopology, start || 0, size || geometry.getSize(), instanceCount);
889
+ } else {
890
+ gl.drawArrays(glTopology, start || 0, size || geometry.getSize());
891
+ }
892
+ return this;
893
+ }
894
+ /** Unbind/reset everything. */
895
+ unbind() {
896
+ this.gl.bindVertexArray(null);
897
+ this._activeVao = null;
898
+ this._activeGeometry = null;
899
+ }
900
+ destroy() {
901
+ this._renderer = null;
902
+ this.gl = null;
903
+ this._activeVao = null;
904
+ this._activeGeometry = null;
905
+ }
906
+ }
907
+ /** @ignore */
908
+ GlGeometrySystem.extension = {
909
+ type: [
910
+ ExtensionType.WebGLSystem
911
+ ],
912
+ name: "geometry"
913
+ };
914
+
915
+ const bigTriangleGeometry = new Geometry({
916
+ attributes: {
917
+ aPosition: [
918
+ -1,
919
+ -1,
920
+ // Bottom left corner
921
+ 3,
922
+ -1,
923
+ // Bottom right corner, extending beyond right edge
924
+ -1,
925
+ 3
926
+ // Top left corner, extending beyond top edge
927
+ ]
928
+ }
929
+ });
930
+ const _GlBackBufferSystem = class _GlBackBufferSystem {
931
+ constructor(renderer) {
932
+ /** if true, the back buffer is used */
933
+ this.useBackBuffer = false;
934
+ this._useBackBufferThisRender = false;
935
+ this._renderer = renderer;
936
+ }
937
+ init(options = {}) {
938
+ const { useBackBuffer, antialias } = { ..._GlBackBufferSystem.defaultOptions, ...options };
939
+ this.useBackBuffer = useBackBuffer;
940
+ this._antialias = antialias;
941
+ if (!this._renderer.context.supports.msaa) {
942
+ warn("antialiasing, is not supported on when using the back buffer");
943
+ this._antialias = false;
944
+ }
945
+ this._state = State.for2d();
946
+ const bigTriangleProgram = new GlProgram({
947
+ vertex: `
948
+ attribute vec2 aPosition;
949
+ out vec2 vUv;
950
+
951
+ void main() {
952
+ gl_Position = vec4(aPosition, 0.0, 1.0);
953
+
954
+ vUv = (aPosition + 1.0) / 2.0;
955
+
956
+ // flip dem UVs
957
+ vUv.y = 1.0 - vUv.y;
958
+ }`,
959
+ fragment: `
960
+ in vec2 vUv;
961
+ out vec4 finalColor;
962
+
963
+ uniform sampler2D uTexture;
964
+
965
+ void main() {
966
+ finalColor = texture(uTexture, vUv);
967
+ }`,
968
+ name: "big-triangle"
969
+ });
970
+ this._bigTriangleShader = new Shader({
971
+ glProgram: bigTriangleProgram,
972
+ resources: {
973
+ uTexture: Texture.WHITE.source
974
+ }
975
+ });
976
+ }
977
+ /**
978
+ * This is called before the RenderTargetSystem is started. This is where
979
+ * we replace the target with the back buffer if required.
980
+ * @param options - The options for this render.
981
+ */
982
+ renderStart(options) {
983
+ const renderTarget = this._renderer.renderTarget.getRenderTarget(options.target);
984
+ this._useBackBufferThisRender = this.useBackBuffer && !!renderTarget.isRoot;
985
+ if (this._useBackBufferThisRender) {
986
+ const renderTarget2 = this._renderer.renderTarget.getRenderTarget(options.target);
987
+ this._targetTexture = renderTarget2.colorTexture;
988
+ options.target = this._getBackBufferTexture(renderTarget2.colorTexture);
989
+ }
990
+ }
991
+ renderEnd() {
992
+ this._presentBackBuffer();
993
+ }
994
+ _presentBackBuffer() {
995
+ const renderer = this._renderer;
996
+ renderer.renderTarget.finishRenderPass();
997
+ if (!this._useBackBufferThisRender)
998
+ return;
999
+ renderer.renderTarget.bind(this._targetTexture, false);
1000
+ this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source;
1001
+ renderer.encoder.draw({
1002
+ geometry: bigTriangleGeometry,
1003
+ shader: this._bigTriangleShader,
1004
+ state: this._state
1005
+ });
1006
+ }
1007
+ _getBackBufferTexture(targetSourceTexture) {
1008
+ this._backBufferTexture = this._backBufferTexture || new Texture({
1009
+ source: new TextureSource({
1010
+ width: targetSourceTexture.width,
1011
+ height: targetSourceTexture.height,
1012
+ resolution: targetSourceTexture._resolution,
1013
+ antialias: this._antialias
1014
+ })
1015
+ });
1016
+ this._backBufferTexture.source.resize(
1017
+ targetSourceTexture.width,
1018
+ targetSourceTexture.height,
1019
+ targetSourceTexture._resolution
1020
+ );
1021
+ return this._backBufferTexture;
1022
+ }
1023
+ /** destroys the back buffer */
1024
+ destroy() {
1025
+ if (this._backBufferTexture) {
1026
+ this._backBufferTexture.destroy();
1027
+ this._backBufferTexture = null;
1028
+ }
1029
+ }
1030
+ };
1031
+ /** @ignore */
1032
+ _GlBackBufferSystem.extension = {
1033
+ type: [
1034
+ ExtensionType.WebGLSystem
1035
+ ],
1036
+ name: "backBuffer",
1037
+ priority: 1
1038
+ };
1039
+ /** default options for the back buffer system */
1040
+ _GlBackBufferSystem.defaultOptions = {
1041
+ /** if true will use the back buffer where required */
1042
+ useBackBuffer: false
1043
+ };
1044
+ let GlBackBufferSystem = _GlBackBufferSystem;
1045
+
1046
+ class GlColorMaskSystem {
1047
+ constructor(renderer) {
1048
+ this._colorMaskCache = 15;
1049
+ this._renderer = renderer;
1050
+ }
1051
+ setMask(colorMask) {
1052
+ if (this._colorMaskCache === colorMask)
1053
+ return;
1054
+ this._colorMaskCache = colorMask;
1055
+ this._renderer.gl.colorMask(
1056
+ !!(colorMask & 8),
1057
+ !!(colorMask & 4),
1058
+ !!(colorMask & 2),
1059
+ !!(colorMask & 1)
1060
+ );
1061
+ }
1062
+ }
1063
+ /** @ignore */
1064
+ GlColorMaskSystem.extension = {
1065
+ type: [
1066
+ ExtensionType.WebGLSystem
1067
+ ],
1068
+ name: "colorMask"
1069
+ };
1070
+
1071
+ class GlEncoderSystem {
1072
+ constructor(renderer) {
1073
+ this.commandFinished = Promise.resolve();
1074
+ this._renderer = renderer;
1075
+ }
1076
+ setGeometry(geometry, shader) {
1077
+ this._renderer.geometry.bind(geometry, shader.glProgram);
1078
+ }
1079
+ finishRenderPass() {
1080
+ }
1081
+ draw(options) {
1082
+ const renderer = this._renderer;
1083
+ const { geometry, shader, state, skipSync, topology: type, size, start, instanceCount } = options;
1084
+ renderer.shader.bind(shader, skipSync);
1085
+ renderer.geometry.bind(geometry, renderer.shader._activeProgram);
1086
+ if (state) {
1087
+ renderer.state.set(state);
1088
+ }
1089
+ renderer.geometry.draw(type, size, start, instanceCount ?? geometry.instanceCount);
1090
+ }
1091
+ destroy() {
1092
+ this._renderer = null;
1093
+ }
1094
+ }
1095
+ /** @ignore */
1096
+ GlEncoderSystem.extension = {
1097
+ type: [
1098
+ ExtensionType.WebGLSystem
1099
+ ],
1100
+ name: "encoder"
1101
+ };
1102
+
1103
+ class GlRenderTarget {
1104
+ constructor() {
1105
+ this.width = -1;
1106
+ this.height = -1;
1107
+ this.msaa = false;
1108
+ this.msaaRenderBuffer = [];
1109
+ }
1110
+ }
1111
+
1112
+ class GlStencilSystem {
1113
+ constructor(renderer) {
1114
+ this._stencilCache = {
1115
+ enabled: false,
1116
+ stencilReference: 0,
1117
+ stencilMode: STENCIL_MODES.NONE
1118
+ };
1119
+ this._renderTargetStencilState = /* @__PURE__ */ Object.create(null);
1120
+ renderer.renderTarget.onRenderTargetChange.add(this);
1121
+ }
1122
+ contextChange(gl) {
1123
+ this._gl = gl;
1124
+ this._comparisonFuncMapping = {
1125
+ always: gl.ALWAYS,
1126
+ never: gl.NEVER,
1127
+ equal: gl.EQUAL,
1128
+ "not-equal": gl.NOTEQUAL,
1129
+ less: gl.LESS,
1130
+ "less-equal": gl.LEQUAL,
1131
+ greater: gl.GREATER,
1132
+ "greater-equal": gl.GEQUAL
1133
+ };
1134
+ this._stencilOpsMapping = {
1135
+ keep: gl.KEEP,
1136
+ zero: gl.ZERO,
1137
+ replace: gl.REPLACE,
1138
+ invert: gl.INVERT,
1139
+ "increment-clamp": gl.INCR,
1140
+ "decrement-clamp": gl.DECR,
1141
+ "increment-wrap": gl.INCR_WRAP,
1142
+ "decrement-wrap": gl.DECR_WRAP
1143
+ };
1144
+ this.resetState();
1145
+ }
1146
+ onRenderTargetChange(renderTarget) {
1147
+ if (this._activeRenderTarget === renderTarget)
1148
+ return;
1149
+ this._activeRenderTarget = renderTarget;
1150
+ let stencilState = this._renderTargetStencilState[renderTarget.uid];
1151
+ if (!stencilState) {
1152
+ stencilState = this._renderTargetStencilState[renderTarget.uid] = {
1153
+ stencilMode: STENCIL_MODES.DISABLED,
1154
+ stencilReference: 0
1155
+ };
1156
+ }
1157
+ this.setStencilMode(stencilState.stencilMode, stencilState.stencilReference);
1158
+ }
1159
+ resetState() {
1160
+ this._stencilCache.enabled = false;
1161
+ this._stencilCache.stencilMode = STENCIL_MODES.NONE;
1162
+ this._stencilCache.stencilReference = 0;
1163
+ }
1164
+ setStencilMode(stencilMode, stencilReference) {
1165
+ const stencilState = this._renderTargetStencilState[this._activeRenderTarget.uid];
1166
+ const gl = this._gl;
1167
+ const mode = GpuStencilModesToPixi[stencilMode];
1168
+ const _stencilCache = this._stencilCache;
1169
+ stencilState.stencilMode = stencilMode;
1170
+ stencilState.stencilReference = stencilReference;
1171
+ if (stencilMode === STENCIL_MODES.DISABLED) {
1172
+ if (this._stencilCache.enabled) {
1173
+ this._stencilCache.enabled = false;
1174
+ gl.disable(gl.STENCIL_TEST);
1175
+ }
1176
+ return;
1177
+ }
1178
+ if (!this._stencilCache.enabled) {
1179
+ this._stencilCache.enabled = true;
1180
+ gl.enable(gl.STENCIL_TEST);
1181
+ }
1182
+ if (stencilMode !== _stencilCache.stencilMode || _stencilCache.stencilReference !== stencilReference) {
1183
+ _stencilCache.stencilMode = stencilMode;
1184
+ _stencilCache.stencilReference = stencilReference;
1185
+ gl.stencilFunc(this._comparisonFuncMapping[mode.stencilBack.compare], stencilReference, 255);
1186
+ gl.stencilOp(gl.KEEP, gl.KEEP, this._stencilOpsMapping[mode.stencilBack.passOp]);
1187
+ }
1188
+ }
1189
+ }
1190
+ /** @ignore */
1191
+ GlStencilSystem.extension = {
1192
+ type: [
1193
+ ExtensionType.WebGLSystem
1194
+ ],
1195
+ name: "stencil"
1196
+ };
1197
+
1198
+ const WGSL_TO_STD40_SIZE = {
1199
+ f32: 4,
1200
+ i32: 4,
1201
+ "vec2<f32>": 8,
1202
+ "vec3<f32>": 12,
1203
+ "vec4<f32>": 16,
1204
+ "vec2<i32>": 8,
1205
+ "vec3<i32>": 12,
1206
+ "vec4<i32>": 16,
1207
+ "mat2x2<f32>": 16 * 2,
1208
+ "mat3x3<f32>": 16 * 3,
1209
+ "mat4x4<f32>": 16 * 4
1210
+ // TODO - not essential for now but support these in the future
1211
+ // int: 4,
1212
+ // ivec2: 8,
1213
+ // ivec3: 12,
1214
+ // ivec4: 16,
1215
+ // uint: 4,
1216
+ // uvec2: 8,
1217
+ // uvec3: 12,
1218
+ // uvec4: 16,
1219
+ // bool: 4,
1220
+ // bvec2: 8,
1221
+ // bvec3: 12,
1222
+ // bvec4: 16,
1223
+ // mat2: 16 * 2,
1224
+ // mat3: 16 * 3,
1225
+ // mat4: 16 * 4,
1226
+ };
1227
+ function createUboElementsSTD40(uniformData) {
1228
+ const uboElements = uniformData.map((data) => ({
1229
+ data,
1230
+ offset: 0,
1231
+ size: 0
1232
+ }));
1233
+ const chunkSize = 16;
1234
+ let size = 0;
1235
+ let offset = 0;
1236
+ for (let i = 0; i < uboElements.length; i++) {
1237
+ const uboElement = uboElements[i];
1238
+ size = WGSL_TO_STD40_SIZE[uboElement.data.type];
1239
+ if (!size) {
1240
+ throw new Error(`Unknown type ${uboElement.data.type}`);
1241
+ }
1242
+ if (uboElement.data.size > 1) {
1243
+ size = Math.max(size, chunkSize) * uboElement.data.size;
1244
+ }
1245
+ const boundary = size === 12 ? 16 : size;
1246
+ uboElement.size = size;
1247
+ const curOffset = offset % chunkSize;
1248
+ if (curOffset > 0 && chunkSize - curOffset < boundary) {
1249
+ offset += (chunkSize - curOffset) % 16;
1250
+ } else {
1251
+ offset += (size - curOffset % size) % size;
1252
+ }
1253
+ uboElement.offset = offset;
1254
+ offset += size;
1255
+ }
1256
+ offset = Math.ceil(offset / 16) * 16;
1257
+ return { uboElements, size: offset };
1258
+ }
1259
+
1260
+ function generateArraySyncSTD40(uboElement, offsetToAdd) {
1261
+ const rowSize = Math.max(WGSL_TO_STD40_SIZE[uboElement.data.type] / 16, 1);
1262
+ const elementSize = uboElement.data.value.length / uboElement.data.size;
1263
+ const remainder = (4 - elementSize % 4) % 4;
1264
+ const data = uboElement.data.type.indexOf("i32") >= 0 ? "dataInt32" : "data";
1265
+ return `
1266
+ v = uv.${uboElement.data.name};
1267
+ offset += ${offsetToAdd};
1268
+
1269
+ arrayOffset = offset;
1270
+
1271
+ t = 0;
1272
+
1273
+ for(var i=0; i < ${uboElement.data.size * rowSize}; i++)
1274
+ {
1275
+ for(var j = 0; j < ${elementSize}; j++)
1276
+ {
1277
+ ${data}[arrayOffset++] = v[t++];
1278
+ }
1279
+ ${remainder !== 0 ? `arrayOffset += ${remainder};` : ""}
1280
+ }
1281
+ `;
1282
+ }
1283
+
1284
+ function createUboSyncFunctionSTD40(uboElements) {
1285
+ return createUboSyncFunction(
1286
+ uboElements,
1287
+ "uboStd40",
1288
+ generateArraySyncSTD40,
1289
+ uboSyncFunctionsSTD40
1290
+ );
1291
+ }
1292
+
1293
+ class GlUboSystem extends UboSystem {
1294
+ constructor() {
1295
+ super({
1296
+ createUboElements: createUboElementsSTD40,
1297
+ generateUboSync: createUboSyncFunctionSTD40
1298
+ });
1299
+ }
1300
+ }
1301
+ /** @ignore */
1302
+ GlUboSystem.extension = {
1303
+ type: [ExtensionType.WebGLSystem],
1304
+ name: "ubo"
1305
+ };
1306
+
1307
+ class GlRenderTargetAdaptor {
1308
+ constructor() {
1309
+ this._clearColorCache = [0, 0, 0, 0];
1310
+ this._viewPortCache = new Rectangle();
1311
+ }
1312
+ init(renderer, renderTargetSystem) {
1313
+ this._renderer = renderer;
1314
+ this._renderTargetSystem = renderTargetSystem;
1315
+ renderer.runners.contextChange.add(this);
1316
+ }
1317
+ contextChange() {
1318
+ this._clearColorCache = [0, 0, 0, 0];
1319
+ this._viewPortCache = new Rectangle();
1320
+ }
1321
+ copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
1322
+ const renderTargetSystem = this._renderTargetSystem;
1323
+ const renderer = this._renderer;
1324
+ const glRenderTarget = renderTargetSystem.getGpuRenderTarget(sourceRenderSurfaceTexture);
1325
+ const gl = renderer.gl;
1326
+ this.finishRenderPass(sourceRenderSurfaceTexture);
1327
+ gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
1328
+ renderer.texture.bind(destinationTexture, 0);
1329
+ gl.copyTexSubImage2D(
1330
+ gl.TEXTURE_2D,
1331
+ 0,
1332
+ originDest.x,
1333
+ originDest.y,
1334
+ originSrc.x,
1335
+ originSrc.y,
1336
+ size.width,
1337
+ size.height
1338
+ );
1339
+ return destinationTexture;
1340
+ }
1341
+ startRenderPass(renderTarget, clear = true, clearColor, viewport) {
1342
+ const renderTargetSystem = this._renderTargetSystem;
1343
+ const source = renderTarget.colorTexture;
1344
+ const gpuRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
1345
+ let viewPortY = viewport.y;
1346
+ if (renderTarget.isRoot) {
1347
+ viewPortY = source.pixelHeight - viewport.height;
1348
+ }
1349
+ renderTarget.colorTextures.forEach((texture) => {
1350
+ this._renderer.texture.unbind(texture);
1351
+ });
1352
+ const gl = this._renderer.gl;
1353
+ gl.bindFramebuffer(gl.FRAMEBUFFER, gpuRenderTarget.framebuffer);
1354
+ const viewPortCache = this._viewPortCache;
1355
+ if (viewPortCache.x !== viewport.x || viewPortCache.y !== viewPortY || viewPortCache.width !== viewport.width || viewPortCache.height !== viewport.height) {
1356
+ viewPortCache.x = viewport.x;
1357
+ viewPortCache.y = viewPortY;
1358
+ viewPortCache.width = viewport.width;
1359
+ viewPortCache.height = viewport.height;
1360
+ gl.viewport(
1361
+ viewport.x,
1362
+ viewPortY,
1363
+ viewport.width,
1364
+ viewport.height
1365
+ );
1366
+ }
1367
+ if (!gpuRenderTarget.depthStencilRenderBuffer && (renderTarget.stencil || renderTarget.depth)) {
1368
+ this._initStencil(gpuRenderTarget);
1369
+ }
1370
+ this.clear(renderTarget, clear, clearColor);
1371
+ }
1372
+ finishRenderPass(renderTarget) {
1373
+ const renderTargetSystem = this._renderTargetSystem;
1374
+ const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
1375
+ if (!glRenderTarget.msaa)
1376
+ return;
1377
+ const gl = this._renderer.gl;
1378
+ gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
1379
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, glRenderTarget.framebuffer);
1380
+ gl.blitFramebuffer(
1381
+ 0,
1382
+ 0,
1383
+ glRenderTarget.width,
1384
+ glRenderTarget.height,
1385
+ 0,
1386
+ 0,
1387
+ glRenderTarget.width,
1388
+ glRenderTarget.height,
1389
+ gl.COLOR_BUFFER_BIT,
1390
+ gl.NEAREST
1391
+ );
1392
+ gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.framebuffer);
1393
+ }
1394
+ initGpuRenderTarget(renderTarget) {
1395
+ const renderer = this._renderer;
1396
+ const gl = renderer.gl;
1397
+ const glRenderTarget = new GlRenderTarget();
1398
+ const colorTexture = renderTarget.colorTexture;
1399
+ if (CanvasSource.test(colorTexture.resource)) {
1400
+ this._renderer.context.ensureCanvasSize(renderTarget.colorTexture.resource);
1401
+ glRenderTarget.framebuffer = null;
1402
+ return glRenderTarget;
1403
+ }
1404
+ this._initColor(renderTarget, glRenderTarget);
1405
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1406
+ return glRenderTarget;
1407
+ }
1408
+ destroyGpuRenderTarget(gpuRenderTarget) {
1409
+ const gl = this._renderer.gl;
1410
+ if (gpuRenderTarget.framebuffer) {
1411
+ gl.deleteFramebuffer(gpuRenderTarget.framebuffer);
1412
+ gpuRenderTarget.framebuffer = null;
1413
+ }
1414
+ if (gpuRenderTarget.resolveTargetFramebuffer) {
1415
+ gl.deleteFramebuffer(gpuRenderTarget.resolveTargetFramebuffer);
1416
+ gpuRenderTarget.resolveTargetFramebuffer = null;
1417
+ }
1418
+ if (gpuRenderTarget.depthStencilRenderBuffer) {
1419
+ gl.deleteRenderbuffer(gpuRenderTarget.depthStencilRenderBuffer);
1420
+ gpuRenderTarget.depthStencilRenderBuffer = null;
1421
+ }
1422
+ gpuRenderTarget.msaaRenderBuffer.forEach((renderBuffer) => {
1423
+ gl.deleteRenderbuffer(renderBuffer);
1424
+ });
1425
+ gpuRenderTarget.msaaRenderBuffer = null;
1426
+ }
1427
+ clear(_renderTarget, clear, clearColor) {
1428
+ if (!clear)
1429
+ return;
1430
+ const renderTargetSystem = this._renderTargetSystem;
1431
+ if (typeof clear === "boolean") {
1432
+ clear = clear ? CLEAR.ALL : CLEAR.NONE;
1433
+ }
1434
+ const gl = this._renderer.gl;
1435
+ if (clear & CLEAR.COLOR) {
1436
+ clearColor ?? (clearColor = renderTargetSystem.defaultClearColor);
1437
+ const clearColorCache = this._clearColorCache;
1438
+ const clearColorArray = clearColor;
1439
+ if (clearColorCache[0] !== clearColorArray[0] || clearColorCache[1] !== clearColorArray[1] || clearColorCache[2] !== clearColorArray[2] || clearColorCache[3] !== clearColorArray[3]) {
1440
+ clearColorCache[0] = clearColorArray[0];
1441
+ clearColorCache[1] = clearColorArray[1];
1442
+ clearColorCache[2] = clearColorArray[2];
1443
+ clearColorCache[3] = clearColorArray[3];
1444
+ gl.clearColor(clearColorArray[0], clearColorArray[1], clearColorArray[2], clearColorArray[3]);
1445
+ }
1446
+ }
1447
+ gl.clear(clear);
1448
+ }
1449
+ resizeGpuRenderTarget(renderTarget) {
1450
+ if (renderTarget.isRoot)
1451
+ return;
1452
+ const renderTargetSystem = this._renderTargetSystem;
1453
+ const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
1454
+ this._resizeColor(renderTarget, glRenderTarget);
1455
+ if (renderTarget.stencil || renderTarget.depth) {
1456
+ this._resizeStencil(glRenderTarget);
1457
+ }
1458
+ }
1459
+ _initColor(renderTarget, glRenderTarget) {
1460
+ const renderer = this._renderer;
1461
+ const gl = renderer.gl;
1462
+ const resolveTargetFramebuffer = gl.createFramebuffer();
1463
+ glRenderTarget.resolveTargetFramebuffer = resolveTargetFramebuffer;
1464
+ gl.bindFramebuffer(gl.FRAMEBUFFER, resolveTargetFramebuffer);
1465
+ glRenderTarget.width = renderTarget.colorTexture.source.pixelWidth;
1466
+ glRenderTarget.height = renderTarget.colorTexture.source.pixelHeight;
1467
+ renderTarget.colorTextures.forEach((colorTexture, i) => {
1468
+ const source = colorTexture.source;
1469
+ if (source.antialias) {
1470
+ if (renderer.context.supports.msaa) {
1471
+ glRenderTarget.msaa = true;
1472
+ } else {
1473
+ warn("[RenderTexture] Antialiasing on textures is not supported in WebGL1");
1474
+ }
1475
+ }
1476
+ renderer.texture.bindSource(source, 0);
1477
+ const glSource = renderer.texture.getGlSource(source);
1478
+ const glTexture = glSource.texture;
1479
+ gl.framebufferTexture2D(
1480
+ gl.FRAMEBUFFER,
1481
+ gl.COLOR_ATTACHMENT0 + i,
1482
+ 3553,
1483
+ // texture.target,
1484
+ glTexture,
1485
+ 0
1486
+ );
1487
+ });
1488
+ if (glRenderTarget.msaa) {
1489
+ const viewFramebuffer = gl.createFramebuffer();
1490
+ glRenderTarget.framebuffer = viewFramebuffer;
1491
+ gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
1492
+ renderTarget.colorTextures.forEach((_, i) => {
1493
+ const msaaRenderBuffer = gl.createRenderbuffer();
1494
+ glRenderTarget.msaaRenderBuffer[i] = msaaRenderBuffer;
1495
+ });
1496
+ } else {
1497
+ glRenderTarget.framebuffer = resolveTargetFramebuffer;
1498
+ }
1499
+ this._resizeColor(renderTarget, glRenderTarget);
1500
+ }
1501
+ _resizeColor(renderTarget, glRenderTarget) {
1502
+ const source = renderTarget.colorTexture.source;
1503
+ glRenderTarget.width = source.pixelWidth;
1504
+ glRenderTarget.height = source.pixelHeight;
1505
+ renderTarget.colorTextures.forEach((colorTexture, i) => {
1506
+ if (i === 0)
1507
+ return;
1508
+ colorTexture.source.resize(source.width, source.height, source._resolution);
1509
+ });
1510
+ if (glRenderTarget.msaa) {
1511
+ const renderer = this._renderer;
1512
+ const gl = renderer.gl;
1513
+ const viewFramebuffer = glRenderTarget.framebuffer;
1514
+ gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
1515
+ renderTarget.colorTextures.forEach((colorTexture, i) => {
1516
+ const source2 = colorTexture.source;
1517
+ renderer.texture.bindSource(source2, 0);
1518
+ const glSource = renderer.texture.getGlSource(source2);
1519
+ const glInternalFormat = glSource.internalFormat;
1520
+ const msaaRenderBuffer = glRenderTarget.msaaRenderBuffer[i];
1521
+ gl.bindRenderbuffer(
1522
+ gl.RENDERBUFFER,
1523
+ msaaRenderBuffer
1524
+ );
1525
+ gl.renderbufferStorageMultisample(
1526
+ gl.RENDERBUFFER,
1527
+ 4,
1528
+ glInternalFormat,
1529
+ source2.pixelWidth,
1530
+ source2.pixelHeight
1531
+ );
1532
+ gl.framebufferRenderbuffer(
1533
+ gl.FRAMEBUFFER,
1534
+ gl.COLOR_ATTACHMENT0 + i,
1535
+ gl.RENDERBUFFER,
1536
+ msaaRenderBuffer
1537
+ );
1538
+ });
1539
+ }
1540
+ }
1541
+ _initStencil(glRenderTarget) {
1542
+ if (glRenderTarget.framebuffer === null)
1543
+ return;
1544
+ const gl = this._renderer.gl;
1545
+ const depthStencilRenderBuffer = gl.createRenderbuffer();
1546
+ glRenderTarget.depthStencilRenderBuffer = depthStencilRenderBuffer;
1547
+ gl.bindRenderbuffer(
1548
+ gl.RENDERBUFFER,
1549
+ depthStencilRenderBuffer
1550
+ );
1551
+ gl.framebufferRenderbuffer(
1552
+ gl.FRAMEBUFFER,
1553
+ gl.DEPTH_STENCIL_ATTACHMENT,
1554
+ gl.RENDERBUFFER,
1555
+ depthStencilRenderBuffer
1556
+ );
1557
+ this._resizeStencil(glRenderTarget);
1558
+ }
1559
+ _resizeStencil(glRenderTarget) {
1560
+ const gl = this._renderer.gl;
1561
+ gl.bindRenderbuffer(
1562
+ gl.RENDERBUFFER,
1563
+ glRenderTarget.depthStencilRenderBuffer
1564
+ );
1565
+ if (glRenderTarget.msaa) {
1566
+ gl.renderbufferStorageMultisample(
1567
+ gl.RENDERBUFFER,
1568
+ 4,
1569
+ gl.DEPTH24_STENCIL8,
1570
+ glRenderTarget.width,
1571
+ glRenderTarget.height
1572
+ );
1573
+ } else {
1574
+ gl.renderbufferStorage(
1575
+ gl.RENDERBUFFER,
1576
+ this._renderer.context.webGLVersion === 2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
1577
+ glRenderTarget.width,
1578
+ glRenderTarget.height
1579
+ );
1580
+ }
1581
+ }
1582
+ prerender(renderTarget) {
1583
+ const resource = renderTarget.colorTexture.resource;
1584
+ if (this._renderer.context.multiView && CanvasSource.test(resource)) {
1585
+ this._renderer.context.ensureCanvasSize(resource);
1586
+ }
1587
+ }
1588
+ postrender(renderTarget) {
1589
+ if (!this._renderer.context.multiView)
1590
+ return;
1591
+ if (CanvasSource.test(renderTarget.colorTexture.resource)) {
1592
+ const contextCanvas = this._renderer.context.canvas;
1593
+ const canvasSource = renderTarget.colorTexture;
1594
+ canvasSource.context2D.drawImage(
1595
+ contextCanvas,
1596
+ 0,
1597
+ canvasSource.pixelHeight - contextCanvas.height
1598
+ );
1599
+ }
1600
+ }
1601
+ }
1602
+
1603
+ class GlRenderTargetSystem extends RenderTargetSystem {
1604
+ constructor(renderer) {
1605
+ super(renderer);
1606
+ this.adaptor = new GlRenderTargetAdaptor();
1607
+ this.adaptor.init(renderer, this);
1608
+ }
1609
+ }
1610
+ /** @ignore */
1611
+ GlRenderTargetSystem.extension = {
1612
+ type: [ExtensionType.WebGLSystem],
1613
+ name: "renderTarget"
1614
+ };
1615
+
1616
+ function generateShaderSyncCode(shader, shaderSystem) {
1617
+ const funcFragments = [];
1618
+ const headerFragments = [`
1619
+ var g = s.groups;
1620
+ var sS = r.shader;
1621
+ var p = s.glProgram;
1622
+ var ugS = r.uniformGroup;
1623
+ var resources;
1624
+ `];
1625
+ let addedTextreSystem = false;
1626
+ let textureCount = 0;
1627
+ const programData = shaderSystem._getProgramData(shader.glProgram);
1628
+ for (const i in shader.groups) {
1629
+ const group = shader.groups[i];
1630
+ funcFragments.push(`
1631
+ resources = g[${i}].resources;
1632
+ `);
1633
+ for (const j in group.resources) {
1634
+ const resource = group.resources[j];
1635
+ if (resource instanceof UniformGroup) {
1636
+ if (resource.ubo) {
1637
+ const resName = shader._uniformBindMap[i][Number(j)];
1638
+ funcFragments.push(`
1639
+ sS.bindUniformBlock(
1640
+ resources[${j}],
1641
+ '${resName}',
1642
+ ${shader.glProgram._uniformBlockData[resName].index}
1643
+ );
1644
+ `);
1645
+ } else {
1646
+ funcFragments.push(`
1647
+ ugS.updateUniformGroup(resources[${j}], p, sD);
1648
+ `);
1649
+ }
1650
+ } else if (resource instanceof BufferResource) {
1651
+ const resName = shader._uniformBindMap[i][Number(j)];
1652
+ funcFragments.push(`
1653
+ sS.bindUniformBlock(
1654
+ resources[${j}],
1655
+ '${resName}',
1656
+ ${shader.glProgram._uniformBlockData[resName].index}
1657
+ );
1658
+ `);
1659
+ } else if (resource instanceof TextureSource) {
1660
+ const uniformName = shader._uniformBindMap[i][j];
1661
+ const uniformData = programData.uniformData[uniformName];
1662
+ if (uniformData) {
1663
+ if (!addedTextreSystem) {
1664
+ addedTextreSystem = true;
1665
+ headerFragments.push(`
1666
+ var tS = r.texture;
1667
+ `);
1668
+ }
1669
+ shaderSystem._gl.uniform1i(uniformData.location, textureCount);
1670
+ funcFragments.push(`
1671
+ tS.bind(resources[${j}], ${textureCount});
1672
+ `);
1673
+ textureCount++;
1674
+ }
1675
+ }
1676
+ }
1677
+ }
1678
+ const functionSource = [...headerFragments, ...funcFragments].join("\n");
1679
+ return new Function("r", "s", "sD", functionSource);
1680
+ }
1681
+
1682
+ class GlProgramData {
1683
+ /**
1684
+ * Makes a new Pixi program.
1685
+ * @param program - webgl program
1686
+ * @param uniformData - uniforms
1687
+ */
1688
+ constructor(program, uniformData) {
1689
+ this.program = program;
1690
+ this.uniformData = uniformData;
1691
+ this.uniformGroups = {};
1692
+ this.uniformDirtyGroups = {};
1693
+ this.uniformBlockBindings = {};
1694
+ }
1695
+ /** Destroys this program. */
1696
+ destroy() {
1697
+ this.uniformData = null;
1698
+ this.uniformGroups = null;
1699
+ this.uniformDirtyGroups = null;
1700
+ this.uniformBlockBindings = null;
1701
+ this.program = null;
1702
+ }
1703
+ }
1704
+
1705
+ function compileShader(gl, type, src) {
1706
+ const shader = gl.createShader(type);
1707
+ gl.shaderSource(shader, src);
1708
+ gl.compileShader(shader);
1709
+ return shader;
1710
+ }
1711
+
1712
+ function booleanArray(size) {
1713
+ const array = new Array(size);
1714
+ for (let i = 0; i < array.length; i++) {
1715
+ array[i] = false;
1716
+ }
1717
+ return array;
1718
+ }
1719
+ function defaultValue(type, size) {
1720
+ switch (type) {
1721
+ case "float":
1722
+ return 0;
1723
+ case "vec2":
1724
+ return new Float32Array(2 * size);
1725
+ case "vec3":
1726
+ return new Float32Array(3 * size);
1727
+ case "vec4":
1728
+ return new Float32Array(4 * size);
1729
+ case "int":
1730
+ case "uint":
1731
+ case "sampler2D":
1732
+ case "sampler2DArray":
1733
+ return 0;
1734
+ case "ivec2":
1735
+ return new Int32Array(2 * size);
1736
+ case "ivec3":
1737
+ return new Int32Array(3 * size);
1738
+ case "ivec4":
1739
+ return new Int32Array(4 * size);
1740
+ case "uvec2":
1741
+ return new Uint32Array(2 * size);
1742
+ case "uvec3":
1743
+ return new Uint32Array(3 * size);
1744
+ case "uvec4":
1745
+ return new Uint32Array(4 * size);
1746
+ case "bool":
1747
+ return false;
1748
+ case "bvec2":
1749
+ return booleanArray(2 * size);
1750
+ case "bvec3":
1751
+ return booleanArray(3 * size);
1752
+ case "bvec4":
1753
+ return booleanArray(4 * size);
1754
+ case "mat2":
1755
+ return new Float32Array([
1756
+ 1,
1757
+ 0,
1758
+ 0,
1759
+ 1
1760
+ ]);
1761
+ case "mat3":
1762
+ return new Float32Array([
1763
+ 1,
1764
+ 0,
1765
+ 0,
1766
+ 0,
1767
+ 1,
1768
+ 0,
1769
+ 0,
1770
+ 0,
1771
+ 1
1772
+ ]);
1773
+ case "mat4":
1774
+ return new Float32Array([
1775
+ 1,
1776
+ 0,
1777
+ 0,
1778
+ 0,
1779
+ 0,
1780
+ 1,
1781
+ 0,
1782
+ 0,
1783
+ 0,
1784
+ 0,
1785
+ 1,
1786
+ 0,
1787
+ 0,
1788
+ 0,
1789
+ 0,
1790
+ 1
1791
+ ]);
1792
+ }
1793
+ return null;
1794
+ }
1795
+
1796
+ let GL_TABLE = null;
1797
+ const GL_TO_GLSL_TYPES = {
1798
+ FLOAT: "float",
1799
+ FLOAT_VEC2: "vec2",
1800
+ FLOAT_VEC3: "vec3",
1801
+ FLOAT_VEC4: "vec4",
1802
+ INT: "int",
1803
+ INT_VEC2: "ivec2",
1804
+ INT_VEC3: "ivec3",
1805
+ INT_VEC4: "ivec4",
1806
+ UNSIGNED_INT: "uint",
1807
+ UNSIGNED_INT_VEC2: "uvec2",
1808
+ UNSIGNED_INT_VEC3: "uvec3",
1809
+ UNSIGNED_INT_VEC4: "uvec4",
1810
+ BOOL: "bool",
1811
+ BOOL_VEC2: "bvec2",
1812
+ BOOL_VEC3: "bvec3",
1813
+ BOOL_VEC4: "bvec4",
1814
+ FLOAT_MAT2: "mat2",
1815
+ FLOAT_MAT3: "mat3",
1816
+ FLOAT_MAT4: "mat4",
1817
+ SAMPLER_2D: "sampler2D",
1818
+ INT_SAMPLER_2D: "sampler2D",
1819
+ UNSIGNED_INT_SAMPLER_2D: "sampler2D",
1820
+ SAMPLER_CUBE: "samplerCube",
1821
+ INT_SAMPLER_CUBE: "samplerCube",
1822
+ UNSIGNED_INT_SAMPLER_CUBE: "samplerCube",
1823
+ SAMPLER_2D_ARRAY: "sampler2DArray",
1824
+ INT_SAMPLER_2D_ARRAY: "sampler2DArray",
1825
+ UNSIGNED_INT_SAMPLER_2D_ARRAY: "sampler2DArray"
1826
+ };
1827
+ const GLSL_TO_VERTEX_TYPES = {
1828
+ float: "float32",
1829
+ vec2: "float32x2",
1830
+ vec3: "float32x3",
1831
+ vec4: "float32x4",
1832
+ int: "sint32",
1833
+ ivec2: "sint32x2",
1834
+ ivec3: "sint32x3",
1835
+ ivec4: "sint32x4",
1836
+ uint: "uint32",
1837
+ uvec2: "uint32x2",
1838
+ uvec3: "uint32x3",
1839
+ uvec4: "uint32x4",
1840
+ bool: "uint32",
1841
+ bvec2: "uint32x2",
1842
+ bvec3: "uint32x3",
1843
+ bvec4: "uint32x4"
1844
+ };
1845
+ function mapType(gl, type) {
1846
+ if (!GL_TABLE) {
1847
+ const typeNames = Object.keys(GL_TO_GLSL_TYPES);
1848
+ GL_TABLE = {};
1849
+ for (let i = 0; i < typeNames.length; ++i) {
1850
+ const tn = typeNames[i];
1851
+ GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn];
1852
+ }
1853
+ }
1854
+ return GL_TABLE[type];
1855
+ }
1856
+ function mapGlToVertexFormat(gl, type) {
1857
+ const typeValue = mapType(gl, type);
1858
+ return GLSL_TO_VERTEX_TYPES[typeValue] || "float32";
1859
+ }
1860
+
1861
+ function extractAttributesFromGlProgram(program, gl, sortAttributes = false) {
1862
+ const attributes = {};
1863
+ const totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
1864
+ for (let i = 0; i < totalAttributes; i++) {
1865
+ const attribData = gl.getActiveAttrib(program, i);
1866
+ if (attribData.name.startsWith("gl_")) {
1867
+ continue;
1868
+ }
1869
+ const format = mapGlToVertexFormat(gl, attribData.type);
1870
+ attributes[attribData.name] = {
1871
+ location: 0,
1872
+ // set further down..
1873
+ format,
1874
+ stride: getAttributeInfoFromFormat(format).stride,
1875
+ offset: 0,
1876
+ instance: false,
1877
+ start: 0
1878
+ };
1879
+ }
1880
+ const keys = Object.keys(attributes);
1881
+ if (sortAttributes) {
1882
+ keys.sort((a, b) => a > b ? 1 : -1);
1883
+ for (let i = 0; i < keys.length; i++) {
1884
+ attributes[keys[i]].location = i;
1885
+ gl.bindAttribLocation(program, i, keys[i]);
1886
+ }
1887
+ gl.linkProgram(program);
1888
+ } else {
1889
+ for (let i = 0; i < keys.length; i++) {
1890
+ attributes[keys[i]].location = gl.getAttribLocation(program, keys[i]);
1891
+ }
1892
+ }
1893
+ return attributes;
1894
+ }
1895
+
1896
+ function getUboData(program, gl) {
1897
+ if (!gl.ACTIVE_UNIFORM_BLOCKS)
1898
+ return {};
1899
+ const uniformBlocks = {};
1900
+ const totalUniformsBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
1901
+ for (let i = 0; i < totalUniformsBlocks; i++) {
1902
+ const name = gl.getActiveUniformBlockName(program, i);
1903
+ const uniformBlockIndex = gl.getUniformBlockIndex(program, name);
1904
+ const size = gl.getActiveUniformBlockParameter(program, i, gl.UNIFORM_BLOCK_DATA_SIZE);
1905
+ uniformBlocks[name] = {
1906
+ name,
1907
+ index: uniformBlockIndex,
1908
+ size
1909
+ };
1910
+ }
1911
+ return uniformBlocks;
1912
+ }
1913
+
1914
+ function getUniformData(program, gl) {
1915
+ const uniforms = {};
1916
+ const totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
1917
+ for (let i = 0; i < totalUniforms; i++) {
1918
+ const uniformData = gl.getActiveUniform(program, i);
1919
+ const name = uniformData.name.replace(/\[.*?\]$/, "");
1920
+ const isArray = !!uniformData.name.match(/\[.*?\]$/);
1921
+ const type = mapType(gl, uniformData.type);
1922
+ uniforms[name] = {
1923
+ name,
1924
+ index: i,
1925
+ type,
1926
+ size: uniformData.size,
1927
+ isArray,
1928
+ value: defaultValue(type, uniformData.size)
1929
+ };
1930
+ }
1931
+ return uniforms;
1932
+ }
1933
+
1934
+ function logPrettyShaderError(gl, shader) {
1935
+ const shaderSrc = gl.getShaderSource(shader).split("\n").map((line, index) => `${index}: ${line}`);
1936
+ const shaderLog = gl.getShaderInfoLog(shader);
1937
+ const splitShader = shaderLog.split("\n");
1938
+ const dedupe = {};
1939
+ const lineNumbers = splitShader.map((line) => parseFloat(line.replace(/^ERROR\: 0\:([\d]+)\:.*$/, "$1"))).filter((n) => {
1940
+ if (n && !dedupe[n]) {
1941
+ dedupe[n] = true;
1942
+ return true;
1943
+ }
1944
+ return false;
1945
+ });
1946
+ const logArgs = [""];
1947
+ lineNumbers.forEach((number) => {
1948
+ shaderSrc[number - 1] = `%c${shaderSrc[number - 1]}%c`;
1949
+ logArgs.push("background: #FF0000; color:#FFFFFF; font-size: 10px", "font-size: 10px");
1950
+ });
1951
+ const fragmentSourceToLog = shaderSrc.join("\n");
1952
+ logArgs[0] = fragmentSourceToLog;
1953
+ console.error(shaderLog);
1954
+ console.groupCollapsed("click to view full shader code");
1955
+ console.warn(...logArgs);
1956
+ console.groupEnd();
1957
+ }
1958
+ function logProgramError(gl, program, vertexShader, fragmentShader) {
1959
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
1960
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
1961
+ logPrettyShaderError(gl, vertexShader);
1962
+ }
1963
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
1964
+ logPrettyShaderError(gl, fragmentShader);
1965
+ }
1966
+ console.error("PixiJS Error: Could not initialize shader.");
1967
+ if (gl.getProgramInfoLog(program) !== "") {
1968
+ console.warn("PixiJS Warning: gl.getProgramInfoLog()", gl.getProgramInfoLog(program));
1969
+ }
1970
+ }
1971
+ }
1972
+
1973
+ function generateProgram(gl, program) {
1974
+ const glVertShader = compileShader(gl, gl.VERTEX_SHADER, program.vertex);
1975
+ const glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, program.fragment);
1976
+ const webGLProgram = gl.createProgram();
1977
+ gl.attachShader(webGLProgram, glVertShader);
1978
+ gl.attachShader(webGLProgram, glFragShader);
1979
+ const transformFeedbackVaryings = program.transformFeedbackVaryings;
1980
+ if (transformFeedbackVaryings) {
1981
+ if (typeof gl.transformFeedbackVaryings !== "function") {
1982
+ warn(`TransformFeedback is not supported but TransformFeedbackVaryings are given.`);
1983
+ } else {
1984
+ gl.transformFeedbackVaryings(
1985
+ webGLProgram,
1986
+ transformFeedbackVaryings.names,
1987
+ transformFeedbackVaryings.bufferMode === "separate" ? gl.SEPARATE_ATTRIBS : gl.INTERLEAVED_ATTRIBS
1988
+ );
1989
+ }
1990
+ }
1991
+ gl.linkProgram(webGLProgram);
1992
+ if (!gl.getProgramParameter(webGLProgram, gl.LINK_STATUS)) {
1993
+ logProgramError(gl, webGLProgram, glVertShader, glFragShader);
1994
+ }
1995
+ program._attributeData = extractAttributesFromGlProgram(
1996
+ webGLProgram,
1997
+ gl,
1998
+ !/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(program.vertex)
1999
+ );
2000
+ program._uniformData = getUniformData(webGLProgram, gl);
2001
+ program._uniformBlockData = getUboData(webGLProgram, gl);
2002
+ gl.deleteShader(glVertShader);
2003
+ gl.deleteShader(glFragShader);
2004
+ const uniformData = {};
2005
+ for (const i in program._uniformData) {
2006
+ const data = program._uniformData[i];
2007
+ uniformData[i] = {
2008
+ location: gl.getUniformLocation(webGLProgram, i),
2009
+ value: defaultValue(data.type, data.size)
2010
+ };
2011
+ }
2012
+ const glProgram = new GlProgramData(webGLProgram, uniformData);
2013
+ return glProgram;
2014
+ }
2015
+
2016
+ const defaultSyncData = {
2017
+ textureCount: 0,
2018
+ blockIndex: 0
2019
+ };
2020
+ class GlShaderSystem {
2021
+ constructor(renderer) {
2022
+ /**
2023
+ * @internal
2024
+ * @private
2025
+ */
2026
+ this._activeProgram = null;
2027
+ this._programDataHash = /* @__PURE__ */ Object.create(null);
2028
+ this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null);
2029
+ this._renderer = renderer;
2030
+ this._renderer.renderableGC.addManagedHash(this, "_programDataHash");
2031
+ }
2032
+ contextChange(gl) {
2033
+ this._gl = gl;
2034
+ this._programDataHash = /* @__PURE__ */ Object.create(null);
2035
+ this._shaderSyncFunctions = /* @__PURE__ */ Object.create(null);
2036
+ this._activeProgram = null;
2037
+ this.maxTextures = getMaxTexturesPerBatch();
2038
+ }
2039
+ /**
2040
+ * Changes the current shader to the one given in parameter.
2041
+ * @param shader - the new shader
2042
+ * @param skipSync - false if the shader should automatically sync its uniforms.
2043
+ * @returns the glProgram that belongs to the shader.
2044
+ */
2045
+ bind(shader, skipSync) {
2046
+ this._setProgram(shader.glProgram);
2047
+ if (skipSync)
2048
+ return;
2049
+ defaultSyncData.textureCount = 0;
2050
+ defaultSyncData.blockIndex = 0;
2051
+ let syncFunction = this._shaderSyncFunctions[shader.glProgram._key];
2052
+ if (!syncFunction) {
2053
+ syncFunction = this._shaderSyncFunctions[shader.glProgram._key] = this._generateShaderSync(shader, this);
2054
+ }
2055
+ this._renderer.buffer.nextBindBase(!!shader.glProgram.transformFeedbackVaryings);
2056
+ syncFunction(this._renderer, shader, defaultSyncData);
2057
+ }
2058
+ /**
2059
+ * Updates the uniform group.
2060
+ * @param uniformGroup - the uniform group to update
2061
+ */
2062
+ updateUniformGroup(uniformGroup) {
2063
+ this._renderer.uniformGroup.updateUniformGroup(uniformGroup, this._activeProgram, defaultSyncData);
2064
+ }
2065
+ /**
2066
+ * Binds a uniform block to the shader.
2067
+ * @param uniformGroup - the uniform group to bind
2068
+ * @param name - the name of the uniform block
2069
+ * @param index - the index of the uniform block
2070
+ */
2071
+ bindUniformBlock(uniformGroup, name, index = 0) {
2072
+ const bufferSystem = this._renderer.buffer;
2073
+ const programData = this._getProgramData(this._activeProgram);
2074
+ const isBufferResource = uniformGroup._bufferResource;
2075
+ if (!isBufferResource) {
2076
+ this._renderer.ubo.updateUniformGroup(uniformGroup);
2077
+ }
2078
+ const buffer = uniformGroup.buffer;
2079
+ const glBuffer = bufferSystem.updateBuffer(buffer);
2080
+ const boundLocation = bufferSystem.freeLocationForBufferBase(glBuffer);
2081
+ if (isBufferResource) {
2082
+ const { offset, size } = uniformGroup;
2083
+ if (offset === 0 && size === buffer.data.byteLength) {
2084
+ bufferSystem.bindBufferBase(glBuffer, boundLocation);
2085
+ } else {
2086
+ bufferSystem.bindBufferRange(glBuffer, boundLocation, offset);
2087
+ }
2088
+ } else if (bufferSystem.getLastBindBaseLocation(glBuffer) !== boundLocation) {
2089
+ bufferSystem.bindBufferBase(glBuffer, boundLocation);
2090
+ }
2091
+ const uniformBlockIndex = this._activeProgram._uniformBlockData[name].index;
2092
+ if (programData.uniformBlockBindings[index] === boundLocation)
2093
+ return;
2094
+ programData.uniformBlockBindings[index] = boundLocation;
2095
+ this._renderer.gl.uniformBlockBinding(programData.program, uniformBlockIndex, boundLocation);
2096
+ }
2097
+ _setProgram(program) {
2098
+ if (this._activeProgram === program)
2099
+ return;
2100
+ this._activeProgram = program;
2101
+ const programData = this._getProgramData(program);
2102
+ this._gl.useProgram(programData.program);
2103
+ }
2104
+ /**
2105
+ * @param program - the program to get the data for
2106
+ * @internal
2107
+ * @private
2108
+ */
2109
+ _getProgramData(program) {
2110
+ return this._programDataHash[program._key] || this._createProgramData(program);
2111
+ }
2112
+ _createProgramData(program) {
2113
+ const key = program._key;
2114
+ this._programDataHash[key] = generateProgram(this._gl, program);
2115
+ return this._programDataHash[key];
2116
+ }
2117
+ destroy() {
2118
+ for (const key of Object.keys(this._programDataHash)) {
2119
+ const programData = this._programDataHash[key];
2120
+ programData.destroy();
2121
+ this._programDataHash[key] = null;
2122
+ }
2123
+ this._programDataHash = null;
2124
+ }
2125
+ /**
2126
+ * Creates a function that can be executed that will sync the shader as efficiently as possible.
2127
+ * Overridden by the unsafe eval package if you don't want eval used in your project.
2128
+ * @param shader - the shader to generate the sync function for
2129
+ * @param shaderSystem - the shader system to use
2130
+ * @returns - the generated sync function
2131
+ * @ignore
2132
+ */
2133
+ _generateShaderSync(shader, shaderSystem) {
2134
+ return generateShaderSyncCode(shader, shaderSystem);
2135
+ }
2136
+ resetState() {
2137
+ this._activeProgram = null;
2138
+ }
2139
+ }
2140
+ /** @ignore */
2141
+ GlShaderSystem.extension = {
2142
+ type: [
2143
+ ExtensionType.WebGLSystem
2144
+ ],
2145
+ name: "shader"
2146
+ };
2147
+
2148
+ const UNIFORM_TO_SINGLE_SETTERS = {
2149
+ f32: `if (cv !== v) {
2150
+ cu.value = v;
2151
+ gl.uniform1f(location, v);
2152
+ }`,
2153
+ "vec2<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
2154
+ cv[0] = v[0];
2155
+ cv[1] = v[1];
2156
+ gl.uniform2f(location, v[0], v[1]);
2157
+ }`,
2158
+ "vec3<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
2159
+ cv[0] = v[0];
2160
+ cv[1] = v[1];
2161
+ cv[2] = v[2];
2162
+ gl.uniform3f(location, v[0], v[1], v[2]);
2163
+ }`,
2164
+ "vec4<f32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
2165
+ cv[0] = v[0];
2166
+ cv[1] = v[1];
2167
+ cv[2] = v[2];
2168
+ cv[3] = v[3];
2169
+ gl.uniform4f(location, v[0], v[1], v[2], v[3]);
2170
+ }`,
2171
+ i32: `if (cv !== v) {
2172
+ cu.value = v;
2173
+ gl.uniform1i(location, v);
2174
+ }`,
2175
+ "vec2<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
2176
+ cv[0] = v[0];
2177
+ cv[1] = v[1];
2178
+ gl.uniform2i(location, v[0], v[1]);
2179
+ }`,
2180
+ "vec3<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
2181
+ cv[0] = v[0];
2182
+ cv[1] = v[1];
2183
+ cv[2] = v[2];
2184
+ gl.uniform3i(location, v[0], v[1], v[2]);
2185
+ }`,
2186
+ "vec4<i32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
2187
+ cv[0] = v[0];
2188
+ cv[1] = v[1];
2189
+ cv[2] = v[2];
2190
+ cv[3] = v[3];
2191
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
2192
+ }`,
2193
+ u32: `if (cv !== v) {
2194
+ cu.value = v;
2195
+ gl.uniform1ui(location, v);
2196
+ }`,
2197
+ "vec2<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
2198
+ cv[0] = v[0];
2199
+ cv[1] = v[1];
2200
+ gl.uniform2ui(location, v[0], v[1]);
2201
+ }`,
2202
+ "vec3<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
2203
+ cv[0] = v[0];
2204
+ cv[1] = v[1];
2205
+ cv[2] = v[2];
2206
+ gl.uniform3ui(location, v[0], v[1], v[2]);
2207
+ }`,
2208
+ "vec4<u32>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
2209
+ cv[0] = v[0];
2210
+ cv[1] = v[1];
2211
+ cv[2] = v[2];
2212
+ cv[3] = v[3];
2213
+ gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
2214
+ }`,
2215
+ bool: `if (cv !== v) {
2216
+ cu.value = v;
2217
+ gl.uniform1i(location, v);
2218
+ }`,
2219
+ "vec2<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1]) {
2220
+ cv[0] = v[0];
2221
+ cv[1] = v[1];
2222
+ gl.uniform2i(location, v[0], v[1]);
2223
+ }`,
2224
+ "vec3<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
2225
+ cv[0] = v[0];
2226
+ cv[1] = v[1];
2227
+ cv[2] = v[2];
2228
+ gl.uniform3i(location, v[0], v[1], v[2]);
2229
+ }`,
2230
+ "vec4<bool>": `if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
2231
+ cv[0] = v[0];
2232
+ cv[1] = v[1];
2233
+ cv[2] = v[2];
2234
+ cv[3] = v[3];
2235
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
2236
+ }`,
2237
+ "mat2x2<f32>": `gl.uniformMatrix2fv(location, false, v);`,
2238
+ "mat3x3<f32>": `gl.uniformMatrix3fv(location, false, v);`,
2239
+ "mat4x4<f32>": `gl.uniformMatrix4fv(location, false, v);`
2240
+ };
2241
+ const UNIFORM_TO_ARRAY_SETTERS = {
2242
+ f32: `gl.uniform1fv(location, v);`,
2243
+ "vec2<f32>": `gl.uniform2fv(location, v);`,
2244
+ "vec3<f32>": `gl.uniform3fv(location, v);`,
2245
+ "vec4<f32>": `gl.uniform4fv(location, v);`,
2246
+ "mat2x2<f32>": `gl.uniformMatrix2fv(location, false, v);`,
2247
+ "mat3x3<f32>": `gl.uniformMatrix3fv(location, false, v);`,
2248
+ "mat4x4<f32>": `gl.uniformMatrix4fv(location, false, v);`,
2249
+ i32: `gl.uniform1iv(location, v);`,
2250
+ "vec2<i32>": `gl.uniform2iv(location, v);`,
2251
+ "vec3<i32>": `gl.uniform3iv(location, v);`,
2252
+ "vec4<i32>": `gl.uniform4iv(location, v);`,
2253
+ u32: `gl.uniform1iv(location, v);`,
2254
+ "vec2<u32>": `gl.uniform2iv(location, v);`,
2255
+ "vec3<u32>": `gl.uniform3iv(location, v);`,
2256
+ "vec4<u32>": `gl.uniform4iv(location, v);`,
2257
+ bool: `gl.uniform1iv(location, v);`,
2258
+ "vec2<bool>": `gl.uniform2iv(location, v);`,
2259
+ "vec3<bool>": `gl.uniform3iv(location, v);`,
2260
+ "vec4<bool>": `gl.uniform4iv(location, v);`
2261
+ };
2262
+
2263
+ function generateUniformsSync(group, uniformData) {
2264
+ const funcFragments = [`
2265
+ var v = null;
2266
+ var cv = null;
2267
+ var cu = null;
2268
+ var t = 0;
2269
+ var gl = renderer.gl;
2270
+ var name = null;
2271
+ `];
2272
+ for (const i in group.uniforms) {
2273
+ if (!uniformData[i]) {
2274
+ if (group.uniforms[i] instanceof UniformGroup) {
2275
+ if (group.uniforms[i].ubo) {
2276
+ funcFragments.push(`
2277
+ renderer.shader.bindUniformBlock(uv.${i}, "${i}");
2278
+ `);
2279
+ } else {
2280
+ funcFragments.push(`
2281
+ renderer.shader.updateUniformGroup(uv.${i});
2282
+ `);
2283
+ }
2284
+ } else if (group.uniforms[i] instanceof BufferResource) {
2285
+ funcFragments.push(`
2286
+ renderer.shader.bindBufferResource(uv.${i}, "${i}");
2287
+ `);
2288
+ }
2289
+ continue;
2290
+ }
2291
+ const uniform = group.uniformStructures[i];
2292
+ let parsed = false;
2293
+ for (let j = 0; j < uniformParsers.length; j++) {
2294
+ const parser = uniformParsers[j];
2295
+ if (uniform.type === parser.type && parser.test(uniform)) {
2296
+ funcFragments.push(`name = "${i}";`, uniformParsers[j].uniform);
2297
+ parsed = true;
2298
+ break;
2299
+ }
2300
+ }
2301
+ if (!parsed) {
2302
+ const templateType = uniform.size === 1 ? UNIFORM_TO_SINGLE_SETTERS : UNIFORM_TO_ARRAY_SETTERS;
2303
+ const template = templateType[uniform.type].replace("location", `ud["${i}"].location`);
2304
+ funcFragments.push(`
2305
+ cu = ud["${i}"];
2306
+ cv = cu.value;
2307
+ v = uv["${i}"];
2308
+ ${template};`);
2309
+ }
2310
+ }
2311
+ return new Function("ud", "uv", "renderer", "syncData", funcFragments.join("\n"));
2312
+ }
2313
+
2314
+ class GlUniformGroupSystem {
2315
+ /** @param renderer - The renderer this System works for. */
2316
+ constructor(renderer) {
2317
+ /** Cache to holds the generated functions. Stored against UniformObjects unique signature. */
2318
+ this._cache = {};
2319
+ this._uniformGroupSyncHash = {};
2320
+ this._renderer = renderer;
2321
+ this.gl = null;
2322
+ this._cache = {};
2323
+ }
2324
+ contextChange(gl) {
2325
+ this.gl = gl;
2326
+ }
2327
+ /**
2328
+ * Uploads the uniforms values to the currently bound shader.
2329
+ * @param group - the uniforms values that be applied to the current shader
2330
+ * @param program
2331
+ * @param syncData
2332
+ * @param syncData.textureCount
2333
+ */
2334
+ updateUniformGroup(group, program, syncData) {
2335
+ const programData = this._renderer.shader._getProgramData(program);
2336
+ if (!group.isStatic || group._dirtyId !== programData.uniformDirtyGroups[group.uid]) {
2337
+ programData.uniformDirtyGroups[group.uid] = group._dirtyId;
2338
+ const syncFunc = this._getUniformSyncFunction(group, program);
2339
+ syncFunc(programData.uniformData, group.uniforms, this._renderer, syncData);
2340
+ }
2341
+ }
2342
+ /**
2343
+ * Overridable by the pixi.js/unsafe-eval package to use static syncUniforms instead.
2344
+ * @param group
2345
+ * @param program
2346
+ */
2347
+ _getUniformSyncFunction(group, program) {
2348
+ return this._uniformGroupSyncHash[group._signature]?.[program._key] || this._createUniformSyncFunction(group, program);
2349
+ }
2350
+ _createUniformSyncFunction(group, program) {
2351
+ const uniformGroupSyncHash = this._uniformGroupSyncHash[group._signature] || (this._uniformGroupSyncHash[group._signature] = {});
2352
+ const id = this._getSignature(group, program._uniformData, "u");
2353
+ if (!this._cache[id]) {
2354
+ this._cache[id] = this._generateUniformsSync(group, program._uniformData);
2355
+ }
2356
+ uniformGroupSyncHash[program._key] = this._cache[id];
2357
+ return uniformGroupSyncHash[program._key];
2358
+ }
2359
+ _generateUniformsSync(group, uniformData) {
2360
+ return generateUniformsSync(group, uniformData);
2361
+ }
2362
+ /**
2363
+ * Takes a uniform group and data and generates a unique signature for them.
2364
+ * @param group - The uniform group to get signature of
2365
+ * @param group.uniforms
2366
+ * @param uniformData - Uniform information generated by the shader
2367
+ * @param preFix
2368
+ * @returns Unique signature of the uniform group
2369
+ */
2370
+ _getSignature(group, uniformData, preFix) {
2371
+ const uniforms = group.uniforms;
2372
+ const strings = [`${preFix}-`];
2373
+ for (const i in uniforms) {
2374
+ strings.push(i);
2375
+ if (uniformData[i]) {
2376
+ strings.push(uniformData[i].type);
2377
+ }
2378
+ }
2379
+ return strings.join("-");
2380
+ }
2381
+ /** Destroys this System and removes all its textures. */
2382
+ destroy() {
2383
+ this._renderer = null;
2384
+ this._cache = null;
2385
+ }
2386
+ }
2387
+ /** @ignore */
2388
+ GlUniformGroupSystem.extension = {
2389
+ type: [
2390
+ ExtensionType.WebGLSystem
2391
+ ],
2392
+ name: "uniformGroup"
2393
+ };
2394
+
2395
+ function mapWebGLBlendModesToPixi(gl) {
2396
+ const blendMap = {};
2397
+ blendMap.normal = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
2398
+ blendMap.add = [gl.ONE, gl.ONE];
2399
+ blendMap.multiply = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
2400
+ blendMap.screen = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
2401
+ blendMap.none = [0, 0];
2402
+ blendMap["normal-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
2403
+ blendMap["add-npm"] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];
2404
+ blendMap["screen-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
2405
+ blendMap.erase = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];
2406
+ const isWebGl2 = !(gl instanceof DOMAdapter.get().getWebGLRenderingContext());
2407
+ if (isWebGl2) {
2408
+ blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MIN, gl.MIN];
2409
+ blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MAX, gl.MAX];
2410
+ } else {
2411
+ const ext = gl.getExtension("EXT_blend_minmax");
2412
+ if (ext) {
2413
+ blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MIN_EXT, ext.MIN_EXT];
2414
+ blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MAX_EXT, ext.MAX_EXT];
2415
+ }
2416
+ }
2417
+ return blendMap;
2418
+ }
2419
+
2420
+ const BLEND = 0;
2421
+ const OFFSET = 1;
2422
+ const CULLING = 2;
2423
+ const DEPTH_TEST = 3;
2424
+ const WINDING = 4;
2425
+ const DEPTH_MASK = 5;
2426
+ const _GlStateSystem = class _GlStateSystem {
2427
+ constructor(renderer) {
2428
+ /**
2429
+ * Whether to invert the front face when rendering
2430
+ * This is used for render textures where the Y-coordinate is flipped
2431
+ * @default false
2432
+ */
2433
+ this._invertFrontFace = false;
2434
+ this.gl = null;
2435
+ this.stateId = 0;
2436
+ this.polygonOffset = 0;
2437
+ this.blendMode = "none";
2438
+ this._blendEq = false;
2439
+ this.map = [];
2440
+ this.map[BLEND] = this.setBlend;
2441
+ this.map[OFFSET] = this.setOffset;
2442
+ this.map[CULLING] = this.setCullFace;
2443
+ this.map[DEPTH_TEST] = this.setDepthTest;
2444
+ this.map[WINDING] = this.setFrontFace;
2445
+ this.map[DEPTH_MASK] = this.setDepthMask;
2446
+ this.checks = [];
2447
+ this.defaultState = State.for2d();
2448
+ renderer.renderTarget.onRenderTargetChange.add(this);
2449
+ }
2450
+ onRenderTargetChange(renderTarget) {
2451
+ this._invertFrontFace = !renderTarget.isRoot;
2452
+ if (this._cullFace) {
2453
+ this.setFrontFace(this._frontFace);
2454
+ } else {
2455
+ this._frontFaceDirty = true;
2456
+ }
2457
+ }
2458
+ contextChange(gl) {
2459
+ this.gl = gl;
2460
+ this.blendModesMap = mapWebGLBlendModesToPixi(gl);
2461
+ this.resetState();
2462
+ }
2463
+ /**
2464
+ * Sets the current state
2465
+ * @param {*} state - The state to set.
2466
+ */
2467
+ set(state) {
2468
+ state || (state = this.defaultState);
2469
+ if (this.stateId !== state.data) {
2470
+ let diff = this.stateId ^ state.data;
2471
+ let i = 0;
2472
+ while (diff) {
2473
+ if (diff & 1) {
2474
+ this.map[i].call(this, !!(state.data & 1 << i));
2475
+ }
2476
+ diff >>= 1;
2477
+ i++;
2478
+ }
2479
+ this.stateId = state.data;
2480
+ }
2481
+ for (let i = 0; i < this.checks.length; i++) {
2482
+ this.checks[i](this, state);
2483
+ }
2484
+ }
2485
+ /**
2486
+ * Sets the state, when previous state is unknown.
2487
+ * @param {*} state - The state to set
2488
+ */
2489
+ forceState(state) {
2490
+ state || (state = this.defaultState);
2491
+ for (let i = 0; i < this.map.length; i++) {
2492
+ this.map[i].call(this, !!(state.data & 1 << i));
2493
+ }
2494
+ for (let i = 0; i < this.checks.length; i++) {
2495
+ this.checks[i](this, state);
2496
+ }
2497
+ this.stateId = state.data;
2498
+ }
2499
+ /**
2500
+ * Sets whether to enable or disable blending.
2501
+ * @param value - Turn on or off WebGl blending.
2502
+ */
2503
+ setBlend(value) {
2504
+ this._updateCheck(_GlStateSystem._checkBlendMode, value);
2505
+ this.gl[value ? "enable" : "disable"](this.gl.BLEND);
2506
+ }
2507
+ /**
2508
+ * Sets whether to enable or disable polygon offset fill.
2509
+ * @param value - Turn on or off webgl polygon offset testing.
2510
+ */
2511
+ setOffset(value) {
2512
+ this._updateCheck(_GlStateSystem._checkPolygonOffset, value);
2513
+ this.gl[value ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
2514
+ }
2515
+ /**
2516
+ * Sets whether to enable or disable depth test.
2517
+ * @param value - Turn on or off webgl depth testing.
2518
+ */
2519
+ setDepthTest(value) {
2520
+ this.gl[value ? "enable" : "disable"](this.gl.DEPTH_TEST);
2521
+ }
2522
+ /**
2523
+ * Sets whether to enable or disable depth mask.
2524
+ * @param value - Turn on or off webgl depth mask.
2525
+ */
2526
+ setDepthMask(value) {
2527
+ this.gl.depthMask(value);
2528
+ }
2529
+ /**
2530
+ * Sets whether to enable or disable cull face.
2531
+ * @param {boolean} value - Turn on or off webgl cull face.
2532
+ */
2533
+ setCullFace(value) {
2534
+ this._cullFace = value;
2535
+ this.gl[value ? "enable" : "disable"](this.gl.CULL_FACE);
2536
+ if (this._cullFace && this._frontFaceDirty) {
2537
+ this.setFrontFace(this._frontFace);
2538
+ }
2539
+ }
2540
+ /**
2541
+ * Sets the gl front face.
2542
+ * @param {boolean} value - true is clockwise and false is counter-clockwise
2543
+ */
2544
+ setFrontFace(value) {
2545
+ this._frontFace = value;
2546
+ this._frontFaceDirty = false;
2547
+ const faceMode = this._invertFrontFace ? !value : value;
2548
+ if (this._glFrontFace !== faceMode) {
2549
+ this._glFrontFace = faceMode;
2550
+ this.gl.frontFace(this.gl[faceMode ? "CW" : "CCW"]);
2551
+ }
2552
+ }
2553
+ /**
2554
+ * Sets the blend mode.
2555
+ * @param {number} value - The blend mode to set to.
2556
+ */
2557
+ setBlendMode(value) {
2558
+ if (!this.blendModesMap[value]) {
2559
+ value = "normal";
2560
+ }
2561
+ if (value === this.blendMode) {
2562
+ return;
2563
+ }
2564
+ this.blendMode = value;
2565
+ const mode = this.blendModesMap[value];
2566
+ const gl = this.gl;
2567
+ if (mode.length === 2) {
2568
+ gl.blendFunc(mode[0], mode[1]);
2569
+ } else {
2570
+ gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
2571
+ }
2572
+ if (mode.length === 6) {
2573
+ this._blendEq = true;
2574
+ gl.blendEquationSeparate(mode[4], mode[5]);
2575
+ } else if (this._blendEq) {
2576
+ this._blendEq = false;
2577
+ gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
2578
+ }
2579
+ }
2580
+ /**
2581
+ * Sets the polygon offset.
2582
+ * @param {number} value - the polygon offset
2583
+ * @param {number} scale - the polygon offset scale
2584
+ */
2585
+ setPolygonOffset(value, scale) {
2586
+ this.gl.polygonOffset(value, scale);
2587
+ }
2588
+ // used
2589
+ /** Resets all the logic and disables the VAOs. */
2590
+ resetState() {
2591
+ this._glFrontFace = false;
2592
+ this._frontFace = false;
2593
+ this._cullFace = false;
2594
+ this._frontFaceDirty = false;
2595
+ this._invertFrontFace = false;
2596
+ this.gl.frontFace(this.gl.CCW);
2597
+ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false);
2598
+ this.forceState(this.defaultState);
2599
+ this._blendEq = true;
2600
+ this.blendMode = "";
2601
+ this.setBlendMode("normal");
2602
+ }
2603
+ /**
2604
+ * Checks to see which updates should be checked based on which settings have been activated.
2605
+ *
2606
+ * For example, if blend is enabled then we should check the blend modes each time the state is changed
2607
+ * or if polygon fill is activated then we need to check if the polygon offset changes.
2608
+ * The idea is that we only check what we have too.
2609
+ * @param func - the checking function to add or remove
2610
+ * @param value - should the check function be added or removed.
2611
+ */
2612
+ _updateCheck(func, value) {
2613
+ const index = this.checks.indexOf(func);
2614
+ if (value && index === -1) {
2615
+ this.checks.push(func);
2616
+ } else if (!value && index !== -1) {
2617
+ this.checks.splice(index, 1);
2618
+ }
2619
+ }
2620
+ /**
2621
+ * A private little wrapper function that we call to check the blend mode.
2622
+ * @param system - the System to perform the state check on
2623
+ * @param state - the state that the blendMode will pulled from
2624
+ */
2625
+ static _checkBlendMode(system, state) {
2626
+ system.setBlendMode(state.blendMode);
2627
+ }
2628
+ /**
2629
+ * A private little wrapper function that we call to check the polygon offset.
2630
+ * @param system - the System to perform the state check on
2631
+ * @param state - the state that the blendMode will pulled from
2632
+ */
2633
+ static _checkPolygonOffset(system, state) {
2634
+ system.setPolygonOffset(1, state.polygonOffset);
2635
+ }
2636
+ /**
2637
+ * @ignore
2638
+ */
2639
+ destroy() {
2640
+ this.gl = null;
2641
+ this.checks.length = 0;
2642
+ }
2643
+ };
2644
+ /** @ignore */
2645
+ _GlStateSystem.extension = {
2646
+ type: [
2647
+ ExtensionType.WebGLSystem
2648
+ ],
2649
+ name: "state"
2650
+ };
2651
+ let GlStateSystem = _GlStateSystem;
2652
+
2653
+ class GlTexture {
2654
+ constructor(texture) {
2655
+ this.target = GL_TARGETS.TEXTURE_2D;
2656
+ this.texture = texture;
2657
+ this.width = -1;
2658
+ this.height = -1;
2659
+ this.type = GL_TYPES.UNSIGNED_BYTE;
2660
+ this.internalFormat = GL_FORMATS.RGBA;
2661
+ this.format = GL_FORMATS.RGBA;
2662
+ this.samplerType = 0;
2663
+ }
2664
+ }
2665
+
2666
+ const glUploadBufferImageResource = {
2667
+ id: "buffer",
2668
+ upload(source, glTexture, gl) {
2669
+ if (glTexture.width === source.width || glTexture.height === source.height) {
2670
+ gl.texSubImage2D(
2671
+ gl.TEXTURE_2D,
2672
+ 0,
2673
+ 0,
2674
+ 0,
2675
+ source.width,
2676
+ source.height,
2677
+ glTexture.format,
2678
+ glTexture.type,
2679
+ source.resource
2680
+ );
2681
+ } else {
2682
+ gl.texImage2D(
2683
+ glTexture.target,
2684
+ 0,
2685
+ glTexture.internalFormat,
2686
+ source.width,
2687
+ source.height,
2688
+ 0,
2689
+ glTexture.format,
2690
+ glTexture.type,
2691
+ source.resource
2692
+ );
2693
+ }
2694
+ glTexture.width = source.width;
2695
+ glTexture.height = source.height;
2696
+ }
2697
+ };
2698
+
2699
+ const compressedFormatMap = {
2700
+ "bc1-rgba-unorm": true,
2701
+ "bc1-rgba-unorm-srgb": true,
2702
+ "bc2-rgba-unorm": true,
2703
+ "bc2-rgba-unorm-srgb": true,
2704
+ "bc3-rgba-unorm": true,
2705
+ "bc3-rgba-unorm-srgb": true,
2706
+ "bc4-r-unorm": true,
2707
+ "bc4-r-snorm": true,
2708
+ "bc5-rg-unorm": true,
2709
+ "bc5-rg-snorm": true,
2710
+ "bc6h-rgb-ufloat": true,
2711
+ "bc6h-rgb-float": true,
2712
+ "bc7-rgba-unorm": true,
2713
+ "bc7-rgba-unorm-srgb": true,
2714
+ // ETC2 compressed formats usable if "texture-compression-etc2" is both
2715
+ // supported by the device/user agent and enabled in requestDevice.
2716
+ "etc2-rgb8unorm": true,
2717
+ "etc2-rgb8unorm-srgb": true,
2718
+ "etc2-rgb8a1unorm": true,
2719
+ "etc2-rgb8a1unorm-srgb": true,
2720
+ "etc2-rgba8unorm": true,
2721
+ "etc2-rgba8unorm-srgb": true,
2722
+ "eac-r11unorm": true,
2723
+ "eac-r11snorm": true,
2724
+ "eac-rg11unorm": true,
2725
+ "eac-rg11snorm": true,
2726
+ // ASTC compressed formats usable if "texture-compression-astc" is both
2727
+ // supported by the device/user agent and enabled in requestDevice.
2728
+ "astc-4x4-unorm": true,
2729
+ "astc-4x4-unorm-srgb": true,
2730
+ "astc-5x4-unorm": true,
2731
+ "astc-5x4-unorm-srgb": true,
2732
+ "astc-5x5-unorm": true,
2733
+ "astc-5x5-unorm-srgb": true,
2734
+ "astc-6x5-unorm": true,
2735
+ "astc-6x5-unorm-srgb": true,
2736
+ "astc-6x6-unorm": true,
2737
+ "astc-6x6-unorm-srgb": true,
2738
+ "astc-8x5-unorm": true,
2739
+ "astc-8x5-unorm-srgb": true,
2740
+ "astc-8x6-unorm": true,
2741
+ "astc-8x6-unorm-srgb": true,
2742
+ "astc-8x8-unorm": true,
2743
+ "astc-8x8-unorm-srgb": true,
2744
+ "astc-10x5-unorm": true,
2745
+ "astc-10x5-unorm-srgb": true,
2746
+ "astc-10x6-unorm": true,
2747
+ "astc-10x6-unorm-srgb": true,
2748
+ "astc-10x8-unorm": true,
2749
+ "astc-10x8-unorm-srgb": true,
2750
+ "astc-10x10-unorm": true,
2751
+ "astc-10x10-unorm-srgb": true,
2752
+ "astc-12x10-unorm": true,
2753
+ "astc-12x10-unorm-srgb": true,
2754
+ "astc-12x12-unorm": true,
2755
+ "astc-12x12-unorm-srgb": true
2756
+ };
2757
+ const glUploadCompressedTextureResource = {
2758
+ id: "compressed",
2759
+ upload(source, glTexture, gl) {
2760
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
2761
+ let mipWidth = source.pixelWidth;
2762
+ let mipHeight = source.pixelHeight;
2763
+ const compressed = !!compressedFormatMap[source.format];
2764
+ for (let i = 0; i < source.resource.length; i++) {
2765
+ const levelBuffer = source.resource[i];
2766
+ if (compressed) {
2767
+ gl.compressedTexImage2D(
2768
+ gl.TEXTURE_2D,
2769
+ i,
2770
+ glTexture.internalFormat,
2771
+ mipWidth,
2772
+ mipHeight,
2773
+ 0,
2774
+ levelBuffer
2775
+ );
2776
+ } else {
2777
+ gl.texImage2D(
2778
+ gl.TEXTURE_2D,
2779
+ i,
2780
+ glTexture.internalFormat,
2781
+ mipWidth,
2782
+ mipHeight,
2783
+ 0,
2784
+ glTexture.format,
2785
+ glTexture.type,
2786
+ levelBuffer
2787
+ );
2788
+ }
2789
+ mipWidth = Math.max(mipWidth >> 1, 1);
2790
+ mipHeight = Math.max(mipHeight >> 1, 1);
2791
+ }
2792
+ }
2793
+ };
2794
+
2795
+ const glUploadImageResource = {
2796
+ id: "image",
2797
+ upload(source, glTexture, gl, webGLVersion) {
2798
+ const glWidth = glTexture.width;
2799
+ const glHeight = glTexture.height;
2800
+ const textureWidth = source.pixelWidth;
2801
+ const textureHeight = source.pixelHeight;
2802
+ const resourceWidth = source.resourceWidth;
2803
+ const resourceHeight = source.resourceHeight;
2804
+ if (resourceWidth < textureWidth || resourceHeight < textureHeight) {
2805
+ if (glWidth !== textureWidth || glHeight !== textureHeight) {
2806
+ gl.texImage2D(
2807
+ glTexture.target,
2808
+ 0,
2809
+ glTexture.internalFormat,
2810
+ textureWidth,
2811
+ textureHeight,
2812
+ 0,
2813
+ glTexture.format,
2814
+ glTexture.type,
2815
+ null
2816
+ );
2817
+ }
2818
+ if (webGLVersion === 2) {
2819
+ gl.texSubImage2D(
2820
+ gl.TEXTURE_2D,
2821
+ 0,
2822
+ 0,
2823
+ 0,
2824
+ resourceWidth,
2825
+ resourceHeight,
2826
+ glTexture.format,
2827
+ glTexture.type,
2828
+ source.resource
2829
+ );
2830
+ } else {
2831
+ gl.texSubImage2D(
2832
+ gl.TEXTURE_2D,
2833
+ 0,
2834
+ 0,
2835
+ 0,
2836
+ glTexture.format,
2837
+ glTexture.type,
2838
+ source.resource
2839
+ );
2840
+ }
2841
+ } else if (glWidth === textureWidth && glHeight === textureHeight) {
2842
+ gl.texSubImage2D(
2843
+ gl.TEXTURE_2D,
2844
+ 0,
2845
+ 0,
2846
+ 0,
2847
+ glTexture.format,
2848
+ glTexture.type,
2849
+ source.resource
2850
+ );
2851
+ } else if (webGLVersion === 2) {
2852
+ gl.texImage2D(
2853
+ glTexture.target,
2854
+ 0,
2855
+ glTexture.internalFormat,
2856
+ textureWidth,
2857
+ textureHeight,
2858
+ 0,
2859
+ glTexture.format,
2860
+ glTexture.type,
2861
+ source.resource
2862
+ );
2863
+ } else {
2864
+ gl.texImage2D(
2865
+ glTexture.target,
2866
+ 0,
2867
+ glTexture.internalFormat,
2868
+ glTexture.format,
2869
+ glTexture.type,
2870
+ source.resource
2871
+ );
2872
+ }
2873
+ glTexture.width = textureWidth;
2874
+ glTexture.height = textureHeight;
2875
+ }
2876
+ };
2877
+
2878
+ const glUploadVideoResource = {
2879
+ id: "video",
2880
+ upload(source, glTexture, gl, webGLVersion) {
2881
+ if (!source.isValid) {
2882
+ gl.texImage2D(
2883
+ glTexture.target,
2884
+ 0,
2885
+ glTexture.internalFormat,
2886
+ 1,
2887
+ 1,
2888
+ 0,
2889
+ glTexture.format,
2890
+ glTexture.type,
2891
+ null
2892
+ );
2893
+ return;
2894
+ }
2895
+ glUploadImageResource.upload(source, glTexture, gl, webGLVersion);
2896
+ }
2897
+ };
2898
+
2899
+ const scaleModeToGlFilter = {
2900
+ linear: 9729,
2901
+ nearest: 9728
2902
+ };
2903
+ const mipmapScaleModeToGlFilter = {
2904
+ linear: {
2905
+ linear: 9987,
2906
+ nearest: 9985
2907
+ },
2908
+ nearest: {
2909
+ linear: 9986,
2910
+ nearest: 9984
2911
+ }
2912
+ };
2913
+ const wrapModeToGlAddress = {
2914
+ "clamp-to-edge": 33071,
2915
+ repeat: 10497,
2916
+ "mirror-repeat": 33648
2917
+ };
2918
+ const compareModeToGlCompare = {
2919
+ never: 512,
2920
+ less: 513,
2921
+ equal: 514,
2922
+ "less-equal": 515,
2923
+ greater: 516,
2924
+ "not-equal": 517,
2925
+ "greater-equal": 518,
2926
+ always: 519
2927
+ };
2928
+
2929
+ function applyStyleParams(style, gl, mipmaps, anisotropicExt, glFunctionName, firstParam, forceClamp, firstCreation) {
2930
+ const castParam = firstParam;
2931
+ if (!firstCreation || style.addressModeU !== "repeat" || style.addressModeV !== "repeat" || style.addressModeW !== "repeat") {
2932
+ const wrapModeS = wrapModeToGlAddress[forceClamp ? "clamp-to-edge" : style.addressModeU];
2933
+ const wrapModeT = wrapModeToGlAddress[forceClamp ? "clamp-to-edge" : style.addressModeV];
2934
+ const wrapModeR = wrapModeToGlAddress[forceClamp ? "clamp-to-edge" : style.addressModeW];
2935
+ gl[glFunctionName](castParam, gl.TEXTURE_WRAP_S, wrapModeS);
2936
+ gl[glFunctionName](castParam, gl.TEXTURE_WRAP_T, wrapModeT);
2937
+ if (gl.TEXTURE_WRAP_R)
2938
+ gl[glFunctionName](castParam, gl.TEXTURE_WRAP_R, wrapModeR);
2939
+ }
2940
+ if (!firstCreation || style.magFilter !== "linear") {
2941
+ gl[glFunctionName](castParam, gl.TEXTURE_MAG_FILTER, scaleModeToGlFilter[style.magFilter]);
2942
+ }
2943
+ if (mipmaps) {
2944
+ if (!firstCreation || style.mipmapFilter !== "linear") {
2945
+ const glFilterMode = mipmapScaleModeToGlFilter[style.minFilter][style.mipmapFilter];
2946
+ gl[glFunctionName](castParam, gl.TEXTURE_MIN_FILTER, glFilterMode);
2947
+ }
2948
+ } else {
2949
+ gl[glFunctionName](castParam, gl.TEXTURE_MIN_FILTER, scaleModeToGlFilter[style.minFilter]);
2950
+ }
2951
+ if (anisotropicExt && style.maxAnisotropy > 1) {
2952
+ const level = Math.min(style.maxAnisotropy, gl.getParameter(anisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
2953
+ gl[glFunctionName](castParam, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, level);
2954
+ }
2955
+ if (style.compare) {
2956
+ gl[glFunctionName](castParam, gl.TEXTURE_COMPARE_FUNC, compareModeToGlCompare[style.compare]);
2957
+ }
2958
+ }
2959
+
2960
+ function mapFormatToGlFormat(gl) {
2961
+ return {
2962
+ // 8-bit formats
2963
+ r8unorm: gl.RED,
2964
+ r8snorm: gl.RED,
2965
+ r8uint: gl.RED,
2966
+ r8sint: gl.RED,
2967
+ // 16-bit formats
2968
+ r16uint: gl.RED,
2969
+ r16sint: gl.RED,
2970
+ r16float: gl.RED,
2971
+ rg8unorm: gl.RG,
2972
+ rg8snorm: gl.RG,
2973
+ rg8uint: gl.RG,
2974
+ rg8sint: gl.RG,
2975
+ // 32-bit formats
2976
+ r32uint: gl.RED,
2977
+ r32sint: gl.RED,
2978
+ r32float: gl.RED,
2979
+ rg16uint: gl.RG,
2980
+ rg16sint: gl.RG,
2981
+ rg16float: gl.RG,
2982
+ rgba8unorm: gl.RGBA,
2983
+ "rgba8unorm-srgb": gl.RGBA,
2984
+ // Packed 32-bit formats
2985
+ rgba8snorm: gl.RGBA,
2986
+ rgba8uint: gl.RGBA,
2987
+ rgba8sint: gl.RGBA,
2988
+ bgra8unorm: gl.RGBA,
2989
+ "bgra8unorm-srgb": gl.RGBA,
2990
+ rgb9e5ufloat: gl.RGB,
2991
+ rgb10a2unorm: gl.RGBA,
2992
+ rg11b10ufloat: gl.RGB,
2993
+ // 64-bit formats
2994
+ rg32uint: gl.RG,
2995
+ rg32sint: gl.RG,
2996
+ rg32float: gl.RG,
2997
+ rgba16uint: gl.RGBA,
2998
+ rgba16sint: gl.RGBA,
2999
+ rgba16float: gl.RGBA,
3000
+ // 128-bit formats
3001
+ rgba32uint: gl.RGBA,
3002
+ rgba32sint: gl.RGBA,
3003
+ rgba32float: gl.RGBA,
3004
+ // Depth/stencil formats
3005
+ stencil8: gl.STENCIL_INDEX8,
3006
+ depth16unorm: gl.DEPTH_COMPONENT,
3007
+ depth24plus: gl.DEPTH_COMPONENT,
3008
+ "depth24plus-stencil8": gl.DEPTH_STENCIL,
3009
+ depth32float: gl.DEPTH_COMPONENT,
3010
+ "depth32float-stencil8": gl.DEPTH_STENCIL
3011
+ };
3012
+ }
3013
+
3014
+ function mapFormatToGlInternalFormat(gl, extensions) {
3015
+ let srgb = {};
3016
+ let bgra8unorm = gl.RGBA;
3017
+ if (!(gl instanceof DOMAdapter.get().getWebGLRenderingContext())) {
3018
+ srgb = {
3019
+ "rgba8unorm-srgb": gl.SRGB8_ALPHA8,
3020
+ "bgra8unorm-srgb": gl.SRGB8_ALPHA8
3021
+ };
3022
+ bgra8unorm = gl.RGBA8;
3023
+ } else if (extensions.srgb) {
3024
+ srgb = {
3025
+ "rgba8unorm-srgb": extensions.srgb.SRGB8_ALPHA8_EXT,
3026
+ "bgra8unorm-srgb": extensions.srgb.SRGB8_ALPHA8_EXT
3027
+ };
3028
+ }
3029
+ return {
3030
+ // 8-bit formats
3031
+ r8unorm: gl.R8,
3032
+ r8snorm: gl.R8_SNORM,
3033
+ r8uint: gl.R8UI,
3034
+ r8sint: gl.R8I,
3035
+ // 16-bit formats
3036
+ r16uint: gl.R16UI,
3037
+ r16sint: gl.R16I,
3038
+ r16float: gl.R16F,
3039
+ rg8unorm: gl.RG8,
3040
+ rg8snorm: gl.RG8_SNORM,
3041
+ rg8uint: gl.RG8UI,
3042
+ rg8sint: gl.RG8I,
3043
+ // 32-bit formats
3044
+ r32uint: gl.R32UI,
3045
+ r32sint: gl.R32I,
3046
+ r32float: gl.R32F,
3047
+ rg16uint: gl.RG16UI,
3048
+ rg16sint: gl.RG16I,
3049
+ rg16float: gl.RG16F,
3050
+ rgba8unorm: gl.RGBA,
3051
+ ...srgb,
3052
+ // Packed 32-bit formats
3053
+ rgba8snorm: gl.RGBA8_SNORM,
3054
+ rgba8uint: gl.RGBA8UI,
3055
+ rgba8sint: gl.RGBA8I,
3056
+ bgra8unorm,
3057
+ rgb9e5ufloat: gl.RGB9_E5,
3058
+ rgb10a2unorm: gl.RGB10_A2,
3059
+ rg11b10ufloat: gl.R11F_G11F_B10F,
3060
+ // 64-bit formats
3061
+ rg32uint: gl.RG32UI,
3062
+ rg32sint: gl.RG32I,
3063
+ rg32float: gl.RG32F,
3064
+ rgba16uint: gl.RGBA16UI,
3065
+ rgba16sint: gl.RGBA16I,
3066
+ rgba16float: gl.RGBA16F,
3067
+ // 128-bit formats
3068
+ rgba32uint: gl.RGBA32UI,
3069
+ rgba32sint: gl.RGBA32I,
3070
+ rgba32float: gl.RGBA32F,
3071
+ // Depth/stencil formats
3072
+ stencil8: gl.STENCIL_INDEX8,
3073
+ depth16unorm: gl.DEPTH_COMPONENT16,
3074
+ depth24plus: gl.DEPTH_COMPONENT24,
3075
+ "depth24plus-stencil8": gl.DEPTH24_STENCIL8,
3076
+ depth32float: gl.DEPTH_COMPONENT32F,
3077
+ "depth32float-stencil8": gl.DEPTH32F_STENCIL8,
3078
+ // Compressed formats
3079
+ ...extensions.s3tc ? {
3080
+ "bc1-rgba-unorm": extensions.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,
3081
+ "bc2-rgba-unorm": extensions.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,
3082
+ "bc3-rgba-unorm": extensions.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
3083
+ } : {},
3084
+ ...extensions.s3tc_sRGB ? {
3085
+ "bc1-rgba-unorm-srgb": extensions.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
3086
+ "bc2-rgba-unorm-srgb": extensions.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
3087
+ "bc3-rgba-unorm-srgb": extensions.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
3088
+ } : {},
3089
+ ...extensions.rgtc ? {
3090
+ "bc4-r-unorm": extensions.rgtc.COMPRESSED_RED_RGTC1_EXT,
3091
+ "bc4-r-snorm": extensions.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,
3092
+ "bc5-rg-unorm": extensions.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,
3093
+ "bc5-rg-snorm": extensions.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
3094
+ } : {},
3095
+ ...extensions.bptc ? {
3096
+ "bc6h-rgb-float": extensions.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
3097
+ "bc6h-rgb-ufloat": extensions.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
3098
+ "bc7-rgba-unorm": extensions.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,
3099
+ "bc7-rgba-unorm-srgb": extensions.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT
3100
+ } : {},
3101
+ ...extensions.etc ? {
3102
+ "etc2-rgb8unorm": extensions.etc.COMPRESSED_RGB8_ETC2,
3103
+ "etc2-rgb8unorm-srgb": extensions.etc.COMPRESSED_SRGB8_ETC2,
3104
+ "etc2-rgb8a1unorm": extensions.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
3105
+ "etc2-rgb8a1unorm-srgb": extensions.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
3106
+ "etc2-rgba8unorm": extensions.etc.COMPRESSED_RGBA8_ETC2_EAC,
3107
+ "etc2-rgba8unorm-srgb": extensions.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
3108
+ "eac-r11unorm": extensions.etc.COMPRESSED_R11_EAC,
3109
+ // 'eac-r11snorm'
3110
+ "eac-rg11unorm": extensions.etc.COMPRESSED_SIGNED_RG11_EAC
3111
+ // 'eac-rg11snorm'
3112
+ } : {},
3113
+ ...extensions.astc ? {
3114
+ "astc-4x4-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,
3115
+ "astc-4x4-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
3116
+ "astc-5x4-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,
3117
+ "astc-5x4-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
3118
+ "astc-5x5-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,
3119
+ "astc-5x5-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
3120
+ "astc-6x5-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,
3121
+ "astc-6x5-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
3122
+ "astc-6x6-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,
3123
+ "astc-6x6-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
3124
+ "astc-8x5-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,
3125
+ "astc-8x5-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
3126
+ "astc-8x6-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,
3127
+ "astc-8x6-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
3128
+ "astc-8x8-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,
3129
+ "astc-8x8-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
3130
+ "astc-10x5-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,
3131
+ "astc-10x5-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
3132
+ "astc-10x6-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,
3133
+ "astc-10x6-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
3134
+ "astc-10x8-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,
3135
+ "astc-10x8-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
3136
+ "astc-10x10-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,
3137
+ "astc-10x10-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
3138
+ "astc-12x10-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,
3139
+ "astc-12x10-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
3140
+ "astc-12x12-unorm": extensions.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,
3141
+ "astc-12x12-unorm-srgb": extensions.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
3142
+ } : {}
3143
+ };
3144
+ }
3145
+
3146
+ function mapFormatToGlType(gl) {
3147
+ return {
3148
+ // 8-bit formats
3149
+ r8unorm: gl.UNSIGNED_BYTE,
3150
+ r8snorm: gl.BYTE,
3151
+ r8uint: gl.UNSIGNED_BYTE,
3152
+ r8sint: gl.BYTE,
3153
+ // 16-bit formats
3154
+ r16uint: gl.UNSIGNED_SHORT,
3155
+ r16sint: gl.SHORT,
3156
+ r16float: gl.HALF_FLOAT,
3157
+ rg8unorm: gl.UNSIGNED_BYTE,
3158
+ rg8snorm: gl.BYTE,
3159
+ rg8uint: gl.UNSIGNED_BYTE,
3160
+ rg8sint: gl.BYTE,
3161
+ // 32-bit formats
3162
+ r32uint: gl.UNSIGNED_INT,
3163
+ r32sint: gl.INT,
3164
+ r32float: gl.FLOAT,
3165
+ rg16uint: gl.UNSIGNED_SHORT,
3166
+ rg16sint: gl.SHORT,
3167
+ rg16float: gl.HALF_FLOAT,
3168
+ rgba8unorm: gl.UNSIGNED_BYTE,
3169
+ "rgba8unorm-srgb": gl.UNSIGNED_BYTE,
3170
+ // Packed 32-bit formats
3171
+ rgba8snorm: gl.BYTE,
3172
+ rgba8uint: gl.UNSIGNED_BYTE,
3173
+ rgba8sint: gl.BYTE,
3174
+ bgra8unorm: gl.UNSIGNED_BYTE,
3175
+ "bgra8unorm-srgb": gl.UNSIGNED_BYTE,
3176
+ rgb9e5ufloat: gl.UNSIGNED_INT_5_9_9_9_REV,
3177
+ rgb10a2unorm: gl.UNSIGNED_INT_2_10_10_10_REV,
3178
+ rg11b10ufloat: gl.UNSIGNED_INT_10F_11F_11F_REV,
3179
+ // 64-bit formats
3180
+ rg32uint: gl.UNSIGNED_INT,
3181
+ rg32sint: gl.INT,
3182
+ rg32float: gl.FLOAT,
3183
+ rgba16uint: gl.UNSIGNED_SHORT,
3184
+ rgba16sint: gl.SHORT,
3185
+ rgba16float: gl.HALF_FLOAT,
3186
+ // 128-bit formats
3187
+ rgba32uint: gl.UNSIGNED_INT,
3188
+ rgba32sint: gl.INT,
3189
+ rgba32float: gl.FLOAT,
3190
+ // Depth/stencil formats
3191
+ stencil8: gl.UNSIGNED_BYTE,
3192
+ depth16unorm: gl.UNSIGNED_SHORT,
3193
+ depth24plus: gl.UNSIGNED_INT,
3194
+ "depth24plus-stencil8": gl.UNSIGNED_INT_24_8,
3195
+ depth32float: gl.FLOAT,
3196
+ "depth32float-stencil8": gl.FLOAT_32_UNSIGNED_INT_24_8_REV
3197
+ };
3198
+ }
3199
+
3200
+ const BYTES_PER_PIXEL = 4;
3201
+ class GlTextureSystem {
3202
+ constructor(renderer) {
3203
+ this.managedTextures = [];
3204
+ this._glTextures = /* @__PURE__ */ Object.create(null);
3205
+ this._glSamplers = /* @__PURE__ */ Object.create(null);
3206
+ this._boundTextures = [];
3207
+ this._activeTextureLocation = -1;
3208
+ this._boundSamplers = /* @__PURE__ */ Object.create(null);
3209
+ this._uploads = {
3210
+ image: glUploadImageResource,
3211
+ buffer: glUploadBufferImageResource,
3212
+ video: glUploadVideoResource,
3213
+ compressed: glUploadCompressedTextureResource
3214
+ };
3215
+ this._premultiplyAlpha = false;
3216
+ // TODO - separate samplers will be a cool thing to add, but not right now!
3217
+ this._useSeparateSamplers = false;
3218
+ this._renderer = renderer;
3219
+ this._renderer.renderableGC.addManagedHash(this, "_glTextures");
3220
+ this._renderer.renderableGC.addManagedHash(this, "_glSamplers");
3221
+ }
3222
+ contextChange(gl) {
3223
+ this._gl = gl;
3224
+ if (!this._mapFormatToInternalFormat) {
3225
+ this._mapFormatToInternalFormat = mapFormatToGlInternalFormat(gl, this._renderer.context.extensions);
3226
+ this._mapFormatToType = mapFormatToGlType(gl);
3227
+ this._mapFormatToFormat = mapFormatToGlFormat(gl);
3228
+ }
3229
+ this._glTextures = /* @__PURE__ */ Object.create(null);
3230
+ this._glSamplers = /* @__PURE__ */ Object.create(null);
3231
+ this._boundSamplers = /* @__PURE__ */ Object.create(null);
3232
+ this._premultiplyAlpha = false;
3233
+ for (let i = 0; i < 16; i++) {
3234
+ this.bind(Texture.EMPTY, i);
3235
+ }
3236
+ }
3237
+ initSource(source) {
3238
+ this.bind(source);
3239
+ }
3240
+ bind(texture, location = 0) {
3241
+ const source = texture.source;
3242
+ if (texture) {
3243
+ this.bindSource(source, location);
3244
+ if (this._useSeparateSamplers) {
3245
+ this._bindSampler(source.style, location);
3246
+ }
3247
+ } else {
3248
+ this.bindSource(null, location);
3249
+ if (this._useSeparateSamplers) {
3250
+ this._bindSampler(null, location);
3251
+ }
3252
+ }
3253
+ }
3254
+ bindSource(source, location = 0) {
3255
+ const gl = this._gl;
3256
+ source._touched = this._renderer.textureGC.count;
3257
+ if (this._boundTextures[location] !== source) {
3258
+ this._boundTextures[location] = source;
3259
+ this._activateLocation(location);
3260
+ source || (source = Texture.EMPTY.source);
3261
+ const glTexture = this.getGlSource(source);
3262
+ gl.bindTexture(glTexture.target, glTexture.texture);
3263
+ }
3264
+ }
3265
+ _bindSampler(style, location = 0) {
3266
+ const gl = this._gl;
3267
+ if (!style) {
3268
+ this._boundSamplers[location] = null;
3269
+ gl.bindSampler(location, null);
3270
+ return;
3271
+ }
3272
+ const sampler = this._getGlSampler(style);
3273
+ if (this._boundSamplers[location] !== sampler) {
3274
+ this._boundSamplers[location] = sampler;
3275
+ gl.bindSampler(location, sampler);
3276
+ }
3277
+ }
3278
+ unbind(texture) {
3279
+ const source = texture.source;
3280
+ const boundTextures = this._boundTextures;
3281
+ const gl = this._gl;
3282
+ for (let i = 0; i < boundTextures.length; i++) {
3283
+ if (boundTextures[i] === source) {
3284
+ this._activateLocation(i);
3285
+ const glTexture = this.getGlSource(source);
3286
+ gl.bindTexture(glTexture.target, null);
3287
+ boundTextures[i] = null;
3288
+ }
3289
+ }
3290
+ }
3291
+ _activateLocation(location) {
3292
+ if (this._activeTextureLocation !== location) {
3293
+ this._activeTextureLocation = location;
3294
+ this._gl.activeTexture(this._gl.TEXTURE0 + location);
3295
+ }
3296
+ }
3297
+ _initSource(source) {
3298
+ const gl = this._gl;
3299
+ const glTexture = new GlTexture(gl.createTexture());
3300
+ glTexture.type = this._mapFormatToType[source.format];
3301
+ glTexture.internalFormat = this._mapFormatToInternalFormat[source.format];
3302
+ glTexture.format = this._mapFormatToFormat[source.format];
3303
+ if (source.autoGenerateMipmaps && (this._renderer.context.supports.nonPowOf2mipmaps || source.isPowerOfTwo)) {
3304
+ const biggestDimension = Math.max(source.width, source.height);
3305
+ source.mipLevelCount = Math.floor(Math.log2(biggestDimension)) + 1;
3306
+ }
3307
+ this._glTextures[source.uid] = glTexture;
3308
+ if (!this.managedTextures.includes(source)) {
3309
+ source.on("update", this.onSourceUpdate, this);
3310
+ source.on("resize", this.onSourceUpdate, this);
3311
+ source.on("styleChange", this.onStyleChange, this);
3312
+ source.on("destroy", this.onSourceDestroy, this);
3313
+ source.on("unload", this.onSourceUnload, this);
3314
+ source.on("updateMipmaps", this.onUpdateMipmaps, this);
3315
+ this.managedTextures.push(source);
3316
+ }
3317
+ this.onSourceUpdate(source);
3318
+ this.updateStyle(source, false);
3319
+ return glTexture;
3320
+ }
3321
+ onStyleChange(source) {
3322
+ this.updateStyle(source, false);
3323
+ }
3324
+ updateStyle(source, firstCreation) {
3325
+ const gl = this._gl;
3326
+ const glTexture = this.getGlSource(source);
3327
+ gl.bindTexture(gl.TEXTURE_2D, glTexture.texture);
3328
+ this._boundTextures[this._activeTextureLocation] = source;
3329
+ applyStyleParams(
3330
+ source.style,
3331
+ gl,
3332
+ source.mipLevelCount > 1,
3333
+ this._renderer.context.extensions.anisotropicFiltering,
3334
+ "texParameteri",
3335
+ gl.TEXTURE_2D,
3336
+ // will force a clamp to edge if the texture is not a power of two
3337
+ !this._renderer.context.supports.nonPowOf2wrapping && !source.isPowerOfTwo,
3338
+ firstCreation
3339
+ );
3340
+ }
3341
+ onSourceUnload(source) {
3342
+ const glTexture = this._glTextures[source.uid];
3343
+ if (!glTexture)
3344
+ return;
3345
+ this.unbind(source);
3346
+ this._glTextures[source.uid] = null;
3347
+ this._gl.deleteTexture(glTexture.texture);
3348
+ }
3349
+ onSourceUpdate(source) {
3350
+ const gl = this._gl;
3351
+ const glTexture = this.getGlSource(source);
3352
+ gl.bindTexture(gl.TEXTURE_2D, glTexture.texture);
3353
+ this._boundTextures[this._activeTextureLocation] = source;
3354
+ const premultipliedAlpha = source.alphaMode === "premultiply-alpha-on-upload";
3355
+ if (this._premultiplyAlpha !== premultipliedAlpha) {
3356
+ this._premultiplyAlpha = premultipliedAlpha;
3357
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultipliedAlpha);
3358
+ }
3359
+ if (this._uploads[source.uploadMethodId]) {
3360
+ this._uploads[source.uploadMethodId].upload(source, glTexture, gl, this._renderer.context.webGLVersion);
3361
+ } else {
3362
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, source.pixelWidth, source.pixelHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
3363
+ }
3364
+ if (source.autoGenerateMipmaps && source.mipLevelCount > 1) {
3365
+ this.onUpdateMipmaps(source, false);
3366
+ }
3367
+ }
3368
+ onUpdateMipmaps(source, bind = true) {
3369
+ if (bind)
3370
+ this.bindSource(source, 0);
3371
+ const glTexture = this.getGlSource(source);
3372
+ this._gl.generateMipmap(glTexture.target);
3373
+ }
3374
+ onSourceDestroy(source) {
3375
+ source.off("destroy", this.onSourceDestroy, this);
3376
+ source.off("update", this.onSourceUpdate, this);
3377
+ source.off("resize", this.onSourceUpdate, this);
3378
+ source.off("unload", this.onSourceUnload, this);
3379
+ source.off("styleChange", this.onStyleChange, this);
3380
+ source.off("updateMipmaps", this.onUpdateMipmaps, this);
3381
+ this.managedTextures.splice(this.managedTextures.indexOf(source), 1);
3382
+ this.onSourceUnload(source);
3383
+ }
3384
+ _initSampler(style) {
3385
+ const gl = this._gl;
3386
+ const glSampler = this._gl.createSampler();
3387
+ this._glSamplers[style._resourceId] = glSampler;
3388
+ applyStyleParams(
3389
+ style,
3390
+ gl,
3391
+ this._boundTextures[this._activeTextureLocation].mipLevelCount > 1,
3392
+ this._renderer.context.extensions.anisotropicFiltering,
3393
+ "samplerParameteri",
3394
+ glSampler,
3395
+ false,
3396
+ true
3397
+ );
3398
+ return this._glSamplers[style._resourceId];
3399
+ }
3400
+ _getGlSampler(sampler) {
3401
+ return this._glSamplers[sampler._resourceId] || this._initSampler(sampler);
3402
+ }
3403
+ getGlSource(source) {
3404
+ return this._glTextures[source.uid] || this._initSource(source);
3405
+ }
3406
+ generateCanvas(texture) {
3407
+ const { pixels, width, height } = this.getPixels(texture);
3408
+ const canvas = DOMAdapter.get().createCanvas();
3409
+ canvas.width = width;
3410
+ canvas.height = height;
3411
+ const ctx = canvas.getContext("2d");
3412
+ if (ctx) {
3413
+ const imageData = ctx.createImageData(width, height);
3414
+ imageData.data.set(pixels);
3415
+ ctx.putImageData(imageData, 0, 0);
3416
+ }
3417
+ return canvas;
3418
+ }
3419
+ getPixels(texture) {
3420
+ const resolution = texture.source.resolution;
3421
+ const frame = texture.frame;
3422
+ const width = Math.max(Math.round(frame.width * resolution), 1);
3423
+ const height = Math.max(Math.round(frame.height * resolution), 1);
3424
+ const pixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
3425
+ const renderer = this._renderer;
3426
+ const renderTarget = renderer.renderTarget.getRenderTarget(texture);
3427
+ const glRenterTarget = renderer.renderTarget.getGpuRenderTarget(renderTarget);
3428
+ const gl = renderer.gl;
3429
+ gl.bindFramebuffer(gl.FRAMEBUFFER, glRenterTarget.resolveTargetFramebuffer);
3430
+ gl.readPixels(
3431
+ Math.round(frame.x * resolution),
3432
+ Math.round(frame.y * resolution),
3433
+ width,
3434
+ height,
3435
+ gl.RGBA,
3436
+ gl.UNSIGNED_BYTE,
3437
+ pixels
3438
+ );
3439
+ return { pixels: new Uint8ClampedArray(pixels.buffer), width, height };
3440
+ }
3441
+ destroy() {
3442
+ this.managedTextures.slice().forEach((source) => this.onSourceDestroy(source));
3443
+ this.managedTextures = null;
3444
+ this._renderer = null;
3445
+ }
3446
+ resetState() {
3447
+ this._activeTextureLocation = -1;
3448
+ this._boundTextures.fill(Texture.EMPTY.source);
3449
+ this._boundSamplers = /* @__PURE__ */ Object.create(null);
3450
+ const gl = this._gl;
3451
+ this._premultiplyAlpha = false;
3452
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._premultiplyAlpha);
3453
+ }
3454
+ }
3455
+ /** @ignore */
3456
+ GlTextureSystem.extension = {
3457
+ type: [
3458
+ ExtensionType.WebGLSystem
3459
+ ],
3460
+ name: "texture"
3461
+ };
3462
+
3463
+ class GlGraphicsAdaptor {
3464
+ init() {
3465
+ const uniforms = new UniformGroup({
3466
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
3467
+ uTransformMatrix: { value: new Matrix(), type: "mat3x3<f32>" },
3468
+ uRound: { value: 0, type: "f32" }
3469
+ });
3470
+ const maxTextures = getMaxTexturesPerBatch();
3471
+ const glProgram = compileHighShaderGlProgram({
3472
+ name: "graphics",
3473
+ bits: [
3474
+ colorBitGl,
3475
+ generateTextureBatchBitGl(maxTextures),
3476
+ localUniformBitGl,
3477
+ roundPixelsBitGl
3478
+ ]
3479
+ });
3480
+ this.shader = new Shader({
3481
+ glProgram,
3482
+ resources: {
3483
+ localUniforms: uniforms,
3484
+ batchSamplers: getBatchSamplersUniformGroup(maxTextures)
3485
+ }
3486
+ });
3487
+ }
3488
+ execute(graphicsPipe, renderable) {
3489
+ const context = renderable.context;
3490
+ const shader = context.customShader || this.shader;
3491
+ const renderer = graphicsPipe.renderer;
3492
+ const contextSystem = renderer.graphicsContext;
3493
+ const {
3494
+ batcher,
3495
+ instructions
3496
+ } = contextSystem.getContextRenderData(context);
3497
+ shader.groups[0] = renderer.globalUniforms.bindGroup;
3498
+ renderer.state.set(graphicsPipe.state);
3499
+ renderer.shader.bind(shader);
3500
+ renderer.geometry.bind(batcher.geometry, shader.glProgram);
3501
+ const batches = instructions.instructions;
3502
+ for (let i = 0; i < instructions.instructionSize; i++) {
3503
+ const batch = batches[i];
3504
+ if (batch.size) {
3505
+ for (let j = 0; j < batch.textures.count; j++) {
3506
+ renderer.texture.bind(batch.textures.textures[j], j);
3507
+ }
3508
+ renderer.geometry.draw(batch.topology, batch.size, batch.start);
3509
+ }
3510
+ }
3511
+ }
3512
+ destroy() {
3513
+ this.shader.destroy(true);
3514
+ this.shader = null;
3515
+ }
3516
+ }
3517
+ /** @ignore */
3518
+ GlGraphicsAdaptor.extension = {
3519
+ type: [
3520
+ ExtensionType.WebGLPipesAdaptor
3521
+ ],
3522
+ name: "graphics"
3523
+ };
3524
+
3525
+ class GlMeshAdaptor {
3526
+ init() {
3527
+ const glProgram = compileHighShaderGlProgram({
3528
+ name: "mesh",
3529
+ bits: [
3530
+ localUniformBitGl,
3531
+ textureBitGl,
3532
+ roundPixelsBitGl
3533
+ ]
3534
+ });
3535
+ this._shader = new Shader({
3536
+ glProgram,
3537
+ resources: {
3538
+ uTexture: Texture.EMPTY.source,
3539
+ textureUniforms: {
3540
+ uTextureMatrix: { type: "mat3x3<f32>", value: new Matrix() }
3541
+ }
3542
+ }
3543
+ });
3544
+ }
3545
+ execute(meshPipe, mesh) {
3546
+ const renderer = meshPipe.renderer;
3547
+ let shader = mesh._shader;
3548
+ if (!shader) {
3549
+ shader = this._shader;
3550
+ const texture = mesh.texture;
3551
+ const source = texture.source;
3552
+ shader.resources.uTexture = source;
3553
+ shader.resources.uSampler = source.style;
3554
+ shader.resources.textureUniforms.uniforms.uTextureMatrix = texture.textureMatrix.mapCoord;
3555
+ } else if (!shader.glProgram) {
3556
+ warn("Mesh shader has no glProgram", mesh.shader);
3557
+ return;
3558
+ }
3559
+ shader.groups[100] = renderer.globalUniforms.bindGroup;
3560
+ shader.groups[101] = meshPipe.localUniformsBindGroup;
3561
+ renderer.encoder.draw({
3562
+ geometry: mesh._geometry,
3563
+ shader,
3564
+ state: mesh.state
3565
+ });
3566
+ }
3567
+ destroy() {
3568
+ this._shader.destroy(true);
3569
+ this._shader = null;
3570
+ }
3571
+ }
3572
+ GlMeshAdaptor.extension = {
3573
+ type: [
3574
+ ExtensionType.WebGLPipesAdaptor
3575
+ ],
3576
+ name: "mesh"
3577
+ };
3578
+
3579
+ const DefaultWebGLSystems = [
3580
+ ...SharedSystems,
3581
+ GlUboSystem,
3582
+ GlBackBufferSystem,
3583
+ GlContextSystem,
3584
+ GlBufferSystem,
3585
+ GlTextureSystem,
3586
+ GlRenderTargetSystem,
3587
+ GlGeometrySystem,
3588
+ GlUniformGroupSystem,
3589
+ GlShaderSystem,
3590
+ GlEncoderSystem,
3591
+ GlStateSystem,
3592
+ GlStencilSystem,
3593
+ GlColorMaskSystem
3594
+ ];
3595
+ const DefaultWebGLPipes = [...SharedRenderPipes];
3596
+ const DefaultWebGLAdapters = [GlBatchAdaptor, GlMeshAdaptor, GlGraphicsAdaptor];
3597
+ const systems = [];
3598
+ const renderPipes = [];
3599
+ const renderPipeAdaptors = [];
3600
+ extensions.handleByNamedList(ExtensionType.WebGLSystem, systems);
3601
+ extensions.handleByNamedList(ExtensionType.WebGLPipes, renderPipes);
3602
+ extensions.handleByNamedList(ExtensionType.WebGLPipesAdaptor, renderPipeAdaptors);
3603
+ extensions.add(...DefaultWebGLSystems, ...DefaultWebGLPipes, ...DefaultWebGLAdapters);
3604
+ class WebGLRenderer extends AbstractRenderer {
3605
+ constructor() {
3606
+ const systemConfig = {
3607
+ name: "webgl",
3608
+ type: RendererType.WEBGL,
3609
+ systems,
3610
+ renderPipes,
3611
+ renderPipeAdaptors
3612
+ };
3613
+ super(systemConfig);
3614
+ }
3615
+ }
3616
+
3617
+ export { WebGLRenderer };