@luma.gl/webgl 9.0.0-alpha.24 → 9.0.0-alpha.26

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 (128) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +1 -1
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +1 -1
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  6. package/dist/adapter/converters/texture-formats.d.ts +1 -1
  7. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  8. package/dist/adapter/converters/texture-formats.js +1 -1
  9. package/dist/adapter/converters/texture-formats.js.map +1 -1
  10. package/dist/adapter/converters/vertex-formats.d.ts +1 -1
  11. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  12. package/dist/adapter/converters/vertex-formats.js +1 -1
  13. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  14. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.d.ts +1 -1
  16. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  17. package/dist/adapter/device-helpers/device-limits.js +1 -1
  18. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  19. package/dist/adapter/device-helpers/get-device-info.js +1 -1
  20. package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
  21. package/dist/adapter/helpers/attribute-utils.js.map +1 -1
  22. package/dist/adapter/helpers/get-shader-layout.js +1 -1
  23. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  24. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
  25. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  26. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  27. package/dist/adapter/helpers/set-uniform.js +1 -1
  28. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  29. package/dist/adapter/helpers/uniforms.js.map +1 -1
  30. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  31. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  32. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  33. package/dist/adapter/objects/webgl-renderbuffer.d.ts +1 -1
  34. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  35. package/dist/adapter/objects/webgl-renderbuffer.js +1 -1
  36. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  37. package/dist/adapter/objects/webgl-resource.d.ts +1 -1
  38. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  39. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  40. package/dist/adapter/objects/webgl-vertex-array-object.js +1 -1
  41. package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  42. package/dist/adapter/resources/webgl-buffer.js +1 -1
  43. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  44. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  45. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  46. package/dist/adapter/resources/webgl-command-buffer.js +1 -1
  47. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  48. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  49. package/dist/adapter/resources/webgl-framebuffer.d.ts +1 -1
  50. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.js +1 -1
  52. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  53. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  54. package/dist/adapter/resources/webgl-render-pipeline.js +1 -1
  55. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  56. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  57. package/dist/adapter/resources/webgl-shader.js +1 -1
  58. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  59. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  60. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  61. package/dist/adapter/webgl-canvas-context.js +1 -0
  62. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  63. package/dist/adapter/webgl-device.js +2 -2
  64. package/dist/adapter/webgl-device.js.map +1 -1
  65. package/dist/classic/accessor.d.ts +1 -1
  66. package/dist/classic/accessor.d.ts.map +1 -1
  67. package/dist/classic/accessor.js +1 -1
  68. package/dist/classic/accessor.js.map +1 -1
  69. package/dist/classic/{buffer.d.ts → buffer-with-accessor.d.ts} +8 -8
  70. package/dist/classic/buffer-with-accessor.d.ts.map +1 -0
  71. package/dist/classic/{buffer.js → buffer-with-accessor.js} +3 -3
  72. package/dist/classic/buffer-with-accessor.js.map +1 -0
  73. package/dist/classic/clear.js.map +1 -1
  74. package/dist/classic/copy-and-blit.d.ts +18 -1
  75. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  76. package/dist/classic/copy-and-blit.js +69 -3
  77. package/dist/classic/copy-and-blit.js.map +1 -1
  78. package/dist/classic/format-utils.js +1 -1
  79. package/dist/classic/format-utils.js.map +1 -1
  80. package/dist/classic/typed-array-utils.js.map +1 -1
  81. package/dist/context/context/create-browser-context.js.map +1 -1
  82. package/dist/context/debug/spector.js.map +1 -1
  83. package/dist/context/debug/webgl-developer-tools.js +1 -1
  84. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  85. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  86. package/dist/context/polyfill/get-parameter-polyfill.js +3 -3
  87. package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
  88. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  89. package/dist/context/polyfill/polyfill-table.js +1 -1
  90. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  91. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +1 -1
  92. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  93. package/dist/dist.dev.js +687 -649
  94. package/dist/index.cjs +1120 -1037
  95. package/dist/index.d.ts +3 -3
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +2 -2
  98. package/dist/index.js.map +1 -1
  99. package/dist.min.js +22 -22
  100. package/package.json +5 -5
  101. package/src/adapter/converters/device-parameters.ts +1 -1
  102. package/src/adapter/converters/texture-formats.ts +1 -1
  103. package/src/adapter/converters/vertex-formats.ts +1 -1
  104. package/src/adapter/device-helpers/device-limits.ts +1 -1
  105. package/src/adapter/device-helpers/get-device-info.ts +1 -1
  106. package/src/adapter/helpers/get-shader-layout.ts +1 -1
  107. package/src/adapter/helpers/set-uniform.ts +1 -1
  108. package/src/adapter/objects/constants-to-keys.ts +1 -1
  109. package/src/adapter/objects/webgl-renderbuffer.ts +1 -1
  110. package/src/adapter/objects/webgl-resource.ts +1 -1
  111. package/src/adapter/objects/webgl-vertex-array-object.ts +1 -1
  112. package/src/adapter/resources/webgl-buffer.ts +1 -1
  113. package/src/adapter/resources/webgl-command-buffer.ts +1 -1
  114. package/src/adapter/resources/webgl-framebuffer.ts +1 -1
  115. package/src/adapter/resources/webgl-render-pipeline.ts +1 -1
  116. package/src/adapter/resources/webgl-shader.ts +1 -1
  117. package/src/adapter/webgl-canvas-context.ts +2 -1
  118. package/src/adapter/webgl-device.ts +2 -2
  119. package/src/classic/accessor.ts +1 -1
  120. package/src/classic/{buffer.ts → buffer-with-accessor.ts} +9 -9
  121. package/src/classic/copy-and-blit.ts +122 -2
  122. package/src/classic/format-utils.ts +1 -1
  123. package/src/context/debug/webgl-developer-tools.ts +1 -1
  124. package/src/context/polyfill/get-parameter-polyfill.ts +1 -1
  125. package/src/context/polyfill/polyfill-table.ts +1 -1
  126. package/src/index.ts +3 -3
  127. package/dist/classic/buffer.d.ts.map +0 -1
  128. package/dist/classic/buffer.js.map +0 -1
