@luma.gl/webgl 9.0.0-alpha.25 → 9.0.0-alpha.27

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
  /**
@@ -1850,6 +1851,7 @@ var __exports__ = (() => {
1850
1851
  };
1851
1852
  /** Set attributes (stored on pipeline and set before each call) */
1852
1853
  /** Set attributes (stored on pipeline and set before each call) */
1854
+ /** Set constant attributes (WebGL only) */
1853
1855
  /** Set bindings (stored on pipeline and set before each call) */
1854
1856
  /** Uniforms (only supported on WebGL devices. Reset before each call to enable pipeline sharing) */
1855
1857
  /** Draw call */
@@ -1864,7 +1866,11 @@ var __exports__ = (() => {
1864
1866
  constructor(device, props) {
1865
1867
  super(device, props, _RenderPass.defaultProps);
1866
1868
  }
1867
- /** A small set of parameters can be changed between every draw call (viewport, scissorRect, blendColor, stencilReference) */
1869
+ /** Call when rendering is done in this pass. */
1870
+ /**
1871
+ * A small set of parameters can be changed between every draw call
1872
+ * (viewport, scissorRect, blendColor, stencilReference)
1873
+ */
1868
1874
  // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
1869
1875
  // beginOcclusionQuery(queryIndex: number): void;
1870
1876
  // endOcclusionQuery(): void;
@@ -2251,6 +2257,43 @@ var __exports__ = (() => {
2251
2257
  });
2252
2258
  }
2253
2259
 
2260
+ // ../api/src/lib/utils/array-utils-flat.ts
2261
+ var arrayBuffer;
2262
+ function getScratchArrayBuffer(byteLength) {
2263
+ if (!arrayBuffer || arrayBuffer.byteLength < byteLength) {
2264
+ arrayBuffer = new ArrayBuffer(byteLength);
2265
+ }
2266
+ return arrayBuffer;
2267
+ }
2268
+ function getScratchArray(Type, length) {
2269
+ const scratchArrayBuffer = getScratchArrayBuffer(Type.BYTES_PER_ELEMENT * length);
2270
+ return new Type(scratchArrayBuffer, 0, length);
2271
+ }
2272
+ function fillArray(options) {
2273
+ const {
2274
+ target,
2275
+ source,
2276
+ start = 0,
2277
+ count = 1
2278
+ } = options;
2279
+ const length = source.length;
2280
+ const total = count * length;
2281
+ let copied = 0;
2282
+ for (let i = start; copied < length; copied++) {
2283
+ target[i++] = source[copied];
2284
+ }
2285
+ while (copied < total) {
2286
+ if (copied < total - copied) {
2287
+ target.copyWithin(start + copied, start, start + copied);
2288
+ copied *= 2;
2289
+ } else {
2290
+ target.copyWithin(start + copied, start, start + total - copied);
2291
+ copied = total;
2292
+ }
2293
+ }
2294
+ return options.target;
2295
+ }
2296
+
2254
2297
  // src/context/polyfill/polyfill-vertex-array-object.ts
2255
2298
  var glErrorShadow = {};
2256
2299
  function error(msg) {
@@ -2269,43 +2312,43 @@ var __exports__ = (() => {
2269
2312
  error(opt_msg);
2270
2313
  }
2271
2314
  }
2272
- function wrapGLError(gl) {
2273
- const f = gl.getError;
2274
- gl.getError = function getError() {
2315
+ function wrapGLError(gl2) {
2316
+ const f = gl2.getError;
2317
+ gl2.getError = function getError() {
2275
2318
  let err;
2276
2319
  do {
2277
- err = f.apply(gl);
2278
- if (err !== gl.NO_ERROR) {
2320
+ err = f.apply(gl2);
2321
+ if (err !== gl2.NO_ERROR) {
2279
2322
  glErrorShadow[err] = true;
2280
2323
  }
2281
- } while (err !== gl.NO_ERROR);
2324
+ } while (err !== gl2.NO_ERROR);
2282
2325
  for (err in glErrorShadow) {
2283
2326
  if (glErrorShadow[err]) {
2284
2327
  delete glErrorShadow[err];
2285
2328
  return parseInt(err, 10);
2286
2329
  }
2287
2330
  }
2288
- return gl.NO_ERROR;
2331
+ return gl2.NO_ERROR;
2289
2332
  };
2290
2333
  }
2291
2334
  var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
2292
- const gl = ext.gl;
2335
+ const gl2 = ext.gl;
2293
2336
  this.ext = ext;
2294
2337
  this.isAlive = true;
2295
2338
  this.hasBeenBound = false;
2296
2339
  this.elementArrayBuffer = null;
2297
2340
  this.attribs = new Array(ext.maxVertexAttribs);
2298
2341
  for (let n = 0; n < this.attribs.length; n++) {
2299
- const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl);
2342
+ const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
2300
2343
  this.attribs[n] = attrib;
2301
2344
  }
2302
2345
  this.maxAttrib = 0;
2303
2346
  };
2304
- WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
2347
+ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
2305
2348
  this.enabled = false;
2306
2349
  this.buffer = null;
2307
2350
  this.size = 4;
2308
- this.type = gl.FLOAT;
2351
+ this.type = gl2.FLOAT;
2309
2352
  this.normalized = false;
2310
2353
  this.stride = 16;
2311
2354
  this.offset = 0;
@@ -2315,19 +2358,19 @@ var __exports__ = (() => {
2315
2358
  WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
2316
2359
  this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
2317
2360
  };
2318
- var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
2361
+ var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
2319
2362
  const self = this;
2320
- this.gl = gl;
2321
- wrapGLError(gl);
2363
+ this.gl = gl2;
2364
+ wrapGLError(gl2);
2322
2365
  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
2366
+ getParameter: gl2.getParameter,
2367
+ enableVertexAttribArray: gl2.enableVertexAttribArray,
2368
+ disableVertexAttribArray: gl2.disableVertexAttribArray,
2369
+ bindBuffer: gl2.bindBuffer,
2370
+ getVertexAttrib: gl2.getVertexAttrib,
2371
+ vertexAttribPointer: gl2.vertexAttribPointer
2329
2372
  };
2330
- gl.getParameter = function getParameter(pname) {
2373
+ gl2.getParameter = function getParameter(pname) {
2331
2374
  if (pname === self.VERTEX_ARRAY_BINDING_OES) {
2332
2375
  if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
2333
2376
  return null;
@@ -2336,53 +2379,53 @@ var __exports__ = (() => {
2336
2379
  }
2337
2380
  return original.getParameter.apply(this, arguments);
2338
2381
  };
2339
- gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
2382
+ gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
2340
2383
  const vao = self.currentVertexArrayObject;
2341
2384
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2342
2385
  const attrib = vao.attribs[index];
2343
2386
  attrib.enabled = true;
2344
2387
  return original.enableVertexAttribArray.apply(this, arguments);
2345
2388
  };
2346
- gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
2389
+ gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
2347
2390
  const vao = self.currentVertexArrayObject;
2348
2391
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
2349
2392
  const attrib = vao.attribs[index];
2350
2393
  attrib.enabled = false;
2351
2394
  return original.disableVertexAttribArray.apply(this, arguments);
2352
2395
  };
2353
- gl.bindBuffer = function bindBuffer2(target, buffer) {
2396
+ gl2.bindBuffer = function bindBuffer2(target, buffer) {
2354
2397
  switch (target) {
2355
- case gl.ARRAY_BUFFER:
2398
+ case gl2.ARRAY_BUFFER:
2356
2399
  self.currentArrayBuffer = buffer;
2357
2400
  break;
2358
- case gl.ELEMENT_ARRAY_BUFFER:
2401
+ case gl2.ELEMENT_ARRAY_BUFFER:
2359
2402
  self.currentVertexArrayObject.elementArrayBuffer = buffer;
2360
2403
  break;
2361
2404
  default:
2362
2405
  }
2363
2406
  return original.bindBuffer.apply(this, arguments);
2364
2407
  };
2365
- gl.getVertexAttrib = function getVertexAttrib(index, pname) {
2408
+ gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
2366
2409
  const vao = self.currentVertexArrayObject;
2367
2410
  const attrib = vao.attribs[index];
2368
2411
  switch (pname) {
2369
- case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2412
+ case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2370
2413
  return attrib.buffer;
2371
- case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
2414
+ case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
2372
2415
  return attrib.enabled;
2373
- case gl.VERTEX_ATTRIB_ARRAY_SIZE:
2416
+ case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
2374
2417
  return attrib.size;
2375
- case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
2418
+ case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
2376
2419
  return attrib.stride;
2377
- case gl.VERTEX_ATTRIB_ARRAY_TYPE:
2420
+ case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
2378
2421
  return attrib.type;
2379
- case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2422
+ case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
2380
2423
  return attrib.normalized;
2381
2424
  default:
2382
2425
  return original.getVertexAttrib.apply(this, arguments);
2383
2426
  }
2384
2427
  };
2385
- gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2428
+ gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
2386
2429
  const vao = self.currentVertexArrayObject;
2387
2430
  vao.maxAttrib = Math.max(vao.maxAttrib, indx);
2388
2431
  const attrib = vao.attribs[indx];
@@ -2395,11 +2438,11 @@ var __exports__ = (() => {
2395
2438
  attrib.recache();
2396
2439
  return original.vertexAttribPointer.apply(this, arguments);
2397
2440
  };
2398
- if (gl.instrumentExtension) {
2399
- gl.instrumentExtension(this, "OES_vertex_array_object");
2441
+ if (gl2.instrumentExtension) {
2442
+ gl2.instrumentExtension(this, "OES_vertex_array_object");
2400
2443
  }
2401
- if (gl.canvas) {
2402
- gl.canvas.addEventListener("webglcontextrestored", () => {
2444
+ if (gl2.canvas) {
2445
+ gl2.canvas.addEventListener("webglcontextrestored", () => {
2403
2446
  log2("OESVertexArrayObject emulation library context restored");
2404
2447
  self.reset_();
2405
2448
  }, true);
@@ -2414,8 +2457,8 @@ var __exports__ = (() => {
2414
2457
  this.vertexArrayObjects.isAlive = false;
2415
2458
  }
2416
2459
  }
2417
- const gl = this.gl;
2418
- this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
2460
+ const gl2 = this.gl;
2461
+ this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
2419
2462
  this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
2420
2463
  this.currentVertexArrayObject = null;
2421
2464
  this.currentArrayBuffer = null;
@@ -2443,9 +2486,9 @@ var __exports__ = (() => {
2443
2486
  return false;
2444
2487
  };
2445
2488
  OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
2446
- const gl = this.gl;
2489
+ const gl2 = this.gl;
2447
2490
  if (arrayObject && !arrayObject.isAlive) {
2448
- synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2491
+ synthesizeGLError(gl2.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
2449
2492
  return;
2450
2493
  }
2451
2494
  const original = this.original;
@@ -2457,7 +2500,7 @@ var __exports__ = (() => {
2457
2500
  return;
2458
2501
  }
2459
2502
  if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
2460
- original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2503
+ original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
2461
2504
  }
2462
2505
  let currentBinding = this.currentArrayBuffer;
2463
2506
  const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
@@ -2466,43 +2509,43 @@ var __exports__ = (() => {
2466
2509
  const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
2467
2510
  if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
2468
2511
  if (attrib.enabled) {
2469
- original.enableVertexAttribArray.call(gl, n);
2512
+ original.enableVertexAttribArray.call(gl2, n);
2470
2513
  } else {
2471
- original.disableVertexAttribArray.call(gl, n);
2514
+ original.disableVertexAttribArray.call(gl2, n);
2472
2515
  }
2473
2516
  }
2474
2517
  if (attrib.enabled) {
2475
2518
  let bufferChanged = false;
2476
2519
  if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
2477
2520
  if (currentBinding !== attrib.buffer) {
2478
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
2521
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
2479
2522
  currentBinding = attrib.buffer;
2480
2523
  }
2481
2524
  bufferChanged = true;
2482
2525
  }
2483
2526
  if (bufferChanged || attrib.cached !== oldAttrib.cached) {
2484
- original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2527
+ original.vertexAttribPointer.call(gl2, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
2485
2528
  }
2486
2529
  }
2487
2530
  }
2488
2531
  if (this.currentArrayBuffer !== currentBinding) {
2489
- original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
2532
+ original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
2490
2533
  }
2491
2534
  };
2492
- function polyfillVertexArrayObject(gl) {
2493
- if (typeof gl.createVertexArray === "function") {
2535
+ function polyfillVertexArrayObject(gl2) {
2536
+ if (typeof gl2.createVertexArray === "function") {
2494
2537
  return;
2495
2538
  }
2496
- const original_getSupportedExtensions = gl.getSupportedExtensions;
2497
- gl.getSupportedExtensions = function getSupportedExtensions() {
2539
+ const original_getSupportedExtensions = gl2.getSupportedExtensions;
2540
+ gl2.getSupportedExtensions = function getSupportedExtensions() {
2498
2541
  const list = original_getSupportedExtensions.call(this) || [];
2499
2542
  if (list.indexOf("OES_vertex_array_object") < 0) {
2500
2543
  list.push("OES_vertex_array_object");
2501
2544
  }
2502
2545
  return list;
2503
2546
  };
2504
- const original_getExtension = gl.getExtension;
2505
- gl.getExtension = function getExtension(name) {
2547
+ const original_getExtension = gl2.getExtension;
2548
+ gl2.getExtension = function getExtension(name) {
2506
2549
  const ext = original_getExtension.call(this, name);
2507
2550
  if (ext) {
2508
2551
  return ext;
@@ -2510,7 +2553,7 @@ var __exports__ = (() => {
2510
2553
  if (name !== "OES_vertex_array_object") {
2511
2554
  return null;
2512
2555
  }
2513
- if (!gl.__OESVertexArrayObject) {
2556
+ if (!gl2.__OESVertexArrayObject) {
2514
2557
  this.__OESVertexArrayObject = new OESVertexArrayObject(this);
2515
2558
  }
2516
2559
  return this.__OESVertexArrayObject;
@@ -3187,31 +3230,31 @@ var __exports__ = (() => {
3187
3230
  // src/context/context/webgl-checks.ts
3188
3231
  var ERR_CONTEXT = "Invalid WebGLRenderingContext";
3189
3232
  var ERR_WEBGL2 = "Requires WebGL2";
3190
- function isWebGL(gl) {
3191
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
3233
+ function isWebGL(gl2) {
3234
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
3192
3235
  return true;
3193
3236
  }
3194
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3237
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3195
3238
  return true;
3196
3239
  }
3197
- return Boolean(gl && Number.isFinite(gl._version));
3240
+ return Boolean(gl2 && Number.isFinite(gl2._version));
3198
3241
  }
3199
- function isWebGL2(gl) {
3200
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
3242
+ function isWebGL2(gl2) {
3243
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
3201
3244
  return true;
3202
3245
  }
3203
- return Boolean(gl && gl._version === 2);
3246
+ return Boolean(gl2 && gl2._version === 2);
3204
3247
  }
3205
- function getWebGL2Context(gl) {
3206
- return isWebGL2(gl) ? gl : null;
3248
+ function getWebGL2Context(gl2) {
3249
+ return isWebGL2(gl2) ? gl2 : null;
3207
3250
  }
3208
- function assertWebGLContext(gl) {
3209
- assert2(isWebGL(gl), ERR_CONTEXT);
3210
- return gl;
3251
+ function assertWebGLContext(gl2) {
3252
+ assert2(isWebGL(gl2), ERR_CONTEXT);
3253
+ return gl2;
3211
3254
  }
3212
- function assertWebGL2Context(gl) {
3213
- assert2(isWebGL2(gl), ERR_WEBGL2);
3214
- return gl;
3255
+ function assertWebGL2Context(gl2) {
3256
+ assert2(isWebGL2(gl2), ERR_WEBGL2);
3257
+ return gl2;
3215
3258
  }
3216
3259
 
3217
3260
  // src/context/polyfill/get-parameter-polyfill.ts
@@ -3227,39 +3270,39 @@ var __exports__ = (() => {
3227
3270
  var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
3228
3271
  var GL_UNMASKED_VENDOR_WEBGL = 37445;
3229
3272
  var GL_UNMASKED_RENDERER_WEBGL = 37446;
3230
- var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
3273
+ var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
3231
3274
  var WEBGL_PARAMETERS = {
3232
- [GL.READ_BUFFER]: (gl) => !isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : void 0,
3275
+ [GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? GL.COLOR_ATTACHMENT0 : void 0,
3233
3276
  // WebGL2 context parameters
3234
- [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => !isWebGL2(gl) ? GL_DONT_CARE : void 0,
3277
+ [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
3235
3278
  [GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
3236
3279
  [GL.SAMPLES]: getWebGL2ValueOrZero,
3237
3280
  // 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);
3281
+ [GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
3282
+ const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
3240
3283
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
3241
3284
  },
3242
3285
  // Extension fixed values
3243
- [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
3244
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3286
+ [GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
3287
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3245
3288
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || GL.VENDOR);
3246
3289
  },
3247
- [GL_UNMASKED_RENDERER_WEBGL]: (gl, getParameter) => {
3248
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
3290
+ [GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
3291
+ const ext = gl2.getExtension(WEBGL_debug_renderer_info);
3249
3292
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || GL.RENDERER);
3250
3293
  },
3251
3294
  // 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");
3295
+ [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
3296
+ const ext = gl2.luma?.extensions?.[EXT_texture_filter_anisotropic] || gl2.getExtension("EXT_texture_filter_anisotropic");
3254
3297
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
3255
3298
  },
3256
3299
  // WebGL2 Limits
3257
3300
  [GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
3258
3301
  [GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
3259
3302
  [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);
3303
+ [GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
3304
+ if (!isWebGL2(gl2)) {
3305
+ const ext = gl2.getExtension(WEBGL_draw_buffers);
3263
3306
  return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
3264
3307
  }
3265
3308
  return void 0;
@@ -3267,24 +3310,24 @@ var __exports__ = (() => {
3267
3310
  [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
3268
3311
  [GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
3269
3312
  [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);
3313
+ [GL.MAX_DRAW_BUFFERS]: (gl2) => {
3314
+ if (!isWebGL2(gl2)) {
3315
+ const ext = gl2.getExtension(WEBGL_draw_buffers);
3273
3316
  return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
3274
3317
  }
3275
3318
  return void 0;
3276
3319
  },
3277
3320
  [GL.MAX_ELEMENT_INDEX]: (
3278
3321
  // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
3279
- (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
3322
+ (gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
3280
3323
  ),
3281
3324
  [GL.MAX_ELEMENTS_INDICES]: (
3282
3325
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3283
- (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
3326
+ (gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
3284
3327
  ),
3285
3328
  [GL.MAX_ELEMENTS_VERTICES]: (
3286
3329
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
3287
- (gl) => 16777216
3330
+ (gl2) => 16777216
3288
3331
  ),
3289
3332
  [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
3290
3333
  [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
@@ -3305,24 +3348,24 @@ var __exports__ = (() => {
3305
3348
  [GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
3306
3349
  [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
3307
3350
  };
3308
- function getParameterPolyfill(gl, originalGetParameter, pname) {
3351
+ function getParameterPolyfill(gl2, originalGetParameter, pname) {
3309
3352
  const limit = WEBGL_PARAMETERS[pname];
3310
- const value = typeof limit === "function" ? limit(gl, originalGetParameter, pname) : limit;
3353
+ const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
3311
3354
  const result = value !== void 0 ? value : originalGetParameter(pname);
3312
3355
  return result;
3313
3356
  }
3314
3357
 
3315
3358
  // src/context/polyfill/context-data.ts
3316
- function getContextData(gl) {
3317
- const luma = gl.luma;
3359
+ function getContextData(gl2) {
3360
+ const luma = gl2.luma;
3318
3361
  if (!luma) {
3319
3362
  const contextState = {
3320
3363
  _polyfilled: false,
3321
3364
  _extensions: {}
3322
3365
  };
3323
- gl.luma = contextState;
3366
+ gl2.luma = contextState;
3324
3367
  }
3325
- return gl.luma;
3368
+ return gl2.luma;
3326
3369
  }
3327
3370
 
3328
3371
  // src/context/polyfill/polyfill-table.ts
@@ -3332,10 +3375,10 @@ var __exports__ = (() => {
3332
3375
  var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
3333
3376
  var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
3334
3377
  var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
3335
- function getExtensionData(gl, extension) {
3378
+ function getExtensionData(gl2, extension) {
3336
3379
  return {
3337
- webgl2: isWebGL2(gl),
3338
- ext: gl.getExtension(extension)
3380
+ webgl2: isWebGL2(gl2),
3381
+ ext: gl2.getExtension(extension)
3339
3382
  };
3340
3383
  }
3341
3384
  var WEBGL2_CONTEXT_POLYFILLS = {
@@ -3406,18 +3449,18 @@ var __exports__ = (() => {
3406
3449
  };
3407
3450
  var WEBGL2_CONTEXT_OVERRIDES = {
3408
3451
  // Ensure readBuffer is a no-op
3409
- readBuffer: (gl, originalFunc, attachment) => {
3410
- if (isWebGL2(gl)) {
3452
+ readBuffer: (gl2, originalFunc, attachment) => {
3453
+ if (isWebGL2(gl2)) {
3411
3454
  originalFunc(attachment);
3412
3455
  } else {
3413
3456
  }
3414
3457
  },
3415
3458
  // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
3416
- getVertexAttrib: (gl, originalFunc, location, pname) => {
3459
+ getVertexAttrib: (gl2, originalFunc, location, pname) => {
3417
3460
  const {
3418
3461
  webgl2,
3419
3462
  ext
3420
- } = getExtensionData(gl, ANGLE_instanced_arrays);
3463
+ } = getExtensionData(gl2, ANGLE_instanced_arrays);
3421
3464
  let result;
3422
3465
  switch (pname) {
3423
3466
  case GL.VERTEX_ATTRIB_ARRAY_INTEGER:
@@ -3431,8 +3474,8 @@ var __exports__ = (() => {
3431
3474
  return result !== void 0 ? result : originalFunc(location, pname);
3432
3475
  },
3433
3476
  // Handle transform feedback and uniform block queries in WebGL1
3434
- getProgramParameter: (gl, originalFunc, program, pname) => {
3435
- if (!isWebGL2(gl)) {
3477
+ getProgramParameter: (gl2, originalFunc, program, pname) => {
3478
+ if (!isWebGL2(gl2)) {
3436
3479
  switch (pname) {
3437
3480
  case GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
3438
3481
  return GL.SEPARATE_ATTRIBS;
@@ -3445,21 +3488,21 @@ var __exports__ = (() => {
3445
3488
  }
3446
3489
  return originalFunc(program, pname);
3447
3490
  },
3448
- getInternalformatParameter: (gl, originalFunc, target, format, pname) => {
3449
- if (!isWebGL2(gl)) {
3491
+ getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
3492
+ if (!isWebGL2(gl2)) {
3450
3493
  switch (pname) {
3451
3494
  case GL.SAMPLES:
3452
3495
  return new Int32Array([0]);
3453
3496
  default:
3454
3497
  }
3455
3498
  }
3456
- const gl2 = gl;
3457
- return gl2.getInternalformatParameter(target, format, pname);
3499
+ const gl22 = gl2;
3500
+ return gl22.getInternalformatParameter(target, format, pname);
3458
3501
  },
3459
- getTexParameter(gl, originalFunc, target, pname) {
3502
+ getTexParameter(gl2, originalFunc, target, pname) {
3460
3503
  switch (pname) {
3461
3504
  case GL.TEXTURE_MAX_ANISOTROPY_EXT:
3462
- const contextData = getContextData(gl);
3505
+ const contextData = getContextData(gl2);
3463
3506
  const {
3464
3507
  _extensions
3465
3508
  } = contextData;
@@ -3471,47 +3514,47 @@ var __exports__ = (() => {
3471
3514
  return originalFunc(target, pname);
3472
3515
  },
3473
3516
  getParameter: getParameterPolyfill,
3474
- hint(gl, originalFunc, pname, value) {
3517
+ hint(gl2, originalFunc, pname, value) {
3475
3518
  return originalFunc(pname, value);
3476
3519
  }
3477
3520
  };
3478
3521
 
3479
3522
  // src/context/polyfill/polyfill-context.ts
3480
- function polyfillContext(gl) {
3481
- const contextState = getContextData(gl);
3523
+ function polyfillContext(gl2) {
3524
+ const contextState = getContextData(gl2);
3482
3525
  if (!contextState._polyfilled) {
3483
- polyfillVertexArrayObject(gl);
3484
- initializeExtensions(gl);
3485
- installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
3486
- installOverrides(gl, {
3526
+ polyfillVertexArrayObject(gl2);
3527
+ initializeExtensions(gl2);
3528
+ installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
3529
+ installOverrides(gl2, {
3487
3530
  target: contextState,
3488
- target2: gl
3531
+ target2: gl2
3489
3532
  });
3490
3533
  contextState._polyfilled = true;
3491
3534
  }
3492
- return gl;
3535
+ return gl2;
3493
3536
  }
3494
- function initializeExtensions(gl) {
3495
- const contextState = getContextData(gl);
3496
- const EXTENSIONS = gl.getSupportedExtensions() || [];
3537
+ function initializeExtensions(gl2) {
3538
+ const contextState = getContextData(gl2);
3539
+ const EXTENSIONS = gl2.getSupportedExtensions() || [];
3497
3540
  for (const extensionName of EXTENSIONS) {
3498
- const extension = gl.getExtension(extensionName);
3541
+ const extension = gl2.getExtension(extensionName);
3499
3542
  contextState._extensions[extensionName] = extension;
3500
3543
  }
3501
3544
  }
3502
- function installPolyfills(gl, polyfills) {
3503
- const contextState = getContextData(gl);
3545
+ function installPolyfills(gl2, polyfills) {
3546
+ const contextState = getContextData(gl2);
3504
3547
  for (const extension of Object.getOwnPropertyNames(polyfills)) {
3505
3548
  if (extension !== "overrides") {
3506
- polyfillExtension(gl, {
3549
+ polyfillExtension(gl2, {
3507
3550
  extension,
3508
3551
  target: contextState,
3509
- target2: gl
3552
+ target2: gl2
3510
3553
  });
3511
3554
  }
3512
3555
  }
3513
3556
  }
3514
- function polyfillExtension(gl, {
3557
+ function polyfillExtension(gl2, {
3515
3558
  extension,
3516
3559
  target,
3517
3560
  target2
@@ -3524,12 +3567,12 @@ var __exports__ = (() => {
3524
3567
  const {
3525
3568
  suffix = ""
3526
3569
  } = meta;
3527
- const ext = gl.getExtension(extension);
3570
+ const ext = gl2.getExtension(extension);
3528
3571
  for (const key of Object.keys(defaults)) {
3529
3572
  const extKey = `${key}${suffix}`;
3530
3573
  let polyfill = null;
3531
3574
  if (key === "meta") {
3532
- } else if (typeof gl[key] === "function") {
3575
+ } else if (typeof gl2[key] === "function") {
3533
3576
  } else if (ext && typeof ext[extKey] === "function") {
3534
3577
  polyfill = (...args) => ext[extKey](...args);
3535
3578
  } else if (typeof defaults[key] === "function") {
@@ -3541,15 +3584,15 @@ var __exports__ = (() => {
3541
3584
  }
3542
3585
  }
3543
3586
  }
3544
- function installOverrides(gl, {
3587
+ function installOverrides(gl2, {
3545
3588
  target,
3546
3589
  target2
3547
3590
  }) {
3548
3591
  Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
3549
3592
  if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
3550
- const originalFunc = gl[key] ? gl[key].bind(gl) : () => {
3593
+ const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
3551
3594
  };
3552
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
3595
+ const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
3553
3596
  target[key] = polyfill;
3554
3597
  target2[key] = polyfill;
3555
3598
  }
@@ -3640,19 +3683,19 @@ var __exports__ = (() => {
3640
3683
  [GL.UNPACK_SKIP_ROWS]: 0,
3641
3684
  [GL.UNPACK_SKIP_IMAGES]: 0
3642
3685
  };
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) => {
3686
+ var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
3687
+ var hint = (gl2, value, key) => gl2.hint(key, value);
3688
+ var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
3689
+ var bindFramebuffer = (gl2, value, key) => {
3647
3690
  let target;
3648
3691
  if (key === GL.FRAMEBUFFER_BINDING) {
3649
- target = isWebGL2(gl) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3692
+ target = isWebGL2(gl2) ? GL.DRAW_FRAMEBUFFER : GL.FRAMEBUFFER;
3650
3693
  } else {
3651
3694
  target = GL.READ_FRAMEBUFFER;
3652
3695
  }
3653
- return gl.bindFramebuffer(target, value);
3696
+ return gl2.bindFramebuffer(target, value);
3654
3697
  };
3655
- var bindBuffer = (gl, value, key) => {
3698
+ var bindBuffer = (gl2, value, key) => {
3656
3699
  const bindingMap = {
3657
3700
  [GL.ARRAY_BUFFER_BINDING]: GL.ARRAY_BUFFER,
3658
3701
  [GL.COPY_READ_BUFFER_BINDING]: GL.COPY_READ_BUFFER,
@@ -3661,35 +3704,35 @@ var __exports__ = (() => {
3661
3704
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
3662
3705
  };
3663
3706
  const target = bindingMap[key];
3664
- gl.bindBuffer(target, value);
3707
+ gl2.bindBuffer(target, value);
3665
3708
  };
3666
3709
  function isArray(array) {
3667
3710
  return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
3668
3711
  }
3669
3712
  var GL_PARAMETER_SETTERS = {
3670
3713
  [GL.BLEND]: enable,
3671
- [GL.BLEND_COLOR]: (gl, value) => gl.blendColor(...value),
3714
+ [GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
3672
3715
  [GL.BLEND_EQUATION_RGB]: "blendEquation",
3673
3716
  [GL.BLEND_EQUATION_ALPHA]: "blendEquation",
3674
3717
  [GL.BLEND_SRC_RGB]: "blendFunc",
3675
3718
  [GL.BLEND_DST_RGB]: "blendFunc",
3676
3719
  [GL.BLEND_SRC_ALPHA]: "blendFunc",
3677
3720
  [GL.BLEND_DST_ALPHA]: "blendFunc",
3678
- [GL.COLOR_CLEAR_VALUE]: (gl, value) => gl.clearColor(...value),
3679
- [GL.COLOR_WRITEMASK]: (gl, value) => gl.colorMask(...value),
3721
+ [GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
3722
+ [GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
3680
3723
  [GL.CULL_FACE]: enable,
3681
- [GL.CULL_FACE_MODE]: (gl, value) => gl.cullFace(value),
3724
+ [GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
3682
3725
  [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),
3726
+ [GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
3727
+ [GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
3728
+ [GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
3729
+ [GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
3687
3730
  [GL.DITHER]: enable,
3688
3731
  [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),
3732
+ [GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
3733
+ [GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(GL.RENDERBUFFER, value),
3734
+ [GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => gl2.bindTransformFeedback?.(GL.TRANSFORM_FEEDBACK, value),
3735
+ [GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
3693
3736
  // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
3694
3737
  [GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
3695
3738
  [GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
@@ -3699,9 +3742,9 @@ var __exports__ = (() => {
3699
3742
  [GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
3700
3743
  [GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
3701
3744
  [GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
3702
- [GL.FRONT_FACE]: (gl, value) => gl.frontFace(value),
3745
+ [GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
3703
3746
  [GL.GENERATE_MIPMAP_HINT]: hint,
3704
- [GL.LINE_WIDTH]: (gl, value) => gl.lineWidth(value),
3747
+ [GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
3705
3748
  [GL.POLYGON_OFFSET_FILL]: enable,
3706
3749
  [GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
3707
3750
  [GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
@@ -3711,11 +3754,11 @@ var __exports__ = (() => {
3711
3754
  [GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
3712
3755
  [GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
3713
3756
  [GL.SCISSOR_TEST]: enable,
3714
- [GL.SCISSOR_BOX]: (gl, value) => gl.scissor(...value),
3757
+ [GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
3715
3758
  [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),
3759
+ [GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
3760
+ [GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.FRONT, value),
3761
+ [GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(GL.BACK, value),
3719
3762
  [GL.STENCIL_FUNC]: "stencilFuncFront",
3720
3763
  [GL.STENCIL_REF]: "stencilFuncFront",
3721
3764
  [GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
@@ -3728,7 +3771,7 @@ var __exports__ = (() => {
3728
3771
  [GL.STENCIL_BACK_FAIL]: "stencilOpBack",
3729
3772
  [GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
3730
3773
  [GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
3731
- [GL.VIEWPORT]: (gl, value) => gl.viewport(...value),
3774
+ [GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
3732
3775
  // WEBGL1 PIXEL PACK/UNPACK MODES
3733
3776
  [GL.PACK_ALIGNMENT]: pixelStorei,
3734
3777
  [GL.UNPACK_ALIGNMENT]: pixelStorei,
@@ -3746,75 +3789,75 @@ var __exports__ = (() => {
3746
3789
  [GL.UNPACK_SKIP_ROWS]: pixelStorei,
3747
3790
  [GL.UNPACK_SKIP_IMAGES]: pixelStorei,
3748
3791
  // Function-style setters
3749
- framebuffer: (gl, framebuffer) => {
3792
+ framebuffer: (gl2, framebuffer) => {
3750
3793
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
3751
- return gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
3794
+ return gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
3752
3795
  },
3753
- blend: (gl, value) => value ? gl.enable(GL.BLEND) : gl.disable(GL.BLEND),
3754
- blendColor: (gl, value) => gl.blendColor(...value),
3755
- blendEquation: (gl, args) => {
3796
+ blend: (gl2, value) => value ? gl2.enable(GL.BLEND) : gl2.disable(GL.BLEND),
3797
+ blendColor: (gl2, value) => gl2.blendColor(...value),
3798
+ blendEquation: (gl2, args) => {
3756
3799
  const separateModes = typeof args === "number" ? [args, args] : args;
3757
- gl.blendEquationSeparate(...separateModes);
3800
+ gl2.blendEquationSeparate(...separateModes);
3758
3801
  },
3759
- blendFunc: (gl, args) => {
3802
+ blendFunc: (gl2, args) => {
3760
3803
  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) => {
3804
+ gl2.blendFuncSeparate(...separateFuncs);
3805
+ },
3806
+ clearColor: (gl2, value) => gl2.clearColor(...value),
3807
+ clearDepth: (gl2, value) => gl2.clearDepth(value),
3808
+ clearStencil: (gl2, value) => gl2.clearStencil(value),
3809
+ colorMask: (gl2, value) => gl2.colorMask(...value),
3810
+ cull: (gl2, value) => value ? gl2.enable(GL.CULL_FACE) : gl2.disable(GL.CULL_FACE),
3811
+ cullFace: (gl2, value) => gl2.cullFace(value),
3812
+ depthTest: (gl2, value) => value ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST),
3813
+ depthFunc: (gl2, value) => gl2.depthFunc(value),
3814
+ depthMask: (gl2, value) => gl2.depthMask(value),
3815
+ depthRange: (gl2, value) => gl2.depthRange(...value),
3816
+ dither: (gl2, value) => value ? gl2.enable(GL.DITHER) : gl2.disable(GL.DITHER),
3817
+ derivativeHint: (gl2, value) => {
3818
+ gl2.hint(GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
3819
+ },
3820
+ frontFace: (gl2, value) => gl2.frontFace(value),
3821
+ mipmapHint: (gl2, value) => gl2.hint(GL.GENERATE_MIPMAP_HINT, value),
3822
+ lineWidth: (gl2, value) => gl2.lineWidth(value),
3823
+ polygonOffsetFill: (gl2, value) => value ? gl2.enable(GL.POLYGON_OFFSET_FILL) : gl2.disable(GL.POLYGON_OFFSET_FILL),
3824
+ polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
3825
+ sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
3826
+ scissorTest: (gl2, value) => value ? gl2.enable(GL.SCISSOR_TEST) : gl2.disable(GL.SCISSOR_TEST),
3827
+ scissor: (gl2, value) => gl2.scissor(...value),
3828
+ stencilTest: (gl2, value) => value ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST),
3829
+ stencilMask: (gl2, value) => {
3787
3830
  value = isArray(value) ? value : [value, value];
3788
3831
  const [mask, backMask] = value;
3789
- gl.stencilMaskSeparate(GL.FRONT, mask);
3790
- gl.stencilMaskSeparate(GL.BACK, backMask);
3832
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
3833
+ gl2.stencilMaskSeparate(GL.BACK, backMask);
3791
3834
  },
3792
- stencilFunc: (gl, args) => {
3835
+ stencilFunc: (gl2, args) => {
3793
3836
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3794
3837
  const [func, ref, mask, backFunc, backRef, backMask] = args;
3795
- gl.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3796
- gl.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3838
+ gl2.stencilFuncSeparate(GL.FRONT, func, ref, mask);
3839
+ gl2.stencilFuncSeparate(GL.BACK, backFunc, backRef, backMask);
3797
3840
  },
3798
- stencilOp: (gl, args) => {
3841
+ stencilOp: (gl2, args) => {
3799
3842
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
3800
3843
  const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
3801
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3802
- gl.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3844
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
3845
+ gl2.stencilOpSeparate(GL.BACK, backSfail, backDpfail, backDppass);
3803
3846
  },
3804
- viewport: (gl, value) => gl.viewport(...value)
3847
+ viewport: (gl2, value) => gl2.viewport(...value)
3805
3848
  };
3806
3849
  function getValue(glEnum, values, cache2) {
3807
3850
  return values[glEnum] !== void 0 ? values[glEnum] : cache2[glEnum];
3808
3851
  }
3809
3852
  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))
3853
+ blendEquation: (gl2, values, cache2) => gl2.blendEquationSeparate(getValue(GL.BLEND_EQUATION_RGB, values, cache2), getValue(GL.BLEND_EQUATION_ALPHA, values, cache2)),
3854
+ 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)),
3855
+ polygonOffset: (gl2, values, cache2) => gl2.polygonOffset(getValue(GL.POLYGON_OFFSET_FACTOR, values, cache2), getValue(GL.POLYGON_OFFSET_UNITS, values, cache2)),
3856
+ sampleCoverage: (gl2, values, cache2) => gl2.sampleCoverage(getValue(GL.SAMPLE_COVERAGE_VALUE, values, cache2), getValue(GL.SAMPLE_COVERAGE_INVERT, values, cache2)),
3857
+ 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)),
3858
+ 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)),
3859
+ 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)),
3860
+ 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
3861
  };
3819
3862
  var GL_HOOKED_SETTERS = {
3820
3863
  // GENERIC SETTERS
@@ -3980,7 +4023,7 @@ var __exports__ = (() => {
3980
4023
  [GL.VIEWPORT]: [x, y, width, height]
3981
4024
  })
3982
4025
  };
3983
- var isEnabled = (gl, key) => gl.isEnabled(key);
4026
+ var isEnabled = (gl2, key) => gl2.isEnabled(key);
3984
4027
  var GL_PARAMETER_GETTERS = {
3985
4028
  [GL.BLEND]: isEnabled,
3986
4029
  [GL.CULL_FACE]: isEnabled,
@@ -4036,7 +4079,7 @@ var __exports__ = (() => {
4036
4079
  // src/context/parameters/unified-parameter-api.ts
4037
4080
  function setParameters(device, parameters) {
4038
4081
  const webglDevice = WebGLDevice.attach(device);
4039
- const gl = webglDevice.gl;
4082
+ const gl2 = webglDevice.gl;
4040
4083
  if (isObjectEmpty2(parameters)) {
4041
4084
  return;
4042
4085
  }
@@ -4048,31 +4091,31 @@ var __exports__ = (() => {
4048
4091
  if (typeof setter === "string") {
4049
4092
  compositeSetters[setter] = true;
4050
4093
  } else {
4051
- setter(gl, parameters[key], glConstant);
4094
+ setter(gl2, parameters[key], glConstant);
4052
4095
  }
4053
4096
  }
4054
4097
  }
4055
- const cache2 = gl.state && gl.state.cache;
4098
+ const cache2 = gl2.state && gl2.state.cache;
4056
4099
  if (cache2) {
4057
4100
  for (const key in compositeSetters) {
4058
4101
  const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
4059
- compositeSetter(gl, parameters, cache2);
4102
+ compositeSetter(gl2, parameters, cache2);
4060
4103
  }
4061
4104
  }
4062
4105
  }
4063
4106
  function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
4064
4107
  const webglDevice = WebGLDevice.attach(device);
4065
- const gl = webglDevice.gl;
4108
+ const gl2 = webglDevice.gl;
4066
4109
  if (typeof parameters === "number") {
4067
4110
  const key = parameters;
4068
4111
  const getter = GL_PARAMETER_GETTERS[key];
4069
- return getter ? getter(gl, key) : gl.getParameter(key);
4112
+ return getter ? getter(gl2, key) : gl2.getParameter(key);
4070
4113
  }
4071
4114
  const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
4072
4115
  const state = {};
4073
4116
  for (const key of parameterKeys) {
4074
4117
  const getter = GL_PARAMETER_GETTERS[key];
4075
- state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
4118
+ state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
4076
4119
  }
4077
4120
  return state;
4078
4121
  }
@@ -4109,15 +4152,15 @@ var __exports__ = (() => {
4109
4152
  program = null;
4110
4153
  stateStack = [];
4111
4154
  enable = true;
4112
- constructor(gl, {
4155
+ constructor(gl2, {
4113
4156
  copyState = false,
4114
4157
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
4115
4158
  log: log3 = () => {
4116
4159
  }
4117
4160
  // Logging function, called when gl parameter change calls are actually issued
4118
4161
  } = {}) {
4119
- this.gl = gl;
4120
- this.cache = copyState ? getParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4162
+ this.gl = gl2;
4163
+ this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
4121
4164
  this.log = log3;
4122
4165
  this._updateCache = this._updateCache.bind(this);
4123
4166
  Object.seal(this);
@@ -4160,53 +4203,53 @@ var __exports__ = (() => {
4160
4203
  };
4161
4204
  }
4162
4205
  };
4163
- function getContextState(gl) {
4164
- return gl.state;
4206
+ function getContextState(gl2) {
4207
+ return gl2.state;
4165
4208
  }
4166
- function trackContextState(gl, options) {
4209
+ function trackContextState(gl2, options) {
4167
4210
  const {
4168
4211
  enable: enable2 = true,
4169
4212
  copyState
4170
4213
  } = options;
4171
4214
  assert2(copyState !== void 0);
4172
- if (!gl.state) {
4173
- gl.state = new GLState(gl, {
4215
+ if (!gl2.state) {
4216
+ gl2.state = new GLState(gl2, {
4174
4217
  copyState
4175
4218
  });
4176
- installProgramSpy(gl);
4219
+ installProgramSpy(gl2);
4177
4220
  for (const key in GL_HOOKED_SETTERS) {
4178
4221
  const setter = GL_HOOKED_SETTERS[key];
4179
- installSetterSpy(gl, key, setter);
4222
+ installSetterSpy(gl2, key, setter);
4180
4223
  }
4181
- installGetterOverride(gl, "getParameter");
4182
- installGetterOverride(gl, "isEnabled");
4224
+ installGetterOverride(gl2, "getParameter");
4225
+ installGetterOverride(gl2, "isEnabled");
4183
4226
  }
4184
- const glState = getContextState(gl);
4227
+ const glState = getContextState(gl2);
4185
4228
  glState.enable = enable2;
4186
- return gl;
4229
+ return gl2;
4187
4230
  }
4188
- function pushContextState(gl) {
4189
- let glState = getContextState(gl);
4231
+ function pushContextState(gl2) {
4232
+ let glState = getContextState(gl2);
4190
4233
  if (!glState) {
4191
- trackContextState(gl, {
4234
+ trackContextState(gl2, {
4192
4235
  copyState: false
4193
4236
  });
4194
- glState = getContextState(gl);
4237
+ glState = getContextState(gl2);
4195
4238
  }
4196
4239
  glState.push();
4197
4240
  }
4198
- function popContextState(gl) {
4199
- const glState = getContextState(gl);
4241
+ function popContextState(gl2) {
4242
+ const glState = getContextState(gl2);
4200
4243
  assert2(glState);
4201
4244
  glState.pop();
4202
4245
  }
4203
- function installGetterOverride(gl, functionName) {
4204
- const originalGetterFunc = gl[functionName].bind(gl);
4205
- gl[functionName] = function get(pname) {
4246
+ function installGetterOverride(gl2, functionName) {
4247
+ const originalGetterFunc = gl2[functionName].bind(gl2);
4248
+ gl2[functionName] = function get(pname) {
4206
4249
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
4207
4250
  return originalGetterFunc(pname);
4208
4251
  }
4209
- const glState = getContextState(gl);
4252
+ const glState = getContextState(gl2);
4210
4253
  if (!(pname in glState.cache)) {
4211
4254
  glState.cache[pname] = originalGetterFunc(pname);
4212
4255
  }
@@ -4218,18 +4261,18 @@ var __exports__ = (() => {
4218
4261
  originalGetterFunc(pname)
4219
4262
  );
4220
4263
  };
4221
- Object.defineProperty(gl[functionName], "name", {
4264
+ Object.defineProperty(gl2[functionName], "name", {
4222
4265
  value: `${functionName}-from-cache`,
4223
4266
  configurable: false
4224
4267
  });
4225
4268
  }
4226
- function installSetterSpy(gl, functionName, setter) {
4227
- if (!gl[functionName]) {
4269
+ function installSetterSpy(gl2, functionName, setter) {
4270
+ if (!gl2[functionName]) {
4228
4271
  return;
4229
4272
  }
4230
- const originalSetterFunc = gl[functionName].bind(gl);
4231
- gl[functionName] = function set(...params) {
4232
- const glState = getContextState(gl);
4273
+ const originalSetterFunc = gl2[functionName].bind(gl2);
4274
+ gl2[functionName] = function set(...params) {
4275
+ const glState = getContextState(gl2);
4233
4276
  const {
4234
4277
  valueChanged,
4235
4278
  oldValue
@@ -4239,15 +4282,15 @@ var __exports__ = (() => {
4239
4282
  }
4240
4283
  return oldValue;
4241
4284
  };
4242
- Object.defineProperty(gl[functionName], "name", {
4285
+ Object.defineProperty(gl2[functionName], "name", {
4243
4286
  value: `${functionName}-to-cache`,
4244
4287
  configurable: false
4245
4288
  });
4246
4289
  }
4247
- function installProgramSpy(gl) {
4248
- const originalUseProgram = gl.useProgram.bind(gl);
4249
- gl.useProgram = function useProgramLuma(handle) {
4250
- const glState = getContextState(gl);
4290
+ function installProgramSpy(gl2) {
4291
+ const originalUseProgram = gl2.useProgram.bind(gl2);
4292
+ gl2.useProgram = function useProgramLuma(handle) {
4293
+ const glState = getContextState(gl2);
4251
4294
  if (glState.program !== handle) {
4252
4295
  originalUseProgram(handle);
4253
4296
  glState.program = handle;
@@ -4276,7 +4319,7 @@ var __exports__ = (() => {
4276
4319
  let errorMessage = null;
4277
4320
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
4278
4321
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
4279
- let gl = null;
4322
+ let gl2 = null;
4280
4323
  if (props.type === "webgl2") {
4281
4324
  props = {
4282
4325
  ...props,
@@ -4289,14 +4332,14 @@ var __exports__ = (() => {
4289
4332
  webgl2: false
4290
4333
  };
4291
4334
  }
4292
- if (!gl && props.webgl2) {
4293
- gl = canvas.getContext("webgl2", props);
4335
+ if (!gl2 && props.webgl2) {
4336
+ gl2 = canvas.getContext("webgl2", props);
4294
4337
  }
4295
- if (!gl && props.webgl1) {
4296
- gl = canvas.getContext("webgl", props);
4338
+ if (!gl2 && props.webgl1) {
4339
+ gl2 = canvas.getContext("webgl", props);
4297
4340
  }
4298
4341
  canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
4299
- if (!gl) {
4342
+ if (!gl2) {
4300
4343
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
4301
4344
  }
4302
4345
  if (props.onContextLost) {
@@ -4311,28 +4354,28 @@ var __exports__ = (() => {
4311
4354
  } = props;
4312
4355
  canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
4313
4356
  }
4314
- return gl;
4357
+ return gl2;
4315
4358
  }
4316
4359
 
4317
4360
  // 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);
4361
+ function getDeviceInfo(gl2) {
4362
+ const vendorMasked = gl2.getParameter(GL.VENDOR);
4363
+ const rendererMasked = gl2.getParameter(GL.RENDERER);
4364
+ const ext = gl2.getExtension("WEBGL_debug_renderer_info");
4365
+ const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : GL.VENDOR);
4366
+ const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : GL.RENDERER);
4324
4367
  const vendor = vendorUnmasked || vendorMasked;
4325
4368
  const renderer = rendererUnmasked || rendererMasked;
4326
4369
  const gpu = identifyGPUVendor(vendor, renderer);
4327
4370
  return {
4328
- type: isWebGL2(gl) ? "webgl2" : "webgl",
4371
+ type: isWebGL2(gl2) ? "webgl2" : "webgl",
4329
4372
  gpu,
4330
4373
  vendor: vendorUnmasked || vendorMasked,
4331
4374
  renderer: rendererUnmasked || rendererMasked,
4332
- version: gl.getParameter(GL.VERSION),
4375
+ version: gl2.getParameter(GL.VERSION),
4333
4376
  shadingLanguages: ["glsl"],
4334
4377
  shadingLanguageVersions: {
4335
- "glsl": gl.getParameter(GL.SHADING_LANGUAGE_VERSION)
4378
+ "glsl": gl2.getParameter(GL.SHADING_LANGUAGE_VERSION)
4336
4379
  }
4337
4380
  };
4338
4381
  }
@@ -4384,38 +4427,38 @@ var __exports__ = (() => {
4384
4427
  var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
4385
4428
  var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
4386
4429
  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));
4430
+ var checkExtension = (gl2, extension) => gl2.getExtension(extension);
4431
+ var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
4389
4432
  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"),
4433
+ "texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
4434
+ "texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
4435
+ "texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
4436
+ "texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
4437
+ "texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
4438
+ "texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
4439
+ "texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
4440
+ "texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
4441
+ "texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
4442
+ "texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
4400
4443
  // [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]),
4444
+ "texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
4445
+ "texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
4446
+ "texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
4404
4447
  // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
4405
4448
  // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
4406
4449
  // '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])
4450
+ "texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
4451
+ "texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
4452
+ "texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
4453
+ "texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
4454
+ "texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
4412
4455
  };
4413
- function checkTextureFeature(gl, feature) {
4414
- return TEXTURE_FEATURE_CHECKS[feature]?.(gl) || false;
4456
+ function checkTextureFeature(gl2, feature) {
4457
+ return TEXTURE_FEATURE_CHECKS[feature]?.(gl2) || false;
4415
4458
  }
4416
- function getTextureFeatures(gl) {
4459
+ function getTextureFeatures(gl2) {
4417
4460
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
4418
- return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
4461
+ return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
4419
4462
  }
4420
4463
  var TEXTURE_FORMATS = {
4421
4464
  // Unsized formats that leave the precision up to the driver.
@@ -5155,23 +5198,23 @@ var __exports__ = (() => {
5155
5198
  [GL.BYTE]: 1,
5156
5199
  [GL.UNSIGNED_BYTE]: 1
5157
5200
  };
5158
- function isTextureFormatSupported(gl, formatOrGL) {
5201
+ function isTextureFormatSupported(gl2, formatOrGL) {
5159
5202
  const format = convertGLToTextureFormat(formatOrGL);
5160
5203
  const info = TEXTURE_FORMATS[format];
5161
5204
  if (!info) {
5162
5205
  return false;
5163
5206
  }
5164
- if (isWebGL2(gl) ? info.gl === void 0 : info.gl1 === void 0) {
5207
+ if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
5165
5208
  return false;
5166
5209
  }
5167
- const extension = info.x || (isWebGL2(gl) ? info.gl2ext || info.gl1ext : info.gl1ext);
5210
+ const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
5168
5211
  if (extension) {
5169
- return Boolean(gl.getExtension(extension));
5212
+ return Boolean(gl2.getExtension(extension));
5170
5213
  }
5171
5214
  return true;
5172
5215
  }
5173
- function isRenderbufferFormatSupported(gl, format) {
5174
- return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5216
+ function isRenderbufferFormatSupported(gl2, format) {
5217
+ return isTextureFormatSupported(gl2, format) && TEXTURE_FORMATS[format]?.renderbuffer;
5175
5218
  }
5176
5219
  function convertGLToTextureFormat(format) {
5177
5220
  if (typeof format === "string") {
@@ -5191,9 +5234,9 @@ var __exports__ = (() => {
5191
5234
  }
5192
5235
  return webglFormat;
5193
5236
  }
5194
- function isTextureFormatFilterable(gl, formatOrGL) {
5237
+ function isTextureFormatFilterable(gl2, formatOrGL) {
5195
5238
  const format = convertGLToTextureFormat(formatOrGL);
5196
- if (!isTextureFormatSupported(gl, format)) {
5239
+ if (!isTextureFormatSupported(gl2, format)) {
5197
5240
  return false;
5198
5241
  }
5199
5242
  try {
@@ -5205,16 +5248,16 @@ var __exports__ = (() => {
5205
5248
  return false;
5206
5249
  }
5207
5250
  if (format.endsWith("32float")) {
5208
- return Boolean(gl.getExtension("OES_texture_float_linear"));
5251
+ return Boolean(gl2.getExtension("OES_texture_float_linear"));
5209
5252
  }
5210
5253
  if (format.endsWith("16float")) {
5211
- return Boolean(gl.getExtension("OES_texture_half_float_linear"));
5254
+ return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
5212
5255
  }
5213
5256
  return true;
5214
5257
  }
5215
- function isTextureFormatRenderable(gl, formatOrGL) {
5258
+ function isTextureFormatRenderable(gl2, formatOrGL) {
5216
5259
  const format = convertGLToTextureFormat(formatOrGL);
5217
- if (!isTextureFormatSupported(gl, format)) {
5260
+ if (!isTextureFormatSupported(gl2, format)) {
5218
5261
  return false;
5219
5262
  }
5220
5263
  if (typeof format === "number") {
@@ -5241,27 +5284,27 @@ var __exports__ = (() => {
5241
5284
  }
5242
5285
  return info.attachment;
5243
5286
  }
5244
- function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5287
+ function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
5245
5288
  let texture = null;
5246
5289
  let framebuffer = null;
5247
5290
  try {
5248
- texture = gl.createTexture();
5249
- gl.bindTexture(GL.TEXTURE_2D, texture);
5291
+ texture = gl2.createTexture();
5292
+ gl2.bindTexture(GL.TEXTURE_2D, texture);
5250
5293
  const level = 0;
5251
5294
  const width = 1;
5252
5295
  const height = 1;
5253
5296
  const border = 0;
5254
5297
  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);
5298
+ gl2.texImage2D(gl2.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
5299
+ framebuffer = gl2.createFramebuffer();
5300
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
5301
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
5302
+ const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
5303
+ gl2.bindTexture(GL.TEXTURE_2D, null);
5261
5304
  return status;
5262
5305
  } finally {
5263
- gl.deleteTexture(texture);
5264
- gl.deleteFramebuffer(framebuffer);
5306
+ gl2.deleteTexture(texture);
5307
+ gl2.deleteFramebuffer(framebuffer);
5265
5308
  }
5266
5309
  }
5267
5310
  function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
@@ -5312,52 +5355,52 @@ var __exports__ = (() => {
5312
5355
  }
5313
5356
 
5314
5357
  // src/adapter/device-helpers/device-features.ts
5315
- function getDeviceFeatures(gl) {
5316
- const features = getWebGLFeatures(gl);
5317
- for (const textureFeature of getTextureFeatures(gl)) {
5358
+ function getDeviceFeatures(gl2) {
5359
+ const features = getWebGLFeatures(gl2);
5360
+ for (const textureFeature of getTextureFeatures(gl2)) {
5318
5361
  features.add(textureFeature);
5319
5362
  }
5320
5363
  return features;
5321
5364
  }
5322
- function getWebGLFeatures(gl) {
5323
- gl.getExtension("EXT_color_buffer_float");
5324
- gl.getExtension("WEBGL_color_buffer_float");
5325
- gl.getExtension("EXT_float_blend");
5365
+ function getWebGLFeatures(gl2) {
5366
+ gl2.getExtension("EXT_color_buffer_float");
5367
+ gl2.getExtension("WEBGL_color_buffer_float");
5368
+ gl2.getExtension("EXT_float_blend");
5326
5369
  const features = /* @__PURE__ */ new Set();
5327
5370
  for (const feature of Object.keys(WEBGL_FEATURES)) {
5328
- if (isFeatureSupported(gl, feature)) {
5371
+ if (isFeatureSupported(gl2, feature)) {
5329
5372
  features.add(feature);
5330
5373
  }
5331
5374
  }
5332
5375
  return features;
5333
5376
  }
5334
- function isFeatureSupported(gl, feature) {
5377
+ function isFeatureSupported(gl2, feature) {
5335
5378
  const featureInfo = WEBGL_FEATURES[feature];
5336
5379
  if (!featureInfo) {
5337
5380
  return false;
5338
5381
  }
5339
5382
  const [webgl1Feature, webgl2Feature] = featureInfo || [];
5340
- const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
5383
+ const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
5341
5384
  if (typeof featureDefinition === "boolean") {
5342
5385
  return featureDefinition;
5343
5386
  }
5344
5387
  switch (feature) {
5345
5388
  case "texture-renderable-rgba32float-webgl":
5346
- return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl);
5389
+ return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
5347
5390
  case "glsl-derivatives":
5348
- return canCompileGLSLExtension(gl, featureDefinition);
5391
+ return canCompileGLSLExtension(gl2, featureDefinition);
5349
5392
  case "glsl-frag-data":
5350
- return canCompileGLSLExtension(gl, featureDefinition, {
5393
+ return canCompileGLSLExtension(gl2, featureDefinition, {
5351
5394
  behavior: "require"
5352
5395
  });
5353
5396
  case "glsl-frag-depth":
5354
- return canCompileGLSLExtension(gl, featureDefinition);
5397
+ return canCompileGLSLExtension(gl2, featureDefinition);
5355
5398
  default:
5356
- return Boolean(gl.getExtension(featureDefinition));
5399
+ return Boolean(gl2.getExtension(featureDefinition));
5357
5400
  }
5358
5401
  }
5359
5402
  var compiledGLSLExtensions = {};
5360
- function canCompileGLSLExtension(gl, extensionName, opts = {}) {
5403
+ function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
5361
5404
  if (!isOldIE(opts)) {
5362
5405
  return true;
5363
5406
  }
@@ -5367,14 +5410,14 @@ var __exports__ = (() => {
5367
5410
  const behavior = opts.behavior || "enable";
5368
5411
  const source = `#extension GL_${extensionName} : ${behavior}
5369
5412
  void main(void) {}`;
5370
- const shader = gl.createShader(gl.VERTEX_SHADER);
5413
+ const shader = gl2.createShader(gl2.VERTEX_SHADER);
5371
5414
  if (!shader) {
5372
5415
  throw new Error("shader");
5373
5416
  }
5374
- gl.shaderSource(shader, source);
5375
- gl.compileShader(shader);
5376
- const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
5377
- gl.deleteShader(shader);
5417
+ gl2.shaderSource(shader, source);
5418
+ gl2.compileShader(shader);
5419
+ const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
5420
+ gl2.deleteShader(shader);
5378
5421
  compiledGLSLExtensions[extensionName] = canCompile;
5379
5422
  return canCompile;
5380
5423
  }
@@ -5411,38 +5454,38 @@ void main(void) {}`;
5411
5454
  };
5412
5455
 
5413
5456
  // src/adapter/device-helpers/device-limits.ts
5414
- function getDeviceLimits(gl) {
5415
- const gl2 = getWebGL2Context(gl);
5457
+ function getDeviceLimits(gl2) {
5458
+ const gl22 = getWebGL2Context(gl2);
5416
5459
  return {
5417
5460
  maxTextureDimension1D: 0,
5418
5461
  // 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,
5462
+ maxTextureDimension2D: gl2.getParameter(GL.MAX_TEXTURE_SIZE),
5463
+ maxTextureDimension3D: gl22 ? gl22.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
5464
+ maxTextureArrayLayers: gl22 ? gl22.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
5422
5465
  maxBindGroups: 1,
5423
5466
  // TBD
5424
5467
  maxDynamicUniformBuffersPerPipelineLayout: 0,
5425
5468
  // TBD
5426
5469
  maxDynamicStorageBuffersPerPipelineLayout: 0,
5427
5470
  // TBD
5428
- maxSampledTexturesPerShaderStage: gl.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5471
+ maxSampledTexturesPerShaderStage: gl2.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
5429
5472
  // TBD
5430
- maxSamplersPerShaderStage: gl.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5473
+ maxSamplersPerShaderStage: gl2.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
5431
5474
  maxStorageBuffersPerShaderStage: 0,
5432
5475
  // TBD
5433
5476
  maxStorageTexturesPerShaderStage: 0,
5434
5477
  // TBD
5435
- maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5436
- maxUniformBufferBindingSize: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5478
+ maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
5479
+ maxUniformBufferBindingSize: gl22 ? gl22.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
5437
5480
  maxStorageBufferBindingSize: 0,
5438
- minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5481
+ minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
5439
5482
  minStorageBufferOffsetAlignment: 0,
5440
5483
  // TBD
5441
5484
  maxVertexBuffers: 0,
5442
- maxVertexAttributes: gl.getParameter(GL.MAX_VERTEX_ATTRIBS),
5485
+ maxVertexAttributes: gl2.getParameter(GL.MAX_VERTEX_ATTRIBS),
5443
5486
  maxVertexBufferArrayStride: 2048,
5444
5487
  // TBD, this is just the default value from WebGPU
5445
- maxInterStageShaderComponents: gl2 ? gl2.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5488
+ maxInterStageShaderComponents: gl22 ? gl22.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
5446
5489
  maxComputeWorkgroupStorageSize: 0,
5447
5490
  // WebGL does not support compute shaders
5448
5491
  maxComputeInvocationsPerWorkgroup: 0,
@@ -5457,13 +5500,13 @@ void main(void) {}`;
5457
5500
  // WebGL does not support compute shaders
5458
5501
  };
5459
5502
  }
5460
- function getWebGLLimits(gl) {
5461
- const gl2 = getWebGL2Context(gl);
5503
+ function getWebGLLimits(gl2) {
5504
+ const gl22 = getWebGL2Context(gl2);
5462
5505
  function get(pname) {
5463
- return gl.getParameter(pname);
5506
+ return gl2.getParameter(pname);
5464
5507
  }
5465
5508
  function get2(pname, defaultValue) {
5466
- return gl2 ? gl2.getParameter(pname) : defaultValue || 0;
5509
+ return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
5467
5510
  }
5468
5511
  return {
5469
5512
  [GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
@@ -5556,24 +5599,24 @@ void main(void) {}`;
5556
5599
  // src/context/state-tracker/with-parameters.ts
5557
5600
  function withParameters(device, parameters, func) {
5558
5601
  const webglDevice = WebGLDevice.attach(device);
5559
- const gl = webglDevice.gl;
5602
+ const gl2 = webglDevice.gl;
5560
5603
  if (isObjectEmpty3(parameters)) {
5561
5604
  return func(device);
5562
5605
  }
5563
5606
  const {
5564
5607
  nocatch = true
5565
5608
  } = parameters;
5566
- pushContextState(gl);
5567
- setParameters(gl, parameters);
5609
+ pushContextState(gl2);
5610
+ setParameters(gl2, parameters);
5568
5611
  let value;
5569
5612
  if (nocatch) {
5570
- value = func(gl);
5571
- popContextState(gl);
5613
+ value = func(gl2);
5614
+ popContextState(gl2);
5572
5615
  } else {
5573
5616
  try {
5574
- value = func(gl);
5617
+ value = func(gl2);
5575
5618
  } finally {
5576
- popContextState(gl);
5619
+ popContextState(gl2);
5577
5620
  }
5578
5621
  }
5579
5622
  return value;
@@ -5613,43 +5656,43 @@ void main(void) {}`;
5613
5656
  function setDeviceParameters(device, parameters) {
5614
5657
  const webglDevice = WebGLDevice.attach(device);
5615
5658
  const {
5616
- gl
5659
+ gl: gl2
5617
5660
  } = webglDevice;
5618
5661
  if (parameters.cullMode) {
5619
5662
  switch (parameters.cullMode) {
5620
5663
  case "none":
5621
- gl.disable(GL.CULL_FACE);
5664
+ gl2.disable(GL.CULL_FACE);
5622
5665
  break;
5623
5666
  case "front":
5624
- gl.enable(GL.CULL_FACE);
5625
- gl.cullFace(GL.FRONT);
5667
+ gl2.enable(GL.CULL_FACE);
5668
+ gl2.cullFace(GL.FRONT);
5626
5669
  break;
5627
5670
  case "back":
5628
- gl.enable(GL.CULL_FACE);
5629
- gl.cullFace(GL.BACK);
5671
+ gl2.enable(GL.CULL_FACE);
5672
+ gl2.cullFace(GL.BACK);
5630
5673
  break;
5631
5674
  }
5632
5675
  }
5633
5676
  if (parameters.frontFace) {
5634
- gl.frontFace(map("frontFace", parameters.frontFace, {
5677
+ gl2.frontFace(map("frontFace", parameters.frontFace, {
5635
5678
  ccw: GL.CCW,
5636
5679
  cw: GL.CW
5637
5680
  }));
5638
5681
  }
5639
5682
  if (parameters.depthBias !== void 0) {
5640
- gl.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5683
+ gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
5641
5684
  }
5642
5685
  if (parameters.depthWriteEnabled !== void 0) {
5643
- gl.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5686
+ gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
5644
5687
  }
5645
5688
  if (parameters.depthCompare) {
5646
- parameters.depthCompare !== "always" ? gl.enable(GL.DEPTH_TEST) : gl.disable(GL.DEPTH_TEST);
5647
- gl.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5689
+ parameters.depthCompare !== "always" ? gl2.enable(GL.DEPTH_TEST) : gl2.disable(GL.DEPTH_TEST);
5690
+ gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
5648
5691
  }
5649
5692
  if (parameters.stencilWriteMask) {
5650
5693
  const mask = parameters.stencilWriteMask;
5651
- gl.stencilMaskSeparate(GL.FRONT, mask);
5652
- gl.stencilMaskSeparate(GL.BACK, mask);
5694
+ gl2.stencilMaskSeparate(GL.FRONT, mask);
5695
+ gl2.stencilMaskSeparate(GL.BACK, mask);
5653
5696
  }
5654
5697
  if (parameters.stencilReadMask) {
5655
5698
  log.warn("stencilReadMask not supported under WebGL");
@@ -5657,16 +5700,16 @@ void main(void) {}`;
5657
5700
  if (parameters.stencilCompare) {
5658
5701
  const mask = parameters.stencilReadMask || 4294967295;
5659
5702
  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);
5703
+ parameters.stencilCompare !== "always" ? gl2.enable(GL.STENCIL_TEST) : gl2.disable(GL.STENCIL_TEST);
5704
+ gl2.stencilFuncSeparate(GL.FRONT, glValue, 0, mask);
5705
+ gl2.stencilFuncSeparate(GL.BACK, glValue, 0, mask);
5663
5706
  }
5664
5707
  if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
5665
5708
  const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
5666
5709
  const sfail = convertStencilOperation("stencilFailOperation", parameters.stencilFailOperation);
5667
5710
  const dpfail = convertStencilOperation("stencilDepthFailOperation", parameters.stencilDepthFailOperation);
5668
- gl.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5669
- gl.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5711
+ gl2.stencilOpSeparate(GL.FRONT, sfail, dpfail, dppass);
5712
+ gl2.stencilOpSeparate(GL.BACK, sfail, dpfail, dppass);
5670
5713
  }
5671
5714
  }
5672
5715
  function convertCompareFunction(parameter, value) {
@@ -6259,9 +6302,9 @@ void main(void) {}`;
6259
6302
  height
6260
6303
  }));
6261
6304
  const {
6262
- gl
6305
+ gl: gl2
6263
6306
  } = this;
6264
- gl.bindTexture(this.target, this.handle);
6307
+ gl2.bindTexture(this.target, this.handle);
6265
6308
  let dataType = null;
6266
6309
  ({
6267
6310
  data,
@@ -6270,14 +6313,14 @@ void main(void) {}`;
6270
6313
  data,
6271
6314
  compressed
6272
6315
  }));
6273
- let gl2;
6316
+ let gl22;
6274
6317
  withParameters(this.gl, parameters, () => {
6275
6318
  switch (dataType) {
6276
6319
  case "null":
6277
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6320
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6278
6321
  break;
6279
6322
  case "typed-array":
6280
- gl.texImage2D(
6323
+ gl2.texImage2D(
6281
6324
  target,
6282
6325
  level,
6283
6326
  glFormat,
@@ -6293,21 +6336,21 @@ void main(void) {}`;
6293
6336
  );
6294
6337
  break;
6295
6338
  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);
6339
+ gl22 = this.device.assertWebGL2();
6340
+ gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
6341
+ gl22.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
6342
+ gl22.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
6300
6343
  break;
6301
6344
  case "browser-object":
6302
6345
  if (this.device.isWebGL2) {
6303
- gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6346
+ gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
6304
6347
  } else {
6305
- gl.texImage2D(target, level, glFormat, dataFormat, type, data);
6348
+ gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
6306
6349
  }
6307
6350
  break;
6308
6351
  case "compressed":
6309
6352
  for (const [levelIndex, levelData] of data.entries()) {
6310
- gl.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6353
+ gl2.compressedTexImage2D(target, levelIndex, levelData.format, levelData.width, levelData.height, 0, levelData.data);
6311
6354
  }
6312
6355
  break;
6313
6356
  default:
@@ -6411,24 +6454,24 @@ void main(void) {}`;
6411
6454
  }
6412
6455
  bind(textureUnit = this.textureUnit) {
6413
6456
  const {
6414
- gl
6457
+ gl: gl2
6415
6458
  } = this;
6416
6459
  if (textureUnit !== void 0) {
6417
6460
  this.textureUnit = textureUnit;
6418
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6461
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6419
6462
  }
6420
- gl.bindTexture(this.target, this.handle);
6463
+ gl2.bindTexture(this.target, this.handle);
6421
6464
  return textureUnit;
6422
6465
  }
6423
6466
  unbind(textureUnit = this.textureUnit) {
6424
6467
  const {
6425
- gl
6468
+ gl: gl2
6426
6469
  } = this;
6427
6470
  if (textureUnit !== void 0) {
6428
6471
  this.textureUnit = textureUnit;
6429
- gl.activeTexture(gl.TEXTURE0 + textureUnit);
6472
+ gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
6430
6473
  }
6431
- gl.bindTexture(this.target, null);
6474
+ gl2.bindTexture(this.target, null);
6432
6475
  return textureUnit;
6433
6476
  }
6434
6477
  // PRIVATE METHODS
@@ -6550,7 +6593,7 @@ void main(void) {}`;
6550
6593
  /* eslint-disable max-statements, max-len */
6551
6594
  async setCubeMapImageData(options) {
6552
6595
  const {
6553
- gl
6596
+ gl: gl2
6554
6597
  } = this;
6555
6598
  const {
6556
6599
  width,
@@ -6572,9 +6615,9 @@ void main(void) {}`;
6572
6615
  }
6573
6616
  resolvedFaces[index].forEach((image, lodLevel) => {
6574
6617
  if (width && height) {
6575
- gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6618
+ gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
6576
6619
  } else {
6577
- gl.texImage2D(face, lodLevel, format, format, type, image);
6620
+ gl2.texImage2D(face, lodLevel, format, format, type, image);
6578
6621
  }
6579
6622
  });
6580
6623
  });
@@ -6593,7 +6636,7 @@ void main(void) {}`;
6593
6636
  // generateMipmap = false // TODO
6594
6637
  } = options;
6595
6638
  const {
6596
- gl
6639
+ gl: gl2
6597
6640
  } = this;
6598
6641
  const imageData = pixels || data;
6599
6642
  this.bind();
@@ -6604,9 +6647,9 @@ void main(void) {}`;
6604
6647
  pixels: resolvedImageData
6605
6648
  })));
6606
6649
  } else if (this.width || this.height) {
6607
- gl.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6650
+ gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
6608
6651
  } else {
6609
- gl.texImage2D(face, 0, format, format, type, imageData);
6652
+ gl2.texImage2D(face, 0, format, format, type, imageData);
6610
6653
  }
6611
6654
  return this;
6612
6655
  }
@@ -6738,7 +6781,7 @@ void main(void) {}`;
6738
6781
  }
6739
6782
 
6740
6783
  // src/adapter/objects/constants-to-keys.ts
6741
- function getKeyValue(gl, name) {
6784
+ function getKeyValue(gl2, name) {
6742
6785
  if (typeof name !== "string") {
6743
6786
  return name;
6744
6787
  }
@@ -6747,7 +6790,7 @@ void main(void) {}`;
6747
6790
  return number;
6748
6791
  }
6749
6792
  name = name.replace(/^.*\./, "");
6750
- const value = gl[name];
6793
+ const value = gl2[name];
6751
6794
  assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
6752
6795
  return value;
6753
6796
  }
@@ -6761,13 +6804,13 @@ void main(void) {}`;
6761
6804
  constructor(device, props, defaultProps) {
6762
6805
  super(device, props, defaultProps);
6763
6806
  this.device = WebGLDevice.attach(device);
6764
- const gl = this.device.gl;
6765
- assertWebGLContext(gl);
6807
+ const gl2 = this.device.gl;
6808
+ assertWebGLContext(gl2);
6766
6809
  const {
6767
6810
  id
6768
6811
  } = props || {};
6769
- this.gl = gl;
6770
- this.gl2 = gl;
6812
+ this.gl = gl2;
6813
+ this.gl2 = gl2;
6771
6814
  this.id = id || uid(this.constructor.name);
6772
6815
  this._handle = props?.handle;
6773
6816
  if (this._handle === void 0) {
@@ -7085,12 +7128,12 @@ void main(void) {}`;
7085
7128
  /** Check the status */
7086
7129
  _checkStatus() {
7087
7130
  const {
7088
- gl
7131
+ gl: gl2
7089
7132
  } = 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) {
7133
+ const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
7134
+ const status = gl2.checkFramebufferStatus(GL.FRAMEBUFFER);
7135
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
7136
+ if (status !== gl2.FRAMEBUFFER_COMPLETE) {
7094
7137
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
7095
7138
  }
7096
7139
  }
@@ -7161,27 +7204,27 @@ void main(void) {}`;
7161
7204
  */
7162
7205
  _attachTexture(attachment, texture, layer, level) {
7163
7206
  const {
7164
- gl,
7165
- gl2
7207
+ gl: gl2,
7208
+ gl2: gl22
7166
7209
  } = this.device;
7167
- gl.bindTexture(texture.target, texture.handle);
7210
+ gl2.bindTexture(texture.target, texture.handle);
7168
7211
  switch (texture.target) {
7169
7212
  case GL.TEXTURE_2D_ARRAY:
7170
7213
  case GL.TEXTURE_3D:
7171
7214
  this.device.assertWebGL2();
7172
- gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7215
+ gl22?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
7173
7216
  break;
7174
7217
  case GL.TEXTURE_CUBE_MAP:
7175
7218
  const face = mapIndexToCubeMapFace(layer);
7176
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7219
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, face, texture.handle, level);
7177
7220
  break;
7178
7221
  case GL.TEXTURE_2D:
7179
- gl.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7222
+ gl2.framebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, texture.handle, level);
7180
7223
  break;
7181
7224
  default:
7182
7225
  assert2(false, "Illegal texture type");
7183
7226
  }
7184
- gl.bindTexture(texture.target, null);
7227
+ gl2.bindTexture(texture.target, null);
7185
7228
  }
7186
7229
  };
7187
7230
  function mapIndexToCubeMapFace(layer) {
@@ -7245,6 +7288,7 @@ void main(void) {}`;
7245
7288
  */
7246
7289
  resize(options) {
7247
7290
  if (this.canvas) {
7291
+ const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
7248
7292
  this.setDevicePixelRatio(devicePixelRatio, options);
7249
7293
  return;
7250
7294
  }
@@ -7318,9 +7362,9 @@ void main(void) {}`;
7318
7362
 
7319
7363
  // src/context/debug/webgl-developer-tools.ts
7320
7364
  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;
7365
+ function getContextData2(gl2) {
7366
+ gl2.luma = gl2.luma || {};
7367
+ return gl2.luma;
7324
7368
  }
7325
7369
  async function loadWebGLDeveloperTools() {
7326
7370
  if (!globalThis.WebGLDebugUtils) {
@@ -7329,30 +7373,30 @@ void main(void) {}`;
7329
7373
  await loadScript(WEBGL_DEBUG_CDN_URL);
7330
7374
  }
7331
7375
  }
7332
- function makeDebugContext(gl, props = {}) {
7333
- if (!gl) {
7376
+ function makeDebugContext(gl2, props = {}) {
7377
+ if (!gl2) {
7334
7378
  return null;
7335
7379
  }
7336
- return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
7380
+ return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
7337
7381
  }
7338
- function getRealContext(gl) {
7339
- const data = getContextData2(gl);
7340
- return data.realContext ? data.realContext : gl;
7382
+ function getRealContext(gl2) {
7383
+ const data = getContextData2(gl2);
7384
+ return data.realContext ? data.realContext : gl2;
7341
7385
  }
7342
- function getDebugContext(gl, props) {
7386
+ function getDebugContext(gl2, props) {
7343
7387
  if (!globalThis.WebGLDebugUtils) {
7344
7388
  log.warn("webgl-debug not loaded")();
7345
- return gl;
7389
+ return gl2;
7346
7390
  }
7347
- const data = getContextData2(gl);
7391
+ const data = getContextData2(gl2);
7348
7392
  if (data.debugContext) {
7349
7393
  return data.debugContext;
7350
7394
  }
7351
7395
  globalThis.WebGLDebugUtils.init({
7352
7396
  ...GL,
7353
- ...gl
7397
+ ...gl2
7354
7398
  });
7355
- const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7399
+ const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl2, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
7356
7400
  for (const key in GL) {
7357
7401
  if (!(key in glDebug) && typeof GL[key] === "number") {
7358
7402
  glDebug[key] = GL[key];
@@ -7360,10 +7404,10 @@ void main(void) {}`;
7360
7404
  }
7361
7405
  class WebGLDebugContext {
7362
7406
  }
7363
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
7407
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
7364
7408
  Object.setPrototypeOf(WebGLDebugContext, glDebug);
7365
7409
  const debugContext = Object.create(WebGLDebugContext);
7366
- data.realContext = gl;
7410
+ data.realContext = gl2;
7367
7411
  data.debugContext = debugContext;
7368
7412
  debugContext.debug = true;
7369
7413
  return debugContext;
@@ -7750,15 +7794,15 @@ void main(void) {}`;
7750
7794
  size
7751
7795
  } = options;
7752
7796
  const {
7753
- gl,
7754
- gl2
7797
+ gl: gl2,
7798
+ gl2: gl22
7755
7799
  } = 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);
7800
+ assertWebGL2Context(gl2);
7801
+ gl2.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
7802
+ gl2.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
7803
+ gl22?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
7804
+ gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
7805
+ gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
7762
7806
  this.debugData = null;
7763
7807
  return this;
7764
7808
  }
@@ -8029,13 +8073,13 @@ void main(void) {}`;
8029
8073
  ${source2}`;
8030
8074
  source = addGLSLVersion(source);
8031
8075
  const {
8032
- gl
8076
+ gl: gl2
8033
8077
  } = this.device;
8034
- gl.shaderSource(this.handle, source);
8035
- gl.compileShader(this.handle);
8036
- const compileStatus = gl.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8078
+ gl2.shaderSource(this.handle, source);
8079
+ gl2.compileShader(this.handle);
8080
+ const compileStatus = gl2.getShaderParameter(this.handle, GL.COMPILE_STATUS);
8037
8081
  if (!compileStatus) {
8038
- const shaderLog = gl.getShaderInfoLog(this.handle);
8082
+ const shaderLog = gl2.getShaderInfoLog(this.handle);
8039
8083
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
8040
8084
  const messages = parsedLog.filter((message2) => message2.type === "error");
8041
8085
  const formattedLog = formatCompilerLog(messages, source);
@@ -8270,8 +8314,8 @@ ${formattedLog}`)();
8270
8314
  }
8271
8315
 
8272
8316
  // src/adapter/helpers/get-shader-layout.ts
8273
- function getShaderLayout(gl, program) {
8274
- const programBindings = getProgramBindings(gl, program);
8317
+ function getShaderLayout(gl2, program) {
8318
+ const programBindings = getProgramBindings(gl2, program);
8275
8319
  const shaderLayout = {
8276
8320
  attributes: [],
8277
8321
  bindings: []
@@ -8333,21 +8377,21 @@ ${formattedLog}`)();
8333
8377
  }
8334
8378
  return shaderLayout;
8335
8379
  }
8336
- function getProgramBindings(gl, program) {
8380
+ function getProgramBindings(gl2, program) {
8337
8381
  const config = {
8338
- attributes: readAttributeBindings(gl, program),
8339
- uniforms: readUniformBindings(gl, program),
8340
- uniformBlocks: readUniformBlocks(gl, program),
8341
- varyings: readVaryings(gl, program)
8382
+ attributes: readAttributeBindings(gl2, program),
8383
+ uniforms: readUniformBindings(gl2, program),
8384
+ uniformBlocks: readUniformBlocks(gl2, program),
8385
+ varyings: readVaryings(gl2, program)
8342
8386
  };
8343
8387
  Object.seal(config);
8344
8388
  return config;
8345
8389
  }
8346
- function readAttributeBindings(gl, program) {
8390
+ function readAttributeBindings(gl2, program) {
8347
8391
  const attributes = [];
8348
- const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
8392
+ const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
8349
8393
  for (let index = 0; index < count; index++) {
8350
- const activeInfo = gl.getActiveAttrib(program, index);
8394
+ const activeInfo = gl2.getActiveAttrib(program, index);
8351
8395
  if (!activeInfo) {
8352
8396
  throw new Error("activeInfo");
8353
8397
  }
@@ -8356,7 +8400,7 @@ ${formattedLog}`)();
8356
8400
  type: compositeType,
8357
8401
  size
8358
8402
  } = activeInfo;
8359
- const location = gl.getAttribLocation(program, name);
8403
+ const location = gl2.getAttribLocation(program, name);
8360
8404
  if (location >= 0) {
8361
8405
  const {
8362
8406
  glType,
@@ -8380,15 +8424,15 @@ ${formattedLog}`)();
8380
8424
  attributes.sort((a, b) => a.location - b.location);
8381
8425
  return attributes;
8382
8426
  }
8383
- function readVaryings(gl, program) {
8384
- if (!isWebGL2(gl)) {
8427
+ function readVaryings(gl2, program) {
8428
+ if (!isWebGL2(gl2)) {
8385
8429
  return [];
8386
8430
  }
8387
- const gl2 = gl;
8431
+ const gl22 = gl2;
8388
8432
  const varyings = [];
8389
- const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8433
+ const count = gl2.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);
8390
8434
  for (let location = 0; location < count; location++) {
8391
- const activeInfo = gl2.getTransformFeedbackVarying(program, location);
8435
+ const activeInfo = gl22.getTransformFeedbackVarying(program, location);
8392
8436
  if (!activeInfo) {
8393
8437
  throw new Error("activeInfo");
8394
8438
  }
@@ -8415,11 +8459,11 @@ ${formattedLog}`)();
8415
8459
  varyings.sort((a, b) => a.location - b.location);
8416
8460
  return varyings;
8417
8461
  }
8418
- function readUniformBindings(gl, program) {
8462
+ function readUniformBindings(gl2, program) {
8419
8463
  const uniforms = [];
8420
- const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8464
+ const uniformCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORMS);
8421
8465
  for (let i = 0; i < uniformCount; i++) {
8422
- const activeInfo = gl.getActiveUniform(program, i);
8466
+ const activeInfo = gl2.getActiveUniform(program, i);
8423
8467
  if (!activeInfo) {
8424
8468
  throw new Error("activeInfo");
8425
8469
  }
@@ -8432,7 +8476,7 @@ ${formattedLog}`)();
8432
8476
  name,
8433
8477
  isArray: isArray2
8434
8478
  } = parseUniformName(rawName);
8435
- let webglLocation = gl.getUniformLocation(program, name);
8479
+ let webglLocation = gl2.getUniformLocation(program, name);
8436
8480
  const uniformInfo = {
8437
8481
  // WebGL locations are uniquely typed but just numbers
8438
8482
  location: webglLocation,
@@ -8445,7 +8489,7 @@ ${formattedLog}`)();
8445
8489
  if (uniformInfo.size > 1) {
8446
8490
  for (let j = 0; j < uniformInfo.size; j++) {
8447
8491
  const elementName = `${name}[${j}]`;
8448
- webglLocation = gl.getUniformLocation(program, elementName);
8492
+ webglLocation = gl2.getUniformLocation(program, elementName);
8449
8493
  const arrayElementUniformInfo = {
8450
8494
  ...uniformInfo,
8451
8495
  name: elementName,
@@ -8457,17 +8501,17 @@ ${formattedLog}`)();
8457
8501
  }
8458
8502
  return uniforms;
8459
8503
  }
8460
- function readUniformBlocks(gl, program) {
8461
- if (!isWebGL2(gl)) {
8504
+ function readUniformBlocks(gl2, program) {
8505
+ if (!isWebGL2(gl2)) {
8462
8506
  return [];
8463
8507
  }
8464
- const gl2 = gl;
8465
- const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
8508
+ const gl22 = gl2;
8509
+ const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
8466
8510
  const uniformBlocks = [];
8467
- const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8511
+ const blockCount = gl22.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);
8468
8512
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
8469
8513
  const blockInfo = {
8470
- name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
8514
+ name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
8471
8515
  location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),
8472
8516
  byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),
8473
8517
  vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
@@ -8476,12 +8520,12 @@ ${formattedLog}`)();
8476
8520
  uniforms: []
8477
8521
  };
8478
8522
  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);
8523
+ const uniformType = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE);
8524
+ const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE);
8525
+ const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET);
8526
+ const uniformStride = gl22.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE);
8483
8527
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
8484
- const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
8528
+ const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
8485
8529
  if (!activeInfo) {
8486
8530
  throw new Error("activeInfo");
8487
8531
  }
@@ -8550,8 +8594,8 @@ ${formattedLog}`)();
8550
8594
  }
8551
8595
 
8552
8596
  // src/adapter/helpers/set-uniform.ts
8553
- function setUniform(gl, location, type, value) {
8554
- const gl2 = gl;
8597
+ function setUniform(gl2, location, type, value) {
8598
+ const gl22 = gl2;
8555
8599
  if (typeof value === "number") {
8556
8600
  switch (type) {
8557
8601
  case GL.SAMPLER_2D:
@@ -8569,7 +8613,7 @@ ${formattedLog}`)();
8569
8613
  case GL.UNSIGNED_INT_SAMPLER_3D:
8570
8614
  case GL.UNSIGNED_INT_SAMPLER_CUBE:
8571
8615
  case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
8572
- return gl.uniform1i(location, value);
8616
+ return gl2.uniform1i(location, value);
8573
8617
  }
8574
8618
  }
8575
8619
  if (value === true) {
@@ -8581,55 +8625,55 @@ ${formattedLog}`)();
8581
8625
  const arrayValue = typeof value === "number" ? [value] : value;
8582
8626
  switch (type) {
8583
8627
  case GL.FLOAT:
8584
- return gl.uniform1fv(location, arrayValue);
8628
+ return gl2.uniform1fv(location, arrayValue);
8585
8629
  case GL.FLOAT_VEC2:
8586
- return gl.uniform2fv(location, arrayValue);
8630
+ return gl2.uniform2fv(location, arrayValue);
8587
8631
  case GL.FLOAT_VEC3:
8588
- return gl.uniform3fv(location, arrayValue);
8632
+ return gl2.uniform3fv(location, arrayValue);
8589
8633
  case GL.FLOAT_VEC4:
8590
- return gl.uniform4fv(location, arrayValue);
8634
+ return gl2.uniform4fv(location, arrayValue);
8591
8635
  case GL.INT:
8592
- return gl.uniform1iv(location, arrayValue);
8636
+ return gl2.uniform1iv(location, arrayValue);
8593
8637
  case GL.INT_VEC2:
8594
- return gl.uniform2iv(location, arrayValue);
8638
+ return gl2.uniform2iv(location, arrayValue);
8595
8639
  case GL.INT_VEC3:
8596
- return gl.uniform3iv(location, arrayValue);
8640
+ return gl2.uniform3iv(location, arrayValue);
8597
8641
  case GL.INT_VEC4:
8598
- return gl.uniform4iv(location, arrayValue);
8642
+ return gl2.uniform4iv(location, arrayValue);
8599
8643
  case GL.BOOL:
8600
- return gl.uniform1iv(location, arrayValue);
8644
+ return gl2.uniform1iv(location, arrayValue);
8601
8645
  case GL.BOOL_VEC2:
8602
- return gl.uniform2iv(location, arrayValue);
8646
+ return gl2.uniform2iv(location, arrayValue);
8603
8647
  case GL.BOOL_VEC3:
8604
- return gl.uniform3iv(location, arrayValue);
8648
+ return gl2.uniform3iv(location, arrayValue);
8605
8649
  case GL.BOOL_VEC4:
8606
- return gl.uniform4iv(location, arrayValue);
8650
+ return gl2.uniform4iv(location, arrayValue);
8607
8651
  case GL.UNSIGNED_INT:
8608
- return gl2.uniform1uiv(location, arrayValue, 1);
8652
+ return gl22.uniform1uiv(location, arrayValue, 1);
8609
8653
  case GL.UNSIGNED_INT_VEC2:
8610
- return gl2.uniform2uiv(location, arrayValue, 2);
8654
+ return gl22.uniform2uiv(location, arrayValue, 2);
8611
8655
  case GL.UNSIGNED_INT_VEC3:
8612
- return gl2.uniform3uiv(location, arrayValue, 3);
8656
+ return gl22.uniform3uiv(location, arrayValue, 3);
8613
8657
  case GL.UNSIGNED_INT_VEC4:
8614
- return gl2.uniform4uiv(location, arrayValue, 4);
8658
+ return gl22.uniform4uiv(location, arrayValue, 4);
8615
8659
  case GL.FLOAT_MAT2:
8616
- return gl.uniformMatrix2fv(location, false, arrayValue);
8660
+ return gl2.uniformMatrix2fv(location, false, arrayValue);
8617
8661
  case GL.FLOAT_MAT3:
8618
- return gl.uniformMatrix3fv(location, false, arrayValue);
8662
+ return gl2.uniformMatrix3fv(location, false, arrayValue);
8619
8663
  case GL.FLOAT_MAT4:
8620
- return gl.uniformMatrix4fv(location, false, arrayValue);
8664
+ return gl2.uniformMatrix4fv(location, false, arrayValue);
8621
8665
  case GL.FLOAT_MAT2x3:
8622
- return gl2.uniformMatrix2x3fv(location, false, arrayValue);
8666
+ return gl22.uniformMatrix2x3fv(location, false, arrayValue);
8623
8667
  case GL.FLOAT_MAT2x4:
8624
- return gl2.uniformMatrix2x4fv(location, false, arrayValue);
8668
+ return gl22.uniformMatrix2x4fv(location, false, arrayValue);
8625
8669
  case GL.FLOAT_MAT3x2:
8626
- return gl2.uniformMatrix3x2fv(location, false, arrayValue);
8670
+ return gl22.uniformMatrix3x2fv(location, false, arrayValue);
8627
8671
  case GL.FLOAT_MAT3x4:
8628
- return gl2.uniformMatrix3x4fv(location, false, arrayValue);
8672
+ return gl22.uniformMatrix3x4fv(location, false, arrayValue);
8629
8673
  case GL.FLOAT_MAT4x2:
8630
- return gl2.uniformMatrix4x2fv(location, false, arrayValue);
8674
+ return gl22.uniformMatrix4x2fv(location, false, arrayValue);
8631
8675
  case GL.FLOAT_MAT4x3:
8632
- return gl2.uniformMatrix4x3fv(location, false, arrayValue);
8676
+ return gl22.uniformMatrix4x3fv(location, false, arrayValue);
8633
8677
  }
8634
8678
  throw new Error("Illegal uniform");
8635
8679
  }
@@ -8640,8 +8684,25 @@ ${formattedLog}`)();
8640
8684
  get [Symbol.toStringTag]() {
8641
8685
  return "BaseVertexArrayObject";
8642
8686
  }
8687
+ /** Buffer constant */
8688
+ buffer = null;
8689
+ bufferValue = null;
8690
+ static isConstantAttributeZeroSupported(device) {
8691
+ return device.info.type === "webgl2" || getBrowser() === "Chrome";
8692
+ }
8693
+ // Create a VertexArray
8643
8694
  constructor(device, props) {
8644
- super(device, props, {});
8695
+ super(device, props, {
8696
+ ...Resource.defaultProps,
8697
+ constantAttributeZero: false
8698
+ });
8699
+ Object.seal(this);
8700
+ }
8701
+ destroy() {
8702
+ super.destroy();
8703
+ if (this.buffer) {
8704
+ this.buffer?.destroy();
8705
+ }
8645
8706
  }
8646
8707
  _createHandle() {
8647
8708
  return this.gl2.createVertexArray();
@@ -8653,6 +8714,20 @@ ${formattedLog}`)();
8653
8714
  _bindHandle(handle) {
8654
8715
  this.gl2.bindVertexArray(handle);
8655
8716
  }
8717
+ /**
8718
+ * Enabling an attribute location makes it reference the currently bound buffer
8719
+ * Disabling an attribute location makes it reference the global constant value
8720
+ * TODO - handle single values for size 1 attributes?
8721
+ * TODO - convert classic arrays based on known type?
8722
+ */
8723
+ enable(location, enable2 = true) {
8724
+ const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === "Chrome";
8725
+ const canDisableAttribute = canDisableAttributeZero || location !== 0;
8726
+ if (enable2 || canDisableAttribute) {
8727
+ location = Number(location);
8728
+ this.bind(() => enable2 ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
8729
+ }
8730
+ }
8656
8731
  // Set (bind) an elements buffer, for indexed rendering.
8657
8732
  // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
8658
8733
  setElementBuffer(elementBuffer = null, opts = {}) {
@@ -8660,12 +8735,12 @@ ${formattedLog}`)();
8660
8735
  this.bind(() => {
8661
8736
  this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
8662
8737
  });
8663
- return this;
8664
8738
  }
8665
8739
  /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
8666
8740
  setBuffer(location, buffer, accessor) {
8667
8741
  if (buffer.target === GL.ELEMENT_ARRAY_BUFFER) {
8668
- return this.setElementBuffer(buffer, accessor);
8742
+ this.setElementBuffer(buffer, accessor);
8743
+ return;
8669
8744
  }
8670
8745
  const {
8671
8746
  size,
@@ -8677,39 +8752,121 @@ ${formattedLog}`)();
8677
8752
  divisor
8678
8753
  } = accessor;
8679
8754
  const {
8680
- gl,
8681
- gl2
8755
+ gl: gl2,
8756
+ gl2: gl22
8682
8757
  } = this;
8683
8758
  location = Number(location);
8684
8759
  this.bind(() => {
8685
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);
8760
+ gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
8686
8761
  if (integer) {
8687
8762
  this.device.assertWebGL2();
8688
- gl2.vertexAttribIPointer(location, size, type, stride, offset);
8763
+ gl22.vertexAttribIPointer(location, size, type, stride, offset);
8689
8764
  } else {
8690
- gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
8765
+ gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
8691
8766
  }
8692
- gl.enableVertexAttribArray(location);
8693
- gl2.vertexAttribDivisor(location, divisor || 0);
8767
+ gl2.enableVertexAttribArray(location);
8768
+ gl22.vertexAttribDivisor(location, divisor || 0);
8694
8769
  });
8695
- return this;
8696
8770
  }
8697
8771
  /**
8698
- * Enabling an attribute location makes it reference the currently bound buffer
8699
- * Disabling an attribute location makes it reference the global constant value
8700
- * TODO - handle single values for size 1 attributes?
8701
- * TODO - convert classic arrays based on known type?
8772
+ * Set an attribute to a constant value
8773
+ * @param device
8774
+ * @param location
8775
+ * @param array
8776
+ *
8777
+ * @note Constants are stored globally on the WebGL context, not the VAO
8778
+ * so they need to be updated before every render
8779
+ * @todo - use known type (in configuration or passed in) to allow non-typed arrays?
8780
+ * @todo - remember/cache values to avoid setting them unnecessarily?
8702
8781
  */
8703
- enable(location, enable2 = true) {
8704
- const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === "Chrome";
8705
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
8706
- if (enable2 || canDisableAttribute) {
8707
- location = Number(location);
8708
- this.bind(() => enable2 ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location));
8782
+ setConstant(location, array) {
8783
+ switch (array.constructor) {
8784
+ case Float32Array:
8785
+ setConstantFloatArray(this.device, location, array);
8786
+ break;
8787
+ case Int32Array:
8788
+ setConstantIntArray(this.device, location, array);
8789
+ break;
8790
+ case Uint32Array:
8791
+ setConstantUintArray(this.device, location, array);
8792
+ break;
8793
+ default:
8794
+ assert2(false);
8709
8795
  }
8710
- return this;
8796
+ }
8797
+ /**
8798
+ * Provide a means to create a buffer that is equivalent to a constant.
8799
+ * NOTE: Desktop OpenGL cannot disable attribute 0.
8800
+ * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
8801
+ * this-has-significant-performance-penalty
8802
+ */
8803
+ getConstantBuffer(elementCount, value) {
8804
+ const constantValue = normalizeConstantArrayValue(value);
8805
+ const byteLength = constantValue.byteLength * elementCount;
8806
+ const length = constantValue.length * elementCount;
8807
+ let updateNeeded = !this.buffer;
8808
+ this.buffer = this.buffer || this.device.createBuffer({
8809
+ byteLength
8810
+ });
8811
+ updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
8812
+ updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
8813
+ if (updateNeeded) {
8814
+ const typedArray = getScratchArray(value.constructor, length);
8815
+ fillArray({
8816
+ target: typedArray,
8817
+ source: constantValue,
8818
+ start: 0,
8819
+ count: length
8820
+ });
8821
+ this.buffer.subData(typedArray);
8822
+ this.bufferValue = value;
8823
+ }
8824
+ return this.buffer;
8711
8825
  }
8712
8826
  };
8827
+ function setConstantFloatArray(device, location, array) {
8828
+ switch (array.length) {
8829
+ case 1:
8830
+ device.gl.vertexAttrib1fv(location, array);
8831
+ break;
8832
+ case 2:
8833
+ device.gl.vertexAttrib2fv(location, array);
8834
+ break;
8835
+ case 3:
8836
+ device.gl.vertexAttrib3fv(location, array);
8837
+ break;
8838
+ case 4:
8839
+ device.gl.vertexAttrib4fv(location, array);
8840
+ break;
8841
+ default:
8842
+ assert2(false);
8843
+ }
8844
+ }
8845
+ function setConstantIntArray(device, location, array) {
8846
+ device.assertWebGL2();
8847
+ device.gl2?.vertexAttribI4iv(location, array);
8848
+ }
8849
+ function setConstantUintArray(device, location, array) {
8850
+ device.assertWebGL2();
8851
+ device.gl2?.vertexAttribI4uiv(location, array);
8852
+ }
8853
+ function normalizeConstantArrayValue(arrayValue) {
8854
+ if (Array.isArray(arrayValue)) {
8855
+ return new Float32Array(arrayValue);
8856
+ }
8857
+ return arrayValue;
8858
+ }
8859
+ function compareConstantArrayValues(v1, v2) {
8860
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
8861
+ return false;
8862
+ }
8863
+ for (let i = 0; i < v1.length; ++i) {
8864
+ if (v1[i] !== v2[i]) {
8865
+ return false;
8866
+ }
8867
+ }
8868
+ return true;
8869
+ }
8713
8870
 
8714
8871
  // src/adapter/resources/webgl-render-pipeline.ts
8715
8872
  var LOG_PROGRAM_PERF_PRIORITY = 4;
@@ -8787,7 +8944,26 @@ ${formattedLog}`)();
8787
8944
  });
8788
8945
  }
8789
8946
  }
8790
- /** @todo needed for portable model */
8947
+ /**
8948
+ * Constant attributes are only supported in WebGL, not in WebGPU
8949
+ * Any attribute that is disabled in the current vertex array object
8950
+ * is read from the context's global constant value for that attribute location.
8951
+ * @param attributes
8952
+ */
8953
+ setConstantAttributes(attributes) {
8954
+ for (const [name, value] of Object.entries(attributes)) {
8955
+ const attribute = getAttributeLayout(this.layout, name);
8956
+ if (!attribute) {
8957
+ log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
8958
+ continue;
8959
+ }
8960
+ this.vertexArrayObject.setConstant(attribute.location, value);
8961
+ }
8962
+ }
8963
+ /**
8964
+ * Bindings include: textures, samplers and uniform buffers
8965
+ * @todo needed for portable model
8966
+ */
8791
8967
  setBindings(bindings) {
8792
8968
  for (const [name, value] of Object.entries(bindings)) {
8793
8969
  const binding = this.layout.bindings.find((binding2) => binding2.name === name);
@@ -8883,22 +9059,22 @@ ${formattedLog}`)();
8883
9059
  // setBindings(bindings: Record<string, Binding>): void {}
8884
9060
  _compileAndLink() {
8885
9061
  const {
8886
- gl
9062
+ gl: gl2
8887
9063
  } = this.device;
8888
- gl.attachShader(this.handle, this.vs.handle);
8889
- gl.attachShader(this.handle, this.fs.handle);
9064
+ gl2.attachShader(this.handle, this.vs.handle);
9065
+ gl2.attachShader(this.handle, this.fs.handle);
8890
9066
  log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
8891
- gl.linkProgram(this.handle);
9067
+ gl2.linkProgram(this.handle);
8892
9068
  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);
9069
+ if (gl2.debug || log.level > 0) {
9070
+ const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
8895
9071
  if (!linked) {
8896
- throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
9072
+ throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
8897
9073
  }
8898
- gl.validateProgram(this.handle);
8899
- const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
9074
+ gl2.validateProgram(this.handle);
9075
+ const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
8900
9076
  if (!validated) {
8901
- throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
9077
+ throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
8902
9078
  }
8903
9079
  }
8904
9080
  }
@@ -9304,18 +9480,18 @@ ${formattedLog}`)();
9304
9480
  * @param gl
9305
9481
  * @returns
9306
9482
  */
9307
- static attach(gl) {
9308
- if (gl instanceof _WebGLDevice) {
9309
- return gl;
9483
+ static attach(gl2) {
9484
+ if (gl2 instanceof _WebGLDevice) {
9485
+ return gl2;
9310
9486
  }
9311
- if (gl?.device instanceof Device) {
9312
- return gl.device;
9487
+ if (gl2?.device instanceof Device) {
9488
+ return gl2.device;
9313
9489
  }
9314
- if (!isWebGL3(gl)) {
9490
+ if (!isWebGL3(gl2)) {
9315
9491
  throw new Error("Invalid WebGLRenderingContext");
9316
9492
  }
9317
9493
  return new _WebGLDevice({
9318
- gl
9494
+ gl: gl2
9319
9495
  });
9320
9496
  }
9321
9497
  static async create(props = {}) {
@@ -9355,19 +9531,19 @@ ${formattedLog}`)();
9355
9531
  reason: "destroyed",
9356
9532
  message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
9357
9533
  });
9358
- let gl = props.gl || null;
9359
- gl = gl || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9534
+ let gl2 = props.gl || null;
9535
+ gl2 = gl2 || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
9360
9536
  ...props,
9361
9537
  onContextLost
9362
9538
  }) : null);
9363
- gl = gl || (!isBrowser() ? createHeadlessContext({
9539
+ gl2 = gl2 || (!isBrowser() ? createHeadlessContext({
9364
9540
  ...props,
9365
9541
  onContextLost
9366
9542
  }) : null);
9367
- if (!gl) {
9543
+ if (!gl2) {
9368
9544
  throw new Error("WebGL context creation failed");
9369
9545
  }
9370
- this.handle = gl;
9546
+ this.handle = gl2;
9371
9547
  this.gl = this.handle;
9372
9548
  this.gl2 = this.gl;
9373
9549
  this.isWebGL2 = isWebGL22(this.gl);
@@ -9555,11 +9731,11 @@ ${formattedLog}`)();
9555
9731
  * Be aware that there are some duplicates especially for constants that are 0,
9556
9732
  * so this isn't guaranteed to return the right key in all cases.
9557
9733
  */
9558
- getGLKey(value, gl) {
9559
- gl = gl || this.gl2 || this.gl;
9734
+ getGLKey(value, gl2) {
9735
+ gl2 = gl2 || this.gl2 || this.gl;
9560
9736
  const number = Number(value);
9561
- for (const key in gl) {
9562
- if (gl[key] === number) {
9737
+ for (const key in gl2) {
9738
+ if (gl2[key] === number) {
9563
9739
  return `GL.${key}`;
9564
9740
  }
9565
9741
  }
@@ -9571,20 +9747,20 @@ ${formattedLog}`)();
9571
9747
  // Public `Device` API
9572
9748
  //
9573
9749
  __publicField(WebGLDevice, "type", "webgl");
9574
- function isWebGL3(gl) {
9575
- if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
9750
+ function isWebGL3(gl2) {
9751
+ if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
9576
9752
  return true;
9577
9753
  }
9578
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9754
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9579
9755
  return true;
9580
9756
  }
9581
- return Boolean(gl && Number.isFinite(gl._version));
9757
+ return Boolean(gl2 && Number.isFinite(gl2._version));
9582
9758
  }
9583
- function isWebGL22(gl) {
9584
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
9759
+ function isWebGL22(gl2) {
9760
+ if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
9585
9761
  return true;
9586
9762
  }
9587
- return Boolean(gl && gl._version === 2);
9763
+ return Boolean(gl2 && gl2._version === 2);
9588
9764
  }
9589
9765
 
9590
9766
  // src/classic/clear.ts
@@ -9592,8 +9768,8 @@ ${formattedLog}`)();
9592
9768
  var GL_STENCIL_BUFFER_BIT2 = 1024;
9593
9769
  var GL_COLOR_BUFFER_BIT2 = 16384;
9594
9770
  var ERR_ARGUMENTS = "clear: bad arguments";
9595
- function clear(gl, options) {
9596
- const device = WebGLDevice.attach(gl);
9771
+ function clear(gl2, options) {
9772
+ const device = WebGLDevice.attach(gl2);
9597
9773
  const {
9598
9774
  framebuffer = null,
9599
9775
  color = null,
@@ -9688,7 +9864,7 @@ ${formattedLog}`)();
9688
9864
  } = getFramebuffer2(source);
9689
9865
  assert2(framebuffer);
9690
9866
  const {
9691
- gl,
9867
+ gl: gl2,
9692
9868
  handle
9693
9869
  } = framebuffer;
9694
9870
  sourceWidth = sourceWidth || framebuffer.width;
@@ -9700,9 +9876,9 @@ ${formattedLog}`)();
9700
9876
  sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
9701
9877
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
9702
9878
  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);
9879
+ const prevHandle2 = gl2.bindFramebuffer(GL.FRAMEBUFFER, handle);
9880
+ gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
9881
+ gl2.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
9706
9882
  if (deleteFramebuffer) {
9707
9883
  framebuffer.destroy();
9708
9884
  }
@@ -9759,6 +9935,85 @@ ${formattedLog}`)();
9759
9935
  }
9760
9936
  return target;
9761
9937
  }
9938
+ function copyToTexture(source, target, options) {
9939
+ const {
9940
+ sourceX = 0,
9941
+ sourceY = 0,
9942
+ // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
9943
+ targetMipmaplevel = 0,
9944
+ targetInternalFormat = GL.RGBA
9945
+ } = options || {};
9946
+ let {
9947
+ targetX,
9948
+ targetY,
9949
+ targetZ,
9950
+ width,
9951
+ // defaults to target width
9952
+ height
9953
+ // defaults to target height
9954
+ } = options || {};
9955
+ const {
9956
+ framebuffer,
9957
+ deleteFramebuffer
9958
+ } = getFramebuffer2(source);
9959
+ assert2(framebuffer);
9960
+ const webglFramebuffer = framebuffer;
9961
+ const {
9962
+ device,
9963
+ handle
9964
+ } = webglFramebuffer;
9965
+ const isSubCopy = typeof targetX !== "undefined" || typeof targetY !== "undefined" || typeof targetZ !== "undefined";
9966
+ targetX = targetX || 0;
9967
+ targetY = targetY || 0;
9968
+ targetZ = targetZ || 0;
9969
+ const prevHandle2 = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
9970
+ assert2(target);
9971
+ let texture = null;
9972
+ let textureTarget;
9973
+ if (target instanceof Texture) {
9974
+ texture = target;
9975
+ width = Number.isFinite(width) ? width : texture.width;
9976
+ height = Number.isFinite(height) ? height : texture.height;
9977
+ texture.bind(0);
9978
+ textureTarget = texture.target;
9979
+ } else {
9980
+ textureTarget = target;
9981
+ }
9982
+ if (!isSubCopy) {
9983
+ device.gl.copyTexImage2D(
9984
+ textureTarget,
9985
+ targetMipmaplevel,
9986
+ targetInternalFormat,
9987
+ sourceX,
9988
+ sourceY,
9989
+ width,
9990
+ height,
9991
+ 0
9992
+ /* border must be 0 */
9993
+ );
9994
+ } else {
9995
+ switch (textureTarget) {
9996
+ case GL.TEXTURE_2D:
9997
+ case GL.TEXTURE_CUBE_MAP:
9998
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
9999
+ break;
10000
+ case GL.TEXTURE_2D_ARRAY:
10001
+ case GL.TEXTURE_3D:
10002
+ device.assertWebGL2();
10003
+ device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
10004
+ break;
10005
+ default:
10006
+ }
10007
+ }
10008
+ if (texture) {
10009
+ texture.unbind();
10010
+ }
10011
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
10012
+ if (deleteFramebuffer) {
10013
+ framebuffer.destroy();
10014
+ }
10015
+ return texture;
10016
+ }
9762
10017
  function getFramebuffer2(source) {
9763
10018
  if (!(source instanceof Framebuffer)) {
9764
10019
  return {