@luma.gl/webgl 9.0.0-alpha.25 → 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.
package/dist/dist.dev.js CHANGED
@@ -53,6 +53,7 @@ var __exports__ = (() => {
53
53
  assertWebGLContext: () => assertWebGLContext,
54
54
  clear: () => clear,
55
55
  convertGLToTextureFormat: () => convertGLToTextureFormat,
56
+ copyToTexture: () => copyToTexture,
56
57
  getParameters: () => getParameters,
57
58
  getProgramBindings: () => getProgramBindings,
58
59
  getShaderLayout: () => getShaderLayout,
@@ -106,11 +107,11 @@ var __exports__ = (() => {
106
107
  if (!headlessGL) {
107
108
  throw new Error(ERR_HEADLESSGL_LOAD);
108
109
  }
109
- const gl = headlessGL(width, height, options);
110
- if (!gl) {
110
+ const gl2 = headlessGL(width, height, options);
111
+ if (!gl2) {
111
112
  throw new Error(ERR_HEADLESSGL_FAILED);
112
113
  }
113
- return gl;
114
+ return gl2;
114
115
  }
115
116
 
116
117
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
@@ -1249,9 +1250,9 @@ var __exports__ = (() => {
1249
1250
  };
1250
1251
  if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
1251
1252
  if (props.data instanceof Uint32Array) {
1252
- props.indexType = "uint32";
1253
+ newProps.indexType = "uint32";
1253
1254
  } else if (props.data instanceof Uint16Array) {
1254
- props.indexType = "uint16";
1255
+ newProps.indexType = "uint16";
1255
1256
  }
1256
1257
  }
1257
1258
  return newProps;
@@ -1403,7 +1404,7 @@ var __exports__ = (() => {
1403
1404
  * Use devicePixelRatio to set canvas width and height
1404
1405
  * @note this is a raw port of luma.gl v8 code. Might be worth a review
1405
1406
  */
1406
- setDevicePixelRatio(devicePixelRatio2, options = {}) {
1407
+ setDevicePixelRatio(devicePixelRatio, options = {}) {
1407
1408
  if (!this.htmlCanvas) {
1408
1409
  return;
1409
1410
  }
@@ -1411,13 +1412,13 @@ var __exports__ = (() => {
1411
1412
  let clientHeight = "height" in options ? options.height : this.htmlCanvas.clientHeight;
1412
1413
  if (!clientWidth || !clientHeight) {
1413
1414
  log.log(1, "Canvas clientWidth/clientHeight is 0")();
1414
- devicePixelRatio2 = 1;
1415
+ devicePixelRatio = 1;
1415
1416
  clientWidth = this.htmlCanvas.width || 1;
1416
1417
  clientHeight = this.htmlCanvas.height || 1;
1417
1418
  }
1418
1419
  const cachedSize = this._canvasSizeInfo;
1419
- if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio2) {
1420
- let clampedPixelRatio = devicePixelRatio2;
1420
+ if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio) {
1421
+ let clampedPixelRatio = devicePixelRatio;
1421
1422
  const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
1422
1423
  const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
1423
1424
  this.htmlCanvas.width = canvasWidth;
@@ -1431,17 +1432,17 @@ var __exports__ = (() => {
1431
1432
  }
1432
1433
  this._canvasSizeInfo.clientWidth = clientWidth;
1433
1434
  this._canvasSizeInfo.clientHeight = clientHeight;
1434
- this._canvasSizeInfo.devicePixelRatio = devicePixelRatio2;
1435
+ this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
1435
1436
  }
1436
1437
  }
1437
1438
  // PRIVATE
1438
1439
  /** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
1439
1440
  getDrawingBufferSize() {
1440
- const gl = this.device.gl;
1441
- if (!gl) {
1441
+ const gl2 = this.device.gl;
1442
+ if (!gl2) {
1442
1443
  throw new Error("canvas size");
1443
1444
  }
1444
- return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1445
+ return [gl2.drawingBufferWidth, gl2.drawingBufferHeight];
1445
1446
  }
1446
1447
  /** Perform platform specific updates (WebGPU vs WebGL) */
1447
1448
  /**
@@ -1864,7 +1865,11 @@ var __exports__ = (() => {
1864
1865
  constructor(device, props) {
1865
1866
  super(device, props, _RenderPass.defaultProps);
1866
1867
  }
1867
- /** 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
+ */
1868
1873
  // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
1869
1874
  // beginOcclusionQuery(queryIndex: number): void;
1870
1875
  // endOcclusionQuery(): void;
@@ -2269,43 +2274,43 @@ var __exports__ = (() => {
2269
2274
  error(opt_msg);
2270
2275
  }
2271
2276
  }
2272
- function wrapGLError(gl) {
2273
- const f = gl.getError;
2274
- gl.getError = function getError() {
2277
+ function wrapGLError(gl2) {
2278
+ const f = gl2.getError;
2279
+ gl2.getError = function getError() {
2275
2280
  let err;
2276
2281
  do {
2277
- err = f.apply(gl);
2278
- if (err !== gl.NO_ERROR) {
2282
+ err = f.apply(gl2);
2283
+ if (err !== gl2.NO_ERROR) {
2279
2284
  glErrorShadow[err] = true;
2280
2285
  }
2281
- } while (err !== gl.NO_ERROR);
2286
+ } while (err !== gl2.NO_ERROR);
2282
2287
  for (err in glErrorShadow) {
2283
2288
  if (glErrorShadow[err]) {
2284
2289
  delete glErrorShadow[err];
2285
2290
  return parseInt(err, 10);
2286
2291
  }
2287
2292
  }
2288
- return gl.NO_ERROR;
2293
+ return gl2.NO_ERROR;
2289
2294
  };
2290
2295
  }
2291
2296
  var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
2292
- const gl = ext.gl;
2297
+ const gl2 = ext.gl;
2293
2298
  this.ext = ext;
2294
2299
  this.isAlive = true;
2295
2300
  this.hasBeenBound = false;
2296
2301
  this.elementArrayBuffer = null;
2297
2302
  this.attribs = new Array(ext.maxVertexAttribs);
2298
2303
  for (let n = 0; n < this.attribs.length; n++) {
2299
- const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl);
2304
+ const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
2300
2305
  this.attribs[n] = attrib;
2301
2306
  }
2302
2307
  this.maxAttrib = 0;
2303
2308
  };
2304
- WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
2309
+ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
2305
2310
  this.enabled = false;
2306
2311
  this.buffer = null;
2307
2312
  this.size = 4;
2308
- this.type = gl.FLOAT;
2313
+ this.type = gl2.FLOAT;
2309
2314
  this.normalized = false;
2310
2315
  this.stride = 16;
2311
2316
  this.offset = 0;
@@ -2315,19 +2320,19 @@ var __exports__ = (() => {
2315
2320
  WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
2316
2321
  this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
2317
2322
  };
2318
- var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
2323
+ var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
2319
2324
  const self = this;
2320
- this.gl = gl;
2321
- wrapGLError(gl);
2325
+ this.gl = gl2;
2326
+ wrapGLError(gl2);
2322
2327
  const original = this.original = {
2323
- getParameter: gl.getParameter,
2324
- enableVertexAttribArray: gl.enableVertexAttribArray,
2325
- disableVertexAttribArray: gl.disableVertexAttribArray,
2326
- bindBuffer: gl.bindBuffer,
2327
- getVertexAttrib: gl.getVertexAttrib,
2328
- 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
2329
2334
  };
2330
- gl.getParameter = function getParameter(pname) {
2335
+ gl2.getParameter = function getParameter(pname) {
2331
2336
  if (pname === self.VERTEX_ARRAY_BINDING_OES) {
2332
2337
  if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
2333
2338
  return null;
@@ -2336,53 +2341,53 @@ var __exports__ = (() => {
2336
2341
  }
2337
2342
  return original.getParameter.apply(this, arguments);
2338
2343
  };
2339
- gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
2344
+ gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
2340
2345
  const vao = self.currentVertexArrayObject;
2341
2346
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2342
2347
  const attrib = vao.attribs[index];
2343
2348
  attrib.enabled = true;
2344
2349
  return original.enableVertexAttribArray.apply(this, arguments);
2345
2350
  };
2346
- gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
2351
+ gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
2347
2352
  const vao = self.currentVertexArrayObject;
2348
2353
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2349
2354
  const attrib = vao.attribs[index];
2350
2355
  attrib.enabled = false;
2351
2356
  return original.disableVertexAttribArray.apply(this, arguments);
2352
2357
  };
2353
- gl.bindBuffer = function bindBuffer2(target, buffer) {
2358
+ gl2.bindBuffer = function bindBuffer2(target, buffer) {
2354
2359
  switch (target) {
2355
- case gl.ARRAY_BUFFER:
2360
+ case gl2.ARRAY_BUFFER:
2356
2361
  self.currentArrayBuffer = buffer;
2357
2362
  break;
2358
- case gl.ELEMENT_ARRAY_BUFFER:
2363
+ case gl2.ELEMENT_ARRAY_BUFFER:
2359
2364
  self.currentVertexArrayObject.elementArrayBuffer = buffer;
2360
2365
  break;
2361
2366
  default:
2362
2367
  }
2363
2368
  return original.bindBuffer.apply(this, arguments);
2364
2369
  };
2365
- gl.getVertexAttrib = function getVertexAttrib(index, pname) {
2370
+ gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
2366
2371
  const vao = self.currentVertexArrayObject;
2367
2372
  const attrib = vao.attribs[index];
2368
2373
  switch (pname) {
2369
- case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2374
+ case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2370
2375
  return attrib.buffer;
2371
- case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
2376
+ case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
2372
2377
  return attrib.enabled;
2373
- case gl.VERTEX_ATTRIB_ARRAY_SIZE:
2378
+ case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
2374
2379
  return attrib.size;
2375
- case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
2380
+ case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
2376
2381
  return attrib.stride;
2377
- case gl.VERTEX_ATTRIB_ARRAY_TYPE:
2382
+ case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
2378
2383
  return attrib.type;
2379
- case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2384
+ case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2380
2385
  return attrib.normalized;
2381
2386
  default:
2382
2387
  return original.getVertexAttrib.apply(this, arguments);
2383
2388
  }
2384
2389
  };
2385
- gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2390
+ gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2386
2391
  const vao = self.currentVertexArrayObject;
2387
2392
  vao.maxAttrib = Math.max(vao.maxAttrib, indx);
2388
2393
  const attrib = vao.attribs[indx];
@@ -2395,11 +2400,11 @@ var __exports__ = (() => {
2395
2400
  attrib.recache();
2396
2401
  return original.vertexAttribPointer.apply(this, arguments);
2397
2402
  };
2398
- if (gl.instrumentExtension) {
2399
- gl.instrumentExtension(this, "OES_vertex_array_object");
2403
+ if (gl2.instrumentExtension) {
2404
+ gl2.instrumentExtension(this, "OES_vertex_array_object");
2400
2405
  }
2401
- if (gl.canvas) {
2402
- gl.canvas.addEventListener("webglcontextrestored", () => {
2406
+ if (gl2.canvas) {
2407
+ gl2.canvas.addEventListener("webglcontextrestored", () => {
2403
2408
  log2("OESVertexArrayObject emulation library context restored");
2404
2409
  self.reset_();
2405
2410
  }, true);
@@ -2414,8 +2419,8 @@ var __exports__ = (() => {
2414
2419
  this.vertexArrayObjects.isAlive = false;
2415
2420
  }
2416
2421
  }
2417
- const gl = this.gl;
2418
- this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
2422
+ const gl2 = this.gl;
2423
+ this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
2419
2424
  this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
2420
2425
  this.currentVertexArrayObject = null;
2421
2426
  this.currentArrayBuffer = null;
@@ -2443,9 +2448,9 @@ var __exports__ = (() => {
2443
2448
  return false;
2444
2449
  };
2445
2450
  OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
2446
- const gl = this.gl;
2451
+ const gl2 = this.gl;
2447
2452
  if (arrayObject && !arrayObject.isAlive) {
2448
- synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2453
+ synthesizeGLError(gl2.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2449
2454
  return;
2450
2455
  }
2451
2456
  const original = this.original;
@@ -2457,7 +2462,7 @@ var __exports__ = (() => {
2457
2462
  return;
2458
2463
  }
2459
2464
  if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
2460
- original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2465
+ original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2461
2466
  }
2462
2467
  let currentBinding = this.currentArrayBuffer;
2463
2468
  const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
@@ -2466,43 +2471,43 @@ var __exports__ = (() => {
2466
2471
  const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
2467
2472
  if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
2468
2473
  if (attrib.enabled) {
2469
- original.enableVertexAttribArray.call(gl, n);
2474
+ original.enableVertexAttribArray.call(gl2, n);
2470
2475
  } else {
2471
- original.disableVertexAttribArray.call(gl, n);
2476
+ original.disableVertexAttribArray.call(gl2, n);
2472
2477
  }
2473
2478
  }
2474
2479
  if (attrib.enabled) {
2475
2480
  let bufferChanged = false;
2476
2481
  if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
2477
2482
  if (currentBinding !== attrib.buffer) {
2478
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
2483
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
2479
2484
  currentBinding = attrib.buffer;
2480
2485
  }
2481
2486
  bufferChanged = true;
2482
2487
  }
2483
2488
  if (bufferChanged || attrib.cached !== oldAttrib.cached) {
2484
- 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);
2485
2490
  }
2486
2491
  }
2487
2492
  }
2488
2493
  if (this.currentArrayBuffer !== currentBinding) {
2489
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
2494
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
2490
2495
  }
2491
2496
  };
2492
- function polyfillVertexArrayObject(gl) {
2493
- if (typeof gl.createVertexArray === "function") {
2497
+ function polyfillVertexArrayObject(gl2) {
2498
+ if (typeof gl2.createVertexArray === "function") {
2494
2499
  return;
2495
2500
  }
2496
- const original_getSupportedExtensions = gl.getSupportedExtensions;
2497
- gl.getSupportedExtensions = function getSupportedExtensions() {
2501
+ const original_getSupportedExtensions = gl2.getSupportedExtensions;
2502
+ gl2.getSupportedExtensions = function getSupportedExtensions() {
2498
2503
  const list = original_getSupportedExtensions.call(this) || [];
2499
2504
  if (list.indexOf("OES_vertex_array_object") < 0) {
2500
2505
  list.push("OES_vertex_array_object");
2501
2506
  }
2502
2507
  return list;
2503
2508
  };
2504
- const original_getExtension = gl.getExtension;
2505
- gl.getExtension = function getExtension(name) {
2509
+ const original_getExtension = gl2.getExtension;
2510
+ gl2.getExtension = function getExtension(name) {
2506
2511
  const ext = original_getExtension.call(this, name);
2507
2512
  if (ext) {
2508
2513
  return ext;
@@ -2510,7 +2515,7 @@ var __exports__ = (() => {
2510
2515
  if (name !== "OES_vertex_array_object") {
2511
2516
  return null;
2512
2517
  }
2513
- if (!gl.__OESVertexArrayObject) {
2518
+ if (!gl2.__OESVertexArrayObject) {
2514
2519
  this.__OESVertexArrayObject = new OESVertexArrayObject(this);
2515
2520
  }
2516
2521
  return this.__OESVertexArrayObject;
@@ -3187,31 +3192,31 @@ var __exports__ = (() => {
3187
3192
  // src/context/context/webgl-checks.ts
3188
3193
  var ERR_CONTEXT = "Invalid WebGLRenderingContext";
3189
3194
  var ERR_WEBGL2 = "Requires WebGL2";
3190
- function isWebGL(gl) {
3191
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
3195
+ function isWebGL(gl2) {
3196
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
3192
3197
  return true;
3193
3198
  }
3194
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3199
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3195
3200
  return true;
3196
3201
  }
3197
- return Boolean(gl && Number.isFinite(gl._version));
3202
+ return Boolean(gl2 && Number.isFinite(gl2._version));
3198
3203
  }
3199
- function isWebGL2(gl) {
3200
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3204
+ function isWebGL2(gl2) {
3205
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3201
3206
  return true;
3202
3207
  }
3203
- return Boolean(gl && gl._version === 2);
3208
+ return Boolean(gl2 && gl2._version === 2);
3204
3209
  }
3205
- function getWebGL2Context(gl) {
3206
- return isWebGL2(gl) ? gl : null;
3210
+ function getWebGL2Context(gl2) {
3211
+ return isWebGL2(gl2) ? gl2 : null;
3207
3212
  }
3208
- function assertWebGLContext(gl) {
3209
- assert2(isWebGL(gl), ERR_CONTEXT);
3210
- return gl;
3213
+ function assertWebGLContext(gl2) {
3214
+ assert2(isWebGL(gl2), ERR_CONTEXT);
3215
+ return gl2;
3211
3216
  }
3212
- function assertWebGL2Context(gl) {
3213
- assert2(isWebGL2(gl), ERR_WEBGL2);
3214
- return gl;
3217
+ function assertWebGL2Context(gl2) {
3218
+ assert2(isWebGL2(gl2), ERR_WEBGL2);
3219
+ return gl2;
3215
3220
  }
3216
3221
 
3217
3222
  // src/context/polyfill/get-parameter-polyfill.ts
@@ -3227,39 +3232,39 @@ var __exports__ = (() => {
3227
3232
  var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
3228
3233
  var GL_UNMASKED_VENDOR_WEBGL = 37445;
3229
3234
  var GL_UNMASKED_RENDERER_WEBGL = 37446;
3230
- var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
3235
+ var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
3231
3236
  var WEBGL_PARAMETERS = {
3232
- [GL.READ_BUFFER]: (gl) => !isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : void 0,
3237
+ [GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? GL.COLOR_ATTACHMENT0 : void 0,
3233
3238
  // WebGL2 context parameters
3234
- [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,
3235
3240
  [GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
3236
3241
  [GL.SAMPLES]: getWebGL2ValueOrZero,
3237
3242
  // WebGL2 extension context parameters
3238
- [GL_GPU_DISJOINT_EXT]: (gl, getParameter) => {
3239
- 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);
3240
3245
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
3241
3246
  },
3242
3247
  // Extension fixed values
3243
- [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
3244
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3248
+ [GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
3249
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3245
3250
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GL.VENDOR);
3246
3251
  },
3247
- [GL_UNMASKED_RENDERER_WEBGL]: (gl, getParameter) => {
3248
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3252
+ [GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
3253
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3249
3254
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GL.RENDERER);
3250
3255
  },
3251
3256
  // Extension LIMITS
3252
- [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl, getParameter) => {
3253
- 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");
3254
3259
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
3255
3260
  },
3256
3261
  // WebGL2 Limits
3257
3262
  [GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
3258
3263
  [GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
3259
3264
  [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
3260
- [GL.MAX_COLOR_ATTACHMENTS]: (gl, getParameter) => {
3261
- if (!isWebGL2(gl)) {
3262
- 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);
3263
3268
  return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
3264
3269
  }
3265
3270
  return void 0;
@@ -3267,24 +3272,24 @@ var __exports__ = (() => {
3267
3272
  [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3268
3273
  [GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
3269
3274
  [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3270
- [GL.MAX_DRAW_BUFFERS]: (gl) => {
3271
- if (!isWebGL2(gl)) {
3272
- 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);
3273
3278
  return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
3274
3279
  }
3275
3280
  return void 0;
3276
3281
  },
3277
3282
  [GL.MAX_ELEMENT_INDEX]: (
3278
3283
  // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
3279
- (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
3284
+ (gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
3280
3285
  ),
3281
3286
  [GL.MAX_ELEMENTS_INDICES]: (
3282
3287
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3283
- (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
3288
+ (gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
3284
3289
  ),
3285
3290
  [GL.MAX_ELEMENTS_VERTICES]: (
3286
3291
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3287
- (gl) => 16777216
3292
+ (gl2) => 16777216
3288
3293
  ),
3289
3294
  [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
3290
3295
  [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
@@ -3305,24 +3310,24 @@ var __exports__ = (() => {
3305
3310
  [GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
3306
3311
  [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
3307
3312
  };
3308
- function getParameterPolyfill(gl, originalGetParameter, pname) {
3313
+ function getParameterPolyfill(gl2, originalGetParameter, pname) {
3309
3314
  const limit = WEBGL_PARAMETERS[pname];
3310
- const value = typeof limit === "function" ? limit(gl, originalGetParameter, pname) : limit;
3315
+ const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
3311
3316
  const result = value !== void 0 ? value : originalGetParameter(pname);
3312
3317
  return result;
3313
3318
  }
3314
3319
 
3315
3320
  // src/context/polyfill/context-data.ts
3316
- function getContextData(gl) {
3317
- const luma = gl.luma;
3321
+ function getContextData(gl2) {
3322
+ const luma = gl2.luma;
3318
3323
  if (!luma) {
3319
3324
  const contextState = {
3320
3325
  _polyfilled: false,
3321
3326
  _extensions: {}
3322
3327
  };
3323
- gl.luma = contextState;
3328
+ gl2.luma = contextState;
3324
3329
  }
3325
- return gl.luma;
3330
+ return gl2.luma;
3326
3331
  }
3327
3332
 
3328
3333
  // src/context/polyfill/polyfill-table.ts
@@ -3332,10 +3337,10 @@ var __exports__ = (() => {
3332
3337
  var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
3333
3338
  var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
3334
3339
  var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
3335
- function getExtensionData(gl, extension) {
3340
+ function getExtensionData(gl2, extension) {
3336
3341
  return {
3337
- webgl2: isWebGL2(gl),
3338
- ext: gl.getExtension(extension)
3342
+ webgl2: isWebGL2(gl2),
3343
+ ext: gl2.getExtension(extension)
3339
3344
  };
3340
3345
  }
3341
3346
  var WEBGL2_CONTEXT_POLYFILLS = {
@@ -3406,18 +3411,18 @@ var __exports__ = (() => {
3406
3411
  };
3407
3412
  var WEBGL2_CONTEXT_OVERRIDES = {
3408
3413
  // Ensure readBuffer is a no-op
3409
- readBuffer: (gl, originalFunc, attachment) => {
3410
- if (isWebGL2(gl)) {
3414
+ readBuffer: (gl2, originalFunc, attachment) => {
3415
+ if (isWebGL2(gl2)) {
3411
3416
  originalFunc(attachment);
3412
3417
  } else {
3413
3418
  }
3414
3419
  },
3415
3420
  // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
3416
- getVertexAttrib: (gl, originalFunc, location, pname) => {
3421
+ getVertexAttrib: (gl2, originalFunc, location, pname) => {
3417
3422
  const {
3418
3423
  webgl2,
3419
3424
  ext
3420
- } = getExtensionData(gl, ANGLE_instanced_arrays);
3425
+ } = getExtensionData(gl2, ANGLE_instanced_arrays);
3421
3426
  let result;
3422
3427
  switch (pname) {
3423
3428
  case GL.VERTEX_ATTRIB_ARRAY_INTEGER:
@@ -3431,8 +3436,8 @@ var __exports__ = (() => {
3431
3436
  return result !== void 0 ? result : originalFunc(location, pname);
3432
3437
  },
3433
3438
  // Handle transform feedback and uniform block queries in WebGL1
3434
- getProgramParameter: (gl, originalFunc, program, pname) => {
3435
- if (!isWebGL2(gl)) {
3439
+ getProgramParameter: (gl2, originalFunc, program, pname) => {
3440
+ if (!isWebGL2(gl2)) {
3436
3441
  switch (pname) {
3437
3442
  case GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
3438
3443
  return GL.SEPARATE_ATTRIBS;
@@ -3445,21 +3450,21 @@ var __exports__ = (() => {
3445
3450
  }
3446
3451
  return originalFunc(program, pname);
3447
3452
  },
3448
- getInternalformatParameter: (gl, originalFunc, target, format, pname) => {
3449
- if (!isWebGL2(gl)) {
3453
+ getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
3454
+ if (!isWebGL2(gl2)) {
3450
3455
  switch (pname) {
3451
3456
  case GL.SAMPLES:
3452
3457
  return new Int32Array([0]);
3453
3458
  default:
3454
3459
  }
3455
3460
  }
3456
- const gl2 = gl;
3457
- return gl2.getInternalformatParameter(target, format, pname);
3461
+ const gl22 = gl2;
3462
+ return gl22.getInternalformatParameter(target, format, pname);
3458
3463
  },
3459
- getTexParameter(gl, originalFunc, target, pname) {
3464
+ getTexParameter(gl2, originalFunc, target, pname) {
3460
3465
  switch (pname) {
3461
3466
  case GL.TEXTURE_MAX_ANISOTROPY_EXT:
3462
- const contextData = getContextData(gl);
3467
+ const contextData = getContextData(gl2);
3463
3468
  const {
3464
3469
  _extensions
3465
3470
  } = contextData;
@@ -3471,47 +3476,47 @@ var __exports__ = (() => {
3471
3476
  return originalFunc(target, pname);
3472
3477
  },
3473
3478
  getParameter: getParameterPolyfill,
3474
- hint(gl, originalFunc, pname, value) {
3479
+ hint(gl2, originalFunc, pname, value) {
3475
3480
  return originalFunc(pname, value);
3476
3481
  }
3477
3482
  };
3478
3483
 
3479
3484
  // src/context/polyfill/polyfill-context.ts
3480
- function polyfillContext(gl) {
3481
- const contextState = getContextData(gl);
3485
+ function polyfillContext(gl2) {
3486
+ const contextState = getContextData(gl2);
3482
3487
  if (!contextState._polyfilled) {
3483
- polyfillVertexArrayObject(gl);
3484
- initializeExtensions(gl);
3485
- installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
3486
- installOverrides(gl, {
3488
+ polyfillVertexArrayObject(gl2);
3489
+ initializeExtensions(gl2);
3490
+ installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
3491
+ installOverrides(gl2, {
3487
3492
  target: contextState,
3488
- target2: gl
3493
+ target2: gl2
3489
3494
  });
3490
3495
  contextState._polyfilled = true;
3491
3496
  }
3492
- return gl;
3497
+ return gl2;
3493
3498
  }
3494
- function initializeExtensions(gl) {
3495
- const contextState = getContextData(gl);
3496
- const EXTENSIONS = gl.getSupportedExtensions() || [];
3499
+ function initializeExtensions(gl2) {
3500
+ const contextState = getContextData(gl2);
3501
+ const EXTENSIONS = gl2.getSupportedExtensions() || [];
3497
3502
  for (const extensionName of EXTENSIONS) {
3498
- const extension = gl.getExtension(extensionName);
3503
+ const extension = gl2.getExtension(extensionName);
3499
3504
  contextState._extensions[extensionName] = extension;
3500
3505
  }
3501
3506
  }
3502
- function installPolyfills(gl, polyfills) {
3503
- const contextState = getContextData(gl);
3507
+ function installPolyfills(gl2, polyfills) {
3508
+ const contextState = getContextData(gl2);
3504
3509
  for (const extension of Object.getOwnPropertyNames(polyfills)) {
3505
3510
  if (extension !== "overrides") {
3506
- polyfillExtension(gl, {
3511
+ polyfillExtension(gl2, {
3507
3512
  extension,
3508
3513
  target: contextState,
3509
- target2: gl
3514
+ target2: gl2
3510
3515
  });
3511
3516
  }
3512
3517
  }
3513
3518
  }
3514
- function polyfillExtension(gl, {
3519
+ function polyfillExtension(gl2, {
3515
3520
  extension,
3516
3521
  target,
3517
3522
  target2
@@ -3524,12 +3529,12 @@ var __exports__ = (() => {
3524
3529
  const {
3525
3530
  suffix = ""
3526
3531
  } = meta;
3527
- const ext = gl.getExtension(extension);
3532
+ const ext = gl2.getExtension(extension);
3528
3533
  for (const key of Object.keys(defaults)) {
3529
3534
  const extKey = `${key}${suffix}`;
3530
3535
  let polyfill = null;
3531
3536
  if (key === "meta") {
3532
- } else if (typeof gl[key] === "function") {
3537
+ } else if (typeof gl2[key] === "function") {
3533
3538
  } else if (ext && typeof ext[extKey] === "function") {
3534
3539
  polyfill = (...args) => ext[extKey](...args);
3535
3540
  } else if (typeof defaults[key] === "function") {
@@ -3541,15 +3546,15 @@ var __exports__ = (() => {
3541
3546
  }
3542
3547
  }
3543
3548
  }
3544
- function installOverrides(gl, {
3549
+ function installOverrides(gl2, {
3545
3550
  target,
3546
3551
  target2
3547
3552
  }) {
3548
3553
  Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
3549
3554
  if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
3550
- const originalFunc = gl[key] ? gl[key].bind(gl) : () => {
3555
+ const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
3551
3556
  };
3552
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
3557
+ const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
3553
3558
  target[key] = polyfill;
3554
3559
  target2[key] = polyfill;
3555
3560
  }
@@ -3640,19 +3645,19 @@ var __exports__ = (() => {
3640
3645
  [GL.UNPACK_SKIP_ROWS]: 0,
3641
3646
  [GL.UNPACK_SKIP_IMAGES]: 0
3642
3647
  };
3643
- var enable = (gl, value, key) => value ? gl.enable(key) : gl.disable(key);
3644
- var hint = (gl, value, key) => gl.hint(key, value);
3645
- var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
3646
- 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) => {
3647
3652
  let target;
3648
3653
  if (key === GL.FRAMEBUFFER_BINDING) {
3649
- target = isWebGL2(gl) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3654
+ target = isWebGL2(gl2) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3650
3655
  } else {
3651
3656
  target = GL.READ_FRAMEBUFFER;
3652
3657
  }
3653
- return gl.bindFramebuffer(target, value);
3658
+ return gl2.bindFramebuffer(target, value);
3654
3659
  };
3655
- var bindBuffer = (gl, value, key) => {
3660
+ var bindBuffer = (gl2, value, key) => {
3656
3661
  const bindingMap = {
3657
3662
  [GL.ARRAY_BUFFER_BINDING]: GL.ARRAY_BUFFER,
3658
3663
  [GL.COPY_READ_BUFFER_BINDING]: GL.COPY_READ_BUFFER,
@@ -3661,35 +3666,35 @@ var __exports__ = (() => {
3661
3666
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
3662
3667
  };
3663
3668
  const target = bindingMap[key];
3664
- gl.bindBuffer(target, value);
3669
+ gl2.bindBuffer(target, value);
3665
3670
  };
3666
3671
  function isArray(array) {
3667
3672
  return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
3668
3673
  }
3669
3674
  var GL_PARAMETER_SETTERS = {
3670
3675
  [GL.BLEND]: enable,
3671
- [GL.BLEND_COLOR]: (gl, value) => gl.blendColor(...value),
3676
+ [GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
3672
3677
  [GL.BLEND_EQUATION_RGB]: "blendEquation",
3673
3678
  [GL.BLEND_EQUATION_ALPHA]: "blendEquation",
3674
3679
  [GL.BLEND_SRC_RGB]: "blendFunc",
3675
3680
  [GL.BLEND_DST_RGB]: "blendFunc",
3676
3681
  [GL.BLEND_SRC_ALPHA]: "blendFunc",
3677
3682
  [GL.BLEND_DST_ALPHA]: "blendFunc",
3678
- [GL.COLOR_CLEAR_VALUE]: (gl, value) => gl.clearColor(...value),
3679
- [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),
3680
3685
  [GL.CULL_FACE]: enable,
3681
- [GL.CULL_FACE_MODE]: (gl, value) => gl.cullFace(value),
3686
+ [GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
3682
3687
  [GL.DEPTH_TEST]: enable,
3683
- [GL.DEPTH_CLEAR_VALUE]: (gl, value) => gl.clearDepth(value),
3684
- [GL.DEPTH_FUNC]: (gl, value) => gl.depthFunc(value),
3685
- [GL.DEPTH_RANGE]: (gl, value) => gl.depthRange(...value),
3686
- [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),
3687
3692
  [GL.DITHER]: enable,
3688
3693
  [GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
3689
- [GL.CURRENT_PROGRAM]: (gl, value) => gl.useProgram(value),
3690
- [GL.RENDERBUFFER_BINDING]: (gl, value) => gl.bindRenderbuffer(GL.RENDERBUFFER, value),
3691
- [GL.TRANSFORM_FEEDBACK_BINDING]: (gl, value) => gl.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3692
- [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),
3693
3698
  // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
3694
3699
  [GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
3695
3700
  [GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
@@ -3699,9 +3704,9 @@ var __exports__ = (() => {
3699
3704
  [GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
3700
3705
  [GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
3701
3706
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
3702
- [GL.FRONT_FACE]: (gl, value) => gl.frontFace(value),
3707
+ [GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
3703
3708
  [GL.GENERATE_MIPMAP_HINT]: hint,
3704
- [GL.LINE_WIDTH]: (gl, value) => gl.lineWidth(value),
3709
+ [GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
3705
3710
  [GL.POLYGON_OFFSET_FILL]: enable,
3706
3711
  [GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
3707
3712
  [GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
@@ -3711,11 +3716,11 @@ var __exports__ = (() => {
3711
3716
  [GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
3712
3717
  [GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
3713
3718
  [GL.SCISSOR_TEST]: enable,
3714
- [GL.SCISSOR_BOX]: (gl, value) => gl.scissor(...value),
3719
+ [GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
3715
3720
  [GL.STENCIL_TEST]: enable,
3716
- [GL.STENCIL_CLEAR_VALUE]: (gl, value) => gl.clearStencil(value),
3717
- [GL.STENCIL_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(GL.FRONT, value),
3718
- [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),
3719
3724
  [GL.STENCIL_FUNC]: "stencilFuncFront",
3720
3725
  [GL.STENCIL_REF]: "stencilFuncFront",
3721
3726
  [GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
@@ -3728,7 +3733,7 @@ var __exports__ = (() => {
3728
3733
  [GL.STENCIL_BACK_FAIL]: "stencilOpBack",
3729
3734
  [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
3730
3735
  [GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
3731
- [GL.VIEWPORT]: (gl, value) => gl.viewport(...value),
3736
+ [GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
3732
3737
  // WEBGL1 PIXEL PACK/UNPACK MODES
3733
3738
  [GL.PACK_ALIGNMENT]: pixelStorei,
3734
3739
  [GL.UNPACK_ALIGNMENT]: pixelStorei,
@@ -3746,75 +3751,75 @@ var __exports__ = (() => {
3746
3751
  [GL.UNPACK_SKIP_ROWS]: pixelStorei,
3747
3752
  [GL.UNPACK_SKIP_IMAGES]: pixelStorei,
3748
3753
  // Function-style setters
3749
- framebuffer: (gl, framebuffer) => {
3754
+ framebuffer: (gl2, framebuffer) => {
3750
3755
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
3751
- return gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
3756
+ return gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
3752
3757
  },
3753
- blend: (gl, value) => value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND),
3754
- blendColor: (gl, value) => gl.blendColor(...value),
3755
- 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) => {
3756
3761
  const separateModes = typeof args === "number" ? [args, args] : args;
3757
- gl.blendEquationSeparate(...separateModes);
3762
+ gl2.blendEquationSeparate(...separateModes);
3758
3763
  },
3759
- blendFunc: (gl, args) => {
3764
+ blendFunc: (gl2, args) => {
3760
3765
  const separateFuncs = args?.length === 2 ? [...args, ...args] : args;
3761
- gl.blendFuncSeparate(...separateFuncs);
3762
- },
3763
- clearColor: (gl, value) => gl.clearColor(...value),
3764
- clearDepth: (gl, value) => gl.clearDepth(value),
3765
- clearStencil: (gl, value) => gl.clearStencil(value),
3766
- colorMask: (gl, value) => gl.colorMask(...value),
3767
- cull: (gl, value) => value ? gl.enable(GL.CULL_FACE) : gl.disable(GL.CULL_FACE),
3768
- cullFace: (gl, value) => gl.cullFace(value),
3769
- depthTest: (gl, value) => value ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST),
3770
- depthFunc: (gl, value) => gl.depthFunc(value),
3771
- depthMask: (gl, value) => gl.depthMask(value),
3772
- depthRange: (gl, value) => gl.depthRange(...value),
3773
- dither: (gl, value) => value ? gl.enable(GL.DITHER) : gl.disable(GL.DITHER),
3774
- derivativeHint: (gl, value) => {
3775
- gl.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
3776
- },
3777
- frontFace: (gl, value) => gl.frontFace(value),
3778
- mipmapHint: (gl, value) => gl.hint(GL.GENERATE_MIPMAP_HINT, value),
3779
- lineWidth: (gl, value) => gl.lineWidth(value),
3780
- polygonOffsetFill: (gl, value) => value ? gl.enable(GL.POLYGON_OFFSET_FILL) : gl.disable(GL.POLYGON_OFFSET_FILL),
3781
- polygonOffset: (gl, value) => gl.polygonOffset(...value),
3782
- sampleCoverage: (gl, value) => gl.sampleCoverage(...value),
3783
- scissorTest: (gl, value) => value ? gl.enable(GL.SCISSOR_TEST) : gl.disable(GL.SCISSOR_TEST),
3784
- scissor: (gl, value) => gl.scissor(...value),
3785
- stencilTest: (gl, value) => value ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST),
3786
- 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) => {
3787
3792
  value = isArray(value) ? value : [value, value];
3788
3793
  const [mask, backMask] = value;
3789
- gl.stencilMaskSeparate(GL.FRONT, mask);
3790
- gl.stencilMaskSeparate(GL.BACK, backMask);
3794
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
3795
+ gl2.stencilMaskSeparate(GL.BACK, backMask);
3791
3796
  },
3792
- stencilFunc: (gl, args) => {
3797
+ stencilFunc: (gl2, args) => {
3793
3798
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3794
3799
  const [func, ref, mask, backFunc, backRef, backMask] = args;
3795
- gl.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3796
- gl.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3800
+ gl2.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3801
+ gl2.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3797
3802
  },
3798
- stencilOp: (gl, args) => {
3803
+ stencilOp: (gl2, args) => {
3799
3804
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3800
3805
  const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
3801
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3802
- gl.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3806
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3807
+ gl2.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3803
3808
  },
3804
- viewport: (gl, value) => gl.viewport(...value)
3809
+ viewport: (gl2, value) => gl2.viewport(...value)
3805
3810
  };
3806
3811
  function getValue(glEnum, values, cache2) {
3807
3812
  return values[glEnum] !== void 0 ? values[glEnum] : cache2[glEnum];
3808
3813
  }
3809
3814
  var GL_COMPOSITE_PARAMETER_SETTERS = {
3810
- blendEquation: (gl, values, cache2) => gl.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
3811
- 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)),
3812
- polygonOffset: (gl, values, cache2) => gl.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
3813
- sampleCoverage: (gl, values, cache2) => gl.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
3814
- 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)),
3815
- 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)),
3816
- 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)),
3817
- 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))
3818
3823
  };
3819
3824
  var GL_HOOKED_SETTERS = {
3820
3825
  // GENERIC SETTERS
@@ -3980,7 +3985,7 @@ var __exports__ = (() => {
3980
3985
  [GL.VIEWPORT]: [x, y, width, height]
3981
3986
  })
3982
3987
  };
3983
- var isEnabled = (gl, key) => gl.isEnabled(key);
3988
+ var isEnabled = (gl2, key) => gl2.isEnabled(key);
3984
3989
  var GL_PARAMETER_GETTERS = {
3985
3990
  [GL.BLEND]: isEnabled,
3986
3991
  [GL.CULL_FACE]: isEnabled,
@@ -4036,7 +4041,7 @@ var __exports__ = (() => {
4036
4041
  // src/context/parameters/unified-parameter-api.ts
4037
4042
  function setParameters(device, parameters) {
4038
4043
  const webglDevice = WebGLDevice.attach(device);
4039
- const gl = webglDevice.gl;
4044
+ const gl2 = webglDevice.gl;
4040
4045
  if (isObjectEmpty2(parameters)) {
4041
4046
  return;
4042
4047
  }
@@ -4048,31 +4053,31 @@ var __exports__ = (() => {
4048
4053
  if (typeof setter === "string") {
4049
4054
  compositeSetters[setter] = true;
4050
4055
  } else {
4051
- setter(gl, parameters[key], glConstant);
4056
+ setter(gl2, parameters[key], glConstant);
4052
4057
  }
4053
4058
  }
4054
4059
  }
4055
- const cache2 = gl.state && gl.state.cache;
4060
+ const cache2 = gl2.state && gl2.state.cache;
4056
4061
  if (cache2) {
4057
4062
  for (const key in compositeSetters) {
4058
4063
  const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
4059
- compositeSetter(gl, parameters, cache2);
4064
+ compositeSetter(gl2, parameters, cache2);
4060
4065
  }
4061
4066
  }
4062
4067
  }
4063
4068
  function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
4064
4069
  const webglDevice = WebGLDevice.attach(device);
4065
- const gl = webglDevice.gl;
4070
+ const gl2 = webglDevice.gl;
4066
4071
  if (typeof parameters === "number") {
4067
4072
  const key = parameters;
4068
4073
  const getter = GL_PARAMETER_GETTERS[key];
4069
- return getter ? getter(gl, key) : gl.getParameter(key);
4074
+ return getter ? getter(gl2, key) : gl2.getParameter(key);
4070
4075
  }
4071
4076
  const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
4072
4077
  const state = {};
4073
4078
  for (const key of parameterKeys) {
4074
4079
  const getter = GL_PARAMETER_GETTERS[key];
4075
- state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
4080
+ state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
4076
4081
  }
4077
4082
  return state;
4078
4083
  }
@@ -4109,15 +4114,15 @@ var __exports__ = (() => {
4109
4114
  program = null;
4110
4115
  stateStack = [];
4111
4116
  enable = true;
4112
- constructor(gl, {
4117
+ constructor(gl2, {
4113
4118
  copyState = false,
4114
4119
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
4115
4120
  log: log3 = () => {
4116
4121
  }
4117
4122
  // Logging function, called when gl parameter change calls are actually issued
4118
4123
  } = {}) {
4119
- this.gl = gl;
4120
- 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);
4121
4126
  this.log = log3;
4122
4127
  this._updateCache = this._updateCache.bind(this);
4123
4128
  Object.seal(this);
@@ -4160,53 +4165,53 @@ var __exports__ = (() => {
4160
4165
  };
4161
4166
  }
4162
4167
  };
4163
- function getContextState(gl) {
4164
- return gl.state;
4168
+ function getContextState(gl2) {
4169
+ return gl2.state;
4165
4170
  }
4166
- function trackContextState(gl, options) {
4171
+ function trackContextState(gl2, options) {
4167
4172
  const {
4168
4173
  enable: enable2 = true,
4169
4174
  copyState
4170
4175
  } = options;
4171
4176
  assert2(copyState !== void 0);
4172
- if (!gl.state) {
4173
- gl.state = new GLState(gl, {
4177
+ if (!gl2.state) {
4178
+ gl2.state = new GLState(gl2, {
4174
4179
  copyState
4175
4180
  });
4176
- installProgramSpy(gl);
4181
+ installProgramSpy(gl2);
4177
4182
  for (const key in GL_HOOKED_SETTERS) {
4178
4183
  const setter = GL_HOOKED_SETTERS[key];
4179
- installSetterSpy(gl, key, setter);
4184
+ installSetterSpy(gl2, key, setter);
4180
4185
  }
4181
- installGetterOverride(gl, "getParameter");
4182
- installGetterOverride(gl, "isEnabled");
4186
+ installGetterOverride(gl2, "getParameter");
4187
+ installGetterOverride(gl2, "isEnabled");
4183
4188
  }
4184
- const glState = getContextState(gl);
4189
+ const glState = getContextState(gl2);
4185
4190
  glState.enable = enable2;
4186
- return gl;
4191
+ return gl2;
4187
4192
  }
4188
- function pushContextState(gl) {
4189
- let glState = getContextState(gl);
4193
+ function pushContextState(gl2) {
4194
+ let glState = getContextState(gl2);
4190
4195
  if (!glState) {
4191
- trackContextState(gl, {
4196
+ trackContextState(gl2, {
4192
4197
  copyState: false
4193
4198
  });
4194
- glState = getContextState(gl);
4199
+ glState = getContextState(gl2);
4195
4200
  }
4196
4201
  glState.push();
4197
4202
  }
4198
- function popContextState(gl) {
4199
- const glState = getContextState(gl);
4203
+ function popContextState(gl2) {
4204
+ const glState = getContextState(gl2);
4200
4205
  assert2(glState);
4201
4206
  glState.pop();
4202
4207
  }
4203
- function installGetterOverride(gl, functionName) {
4204
- const originalGetterFunc = gl[functionName].bind(gl);
4205
- gl[functionName] = function get(pname) {
4208
+ function installGetterOverride(gl2, functionName) {
4209
+ const originalGetterFunc = gl2[functionName].bind(gl2);
4210
+ gl2[functionName] = function get(pname) {
4206
4211
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
4207
4212
  return originalGetterFunc(pname);
4208
4213
  }
4209
- const glState = getContextState(gl);
4214
+ const glState = getContextState(gl2);
4210
4215
  if (!(pname in glState.cache)) {
4211
4216
  glState.cache[pname] = originalGetterFunc(pname);
4212
4217
  }
@@ -4218,18 +4223,18 @@ var __exports__ = (() => {
4218
4223
  originalGetterFunc(pname)
4219
4224
  );
4220
4225
  };
4221
- Object.defineProperty(gl[functionName], "name", {
4226
+ Object.defineProperty(gl2[functionName], "name", {
4222
4227
  value: `${functionName}-from-cache`,
4223
4228
  configurable: false
4224
4229
  });
4225
4230
  }
4226
- function installSetterSpy(gl, functionName, setter) {
4227
- if (!gl[functionName]) {
4231
+ function installSetterSpy(gl2, functionName, setter) {
4232
+ if (!gl2[functionName]) {
4228
4233
  return;
4229
4234
  }
4230
- const originalSetterFunc = gl[functionName].bind(gl);
4231
- gl[functionName] = function set(...params) {
4232
- const glState = getContextState(gl);
4235
+ const originalSetterFunc = gl2[functionName].bind(gl2);
4236
+ gl2[functionName] = function set(...params) {
4237
+ const glState = getContextState(gl2);
4233
4238
  const {
4234
4239
  valueChanged,
4235
4240
  oldValue
@@ -4239,15 +4244,15 @@ var __exports__ = (() => {
4239
4244
  }
4240
4245
  return oldValue;
4241
4246
  };
4242
- Object.defineProperty(gl[functionName], "name", {
4247
+ Object.defineProperty(gl2[functionName], "name", {
4243
4248
  value: `${functionName}-to-cache`,
4244
4249
  configurable: false
4245
4250
  });
4246
4251
  }
4247
- function installProgramSpy(gl) {
4248
- const originalUseProgram = gl.useProgram.bind(gl);
4249
- gl.useProgram = function useProgramLuma(handle) {
4250
- 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);
4251
4256
  if (glState.program !== handle) {
4252
4257
  originalUseProgram(handle);
4253
4258
  glState.program = handle;
@@ -4276,7 +4281,7 @@ var __exports__ = (() => {
4276
4281
  let errorMessage = null;
4277
4282
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
4278
4283
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
4279
- let gl = null;
4284
+ let gl2 = null;
4280
4285
  if (props.type === "webgl2") {
4281
4286
  props = {
4282
4287
  ...props,
@@ -4289,14 +4294,14 @@ var __exports__ = (() => {
4289
4294
  webgl2: false
4290
4295
  };
4291
4296
  }
4292
- if (!gl && props.webgl2) {
4293
- gl = canvas.getContext("webgl2", props);
4297
+ if (!gl2 && props.webgl2) {
4298
+ gl2 = canvas.getContext("webgl2", props);
4294
4299
  }
4295
- if (!gl && props.webgl1) {
4296
- gl = canvas.getContext("webgl", props);
4300
+ if (!gl2 && props.webgl1) {
4301
+ gl2 = canvas.getContext("webgl", props);
4297
4302
  }
4298
4303
  canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
4299
- if (!gl) {
4304
+ if (!gl2) {
4300
4305
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
4301
4306
  }
4302
4307
  if (props.onContextLost) {
@@ -4311,28 +4316,28 @@ var __exports__ = (() => {
4311
4316
  } = props;
4312
4317
  canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
4313
4318
  }
4314
- return gl;
4319
+ return gl2;
4315
4320
  }
4316
4321
 
4317
4322
  // src/adapter/device-helpers/get-device-info.ts
4318
- function getDeviceInfo(gl) {
4319
- const vendorMasked = gl.getParameter(GL.VENDOR);
4320
- const rendererMasked = gl.getParameter(GL.RENDERER);
4321
- const ext = gl.getExtension("WEBGL_debug_renderer_info");
4322
- const vendorUnmasked = gl.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4323
- 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);
4324
4329
  const vendor = vendorUnmasked || vendorMasked;
4325
4330
  const renderer = rendererUnmasked || rendererMasked;
4326
4331
  const gpu = identifyGPUVendor(vendor, renderer);
4327
4332
  return {
4328
- type: isWebGL2(gl) ? "webgl2" : "webgl",
4333
+ type: isWebGL2(gl2) ? "webgl2" : "webgl",
4329
4334
  gpu,
4330
4335
  vendor: vendorUnmasked || vendorMasked,
4331
4336
  renderer: rendererUnmasked || rendererMasked,
4332
- version: gl.getParameter(GL.VERSION),
4337
+ version: gl2.getParameter(GL.VERSION),
4333
4338
  shadingLanguages: ["glsl"],
4334
4339
  shadingLanguageVersions: {
4335
- "glsl": gl.getParameter(GL.SHADING_LANGUAGE_VERSION)
4340
+ "glsl": gl2.getParameter(GL.SHADING_LANGUAGE_VERSION)
4336
4341
  }
4337
4342
  };
4338
4343
  }
@@ -4384,38 +4389,38 @@ var __exports__ = (() => {
4384
4389
  var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
4385
4390
  var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
4386
4391
  var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
4387
- var checkExtension = (gl, extension) => gl.getExtension(extension);
4388
- 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));
4389
4394
  var TEXTURE_FEATURE_CHECKS = {
4390
- "texture-blend-float-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "EXT_float_blend"),
4391
- "texture-formats-srgb-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, EXT_SRGB),
4392
- "texture-formats-depth-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "WEBGL_depth_texture"),
4393
- "texture-formats-float32-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_float"),
4394
- "texture-formats-float16-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_half_float"),
4395
- "texture-formats-norm16-webgl": (gl) => isWebGL2(gl) ? checkExtension(gl, EXT_TEXTURE_NORM16) : false,
4396
- "texture-filter-linear-float32-webgl": (gl) => checkExtension(gl, "OES_texture_float_linear"),
4397
- "texture-filter-linear-float16-webgl": (gl) => checkExtension(gl, "OES_texture_half_float_linear"),
4398
- "texture-filter-anisotropic-webgl": (gl) => checkExtension(gl, "EXT_texture_filter_anisotropic"),
4399
- "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"),
4400
4405
  // [false, 'EXT_color_buffer_float'],
4401
- "texture-renderable-float16-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_half_float"),
4402
- "texture-compression-bc": (gl) => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4403
- "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]),
4404
4409
  // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
4405
4410
  // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
4406
4411
  // 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
4407
- "texture-compression-etc2": (gl) => checkExtensions(gl, [X_ETC2]),
4408
- "texture-compression-astc": (gl) => checkExtensions(gl, [X_ASTC]),
4409
- "texture-compression-etc1-webgl": (gl) => checkExtensions(gl, [X_ETC1]),
4410
- "texture-compression-pvrtc-webgl": (gl) => checkExtensions(gl, [X_PVRTC]),
4411
- "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])
4412
4417
  };
4413
- function checkTextureFeature(gl, feature) {
4414
- return TEXTURE_FEATURE_CHECKS[feature]?.(gl) || false;
4418
+ function checkTextureFeature(gl2, feature) {
4419
+ return TEXTURE_FEATURE_CHECKS[feature]?.(gl2) || false;
4415
4420
  }
4416
- function getTextureFeatures(gl) {
4421
+ function getTextureFeatures(gl2) {
4417
4422
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
4418
- return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
4423
+ return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
4419
4424
  }
4420
4425
  var TEXTURE_FORMATS = {
4421
4426
  // Unsized formats that leave the precision up to the driver.
@@ -5155,23 +5160,23 @@ var __exports__ = (() => {
5155
5160
  [GL.BYTE]: 1,
5156
5161
  [GL.UNSIGNED_BYTE]: 1
5157
5162
  };
5158
- function isTextureFormatSupported(gl, formatOrGL) {
5163
+ function isTextureFormatSupported(gl2, formatOrGL) {
5159
5164
  const format = convertGLToTextureFormat(formatOrGL);
5160
5165
  const info = TEXTURE_FORMATS[format];
5161
5166
  if (!info) {
5162
5167
  return false;
5163
5168
  }
5164
- if (isWebGL2(gl) ? info.gl === void 0 : info.gl1 === void 0) {
5169
+ if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
5165
5170
  return false;
5166
5171
  }
5167
- 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);
5168
5173
  if (extension) {
5169
- return Boolean(gl.getExtension(extension));
5174
+ return Boolean(gl2.getExtension(extension));
5170
5175
  }
5171
5176
  return true;
5172
5177
  }
5173
- function isRenderbufferFormatSupported(gl, format) {
5174
- return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5178
+ function isRenderbufferFormatSupported(gl2, format) {
5179
+ return isTextureFormatSupported(gl2, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5175
5180
  }
5176
5181
  function convertGLToTextureFormat(format) {
5177
5182
  if (typeof format === "string") {
@@ -5191,9 +5196,9 @@ var __exports__ = (() => {
5191
5196
  }
5192
5197
  return webglFormat;
5193
5198
  }
5194
- function isTextureFormatFilterable(gl, formatOrGL) {
5199
+ function isTextureFormatFilterable(gl2, formatOrGL) {
5195
5200
  const format = convertGLToTextureFormat(formatOrGL);
5196
- if (!isTextureFormatSupported(gl, format)) {
5201
+ if (!isTextureFormatSupported(gl2, format)) {
5197
5202
  return false;
5198
5203
  }
5199
5204
  try {
@@ -5205,16 +5210,16 @@ var __exports__ = (() => {
5205
5210
  return false;
5206
5211
  }
5207
5212
  if (format.endsWith("32float")) {
5208
- return Boolean(gl.getExtension("OES_texture_float_linear"));
5213
+ return Boolean(gl2.getExtension("OES_texture_float_linear"));
5209
5214
  }
5210
5215
  if (format.endsWith("16float")) {
5211
- return Boolean(gl.getExtension("OES_texture_half_float_linear"));
5216
+ return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
5212
5217
  }
5213
5218
  return true;
5214
5219
  }
5215
- function isTextureFormatRenderable(gl, formatOrGL) {
5220
+ function isTextureFormatRenderable(gl2, formatOrGL) {
5216
5221
  const format = convertGLToTextureFormat(formatOrGL);
5217
- if (!isTextureFormatSupported(gl, format)) {
5222
+ if (!isTextureFormatSupported(gl2, format)) {
5218
5223
  return false;
5219
5224
  }
5220
5225
  if (typeof format === "number") {
@@ -5241,27 +5246,27 @@ var __exports__ = (() => {
5241
5246
  }
5242
5247
  return info.attachment;
5243
5248
  }
5244
- 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) {
5245
5250
  let texture = null;
5246
5251
  let framebuffer = null;
5247
5252
  try {
5248
- texture = gl.createTexture();
5249
- gl.bindTexture(GL.TEXTURE_2D, texture);
5253
+ texture = gl2.createTexture();
5254
+ gl2.bindTexture(GL.TEXTURE_2D, texture);
5250
5255
  const level = 0;
5251
5256
  const width = 1;
5252
5257
  const height = 1;
5253
5258
  const border = 0;
5254
5259
  const pixel = new Uint8Array([0, 0, 255, 255]);
5255
- gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5256
- framebuffer = gl.createFramebuffer();
5257
- gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5258
- gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5259
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5260
- 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);
5261
5266
  return status;
5262
5267
  } finally {
5263
- gl.deleteTexture(texture);
5264
- gl.deleteFramebuffer(framebuffer);
5268
+ gl2.deleteTexture(texture);
5269
+ gl2.deleteFramebuffer(framebuffer);
5265
5270
  }
5266
5271
  }
5267
5272
  function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
@@ -5312,52 +5317,52 @@ var __exports__ = (() => {
5312
5317
  }
5313
5318
 
5314
5319
  // src/adapter/device-helpers/device-features.ts
5315
- function getDeviceFeatures(gl) {
5316
- const features = getWebGLFeatures(gl);
5317
- for (const textureFeature of getTextureFeatures(gl)) {
5320
+ function getDeviceFeatures(gl2) {
5321
+ const features = getWebGLFeatures(gl2);
5322
+ for (const textureFeature of getTextureFeatures(gl2)) {
5318
5323
  features.add(textureFeature);
5319
5324
  }
5320
5325
  return features;
5321
5326
  }
5322
- function getWebGLFeatures(gl) {
5323
- gl.getExtension("EXT_color_buffer_float");
5324
- gl.getExtension("WEBGL_color_buffer_float");
5325
- 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");
5326
5331
  const features = /* @__PURE__ */ new Set();
5327
5332
  for (const feature of Object.keys(WEBGL_FEATURES)) {
5328
- if (isFeatureSupported(gl, feature)) {
5333
+ if (isFeatureSupported(gl2, feature)) {
5329
5334
  features.add(feature);
5330
5335
  }
5331
5336
  }
5332
5337
  return features;
5333
5338
  }
5334
- function isFeatureSupported(gl, feature) {
5339
+ function isFeatureSupported(gl2, feature) {
5335
5340
  const featureInfo = WEBGL_FEATURES[feature];
5336
5341
  if (!featureInfo) {
5337
5342
  return false;
5338
5343
  }
5339
5344
  const [webgl1Feature, webgl2Feature] = featureInfo || [];
5340
- const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
5345
+ const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
5341
5346
  if (typeof featureDefinition === "boolean") {
5342
5347
  return featureDefinition;
5343
5348
  }
5344
5349
  switch (feature) {
5345
5350
  case "texture-renderable-rgba32float-webgl":
5346
- return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl);
5351
+ return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
5347
5352
  case "glsl-derivatives":
5348
- return canCompileGLSLExtension(gl, featureDefinition);
5353
+ return canCompileGLSLExtension(gl2, featureDefinition);
5349
5354
  case "glsl-frag-data":
5350
- return canCompileGLSLExtension(gl, featureDefinition, {
5355
+ return canCompileGLSLExtension(gl2, featureDefinition, {
5351
5356
  behavior: "require"
5352
5357
  });
5353
5358
  case "glsl-frag-depth":
5354
- return canCompileGLSLExtension(gl, featureDefinition);
5359
+ return canCompileGLSLExtension(gl2, featureDefinition);
5355
5360
  default:
5356
- return Boolean(gl.getExtension(featureDefinition));
5361
+ return Boolean(gl2.getExtension(featureDefinition));
5357
5362
  }
5358
5363
  }
5359
5364
  var compiledGLSLExtensions = {};
5360
- function canCompileGLSLExtension(gl, extensionName, opts = {}) {
5365
+ function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
5361
5366
  if (!isOldIE(opts)) {
5362
5367
  return true;
5363
5368
  }
@@ -5367,14 +5372,14 @@ var __exports__ = (() => {
5367
5372
  const behavior = opts.behavior || "enable";
5368
5373
  const source = `#extension GL_${extensionName} : ${behavior}
5369
5374
  void main(void) {}`;
5370
- const shader = gl.createShader(gl.VERTEX_SHADER);
5375
+ const shader = gl2.createShader(gl2.VERTEX_SHADER);
5371
5376
  if (!shader) {
5372
5377
  throw new Error("shader");
5373
5378
  }
5374
- gl.shaderSource(shader, source);
5375
- gl.compileShader(shader);
5376
- const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
5377
- 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);
5378
5383
  compiledGLSLExtensions[extensionName] = canCompile;
5379
5384
  return canCompile;
5380
5385
  }
@@ -5411,38 +5416,38 @@ void main(void) {}`;
5411
5416
  };
5412
5417
 
5413
5418
  // src/adapter/device-helpers/device-limits.ts
5414
- function getDeviceLimits(gl) {
5415
- const gl2 = getWebGL2Context(gl);
5419
+ function getDeviceLimits(gl2) {
5420
+ const gl22 = getWebGL2Context(gl2);
5416
5421
  return {
5417
5422
  maxTextureDimension1D: 0,
5418
5423
  // WebGL does not support 1D textures
5419
- maxTextureDimension2D: gl.getParameter(GL.MAX_TEXTURE_SIZE),
5420
- maxTextureDimension3D: gl2 ? gl2.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5421
- 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,
5422
5427
  maxBindGroups: 1,
5423
5428
  // TBD
5424
5429
  maxDynamicUniformBuffersPerPipelineLayout: 0,
5425
5430
  // TBD
5426
5431
  maxDynamicStorageBuffersPerPipelineLayout: 0,
5427
5432
  // TBD
5428
- maxSampledTexturesPerShaderStage: gl.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5433
+ maxSampledTexturesPerShaderStage: gl2.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5429
5434
  // TBD
5430
- maxSamplersPerShaderStage: gl.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5435
+ maxSamplersPerShaderStage: gl2.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5431
5436
  maxStorageBuffersPerShaderStage: 0,
5432
5437
  // TBD
5433
5438
  maxStorageTexturesPerShaderStage: 0,
5434
5439
  // TBD
5435
- maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5436
- 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,
5437
5442
  maxStorageBufferBindingSize: 0,
5438
- minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5443
+ minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5439
5444
  minStorageBufferOffsetAlignment: 0,
5440
5445
  // TBD
5441
5446
  maxVertexBuffers: 0,
5442
- maxVertexAttributes: gl.getParameter(GL.MAX_VERTEX_ATTRIBS),
5447
+ maxVertexAttributes: gl2.getParameter(GL.MAX_VERTEX_ATTRIBS),
5443
5448
  maxVertexBufferArrayStride: 2048,
5444
5449
  // TBD, this is just the default value from WebGPU
5445
- maxInterStageShaderComponents: gl2 ? gl2.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5450
+ maxInterStageShaderComponents: gl22 ? gl22.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5446
5451
  maxComputeWorkgroupStorageSize: 0,
5447
5452
  // WebGL does not support compute shaders
5448
5453
  maxComputeInvocationsPerWorkgroup: 0,
@@ -5457,13 +5462,13 @@ void main(void) {}`;
5457
5462
  // WebGL does not support compute shaders
5458
5463
  };
5459
5464
  }
5460
- function getWebGLLimits(gl) {
5461
- const gl2 = getWebGL2Context(gl);
5465
+ function getWebGLLimits(gl2) {
5466
+ const gl22 = getWebGL2Context(gl2);
5462
5467
  function get(pname) {
5463
- return gl.getParameter(pname);
5468
+ return gl2.getParameter(pname);
5464
5469
  }
5465
5470
  function get2(pname, defaultValue) {
5466
- return gl2 ? gl2.getParameter(pname) : defaultValue || 0;
5471
+ return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
5467
5472
  }
5468
5473
  return {
5469
5474
  [GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
@@ -5556,24 +5561,24 @@ void main(void) {}`;
5556
5561
  // src/context/state-tracker/with-parameters.ts
5557
5562
  function withParameters(device, parameters, func) {
5558
5563
  const webglDevice = WebGLDevice.attach(device);
5559
- const gl = webglDevice.gl;
5564
+ const gl2 = webglDevice.gl;
5560
5565
  if (isObjectEmpty3(parameters)) {
5561
5566
  return func(device);
5562
5567
  }
5563
5568
  const {
5564
5569
  nocatch = true
5565
5570
  } = parameters;
5566
- pushContextState(gl);
5567
- setParameters(gl, parameters);
5571
+ pushContextState(gl2);
5572
+ setParameters(gl2, parameters);
5568
5573
  let value;
5569
5574
  if (nocatch) {
5570
- value = func(gl);
5571
- popContextState(gl);
5575
+ value = func(gl2);
5576
+ popContextState(gl2);
5572
5577
  } else {
5573
5578
  try {
5574
- value = func(gl);
5579
+ value = func(gl2);
5575
5580
  } finally {
5576
- popContextState(gl);
5581
+ popContextState(gl2);
5577
5582
  }
5578
5583
  }
5579
5584
  return value;
@@ -5613,43 +5618,43 @@ void main(void) {}`;
5613
5618
  function setDeviceParameters(device, parameters) {
5614
5619
  const webglDevice = WebGLDevice.attach(device);
5615
5620
  const {
5616
- gl
5621
+ gl: gl2
5617
5622
  } = webglDevice;
5618
5623
  if (parameters.cullMode) {
5619
5624
  switch (parameters.cullMode) {
5620
5625
  case "none":
5621
- gl.disable(GL.CULL_FACE);
5626
+ gl2.disable(GL.CULL_FACE);
5622
5627
  break;
5623
5628
  case "front":
5624
- gl.enable(GL.CULL_FACE);
5625
- gl.cullFace(GL.FRONT);
5629
+ gl2.enable(GL.CULL_FACE);
5630
+ gl2.cullFace(GL.FRONT);
5626
5631
  break;
5627
5632
  case "back":
5628
- gl.enable(GL.CULL_FACE);
5629
- gl.cullFace(GL.BACK);
5633
+ gl2.enable(GL.CULL_FACE);
5634
+ gl2.cullFace(GL.BACK);
5630
5635
  break;
5631
5636
  }
5632
5637
  }
5633
5638
  if (parameters.frontFace) {
5634
- gl.frontFace(map("frontFace", parameters.frontFace, {
5639
+ gl2.frontFace(map("frontFace", parameters.frontFace, {
5635
5640
  ccw: GL.CCW,
5636
5641
  cw: GL.CW
5637
5642
  }));
5638
5643
  }
5639
5644
  if (parameters.depthBias !== void 0) {
5640
- gl.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5645
+ gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5641
5646
  }
5642
5647
  if (parameters.depthWriteEnabled !== void 0) {
5643
- gl.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5648
+ gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5644
5649
  }
5645
5650
  if (parameters.depthCompare) {
5646
- parameters.depthCompare !== "always" ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST);
5647
- 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));
5648
5653
  }
5649
5654
  if (parameters.stencilWriteMask) {
5650
5655
  const mask = parameters.stencilWriteMask;
5651
- gl.stencilMaskSeparate(GL.FRONT, mask);
5652
- gl.stencilMaskSeparate(GL.BACK, mask);
5656
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
5657
+ gl2.stencilMaskSeparate(GL.BACK, mask);
5653
5658
  }
5654
5659
  if (parameters.stencilReadMask) {
5655
5660
  log.warn("stencilReadMask not supported under WebGL");
@@ -5657,16 +5662,16 @@ void main(void) {}`;
5657
5662
  if (parameters.stencilCompare) {
5658
5663
  const mask = parameters.stencilReadMask || 4294967295;
5659
5664
  const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
5660
- parameters.stencilCompare !== "always" ? gl.enable(GL.STENCIL_TEST) : gl.disable(GL.STENCIL_TEST);
5661
- gl.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5662
- 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);
5663
5668
  }
5664
5669
  if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
5665
5670
  const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
5666
5671
  const sfail = convertStencilOperation("stencilFailOperation", parameters.stencilFailOperation);
5667
5672
  const dpfail = convertStencilOperation("stencilDepthFailOperation", parameters.stencilDepthFailOperation);
5668
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5669
- gl.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5673
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5674
+ gl2.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5670
5675
  }
5671
5676
  }
5672
5677
  function convertCompareFunction(parameter, value) {
@@ -6259,9 +6264,9 @@ void main(void) {}`;
6259
6264
  height
6260
6265
  }));
6261
6266
  const {
6262
- gl
6267
+ gl: gl2
6263
6268
  } = this;
6264
- gl.bindTexture(this.target, this.handle);
6269
+ gl2.bindTexture(this.target, this.handle);
6265
6270
  let dataType = null;
6266
6271
  ({
6267
6272
  data,
@@ -6270,14 +6275,14 @@ void main(void) {}`;
6270
6275
  data,
6271
6276
  compressed
6272
6277
  }));
6273
- let gl2;
6278
+ let gl22;
6274
6279
  withParameters(this.gl, parameters, () => {
6275
6280
  switch (dataType) {
6276
6281
  case "null":
6277
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6282
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6278
6283
  break;
6279
6284
  case "typed-array":
6280
- gl.texImage2D(
6285
+ gl2.texImage2D(
6281
6286
  target,
6282
6287
  level,
6283
6288
  glFormat,
@@ -6293,21 +6298,21 @@ void main(void) {}`;
6293
6298
  );
6294
6299
  break;
6295
6300
  case "buffer":
6296
- gl2 = this.device.assertWebGL2();
6297
- gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6298
- gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6299
- 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);
6300
6305
  break;
6301
6306
  case "browser-object":
6302
6307
  if (this.device.isWebGL2) {
6303
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6308
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6304
6309
  } else {
6305
- gl.texImage2D(target, level, glFormat, dataFormat, type, data);
6310
+ gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
6306
6311
  }
6307
6312
  break;
6308
6313
  case "compressed":
6309
6314
  for (const [levelIndex, levelData] of data.entries()) {
6310
- 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);
6311
6316
  }
6312
6317
  break;
6313
6318
  default:
@@ -6411,24 +6416,24 @@ void main(void) {}`;
6411
6416
  }
6412
6417
  bind(textureUnit = this.textureUnit) {
6413
6418
  const {
6414
- gl
6419
+ gl: gl2
6415
6420
  } = this;
6416
6421
  if (textureUnit !== void 0) {
6417
6422
  this.textureUnit = textureUnit;
6418
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6423
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6419
6424
  }
6420
- gl.bindTexture(this.target, this.handle);
6425
+ gl2.bindTexture(this.target, this.handle);
6421
6426
  return textureUnit;
6422
6427
  }
6423
6428
  unbind(textureUnit = this.textureUnit) {
6424
6429
  const {
6425
- gl
6430
+ gl: gl2
6426
6431
  } = this;
6427
6432
  if (textureUnit !== void 0) {
6428
6433
  this.textureUnit = textureUnit;
6429
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6434
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6430
6435
  }
6431
- gl.bindTexture(this.target, null);
6436
+ gl2.bindTexture(this.target, null);
6432
6437
  return textureUnit;
6433
6438
  }
6434
6439
  // PRIVATE METHODS
@@ -6550,7 +6555,7 @@ void main(void) {}`;
6550
6555
  /* eslint-disable max-statements, max-len */
6551
6556
  async setCubeMapImageData(options) {
6552
6557
  const {
6553
- gl
6558
+ gl: gl2
6554
6559
  } = this;
6555
6560
  const {
6556
6561
  width,
@@ -6572,9 +6577,9 @@ void main(void) {}`;
6572
6577
  }
6573
6578
  resolvedFaces[index].forEach((image, lodLevel) => {
6574
6579
  if (width && height) {
6575
- gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6580
+ gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6576
6581
  } else {
6577
- gl.texImage2D(face, lodLevel, format, format, type, image);
6582
+ gl2.texImage2D(face, lodLevel, format, format, type, image);
6578
6583
  }
6579
6584
  });
6580
6585
  });
@@ -6593,7 +6598,7 @@ void main(void) {}`;
6593
6598
  // generateMipmap = false // TODO
6594
6599
  } = options;
6595
6600
  const {
6596
- gl
6601
+ gl: gl2
6597
6602
  } = this;
6598
6603
  const imageData = pixels || data;
6599
6604
  this.bind();
@@ -6604,9 +6609,9 @@ void main(void) {}`;
6604
6609
  pixels: resolvedImageData
6605
6610
  })));
6606
6611
  } else if (this.width || this.height) {
6607
- gl.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6612
+ gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6608
6613
  } else {
6609
- gl.texImage2D(face, 0, format, format, type, imageData);
6614
+ gl2.texImage2D(face, 0, format, format, type, imageData);
6610
6615
  }
6611
6616
  return this;
6612
6617
  }
@@ -6738,7 +6743,7 @@ void main(void) {}`;
6738
6743
  }
6739
6744
 
6740
6745
  // src/adapter/objects/constants-to-keys.ts
6741
- function getKeyValue(gl, name) {
6746
+ function getKeyValue(gl2, name) {
6742
6747
  if (typeof name !== "string") {
6743
6748
  return name;
6744
6749
  }
@@ -6747,7 +6752,7 @@ void main(void) {}`;
6747
6752
  return number;
6748
6753
  }
6749
6754
  name = name.replace(/^.*\./, "");
6750
- const value = gl[name];
6755
+ const value = gl2[name];
6751
6756
  assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
6752
6757
  return value;
6753
6758
  }
@@ -6761,13 +6766,13 @@ void main(void) {}`;
6761
6766
  constructor(device, props, defaultProps) {
6762
6767
  super(device, props, defaultProps);
6763
6768
  this.device = WebGLDevice.attach(device);
6764
- const gl = this.device.gl;
6765
- assertWebGLContext(gl);
6769
+ const gl2 = this.device.gl;
6770
+ assertWebGLContext(gl2);
6766
6771
  const {
6767
6772
  id
6768
6773
  } = props || {};
6769
- this.gl = gl;
6770
- this.gl2 = gl;
6774
+ this.gl = gl2;
6775
+ this.gl2 = gl2;
6771
6776
  this.id = id || uid(this.constructor.name);
6772
6777
  this._handle = props?.handle;
6773
6778
  if (this._handle === void 0) {
@@ -7085,12 +7090,12 @@ void main(void) {}`;
7085
7090
  /** Check the status */
7086
7091
  _checkStatus() {
7087
7092
  const {
7088
- gl
7093
+ gl: gl2
7089
7094
  } = this;
7090
- const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7091
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
7092
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
7093
- 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) {
7094
7099
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
7095
7100
  }
7096
7101
  }
@@ -7161,27 +7166,27 @@ void main(void) {}`;
7161
7166
  */
7162
7167
  _attachTexture(attachment, texture, layer, level) {
7163
7168
  const {
7164
- gl,
7165
- gl2
7169
+ gl: gl2,
7170
+ gl2: gl22
7166
7171
  } = this.device;
7167
- gl.bindTexture(texture.target, texture.handle);
7172
+ gl2.bindTexture(texture.target, texture.handle);
7168
7173
  switch (texture.target) {
7169
7174
  case GL.TEXTURE_2D_ARRAY:
7170
7175
  case GL.TEXTURE_3D:
7171
7176
  this.device.assertWebGL2();
7172
- gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7177
+ gl22?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7173
7178
  break;
7174
7179
  case GL.TEXTURE_CUBE_MAP:
7175
7180
  const face = mapIndexToCubeMapFace(layer);
7176
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7181
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7177
7182
  break;
7178
7183
  case GL.TEXTURE_2D:
7179
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7184
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7180
7185
  break;
7181
7186
  default:
7182
7187
  assert2(false, "Illegal texture type");
7183
7188
  }
7184
- gl.bindTexture(texture.target, null);
7189
+ gl2.bindTexture(texture.target, null);
7185
7190
  }
7186
7191
  };
7187
7192
  function mapIndexToCubeMapFace(layer) {
@@ -7245,6 +7250,7 @@ void main(void) {}`;
7245
7250
  */
7246
7251
  resize(options) {
7247
7252
  if (this.canvas) {
7253
+ const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
7248
7254
  this.setDevicePixelRatio(devicePixelRatio, options);
7249
7255
  return;
7250
7256
  }
@@ -7318,9 +7324,9 @@ void main(void) {}`;
7318
7324
 
7319
7325
  // src/context/debug/webgl-developer-tools.ts
7320
7326
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
7321
- function getContextData2(gl) {
7322
- gl.luma = gl.luma || {};
7323
- return gl.luma;
7327
+ function getContextData2(gl2) {
7328
+ gl2.luma = gl2.luma || {};
7329
+ return gl2.luma;
7324
7330
  }
7325
7331
  async function loadWebGLDeveloperTools() {
7326
7332
  if (!globalThis.WebGLDebugUtils) {
@@ -7329,30 +7335,30 @@ void main(void) {}`;
7329
7335
  await loadScript(WEBGL_DEBUG_CDN_URL);
7330
7336
  }
7331
7337
  }
7332
- function makeDebugContext(gl, props = {}) {
7333
- if (!gl) {
7338
+ function makeDebugContext(gl2, props = {}) {
7339
+ if (!gl2) {
7334
7340
  return null;
7335
7341
  }
7336
- return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
7342
+ return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
7337
7343
  }
7338
- function getRealContext(gl) {
7339
- const data = getContextData2(gl);
7340
- return data.realContext ? data.realContext : gl;
7344
+ function getRealContext(gl2) {
7345
+ const data = getContextData2(gl2);
7346
+ return data.realContext ? data.realContext : gl2;
7341
7347
  }
7342
- function getDebugContext(gl, props) {
7348
+ function getDebugContext(gl2, props) {
7343
7349
  if (!globalThis.WebGLDebugUtils) {
7344
7350
  log.warn("webgl-debug not loaded")();
7345
- return gl;
7351
+ return gl2;
7346
7352
  }
7347
- const data = getContextData2(gl);
7353
+ const data = getContextData2(gl2);
7348
7354
  if (data.debugContext) {
7349
7355
  return data.debugContext;
7350
7356
  }
7351
7357
  globalThis.WebGLDebugUtils.init({
7352
7358
  ...GL,
7353
- ...gl
7359
+ ...gl2
7354
7360
  });
7355
- 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));
7356
7362
  for (const key in GL) {
7357
7363
  if (!(key in glDebug) && typeof GL[key] === "number") {
7358
7364
  glDebug[key] = GL[key];
@@ -7360,10 +7366,10 @@ void main(void) {}`;
7360
7366
  }
7361
7367
  class WebGLDebugContext {
7362
7368
  }
7363
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
7369
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
7364
7370
  Object.setPrototypeOf(WebGLDebugContext, glDebug);
7365
7371
  const debugContext = Object.create(WebGLDebugContext);
7366
- data.realContext = gl;
7372
+ data.realContext = gl2;
7367
7373
  data.debugContext = debugContext;
7368
7374
  debugContext.debug = true;
7369
7375
  return debugContext;
@@ -7750,15 +7756,15 @@ void main(void) {}`;
7750
7756
  size
7751
7757
  } = options;
7752
7758
  const {
7753
- gl,
7754
- gl2
7759
+ gl: gl2,
7760
+ gl2: gl22
7755
7761
  } = this;
7756
- assertWebGL2Context(gl);
7757
- gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
7758
- gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
7759
- gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
7760
- gl.bindBuffer(GL.COPY_READ_BUFFER, null);
7761
- 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);
7762
7768
  this.debugData = null;
7763
7769
  return this;
7764
7770
  }
@@ -8029,13 +8035,13 @@ void main(void) {}`;
8029
8035
  ${source2}`;
8030
8036
  source = addGLSLVersion(source);
8031
8037
  const {
8032
- gl
8038
+ gl: gl2
8033
8039
  } = this.device;
8034
- gl.shaderSource(this.handle, source);
8035
- gl.compileShader(this.handle);
8036
- 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);
8037
8043
  if (!compileStatus) {
8038
- const shaderLog = gl.getShaderInfoLog(this.handle);
8044
+ const shaderLog = gl2.getShaderInfoLog(this.handle);
8039
8045
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
8040
8046
  const messages = parsedLog.filter((message2) => message2.type === "error");
8041
8047
  const formattedLog = formatCompilerLog(messages, source);
@@ -8270,8 +8276,8 @@ ${formattedLog}`)();
8270
8276
  }
8271
8277
 
8272
8278
  // src/adapter/helpers/get-shader-layout.ts
8273
- function getShaderLayout(gl, program) {
8274
- const programBindings = getProgramBindings(gl, program);
8279
+ function getShaderLayout(gl2, program) {
8280
+ const programBindings = getProgramBindings(gl2, program);
8275
8281
  const shaderLayout = {
8276
8282
  attributes: [],
8277
8283
  bindings: []
@@ -8333,21 +8339,21 @@ ${formattedLog}`)();
8333
8339
  }
8334
8340
  return shaderLayout;
8335
8341
  }
8336
- function getProgramBindings(gl, program) {
8342
+ function getProgramBindings(gl2, program) {
8337
8343
  const config = {
8338
- attributes: readAttributeBindings(gl, program),
8339
- uniforms: readUniformBindings(gl, program),
8340
- uniformBlocks: readUniformBlocks(gl, program),
8341
- varyings: readVaryings(gl, program)
8344
+ attributes: readAttributeBindings(gl2, program),
8345
+ uniforms: readUniformBindings(gl2, program),
8346
+ uniformBlocks: readUniformBlocks(gl2, program),
8347
+ varyings: readVaryings(gl2, program)
8342
8348
  };
8343
8349
  Object.seal(config);
8344
8350
  return config;
8345
8351
  }
8346
- function readAttributeBindings(gl, program) {
8352
+ function readAttributeBindings(gl2, program) {
8347
8353
  const attributes = [];
8348
- const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
8354
+ const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
8349
8355
  for (let index = 0; index < count; index++) {
8350
- const activeInfo = gl.getActiveAttrib(program, index);
8356
+ const activeInfo = gl2.getActiveAttrib(program, index);
8351
8357
  if (!activeInfo) {
8352
8358
  throw new Error("activeInfo");
8353
8359
  }
@@ -8356,7 +8362,7 @@ ${formattedLog}`)();
8356
8362
  type: compositeType,
8357
8363
  size
8358
8364
  } = activeInfo;
8359
- const location = gl.getAttribLocation(program, name);
8365
+ const location = gl2.getAttribLocation(program, name);
8360
8366
  if (location >= 0) {
8361
8367
  const {
8362
8368
  glType,
@@ -8380,15 +8386,15 @@ ${formattedLog}`)();
8380
8386
  attributes.sort((a, b) => a.location - b.location);
8381
8387
  return attributes;
8382
8388
  }
8383
- function readVaryings(gl, program) {
8384
- if (!isWebGL2(gl)) {
8389
+ function readVaryings(gl2, program) {
8390
+ if (!isWebGL2(gl2)) {
8385
8391
  return [];
8386
8392
  }
8387
- const gl2 = gl;
8393
+ const gl22 = gl2;
8388
8394
  const varyings = [];
8389
- const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8395
+ const count = gl2.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8390
8396
  for (let location = 0; location < count; location++) {
8391
- const activeInfo = gl2.getTransformFeedbackVarying(program, location);
8397
+ const activeInfo = gl22.getTransformFeedbackVarying(program, location);
8392
8398
  if (!activeInfo) {
8393
8399
  throw new Error("activeInfo");
8394
8400
  }
@@ -8415,11 +8421,11 @@ ${formattedLog}`)();
8415
8421
  varyings.sort((a, b) => a.location - b.location);
8416
8422
  return varyings;
8417
8423
  }
8418
- function readUniformBindings(gl, program) {
8424
+ function readUniformBindings(gl2, program) {
8419
8425
  const uniforms = [];
8420
- const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8426
+ const uniformCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8421
8427
  for (let i = 0; i < uniformCount; i++) {
8422
- const activeInfo = gl.getActiveUniform(program, i);
8428
+ const activeInfo = gl2.getActiveUniform(program, i);
8423
8429
  if (!activeInfo) {
8424
8430
  throw new Error("activeInfo");
8425
8431
  }
@@ -8432,7 +8438,7 @@ ${formattedLog}`)();
8432
8438
  name,
8433
8439
  isArray: isArray2
8434
8440
  } = parseUniformName(rawName);
8435
- let webglLocation = gl.getUniformLocation(program, name);
8441
+ let webglLocation = gl2.getUniformLocation(program, name);
8436
8442
  const uniformInfo = {
8437
8443
  // WebGL locations are uniquely typed but just numbers
8438
8444
  location: webglLocation,
@@ -8445,7 +8451,7 @@ ${formattedLog}`)();
8445
8451
  if (uniformInfo.size > 1) {
8446
8452
  for (let j = 0; j < uniformInfo.size; j++) {
8447
8453
  const elementName = `${name}[${j}]`;
8448
- webglLocation = gl.getUniformLocation(program, elementName);
8454
+ webglLocation = gl2.getUniformLocation(program, elementName);
8449
8455
  const arrayElementUniformInfo = {
8450
8456
  ...uniformInfo,
8451
8457
  name: elementName,
@@ -8457,17 +8463,17 @@ ${formattedLog}`)();
8457
8463
  }
8458
8464
  return uniforms;
8459
8465
  }
8460
- function readUniformBlocks(gl, program) {
8461
- if (!isWebGL2(gl)) {
8466
+ function readUniformBlocks(gl2, program) {
8467
+ if (!isWebGL2(gl2)) {
8462
8468
  return [];
8463
8469
  }
8464
- const gl2 = gl;
8465
- const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
8470
+ const gl22 = gl2;
8471
+ const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
8466
8472
  const uniformBlocks = [];
8467
- const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8473
+ const blockCount = gl22.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8468
8474
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
8469
8475
  const blockInfo = {
8470
- name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
8476
+ name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
8471
8477
  location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),
8472
8478
  byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),
8473
8479
  vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
@@ -8476,12 +8482,12 @@ ${formattedLog}`)();
8476
8482
  uniforms: []
8477
8483
  };
8478
8484
  const uniformIndices = getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
8479
- const uniformType = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8480
- const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8481
- const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8482
- 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);
8483
8489
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
8484
- const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
8490
+ const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
8485
8491
  if (!activeInfo) {
8486
8492
  throw new Error("activeInfo");
8487
8493
  }
@@ -8550,8 +8556,8 @@ ${formattedLog}`)();
8550
8556
  }
8551
8557
 
8552
8558
  // src/adapter/helpers/set-uniform.ts
8553
- function setUniform(gl, location, type, value) {
8554
- const gl2 = gl;
8559
+ function setUniform(gl2, location, type, value) {
8560
+ const gl22 = gl2;
8555
8561
  if (typeof value === "number") {
8556
8562
  switch (type) {
8557
8563
  case GL.SAMPLER_2D:
@@ -8569,7 +8575,7 @@ ${formattedLog}`)();
8569
8575
  case GL.UNSIGNED_INT_SAMPLER_3D:
8570
8576
  case GL.UNSIGNED_INT_SAMPLER_CUBE:
8571
8577
  case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
8572
- return gl.uniform1i(location, value);
8578
+ return gl2.uniform1i(location, value);
8573
8579
  }
8574
8580
  }
8575
8581
  if (value === true) {
@@ -8581,55 +8587,55 @@ ${formattedLog}`)();
8581
8587
  const arrayValue = typeof value === "number" ? [value] : value;
8582
8588
  switch (type) {
8583
8589
  case GL.FLOAT:
8584
- return gl.uniform1fv(location, arrayValue);
8590
+ return gl2.uniform1fv(location, arrayValue);
8585
8591
  case GL.FLOAT_VEC2:
8586
- return gl.uniform2fv(location, arrayValue);
8592
+ return gl2.uniform2fv(location, arrayValue);
8587
8593
  case GL.FLOAT_VEC3:
8588
- return gl.uniform3fv(location, arrayValue);
8594
+ return gl2.uniform3fv(location, arrayValue);
8589
8595
  case GL.FLOAT_VEC4:
8590
- return gl.uniform4fv(location, arrayValue);
8596
+ return gl2.uniform4fv(location, arrayValue);
8591
8597
  case GL.INT:
8592
- return gl.uniform1iv(location, arrayValue);
8598
+ return gl2.uniform1iv(location, arrayValue);
8593
8599
  case GL.INT_VEC2:
8594
- return gl.uniform2iv(location, arrayValue);
8600
+ return gl2.uniform2iv(location, arrayValue);
8595
8601
  case GL.INT_VEC3:
8596
- return gl.uniform3iv(location, arrayValue);
8602
+ return gl2.uniform3iv(location, arrayValue);
8597
8603
  case GL.INT_VEC4:
8598
- return gl.uniform4iv(location, arrayValue);
8604
+ return gl2.uniform4iv(location, arrayValue);
8599
8605
  case GL.BOOL:
8600
- return gl.uniform1iv(location, arrayValue);
8606
+ return gl2.uniform1iv(location, arrayValue);
8601
8607
  case GL.BOOL_VEC2:
8602
- return gl.uniform2iv(location, arrayValue);
8608
+ return gl2.uniform2iv(location, arrayValue);
8603
8609
  case GL.BOOL_VEC3:
8604
- return gl.uniform3iv(location, arrayValue);
8610
+ return gl2.uniform3iv(location, arrayValue);
8605
8611
  case GL.BOOL_VEC4:
8606
- return gl.uniform4iv(location, arrayValue);
8612
+ return gl2.uniform4iv(location, arrayValue);
8607
8613
  case GL.UNSIGNED_INT:
8608
- return gl2.uniform1uiv(location, arrayValue, 1);
8614
+ return gl22.uniform1uiv(location, arrayValue, 1);
8609
8615
  case GL.UNSIGNED_INT_VEC2:
8610
- return gl2.uniform2uiv(location, arrayValue, 2);
8616
+ return gl22.uniform2uiv(location, arrayValue, 2);
8611
8617
  case GL.UNSIGNED_INT_VEC3:
8612
- return gl2.uniform3uiv(location, arrayValue, 3);
8618
+ return gl22.uniform3uiv(location, arrayValue, 3);
8613
8619
  case GL.UNSIGNED_INT_VEC4:
8614
- return gl2.uniform4uiv(location, arrayValue, 4);
8620
+ return gl22.uniform4uiv(location, arrayValue, 4);
8615
8621
  case GL.FLOAT_MAT2:
8616
- return gl.uniformMatrix2fv(location, false, arrayValue);
8622
+ return gl2.uniformMatrix2fv(location, false, arrayValue);
8617
8623
  case GL.FLOAT_MAT3:
8618
- return gl.uniformMatrix3fv(location, false, arrayValue);
8624
+ return gl2.uniformMatrix3fv(location, false, arrayValue);
8619
8625
  case GL.FLOAT_MAT4:
8620
- return gl.uniformMatrix4fv(location, false, arrayValue);
8626
+ return gl2.uniformMatrix4fv(location, false, arrayValue);
8621
8627
  case GL.FLOAT_MAT2x3:
8622
- return gl2.uniformMatrix2x3fv(location, false, arrayValue);
8628
+ return gl22.uniformMatrix2x3fv(location, false, arrayValue);
8623
8629
  case GL.FLOAT_MAT2x4:
8624
- return gl2.uniformMatrix2x4fv(location, false, arrayValue);
8630
+ return gl22.uniformMatrix2x4fv(location, false, arrayValue);
8625
8631
  case GL.FLOAT_MAT3x2:
8626
- return gl2.uniformMatrix3x2fv(location, false, arrayValue);
8632
+ return gl22.uniformMatrix3x2fv(location, false, arrayValue);
8627
8633
  case GL.FLOAT_MAT3x4:
8628
- return gl2.uniformMatrix3x4fv(location, false, arrayValue);
8634
+ return gl22.uniformMatrix3x4fv(location, false, arrayValue);
8629
8635
  case GL.FLOAT_MAT4x2:
8630
- return gl2.uniformMatrix4x2fv(location, false, arrayValue);
8636
+ return gl22.uniformMatrix4x2fv(location, false, arrayValue);
8631
8637
  case GL.FLOAT_MAT4x3:
8632
- return gl2.uniformMatrix4x3fv(location, false, arrayValue);
8638
+ return gl22.uniformMatrix4x3fv(location, false, arrayValue);
8633
8639
  }
8634
8640
  throw new Error("Illegal uniform");
8635
8641
  }
@@ -8677,20 +8683,20 @@ ${formattedLog}`)();
8677
8683
  divisor
8678
8684
  } = accessor;
8679
8685
  const {
8680
- gl,
8681
- gl2
8686
+ gl: gl2,
8687
+ gl2: gl22
8682
8688
  } = this;
8683
8689
  location = Number(location);
8684
8690
  this.bind(() => {
8685
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);
8691
+ gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
8686
8692
  if (integer) {
8687
8693
  this.device.assertWebGL2();
8688
- gl2.vertexAttribIPointer(location, size, type, stride, offset);
8694
+ gl22.vertexAttribIPointer(location, size, type, stride, offset);
8689
8695
  } else {
8690
- gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
8696
+ gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
8691
8697
  }
8692
- gl.enableVertexAttribArray(location);
8693
- gl2.vertexAttribDivisor(location, divisor || 0);
8698
+ gl2.enableVertexAttribArray(location);
8699
+ gl22.vertexAttribDivisor(location, divisor || 0);
8694
8700
  });
8695
8701
  return this;
8696
8702
  }
@@ -8883,22 +8889,22 @@ ${formattedLog}`)();
8883
8889
  // setBindings(bindings: Record<string, Binding>): void {}
8884
8890
  _compileAndLink() {
8885
8891
  const {
8886
- gl
8892
+ gl: gl2
8887
8893
  } = this.device;
8888
- gl.attachShader(this.handle, this.vs.handle);
8889
- gl.attachShader(this.handle, this.fs.handle);
8894
+ gl2.attachShader(this.handle, this.vs.handle);
8895
+ gl2.attachShader(this.handle, this.fs.handle);
8890
8896
  log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
8891
- gl.linkProgram(this.handle);
8897
+ gl2.linkProgram(this.handle);
8892
8898
  log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
8893
- if (gl.debug || log.level > 0) {
8894
- 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);
8895
8901
  if (!linked) {
8896
- throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
8902
+ throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
8897
8903
  }
8898
- gl.validateProgram(this.handle);
8899
- const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
8904
+ gl2.validateProgram(this.handle);
8905
+ const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
8900
8906
  if (!validated) {
8901
- throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
8907
+ throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
8902
8908
  }
8903
8909
  }
8904
8910
  }
@@ -9304,18 +9310,18 @@ ${formattedLog}`)();
9304
9310
  * @param gl
9305
9311
  * @returns
9306
9312
  */
9307
- static attach(gl) {
9308
- if (gl instanceof _WebGLDevice) {
9309
- return gl;
9313
+ static attach(gl2) {
9314
+ if (gl2 instanceof _WebGLDevice) {
9315
+ return gl2;
9310
9316
  }
9311
- if (gl?.device instanceof Device) {
9312
- return gl.device;
9317
+ if (gl2?.device instanceof Device) {
9318
+ return gl2.device;
9313
9319
  }
9314
- if (!isWebGL3(gl)) {
9320
+ if (!isWebGL3(gl2)) {
9315
9321
  throw new Error("Invalid WebGLRenderingContext");
9316
9322
  }
9317
9323
  return new _WebGLDevice({
9318
- gl
9324
+ gl: gl2
9319
9325
  });
9320
9326
  }
9321
9327
  static async create(props = {}) {
@@ -9355,19 +9361,19 @@ ${formattedLog}`)();
9355
9361
  reason: "destroyed",
9356
9362
  message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
9357
9363
  });
9358
- let gl = props.gl || null;
9359
- gl = gl || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9364
+ let gl2 = props.gl || null;
9365
+ gl2 = gl2 || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9360
9366
  ...props,
9361
9367
  onContextLost
9362
9368
  }) : null);
9363
- gl = gl || (!isBrowser() ? createHeadlessContext({
9369
+ gl2 = gl2 || (!isBrowser() ? createHeadlessContext({
9364
9370
  ...props,
9365
9371
  onContextLost
9366
9372
  }) : null);
9367
- if (!gl) {
9373
+ if (!gl2) {
9368
9374
  throw new Error("WebGL context creation failed");
9369
9375
  }
9370
- this.handle = gl;
9376
+ this.handle = gl2;
9371
9377
  this.gl = this.handle;
9372
9378
  this.gl2 = this.gl;
9373
9379
  this.isWebGL2 = isWebGL22(this.gl);
@@ -9555,11 +9561,11 @@ ${formattedLog}`)();
9555
9561
  * Be aware that there are some duplicates especially for constants that are 0,
9556
9562
  * so this isn't guaranteed to return the right key in all cases.
9557
9563
  */
9558
- getGLKey(value, gl) {
9559
- gl = gl || this.gl2 || this.gl;
9564
+ getGLKey(value, gl2) {
9565
+ gl2 = gl2 || this.gl2 || this.gl;
9560
9566
  const number = Number(value);
9561
- for (const key in gl) {
9562
- if (gl[key] === number) {
9567
+ for (const key in gl2) {
9568
+ if (gl2[key] === number) {
9563
9569
  return `GL.${key}`;
9564
9570
  }
9565
9571
  }
@@ -9571,20 +9577,20 @@ ${formattedLog}`)();
9571
9577
  // Public `Device` API
9572
9578
  //
9573
9579
  __publicField(WebGLDevice, "type", "webgl");
9574
- function isWebGL3(gl) {
9575
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
9580
+ function isWebGL3(gl2) {
9581
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
9576
9582
  return true;
9577
9583
  }
9578
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9584
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9579
9585
  return true;
9580
9586
  }
9581
- return Boolean(gl && Number.isFinite(gl._version));
9587
+ return Boolean(gl2 && Number.isFinite(gl2._version));
9582
9588
  }
9583
- function isWebGL22(gl) {
9584
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9589
+ function isWebGL22(gl2) {
9590
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9585
9591
  return true;
9586
9592
  }
9587
- return Boolean(gl && gl._version === 2);
9593
+ return Boolean(gl2 && gl2._version === 2);
9588
9594
  }
9589
9595
 
9590
9596
  // src/classic/clear.ts
@@ -9592,8 +9598,8 @@ ${formattedLog}`)();
9592
9598
  var GL_STENCIL_BUFFER_BIT2 = 1024;
9593
9599
  var GL_COLOR_BUFFER_BIT2 = 16384;
9594
9600
  var ERR_ARGUMENTS = "clear: bad arguments";
9595
- function clear(gl, options) {
9596
- const device = WebGLDevice.attach(gl);
9601
+ function clear(gl2, options) {
9602
+ const device = WebGLDevice.attach(gl2);
9597
9603
  const {
9598
9604
  framebuffer = null,
9599
9605
  color = null,
@@ -9688,7 +9694,7 @@ ${formattedLog}`)();
9688
9694
  } = getFramebuffer2(source);
9689
9695
  assert2(framebuffer);
9690
9696
  const {
9691
- gl,
9697
+ gl: gl2,
9692
9698
  handle
9693
9699
  } = framebuffer;
9694
9700
  sourceWidth = sourceWidth || framebuffer.width;
@@ -9700,9 +9706,9 @@ ${formattedLog}`)();
9700
9706
  sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
9701
9707
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
9702
9708
  sourceType = sourceType || getGLTypeFromTypedArray(target);
9703
- const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
9704
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
9705
- 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);
9706
9712
  if (deleteFramebuffer) {
9707
9713
  framebuffer.destroy();
9708
9714
  }
@@ -9759,6 +9765,85 @@ ${formattedLog}`)();
9759
9765
  }
9760
9766
  return target;
9761
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
+ }
9762
9847
  function getFramebuffer2(source) {
9763
9848
  if (!(source instanceof Framebuffer)) {
9764
9849
  return {