package/dist/dist.dev.js CHANGED
@@ -32,8 +32,7 @@ var __exports__ = (() => {
32
32
  var src_exports = {};
33
33
  __export(src_exports, {
34
34
  Accessor: () => Accessor,
35
- Buffer: () => ClassicBuffer,
36
- ClassicBuffer: () => ClassicBuffer,
35
+ BufferWithAccessor: () => BufferWithAccessor,
37
36
  WEBGLBuffer: () => WEBGLBuffer,
38
37
  WEBGLCommandEncoder: () => WEBGLCommandEncoder,
39
38
  WEBGLFramebuffer: () => WEBGLFramebuffer,
@@ -54,6 +53,7 @@ var __exports__ = (() => {
54
53
  assertWebGLContext: () => assertWebGLContext,
55
54
  clear: () => clear,
56
55
  convertGLToTextureFormat: () => convertGLToTextureFormat,
56
+ copyToTexture: () => copyToTexture,
57
57
  getParameters: () => getParameters,
58
58
  getProgramBindings: () => getProgramBindings,
59
59
  getShaderLayout: () => getShaderLayout,
@@ -107,11 +107,11 @@ var __exports__ = (() => {
107
107
  if (!headlessGL) {
108
108
  throw new Error(ERR_HEADLESSGL_LOAD);
109
109
  }
110
- const gl = headlessGL(width, height, options);
111
- if (!gl) {
110
+ const gl2 = headlessGL(width, height, options);
111
+ if (!gl2) {
112
112
  throw new Error(ERR_HEADLESSGL_FAILED);
113
113
  }
114
- return gl;
114
+ return gl2;
115
115
  }
116
116
 
117
117
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
@@ -178,52 +178,6 @@ var __exports__ = (() => {
178
178
  return "Unknown";
179
179
  }
180
180
 
181
- // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
182
- function _typeof(obj) {
183
- "@babel/helpers - typeof";
184
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
185
- return typeof obj2;
186
- } : function(obj2) {
187
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
188
- }, _typeof(obj);
189
- }
190
-
191
- // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
192
- function _toPrimitive(input, hint2) {
193
- if (_typeof(input) !== "object" || input === null)
194
- return input;
195
- var prim = input[Symbol.toPrimitive];
196
- if (prim !== void 0) {
197
- var res = prim.call(input, hint2 || "default");
198
- if (_typeof(res) !== "object")
199
- return res;
200
- throw new TypeError("@@toPrimitive must return a primitive value.");
201
- }
202
- return (hint2 === "string" ? String : Number)(input);
203
- }
204
-
205
- // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
206
- function _toPropertyKey(arg) {
207
- var key = _toPrimitive(arg, "string");
208
- return _typeof(key) === "symbol" ? key : String(key);
209
- }
210
-
211
- // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
212
- function _defineProperty(obj, key, value) {
213
- key = _toPropertyKey(key);
214
- if (key in obj) {
215
- Object.defineProperty(obj, key, {
216
- value,
217
- enumerable: true,
218
- configurable: true,
219
- writable: true
220
- });
221
- } else {
222
- obj[key] = value;
223
- }
224
- return obj;
225
- }
226
-
227
181
  // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
228
182
  function getStorage(type) {
229
183
  try {
@@ -239,9 +193,9 @@ var __exports__ = (() => {
239
193
  var LocalStorage = class {
240
194
  constructor(id, defaultConfig) {
241
195
  let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
242
- _defineProperty(this, "storage", void 0);
243
- _defineProperty(this, "id", void 0);
244
- _defineProperty(this, "config", void 0);
196
+ this.storage = void 0;
197
+ this.id = void 0;
198
+ this.config = void 0;
245
199
  this.storage = getStorage(type);
246
200
  this.id = id;
247
201
  this.config = defaultConfig;
@@ -405,13 +359,13 @@ var __exports__ = (() => {
405
359
  } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
406
360
  id: ""
407
361
  };
408
- _defineProperty(this, "id", void 0);
409
- _defineProperty(this, "VERSION", VERSION);
410
- _defineProperty(this, "_startTs", getHiResTimestamp());
411
- _defineProperty(this, "_deltaTs", getHiResTimestamp());
412
- _defineProperty(this, "_storage", void 0);
413
- _defineProperty(this, "userData", {});
414
- _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
362
+ this.id = void 0;
363
+ this.VERSION = VERSION;
364
+ this._startTs = getHiResTimestamp();
365
+ this._deltaTs = getHiResTimestamp();
366
+ this._storage = void 0;
367
+ this.userData = {};
368
+ this.LOG_THROTTLE_TIMEOUT = 0;
415
369
  this.id = id;
416
370
  this.userData = {};
417
371
  this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
@@ -609,7 +563,7 @@ var __exports__ = (() => {
609
563
  return noop;
610
564
  }
611
565
  };
612
- _defineProperty(Log, "VERSION", VERSION);
566
+ Log.VERSION = VERSION;
613
567
  function normalizeLogLevel(logLevel) {
614
568
  if (!logLevel) {
615
569
  return 0;
@@ -740,20 +694,20 @@ var __exports__ = (() => {
740
694
  // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
741
695
  var Stat = class {
742
696
  constructor(name, type) {
743
- _defineProperty(this, "name", void 0);
744
- _defineProperty(this, "type", void 0);
745
- _defineProperty(this, "sampleSize", 1);
746
- _defineProperty(this, "time", 0);
747
- _defineProperty(this, "count", 0);
748
- _defineProperty(this, "samples", 0);
749
- _defineProperty(this, "lastTiming", 0);
750
- _defineProperty(this, "lastSampleTime", 0);
751
- _defineProperty(this, "lastSampleCount", 0);
752
- _defineProperty(this, "_count", 0);
753
- _defineProperty(this, "_time", 0);
754
- _defineProperty(this, "_samples", 0);
755
- _defineProperty(this, "_startTime", 0);
756
- _defineProperty(this, "_timerPending", false);
697
+ this.name = void 0;
698
+ this.type = void 0;
699
+ this.sampleSize = 1;
700
+ this.time = 0;
701
+ this.count = 0;
702
+ this.samples = 0;
703
+ this.lastTiming = 0;
704
+ this.lastSampleTime = 0;
705
+ this.lastSampleCount = 0;
706
+ this._count = 0;
707
+ this._time = 0;
708
+ this._samples = 0;
709
+ this._startTime = 0;
710
+ this._timerPending = false;
757
711
  this.name = name;
758
712
  this.type = type;
759
713
  this.reset();
@@ -852,8 +806,8 @@ var __exports__ = (() => {
852
806
  // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
853
807
  var Stats = class {
854
808
  constructor(options) {
855
- _defineProperty(this, "id", void 0);
856
- _defineProperty(this, "stats", {});
809
+ this.id = void 0;
810
+ this.stats = {};
857
811
  this.id = options.id;
858
812
  this.stats = {};
859
813
  this._initializeStats(options.stats);
@@ -1296,9 +1250,9 @@ var __exports__ = (() => {
1296
1250
  };
1297
1251
  if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
1298
1252
  if (props.data instanceof Uint32Array) {
1299
- props.indexType = "uint32";
1253
+ newProps.indexType = "uint32";
1300
1254
  } else if (props.data instanceof Uint16Array) {
1301
- props.indexType = "uint16";
1255
+ newProps.indexType = "uint16";
1302
1256
  }
1303
1257
  }
1304
1258
  return newProps;
@@ -1450,7 +1404,7 @@ var __exports__ = (() => {
1450
1404
  * Use devicePixelRatio to set canvas width and height
1451
1405
  * @note this is a raw port of luma.gl v8 code. Might be worth a review
1452
1406
  */
1453
- setDevicePixelRatio(devicePixelRatio2, options = {}) {
1407
+ setDevicePixelRatio(devicePixelRatio, options = {}) {
1454
1408
  if (!this.htmlCanvas) {
1455
1409
  return;
1456
1410
  }
@@ -1458,13 +1412,13 @@ var __exports__ = (() => {
1458
1412
  let clientHeight = "height" in options ? options.height : this.htmlCanvas.clientHeight;
1459
1413
  if (!clientWidth || !clientHeight) {
1460
1414
  log.log(1, "Canvas clientWidth/clientHeight is 0")();
1461
- devicePixelRatio2 = 1;
1415
+ devicePixelRatio = 1;
1462
1416
  clientWidth = this.htmlCanvas.width || 1;
1463
1417
  clientHeight = this.htmlCanvas.height || 1;
1464
1418
  }
1465
1419
  const cachedSize = this._canvasSizeInfo;
1466
- if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio2) {
1467
- let clampedPixelRatio = devicePixelRatio2;
1420
+ if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio) {
1421
+ let clampedPixelRatio = devicePixelRatio;
1468
1422
  const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
1469
1423
  const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
1470
1424
  this.htmlCanvas.width = canvasWidth;
@@ -1478,17 +1432,17 @@ var __exports__ = (() => {
1478
1432
  }
1479
1433
  this._canvasSizeInfo.clientWidth = clientWidth;
1480
1434
  this._canvasSizeInfo.clientHeight = clientHeight;
1481
- this._canvasSizeInfo.devicePixelRatio = devicePixelRatio2;
1435
+ this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
1482
1436
  }
1483
1437
  }
1484
1438
  // PRIVATE
1485
1439
  /** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
1486
1440
  getDrawingBufferSize() {
1487
- const gl = this.device.gl;
1488
- if (!gl) {
1441
+ const gl2 = this.device.gl;
1442
+ if (!gl2) {
1489
1443
  throw new Error("canvas size");
1490
1444
  }
1491
- return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1445
+ return [gl2.drawingBufferWidth, gl2.drawingBufferHeight];
1492
1446
  }
1493
1447
  /** Perform platform specific updates (WebGPU vs WebGL) */
1494
1448
  /**
@@ -1911,7 +1865,11 @@ var __exports__ = (() => {
1911
1865
  constructor(device, props) {
1912
1866
  super(device, props, _RenderPass.defaultProps);
1913
1867
  }
1914
- /** A small set of parameters can be changed between every draw call (viewport, scissorRect, blendColor, stencilReference) */
1868
+ /** Call when rendering is done in this pass. */
1869
+ /**
1870
+ * A small set of parameters can be changed between every draw call
1871
+ * (viewport, scissorRect, blendColor, stencilReference)
1872
+ */
1915
1873
  // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
1916
1874
  // beginOcclusionQuery(queryIndex: number): void;
1917
1875
  // endOcclusionQuery(): void;
@@ -2316,43 +2274,43 @@ var __exports__ = (() => {
2316
2274
  error(opt_msg);
2317
2275
  }
2318
2276
  }
2319
- function wrapGLError(gl) {
2320
- const f = gl.getError;
2321
- gl.getError = function getError() {
2277
+ function wrapGLError(gl2) {
2278
+ const f = gl2.getError;
2279
+ gl2.getError = function getError() {
2322
2280
  let err;
2323
2281
  do {
2324
- err = f.apply(gl);
2325
- if (err !== gl.NO_ERROR) {
2282
+ err = f.apply(gl2);
2283
+ if (err !== gl2.NO_ERROR) {
2326
2284
  glErrorShadow[err] = true;
2327
2285
  }
2328
- } while (err !== gl.NO_ERROR);
2286
+ } while (err !== gl2.NO_ERROR);
2329
2287
  for (err in glErrorShadow) {
2330
2288
  if (glErrorShadow[err]) {
2331
2289
  delete glErrorShadow[err];
2332
2290
  return parseInt(err, 10);
2333
2291
  }
2334
2292
  }
2335
- return gl.NO_ERROR;
2293
+ return gl2.NO_ERROR;
2336
2294
  };
2337
2295
  }
2338
2296
  var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
2339
- const gl = ext.gl;
2297
+ const gl2 = ext.gl;
2340
2298
  this.ext = ext;
2341
2299
  this.isAlive = true;
2342
2300
  this.hasBeenBound = false;
2343
2301
  this.elementArrayBuffer = null;
2344
2302
  this.attribs = new Array(ext.maxVertexAttribs);
2345
2303
  for (let n = 0; n < this.attribs.length; n++) {
2346
- const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl);
2304
+ const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
2347
2305
  this.attribs[n] = attrib;
2348
2306
  }
2349
2307
  this.maxAttrib = 0;
2350
2308
  };
2351
- WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
2309
+ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
2352
2310
  this.enabled = false;
2353
2311
  this.buffer = null;
2354
2312
  this.size = 4;
2355
- this.type = gl.FLOAT;
2313
+ this.type = gl2.FLOAT;
2356
2314
  this.normalized = false;
2357
2315
  this.stride = 16;
2358
2316
  this.offset = 0;
@@ -2362,19 +2320,19 @@ var __exports__ = (() => {
2362
2320
  WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
2363
2321
  this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
2364
2322
  };
2365
- var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
2323
+ var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
2366
2324
  const self = this;
2367
- this.gl = gl;
2368
- wrapGLError(gl);
2325
+ this.gl = gl2;
2326
+ wrapGLError(gl2);
2369
2327
  const original = this.original = {
2370
- getParameter: gl.getParameter,
2371
- enableVertexAttribArray: gl.enableVertexAttribArray,
2372
- disableVertexAttribArray: gl.disableVertexAttribArray,
2373
- bindBuffer: gl.bindBuffer,
2374
- getVertexAttrib: gl.getVertexAttrib,
2375
- vertexAttribPointer: gl.vertexAttribPointer
2328
+ getParameter: gl2.getParameter,
2329
+ enableVertexAttribArray: gl2.enableVertexAttribArray,
2330
+ disableVertexAttribArray: gl2.disableVertexAttribArray,
2331
+ bindBuffer: gl2.bindBuffer,
2332
+ getVertexAttrib: gl2.getVertexAttrib,
2333
+ vertexAttribPointer: gl2.vertexAttribPointer
2376
2334
  };
2377
- gl.getParameter = function getParameter(pname) {
2335
+ gl2.getParameter = function getParameter(pname) {
2378
2336
  if (pname === self.VERTEX_ARRAY_BINDING_OES) {
2379
2337
  if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
2380
2338
  return null;
@@ -2383,53 +2341,53 @@ var __exports__ = (() => {
2383
2341
  }
2384
2342
  return original.getParameter.apply(this, arguments);
2385
2343
  };
2386
- gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
2344
+ gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
2387
2345
  const vao = self.currentVertexArrayObject;
2388
2346
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2389
2347
  const attrib = vao.attribs[index];
2390
2348
  attrib.enabled = true;
2391
2349
  return original.enableVertexAttribArray.apply(this, arguments);
2392
2350
  };
2393
- gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
2351
+ gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
2394
2352
  const vao = self.currentVertexArrayObject;
2395
2353
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2396
2354
  const attrib = vao.attribs[index];
2397
2355
  attrib.enabled = false;
2398
2356
  return original.disableVertexAttribArray.apply(this, arguments);
2399
2357
  };
2400
- gl.bindBuffer = function bindBuffer2(target, buffer) {
2358
+ gl2.bindBuffer = function bindBuffer2(target, buffer) {
2401
2359
  switch (target) {
2402
- case gl.ARRAY_BUFFER:
2360
+ case gl2.ARRAY_BUFFER:
2403
2361
  self.currentArrayBuffer = buffer;
2404
2362
  break;
2405
- case gl.ELEMENT_ARRAY_BUFFER:
2363
+ case gl2.ELEMENT_ARRAY_BUFFER:
2406
2364
  self.currentVertexArrayObject.elementArrayBuffer = buffer;
2407
2365
  break;
2408
2366
  default:
2409
2367
  }
2410
2368
  return original.bindBuffer.apply(this, arguments);
2411
2369
  };
2412
- gl.getVertexAttrib = function getVertexAttrib(index, pname) {
2370
+ gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
2413
2371
  const vao = self.currentVertexArrayObject;
2414
2372
  const attrib = vao.attribs[index];
2415
2373
  switch (pname) {
2416
- case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2374
+ case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2417
2375
  return attrib.buffer;
2418
- case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
2376
+ case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
2419
2377
  return attrib.enabled;
2420
- case gl.VERTEX_ATTRIB_ARRAY_SIZE:
2378
+ case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
2421
2379
  return attrib.size;
2422
- case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
2380
+ case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
2423
2381
  return attrib.stride;
2424
- case gl.VERTEX_ATTRIB_ARRAY_TYPE:
2382
+ case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
2425
2383
  return attrib.type;
2426
- case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2384
+ case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2427
2385
  return attrib.normalized;
2428
2386
  default:
2429
2387
  return original.getVertexAttrib.apply(this, arguments);
2430
2388
  }
2431
2389
  };
2432
- gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2390
+ gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2433
2391
  const vao = self.currentVertexArrayObject;
2434
2392
  vao.maxAttrib = Math.max(vao.maxAttrib, indx);
2435
2393
  const attrib = vao.attribs[indx];
@@ -2442,11 +2400,11 @@ var __exports__ = (() => {
2442
2400
  attrib.recache();
2443
2401
  return original.vertexAttribPointer.apply(this, arguments);
2444
2402
  };
2445
- if (gl.instrumentExtension) {
2446
- gl.instrumentExtension(this, "OES_vertex_array_object");
2403
+ if (gl2.instrumentExtension) {
2404
+ gl2.instrumentExtension(this, "OES_vertex_array_object");
2447
2405
  }
2448
- if (gl.canvas) {
2449
- gl.canvas.addEventListener("webglcontextrestored", () => {
2406
+ if (gl2.canvas) {
2407
+ gl2.canvas.addEventListener("webglcontextrestored", () => {
2450
2408
  log2("OESVertexArrayObject emulation library context restored");
2451
2409
  self.reset_();
2452
2410
  }, true);
@@ -2461,8 +2419,8 @@ var __exports__ = (() => {
2461
2419
  this.vertexArrayObjects.isAlive = false;
2462
2420
  }
2463
2421
  }
2464
- const gl = this.gl;
2465
- this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
2422
+ const gl2 = this.gl;
2423
+ this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
2466
2424
  this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
2467
2425
  this.currentVertexArrayObject = null;
2468
2426
  this.currentArrayBuffer = null;
@@ -2490,9 +2448,9 @@ var __exports__ = (() => {
2490
2448
  return false;
2491
2449
  };
2492
2450
  OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
2493
- const gl = this.gl;
2451
+ const gl2 = this.gl;
2494
2452
  if (arrayObject && !arrayObject.isAlive) {
2495
- synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2453
+ synthesizeGLError(gl2.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2496
2454
  return;
2497
2455
  }
2498
2456
  const original = this.original;
@@ -2504,7 +2462,7 @@ var __exports__ = (() => {
2504
2462
  return;
2505
2463
  }
2506
2464
  if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
2507
- original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2465
+ original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2508
2466
  }
2509
2467
  let currentBinding = this.currentArrayBuffer;
2510
2468
  const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
@@ -2513,43 +2471,43 @@ var __exports__ = (() => {
2513
2471
  const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
2514
2472
  if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
2515
2473
  if (attrib.enabled) {
2516
- original.enableVertexAttribArray.call(gl, n);
2474
+ original.enableVertexAttribArray.call(gl2, n);
2517
2475
  } else {
2518
- original.disableVertexAttribArray.call(gl, n);
2476
+ original.disableVertexAttribArray.call(gl2, n);
2519
2477
  }
2520
2478
  }
2521
2479
  if (attrib.enabled) {
2522
2480
  let bufferChanged = false;
2523
2481
  if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
2524
2482
  if (currentBinding !== attrib.buffer) {
2525
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
2483
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
2526
2484
  currentBinding = attrib.buffer;
2527
2485
  }
2528
2486
  bufferChanged = true;
2529
2487
  }
2530
2488
  if (bufferChanged || attrib.cached !== oldAttrib.cached) {
2531
- original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2489
+ original.vertexAttribPointer.call(gl2, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2532
2490
  }
2533
2491
  }
2534
2492
  }
2535
2493
  if (this.currentArrayBuffer !== currentBinding) {
2536
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
2494
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
2537
2495
  }
2538
2496
  };
2539
- function polyfillVertexArrayObject(gl) {
2540
- if (typeof gl.createVertexArray === "function") {
2497
+ function polyfillVertexArrayObject(gl2) {
2498
+ if (typeof gl2.createVertexArray === "function") {
2541
2499
  return;
2542
2500
  }
2543
- const original_getSupportedExtensions = gl.getSupportedExtensions;
2544
- gl.getSupportedExtensions = function getSupportedExtensions() {
2501
+ const original_getSupportedExtensions = gl2.getSupportedExtensions;
2502
+ gl2.getSupportedExtensions = function getSupportedExtensions() {
2545
2503
  const list = original_getSupportedExtensions.call(this) || [];
2546
2504
  if (list.indexOf("OES_vertex_array_object") < 0) {
2547
2505
  list.push("OES_vertex_array_object");
2548
2506
  }
2549
2507
  return list;
2550
2508
  };
2551
- const original_getExtension = gl.getExtension;
2552
- gl.getExtension = function getExtension(name) {
2509
+ const original_getExtension = gl2.getExtension;
2510
+ gl2.getExtension = function getExtension(name) {
2553
2511
  const ext = original_getExtension.call(this, name);
2554
2512
  if (ext) {
2555
2513
  return ext;
@@ -2557,7 +2515,7 @@ var __exports__ = (() => {
2557
2515
  if (name !== "OES_vertex_array_object") {
2558
2516
  return null;
2559
2517
  }
2560
- if (!gl.__OESVertexArrayObject) {
2518
+ if (!gl2.__OESVertexArrayObject) {
2561
2519
  this.__OESVertexArrayObject = new OESVertexArrayObject(this);
2562
2520
  }
2563
2521
  return this.__OESVertexArrayObject;
@@ -3234,31 +3192,31 @@ var __exports__ = (() => {
3234
3192
  // src/context/context/webgl-checks.ts
3235
3193
  var ERR_CONTEXT = "Invalid WebGLRenderingContext";
3236
3194
  var ERR_WEBGL2 = "Requires WebGL2";
3237
- function isWebGL(gl) {
3238
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
3195
+ function isWebGL(gl2) {
3196
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
3239
3197
  return true;
3240
3198
  }
3241
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3199
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3242
3200
  return true;
3243
3201
  }
3244
- return Boolean(gl && Number.isFinite(gl._version));
3202
+ return Boolean(gl2 && Number.isFinite(gl2._version));
3245
3203
  }
3246
- function isWebGL2(gl) {
3247
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3204
+ function isWebGL2(gl2) {
3205
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3248
3206
  return true;
3249
3207
  }
3250
- return Boolean(gl && gl._version === 2);
3208
+ return Boolean(gl2 && gl2._version === 2);
3251
3209
  }
3252
- function getWebGL2Context(gl) {
3253
- return isWebGL2(gl) ? gl : null;
3210
+ function getWebGL2Context(gl2) {
3211
+ return isWebGL2(gl2) ? gl2 : null;
3254
3212
  }
3255
- function assertWebGLContext(gl) {
3256
- assert2(isWebGL(gl), ERR_CONTEXT);
3257
- return gl;
3213
+ function assertWebGLContext(gl2) {
3214
+ assert2(isWebGL(gl2), ERR_CONTEXT);
3215
+ return gl2;
3258
3216
  }
3259
- function assertWebGL2Context(gl) {
3260
- assert2(isWebGL2(gl), ERR_WEBGL2);
3261
- return gl;
3217
+ function assertWebGL2Context(gl2) {
3218
+ assert2(isWebGL2(gl2), ERR_WEBGL2);
3219
+ return gl2;
3262
3220
  }
3263
3221
 
3264
3222
  // src/context/polyfill/get-parameter-polyfill.ts
@@ -3274,39 +3232,39 @@ var __exports__ = (() => {
3274
3232
  var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
3275
3233
  var GL_UNMASKED_VENDOR_WEBGL = 37445;
3276
3234
  var GL_UNMASKED_RENDERER_WEBGL = 37446;
3277
- var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
3235
+ var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
3278
3236
  var WEBGL_PARAMETERS = {
3279
- [GL.READ_BUFFER]: (gl) => !isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : void 0,
3237
+ [GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? GL.COLOR_ATTACHMENT0 : void 0,
3280
3238
  // WebGL2 context parameters
3281
- [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => !isWebGL2(gl) ? GL_DONT_CARE : void 0,
3239
+ [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
3282
3240
  [GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
3283
3241
  [GL.SAMPLES]: getWebGL2ValueOrZero,
3284
3242
  // WebGL2 extension context parameters
3285
- [GL_GPU_DISJOINT_EXT]: (gl, getParameter) => {
3286
- const ext = isWebGL2(gl) ? gl.getExtension(EXT_disjoint_timer_query_webgl2) : gl.getExtension(EXT_disjoint_timer_query);
3243
+ [GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
3244
+ const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
3287
3245
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
3288
3246
  },
3289
3247
  // Extension fixed values
3290
- [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
3291
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3248
+ [GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
3249
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3292
3250
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GL.VENDOR);
3293
3251
  },
3294
- [GL_UNMASKED_RENDERER_WEBGL]: (gl, getParameter) => {
3295
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3252
+ [GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
3253
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3296
3254
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GL.RENDERER);
3297
3255
  },
3298
3256
  // Extension LIMITS
3299
- [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl, getParameter) => {
3300
- const ext = gl.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl.getExtension("EXT_texture_filter_anisotropic");
3257
+ [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
3258
+ const ext = gl2.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl2.getExtension("EXT_texture_filter_anisotropic");
3301
3259
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
3302
3260
  },
3303
3261
  // WebGL2 Limits
3304
3262
  [GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
3305
3263
  [GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
3306
3264
  [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
3307
- [GL.MAX_COLOR_ATTACHMENTS]: (gl, getParameter) => {
3308
- if (!isWebGL2(gl)) {
3309
- const ext = gl.getExtension(WEBGL_draw_buffers);
3265
+ [GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
3266
+ if (!isWebGL2(gl2)) {
3267
+ const ext = gl2.getExtension(WEBGL_draw_buffers);
3310
3268
  return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
3311
3269
  }
3312
3270
  return void 0;
@@ -3314,24 +3272,24 @@ var __exports__ = (() => {
3314
3272
  [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3315
3273
  [GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
3316
3274
  [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3317
- [GL.MAX_DRAW_BUFFERS]: (gl) => {
3318
- if (!isWebGL2(gl)) {
3319
- const ext = gl.getExtension(WEBGL_draw_buffers);
3275
+ [GL.MAX_DRAW_BUFFERS]: (gl2) => {
3276
+ if (!isWebGL2(gl2)) {
3277
+ const ext = gl2.getExtension(WEBGL_draw_buffers);
3320
3278
  return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
3321
3279
  }
3322
3280
  return void 0;
3323
3281
  },
3324
3282
  [GL.MAX_ELEMENT_INDEX]: (
3325
3283
  // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
3326
- (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
3284
+ (gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
3327
3285
  ),
3328
3286
  [GL.MAX_ELEMENTS_INDICES]: (
3329
3287
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3330
- (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
3288
+ (gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
3331
3289
  ),
3332
3290
  [GL.MAX_ELEMENTS_VERTICES]: (
3333
3291
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3334
- (gl) => 16777216
3292
+ (gl2) => 16777216
3335
3293
  ),
3336
3294
  [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
3337
3295
  [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
@@ -3352,24 +3310,24 @@ var __exports__ = (() => {
3352
3310
  [GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
3353
3311
  [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
3354
3312
  };
3355
- function getParameterPolyfill(gl, originalGetParameter, pname) {
3313
+ function getParameterPolyfill(gl2, originalGetParameter, pname) {
3356
3314
  const limit = WEBGL_PARAMETERS[pname];
3357
- const value = typeof limit === "function" ? limit(gl, originalGetParameter, pname) : limit;
3315
+ const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
3358
3316
  const result = value !== void 0 ? value : originalGetParameter(pname);
3359
3317
  return result;
3360
3318
  }
3361
3319
 
3362
3320
  // src/context/polyfill/context-data.ts
3363
- function getContextData(gl) {
3364
- const luma = gl.luma;
3321
+ function getContextData(gl2) {
3322
+ const luma = gl2.luma;
3365
3323
  if (!luma) {
3366
3324
  const contextState = {
3367
3325
  _polyfilled: false,
3368
3326
  _extensions: {}
3369
3327
  };
3370
- gl.luma = contextState;
3328
+ gl2.luma = contextState;
3371
3329
  }
3372
- return gl.luma;
3330
+ return gl2.luma;
3373
3331
  }
3374
3332
 
3375
3333
  // src/context/polyfill/polyfill-table.ts
@@ -3379,10 +3337,10 @@ var __exports__ = (() => {
3379
3337
  var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
3380
3338
  var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
3381
3339
  var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
3382
- function getExtensionData(gl, extension) {
3340
+ function getExtensionData(gl2, extension) {
3383
3341
  return {
3384
- webgl2: isWebGL2(gl),
3385
- ext: gl.getExtension(extension)
3342
+ webgl2: isWebGL2(gl2),
3343
+ ext: gl2.getExtension(extension)
3386
3344
  };
3387
3345
  }
3388
3346
  var WEBGL2_CONTEXT_POLYFILLS = {
@@ -3453,18 +3411,18 @@ var __exports__ = (() => {
3453
3411
  };
3454
3412
  var WEBGL2_CONTEXT_OVERRIDES = {
3455
3413
  // Ensure readBuffer is a no-op
3456
- readBuffer: (gl, originalFunc, attachment) => {
3457
- if (isWebGL2(gl)) {
3414
+ readBuffer: (gl2, originalFunc, attachment) => {
3415
+ if (isWebGL2(gl2)) {
3458
3416
  originalFunc(attachment);
3459
3417
  } else {
3460
3418
  }
3461
3419
  },
3462
3420
  // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
3463
- getVertexAttrib: (gl, originalFunc, location, pname) => {
3421
+ getVertexAttrib: (gl2, originalFunc, location, pname) => {
3464
3422
  const {
3465
3423
  webgl2,
3466
3424
  ext
3467
- } = getExtensionData(gl, ANGLE_instanced_arrays);
3425
+ } = getExtensionData(gl2, ANGLE_instanced_arrays);
3468
3426
  let result;
3469
3427
  switch (pname) {
3470
3428
  case GL.VERTEX_ATTRIB_ARRAY_INTEGER:
@@ -3478,8 +3436,8 @@ var __exports__ = (() => {
3478
3436
  return result !== void 0 ? result : originalFunc(location, pname);
3479
3437
  },
3480
3438
  // Handle transform feedback and uniform block queries in WebGL1
3481
- getProgramParameter: (gl, originalFunc, program, pname) => {
3482
- if (!isWebGL2(gl)) {
3439
+ getProgramParameter: (gl2, originalFunc, program, pname) => {
3440
+ if (!isWebGL2(gl2)) {
3483
3441
  switch (pname) {
3484
3442
  case GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
3485
3443
  return GL.SEPARATE_ATTRIBS;
@@ -3492,21 +3450,21 @@ var __exports__ = (() => {
3492
3450
  }
3493
3451
  return originalFunc(program, pname);
3494
3452
  },
3495
- getInternalformatParameter: (gl, originalFunc, target, format, pname) => {
3496
- if (!isWebGL2(gl)) {
3453
+ getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
3454
+ if (!isWebGL2(gl2)) {
3497
3455
  switch (pname) {
3498
3456
  case GL.SAMPLES:
3499
3457
  return new Int32Array([0]);
3500
3458
  default:
3501
3459
  }
3502
3460
  }
3503
- const gl2 = gl;
3504
- return gl2.getInternalformatParameter(target, format, pname);
3461
+ const gl22 = gl2;
3462
+ return gl22.getInternalformatParameter(target, format, pname);
3505
3463
  },
3506
- getTexParameter(gl, originalFunc, target, pname) {
3464
+ getTexParameter(gl2, originalFunc, target, pname) {
3507
3465
  switch (pname) {
3508
3466
  case GL.TEXTURE_MAX_ANISOTROPY_EXT:
3509
- const contextData = getContextData(gl);
3467
+ const contextData = getContextData(gl2);
3510
3468
  const {
3511
3469
  _extensions
3512
3470
  } = contextData;
@@ -3518,47 +3476,47 @@ var __exports__ = (() => {
3518
3476
  return originalFunc(target, pname);
3519
3477
  },
3520
3478
  getParameter: getParameterPolyfill,
3521
- hint(gl, originalFunc, pname, value) {
3479
+ hint(gl2, originalFunc, pname, value) {
3522
3480
  return originalFunc(pname, value);
3523
3481
  }
3524
3482
  };
3525
3483
 
3526
3484
  // src/context/polyfill/polyfill-context.ts
3527
- function polyfillContext(gl) {
3528
- const contextState = getContextData(gl);
3485
+ function polyfillContext(gl2) {
3486
+ const contextState = getContextData(gl2);
3529
3487
  if (!contextState._polyfilled) {
3530
- polyfillVertexArrayObject(gl);
3531
- initializeExtensions(gl);
3532
- installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
3533
- installOverrides(gl, {
3488
+ polyfillVertexArrayObject(gl2);
3489
+ initializeExtensions(gl2);
3490
+ installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
3491
+ installOverrides(gl2, {
3534
3492
  target: contextState,
3535
- target2: gl
3493
+ target2: gl2
3536
3494
  });
3537
3495
  contextState._polyfilled = true;
3538
3496
  }
3539
- return gl;
3497
+ return gl2;
3540
3498
  }
3541
- function initializeExtensions(gl) {
3542
- const contextState = getContextData(gl);
3543
- const EXTENSIONS = gl.getSupportedExtensions() || [];
3499
+ function initializeExtensions(gl2) {
3500
+ const contextState = getContextData(gl2);
3501
+ const EXTENSIONS = gl2.getSupportedExtensions() || [];
3544
3502
  for (const extensionName of EXTENSIONS) {
3545
- const extension = gl.getExtension(extensionName);
3503
+ const extension = gl2.getExtension(extensionName);
3546
3504
  contextState._extensions[extensionName] = extension;
3547
3505
  }
3548
3506
  }
3549
- function installPolyfills(gl, polyfills) {
3550
- const contextState = getContextData(gl);
3507
+ function installPolyfills(gl2, polyfills) {
3508
+ const contextState = getContextData(gl2);
3551
3509
  for (const extension of Object.getOwnPropertyNames(polyfills)) {
3552
3510
  if (extension !== "overrides") {
3553
- polyfillExtension(gl, {
3511
+ polyfillExtension(gl2, {
3554
3512
  extension,
3555
3513
  target: contextState,
3556
- target2: gl
3514
+ target2: gl2
3557
3515
  });
3558
3516
  }
3559
3517
  }
3560
3518
  }
3561
- function polyfillExtension(gl, {
3519
+ function polyfillExtension(gl2, {
3562
3520
  extension,
3563
3521
  target,
3564
3522
  target2
@@ -3571,12 +3529,12 @@ var __exports__ = (() => {
3571
3529
  const {
3572
3530
  suffix = ""
3573
3531
  } = meta;
3574
- const ext = gl.getExtension(extension);
3532
+ const ext = gl2.getExtension(extension);
3575
3533
  for (const key of Object.keys(defaults)) {
3576
3534
  const extKey = `${key}${suffix}`;
3577
3535
  let polyfill = null;
3578
3536
  if (key === "meta") {
3579
- } else if (typeof gl[key] === "function") {
3537
+ } else if (typeof gl2[key] === "function") {
3580
3538
  } else if (ext && typeof ext[extKey] === "function") {
3581
3539
  polyfill = (...args) => ext[extKey](...args);
3582
3540
  } else if (typeof defaults[key] === "function") {
@@ -3588,15 +3546,15 @@ var __exports__ = (() => {
3588
3546
  }
3589
3547
  }
3590
3548
  }
3591
- function installOverrides(gl, {
3549
+ function installOverrides(gl2, {
3592
3550
  target,
3593
3551
  target2
3594
3552
  }) {
3595
3553
  Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
3596
3554
  if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
3597
- const originalFunc = gl[key] ? gl[key].bind(gl) : () => {
3555
+ const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
3598
3556
  };
3599
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
3557
+ const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
3600
3558
  target[key] = polyfill;
3601
3559
  target2[key] = polyfill;
3602
3560
  }
@@ -3687,19 +3645,19 @@ var __exports__ = (() => {
3687
3645
  [GL.UNPACK_SKIP_ROWS]: 0,
3688
3646
  [GL.UNPACK_SKIP_IMAGES]: 0
3689
3647
  };
3690
- var enable = (gl, value, key) => value ? gl.enable(key) : gl.disable(key);
3691
- var hint = (gl, value, key) => gl.hint(key, value);
3692
- var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
3693
- var bindFramebuffer = (gl, value, key) => {
3648
+ var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
3649
+ var hint = (gl2, value, key) => gl2.hint(key, value);
3650
+ var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
3651
+ var bindFramebuffer = (gl2, value, key) => {
3694
3652
  let target;
3695
3653
  if (key === GL.FRAMEBUFFER_BINDING) {
3696
- target = isWebGL2(gl) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3654
+ target = isWebGL2(gl2) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3697
3655
  } else {
3698
3656
  target = GL.READ_FRAMEBUFFER;
3699
3657
  }
3700
- return gl.bindFramebuffer(target, value);
3658
+ return gl2.bindFramebuffer(target, value);
3701
3659
  };
3702
- var bindBuffer = (gl, value, key) => {
3660
+ var bindBuffer = (gl2, value, key) => {
3703
3661
  const bindingMap = {
3704
3662
  [GL.ARRAY_BUFFER_BINDING]: GL.ARRAY_BUFFER,
3705
3663
  [GL.COPY_READ_BUFFER_BINDING]: GL.COPY_READ_BUFFER,
@@ -3708,35 +3666,35 @@ var __exports__ = (() => {
3708
3666
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
3709
3667
  };
3710
3668
  const target = bindingMap[key];
3711
- gl.bindBuffer(target, value);
3669
+ gl2.bindBuffer(target, value);
3712
3670
  };
3713
3671
  function isArray(array) {
3714
3672
  return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
3715
3673
  }
3716
3674
  var GL_PARAMETER_SETTERS = {
3717
3675
  [GL.BLEND]: enable,
3718
- [GL.BLEND_COLOR]: (gl, value) => gl.blendColor(...value),
3676
+ [GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
3719
3677
  [GL.BLEND_EQUATION_RGB]: "blendEquation",
3720
3678
  [GL.BLEND_EQUATION_ALPHA]: "blendEquation",
3721
3679
  [GL.BLEND_SRC_RGB]: "blendFunc",
3722
3680
  [GL.BLEND_DST_RGB]: "blendFunc",
3723
3681
  [GL.BLEND_SRC_ALPHA]: "blendFunc",
3724
3682
  [GL.BLEND_DST_ALPHA]: "blendFunc",
3725
- [GL.COLOR_CLEAR_VALUE]: (gl, value) => gl.clearColor(...value),
3726
- [GL.COLOR_WRITEMASK]: (gl, value) => gl.colorMask(...value),
3683
+ [GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
3684
+ [GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
3727
3685
  [GL.CULL_FACE]: enable,
3728
- [GL.CULL_FACE_MODE]: (gl, value) => gl.cullFace(value),
3686
+ [GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
3729
3687
  [GL.DEPTH_TEST]: enable,
3730
- [GL.DEPTH_CLEAR_VALUE]: (gl, value) => gl.clearDepth(value),
3731
- [GL.DEPTH_FUNC]: (gl, value) => gl.depthFunc(value),
3732
- [GL.DEPTH_RANGE]: (gl, value) => gl.depthRange(...value),
3733
- [GL.DEPTH_WRITEMASK]: (gl, value) => gl.depthMask(value),
3688
+ [GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
3689
+ [GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
3690
+ [GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
3691
+ [GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
3734
3692
  [GL.DITHER]: enable,
3735
3693
  [GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
3736
- [GL.CURRENT_PROGRAM]: (gl, value) => gl.useProgram(value),
3737
- [GL.RENDERBUFFER_BINDING]: (gl, value) => gl.bindRenderbuffer(GL.RENDERBUFFER, value),
3738
- [GL.TRANSFORM_FEEDBACK_BINDING]: (gl, value) => gl.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3739
- [GL.VERTEX_ARRAY_BINDING]: (gl, value) => gl.bindVertexArray(value),
3694
+ [GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
3695
+ [GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(GL.RENDERBUFFER, value),
3696
+ [GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => gl2.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3697
+ [GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
3740
3698
  // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
3741
3699
  [GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
3742
3700
  [GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
@@ -3746,9 +3704,9 @@ var __exports__ = (() => {
3746
3704
  [GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
3747
3705
  [GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
3748
3706
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
3749
- [GL.FRONT_FACE]: (gl, value) => gl.frontFace(value),
3707
+ [GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
3750
3708
  [GL.GENERATE_MIPMAP_HINT]: hint,
3751
- [GL.LINE_WIDTH]: (gl, value) => gl.lineWidth(value),
3709
+ [GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
3752
3710
  [GL.POLYGON_OFFSET_FILL]: enable,
3753
3711
  [GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
3754
3712
  [GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
@@ -3758,11 +3716,11 @@ var __exports__ = (() => {
3758
3716
  [GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
3759
3717
  [GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
3760
3718
  [GL.SCISSOR_TEST]: enable,
3761
- [GL.SCISSOR_BOX]: (gl, value) => gl.scissor(...value),
3719
+ [GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
3762
3720
  [GL.STENCIL_TEST]: enable,
3763
- [GL.STENCIL_CLEAR_VALUE]: (gl, value) => gl.clearStencil(value),
3764
- [GL.STENCIL_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(GL.FRONT, value),
3765
- [GL.STENCIL_BACK_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(GL.BACK, value),
3721
+ [GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
3722
+ [GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.FRONT, value),
3723
+ [GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.BACK, value),
3766
3724
  [GL.STENCIL_FUNC]: "stencilFuncFront",
3767
3725
  [GL.STENCIL_REF]: "stencilFuncFront",
3768
3726
  [GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
@@ -3775,7 +3733,7 @@ var __exports__ = (() => {
3775
3733
  [GL.STENCIL_BACK_FAIL]: "stencilOpBack",
3776
3734
  [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
3777
3735
  [GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
3778
- [GL.VIEWPORT]: (gl, value) => gl.viewport(...value),
3736
+ [GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
3779
3737
  // WEBGL1 PIXEL PACK/UNPACK MODES
3780
3738
  [GL.PACK_ALIGNMENT]: pixelStorei,
3781
3739
  [GL.UNPACK_ALIGNMENT]: pixelStorei,
@@ -3793,75 +3751,75 @@ var __exports__ = (() => {
3793
3751
  [GL.UNPACK_SKIP_ROWS]: pixelStorei,
3794
3752
  [GL.UNPACK_SKIP_IMAGES]: pixelStorei,
3795
3753
  // Function-style setters
3796
- framebuffer: (gl, framebuffer) => {
3754
+ framebuffer: (gl2, framebuffer) => {
3797
3755
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
3798
- return gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
3756
+ return gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
3799
3757
  },
3800
- blend: (gl, value) => value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND),
3801
- blendColor: (gl, value) => gl.blendColor(...value),
3802
- blendEquation: (gl, args) => {
3758
+ blend: (gl2, value) => value ? gl2.enable(GL.BLEND) : gl2.disable(GL.BLEND),
3759
+ blendColor: (gl2, value) => gl2.blendColor(...value),
3760
+ blendEquation: (gl2, args) => {
3803
3761
  const separateModes = typeof args === "number" ? [args, args] : args;
3804
- gl.blendEquationSeparate(...separateModes);
3762
+ gl2.blendEquationSeparate(...separateModes);
3805
3763
  },
3806
- blendFunc: (gl, args) => {
3764
+ blendFunc: (gl2, args) => {
3807
3765
  const separateFuncs = args?.length === 2 ? [...args, ...args] : args;
3808
- gl.blendFuncSeparate(...separateFuncs);
3809
- },
3810
- clearColor: (gl, value) => gl.clearColor(...value),
3811
- clearDepth: (gl, value) => gl.clearDepth(value),
3812
- clearStencil: (gl, value) => gl.clearStencil(value),
3813
- colorMask: (gl, value) => gl.colorMask(...value),
3814
- cull: (gl, value) => value ? gl.enable(GL.CULL_FACE) : gl.disable(GL.CULL_FACE),
3815
- cullFace: (gl, value) => gl.cullFace(value),
3816
- depthTest: (gl, value) => value ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST),
3817
- depthFunc: (gl, value) => gl.depthFunc(value),
3818
- depthMask: (gl, value) => gl.depthMask(value),
3819
- depthRange: (gl, value) => gl.depthRange(...value),
3820
- dither: (gl, value) => value ? gl.enable(GL.DITHER) : gl.disable(GL.DITHER),
3821
- derivativeHint: (gl, value) => {
3822
- gl.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
3823
- },
3824
- frontFace: (gl, value) => gl.frontFace(value),
3825
- mipmapHint: (gl, value) => gl.hint(GL.GENERATE_MIPMAP_HINT, value),
3826
- lineWidth: (gl, value) => gl.lineWidth(value),
3827
- polygonOffsetFill: (gl, value) => value ? gl.enable(GL.POLYGON_OFFSET_FILL) : gl.disable(GL.POLYGON_OFFSET_FILL),
3828
- polygonOffset: (gl, value) => gl.polygonOffset(...value),
3829
- sampleCoverage: (gl, value) => gl.sampleCoverage(...value),
3830
- scissorTest: (gl, value) => value ? gl.enable(GL.SCISSOR_TEST) : gl.disable(GL.SCISSOR_TEST),
3831
- scissor: (gl, value) => gl.scissor(...value),
3832
- stencilTest: (gl, value) => value ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST),
3833
- stencilMask: (gl, value) => {
3766
+ gl2.blendFuncSeparate(...separateFuncs);
3767
+ },
3768
+ clearColor: (gl2, value) => gl2.clearColor(...value),
3769
+ clearDepth: (gl2, value) => gl2.clearDepth(value),
3770
+ clearStencil: (gl2, value) => gl2.clearStencil(value),
3771
+ colorMask: (gl2, value) => gl2.colorMask(...value),
3772
+ cull: (gl2, value) => value ? gl2.enable(GL.CULL_FACE) : gl2.disable(GL.CULL_FACE),
3773
+ cullFace: (gl2, value) => gl2.cullFace(value),
3774
+ depthTest: (gl2, value) => value ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST),
3775
+ depthFunc: (gl2, value) => gl2.depthFunc(value),
3776
+ depthMask: (gl2, value) => gl2.depthMask(value),
3777
+ depthRange: (gl2, value) => gl2.depthRange(...value),
3778
+ dither: (gl2, value) => value ? gl2.enable(GL.DITHER) : gl2.disable(GL.DITHER),
3779
+ derivativeHint: (gl2, value) => {
3780
+ gl2.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
3781
+ },
3782
+ frontFace: (gl2, value) => gl2.frontFace(value),
3783
+ mipmapHint: (gl2, value) => gl2.hint(GL.GENERATE_MIPMAP_HINT, value),
3784
+ lineWidth: (gl2, value) => gl2.lineWidth(value),
3785
+ polygonOffsetFill: (gl2, value) => value ? gl2.enable(GL.POLYGON_OFFSET_FILL) : gl2.disable(GL.POLYGON_OFFSET_FILL),
3786
+ polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
3787
+ sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
3788
+ scissorTest: (gl2, value) => value ? gl2.enable(GL.SCISSOR_TEST) : gl2.disable(GL.SCISSOR_TEST),
3789
+ scissor: (gl2, value) => gl2.scissor(...value),
3790
+ stencilTest: (gl2, value) => value ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST),
3791
+ stencilMask: (gl2, value) => {
3834
3792
  value = isArray(value) ? value : [value, value];
3835
3793
  const [mask, backMask] = value;
3836
- gl.stencilMaskSeparate(GL.FRONT, mask);
3837
- gl.stencilMaskSeparate(GL.BACK, backMask);
3794
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
3795
+ gl2.stencilMaskSeparate(GL.BACK, backMask);
3838
3796
  },
3839
- stencilFunc: (gl, args) => {
3797
+ stencilFunc: (gl2, args) => {
3840
3798
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3841
3799
  const [func, ref, mask, backFunc, backRef, backMask] = args;
3842
- gl.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3843
- gl.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3800
+ gl2.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3801
+ gl2.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3844
3802
  },
3845
- stencilOp: (gl, args) => {
3803
+ stencilOp: (gl2, args) => {
3846
3804
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3847
3805
  const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
3848
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3849
- gl.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3806
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3807
+ gl2.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3850
3808
  },
3851
- viewport: (gl, value) => gl.viewport(...value)
3809
+ viewport: (gl2, value) => gl2.viewport(...value)
3852
3810
  };
3853
3811
  function getValue(glEnum, values, cache2) {
3854
3812
  return values[glEnum] !== void 0 ? values[glEnum] : cache2[glEnum];
3855
3813
  }
3856
3814
  var GL_COMPOSITE_PARAMETER_SETTERS = {
3857
- blendEquation: (gl, values, cache2) => gl.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
3858
- blendFunc: (gl, values, cache2) => gl.blendFuncSeparate(getValue(GL.BLEND_SRC_RGB, values, cache2), getValue(GL.BLEND_DST_RGB, values, cache2), getValue(GL.BLEND_SRC_ALPHA, values, cache2), getValue(GL.BLEND_DST_ALPHA, values, cache2)),
3859
- polygonOffset: (gl, values, cache2) => gl.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
3860
- sampleCoverage: (gl, values, cache2) => gl.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
3861
- stencilFuncFront: (gl, values, cache2) => gl.stencilFuncSeparate(GL.FRONT, getValue(GL.STENCIL_FUNC, values, cache2), getValue(GL.STENCIL_REF, values, cache2), getValue(GL.STENCIL_VALUE_MASK, values, cache2)),
3862
- stencilFuncBack: (gl, values, cache2) => gl.stencilFuncSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FUNC, values, cache2), getValue(GL.STENCIL_BACK_REF, values, cache2), getValue(GL.STENCIL_BACK_VALUE_MASK, values, cache2)),
3863
- stencilOpFront: (gl, values, cache2) => gl.stencilOpSeparate(GL.FRONT, getValue(GL.STENCIL_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_PASS, values, cache2)),
3864
- stencilOpBack: (gl, values, cache2) => gl.stencilOpSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_PASS, values, cache2))
3815
+ blendEquation: (gl2, values, cache2) => gl2.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
3816
+ blendFunc: (gl2, values, cache2) => gl2.blendFuncSeparate(getValue(GL.BLEND_SRC_RGB, values, cache2), getValue(GL.BLEND_DST_RGB, values, cache2), getValue(GL.BLEND_SRC_ALPHA, values, cache2), getValue(GL.BLEND_DST_ALPHA, values, cache2)),
3817
+ polygonOffset: (gl2, values, cache2) => gl2.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
3818
+ sampleCoverage: (gl2, values, cache2) => gl2.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
3819
+ stencilFuncFront: (gl2, values, cache2) => gl2.stencilFuncSeparate(GL.FRONT, getValue(GL.STENCIL_FUNC, values, cache2), getValue(GL.STENCIL_REF, values, cache2), getValue(GL.STENCIL_VALUE_MASK, values, cache2)),
3820
+ stencilFuncBack: (gl2, values, cache2) => gl2.stencilFuncSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FUNC, values, cache2), getValue(GL.STENCIL_BACK_REF, values, cache2), getValue(GL.STENCIL_BACK_VALUE_MASK, values, cache2)),
3821
+ stencilOpFront: (gl2, values, cache2) => gl2.stencilOpSeparate(GL.FRONT, getValue(GL.STENCIL_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_PASS_DEPTH_PASS, values, cache2)),
3822
+ stencilOpBack: (gl2, values, cache2) => gl2.stencilOpSeparate(GL.BACK, getValue(GL.STENCIL_BACK_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache2), getValue(GL.STENCIL_BACK_PASS_DEPTH_PASS, values, cache2))
3865
3823
  };
3866
3824
  var GL_HOOKED_SETTERS = {
3867
3825
  // GENERIC SETTERS
@@ -4027,7 +3985,7 @@ var __exports__ = (() => {
4027
3985
  [GL.VIEWPORT]: [x, y, width, height]
4028
3986
  })
4029
3987
  };
4030
- var isEnabled = (gl, key) => gl.isEnabled(key);
3988
+ var isEnabled = (gl2, key) => gl2.isEnabled(key);
4031
3989
  var GL_PARAMETER_GETTERS = {
4032
3990
  [GL.BLEND]: isEnabled,
4033
3991
  [GL.CULL_FACE]: isEnabled,
@@ -4083,7 +4041,7 @@ var __exports__ = (() => {
4083
4041
  // src/context/parameters/unified-parameter-api.ts
4084
4042
  function setParameters(device, parameters) {
4085
4043
  const webglDevice = WebGLDevice.attach(device);
4086
- const gl = webglDevice.gl;
4044
+ const gl2 = webglDevice.gl;
4087
4045
  if (isObjectEmpty2(parameters)) {
4088
4046
  return;
4089
4047
  }
@@ -4095,31 +4053,31 @@ var __exports__ = (() => {
4095
4053
  if (typeof setter === "string") {
4096
4054
  compositeSetters[setter] = true;
4097
4055
  } else {
4098
- setter(gl, parameters[key], glConstant);
4056
+ setter(gl2, parameters[key], glConstant);
4099
4057
  }
4100
4058
  }
4101
4059
  }
4102
- const cache2 = gl.state && gl.state.cache;
4060
+ const cache2 = gl2.state && gl2.state.cache;
4103
4061
  if (cache2) {
4104
4062
  for (const key in compositeSetters) {
4105
4063
  const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
4106
- compositeSetter(gl, parameters, cache2);
4064
+ compositeSetter(gl2, parameters, cache2);
4107
4065
  }
4108
4066
  }
4109
4067
  }
4110
4068
  function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
4111
4069
  const webglDevice = WebGLDevice.attach(device);
4112
- const gl = webglDevice.gl;
4070
+ const gl2 = webglDevice.gl;
4113
4071
  if (typeof parameters === "number") {
4114
4072
  const key = parameters;
4115
4073
  const getter = GL_PARAMETER_GETTERS[key];
4116
- return getter ? getter(gl, key) : gl.getParameter(key);
4074
+ return getter ? getter(gl2, key) : gl2.getParameter(key);
4117
4075
  }
4118
4076
  const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
4119
4077
  const state = {};
4120
4078
  for (const key of parameterKeys) {
4121
4079
  const getter = GL_PARAMETER_GETTERS[key];
4122
- state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
4080
+ state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
4123
4081
  }
4124
4082
  return state;
4125
4083
  }
@@ -4156,15 +4114,15 @@ var __exports__ = (() => {
4156
4114
  program = null;
4157
4115
  stateStack = [];
4158
4116
  enable = true;
4159
- constructor(gl, {
4117
+ constructor(gl2, {
4160
4118
  copyState = false,
4161
4119
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
4162
4120
  log: log3 = () => {
4163
4121
  }
4164
4122
  // Logging function, called when gl parameter change calls are actually issued
4165
4123
  } = {}) {
4166
- this.gl = gl;
4167
- this.cache = copyState ? getParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4124
+ this.gl = gl2;
4125
+ this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4168
4126
  this.log = log3;
4169
4127
  this._updateCache = this._updateCache.bind(this);
4170
4128
  Object.seal(this);
@@ -4207,53 +4165,53 @@ var __exports__ = (() => {
4207
4165
  };
4208
4166
  }
4209
4167
  };
4210
- function getContextState(gl) {
4211
- return gl.state;
4168
+ function getContextState(gl2) {
4169
+ return gl2.state;
4212
4170
  }
4213
- function trackContextState(gl, options) {
4171
+ function trackContextState(gl2, options) {
4214
4172
  const {
4215
4173
  enable: enable2 = true,
4216
4174
  copyState
4217
4175
  } = options;
4218
4176
  assert2(copyState !== void 0);
4219
- if (!gl.state) {
4220
- gl.state = new GLState(gl, {
4177
+ if (!gl2.state) {
4178
+ gl2.state = new GLState(gl2, {
4221
4179
  copyState
4222
4180
  });
4223
- installProgramSpy(gl);
4181
+ installProgramSpy(gl2);
4224
4182
  for (const key in GL_HOOKED_SETTERS) {
4225
4183
  const setter = GL_HOOKED_SETTERS[key];
4226
- installSetterSpy(gl, key, setter);
4184
+ installSetterSpy(gl2, key, setter);
4227
4185
  }
4228
- installGetterOverride(gl, "getParameter");
4229
- installGetterOverride(gl, "isEnabled");
4186
+ installGetterOverride(gl2, "getParameter");
4187
+ installGetterOverride(gl2, "isEnabled");
4230
4188
  }
4231
- const glState = getContextState(gl);
4189
+ const glState = getContextState(gl2);
4232
4190
  glState.enable = enable2;
4233
- return gl;
4191
+ return gl2;
4234
4192
  }
4235
- function pushContextState(gl) {
4236
- let glState = getContextState(gl);
4193
+ function pushContextState(gl2) {
4194
+ let glState = getContextState(gl2);
4237
4195
  if (!glState) {
4238
- trackContextState(gl, {
4196
+ trackContextState(gl2, {
4239
4197
  copyState: false
4240
4198
  });
4241
- glState = getContextState(gl);
4199
+ glState = getContextState(gl2);
4242
4200
  }
4243
4201
  glState.push();
4244
4202
  }
4245
- function popContextState(gl) {
4246
- const glState = getContextState(gl);
4203
+ function popContextState(gl2) {
4204
+ const glState = getContextState(gl2);
4247
4205
  assert2(glState);
4248
4206
  glState.pop();
4249
4207
  }
4250
- function installGetterOverride(gl, functionName) {
4251
- const originalGetterFunc = gl[functionName].bind(gl);
4252
- gl[functionName] = function get(pname) {
4208
+ function installGetterOverride(gl2, functionName) {
4209
+ const originalGetterFunc = gl2[functionName].bind(gl2);
4210
+ gl2[functionName] = function get(pname) {
4253
4211
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
4254
4212
  return originalGetterFunc(pname);
4255
4213
  }
4256
- const glState = getContextState(gl);
4214
+ const glState = getContextState(gl2);
4257
4215
  if (!(pname in glState.cache)) {
4258
4216
  glState.cache[pname] = originalGetterFunc(pname);
4259
4217
  }
@@ -4265,18 +4223,18 @@ var __exports__ = (() => {
4265
4223
  originalGetterFunc(pname)
4266
4224
  );
4267
4225
  };
4268
- Object.defineProperty(gl[functionName], "name", {
4226
+ Object.defineProperty(gl2[functionName], "name", {
4269
4227
  value: `${functionName}-from-cache`,
4270
4228
  configurable: false
4271
4229
  });
4272
4230
  }
4273
- function installSetterSpy(gl, functionName, setter) {
4274
- if (!gl[functionName]) {
4231
+ function installSetterSpy(gl2, functionName, setter) {
4232
+ if (!gl2[functionName]) {
4275
4233
  return;
4276
4234
  }
4277
- const originalSetterFunc = gl[functionName].bind(gl);
4278
- gl[functionName] = function set(...params) {
4279
- const glState = getContextState(gl);
4235
+ const originalSetterFunc = gl2[functionName].bind(gl2);
4236
+ gl2[functionName] = function set(...params) {
4237
+ const glState = getContextState(gl2);
4280
4238
  const {
4281
4239
  valueChanged,
4282
4240
  oldValue
@@ -4286,15 +4244,15 @@ var __exports__ = (() => {
4286
4244
  }
4287
4245
  return oldValue;
4288
4246
  };
4289
- Object.defineProperty(gl[functionName], "name", {
4247
+ Object.defineProperty(gl2[functionName], "name", {
4290
4248
  value: `${functionName}-to-cache`,
4291
4249
  configurable: false
4292
4250
  });
4293
4251
  }
4294
- function installProgramSpy(gl) {
4295
- const originalUseProgram = gl.useProgram.bind(gl);
4296
- gl.useProgram = function useProgramLuma(handle) {
4297
- const glState = getContextState(gl);
4252
+ function installProgramSpy(gl2) {
4253
+ const originalUseProgram = gl2.useProgram.bind(gl2);
4254
+ gl2.useProgram = function useProgramLuma(handle) {
4255
+ const glState = getContextState(gl2);
4298
4256
  if (glState.program !== handle) {
4299
4257
  originalUseProgram(handle);
4300
4258
  glState.program = handle;
@@ -4323,7 +4281,7 @@ var __exports__ = (() => {
4323
4281
  let errorMessage = null;
4324
4282
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
4325
4283
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
4326
- let gl = null;
4284
+ let gl2 = null;
4327
4285
  if (props.type === "webgl2") {
4328
4286
  props = {
4329
4287
  ...props,
@@ -4336,14 +4294,14 @@ var __exports__ = (() => {
4336
4294
  webgl2: false
4337
4295
  };
4338
4296
  }
4339
- if (!gl && props.webgl2) {
4340
- gl = canvas.getContext("webgl2", props);
4297
+ if (!gl2 && props.webgl2) {
4298
+ gl2 = canvas.getContext("webgl2", props);
4341
4299
  }
4342
- if (!gl && props.webgl1) {
4343
- gl = canvas.getContext("webgl", props);
4300
+ if (!gl2 && props.webgl1) {
4301
+ gl2 = canvas.getContext("webgl", props);
4344
4302
  }
4345
4303
  canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
4346
- if (!gl) {
4304
+ if (!gl2) {
4347
4305
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
4348
4306
  }
4349
4307
  if (props.onContextLost) {
@@ -4358,28 +4316,28 @@ var __exports__ = (() => {
4358
4316
  } = props;
4359
4317
  canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
4360
4318
  }
4361
- return gl;
4319
+ return gl2;
4362
4320
  }
4363
4321
 
4364
4322
  // src/adapter/device-helpers/get-device-info.ts
4365
- function getDeviceInfo(gl) {
4366
- const vendorMasked = gl.getParameter(GL.VENDOR);
4367
- const rendererMasked = gl.getParameter(GL.RENDERER);
4368
- const ext = gl.getExtension("WEBGL_debug_renderer_info");
4369
- const vendorUnmasked = gl.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4370
- const rendererUnmasked = gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
4323
+ function getDeviceInfo(gl2) {
4324
+ const vendorMasked = gl2.getParameter(GL.VENDOR);
4325
+ const rendererMasked = gl2.getParameter(GL.RENDERER);
4326
+ const ext = gl2.getExtension("WEBGL_debug_renderer_info");
4327
+ const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4328
+ const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
4371
4329
  const vendor = vendorUnmasked || vendorMasked;
4372
4330
  const renderer = rendererUnmasked || rendererMasked;
4373
4331
  const gpu = identifyGPUVendor(vendor, renderer);
4374
4332
  return {
4375
- type: isWebGL2(gl) ? "webgl2" : "webgl",
4333
+ type: isWebGL2(gl2) ? "webgl2" : "webgl",
4376
4334
  gpu,
4377
4335
  vendor: vendorUnmasked || vendorMasked,
4378
4336
  renderer: rendererUnmasked || rendererMasked,
4379
- version: gl.getParameter(GL.VERSION),
4337
+ version: gl2.getParameter(GL.VERSION),
4380
4338
  shadingLanguages: ["glsl"],
4381
4339
  shadingLanguageVersions: {
4382
- "glsl": gl.getParameter(GL.SHADING_LANGUAGE_VERSION)
4340
+ "glsl": gl2.getParameter(GL.SHADING_LANGUAGE_VERSION)
4383
4341
  }
4384
4342
  };
4385
4343
  }
@@ -4431,38 +4389,38 @@ var __exports__ = (() => {
4431
4389
  var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
4432
4390
  var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
4433
4391
  var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
4434
- var checkExtension = (gl, extension) => gl.getExtension(extension);
4435
- var checkExtensions = (gl, extensions) => extensions.every((extension) => gl.getExtension(extension));
4392
+ var checkExtension = (gl2, extension) => gl2.getExtension(extension);
4393
+ var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
4436
4394
  var TEXTURE_FEATURE_CHECKS = {
4437
- "texture-blend-float-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "EXT_float_blend"),
4438
- "texture-formats-srgb-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, EXT_SRGB),
4439
- "texture-formats-depth-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "WEBGL_depth_texture"),
4440
- "texture-formats-float32-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_float"),
4441
- "texture-formats-float16-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_half_float"),
4442
- "texture-formats-norm16-webgl": (gl) => isWebGL2(gl) ? checkExtension(gl, EXT_TEXTURE_NORM16) : false,
4443
- "texture-filter-linear-float32-webgl": (gl) => checkExtension(gl, "OES_texture_float_linear"),
4444
- "texture-filter-linear-float16-webgl": (gl) => checkExtension(gl, "OES_texture_half_float_linear"),
4445
- "texture-filter-anisotropic-webgl": (gl) => checkExtension(gl, "EXT_texture_filter_anisotropic"),
4446
- "texture-renderable-float32-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_float"),
4395
+ "texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
4396
+ "texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
4397
+ "texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
4398
+ "texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
4399
+ "texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
4400
+ "texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
4401
+ "texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
4402
+ "texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
4403
+ "texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
4404
+ "texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
4447
4405
  // [false, 'EXT_color_buffer_float'],
4448
- "texture-renderable-float16-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_half_float"),
4449
- "texture-compression-bc": (gl) => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4450
- "texture-compression-bc5-webgl": (gl) => checkExtensions(gl, [X_RGTC]),
4406
+ "texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
4407
+ "texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4408
+ "texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
4451
4409
  // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
4452
4410
  // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
4453
4411
  // 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
4454
- "texture-compression-etc2": (gl) => checkExtensions(gl, [X_ETC2]),
4455
- "texture-compression-astc": (gl) => checkExtensions(gl, [X_ASTC]),
4456
- "texture-compression-etc1-webgl": (gl) => checkExtensions(gl, [X_ETC1]),
4457
- "texture-compression-pvrtc-webgl": (gl) => checkExtensions(gl, [X_PVRTC]),
4458
- "texture-compression-atc-webgl": (gl) => checkExtensions(gl, [X_ATC])
4412
+ "texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
4413
+ "texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
4414
+ "texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
4415
+ "texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
4416
+ "texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
4459
4417
  };
4460
- function checkTextureFeature(gl, feature) {
4461
- return TEXTURE_FEATURE_CHECKS[feature]?.(gl) || false;
4418
+ function checkTextureFeature(gl2, feature) {
4419
+ return TEXTURE_FEATURE_CHECKS[feature]?.(gl2) || false;
4462
4420
  }
4463
- function getTextureFeatures(gl) {
4421
+ function getTextureFeatures(gl2) {
4464
4422
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
4465
- return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
4423
+ return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
4466
4424
  }
4467
4425
  var TEXTURE_FORMATS = {
4468
4426
  // Unsized formats that leave the precision up to the driver.
@@ -5202,23 +5160,23 @@ var __exports__ = (() => {
5202
5160
  [GL.BYTE]: 1,
5203
5161
  [GL.UNSIGNED_BYTE]: 1
5204
5162
  };
5205
- function isTextureFormatSupported(gl, formatOrGL) {
5163
+ function isTextureFormatSupported(gl2, formatOrGL) {
5206
5164
  const format = convertGLToTextureFormat(formatOrGL);
5207
5165
  const info = TEXTURE_FORMATS[format];
5208
5166
  if (!info) {
5209
5167
  return false;
5210
5168
  }
5211
- if (isWebGL2(gl) ? info.gl === void 0 : info.gl1 === void 0) {
5169
+ if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
5212
5170
  return false;
5213
5171
  }
5214
- const extension = info.x || (isWebGL2(gl) ? info.gl2ext || info.gl1ext : info.gl1ext);
5172
+ const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
5215
5173
  if (extension) {
5216
- return Boolean(gl.getExtension(extension));
5174
+ return Boolean(gl2.getExtension(extension));
5217
5175
  }
5218
5176
  return true;
5219
5177
  }
5220
- function isRenderbufferFormatSupported(gl, format) {
5221
- return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5178
+ function isRenderbufferFormatSupported(gl2, format) {
5179
+ return isTextureFormatSupported(gl2, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5222
5180
  }
5223
5181
  function convertGLToTextureFormat(format) {
5224
5182
  if (typeof format === "string") {
@@ -5238,9 +5196,9 @@ var __exports__ = (() => {
5238
5196
  }
5239
5197
  return webglFormat;
5240
5198
  }
5241
- function isTextureFormatFilterable(gl, formatOrGL) {
5199
+ function isTextureFormatFilterable(gl2, formatOrGL) {
5242
5200
  const format = convertGLToTextureFormat(formatOrGL);
5243
- if (!isTextureFormatSupported(gl, format)) {
5201
+ if (!isTextureFormatSupported(gl2, format)) {
5244
5202
  return false;
5245
5203
  }
5246
5204
  try {
@@ -5252,16 +5210,16 @@ var __exports__ = (() => {
5252
5210
  return false;
5253
5211
  }
5254
5212
  if (format.endsWith("32float")) {
5255
- return Boolean(gl.getExtension("OES_texture_float_linear"));
5213
+ return Boolean(gl2.getExtension("OES_texture_float_linear"));
5256
5214
  }
5257
5215
  if (format.endsWith("16float")) {
5258
- return Boolean(gl.getExtension("OES_texture_half_float_linear"));
5216
+ return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
5259
5217
  }
5260
5218
  return true;
5261
5219
  }
5262
- function isTextureFormatRenderable(gl, formatOrGL) {
5220
+ function isTextureFormatRenderable(gl2, formatOrGL) {
5263
5221
  const format = convertGLToTextureFormat(formatOrGL);
5264
- if (!isTextureFormatSupported(gl, format)) {
5222
+ if (!isTextureFormatSupported(gl2, format)) {
5265
5223
  return false;
5266
5224
  }
5267
5225
  if (typeof format === "number") {
@@ -5288,27 +5246,27 @@ var __exports__ = (() => {
5288
5246
  }
5289
5247
  return info.attachment;
5290
5248
  }
5291
- function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5249
+ function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5292
5250
  let texture = null;
5293
5251
  let framebuffer = null;
5294
5252
  try {
5295
- texture = gl.createTexture();
5296
- gl.bindTexture(GL.TEXTURE_2D, texture);
5253
+ texture = gl2.createTexture();
5254
+ gl2.bindTexture(GL.TEXTURE_2D, texture);
5297
5255
  const level = 0;
5298
5256
  const width = 1;
5299
5257
  const height = 1;
5300
5258
  const border = 0;
5301
5259
  const pixel = new Uint8Array([0, 0, 255, 255]);
5302
- gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5303
- framebuffer = gl.createFramebuffer();
5304
- gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5305
- gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5306
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5307
- gl.bindTexture(GL.TEXTURE_2D, null);
5260
+ gl2.texImage2D(gl2.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5261
+ framebuffer = gl2.createFramebuffer();
5262
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5263
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5264
+ const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5265
+ gl2.bindTexture(GL.TEXTURE_2D, null);
5308
5266
  return status;
5309
5267
  } finally {
5310
- gl.deleteTexture(texture);
5311
- gl.deleteFramebuffer(framebuffer);
5268
+ gl2.deleteTexture(texture);
5269
+ gl2.deleteFramebuffer(framebuffer);
5312
5270
  }
5313
5271
  }
5314
5272
  function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
@@ -5359,52 +5317,52 @@ var __exports__ = (() => {
5359
5317
  }
5360
5318
 
5361
5319
  // src/adapter/device-helpers/device-features.ts
5362
- function getDeviceFeatures(gl) {
5363
- const features = getWebGLFeatures(gl);
5364
- for (const textureFeature of getTextureFeatures(gl)) {
5320
+ function getDeviceFeatures(gl2) {
5321
+ const features = getWebGLFeatures(gl2);
5322
+ for (const textureFeature of getTextureFeatures(gl2)) {
5365
5323
  features.add(textureFeature);
5366
5324
  }
5367
5325
  return features;
5368
5326
  }
5369
- function getWebGLFeatures(gl) {
5370
- gl.getExtension("EXT_color_buffer_float");
5371
- gl.getExtension("WEBGL_color_buffer_float");
5372
- gl.getExtension("EXT_float_blend");
5327
+ function getWebGLFeatures(gl2) {
5328
+ gl2.getExtension("EXT_color_buffer_float");
5329
+ gl2.getExtension("WEBGL_color_buffer_float");
5330
+ gl2.getExtension("EXT_float_blend");
5373
5331
  const features = /* @__PURE__ */ new Set();
5374
5332
  for (const feature of Object.keys(WEBGL_FEATURES)) {
5375
- if (isFeatureSupported(gl, feature)) {
5333
+ if (isFeatureSupported(gl2, feature)) {
5376
5334
  features.add(feature);
5377
5335
  }
5378
5336
  }
5379
5337
  return features;
5380
5338
  }
5381
- function isFeatureSupported(gl, feature) {
5339
+ function isFeatureSupported(gl2, feature) {
5382
5340
  const featureInfo = WEBGL_FEATURES[feature];
5383
5341
  if (!featureInfo) {
5384
5342
  return false;
5385
5343
  }
5386
5344
  const [webgl1Feature, webgl2Feature] = featureInfo || [];
5387
- const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
5345
+ const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
5388
5346
  if (typeof featureDefinition === "boolean") {
5389
5347
  return featureDefinition;
5390
5348
  }
5391
5349
  switch (feature) {
5392
5350
  case "texture-renderable-rgba32float-webgl":
5393
- return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl);
5351
+ return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
5394
5352
  case "glsl-derivatives":
5395
- return canCompileGLSLExtension(gl, featureDefinition);
5353
+ return canCompileGLSLExtension(gl2, featureDefinition);
5396
5354
  case "glsl-frag-data":
5397
- return canCompileGLSLExtension(gl, featureDefinition, {
5355
+ return canCompileGLSLExtension(gl2, featureDefinition, {
5398
5356
  behavior: "require"
5399
5357
  });
5400
5358
  case "glsl-frag-depth":
5401
- return canCompileGLSLExtension(gl, featureDefinition);
5359
+ return canCompileGLSLExtension(gl2, featureDefinition);
5402
5360
  default:
5403
- return Boolean(gl.getExtension(featureDefinition));
5361
+ return Boolean(gl2.getExtension(featureDefinition));
5404
5362
  }
5405
5363
  }
5406
5364
  var compiledGLSLExtensions = {};
5407
- function canCompileGLSLExtension(gl, extensionName, opts = {}) {
5365
+ function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
5408
5366
  if (!isOldIE(opts)) {
5409
5367
  return true;
5410
5368
  }
@@ -5414,14 +5372,14 @@ var __exports__ = (() => {
5414
5372
  const behavior = opts.behavior || "enable";
5415
5373
  const source = `#extension GL_${extensionName} : ${behavior}
5416
5374
  void main(void) {}`;
5417
- const shader = gl.createShader(gl.VERTEX_SHADER);
5375
+ const shader = gl2.createShader(gl2.VERTEX_SHADER);
5418
5376
  if (!shader) {
5419
5377
  throw new Error("shader");
5420
5378
  }
5421
- gl.shaderSource(shader, source);
5422
- gl.compileShader(shader);
5423
- const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
5424
- gl.deleteShader(shader);
5379
+ gl2.shaderSource(shader, source);
5380
+ gl2.compileShader(shader);
5381
+ const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
5382
+ gl2.deleteShader(shader);
5425
5383
  compiledGLSLExtensions[extensionName] = canCompile;
5426
5384
  return canCompile;
5427
5385
  }
@@ -5458,38 +5416,38 @@ void main(void) {}`;
5458
5416
  };
5459
5417
 
5460
5418
  // src/adapter/device-helpers/device-limits.ts
5461
- function getDeviceLimits(gl) {
5462
- const gl2 = getWebGL2Context(gl);
5419
+ function getDeviceLimits(gl2) {
5420
+ const gl22 = getWebGL2Context(gl2);
5463
5421
  return {
5464
5422
  maxTextureDimension1D: 0,
5465
5423
  // WebGL does not support 1D textures
5466
- maxTextureDimension2D: gl.getParameter(GL.MAX_TEXTURE_SIZE),
5467
- maxTextureDimension3D: gl2 ? gl2.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5468
- maxTextureArrayLayers: gl2 ? gl2.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
5424
+ maxTextureDimension2D: gl2.getParameter(GL.MAX_TEXTURE_SIZE),
5425
+ maxTextureDimension3D: gl22 ? gl22.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5426
+ maxTextureArrayLayers: gl22 ? gl22.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
5469
5427
  maxBindGroups: 1,
5470
5428
  // TBD
5471
5429
  maxDynamicUniformBuffersPerPipelineLayout: 0,
5472
5430
  // TBD
5473
5431
  maxDynamicStorageBuffersPerPipelineLayout: 0,
5474
5432
  // TBD
5475
- maxSampledTexturesPerShaderStage: gl.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5433
+ maxSampledTexturesPerShaderStage: gl2.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5476
5434
  // TBD
5477
- maxSamplersPerShaderStage: gl.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5435
+ maxSamplersPerShaderStage: gl2.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5478
5436
  maxStorageBuffersPerShaderStage: 0,
5479
5437
  // TBD
5480
5438
  maxStorageTexturesPerShaderStage: 0,
5481
5439
  // TBD
5482
- maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5483
- maxUniformBufferBindingSize: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5440
+ maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5441
+ maxUniformBufferBindingSize: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5484
5442
  maxStorageBufferBindingSize: 0,
5485
- minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5443
+ minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5486
5444
  minStorageBufferOffsetAlignment: 0,
5487
5445
  // TBD
5488
5446
  maxVertexBuffers: 0,
5489
- maxVertexAttributes: gl.getParameter(GL.MAX_VERTEX_ATTRIBS),
5447
+ maxVertexAttributes: gl2.getParameter(GL.MAX_VERTEX_ATTRIBS),
5490
5448
  maxVertexBufferArrayStride: 2048,
5491
5449
  // TBD, this is just the default value from WebGPU
5492
- maxInterStageShaderComponents: gl2 ? gl2.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5450
+ maxInterStageShaderComponents: gl22 ? gl22.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5493
5451
  maxComputeWorkgroupStorageSize: 0,
5494
5452
  // WebGL does not support compute shaders
5495
5453
  maxComputeInvocationsPerWorkgroup: 0,
@@ -5504,13 +5462,13 @@ void main(void) {}`;
5504
5462
  // WebGL does not support compute shaders
5505
5463
  };
5506
5464
  }
5507
- function getWebGLLimits(gl) {
5508
- const gl2 = getWebGL2Context(gl);
5465
+ function getWebGLLimits(gl2) {
5466
+ const gl22 = getWebGL2Context(gl2);
5509
5467
  function get(pname) {
5510
- return gl.getParameter(pname);
5468
+ return gl2.getParameter(pname);
5511
5469
  }
5512
5470
  function get2(pname, defaultValue) {
5513
- return gl2 ? gl2.getParameter(pname) : defaultValue || 0;
5471
+ return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
5514
5472
  }
5515
5473
  return {
5516
5474
  [GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
@@ -5603,24 +5561,24 @@ void main(void) {}`;
5603
5561
  // src/context/state-tracker/with-parameters.ts
5604
5562
  function withParameters(device, parameters, func) {
5605
5563
  const webglDevice = WebGLDevice.attach(device);
5606
- const gl = webglDevice.gl;
5564
+ const gl2 = webglDevice.gl;
5607
5565
  if (isObjectEmpty3(parameters)) {
5608
5566
  return func(device);
5609
5567
  }
5610
5568
  const {
5611
5569
  nocatch = true
5612
5570
  } = parameters;
5613
- pushContextState(gl);
5614
- setParameters(gl, parameters);
5571
+ pushContextState(gl2);
5572
+ setParameters(gl2, parameters);
5615
5573
  let value;
5616
5574
  if (nocatch) {
5617
- value = func(gl);
5618
- popContextState(gl);
5575
+ value = func(gl2);
5576
+ popContextState(gl2);
5619
5577
  } else {
5620
5578
  try {
5621
- value = func(gl);
5579
+ value = func(gl2);
5622
5580
  } finally {
5623
- popContextState(gl);
5581
+ popContextState(gl2);
5624
5582
  }
5625
5583
  }
5626
5584
  return value;
@@ -5660,43 +5618,43 @@ void main(void) {}`;
5660
5618
  function setDeviceParameters(device, parameters) {
5661
5619
  const webglDevice = WebGLDevice.attach(device);
5662
5620
  const {
5663
- gl
5621
+ gl: gl2
5664
5622
  } = webglDevice;
5665
5623
  if (parameters.cullMode) {
5666
5624
  switch (parameters.cullMode) {
5667
5625
  case "none":
5668
- gl.disable(GL.CULL_FACE);
5626
+ gl2.disable(GL.CULL_FACE);
5669
5627
  break;
5670
5628
  case "front":
5671
- gl.enable(GL.CULL_FACE);
5672
- gl.cullFace(GL.FRONT);
5629
+ gl2.enable(GL.CULL_FACE);
5630
+ gl2.cullFace(GL.FRONT);
5673
5631
  break;
5674
5632
  case "back":
5675
- gl.enable(GL.CULL_FACE);
5676
- gl.cullFace(GL.BACK);
5633
+ gl2.enable(GL.CULL_FACE);
5634
+ gl2.cullFace(GL.BACK);
5677
5635
  break;
5678
5636
  }
5679
5637
  }
5680
5638
  if (parameters.frontFace) {
5681
- gl.frontFace(map("frontFace", parameters.frontFace, {
5639
+ gl2.frontFace(map("frontFace", parameters.frontFace, {
5682
5640
  ccw: GL.CCW,
5683
5641
  cw: GL.CW
5684
5642
  }));
5685
5643
  }
5686
5644
  if (parameters.depthBias !== void 0) {
5687
- gl.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5645
+ gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5688
5646
  }
5689
5647
  if (parameters.depthWriteEnabled !== void 0) {
5690
- gl.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5648
+ gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5691
5649
  }
5692
5650
  if (parameters.depthCompare) {
5693
- parameters.depthCompare !== "always" ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST);
5694
- gl.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5651
+ parameters.depthCompare !== "always" ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST);
5652
+ gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5695
5653
  }
5696
5654
  if (parameters.stencilWriteMask) {
5697
5655
  const mask = parameters.stencilWriteMask;
5698
- gl.stencilMaskSeparate(GL.FRONT, mask);
5699
- gl.stencilMaskSeparate(GL.BACK, mask);
5656
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
5657
+ gl2.stencilMaskSeparate(GL.BACK, mask);
5700
5658
  }
5701
5659
  if (parameters.stencilReadMask) {
5702
5660
  log.warn("stencilReadMask not supported under WebGL");
@@ -5704,16 +5662,16 @@ void main(void) {}`;
5704
5662
  if (parameters.stencilCompare) {
5705
5663
  const mask = parameters.stencilReadMask || 4294967295;
5706
5664
  const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
5707
- parameters.stencilCompare !== "always" ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST);
5708
- gl.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5709
- gl.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
5665
+ parameters.stencilCompare !== "always" ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST);
5666
+ gl2.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5667
+ gl2.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
5710
5668
  }
5711
5669
  if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
5712
5670
  const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
5713
5671
  const sfail = convertStencilOperation("stencilFailOperation", parameters.stencilFailOperation);
5714
5672
  const dpfail = convertStencilOperation("stencilDepthFailOperation", parameters.stencilDepthFailOperation);
5715
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5716
- gl.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5673
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5674
+ gl2.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5717
5675
  }
5718
5676
  }
5719
5677
  function convertCompareFunction(parameter, value) {
@@ -6306,9 +6264,9 @@ void main(void) {}`;
6306
6264
  height
6307
6265
  }));
6308
6266
  const {
6309
- gl
6267
+ gl: gl2
6310
6268
  } = this;
6311
- gl.bindTexture(this.target, this.handle);
6269
+ gl2.bindTexture(this.target, this.handle);
6312
6270
  let dataType = null;
6313
6271
  ({
6314
6272
  data,
@@ -6317,14 +6275,14 @@ void main(void) {}`;
6317
6275
  data,
6318
6276
  compressed
6319
6277
  }));
6320
- let gl2;
6278
+ let gl22;
6321
6279
  withParameters(this.gl, parameters, () => {
6322
6280
  switch (dataType) {
6323
6281
  case "null":
6324
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6282
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6325
6283
  break;
6326
6284
  case "typed-array":
6327
- gl.texImage2D(
6285
+ gl2.texImage2D(
6328
6286
  target,
6329
6287
  level,
6330
6288
  glFormat,
@@ -6340,21 +6298,21 @@ void main(void) {}`;
6340
6298
  );
6341
6299
  break;
6342
6300
  case "buffer":
6343
- gl2 = this.device.assertWebGL2();
6344
- gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6345
- gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6346
- gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
6301
+ gl22 = this.device.assertWebGL2();
6302
+ gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6303
+ gl22.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6304
+ gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
6347
6305
  break;
6348
6306
  case "browser-object":
6349
6307
  if (this.device.isWebGL2) {
6350
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6308
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6351
6309
  } else {
6352
- gl.texImage2D(target, level, glFormat, dataFormat, type, data);
6310
+ gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
6353
6311
  }
6354
6312
  break;
6355
6313
  case "compressed":
6356
6314
  for (const [levelIndex, levelData] of data.entries()) {
6357
- gl.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6315
+ gl2.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6358
6316
  }
6359
6317
  break;
6360
6318
  default:
@@ -6458,24 +6416,24 @@ void main(void) {}`;
6458
6416
  }
6459
6417
  bind(textureUnit = this.textureUnit) {
6460
6418
  const {
6461
- gl
6419
+ gl: gl2
6462
6420
  } = this;
6463
6421
  if (textureUnit !== void 0) {
6464
6422
  this.textureUnit = textureUnit;
6465
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6423
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6466
6424
  }
6467
- gl.bindTexture(this.target, this.handle);
6425
+ gl2.bindTexture(this.target, this.handle);
6468
6426
  return textureUnit;
6469
6427
  }
6470
6428
  unbind(textureUnit = this.textureUnit) {
6471
6429
  const {
6472
- gl
6430
+ gl: gl2
6473
6431
  } = this;
6474
6432
  if (textureUnit !== void 0) {
6475
6433
  this.textureUnit = textureUnit;
6476
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6434
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6477
6435
  }
6478
- gl.bindTexture(this.target, null);
6436
+ gl2.bindTexture(this.target, null);
6479
6437
  return textureUnit;
6480
6438
  }
6481
6439
  // PRIVATE METHODS
@@ -6597,7 +6555,7 @@ void main(void) {}`;
6597
6555
  /* eslint-disable max-statements, max-len */
6598
6556
  async setCubeMapImageData(options) {
6599
6557
  const {
6600
- gl
6558
+ gl: gl2
6601
6559
  } = this;
6602
6560
  const {
6603
6561
  width,
@@ -6619,9 +6577,9 @@ void main(void) {}`;
6619
6577
  }
6620
6578
  resolvedFaces[index].forEach((image, lodLevel) => {
6621
6579
  if (width && height) {
6622
- gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6580
+ gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6623
6581
  } else {
6624
- gl.texImage2D(face, lodLevel, format, format, type, image);
6582
+ gl2.texImage2D(face, lodLevel, format, format, type, image);
6625
6583
  }
6626
6584
  });
6627
6585
  });
@@ -6640,7 +6598,7 @@ void main(void) {}`;
6640
6598
  // generateMipmap = false // TODO
6641
6599
  } = options;
6642
6600
  const {
6643
- gl
6601
+ gl: gl2
6644
6602
  } = this;
6645
6603
  const imageData = pixels || data;
6646
6604
  this.bind();
@@ -6651,9 +6609,9 @@ void main(void) {}`;
6651
6609
  pixels: resolvedImageData
6652
6610
  })));
6653
6611
  } else if (this.width || this.height) {
6654
- gl.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6612
+ gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6655
6613
  } else {
6656
- gl.texImage2D(face, 0, format, format, type, imageData);
6614
+ gl2.texImage2D(face, 0, format, format, type, imageData);
6657
6615
  }
6658
6616
  return this;
6659
6617
  }
@@ -6785,7 +6743,7 @@ void main(void) {}`;
6785
6743
  }
6786
6744
 
6787
6745
  // src/adapter/objects/constants-to-keys.ts
6788
- function getKeyValue(gl, name) {
6746
+ function getKeyValue(gl2, name) {
6789
6747
  if (typeof name !== "string") {
6790
6748
  return name;
6791
6749
  }
@@ -6794,7 +6752,7 @@ void main(void) {}`;
6794
6752
  return number;
6795
6753
  }
6796
6754
  name = name.replace(/^.*\./, "");
6797
- const value = gl[name];
6755
+ const value = gl2[name];
6798
6756
  assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
6799
6757
  return value;
6800
6758
  }
@@ -6808,13 +6766,13 @@ void main(void) {}`;
6808
6766
  constructor(device, props, defaultProps) {
6809
6767
  super(device, props, defaultProps);
6810
6768
  this.device = WebGLDevice.attach(device);
6811
- const gl = this.device.gl;
6812
- assertWebGLContext(gl);
6769
+ const gl2 = this.device.gl;
6770
+ assertWebGLContext(gl2);
6813
6771
  const {
6814
6772
  id
6815
6773
  } = props || {};
6816
- this.gl = gl;
6817
- this.gl2 = gl;
6774
+ this.gl = gl2;
6775
+ this.gl2 = gl2;
6818
6776
  this.id = id || uid(this.constructor.name);
6819
6777
  this._handle = props?.handle;
6820
6778
  if (this._handle === void 0) {
@@ -7132,12 +7090,12 @@ void main(void) {}`;
7132
7090
  /** Check the status */
7133
7091
  _checkStatus() {
7134
7092
  const {
7135
- gl
7093
+ gl: gl2
7136
7094
  } = this;
7137
- const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7138
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
7139
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
7140
- if (status !== gl.FRAMEBUFFER_COMPLETE) {
7095
+ const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7096
+ const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER);
7097
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
7098
+ if (status !== gl2.FRAMEBUFFER_COMPLETE) {
7141
7099
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
7142
7100
  }
7143
7101
  }
@@ -7208,27 +7166,27 @@ void main(void) {}`;
7208
7166
  */
7209
7167
  _attachTexture(attachment, texture, layer, level) {
7210
7168
  const {
7211
- gl,
7212
- gl2
7169
+ gl: gl2,
7170
+ gl2: gl22
7213
7171
  } = this.device;
7214
- gl.bindTexture(texture.target, texture.handle);
7172
+ gl2.bindTexture(texture.target, texture.handle);
7215
7173
  switch (texture.target) {
7216
7174
  case GL.TEXTURE_2D_ARRAY:
7217
7175
  case GL.TEXTURE_3D:
7218
7176
  this.device.assertWebGL2();
7219
- gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7177
+ gl22?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7220
7178
  break;
7221
7179
  case GL.TEXTURE_CUBE_MAP:
7222
7180
  const face = mapIndexToCubeMapFace(layer);
7223
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7181
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7224
7182
  break;
7225
7183
  case GL.TEXTURE_2D:
7226
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7184
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7227
7185
  break;
7228
7186
  default:
7229
7187
  assert2(false, "Illegal texture type");
7230
7188
  }
7231
- gl.bindTexture(texture.target, null);
7189
+ gl2.bindTexture(texture.target, null);
7232
7190
  }
7233
7191
  };
7234
7192
  function mapIndexToCubeMapFace(layer) {
@@ -7292,6 +7250,7 @@ void main(void) {}`;
7292
7250
  */
7293
7251
  resize(options) {
7294
7252
  if (this.canvas) {
7253
+ const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
7295
7254
  this.setDevicePixelRatio(devicePixelRatio, options);
7296
7255
  return;
7297
7256
  }
@@ -7365,9 +7324,9 @@ void main(void) {}`;
7365
7324
 
7366
7325
  // src/context/debug/webgl-developer-tools.ts
7367
7326
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
7368
- function getContextData2(gl) {
7369
- gl.luma = gl.luma || {};
7370
- return gl.luma;
7327
+ function getContextData2(gl2) {
7328
+ gl2.luma = gl2.luma || {};
7329
+ return gl2.luma;
7371
7330
  }
7372
7331
  async function loadWebGLDeveloperTools() {
7373
7332
  if (!globalThis.WebGLDebugUtils) {
@@ -7376,30 +7335,30 @@ void main(void) {}`;
7376
7335
  await loadScript(WEBGL_DEBUG_CDN_URL);
7377
7336
  }
7378
7337
  }
7379
- function makeDebugContext(gl, props = {}) {
7380
- if (!gl) {
7338
+ function makeDebugContext(gl2, props = {}) {
7339
+ if (!gl2) {
7381
7340
  return null;
7382
7341
  }
7383
- return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
7342
+ return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
7384
7343
  }
7385
- function getRealContext(gl) {
7386
- const data = getContextData2(gl);
7387
- return data.realContext ? data.realContext : gl;
7344
+ function getRealContext(gl2) {
7345
+ const data = getContextData2(gl2);
7346
+ return data.realContext ? data.realContext : gl2;
7388
7347
  }
7389
- function getDebugContext(gl, props) {
7348
+ function getDebugContext(gl2, props) {
7390
7349
  if (!globalThis.WebGLDebugUtils) {
7391
7350
  log.warn("webgl-debug not loaded")();
7392
- return gl;
7351
+ return gl2;
7393
7352
  }
7394
- const data = getContextData2(gl);
7353
+ const data = getContextData2(gl2);
7395
7354
  if (data.debugContext) {
7396
7355
  return data.debugContext;
7397
7356
  }
7398
7357
  globalThis.WebGLDebugUtils.init({
7399
7358
  ...GL,
7400
- ...gl
7359
+ ...gl2
7401
7360
  });
7402
- const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7361
+ const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl2, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7403
7362
  for (const key in GL) {
7404
7363
  if (!(key in glDebug) && typeof GL[key] === "number") {
7405
7364
  glDebug[key] = GL[key];
@@ -7407,10 +7366,10 @@ void main(void) {}`;
7407
7366
  }
7408
7367
  class WebGLDebugContext {
7409
7368
  }
7410
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
7369
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
7411
7370
  Object.setPrototypeOf(WebGLDebugContext, glDebug);
7412
7371
  const debugContext = Object.create(WebGLDebugContext);
7413
- data.realContext = gl;
7372
+ data.realContext = gl2;
7414
7373
  data.debugContext = debugContext;
7415
7374
  debugContext.debug = true;
7416
7375
  return debugContext;
@@ -7628,7 +7587,7 @@ void main(void) {}`;
7628
7587
  }
7629
7588
  };
7630
7589
 
7631
- // src/classic/buffer.ts
7590
+ // src/classic/buffer-with-accessor.ts
7632
7591
  var DEBUG_DATA_LENGTH2 = 10;
7633
7592
  var DEPRECATED_PROPS = {
7634
7593
  offset: "accessor.offset",
@@ -7672,7 +7631,7 @@ void main(void) {}`;
7672
7631
  }
7673
7632
  return bufferProps;
7674
7633
  }
7675
- var ClassicBuffer = class extends WEBGLBuffer {
7634
+ var BufferWithAccessor = class extends WEBGLBuffer {
7676
7635
  constructor(device, props = {}) {
7677
7636
  super(WebGLDevice.attach(device), getWEBGLBufferProps(props));
7678
7637
  this.setAccessor(Object.assign({}, props, props.accessor));
@@ -7797,15 +7756,15 @@ void main(void) {}`;
7797
7756
  size
7798
7757
  } = options;
7799
7758
  const {
7800
- gl,
7801
- gl2
7759
+ gl: gl2,
7760
+ gl2: gl22
7802
7761
  } = this;
7803
- assertWebGL2Context(gl);
7804
- gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
7805
- gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
7806
- gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
7807
- gl.bindBuffer(GL.COPY_READ_BUFFER, null);
7808
- gl.bindBuffer(GL.COPY_WRITE_BUFFER, null);
7762
+ assertWebGL2Context(gl2);
7763
+ gl2.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
7764
+ gl2.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
7765
+ gl22?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
7766
+ gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
7767
+ gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
7809
7768
  this.debugData = null;
7810
7769
  return this;
7811
7770
  }
@@ -8076,13 +8035,13 @@ void main(void) {}`;
8076
8035
  ${source2}`;
8077
8036
  source = addGLSLVersion(source);
8078
8037
  const {
8079
- gl
8038
+ gl: gl2
8080
8039
  } = this.device;
8081
- gl.shaderSource(this.handle, source);
8082
- gl.compileShader(this.handle);
8083
- const compileStatus = gl.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8040
+ gl2.shaderSource(this.handle, source);
8041
+ gl2.compileShader(this.handle);
8042
+ const compileStatus = gl2.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8084
8043
  if (!compileStatus) {
8085
- const shaderLog = gl.getShaderInfoLog(this.handle);
8044
+ const shaderLog = gl2.getShaderInfoLog(this.handle);
8086
8045
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
8087
8046
  const messages = parsedLog.filter((message2) => message2.type === "error");
8088
8047
  const formattedLog = formatCompilerLog(messages, source);
@@ -8317,8 +8276,8 @@ ${formattedLog}`)();
8317
8276
  }
8318
8277
 
8319
8278
  // src/adapter/helpers/get-shader-layout.ts
8320
- function getShaderLayout(gl, program) {
8321
- const programBindings = getProgramBindings(gl, program);
8279
+ function getShaderLayout(gl2, program) {
8280
+ const programBindings = getProgramBindings(gl2, program);
8322
8281
  const shaderLayout = {
8323
8282
  attributes: [],
8324
8283
  bindings: []
@@ -8380,21 +8339,21 @@ ${formattedLog}`)();
8380
8339
  }
8381
8340
  return shaderLayout;
8382
8341
  }
8383
- function getProgramBindings(gl, program) {
8342
+ function getProgramBindings(gl2, program) {
8384
8343
  const config = {
8385
- attributes: readAttributeBindings(gl, program),
8386
- uniforms: readUniformBindings(gl, program),
8387
- uniformBlocks: readUniformBlocks(gl, program),
8388
- varyings: readVaryings(gl, program)
8344
+ attributes: readAttributeBindings(gl2, program),
8345
+ uniforms: readUniformBindings(gl2, program),
8346
+ uniformBlocks: readUniformBlocks(gl2, program),
8347
+ varyings: readVaryings(gl2, program)
8389
8348
  };
8390
8349
  Object.seal(config);
8391
8350
  return config;
8392
8351
  }
8393
- function readAttributeBindings(gl, program) {
8352
+ function readAttributeBindings(gl2, program) {
8394
8353
  const attributes = [];
8395
- const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
8354
+ const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
8396
8355
  for (let index = 0; index < count; index++) {
8397
- const activeInfo = gl.getActiveAttrib(program, index);
8356
+ const activeInfo = gl2.getActiveAttrib(program, index);
8398
8357
  if (!activeInfo) {
8399
8358
  throw new Error("activeInfo");
8400
8359
  }
@@ -8403,7 +8362,7 @@ ${formattedLog}`)();
8403
8362
  type: compositeType,
8404
8363
  size
8405
8364
  } = activeInfo;
8406
- const location = gl.getAttribLocation(program, name);
8365
+ const location = gl2.getAttribLocation(program, name);
8407
8366
  if (location >= 0) {
8408
8367
  const {
8409
8368
  glType,
@@ -8427,15 +8386,15 @@ ${formattedLog}`)();
8427
8386
  attributes.sort((a, b) => a.location - b.location);
8428
8387
  return attributes;
8429
8388
  }
8430
- function readVaryings(gl, program) {
8431
- if (!isWebGL2(gl)) {
8389
+ function readVaryings(gl2, program) {
8390
+ if (!isWebGL2(gl2)) {
8432
8391
  return [];
8433
8392
  }
8434
- const gl2 = gl;
8393
+ const gl22 = gl2;
8435
8394
  const varyings = [];
8436
- const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8395
+ const count = gl2.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8437
8396
  for (let location = 0; location < count; location++) {
8438
- const activeInfo = gl2.getTransformFeedbackVarying(program, location);
8397
+ const activeInfo = gl22.getTransformFeedbackVarying(program, location);
8439
8398
  if (!activeInfo) {
8440
8399
  throw new Error("activeInfo");
8441
8400
  }
@@ -8462,11 +8421,11 @@ ${formattedLog}`)();
8462
8421
  varyings.sort((a, b) => a.location - b.location);
8463
8422
  return varyings;
8464
8423
  }
8465
- function readUniformBindings(gl, program) {
8424
+ function readUniformBindings(gl2, program) {
8466
8425
  const uniforms = [];
8467
- const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8426
+ const uniformCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8468
8427
  for (let i = 0; i < uniformCount; i++) {
8469
- const activeInfo = gl.getActiveUniform(program, i);
8428
+ const activeInfo = gl2.getActiveUniform(program, i);
8470
8429
  if (!activeInfo) {
8471
8430
  throw new Error("activeInfo");
8472
8431
  }
@@ -8479,7 +8438,7 @@ ${formattedLog}`)();
8479
8438
  name,
8480
8439
  isArray: isArray2
8481
8440
  } = parseUniformName(rawName);
8482
- let webglLocation = gl.getUniformLocation(program, name);
8441
+ let webglLocation = gl2.getUniformLocation(program, name);
8483
8442
  const uniformInfo = {
8484
8443
  // WebGL locations are uniquely typed but just numbers
8485
8444
  location: webglLocation,
@@ -8492,7 +8451,7 @@ ${formattedLog}`)();
8492
8451
  if (uniformInfo.size > 1) {
8493
8452
  for (let j = 0; j < uniformInfo.size; j++) {
8494
8453
  const elementName = `${name}[${j}]`;
8495
- webglLocation = gl.getUniformLocation(program, elementName);
8454
+ webglLocation = gl2.getUniformLocation(program, elementName);
8496
8455
  const arrayElementUniformInfo = {
8497
8456
  ...uniformInfo,
8498
8457
  name: elementName,
@@ -8504,17 +8463,17 @@ ${formattedLog}`)();
8504
8463
  }
8505
8464
  return uniforms;
8506
8465
  }
8507
- function readUniformBlocks(gl, program) {
8508
- if (!isWebGL2(gl)) {
8466
+ function readUniformBlocks(gl2, program) {
8467
+ if (!isWebGL2(gl2)) {
8509
8468
  return [];
8510
8469
  }
8511
- const gl2 = gl;
8512
- const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
8470
+ const gl22 = gl2;
8471
+ const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
8513
8472
  const uniformBlocks = [];
8514
- const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8473
+ const blockCount = gl22.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8515
8474
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
8516
8475
  const blockInfo = {
8517
- name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
8476
+ name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
8518
8477
  location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),
8519
8478
  byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),
8520
8479
  vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
@@ -8523,12 +8482,12 @@ ${formattedLog}`)();
8523
8482
  uniforms: []
8524
8483
  };
8525
8484
  const uniformIndices = getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
8526
- const uniformType = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8527
- const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8528
- const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8529
- const uniformStride = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
8485
+ const uniformType = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8486
+ const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8487
+ const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8488
+ const uniformStride = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
8530
8489
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
8531
- const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
8490
+ const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
8532
8491
  if (!activeInfo) {
8533
8492
  throw new Error("activeInfo");
8534
8493
  }
@@ -8597,8 +8556,8 @@ ${formattedLog}`)();
8597
8556
  }
8598
8557
 
8599
8558
  // src/adapter/helpers/set-uniform.ts
8600
- function setUniform(gl, location, type, value) {
8601
- const gl2 = gl;
8559
+ function setUniform(gl2, location, type, value) {
8560
+ const gl22 = gl2;
8602
8561
  if (typeof value === "number") {
8603
8562
  switch (type) {
8604
8563
  case GL.SAMPLER_2D:
@@ -8616,7 +8575,7 @@ ${formattedLog}`)();
8616
8575
  case GL.UNSIGNED_INT_SAMPLER_3D:
8617
8576
  case GL.UNSIGNED_INT_SAMPLER_CUBE:
8618
8577
  case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
8619
- return gl.uniform1i(location, value);
8578
+ return gl2.uniform1i(location, value);
8620
8579
  }
8621
8580
  }
8622
8581
  if (value === true) {
@@ -8628,55 +8587,55 @@ ${formattedLog}`)();
8628
8587
  const arrayValue = typeof value === "number" ? [value] : value;
8629
8588
  switch (type) {
8630
8589
  case GL.FLOAT:
8631
- return gl.uniform1fv(location, arrayValue);
8590
+ return gl2.uniform1fv(location, arrayValue);
8632
8591
  case GL.FLOAT_VEC2:
8633
- return gl.uniform2fv(location, arrayValue);
8592
+ return gl2.uniform2fv(location, arrayValue);
8634
8593
  case GL.FLOAT_VEC3:
8635
- return gl.uniform3fv(location, arrayValue);
8594
+ return gl2.uniform3fv(location, arrayValue);
8636
8595
  case GL.FLOAT_VEC4:
8637
- return gl.uniform4fv(location, arrayValue);
8596
+ return gl2.uniform4fv(location, arrayValue);
8638
8597
  case GL.INT:
8639
- return gl.uniform1iv(location, arrayValue);
8598
+ return gl2.uniform1iv(location, arrayValue);
8640
8599
  case GL.INT_VEC2:
8641
- return gl.uniform2iv(location, arrayValue);
8600
+ return gl2.uniform2iv(location, arrayValue);
8642
8601
  case GL.INT_VEC3:
8643
- return gl.uniform3iv(location, arrayValue);
8602
+ return gl2.uniform3iv(location, arrayValue);
8644
8603
  case GL.INT_VEC4:
8645
- return gl.uniform4iv(location, arrayValue);
8604
+ return gl2.uniform4iv(location, arrayValue);
8646
8605
  case GL.BOOL:
8647
- return gl.uniform1iv(location, arrayValue);
8606
+ return gl2.uniform1iv(location, arrayValue);
8648
8607
  case GL.BOOL_VEC2:
8649
- return gl.uniform2iv(location, arrayValue);
8608
+ return gl2.uniform2iv(location, arrayValue);
8650
8609
  case GL.BOOL_VEC3:
8651
- return gl.uniform3iv(location, arrayValue);
8610
+ return gl2.uniform3iv(location, arrayValue);
8652
8611
  case GL.BOOL_VEC4:
8653
- return gl.uniform4iv(location, arrayValue);
8612
+ return gl2.uniform4iv(location, arrayValue);
8654
8613
  case GL.UNSIGNED_INT:
8655
- return gl2.uniform1uiv(location, arrayValue, 1);
8614
+ return gl22.uniform1uiv(location, arrayValue, 1);
8656
8615
  case GL.UNSIGNED_INT_VEC2:
8657
- return gl2.uniform2uiv(location, arrayValue, 2);
8616
+ return gl22.uniform2uiv(location, arrayValue, 2);
8658
8617
  case GL.UNSIGNED_INT_VEC3:
8659
- return gl2.uniform3uiv(location, arrayValue, 3);
8618
+ return gl22.uniform3uiv(location, arrayValue, 3);
8660
8619
  case GL.UNSIGNED_INT_VEC4:
8661
- return gl2.uniform4uiv(location, arrayValue, 4);
8620
+ return gl22.uniform4uiv(location, arrayValue, 4);
8662
8621
  case GL.FLOAT_MAT2:
8663
- return gl.uniformMatrix2fv(location, false, arrayValue);
8622
+ return gl2.uniformMatrix2fv(location, false, arrayValue);
8664
8623
  case GL.FLOAT_MAT3:
8665
- return gl.uniformMatrix3fv(location, false, arrayValue);
8624
+ return gl2.uniformMatrix3fv(location, false, arrayValue);
8666
8625
  case GL.FLOAT_MAT4:
8667
- return gl.uniformMatrix4fv(location, false, arrayValue);
8626
+ return gl2.uniformMatrix4fv(location, false, arrayValue);
8668
8627
  case GL.FLOAT_MAT2x3:
8669
- return gl2.uniformMatrix2x3fv(location, false, arrayValue);
8628
+ return gl22.uniformMatrix2x3fv(location, false, arrayValue);
8670
8629
  case GL.FLOAT_MAT2x4:
8671
- return gl2.uniformMatrix2x4fv(location, false, arrayValue);
8630
+ return gl22.uniformMatrix2x4fv(location, false, arrayValue);
8672
8631
  case GL.FLOAT_MAT3x2:
8673
- return gl2.uniformMatrix3x2fv(location, false, arrayValue);
8632
+ return gl22.uniformMatrix3x2fv(location, false, arrayValue);
8674
8633
  case GL.FLOAT_MAT3x4:
8675
- return gl2.uniformMatrix3x4fv(location, false, arrayValue);
8634
+ return gl22.uniformMatrix3x4fv(location, false, arrayValue);
8676
8635
  case GL.FLOAT_MAT4x2:
8677
- return gl2.uniformMatrix4x2fv(location, false, arrayValue);
8636
+ return gl22.uniformMatrix4x2fv(location, false, arrayValue);
8678
8637
  case GL.FLOAT_MAT4x3:
8679
- return gl2.uniformMatrix4x3fv(location, false, arrayValue);
8638
+ return gl22.uniformMatrix4x3fv(location, false, arrayValue);
8680
8639
  }
8681
8640
  throw new Error("Illegal uniform");
8682
8641
  }
@@ -8724,20 +8683,20 @@ ${formattedLog}`)();
8724
8683
  divisor
8725
8684
  } = accessor;
8726
8685
  const {
8727
- gl,
8728
- gl2
8686
+ gl: gl2,
8687
+ gl2: gl22
8729
8688
  } = this;
8730
8689
  location = Number(location);
8731
8690
  this.bind(() => {
8732
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);
8691
+ gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
8733
8692
  if (integer) {
8734
8693
  this.device.assertWebGL2();
8735
- gl2.vertexAttribIPointer(location, size, type, stride, offset);
8694
+ gl22.vertexAttribIPointer(location, size, type, stride, offset);
8736
8695
  } else {
8737
- gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
8696
+ gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
8738
8697
  }
8739
- gl.enableVertexAttribArray(location);
8740
- gl2.vertexAttribDivisor(location, divisor || 0);
8698
+ gl2.enableVertexAttribArray(location);
8699
+ gl22.vertexAttribDivisor(location, divisor || 0);
8741
8700
  });
8742
8701
  return this;
8743
8702
  }
@@ -8930,22 +8889,22 @@ ${formattedLog}`)();
8930
8889
  // setBindings(bindings: Record<string, Binding>): void {}
8931
8890
  _compileAndLink() {
8932
8891
  const {
8933
- gl
8892
+ gl: gl2
8934
8893
  } = this.device;
8935
- gl.attachShader(this.handle, this.vs.handle);
8936
- gl.attachShader(this.handle, this.fs.handle);
8894
+ gl2.attachShader(this.handle, this.vs.handle);
8895
+ gl2.attachShader(this.handle, this.fs.handle);
8937
8896
  log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
8938
- gl.linkProgram(this.handle);
8897
+ gl2.linkProgram(this.handle);
8939
8898
  log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
8940
- if (gl.debug || log.level > 0) {
8941
- const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
8899
+ if (gl2.debug || log.level > 0) {
8900
+ const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
8942
8901
  if (!linked) {
8943
- throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
8902
+ throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
8944
8903
  }
8945
- gl.validateProgram(this.handle);
8946
- const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
8904
+ gl2.validateProgram(this.handle);
8905
+ const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
8947
8906
  if (!validated) {
8948
- throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
8907
+ throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
8949
8908
  }
8950
8909
  }
8951
8910
  }
@@ -9351,18 +9310,18 @@ ${formattedLog}`)();
9351
9310
  * @param gl
9352
9311
  * @returns
9353
9312
  */
9354
- static attach(gl) {
9355
- if (gl instanceof _WebGLDevice) {
9356
- return gl;
9313
+ static attach(gl2) {
9314
+ if (gl2 instanceof _WebGLDevice) {
9315
+ return gl2;
9357
9316
  }
9358
- if (gl?.device instanceof Device) {
9359
- return gl.device;
9317
+ if (gl2?.device instanceof Device) {
9318
+ return gl2.device;
9360
9319
  }
9361
- if (!isWebGL3(gl)) {
9320
+ if (!isWebGL3(gl2)) {
9362
9321
  throw new Error("Invalid WebGLRenderingContext");
9363
9322
  }
9364
9323
  return new _WebGLDevice({
9365
- gl
9324
+ gl: gl2
9366
9325
  });
9367
9326
  }
9368
9327
  static async create(props = {}) {
@@ -9402,19 +9361,19 @@ ${formattedLog}`)();
9402
9361
  reason: "destroyed",
9403
9362
  message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
9404
9363
  });
9405
- let gl = props.gl || null;
9406
- gl = gl || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9364
+ let gl2 = props.gl || null;
9365
+ gl2 = gl2 || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9407
9366
  ...props,
9408
9367
  onContextLost
9409
9368
  }) : null);
9410
- gl = gl || (!isBrowser() ? createHeadlessContext({
9369
+ gl2 = gl2 || (!isBrowser() ? createHeadlessContext({
9411
9370
  ...props,
9412
9371
  onContextLost
9413
9372
  }) : null);
9414
- if (!gl) {
9373
+ if (!gl2) {
9415
9374
  throw new Error("WebGL context creation failed");
9416
9375
  }
9417
- this.handle = gl;
9376
+ this.handle = gl2;
9418
9377
  this.gl = this.handle;
9419
9378
  this.gl2 = this.gl;
9420
9379
  this.isWebGL2 = isWebGL22(this.gl);
@@ -9493,7 +9452,7 @@ ${formattedLog}`)();
9493
9452
  }
9494
9453
  createBuffer(props) {
9495
9454
  const newProps = this._getBufferProps(props);
9496
- return new ClassicBuffer(this, newProps);
9455
+ return new BufferWithAccessor(this, newProps);
9497
9456
  }
9498
9457
  _createTexture(props) {
9499
9458
  return new WEBGLTexture(this, props);
@@ -9602,11 +9561,11 @@ ${formattedLog}`)();
9602
9561
  * Be aware that there are some duplicates especially for constants that are 0,
9603
9562
  * so this isn't guaranteed to return the right key in all cases.
9604
9563
  */
9605
- getGLKey(value, gl) {
9606
- gl = gl || this.gl2 || this.gl;
9564
+ getGLKey(value, gl2) {
9565
+ gl2 = gl2 || this.gl2 || this.gl;
9607
9566
  const number = Number(value);
9608
- for (const key in gl) {
9609
- if (gl[key] === number) {
9567
+ for (const key in gl2) {
9568
+ if (gl2[key] === number) {
9610
9569
  return `GL.${key}`;
9611
9570
  }
9612
9571
  }
@@ -9618,20 +9577,20 @@ ${formattedLog}`)();
9618
9577
  // Public `Device` API
9619
9578
  //
9620
9579
  __publicField(WebGLDevice, "type", "webgl");
9621
- function isWebGL3(gl) {
9622
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
9580
+ function isWebGL3(gl2) {
9581
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
9623
9582
  return true;
9624
9583
  }
9625
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9584
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9626
9585
  return true;
9627
9586
  }
9628
- return Boolean(gl && Number.isFinite(gl._version));
9587
+ return Boolean(gl2 && Number.isFinite(gl2._version));
9629
9588
  }
9630
- function isWebGL22(gl) {
9631
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9589
+ function isWebGL22(gl2) {
9590
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9632
9591
  return true;
9633
9592
  }
9634
- return Boolean(gl && gl._version === 2);
9593
+ return Boolean(gl2 && gl2._version === 2);
9635
9594
  }
9636
9595
 
9637
9596
  // src/classic/clear.ts
@@ -9639,8 +9598,8 @@ ${formattedLog}`)();
9639
9598
  var GL_STENCIL_BUFFER_BIT2 = 1024;
9640
9599
  var GL_COLOR_BUFFER_BIT2 = 16384;
9641
9600
  var ERR_ARGUMENTS = "clear: bad arguments";
9642
- function clear(gl, options) {
9643
- const device = WebGLDevice.attach(gl);
9601
+ function clear(gl2, options) {
9602
+ const device = WebGLDevice.attach(gl2);
9644
9603
  const {
9645
9604
  framebuffer = null,
9646
9605
  color = null,
@@ -9735,7 +9694,7 @@ ${formattedLog}`)();
9735
9694
  } = getFramebuffer2(source);
9736
9695
  assert2(framebuffer);
9737
9696
  const {
9738
- gl,
9697
+ gl: gl2,
9739
9698
  handle
9740
9699
  } = framebuffer;
9741
9700
  sourceWidth = sourceWidth || framebuffer.width;
@@ -9747,9 +9706,9 @@ ${formattedLog}`)();
9747
9706
  sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
9748
9707
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
9749
9708
  sourceType = sourceType || getGLTypeFromTypedArray(target);
9750
- const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
9751
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
9752
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
9709
+ const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
9710
+ gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
9711
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
9753
9712
  if (deleteFramebuffer) {
9754
9713
  framebuffer.destroy();
9755
9714
  }
@@ -9782,7 +9741,7 @@ ${formattedLog}`)();
9782
9741
  const components = glFormatToComponents(sourceFormat);
9783
9742
  const byteCount = glTypeToBytes(sourceType);
9784
9743
  const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
9785
- target = new ClassicBuffer(gl2, {
9744
+ target = new BufferWithAccessor(gl2, {
9786
9745
  byteLength,
9787
9746
  accessor: {
9788
9747
  type: sourceType,
@@ -9806,6 +9765,85 @@ ${formattedLog}`)();
9806
9765
  }
9807
9766
  return target;
9808
9767
  }
9768
+ function copyToTexture(source, target, options) {
9769
+ const {
9770
+ sourceX = 0,
9771
+ sourceY = 0,
9772
+ // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
9773
+ targetMipmaplevel = 0,
9774
+ targetInternalFormat = GL.RGBA
9775
+ } = options || {};
9776
+ let {
9777
+ targetX,
9778
+ targetY,
9779
+ targetZ,
9780
+ width,
9781
+ // defaults to target width
9782
+ height
9783
+ // defaults to target height
9784
+ } = options || {};
9785
+ const {
9786
+ framebuffer,
9787
+ deleteFramebuffer
9788
+ } = getFramebuffer2(source);
9789
+ assert2(framebuffer);
9790
+ const webglFramebuffer = framebuffer;
9791
+ const {
9792
+ device,
9793
+ handle
9794
+ } = webglFramebuffer;
9795
+ const isSubCopy = typeof targetX !== "undefined" || typeof targetY !== "undefined" || typeof targetZ !== "undefined";
9796
+ targetX = targetX || 0;
9797
+ targetY = targetY || 0;
9798
+ targetZ = targetZ || 0;
9799
+ const prevHandle2 = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
9800
+ assert2(target);
9801
+ let texture = null;
9802
+ let textureTarget;
9803
+ if (target instanceof Texture) {
9804
+ texture = target;
9805
+ width = Number.isFinite(width) ? width : texture.width;
9806
+ height = Number.isFinite(height) ? height : texture.height;
9807
+ texture.bind(0);
9808
+ textureTarget = texture.target;
9809
+ } else {
9810
+ textureTarget = target;
9811
+ }
9812
+ if (!isSubCopy) {
9813
+ device.gl.copyTexImage2D(
9814
+ textureTarget,
9815
+ targetMipmaplevel,
9816
+ targetInternalFormat,
9817
+ sourceX,
9818
+ sourceY,
9819
+ width,
9820
+ height,
9821
+ 0
9822
+ /* border must be 0 */
9823
+ );
9824
+ } else {
9825
+ switch (textureTarget) {
9826
+ case GL.TEXTURE_2D:
9827
+ case GL.TEXTURE_CUBE_MAP:
9828
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
9829
+ break;
9830
+ case GL.TEXTURE_2D_ARRAY:
9831
+ case GL.TEXTURE_3D:
9832
+ device.assertWebGL2();
9833
+ device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
9834
+ break;
9835
+ default:
9836
+ }
9837
+ }
9838
+ if (texture) {
9839
+ texture.unbind();
9840
+ }
9841
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
9842
+ if (deleteFramebuffer) {
9843
+ framebuffer.destroy();
9844
+ }
9845
+ return texture;
9846
+ }
9809
9847
  function getFramebuffer2(source) {
9810
9848
  if (!(source instanceof Framebuffer)) {
9811
9849
  return {