@luma.gl/webgl 9.0.0-alpha.35 → 9.0.0-alpha.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +9 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +15 -2
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgl-command-buffer.js +0 -1
  6. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  7. package/dist/adapter/resources/webgl-render-pass.d.ts +2 -2
  8. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-render-pass.js +5 -3
  10. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +23 -28
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pipeline.js +41 -110
  14. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  15. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  16. package/dist/adapter/resources/webgl-shader.js +3 -1
  17. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  18. package/dist/adapter/resources/webgl-texture.js +5 -5
  19. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  20. package/dist/adapter/resources/webgl-vertex-array.d.ts +67 -0
  21. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.js +166 -0
  23. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  24. package/dist/adapter/webgl-device.d.ts +11 -1
  25. package/dist/adapter/webgl-device.d.ts.map +1 -1
  26. package/dist/adapter/webgl-device.js +66 -1
  27. package/dist/adapter/webgl-device.js.map +1 -1
  28. package/dist/classic/clear.js +3 -3
  29. package/dist/classic/clear.js.map +1 -1
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +7 -9
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  34. package/dist/context/context/create-browser-context.js.map +1 -1
  35. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  36. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  37. package/dist/context/parameters/unified-parameter-api.js +4 -4
  38. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  39. package/dist/context/state-tracker/track-context-state.js +3 -3
  40. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  41. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  42. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  43. package/dist/context/state-tracker/with-parameters.js +3 -3
  44. package/dist/context/state-tracker/with-parameters.js.map +1 -1
  45. package/dist/dist.dev.js +1273 -1179
  46. package/dist/index.cjs +1026 -972
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +5 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist.min.js +22 -22
  52. package/package.json +5 -5
  53. package/src/.DS_Store +0 -0
  54. package/src/adapter/.DS_Store +0 -0
  55. package/src/adapter/converters/device-parameters.ts +34 -2
  56. package/src/adapter/resources/webgl-command-buffer.ts +2 -2
  57. package/src/adapter/resources/webgl-render-pass.ts +8 -6
  58. package/src/adapter/resources/webgl-render-pipeline.ts +141 -174
  59. package/src/adapter/resources/webgl-sampler.ts +1 -1
  60. package/src/adapter/resources/webgl-shader.ts +1 -1
  61. package/src/adapter/resources/webgl-texture.ts +5 -5
  62. package/src/adapter/resources/webgl-vertex-array.ts +278 -0
  63. package/src/adapter/webgl-device.ts +137 -11
  64. package/src/classic/clear.ts +3 -3
  65. package/src/classic/copy-and-blit.ts +19 -15
  66. package/src/context/.DS_Store +0 -0
  67. package/src/context/context/create-browser-context.ts +12 -0
  68. package/src/context/parameters/unified-parameter-api.ts +4 -4
  69. package/src/context/state-tracker/track-context-state.ts +3 -3
  70. package/src/context/state-tracker/with-parameters.ts +3 -3
  71. package/src/index.ts +38 -16
  72. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -55
  73. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  74. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -173
  75. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  76. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -276
package/dist/index.cjs CHANGED
@@ -20,8 +20,8 @@ var __spreadValues = (a, b) => {
20
20
  };
21
21
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  var __export = (target, all) => {
23
- for (var name2 in all)
24
- __defProp(target, name2, { get: all[name2], enumerable: true });
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
25
  };
26
26
  var __copyProps = (to, from, except, desc) => {
27
27
  if (from && typeof from === "object" || typeof from === "function") {
@@ -68,7 +68,7 @@ __export(src_exports, {
68
68
  WEBGLSampler: () => WEBGLSampler,
69
69
  WEBGLShader: () => WEBGLShader,
70
70
  WEBGLTexture: () => WEBGLTexture,
71
- WEBGLVertexArrayObject: () => WEBGLVertexArrayObject,
71
+ WEBGLVertexArray: () => WEBGLVertexArray,
72
72
  WebGLCanvasContext: () => WebGLCanvasContext,
73
73
  WebGLDevice: () => WebGLDevice,
74
74
  WebGLResource: () => WebGLResource,
@@ -79,7 +79,7 @@ __export(src_exports, {
79
79
  clear: () => clear,
80
80
  convertGLToTextureFormat: () => convertGLToTextureFormat,
81
81
  copyToTexture: () => copyToTexture,
82
- getParameters: () => getParameters,
82
+ getGLParameters: () => getGLParameters,
83
83
  getShaderLayout: () => getShaderLayout,
84
84
  getWebGL2Context: () => getWebGL2Context,
85
85
  isWebGL: () => isWebGL,
@@ -90,12 +90,12 @@ __export(src_exports, {
90
90
  readPixelsToArray: () => readPixelsToArray,
91
91
  readPixelsToBuffer: () => readPixelsToBuffer,
92
92
  registerHeadlessGL: () => registerHeadlessGL,
93
- resetParameters: () => resetParameters,
93
+ resetGLParameters: () => resetGLParameters,
94
94
  setDeviceParameters: () => setDeviceParameters,
95
- setParameters: () => setParameters,
95
+ setGLParameters: () => setGLParameters,
96
96
  trackContextState: () => trackContextState,
97
97
  withDeviceParameters: () => withDeviceParameters,
98
- withParameters: () => withParameters
98
+ withGLParameters: () => withGLParameters
99
99
  });
100
100
  module.exports = __toCommonJS(src_exports);
101
101
 
@@ -124,11 +124,11 @@ function createHeadlessContext(options) {
124
124
  if (!headlessGL) {
125
125
  throw new Error(ERR_HEADLESSGL_LOAD);
126
126
  }
127
- const gl2 = headlessGL(width, height, options);
128
- if (!gl2) {
127
+ const gl = headlessGL(width, height, options);
128
+ if (!gl) {
129
129
  throw new Error(ERR_HEADLESSGL_FAILED);
130
130
  }
131
- return gl2;
131
+ return gl;
132
132
  }
133
133
 
134
134
  // src/adapter/webgl-device.ts
@@ -156,43 +156,43 @@ function synthesizeGLError(err, opt_msg) {
156
156
  error(opt_msg);
157
157
  }
158
158
  }
159
- function wrapGLError(gl2) {
160
- const f = gl2.getError;
161
- gl2.getError = function getError() {
159
+ function wrapGLError(gl) {
160
+ const f = gl.getError;
161
+ gl.getError = function getError() {
162
162
  let err;
163
163
  do {
164
- err = f.apply(gl2);
165
- if (err !== gl2.NO_ERROR) {
164
+ err = f.apply(gl);
165
+ if (err !== gl.NO_ERROR) {
166
166
  glErrorShadow[err] = true;
167
167
  }
168
- } while (err !== gl2.NO_ERROR);
168
+ } while (err !== gl.NO_ERROR);
169
169
  for (err in glErrorShadow) {
170
170
  if (glErrorShadow[err]) {
171
171
  delete glErrorShadow[err];
172
172
  return parseInt(err, 10);
173
173
  }
174
174
  }
175
- return gl2.NO_ERROR;
175
+ return gl.NO_ERROR;
176
176
  };
177
177
  }
178
178
  var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
179
- const gl2 = ext.gl;
179
+ const gl = ext.gl;
180
180
  this.ext = ext;
181
181
  this.isAlive = true;
182
182
  this.hasBeenBound = false;
183
183
  this.elementArrayBuffer = null;
184
184
  this.attribs = new Array(ext.maxVertexAttribs);
185
185
  for (let n = 0; n < this.attribs.length; n++) {
186
- const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
186
+ const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl);
187
187
  this.attribs[n] = attrib;
188
188
  }
189
189
  this.maxAttrib = 0;
190
190
  };
191
- WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
191
+ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
192
192
  this.enabled = false;
193
193
  this.buffer = null;
194
194
  this.size = 4;
195
- this.type = gl2.FLOAT;
195
+ this.type = gl.FLOAT;
196
196
  this.normalized = false;
197
197
  this.stride = 16;
198
198
  this.offset = 0;
@@ -202,19 +202,19 @@ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
202
202
  WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
203
203
  this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
204
204
  };
205
- var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
205
+ var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
206
206
  const self = this;
207
- this.gl = gl2;
208
- wrapGLError(gl2);
207
+ this.gl = gl;
208
+ wrapGLError(gl);
209
209
  const original = this.original = {
210
- getParameter: gl2.getParameter,
211
- enableVertexAttribArray: gl2.enableVertexAttribArray,
212
- disableVertexAttribArray: gl2.disableVertexAttribArray,
213
- bindBuffer: gl2.bindBuffer,
214
- getVertexAttrib: gl2.getVertexAttrib,
215
- vertexAttribPointer: gl2.vertexAttribPointer
210
+ getParameter: gl.getParameter,
211
+ enableVertexAttribArray: gl.enableVertexAttribArray,
212
+ disableVertexAttribArray: gl.disableVertexAttribArray,
213
+ bindBuffer: gl.bindBuffer,
214
+ getVertexAttrib: gl.getVertexAttrib,
215
+ vertexAttribPointer: gl.vertexAttribPointer
216
216
  };
217
- gl2.getParameter = function getParameter(pname) {
217
+ gl.getParameter = function getParameter(pname) {
218
218
  if (pname === self.VERTEX_ARRAY_BINDING_OES) {
219
219
  if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
220
220
  return null;
@@ -223,53 +223,53 @@ var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
223
223
  }
224
224
  return original.getParameter.apply(this, arguments);
225
225
  };
226
- gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
226
+ gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
227
227
  const vao = self.currentVertexArrayObject;
228
228
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
229
229
  const attrib = vao.attribs[index];
230
230
  attrib.enabled = true;
231
231
  return original.enableVertexAttribArray.apply(this, arguments);
232
232
  };
233
- gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
233
+ gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
234
234
  const vao = self.currentVertexArrayObject;
235
235
  vao.maxAttrib = Math.max(vao.maxAttrib, index);
236
236
  const attrib = vao.attribs[index];
237
237
  attrib.enabled = false;
238
238
  return original.disableVertexAttribArray.apply(this, arguments);
239
239
  };
240
- gl2.bindBuffer = function bindBuffer2(target, buffer) {
240
+ gl.bindBuffer = function bindBuffer2(target, buffer) {
241
241
  switch (target) {
242
- case gl2.ARRAY_BUFFER:
242
+ case gl.ARRAY_BUFFER:
243
243
  self.currentArrayBuffer = buffer;
244
244
  break;
245
- case gl2.ELEMENT_ARRAY_BUFFER:
245
+ case gl.ELEMENT_ARRAY_BUFFER:
246
246
  self.currentVertexArrayObject.elementArrayBuffer = buffer;
247
247
  break;
248
248
  default:
249
249
  }
250
250
  return original.bindBuffer.apply(this, arguments);
251
251
  };
252
- gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
252
+ gl.getVertexAttrib = function getVertexAttrib(index, pname) {
253
253
  const vao = self.currentVertexArrayObject;
254
254
  const attrib = vao.attribs[index];
255
255
  switch (pname) {
256
- case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
256
+ case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
257
257
  return attrib.buffer;
258
- case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
258
+ case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
259
259
  return attrib.enabled;
260
- case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
260
+ case gl.VERTEX_ATTRIB_ARRAY_SIZE:
261
261
  return attrib.size;
262
- case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
262
+ case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
263
263
  return attrib.stride;
264
- case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
264
+ case gl.VERTEX_ATTRIB_ARRAY_TYPE:
265
265
  return attrib.type;
266
- case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
266
+ case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
267
267
  return attrib.normalized;
268
268
  default:
269
269
  return original.getVertexAttrib.apply(this, arguments);
270
270
  }
271
271
  };
272
- gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
272
+ gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
273
273
  const vao = self.currentVertexArrayObject;
274
274
  vao.maxAttrib = Math.max(vao.maxAttrib, indx);
275
275
  const attrib = vao.attribs[indx];
@@ -282,11 +282,11 @@ var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
282
282
  attrib.recache();
283
283
  return original.vertexAttribPointer.apply(this, arguments);
284
284
  };
285
- if (gl2.instrumentExtension) {
286
- gl2.instrumentExtension(this, "OES_vertex_array_object");
285
+ if (gl.instrumentExtension) {
286
+ gl.instrumentExtension(this, "OES_vertex_array_object");
287
287
  }
288
- if (gl2.canvas) {
289
- gl2.canvas.addEventListener(
288
+ if (gl.canvas) {
289
+ gl.canvas.addEventListener(
290
290
  "webglcontextrestored",
291
291
  () => {
292
292
  log("OESVertexArrayObject emulation library context restored");
@@ -305,8 +305,8 @@ OESVertexArrayObject.prototype.reset_ = function reset_() {
305
305
  this.vertexArrayObjects.isAlive = false;
306
306
  }
307
307
  }
308
- const gl2 = this.gl;
309
- this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
308
+ const gl = this.gl;
309
+ this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
310
310
  this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
311
311
  this.currentVertexArrayObject = null;
312
312
  this.currentArrayBuffer = null;
@@ -334,10 +334,10 @@ OESVertexArrayObject.prototype.isVertexArrayOES = function isVertexArrayOES(arra
334
334
  return false;
335
335
  };
336
336
  OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
337
- const gl2 = this.gl;
337
+ const gl = this.gl;
338
338
  if (arrayObject && !arrayObject.isAlive) {
339
339
  synthesizeGLError(
340
- gl2.INVALID_OPERATION,
340
+ gl.INVALID_OPERATION,
341
341
  "bindVertexArrayOES: attempt to bind deleted arrayObject"
342
342
  );
343
343
  return;
@@ -351,7 +351,7 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
351
351
  return;
352
352
  }
353
353
  if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
354
- original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
354
+ original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
355
355
  }
356
356
  let currentBinding = this.currentArrayBuffer;
357
357
  const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
@@ -360,23 +360,23 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
360
360
  const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
361
361
  if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
362
362
  if (attrib.enabled) {
363
- original.enableVertexAttribArray.call(gl2, n);
363
+ original.enableVertexAttribArray.call(gl, n);
364
364
  } else {
365
- original.disableVertexAttribArray.call(gl2, n);
365
+ original.disableVertexAttribArray.call(gl, n);
366
366
  }
367
367
  }
368
368
  if (attrib.enabled) {
369
369
  let bufferChanged = false;
370
370
  if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
371
371
  if (currentBinding !== attrib.buffer) {
372
- original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
372
+ original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
373
373
  currentBinding = attrib.buffer;
374
374
  }
375
375
  bufferChanged = true;
376
376
  }
377
377
  if (bufferChanged || attrib.cached !== oldAttrib.cached) {
378
378
  original.vertexAttribPointer.call(
379
- gl2,
379
+ gl,
380
380
  n,
381
381
  attrib.size,
382
382
  attrib.type,
@@ -388,31 +388,31 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
388
388
  }
389
389
  }
390
390
  if (this.currentArrayBuffer !== currentBinding) {
391
- original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
391
+ original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
392
392
  }
393
393
  };
394
- function polyfillVertexArrayObject(gl2) {
395
- if (typeof gl2.createVertexArray === "function") {
394
+ function polyfillVertexArrayObject(gl) {
395
+ if (typeof gl.createVertexArray === "function") {
396
396
  return;
397
397
  }
398
- const original_getSupportedExtensions = gl2.getSupportedExtensions;
399
- gl2.getSupportedExtensions = function getSupportedExtensions() {
398
+ const original_getSupportedExtensions = gl.getSupportedExtensions;
399
+ gl.getSupportedExtensions = function getSupportedExtensions() {
400
400
  const list = original_getSupportedExtensions.call(this) || [];
401
401
  if (list.indexOf("OES_vertex_array_object") < 0) {
402
402
  list.push("OES_vertex_array_object");
403
403
  }
404
404
  return list;
405
405
  };
406
- const original_getExtension = gl2.getExtension;
407
- gl2.getExtension = function getExtension(name2) {
408
- const ext = original_getExtension.call(this, name2);
406
+ const original_getExtension = gl.getExtension;
407
+ gl.getExtension = function getExtension(name) {
408
+ const ext = original_getExtension.call(this, name);
409
409
  if (ext) {
410
410
  return ext;
411
411
  }
412
- if (name2 !== "OES_vertex_array_object") {
412
+ if (name !== "OES_vertex_array_object") {
413
413
  return null;
414
414
  }
415
- if (!gl2.__OESVertexArrayObject) {
415
+ if (!gl.__OESVertexArrayObject) {
416
416
  this.__OESVertexArrayObject = new OESVertexArrayObject(this);
417
417
  }
418
418
  return this.__OESVertexArrayObject;
@@ -427,31 +427,31 @@ var import_constants2 = require("@luma.gl/constants");
427
427
  var import_core = require("@luma.gl/core");
428
428
  var ERR_CONTEXT = "Invalid WebGLRenderingContext";
429
429
  var ERR_WEBGL2 = "Requires WebGL2";
430
- function isWebGL(gl2) {
431
- if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
430
+ function isWebGL(gl) {
431
+ if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
432
432
  return true;
433
433
  }
434
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
434
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
435
435
  return true;
436
436
  }
437
- return Boolean(gl2 && Number.isFinite(gl2._version));
437
+ return Boolean(gl && Number.isFinite(gl._version));
438
438
  }
439
- function isWebGL2(gl2) {
440
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
439
+ function isWebGL2(gl) {
440
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
441
441
  return true;
442
442
  }
443
- return Boolean(gl2 && gl2._version === 2);
443
+ return Boolean(gl && gl._version === 2);
444
444
  }
445
- function getWebGL2Context(gl2) {
446
- return isWebGL2(gl2) ? gl2 : null;
445
+ function getWebGL2Context(gl) {
446
+ return isWebGL2(gl) ? gl : null;
447
447
  }
448
- function assertWebGLContext(gl2) {
449
- (0, import_core.assert)(isWebGL(gl2), ERR_CONTEXT);
450
- return gl2;
448
+ function assertWebGLContext(gl) {
449
+ (0, import_core.assert)(isWebGL(gl), ERR_CONTEXT);
450
+ return gl;
451
451
  }
452
- function assertWebGL2Context(gl2) {
453
- (0, import_core.assert)(isWebGL2(gl2), ERR_WEBGL2);
454
- return gl2;
452
+ function assertWebGL2Context(gl) {
453
+ (0, import_core.assert)(isWebGL2(gl), ERR_WEBGL2);
454
+ return gl;
455
455
  }
456
456
 
457
457
  // src/context/polyfill/get-parameter-polyfill.ts
@@ -468,40 +468,40 @@ var GL_GPU_DISJOINT_EXT = 36795;
468
468
  var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
469
469
  var GL_UNMASKED_VENDOR_WEBGL = 37445;
470
470
  var GL_UNMASKED_RENDERER_WEBGL = 37446;
471
- var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
471
+ var getWebGL2ValueOrZero = (gl) => !isWebGL2(gl) ? 0 : void 0;
472
472
  var WEBGL_PARAMETERS = {
473
- [import_constants.GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? import_constants.GL.COLOR_ATTACHMENT0 : void 0,
473
+ [import_constants.GL.READ_BUFFER]: (gl) => !isWebGL2(gl) ? import_constants.GL.COLOR_ATTACHMENT0 : void 0,
474
474
  // WebGL2 context parameters
475
- [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
475
+ [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => !isWebGL2(gl) ? GL_DONT_CARE : void 0,
476
476
  [import_constants.GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
477
477
  [import_constants.GL.SAMPLES]: getWebGL2ValueOrZero,
478
478
  // WebGL2 extension context parameters
479
- [GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
480
- const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
479
+ [GL_GPU_DISJOINT_EXT]: (gl, getParameter) => {
480
+ const ext = isWebGL2(gl) ? gl.getExtension(EXT_disjoint_timer_query_webgl2) : gl.getExtension(EXT_disjoint_timer_query);
481
481
  return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
482
482
  },
483
483
  // Extension fixed values
484
- [GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
485
- const ext = gl2.getExtension(WEBGL_debug_renderer_info);
484
+ [GL_UNMASKED_VENDOR_WEBGL]: (gl, getParameter) => {
485
+ const ext = gl.getExtension(WEBGL_debug_renderer_info);
486
486
  return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || import_constants.GL.VENDOR);
487
487
  },
488
- [GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
489
- const ext = gl2.getExtension(WEBGL_debug_renderer_info);
488
+ [GL_UNMASKED_RENDERER_WEBGL]: (gl, getParameter) => {
489
+ const ext = gl.getExtension(WEBGL_debug_renderer_info);
490
490
  return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || import_constants.GL.RENDERER);
491
491
  },
492
492
  // Extension LIMITS
493
- [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
493
+ [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl, getParameter) => {
494
494
  var _a, _b;
495
- const ext = ((_b = (_a = gl2.luma) == null ? void 0 : _a.extensions) == null ? void 0 : _b[EXT_texture_filter_anisotropic]) || gl2.getExtension("EXT_texture_filter_anisotropic");
495
+ const ext = ((_b = (_a = gl.luma) == null ? void 0 : _a.extensions) == null ? void 0 : _b[EXT_texture_filter_anisotropic]) || gl.getExtension("EXT_texture_filter_anisotropic");
496
496
  return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
497
497
  },
498
498
  // WebGL2 Limits
499
499
  [import_constants.GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
500
500
  [import_constants.GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
501
501
  [import_constants.GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
502
- [import_constants.GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
503
- if (!isWebGL2(gl2)) {
504
- const ext = gl2.getExtension(WEBGL_draw_buffers);
502
+ [import_constants.GL.MAX_COLOR_ATTACHMENTS]: (gl, getParameter) => {
503
+ if (!isWebGL2(gl)) {
504
+ const ext = gl.getExtension(WEBGL_draw_buffers);
505
505
  return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
506
506
  }
507
507
  return void 0;
@@ -509,24 +509,24 @@ var WEBGL_PARAMETERS = {
509
509
  [import_constants.GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
510
510
  [import_constants.GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
511
511
  [import_constants.GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
512
- [import_constants.GL.MAX_DRAW_BUFFERS]: (gl2) => {
513
- if (!isWebGL2(gl2)) {
514
- const ext = gl2.getExtension(WEBGL_draw_buffers);
512
+ [import_constants.GL.MAX_DRAW_BUFFERS]: (gl) => {
513
+ if (!isWebGL2(gl)) {
514
+ const ext = gl.getExtension(WEBGL_draw_buffers);
515
515
  return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
516
516
  }
517
517
  return void 0;
518
518
  },
519
519
  [import_constants.GL.MAX_ELEMENT_INDEX]: (
520
520
  // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
521
- (gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
521
+ (gl) => gl.getExtension(OES_element_index) ? 2147483647 : 65535
522
522
  ),
523
523
  [import_constants.GL.MAX_ELEMENTS_INDICES]: (
524
524
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
525
- (gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
525
+ (gl) => gl.getExtension(OES_element_index) ? 16777216 : 65535
526
526
  ),
527
527
  [import_constants.GL.MAX_ELEMENTS_VERTICES]: (
528
528
  // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
529
- (gl2) => 16777216
529
+ (gl) => 16777216
530
530
  ),
531
531
  [import_constants.GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
532
532
  [import_constants.GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
@@ -547,24 +547,24 @@ var WEBGL_PARAMETERS = {
547
547
  [import_constants.GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
548
548
  [import_constants.GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
549
549
  };
550
- function getParameterPolyfill(gl2, originalGetParameter, pname) {
550
+ function getParameterPolyfill(gl, originalGetParameter, pname) {
551
551
  const limit = WEBGL_PARAMETERS[pname];
552
- const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
552
+ const value = typeof limit === "function" ? limit(gl, originalGetParameter, pname) : limit;
553
553
  const result = value !== void 0 ? value : originalGetParameter(pname);
554
554
  return result;
555
555
  }
556
556
 
557
557
  // src/context/polyfill/context-data.ts
558
- function getContextData(gl2) {
559
- const luma = gl2.luma;
558
+ function getContextData(gl) {
559
+ const luma = gl.luma;
560
560
  if (!luma) {
561
561
  const contextState = {
562
562
  _polyfilled: false,
563
563
  _extensions: {}
564
564
  };
565
- gl2.luma = contextState;
565
+ gl.luma = contextState;
566
566
  }
567
- return gl2.luma;
567
+ return gl.luma;
568
568
  }
569
569
 
570
570
  // src/context/polyfill/polyfill-table.ts
@@ -574,10 +574,10 @@ var WEBGL_draw_buffers2 = "WEBGL_draw_buffers";
574
574
  var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
575
575
  var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
576
576
  var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
577
- function getExtensionData(gl2, extension) {
577
+ function getExtensionData(gl, extension) {
578
578
  return {
579
- webgl2: isWebGL2(gl2),
580
- ext: gl2.getExtension(extension)
579
+ webgl2: isWebGL2(gl),
580
+ ext: gl.getExtension(extension)
581
581
  };
582
582
  }
583
583
  var WEBGL2_CONTEXT_POLYFILLS = {
@@ -644,15 +644,15 @@ var WEBGL2_CONTEXT_POLYFILLS = {
644
644
  };
645
645
  var WEBGL2_CONTEXT_OVERRIDES = {
646
646
  // Ensure readBuffer is a no-op
647
- readBuffer: (gl2, originalFunc, attachment) => {
648
- if (isWebGL2(gl2)) {
647
+ readBuffer: (gl, originalFunc, attachment) => {
648
+ if (isWebGL2(gl)) {
649
649
  originalFunc(attachment);
650
650
  } else {
651
651
  }
652
652
  },
653
653
  // Override for getVertexAttrib that returns sane values for non-WebGL1 constants
654
- getVertexAttrib: (gl2, originalFunc, location, pname) => {
655
- const { webgl2, ext } = getExtensionData(gl2, ANGLE_instanced_arrays);
654
+ getVertexAttrib: (gl, originalFunc, location, pname) => {
655
+ const { webgl2, ext } = getExtensionData(gl, ANGLE_instanced_arrays);
656
656
  let result;
657
657
  switch (pname) {
658
658
  case import_constants2.GL.VERTEX_ATTRIB_ARRAY_INTEGER:
@@ -666,8 +666,8 @@ var WEBGL2_CONTEXT_OVERRIDES = {
666
666
  return result !== void 0 ? result : originalFunc(location, pname);
667
667
  },
668
668
  // Handle transform feedback and uniform block queries in WebGL1
669
- getProgramParameter: (gl2, originalFunc, program, pname) => {
670
- if (!isWebGL2(gl2)) {
669
+ getProgramParameter: (gl, originalFunc, program, pname) => {
670
+ if (!isWebGL2(gl)) {
671
671
  switch (pname) {
672
672
  case import_constants2.GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
673
673
  return import_constants2.GL.SEPARATE_ATTRIBS;
@@ -680,21 +680,21 @@ var WEBGL2_CONTEXT_OVERRIDES = {
680
680
  }
681
681
  return originalFunc(program, pname);
682
682
  },
683
- getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
684
- if (!isWebGL2(gl2)) {
683
+ getInternalformatParameter: (gl, originalFunc, target, format, pname) => {
684
+ if (!isWebGL2(gl)) {
685
685
  switch (pname) {
686
686
  case import_constants2.GL.SAMPLES:
687
687
  return new Int32Array([0]);
688
688
  default:
689
689
  }
690
690
  }
691
- const gl22 = gl2;
692
- return gl22.getInternalformatParameter(target, format, pname);
691
+ const gl2 = gl;
692
+ return gl2.getInternalformatParameter(target, format, pname);
693
693
  },
694
- getTexParameter(gl2, originalFunc, target, pname) {
694
+ getTexParameter(gl, originalFunc, target, pname) {
695
695
  switch (pname) {
696
696
  case import_constants2.GL.TEXTURE_MAX_ANISOTROPY_EXT:
697
- const contextData = getContextData(gl2);
697
+ const contextData = getContextData(gl);
698
698
  const { _extensions } = contextData;
699
699
  const ext = _extensions[EXT_texture_filter_anisotropic2];
700
700
  pname = ext && ext.TEXTURE_MAX_ANISOTROPY_EXT || import_constants2.GL.TEXTURE_MAX_ANISOTROPY_EXT;
@@ -704,50 +704,50 @@ var WEBGL2_CONTEXT_OVERRIDES = {
704
704
  return originalFunc(target, pname);
705
705
  },
706
706
  getParameter: getParameterPolyfill,
707
- hint(gl2, originalFunc, pname, value) {
707
+ hint(gl, originalFunc, pname, value) {
708
708
  return originalFunc(pname, value);
709
709
  }
710
710
  };
711
711
 
712
712
  // src/context/polyfill/polyfill-context.ts
713
- function polyfillContext(gl2) {
714
- const contextState = getContextData(gl2);
713
+ function polyfillContext(gl) {
714
+ const contextState = getContextData(gl);
715
715
  if (!contextState._polyfilled) {
716
- polyfillVertexArrayObject(gl2);
717
- initializeExtensions(gl2);
718
- installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
719
- installOverrides(gl2, { target: contextState, target2: gl2 });
716
+ polyfillVertexArrayObject(gl);
717
+ initializeExtensions(gl);
718
+ installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
719
+ installOverrides(gl, { target: contextState, target2: gl });
720
720
  contextState._polyfilled = true;
721
721
  }
722
- return gl2;
722
+ return gl;
723
723
  }
724
- function initializeExtensions(gl2) {
725
- const contextState = getContextData(gl2);
726
- const EXTENSIONS = gl2.getSupportedExtensions() || [];
724
+ function initializeExtensions(gl) {
725
+ const contextState = getContextData(gl);
726
+ const EXTENSIONS = gl.getSupportedExtensions() || [];
727
727
  for (const extensionName of EXTENSIONS) {
728
- const extension = gl2.getExtension(extensionName);
728
+ const extension = gl.getExtension(extensionName);
729
729
  contextState._extensions[extensionName] = extension;
730
730
  }
731
731
  }
732
- function installPolyfills(gl2, polyfills) {
733
- const contextState = getContextData(gl2);
732
+ function installPolyfills(gl, polyfills) {
733
+ const contextState = getContextData(gl);
734
734
  for (const extension of Object.getOwnPropertyNames(polyfills)) {
735
735
  if (extension !== "overrides") {
736
- polyfillExtension(gl2, { extension, target: contextState, target2: gl2 });
736
+ polyfillExtension(gl, { extension, target: contextState, target2: gl });
737
737
  }
738
738
  }
739
739
  }
740
- function polyfillExtension(gl2, { extension, target, target2 }) {
740
+ function polyfillExtension(gl, { extension, target, target2 }) {
741
741
  const defaults = WEBGL2_CONTEXT_POLYFILLS[extension];
742
742
  (0, import_core3.assert)(defaults);
743
743
  const { meta = {} } = defaults;
744
744
  const { suffix = "" } = meta;
745
- const ext = gl2.getExtension(extension);
745
+ const ext = gl.getExtension(extension);
746
746
  for (const key of Object.keys(defaults)) {
747
747
  const extKey = `${key}${suffix}`;
748
748
  let polyfill = null;
749
749
  if (key === "meta") {
750
- } else if (typeof gl2[key] === "function") {
750
+ } else if (typeof gl[key] === "function") {
751
751
  } else if (ext && typeof ext[extKey] === "function") {
752
752
  polyfill = (...args) => ext[extKey](...args);
753
753
  } else if (typeof defaults[key] === "function") {
@@ -759,12 +759,12 @@ function polyfillExtension(gl2, { extension, target, target2 }) {
759
759
  }
760
760
  }
761
761
  }
762
- function installOverrides(gl2, { target, target2 }) {
762
+ function installOverrides(gl, { target, target2 }) {
763
763
  Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
764
764
  if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
765
- const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
765
+ const originalFunc = gl[key] ? gl[key].bind(gl) : () => {
766
766
  };
767
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
767
+ const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
768
768
  target[key] = polyfill;
769
769
  target2[key] = polyfill;
770
770
  }
@@ -859,19 +859,19 @@ var GL_PARAMETER_DEFAULTS = {
859
859
  [import_constants3.GL.UNPACK_SKIP_ROWS]: 0,
860
860
  [import_constants3.GL.UNPACK_SKIP_IMAGES]: 0
861
861
  };
862
- var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
863
- var hint = (gl2, value, key) => gl2.hint(key, value);
864
- var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
865
- var bindFramebuffer = (gl2, value, key) => {
862
+ var enable = (gl, value, key) => value ? gl.enable(key) : gl.disable(key);
863
+ var hint = (gl, value, key) => gl.hint(key, value);
864
+ var pixelStorei = (gl, value, key) => gl.pixelStorei(key, value);
865
+ var bindFramebuffer = (gl, value, key) => {
866
866
  let target;
867
867
  if (key === import_constants3.GL.FRAMEBUFFER_BINDING) {
868
- target = isWebGL2(gl2) ? import_constants3.GL.DRAW_FRAMEBUFFER : import_constants3.GL.FRAMEBUFFER;
868
+ target = isWebGL2(gl) ? import_constants3.GL.DRAW_FRAMEBUFFER : import_constants3.GL.FRAMEBUFFER;
869
869
  } else {
870
870
  target = import_constants3.GL.READ_FRAMEBUFFER;
871
871
  }
872
- return gl2.bindFramebuffer(target, value);
872
+ return gl.bindFramebuffer(target, value);
873
873
  };
874
- var bindBuffer = (gl2, value, key) => {
874
+ var bindBuffer = (gl, value, key) => {
875
875
  const bindingMap = {
876
876
  [import_constants3.GL.ARRAY_BUFFER_BINDING]: import_constants3.GL.ARRAY_BUFFER,
877
877
  [import_constants3.GL.COPY_READ_BUFFER_BINDING]: import_constants3.GL.COPY_READ_BUFFER,
@@ -880,38 +880,38 @@ var bindBuffer = (gl2, value, key) => {
880
880
  [import_constants3.GL.PIXEL_UNPACK_BUFFER_BINDING]: import_constants3.GL.PIXEL_UNPACK_BUFFER
881
881
  };
882
882
  const glTarget = bindingMap[key];
883
- gl2.bindBuffer(glTarget, value);
883
+ gl.bindBuffer(glTarget, value);
884
884
  };
885
885
  function isArray(array) {
886
886
  return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
887
887
  }
888
888
  var GL_PARAMETER_SETTERS = {
889
889
  [import_constants3.GL.BLEND]: enable,
890
- [import_constants3.GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
890
+ [import_constants3.GL.BLEND_COLOR]: (gl, value) => gl.blendColor(...value),
891
891
  [import_constants3.GL.BLEND_EQUATION_RGB]: "blendEquation",
892
892
  [import_constants3.GL.BLEND_EQUATION_ALPHA]: "blendEquation",
893
893
  [import_constants3.GL.BLEND_SRC_RGB]: "blendFunc",
894
894
  [import_constants3.GL.BLEND_DST_RGB]: "blendFunc",
895
895
  [import_constants3.GL.BLEND_SRC_ALPHA]: "blendFunc",
896
896
  [import_constants3.GL.BLEND_DST_ALPHA]: "blendFunc",
897
- [import_constants3.GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
898
- [import_constants3.GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
897
+ [import_constants3.GL.COLOR_CLEAR_VALUE]: (gl, value) => gl.clearColor(...value),
898
+ [import_constants3.GL.COLOR_WRITEMASK]: (gl, value) => gl.colorMask(...value),
899
899
  [import_constants3.GL.CULL_FACE]: enable,
900
- [import_constants3.GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
900
+ [import_constants3.GL.CULL_FACE_MODE]: (gl, value) => gl.cullFace(value),
901
901
  [import_constants3.GL.DEPTH_TEST]: enable,
902
- [import_constants3.GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
903
- [import_constants3.GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
904
- [import_constants3.GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
905
- [import_constants3.GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
902
+ [import_constants3.GL.DEPTH_CLEAR_VALUE]: (gl, value) => gl.clearDepth(value),
903
+ [import_constants3.GL.DEPTH_FUNC]: (gl, value) => gl.depthFunc(value),
904
+ [import_constants3.GL.DEPTH_RANGE]: (gl, value) => gl.depthRange(...value),
905
+ [import_constants3.GL.DEPTH_WRITEMASK]: (gl, value) => gl.depthMask(value),
906
906
  [import_constants3.GL.DITHER]: enable,
907
907
  [import_constants3.GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
908
- [import_constants3.GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
909
- [import_constants3.GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(import_constants3.GL.RENDERBUFFER, value),
910
- [import_constants3.GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => {
908
+ [import_constants3.GL.CURRENT_PROGRAM]: (gl, value) => gl.useProgram(value),
909
+ [import_constants3.GL.RENDERBUFFER_BINDING]: (gl, value) => gl.bindRenderbuffer(import_constants3.GL.RENDERBUFFER, value),
910
+ [import_constants3.GL.TRANSFORM_FEEDBACK_BINDING]: (gl, value) => {
911
911
  var _a;
912
- return (_a = gl2.bindTransformFeedback) == null ? void 0 : _a.call(gl2, import_constants3.GL.TRANSFORM_FEEDBACK, value);
912
+ return (_a = gl.bindTransformFeedback) == null ? void 0 : _a.call(gl, import_constants3.GL.TRANSFORM_FEEDBACK, value);
913
913
  },
914
- [import_constants3.GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
914
+ [import_constants3.GL.VERTEX_ARRAY_BINDING]: (gl, value) => gl.bindVertexArray(value),
915
915
  // NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
916
916
  [import_constants3.GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
917
917
  [import_constants3.GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
@@ -921,9 +921,9 @@ var GL_PARAMETER_SETTERS = {
921
921
  [import_constants3.GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
922
922
  [import_constants3.GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
923
923
  [import_constants3.GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
924
- [import_constants3.GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
924
+ [import_constants3.GL.FRONT_FACE]: (gl, value) => gl.frontFace(value),
925
925
  [import_constants3.GL.GENERATE_MIPMAP_HINT]: hint,
926
- [import_constants3.GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
926
+ [import_constants3.GL.LINE_WIDTH]: (gl, value) => gl.lineWidth(value),
927
927
  [import_constants3.GL.POLYGON_OFFSET_FILL]: enable,
928
928
  [import_constants3.GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
929
929
  [import_constants3.GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
@@ -933,11 +933,11 @@ var GL_PARAMETER_SETTERS = {
933
933
  [import_constants3.GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
934
934
  [import_constants3.GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
935
935
  [import_constants3.GL.SCISSOR_TEST]: enable,
936
- [import_constants3.GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
936
+ [import_constants3.GL.SCISSOR_BOX]: (gl, value) => gl.scissor(...value),
937
937
  [import_constants3.GL.STENCIL_TEST]: enable,
938
- [import_constants3.GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
939
- [import_constants3.GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(import_constants3.GL.FRONT, value),
940
- [import_constants3.GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(import_constants3.GL.BACK, value),
938
+ [import_constants3.GL.STENCIL_CLEAR_VALUE]: (gl, value) => gl.clearStencil(value),
939
+ [import_constants3.GL.STENCIL_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(import_constants3.GL.FRONT, value),
940
+ [import_constants3.GL.STENCIL_BACK_WRITEMASK]: (gl, value) => gl.stencilMaskSeparate(import_constants3.GL.BACK, value),
941
941
  [import_constants3.GL.STENCIL_FUNC]: "stencilFuncFront",
942
942
  [import_constants3.GL.STENCIL_REF]: "stencilFuncFront",
943
943
  [import_constants3.GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
@@ -950,7 +950,7 @@ var GL_PARAMETER_SETTERS = {
950
950
  [import_constants3.GL.STENCIL_BACK_FAIL]: "stencilOpBack",
951
951
  [import_constants3.GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
952
952
  [import_constants3.GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
953
- [import_constants3.GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
953
+ [import_constants3.GL.VIEWPORT]: (gl, value) => gl.viewport(...value),
954
954
  // WEBGL1 PIXEL PACK/UNPACK MODES
955
955
  [import_constants3.GL.PACK_ALIGNMENT]: pixelStorei,
956
956
  [import_constants3.GL.UNPACK_ALIGNMENT]: pixelStorei,
@@ -968,104 +968,104 @@ var GL_PARAMETER_SETTERS = {
968
968
  [import_constants3.GL.UNPACK_SKIP_ROWS]: pixelStorei,
969
969
  [import_constants3.GL.UNPACK_SKIP_IMAGES]: pixelStorei,
970
970
  // Function-style setters
971
- framebuffer: (gl2, framebuffer) => {
971
+ framebuffer: (gl, framebuffer) => {
972
972
  const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
973
- return gl2.bindFramebuffer(import_constants3.GL.FRAMEBUFFER, handle);
973
+ return gl.bindFramebuffer(import_constants3.GL.FRAMEBUFFER, handle);
974
974
  },
975
- blend: (gl2, value) => value ? gl2.enable(import_constants3.GL.BLEND) : gl2.disable(import_constants3.GL.BLEND),
976
- blendColor: (gl2, value) => gl2.blendColor(...value),
977
- blendEquation: (gl2, args) => {
975
+ blend: (gl, value) => value ? gl.enable(import_constants3.GL.BLEND) : gl.disable(import_constants3.GL.BLEND),
976
+ blendColor: (gl, value) => gl.blendColor(...value),
977
+ blendEquation: (gl, args) => {
978
978
  const separateModes = typeof args === "number" ? [args, args] : args;
979
- gl2.blendEquationSeparate(...separateModes);
979
+ gl.blendEquationSeparate(...separateModes);
980
980
  },
981
- blendFunc: (gl2, args) => {
981
+ blendFunc: (gl, args) => {
982
982
  const separateFuncs = (args == null ? void 0 : args.length) === 2 ? [...args, ...args] : args;
983
- gl2.blendFuncSeparate(...separateFuncs);
983
+ gl.blendFuncSeparate(...separateFuncs);
984
984
  },
985
- clearColor: (gl2, value) => gl2.clearColor(...value),
986
- clearDepth: (gl2, value) => gl2.clearDepth(value),
987
- clearStencil: (gl2, value) => gl2.clearStencil(value),
988
- colorMask: (gl2, value) => gl2.colorMask(...value),
989
- cull: (gl2, value) => value ? gl2.enable(import_constants3.GL.CULL_FACE) : gl2.disable(import_constants3.GL.CULL_FACE),
990
- cullFace: (gl2, value) => gl2.cullFace(value),
991
- depthTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.DEPTH_TEST) : gl2.disable(import_constants3.GL.DEPTH_TEST),
992
- depthFunc: (gl2, value) => gl2.depthFunc(value),
993
- depthMask: (gl2, value) => gl2.depthMask(value),
994
- depthRange: (gl2, value) => gl2.depthRange(...value),
995
- dither: (gl2, value) => value ? gl2.enable(import_constants3.GL.DITHER) : gl2.disable(import_constants3.GL.DITHER),
996
- derivativeHint: (gl2, value) => {
997
- gl2.hint(import_constants3.GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
985
+ clearColor: (gl, value) => gl.clearColor(...value),
986
+ clearDepth: (gl, value) => gl.clearDepth(value),
987
+ clearStencil: (gl, value) => gl.clearStencil(value),
988
+ colorMask: (gl, value) => gl.colorMask(...value),
989
+ cull: (gl, value) => value ? gl.enable(import_constants3.GL.CULL_FACE) : gl.disable(import_constants3.GL.CULL_FACE),
990
+ cullFace: (gl, value) => gl.cullFace(value),
991
+ depthTest: (gl, value) => value ? gl.enable(import_constants3.GL.DEPTH_TEST) : gl.disable(import_constants3.GL.DEPTH_TEST),
992
+ depthFunc: (gl, value) => gl.depthFunc(value),
993
+ depthMask: (gl, value) => gl.depthMask(value),
994
+ depthRange: (gl, value) => gl.depthRange(...value),
995
+ dither: (gl, value) => value ? gl.enable(import_constants3.GL.DITHER) : gl.disable(import_constants3.GL.DITHER),
996
+ derivativeHint: (gl, value) => {
997
+ gl.hint(import_constants3.GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
998
998
  },
999
- frontFace: (gl2, value) => gl2.frontFace(value),
1000
- mipmapHint: (gl2, value) => gl2.hint(import_constants3.GL.GENERATE_MIPMAP_HINT, value),
1001
- lineWidth: (gl2, value) => gl2.lineWidth(value),
1002
- polygonOffsetFill: (gl2, value) => value ? gl2.enable(import_constants3.GL.POLYGON_OFFSET_FILL) : gl2.disable(import_constants3.GL.POLYGON_OFFSET_FILL),
1003
- polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
1004
- sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
1005
- scissorTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.SCISSOR_TEST) : gl2.disable(import_constants3.GL.SCISSOR_TEST),
1006
- scissor: (gl2, value) => gl2.scissor(...value),
1007
- stencilTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.STENCIL_TEST) : gl2.disable(import_constants3.GL.STENCIL_TEST),
1008
- stencilMask: (gl2, value) => {
999
+ frontFace: (gl, value) => gl.frontFace(value),
1000
+ mipmapHint: (gl, value) => gl.hint(import_constants3.GL.GENERATE_MIPMAP_HINT, value),
1001
+ lineWidth: (gl, value) => gl.lineWidth(value),
1002
+ polygonOffsetFill: (gl, value) => value ? gl.enable(import_constants3.GL.POLYGON_OFFSET_FILL) : gl.disable(import_constants3.GL.POLYGON_OFFSET_FILL),
1003
+ polygonOffset: (gl, value) => gl.polygonOffset(...value),
1004
+ sampleCoverage: (gl, value) => gl.sampleCoverage(...value),
1005
+ scissorTest: (gl, value) => value ? gl.enable(import_constants3.GL.SCISSOR_TEST) : gl.disable(import_constants3.GL.SCISSOR_TEST),
1006
+ scissor: (gl, value) => gl.scissor(...value),
1007
+ stencilTest: (gl, value) => value ? gl.enable(import_constants3.GL.STENCIL_TEST) : gl.disable(import_constants3.GL.STENCIL_TEST),
1008
+ stencilMask: (gl, value) => {
1009
1009
  value = isArray(value) ? value : [value, value];
1010
1010
  const [mask, backMask] = value;
1011
- gl2.stencilMaskSeparate(import_constants3.GL.FRONT, mask);
1012
- gl2.stencilMaskSeparate(import_constants3.GL.BACK, backMask);
1011
+ gl.stencilMaskSeparate(import_constants3.GL.FRONT, mask);
1012
+ gl.stencilMaskSeparate(import_constants3.GL.BACK, backMask);
1013
1013
  },
1014
- stencilFunc: (gl2, args) => {
1014
+ stencilFunc: (gl, args) => {
1015
1015
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
1016
1016
  const [func, ref, mask, backFunc, backRef, backMask] = args;
1017
- gl2.stencilFuncSeparate(import_constants3.GL.FRONT, func, ref, mask);
1018
- gl2.stencilFuncSeparate(import_constants3.GL.BACK, backFunc, backRef, backMask);
1017
+ gl.stencilFuncSeparate(import_constants3.GL.FRONT, func, ref, mask);
1018
+ gl.stencilFuncSeparate(import_constants3.GL.BACK, backFunc, backRef, backMask);
1019
1019
  },
1020
- stencilOp: (gl2, args) => {
1020
+ stencilOp: (gl, args) => {
1021
1021
  args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
1022
1022
  const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
1023
- gl2.stencilOpSeparate(import_constants3.GL.FRONT, sfail, dpfail, dppass);
1024
- gl2.stencilOpSeparate(import_constants3.GL.BACK, backSfail, backDpfail, backDppass);
1023
+ gl.stencilOpSeparate(import_constants3.GL.FRONT, sfail, dpfail, dppass);
1024
+ gl.stencilOpSeparate(import_constants3.GL.BACK, backSfail, backDpfail, backDppass);
1025
1025
  },
1026
- viewport: (gl2, value) => gl2.viewport(...value)
1026
+ viewport: (gl, value) => gl.viewport(...value)
1027
1027
  };
1028
1028
  function getValue(glEnum, values, cache) {
1029
1029
  return values[glEnum] !== void 0 ? values[glEnum] : cache[glEnum];
1030
1030
  }
1031
1031
  var GL_COMPOSITE_PARAMETER_SETTERS = {
1032
- blendEquation: (gl2, values, cache) => gl2.blendEquationSeparate(
1032
+ blendEquation: (gl, values, cache) => gl.blendEquationSeparate(
1033
1033
  getValue(import_constants3.GL.BLEND_EQUATION_RGB, values, cache),
1034
1034
  getValue(import_constants3.GL.BLEND_EQUATION_ALPHA, values, cache)
1035
1035
  ),
1036
- blendFunc: (gl2, values, cache) => gl2.blendFuncSeparate(
1036
+ blendFunc: (gl, values, cache) => gl.blendFuncSeparate(
1037
1037
  getValue(import_constants3.GL.BLEND_SRC_RGB, values, cache),
1038
1038
  getValue(import_constants3.GL.BLEND_DST_RGB, values, cache),
1039
1039
  getValue(import_constants3.GL.BLEND_SRC_ALPHA, values, cache),
1040
1040
  getValue(import_constants3.GL.BLEND_DST_ALPHA, values, cache)
1041
1041
  ),
1042
- polygonOffset: (gl2, values, cache) => gl2.polygonOffset(
1042
+ polygonOffset: (gl, values, cache) => gl.polygonOffset(
1043
1043
  getValue(import_constants3.GL.POLYGON_OFFSET_FACTOR, values, cache),
1044
1044
  getValue(import_constants3.GL.POLYGON_OFFSET_UNITS, values, cache)
1045
1045
  ),
1046
- sampleCoverage: (gl2, values, cache) => gl2.sampleCoverage(
1046
+ sampleCoverage: (gl, values, cache) => gl.sampleCoverage(
1047
1047
  getValue(import_constants3.GL.SAMPLE_COVERAGE_VALUE, values, cache),
1048
1048
  getValue(import_constants3.GL.SAMPLE_COVERAGE_INVERT, values, cache)
1049
1049
  ),
1050
- stencilFuncFront: (gl2, values, cache) => gl2.stencilFuncSeparate(
1050
+ stencilFuncFront: (gl, values, cache) => gl.stencilFuncSeparate(
1051
1051
  import_constants3.GL.FRONT,
1052
1052
  getValue(import_constants3.GL.STENCIL_FUNC, values, cache),
1053
1053
  getValue(import_constants3.GL.STENCIL_REF, values, cache),
1054
1054
  getValue(import_constants3.GL.STENCIL_VALUE_MASK, values, cache)
1055
1055
  ),
1056
- stencilFuncBack: (gl2, values, cache) => gl2.stencilFuncSeparate(
1056
+ stencilFuncBack: (gl, values, cache) => gl.stencilFuncSeparate(
1057
1057
  import_constants3.GL.BACK,
1058
1058
  getValue(import_constants3.GL.STENCIL_BACK_FUNC, values, cache),
1059
1059
  getValue(import_constants3.GL.STENCIL_BACK_REF, values, cache),
1060
1060
  getValue(import_constants3.GL.STENCIL_BACK_VALUE_MASK, values, cache)
1061
1061
  ),
1062
- stencilOpFront: (gl2, values, cache) => gl2.stencilOpSeparate(
1062
+ stencilOpFront: (gl, values, cache) => gl.stencilOpSeparate(
1063
1063
  import_constants3.GL.FRONT,
1064
1064
  getValue(import_constants3.GL.STENCIL_FAIL, values, cache),
1065
1065
  getValue(import_constants3.GL.STENCIL_PASS_DEPTH_FAIL, values, cache),
1066
1066
  getValue(import_constants3.GL.STENCIL_PASS_DEPTH_PASS, values, cache)
1067
1067
  ),
1068
- stencilOpBack: (gl2, values, cache) => gl2.stencilOpSeparate(
1068
+ stencilOpBack: (gl, values, cache) => gl.stencilOpSeparate(
1069
1069
  import_constants3.GL.BACK,
1070
1070
  getValue(import_constants3.GL.STENCIL_BACK_FAIL, values, cache),
1071
1071
  getValue(import_constants3.GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache),
@@ -1228,7 +1228,7 @@ var GL_HOOKED_SETTERS = {
1228
1228
  [import_constants3.GL.VIEWPORT]: [x, y, width, height]
1229
1229
  })
1230
1230
  };
1231
- var isEnabled = (gl2, key) => gl2.isEnabled(key);
1231
+ var isEnabled = (gl, key) => gl.isEnabled(key);
1232
1232
  var GL_PARAMETER_GETTERS = {
1233
1233
  [import_constants3.GL.BLEND]: isEnabled,
1234
1234
  [import_constants3.GL.CULL_FACE]: isEnabled,
@@ -1282,9 +1282,9 @@ var NON_CACHE_PARAMETERS = /* @__PURE__ */ new Set([
1282
1282
  ]);
1283
1283
 
1284
1284
  // src/context/parameters/unified-parameter-api.ts
1285
- function setParameters(device, parameters) {
1285
+ function setGLParameters(device, parameters) {
1286
1286
  const webglDevice = WebGLDevice.attach(device);
1287
- const gl2 = webglDevice.gl;
1287
+ const gl = webglDevice.gl;
1288
1288
  if (isObjectEmpty(parameters)) {
1289
1289
  return;
1290
1290
  }
@@ -1296,36 +1296,36 @@ function setParameters(device, parameters) {
1296
1296
  if (typeof setter === "string") {
1297
1297
  compositeSetters[setter] = true;
1298
1298
  } else {
1299
- setter(gl2, parameters[key], glConstant);
1299
+ setter(gl, parameters[key], glConstant);
1300
1300
  }
1301
1301
  }
1302
1302
  }
1303
- const cache = gl2.state && gl2.state.cache;
1303
+ const cache = gl.state && gl.state.cache;
1304
1304
  if (cache) {
1305
1305
  for (const key in compositeSetters) {
1306
1306
  const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
1307
- compositeSetter(gl2, parameters, cache);
1307
+ compositeSetter(gl, parameters, cache);
1308
1308
  }
1309
1309
  }
1310
1310
  }
1311
- function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
1311
+ function getGLParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
1312
1312
  const webglDevice = WebGLDevice.attach(device);
1313
- const gl2 = webglDevice.gl;
1313
+ const gl = webglDevice.gl;
1314
1314
  if (typeof parameters === "number") {
1315
1315
  const key = parameters;
1316
1316
  const getter = GL_PARAMETER_GETTERS[key];
1317
- return getter ? getter(gl2, key) : gl2.getParameter(key);
1317
+ return getter ? getter(gl, key) : gl.getParameter(key);
1318
1318
  }
1319
1319
  const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
1320
1320
  const state = {};
1321
1321
  for (const key of parameterKeys) {
1322
1322
  const getter = GL_PARAMETER_GETTERS[key];
1323
- state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
1323
+ state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
1324
1324
  }
1325
1325
  return state;
1326
1326
  }
1327
- function resetParameters(device) {
1328
- setParameters(device, GL_PARAMETER_DEFAULTS);
1327
+ function resetGLParameters(device) {
1328
+ setGLParameters(device, GL_PARAMETER_DEFAULTS);
1329
1329
  }
1330
1330
  function isObjectEmpty(object) {
1331
1331
  for (const key in object) {
@@ -1354,7 +1354,7 @@ function deepArrayEqual(x, y) {
1354
1354
 
1355
1355
  // src/context/state-tracker/track-context-state.ts
1356
1356
  var GLState = class {
1357
- constructor(gl2, {
1357
+ constructor(gl, {
1358
1358
  copyState = false,
1359
1359
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
1360
1360
  log: log9 = () => {
@@ -1364,8 +1364,8 @@ var GLState = class {
1364
1364
  this.program = null;
1365
1365
  this.stateStack = [];
1366
1366
  this.enable = true;
1367
- this.gl = gl2;
1368
- this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
1367
+ this.gl = gl;
1368
+ this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
1369
1369
  this.log = log9;
1370
1370
  this._updateCache = this._updateCache.bind(this);
1371
1371
  Object.seal(this);
@@ -1376,7 +1376,7 @@ var GLState = class {
1376
1376
  pop() {
1377
1377
  (0, import_core4.assert)(this.stateStack.length > 0);
1378
1378
  const oldValues = this.stateStack[this.stateStack.length - 1];
1379
- setParameters(this.gl, oldValues);
1379
+ setGLParameters(this.gl, oldValues);
1380
1380
  this.stateStack.pop();
1381
1381
  }
1382
1382
  /**
@@ -1405,46 +1405,46 @@ var GLState = class {
1405
1405
  return { valueChanged, oldValue };
1406
1406
  }
1407
1407
  };
1408
- function getContextState(gl2) {
1409
- return gl2.state;
1408
+ function getContextState(gl) {
1409
+ return gl.state;
1410
1410
  }
1411
- function trackContextState(gl2, options) {
1411
+ function trackContextState(gl, options) {
1412
1412
  const { enable: enable2 = true, copyState } = options;
1413
1413
  (0, import_core4.assert)(copyState !== void 0);
1414
- if (!gl2.state) {
1415
- gl2.state = new GLState(gl2, { copyState });
1416
- installProgramSpy(gl2);
1414
+ if (!gl.state) {
1415
+ gl.state = new GLState(gl, { copyState });
1416
+ installProgramSpy(gl);
1417
1417
  for (const key in GL_HOOKED_SETTERS) {
1418
1418
  const setter = GL_HOOKED_SETTERS[key];
1419
- installSetterSpy(gl2, key, setter);
1419
+ installSetterSpy(gl, key, setter);
1420
1420
  }
1421
- installGetterOverride(gl2, "getParameter");
1422
- installGetterOverride(gl2, "isEnabled");
1421
+ installGetterOverride(gl, "getParameter");
1422
+ installGetterOverride(gl, "isEnabled");
1423
1423
  }
1424
- const glState = getContextState(gl2);
1424
+ const glState = getContextState(gl);
1425
1425
  glState.enable = enable2;
1426
- return gl2;
1426
+ return gl;
1427
1427
  }
1428
- function pushContextState(gl2) {
1429
- let glState = getContextState(gl2);
1428
+ function pushContextState(gl) {
1429
+ let glState = getContextState(gl);
1430
1430
  if (!glState) {
1431
- trackContextState(gl2, { copyState: false });
1432
- glState = getContextState(gl2);
1431
+ trackContextState(gl, { copyState: false });
1432
+ glState = getContextState(gl);
1433
1433
  }
1434
1434
  glState.push();
1435
1435
  }
1436
- function popContextState(gl2) {
1437
- const glState = getContextState(gl2);
1436
+ function popContextState(gl) {
1437
+ const glState = getContextState(gl);
1438
1438
  (0, import_core4.assert)(glState);
1439
1439
  glState.pop();
1440
1440
  }
1441
- function installGetterOverride(gl2, functionName) {
1442
- const originalGetterFunc = gl2[functionName].bind(gl2);
1443
- gl2[functionName] = function get(pname) {
1441
+ function installGetterOverride(gl, functionName) {
1442
+ const originalGetterFunc = gl[functionName].bind(gl);
1443
+ gl[functionName] = function get(pname) {
1444
1444
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
1445
1445
  return originalGetterFunc(pname);
1446
1446
  }
1447
- const glState = getContextState(gl2);
1447
+ const glState = getContextState(gl);
1448
1448
  if (!(pname in glState.cache)) {
1449
1449
  glState.cache[pname] = originalGetterFunc(pname);
1450
1450
  }
@@ -1456,33 +1456,33 @@ function installGetterOverride(gl2, functionName) {
1456
1456
  originalGetterFunc(pname)
1457
1457
  );
1458
1458
  };
1459
- Object.defineProperty(gl2[functionName], "name", {
1459
+ Object.defineProperty(gl[functionName], "name", {
1460
1460
  value: `${functionName}-from-cache`,
1461
1461
  configurable: false
1462
1462
  });
1463
1463
  }
1464
- function installSetterSpy(gl2, functionName, setter) {
1465
- if (!gl2[functionName]) {
1464
+ function installSetterSpy(gl, functionName, setter) {
1465
+ if (!gl[functionName]) {
1466
1466
  return;
1467
1467
  }
1468
- const originalSetterFunc = gl2[functionName].bind(gl2);
1469
- gl2[functionName] = function set(...params) {
1470
- const glState = getContextState(gl2);
1468
+ const originalSetterFunc = gl[functionName].bind(gl);
1469
+ gl[functionName] = function set(...params) {
1470
+ const glState = getContextState(gl);
1471
1471
  const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
1472
1472
  if (valueChanged) {
1473
1473
  originalSetterFunc(...params);
1474
1474
  }
1475
1475
  return oldValue;
1476
1476
  };
1477
- Object.defineProperty(gl2[functionName], "name", {
1477
+ Object.defineProperty(gl[functionName], "name", {
1478
1478
  value: `${functionName}-to-cache`,
1479
1479
  configurable: false
1480
1480
  });
1481
1481
  }
1482
- function installProgramSpy(gl2) {
1483
- const originalUseProgram = gl2.useProgram.bind(gl2);
1484
- gl2.useProgram = function useProgramLuma(handle) {
1485
- const glState = getContextState(gl2);
1482
+ function installProgramSpy(gl) {
1483
+ const originalUseProgram = gl.useProgram.bind(gl);
1484
+ gl.useProgram = function useProgramLuma(handle) {
1485
+ const glState = getContextState(gl);
1486
1486
  if (glState.program !== handle) {
1487
1487
  originalUseProgram(handle);
1488
1488
  glState.program = handle;
@@ -1508,21 +1508,21 @@ function createBrowserContext(canvas, props) {
1508
1508
  let errorMessage = null;
1509
1509
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
1510
1510
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
1511
- let gl2 = null;
1511
+ let gl = null;
1512
1512
  if (props.type === "webgl2") {
1513
1513
  props = __spreadProps(__spreadValues({}, props), { webgl1: false });
1514
1514
  }
1515
1515
  if (props.type === "webgl1") {
1516
1516
  props = __spreadProps(__spreadValues({}, props), { webgl2: false });
1517
1517
  }
1518
- if (!gl2 && props.webgl2) {
1519
- gl2 = canvas.getContext("webgl2", props);
1518
+ if (!gl && props.webgl2) {
1519
+ gl = canvas.getContext("webgl2", props);
1520
1520
  }
1521
- if (!gl2 && props.webgl1) {
1522
- gl2 = canvas.getContext("webgl", props);
1521
+ if (!gl && props.webgl1) {
1522
+ gl = canvas.getContext("webgl", props);
1523
1523
  }
1524
1524
  canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
1525
- if (!gl2) {
1525
+ if (!gl) {
1526
1526
  throw new Error(
1527
1527
  `Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`
1528
1528
  );
@@ -1539,29 +1539,29 @@ function createBrowserContext(canvas, props) {
1539
1539
  false
1540
1540
  );
1541
1541
  }
1542
- return gl2;
1542
+ return gl;
1543
1543
  }
1544
1544
 
1545
1545
  // src/adapter/device-helpers/get-device-info.ts
1546
1546
  var import_constants4 = require("@luma.gl/constants");
1547
- function getDeviceInfo(gl2) {
1548
- const vendorMasked = gl2.getParameter(import_constants4.GL.VENDOR);
1549
- const rendererMasked = gl2.getParameter(import_constants4.GL.RENDERER);
1550
- const ext = gl2.getExtension("WEBGL_debug_renderer_info");
1551
- const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : import_constants4.GL.VENDOR);
1552
- const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : import_constants4.GL.RENDERER);
1547
+ function getDeviceInfo(gl) {
1548
+ const vendorMasked = gl.getParameter(import_constants4.GL.VENDOR);
1549
+ const rendererMasked = gl.getParameter(import_constants4.GL.RENDERER);
1550
+ const ext = gl.getExtension("WEBGL_debug_renderer_info");
1551
+ const vendorUnmasked = gl.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : import_constants4.GL.VENDOR);
1552
+ const rendererUnmasked = gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : import_constants4.GL.RENDERER);
1553
1553
  const vendor = vendorUnmasked || vendorMasked;
1554
1554
  const renderer = rendererUnmasked || rendererMasked;
1555
1555
  const gpu = identifyGPUVendor(vendor, renderer);
1556
1556
  return {
1557
- type: isWebGL2(gl2) ? "webgl2" : "webgl",
1557
+ type: isWebGL2(gl) ? "webgl2" : "webgl",
1558
1558
  gpu,
1559
1559
  vendor: vendorUnmasked || vendorMasked,
1560
1560
  renderer: rendererUnmasked || rendererMasked,
1561
- version: gl2.getParameter(import_constants4.GL.VERSION),
1561
+ version: gl.getParameter(import_constants4.GL.VERSION),
1562
1562
  shadingLanguages: ["glsl"],
1563
1563
  shadingLanguageVersions: {
1564
- "glsl": gl2.getParameter(import_constants4.GL.SHADING_LANGUAGE_VERSION)
1564
+ "glsl": gl.getParameter(import_constants4.GL.SHADING_LANGUAGE_VERSION)
1565
1565
  }
1566
1566
  };
1567
1567
  }
@@ -1649,39 +1649,39 @@ var EXT_SRGB = "EXT_sRGB";
1649
1649
  var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
1650
1650
  var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
1651
1651
  var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
1652
- var checkExtension = (gl2, extension) => gl2.getExtension(extension);
1653
- var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
1652
+ var checkExtension = (gl, extension) => gl.getExtension(extension);
1653
+ var checkExtensions = (gl, extensions) => extensions.every((extension) => gl.getExtension(extension));
1654
1654
  var TEXTURE_FEATURE_CHECKS = {
1655
- "texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
1656
- "texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
1657
- "texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
1658
- "texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
1659
- "texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
1660
- "texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
1661
- "texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
1662
- "texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
1663
- "texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
1664
- "texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
1655
+ "texture-blend-float-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "EXT_float_blend"),
1656
+ "texture-formats-srgb-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, EXT_SRGB),
1657
+ "texture-formats-depth-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "WEBGL_depth_texture"),
1658
+ "texture-formats-float32-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_float"),
1659
+ "texture-formats-float16-webgl1": (gl) => isWebGL2(gl) ? true : checkExtension(gl, "OES_texture_half_float"),
1660
+ "texture-formats-norm16-webgl": (gl) => isWebGL2(gl) ? checkExtension(gl, EXT_TEXTURE_NORM16) : false,
1661
+ "texture-filter-linear-float32-webgl": (gl) => checkExtension(gl, "OES_texture_float_linear"),
1662
+ "texture-filter-linear-float16-webgl": (gl) => checkExtension(gl, "OES_texture_half_float_linear"),
1663
+ "texture-filter-anisotropic-webgl": (gl) => checkExtension(gl, "EXT_texture_filter_anisotropic"),
1664
+ "texture-renderable-float32-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_float"),
1665
1665
  // [false, 'EXT_color_buffer_float'],
1666
- "texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
1667
- "texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
1668
- "texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
1666
+ "texture-renderable-float16-webgl": (gl) => checkExtension(gl, "EXT_color_buffer_half_float"),
1667
+ "texture-compression-bc": (gl) => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
1668
+ "texture-compression-bc5-webgl": (gl) => checkExtensions(gl, [X_RGTC]),
1669
1669
  // 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
1670
1670
  // 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
1671
1671
  // 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
1672
- "texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
1673
- "texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
1674
- "texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
1675
- "texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
1676
- "texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
1672
+ "texture-compression-etc2": (gl) => checkExtensions(gl, [X_ETC2]),
1673
+ "texture-compression-astc": (gl) => checkExtensions(gl, [X_ASTC]),
1674
+ "texture-compression-etc1-webgl": (gl) => checkExtensions(gl, [X_ETC1]),
1675
+ "texture-compression-pvrtc-webgl": (gl) => checkExtensions(gl, [X_PVRTC]),
1676
+ "texture-compression-atc-webgl": (gl) => checkExtensions(gl, [X_ATC])
1677
1677
  };
1678
- function checkTextureFeature(gl2, feature) {
1678
+ function checkTextureFeature(gl, feature) {
1679
1679
  var _a;
1680
- return ((_a = TEXTURE_FEATURE_CHECKS[feature]) == null ? void 0 : _a.call(TEXTURE_FEATURE_CHECKS, gl2)) || false;
1680
+ return ((_a = TEXTURE_FEATURE_CHECKS[feature]) == null ? void 0 : _a.call(TEXTURE_FEATURE_CHECKS, gl)) || false;
1681
1681
  }
1682
- function getTextureFeatures(gl2) {
1682
+ function getTextureFeatures(gl) {
1683
1683
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
1684
- return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
1684
+ return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
1685
1685
  }
1686
1686
  var TEXTURE_FORMATS = {
1687
1687
  // Unsized formats that leave the precision up to the driver.
@@ -1889,24 +1889,24 @@ var TYPE_SIZES = {
1889
1889
  [import_constants6.GL.BYTE]: 1,
1890
1890
  [import_constants6.GL.UNSIGNED_BYTE]: 1
1891
1891
  };
1892
- function isTextureFormatSupported(gl2, formatOrGL) {
1892
+ function isTextureFormatSupported(gl, formatOrGL) {
1893
1893
  const format = convertGLToTextureFormat(formatOrGL);
1894
1894
  const info = TEXTURE_FORMATS[format];
1895
1895
  if (!info) {
1896
1896
  return false;
1897
1897
  }
1898
- if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
1898
+ if (isWebGL2(gl) ? info.gl === void 0 : info.gl1 === void 0) {
1899
1899
  return false;
1900
1900
  }
1901
- const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
1901
+ const extension = info.x || (isWebGL2(gl) ? info.gl2ext || info.gl1ext : info.gl1ext);
1902
1902
  if (extension) {
1903
- return Boolean(gl2.getExtension(extension));
1903
+ return Boolean(gl.getExtension(extension));
1904
1904
  }
1905
1905
  return true;
1906
1906
  }
1907
- function isRenderbufferFormatSupported(gl2, format) {
1907
+ function isRenderbufferFormatSupported(gl, format) {
1908
1908
  var _a;
1909
- return isTextureFormatSupported(gl2, format) && ((_a = TEXTURE_FORMATS[format]) == null ? void 0 : _a.renderbuffer);
1909
+ return isTextureFormatSupported(gl, format) && ((_a = TEXTURE_FORMATS[format]) == null ? void 0 : _a.renderbuffer);
1910
1910
  }
1911
1911
  function convertGLToTextureFormat(format) {
1912
1912
  if (typeof format === "string") {
@@ -1928,9 +1928,9 @@ function convertTextureFormatToGL(format, isWebGL23) {
1928
1928
  }
1929
1929
  return webglFormat;
1930
1930
  }
1931
- function isTextureFormatFilterable(gl2, formatOrGL) {
1931
+ function isTextureFormatFilterable(gl, formatOrGL) {
1932
1932
  const format = convertGLToTextureFormat(formatOrGL);
1933
- if (!isTextureFormatSupported(gl2, format)) {
1933
+ if (!isTextureFormatSupported(gl, format)) {
1934
1934
  return false;
1935
1935
  }
1936
1936
  try {
@@ -1942,16 +1942,16 @@ function isTextureFormatFilterable(gl2, formatOrGL) {
1942
1942
  return false;
1943
1943
  }
1944
1944
  if (format.endsWith("32float")) {
1945
- return Boolean(gl2.getExtension("OES_texture_float_linear"));
1945
+ return Boolean(gl.getExtension("OES_texture_float_linear"));
1946
1946
  }
1947
1947
  if (format.endsWith("16float")) {
1948
- return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
1948
+ return Boolean(gl.getExtension("OES_texture_half_float_linear"));
1949
1949
  }
1950
1950
  return true;
1951
1951
  }
1952
- function isTextureFormatRenderable(gl2, formatOrGL) {
1952
+ function isTextureFormatRenderable(gl, formatOrGL) {
1953
1953
  const format = convertGLToTextureFormat(formatOrGL);
1954
- if (!isTextureFormatSupported(gl2, format)) {
1954
+ if (!isTextureFormatSupported(gl, format)) {
1955
1955
  return false;
1956
1956
  }
1957
1957
  if (typeof format === "number") {
@@ -1984,19 +1984,19 @@ function getDepthStencilAttachmentWebGL(format) {
1984
1984
  }
1985
1985
  return info.attachment;
1986
1986
  }
1987
- function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = import_constants6.GL.RGBA, srcType = import_constants6.GL.UNSIGNED_BYTE) {
1987
+ function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat = import_constants6.GL.RGBA, srcType = import_constants6.GL.UNSIGNED_BYTE) {
1988
1988
  let texture = null;
1989
1989
  let framebuffer = null;
1990
1990
  try {
1991
- texture = gl2.createTexture();
1992
- gl2.bindTexture(import_constants6.GL.TEXTURE_2D, texture);
1991
+ texture = gl.createTexture();
1992
+ gl.bindTexture(import_constants6.GL.TEXTURE_2D, texture);
1993
1993
  const level = 0;
1994
1994
  const width = 1;
1995
1995
  const height = 1;
1996
1996
  const border = 0;
1997
1997
  const pixel = new Uint8Array([0, 0, 255, 255]);
1998
- gl2.texImage2D(
1999
- gl2.TEXTURE_2D,
1998
+ gl.texImage2D(
1999
+ gl.TEXTURE_2D,
2000
2000
  level,
2001
2001
  internalFormat,
2002
2002
  width,
@@ -2006,15 +2006,15 @@ function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat
2006
2006
  srcType,
2007
2007
  pixel
2008
2008
  );
2009
- framebuffer = gl2.createFramebuffer();
2010
- gl2.bindFramebuffer(import_constants6.GL.FRAMEBUFFER, framebuffer);
2011
- gl2.framebufferTexture2D(import_constants6.GL.FRAMEBUFFER, import_constants6.GL.COLOR_ATTACHMENT0, import_constants6.GL.TEXTURE_2D, texture, 0);
2012
- const status = gl2.checkFramebufferStatus(import_constants6.GL.FRAMEBUFFER) === import_constants6.GL.FRAMEBUFFER_COMPLETE;
2013
- gl2.bindTexture(import_constants6.GL.TEXTURE_2D, null);
2009
+ framebuffer = gl.createFramebuffer();
2010
+ gl.bindFramebuffer(import_constants6.GL.FRAMEBUFFER, framebuffer);
2011
+ gl.framebufferTexture2D(import_constants6.GL.FRAMEBUFFER, import_constants6.GL.COLOR_ATTACHMENT0, import_constants6.GL.TEXTURE_2D, texture, 0);
2012
+ const status = gl.checkFramebufferStatus(import_constants6.GL.FRAMEBUFFER) === import_constants6.GL.FRAMEBUFFER_COMPLETE;
2013
+ gl.bindTexture(import_constants6.GL.TEXTURE_2D, null);
2014
2014
  return status;
2015
2015
  } finally {
2016
- gl2.deleteTexture(texture);
2017
- gl2.deleteFramebuffer(framebuffer);
2016
+ gl.deleteTexture(texture);
2017
+ gl.deleteFramebuffer(framebuffer);
2018
2018
  }
2019
2019
  }
2020
2020
  function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
@@ -2043,50 +2043,50 @@ function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
2043
2043
  }
2044
2044
 
2045
2045
  // src/adapter/device-helpers/device-features.ts
2046
- function getDeviceFeatures(gl2) {
2047
- const features = getWebGLFeatures(gl2);
2048
- for (const textureFeature of getTextureFeatures(gl2)) {
2046
+ function getDeviceFeatures(gl) {
2047
+ const features = getWebGLFeatures(gl);
2048
+ for (const textureFeature of getTextureFeatures(gl)) {
2049
2049
  features.add(textureFeature);
2050
2050
  }
2051
2051
  return features;
2052
2052
  }
2053
- function getWebGLFeatures(gl2) {
2054
- gl2.getExtension("EXT_color_buffer_float");
2055
- gl2.getExtension("WEBGL_color_buffer_float");
2056
- gl2.getExtension("EXT_float_blend");
2053
+ function getWebGLFeatures(gl) {
2054
+ gl.getExtension("EXT_color_buffer_float");
2055
+ gl.getExtension("WEBGL_color_buffer_float");
2056
+ gl.getExtension("EXT_float_blend");
2057
2057
  const features = /* @__PURE__ */ new Set();
2058
2058
  for (const feature of Object.keys(WEBGL_FEATURES)) {
2059
- if (isFeatureSupported(gl2, feature)) {
2059
+ if (isFeatureSupported(gl, feature)) {
2060
2060
  features.add(feature);
2061
2061
  }
2062
2062
  }
2063
2063
  return features;
2064
2064
  }
2065
- function isFeatureSupported(gl2, feature) {
2065
+ function isFeatureSupported(gl, feature) {
2066
2066
  const featureInfo = WEBGL_FEATURES[feature];
2067
2067
  if (!featureInfo) {
2068
2068
  return false;
2069
2069
  }
2070
2070
  const [webgl1Feature, webgl2Feature] = featureInfo || [];
2071
- const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
2071
+ const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
2072
2072
  if (typeof featureDefinition === "boolean") {
2073
2073
  return featureDefinition;
2074
2074
  }
2075
2075
  switch (feature) {
2076
2076
  case "texture-renderable-rgba32float-webgl":
2077
- return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
2077
+ return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl);
2078
2078
  case "glsl-derivatives":
2079
- return canCompileGLSLExtension(gl2, featureDefinition);
2079
+ return canCompileGLSLExtension(gl, featureDefinition);
2080
2080
  case "glsl-frag-data":
2081
- return canCompileGLSLExtension(gl2, featureDefinition, { behavior: "require" });
2081
+ return canCompileGLSLExtension(gl, featureDefinition, { behavior: "require" });
2082
2082
  case "glsl-frag-depth":
2083
- return canCompileGLSLExtension(gl2, featureDefinition);
2083
+ return canCompileGLSLExtension(gl, featureDefinition);
2084
2084
  default:
2085
- return Boolean(gl2.getExtension(featureDefinition));
2085
+ return Boolean(gl.getExtension(featureDefinition));
2086
2086
  }
2087
2087
  }
2088
2088
  var compiledGLSLExtensions = {};
2089
- function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
2089
+ function canCompileGLSLExtension(gl, extensionName, opts = {}) {
2090
2090
  if (!isOldIE(opts)) {
2091
2091
  return true;
2092
2092
  }
@@ -2096,14 +2096,14 @@ function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
2096
2096
  const behavior = opts.behavior || "enable";
2097
2097
  const source = `#extension GL_${extensionName} : ${behavior}
2098
2098
  void main(void) {}`;
2099
- const shader = gl2.createShader(gl2.VERTEX_SHADER);
2099
+ const shader = gl.createShader(gl.VERTEX_SHADER);
2100
2100
  if (!shader) {
2101
2101
  throw new Error("shader");
2102
2102
  }
2103
- gl2.shaderSource(shader, source);
2104
- gl2.compileShader(shader);
2105
- const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
2106
- gl2.deleteShader(shader);
2103
+ gl.shaderSource(shader, source);
2104
+ gl.compileShader(shader);
2105
+ const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
2106
+ gl.deleteShader(shader);
2107
2107
  compiledGLSLExtensions[extensionName] = canCompile;
2108
2108
  return canCompile;
2109
2109
  }
@@ -2141,38 +2141,38 @@ var WEBGL_FEATURES = {
2141
2141
 
2142
2142
  // src/adapter/device-helpers/device-limits.ts
2143
2143
  var import_constants7 = require("@luma.gl/constants");
2144
- function getDeviceLimits(gl2) {
2145
- const gl22 = getWebGL2Context(gl2);
2144
+ function getDeviceLimits(gl) {
2145
+ const gl2 = getWebGL2Context(gl);
2146
2146
  return {
2147
2147
  maxTextureDimension1D: 0,
2148
2148
  // WebGL does not support 1D textures
2149
- maxTextureDimension2D: gl2.getParameter(import_constants7.GL.MAX_TEXTURE_SIZE),
2150
- maxTextureDimension3D: gl22 ? gl22.getParameter(import_constants7.GL.MAX_3D_TEXTURE_SIZE) : 0,
2151
- maxTextureArrayLayers: gl22 ? gl22.getParameter(import_constants7.GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
2149
+ maxTextureDimension2D: gl.getParameter(import_constants7.GL.MAX_TEXTURE_SIZE),
2150
+ maxTextureDimension3D: gl2 ? gl2.getParameter(import_constants7.GL.MAX_3D_TEXTURE_SIZE) : 0,
2151
+ maxTextureArrayLayers: gl2 ? gl2.getParameter(import_constants7.GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
2152
2152
  maxBindGroups: 1,
2153
2153
  // TBD
2154
2154
  maxDynamicUniformBuffersPerPipelineLayout: 0,
2155
2155
  // TBD
2156
2156
  maxDynamicStorageBuffersPerPipelineLayout: 0,
2157
2157
  // TBD
2158
- maxSampledTexturesPerShaderStage: gl2.getParameter(import_constants7.GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
2158
+ maxSampledTexturesPerShaderStage: gl.getParameter(import_constants7.GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
2159
2159
  // TBD
2160
- maxSamplersPerShaderStage: gl2.getParameter(import_constants7.GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
2160
+ maxSamplersPerShaderStage: gl.getParameter(import_constants7.GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
2161
2161
  maxStorageBuffersPerShaderStage: 0,
2162
2162
  // TBD
2163
2163
  maxStorageTexturesPerShaderStage: 0,
2164
2164
  // TBD
2165
- maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(import_constants7.GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
2166
- maxUniformBufferBindingSize: gl22 ? gl22.getParameter(import_constants7.GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
2165
+ maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(import_constants7.GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
2166
+ maxUniformBufferBindingSize: gl2 ? gl2.getParameter(import_constants7.GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
2167
2167
  maxStorageBufferBindingSize: 0,
2168
- minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(import_constants7.GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
2168
+ minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(import_constants7.GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
2169
2169
  minStorageBufferOffsetAlignment: 0,
2170
2170
  // TBD
2171
2171
  maxVertexBuffers: 0,
2172
- maxVertexAttributes: gl2.getParameter(import_constants7.GL.MAX_VERTEX_ATTRIBS),
2172
+ maxVertexAttributes: gl.getParameter(import_constants7.GL.MAX_VERTEX_ATTRIBS),
2173
2173
  maxVertexBufferArrayStride: 2048,
2174
2174
  // TBD, this is just the default value from WebGPU
2175
- maxInterStageShaderComponents: gl22 ? gl22.getParameter(import_constants7.GL.MAX_VARYING_COMPONENTS) : 0,
2175
+ maxInterStageShaderComponents: gl2 ? gl2.getParameter(import_constants7.GL.MAX_VARYING_COMPONENTS) : 0,
2176
2176
  maxComputeWorkgroupStorageSize: 0,
2177
2177
  // WebGL does not support compute shaders
2178
2178
  maxComputeInvocationsPerWorkgroup: 0,
@@ -2187,13 +2187,13 @@ function getDeviceLimits(gl2) {
2187
2187
  // WebGL does not support compute shaders
2188
2188
  };
2189
2189
  }
2190
- function getWebGLLimits(gl2) {
2191
- const gl22 = getWebGL2Context(gl2);
2190
+ function getWebGLLimits(gl) {
2191
+ const gl2 = getWebGL2Context(gl);
2192
2192
  function get(pname) {
2193
- return gl2.getParameter(pname);
2193
+ return gl.getParameter(pname);
2194
2194
  }
2195
2195
  function get2(pname, defaultValue) {
2196
- return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
2196
+ return gl2 ? gl2.getParameter(pname) : defaultValue || 0;
2197
2197
  }
2198
2198
  return {
2199
2199
  [import_constants7.GL.ALIASED_LINE_WIDTH_RANGE]: get(import_constants7.GL.ALIASED_LINE_WIDTH_RANGE),
@@ -2296,24 +2296,24 @@ var import_core10 = require("@luma.gl/core");
2296
2296
  var import_constants12 = require("@luma.gl/constants");
2297
2297
 
2298
2298
  // src/context/state-tracker/with-parameters.ts
2299
- function withParameters(device, parameters, func) {
2299
+ function withGLParameters(device, parameters, func) {
2300
2300
  const webglDevice = WebGLDevice.attach(device);
2301
- const gl2 = webglDevice.gl;
2301
+ const gl = webglDevice.gl;
2302
2302
  if (isObjectEmpty2(parameters)) {
2303
2303
  return func(device);
2304
2304
  }
2305
2305
  const { nocatch = true } = parameters;
2306
- pushContextState(gl2);
2307
- setParameters(gl2, parameters);
2306
+ pushContextState(gl);
2307
+ setGLParameters(gl, parameters);
2308
2308
  let value;
2309
2309
  if (nocatch) {
2310
- value = func(gl2);
2311
- popContextState(gl2);
2310
+ value = func(gl);
2311
+ popContextState(gl);
2312
2312
  } else {
2313
2313
  try {
2314
- value = func(gl2);
2314
+ value = func(gl);
2315
2315
  } finally {
2316
- popContextState(gl2);
2316
+ popContextState(gl);
2317
2317
  }
2318
2318
  }
2319
2319
  return value;
@@ -2331,13 +2331,14 @@ var import_constants9 = require("@luma.gl/constants");
2331
2331
  // src/adapter/converters/device-parameters.ts
2332
2332
  var import_core6 = require("@luma.gl/core");
2333
2333
  var import_constants8 = require("@luma.gl/constants");
2334
- function withGLParameters(device, parameters, func) {
2334
+ function withDeviceAndGLParameters(device, parameters, glParameters, func) {
2335
2335
  if ((0, import_core6.isObjectEmpty)(parameters)) {
2336
2336
  return func(device);
2337
2337
  }
2338
2338
  pushContextState(device.gl);
2339
2339
  try {
2340
- setParameters(device, parameters);
2340
+ setDeviceParameters(device, parameters);
2341
+ setGLParameters(device, glParameters);
2341
2342
  return func(device);
2342
2343
  } finally {
2343
2344
  popContextState(device.gl);
@@ -2357,24 +2358,24 @@ function withDeviceParameters(device, parameters, func) {
2357
2358
  }
2358
2359
  function setDeviceParameters(device, parameters) {
2359
2360
  const webglDevice = WebGLDevice.attach(device);
2360
- const { gl: gl2 } = webglDevice;
2361
+ const { gl } = webglDevice;
2361
2362
  if (parameters.cullMode) {
2362
2363
  switch (parameters.cullMode) {
2363
2364
  case "none":
2364
- gl2.disable(import_constants8.GL.CULL_FACE);
2365
+ gl.disable(import_constants8.GL.CULL_FACE);
2365
2366
  break;
2366
2367
  case "front":
2367
- gl2.enable(import_constants8.GL.CULL_FACE);
2368
- gl2.cullFace(import_constants8.GL.FRONT);
2368
+ gl.enable(import_constants8.GL.CULL_FACE);
2369
+ gl.cullFace(import_constants8.GL.FRONT);
2369
2370
  break;
2370
2371
  case "back":
2371
- gl2.enable(import_constants8.GL.CULL_FACE);
2372
- gl2.cullFace(import_constants8.GL.BACK);
2372
+ gl.enable(import_constants8.GL.CULL_FACE);
2373
+ gl.cullFace(import_constants8.GL.BACK);
2373
2374
  break;
2374
2375
  }
2375
2376
  }
2376
2377
  if (parameters.frontFace) {
2377
- gl2.frontFace(
2378
+ gl.frontFace(
2378
2379
  map("frontFace", parameters.frontFace, {
2379
2380
  ccw: import_constants8.GL.CCW,
2380
2381
  cw: import_constants8.GL.CW
@@ -2382,19 +2383,19 @@ function setDeviceParameters(device, parameters) {
2382
2383
  );
2383
2384
  }
2384
2385
  if (parameters.depthBias !== void 0) {
2385
- gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
2386
+ gl.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
2386
2387
  }
2387
2388
  if (parameters.depthWriteEnabled !== void 0) {
2388
- gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
2389
+ gl.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
2389
2390
  }
2390
2391
  if (parameters.depthCompare) {
2391
- parameters.depthCompare !== "always" ? gl2.enable(import_constants8.GL.DEPTH_TEST) : gl2.disable(import_constants8.GL.DEPTH_TEST);
2392
- gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
2392
+ parameters.depthCompare !== "always" ? gl.enable(import_constants8.GL.DEPTH_TEST) : gl.disable(import_constants8.GL.DEPTH_TEST);
2393
+ gl.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
2393
2394
  }
2394
2395
  if (parameters.stencilWriteMask) {
2395
2396
  const mask = parameters.stencilWriteMask;
2396
- gl2.stencilMaskSeparate(import_constants8.GL.FRONT, mask);
2397
- gl2.stencilMaskSeparate(import_constants8.GL.BACK, mask);
2397
+ gl.stencilMaskSeparate(import_constants8.GL.FRONT, mask);
2398
+ gl.stencilMaskSeparate(import_constants8.GL.BACK, mask);
2398
2399
  }
2399
2400
  if (parameters.stencilReadMask) {
2400
2401
  import_core6.log.warn("stencilReadMask not supported under WebGL");
@@ -2402,9 +2403,9 @@ function setDeviceParameters(device, parameters) {
2402
2403
  if (parameters.stencilCompare) {
2403
2404
  const mask = parameters.stencilReadMask || 4294967295;
2404
2405
  const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
2405
- parameters.stencilCompare !== "always" ? gl2.enable(import_constants8.GL.STENCIL_TEST) : gl2.disable(import_constants8.GL.STENCIL_TEST);
2406
- gl2.stencilFuncSeparate(import_constants8.GL.FRONT, glValue, 0, mask);
2407
- gl2.stencilFuncSeparate(import_constants8.GL.BACK, glValue, 0, mask);
2406
+ parameters.stencilCompare !== "always" ? gl.enable(import_constants8.GL.STENCIL_TEST) : gl.disable(import_constants8.GL.STENCIL_TEST);
2407
+ gl.stencilFuncSeparate(import_constants8.GL.FRONT, glValue, 0, mask);
2408
+ gl.stencilFuncSeparate(import_constants8.GL.BACK, glValue, 0, mask);
2408
2409
  }
2409
2410
  if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
2410
2411
  const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
@@ -2413,8 +2414,8 @@ function setDeviceParameters(device, parameters) {
2413
2414
  "stencilDepthFailOperation",
2414
2415
  parameters.stencilDepthFailOperation
2415
2416
  );
2416
- gl2.stencilOpSeparate(import_constants8.GL.FRONT, sfail, dpfail, dppass);
2417
- gl2.stencilOpSeparate(import_constants8.GL.BACK, sfail, dpfail, dppass);
2417
+ gl.stencilOpSeparate(import_constants8.GL.FRONT, sfail, dpfail, dppass);
2418
+ gl.stencilOpSeparate(import_constants8.GL.BACK, sfail, dpfail, dppass);
2418
2419
  }
2419
2420
  }
2420
2421
  function convertCompareFunction(parameter, value) {
@@ -2903,7 +2904,7 @@ var _WEBGLTexture = class extends import_core10.Texture {
2903
2904
  }
2904
2905
  this.mipmaps = true;
2905
2906
  this.gl.bindTexture(this.target, this.handle);
2906
- withParameters(this.gl, params, () => {
2907
+ withGLParameters(this.gl, params, () => {
2907
2908
  this.gl.generateMipmap(this.target);
2908
2909
  });
2909
2910
  this.gl.bindTexture(this.target, null);
@@ -2963,18 +2964,18 @@ var _WEBGLTexture = class extends import_core10.Texture {
2963
2964
  width,
2964
2965
  height
2965
2966
  }));
2966
- const { gl: gl2 } = this;
2967
- gl2.bindTexture(this.target, this.handle);
2967
+ const { gl } = this;
2968
+ gl.bindTexture(this.target, this.handle);
2968
2969
  let dataType = null;
2969
2970
  ({ data, dataType } = this._getDataType({ data, compressed }));
2970
- let gl22;
2971
- withParameters(this.gl, parameters, () => {
2971
+ let gl2;
2972
+ withGLParameters(this.gl, parameters, () => {
2972
2973
  switch (dataType) {
2973
2974
  case "null":
2974
- gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
2975
+ gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
2975
2976
  break;
2976
2977
  case "typed-array":
2977
- gl2.texImage2D(
2978
+ gl.texImage2D(
2978
2979
  target,
2979
2980
  level,
2980
2981
  glFormat,
@@ -2990,9 +2991,9 @@ var _WEBGLTexture = class extends import_core10.Texture {
2990
2991
  );
2991
2992
  break;
2992
2993
  case "buffer":
2993
- gl22 = this.device.assertWebGL2();
2994
- gl22.bindBuffer(import_constants12.GL.PIXEL_UNPACK_BUFFER, data.handle || data);
2995
- gl22.texImage2D(
2994
+ gl2 = this.device.assertWebGL2();
2995
+ gl2.bindBuffer(import_constants12.GL.PIXEL_UNPACK_BUFFER, data.handle || data);
2996
+ gl2.texImage2D(
2996
2997
  target,
2997
2998
  level,
2998
2999
  glFormat,
@@ -3003,11 +3004,11 @@ var _WEBGLTexture = class extends import_core10.Texture {
3003
3004
  type,
3004
3005
  offset
3005
3006
  );
3006
- gl22.bindBuffer(import_constants12.GL.PIXEL_UNPACK_BUFFER, null);
3007
+ gl2.bindBuffer(import_constants12.GL.PIXEL_UNPACK_BUFFER, null);
3007
3008
  break;
3008
3009
  case "browser-object":
3009
3010
  if (this.device.isWebGL2) {
3010
- gl2.texImage2D(
3011
+ gl.texImage2D(
3011
3012
  target,
3012
3013
  level,
3013
3014
  glFormat,
@@ -3019,12 +3020,12 @@ var _WEBGLTexture = class extends import_core10.Texture {
3019
3020
  data
3020
3021
  );
3021
3022
  } else {
3022
- gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
3023
+ gl.texImage2D(target, level, glFormat, dataFormat, type, data);
3023
3024
  }
3024
3025
  break;
3025
3026
  case "compressed":
3026
3027
  for (const [levelIndex, levelData] of data.entries()) {
3027
- gl2.compressedTexImage2D(
3028
+ gl.compressedTexImage2D(
3028
3029
  target,
3029
3030
  levelIndex,
3030
3031
  levelData.format,
@@ -3092,7 +3093,7 @@ var _WEBGLTexture = class extends import_core10.Texture {
3092
3093
  data = data.handle;
3093
3094
  }
3094
3095
  this.gl.bindTexture(this.target, this.handle);
3095
- withParameters(this.gl, parameters, () => {
3096
+ withGLParameters(this.gl, parameters, () => {
3096
3097
  if (compressed) {
3097
3098
  this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
3098
3099
  } else if (data === null) {
@@ -3131,21 +3132,21 @@ var _WEBGLTexture = class extends import_core10.Texture {
3131
3132
  return this.gl.getParameter(import_constants12.GL.ACTIVE_TEXTURE) - import_constants12.GL.TEXTURE0;
3132
3133
  }
3133
3134
  bind(textureUnit = this.textureUnit) {
3134
- const { gl: gl2 } = this;
3135
+ const { gl } = this;
3135
3136
  if (textureUnit !== void 0) {
3136
3137
  this.textureUnit = textureUnit;
3137
- gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
3138
+ gl.activeTexture(gl.TEXTURE0 + textureUnit);
3138
3139
  }
3139
- gl2.bindTexture(this.target, this.handle);
3140
+ gl.bindTexture(this.target, this.handle);
3140
3141
  return textureUnit;
3141
3142
  }
3142
3143
  unbind(textureUnit = this.textureUnit) {
3143
- const { gl: gl2 } = this;
3144
+ const { gl } = this;
3144
3145
  if (textureUnit !== void 0) {
3145
3146
  this.textureUnit = textureUnit;
3146
- gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
3147
+ gl.activeTexture(gl.TEXTURE0 + textureUnit);
3147
3148
  }
3148
- gl2.bindTexture(this.target, null);
3149
+ gl.bindTexture(this.target, null);
3149
3150
  return textureUnit;
3150
3151
  }
3151
3152
  // PRIVATE METHODS
@@ -3211,7 +3212,7 @@ var _WEBGLTexture = class extends import_core10.Texture {
3211
3212
  /* eslint-disable max-statements, max-len */
3212
3213
  setCubeMapImageData(options) {
3213
3214
  return __async(this, null, function* () {
3214
- const { gl: gl2 } = this;
3215
+ const { gl } = this;
3215
3216
  const { width, height, pixels, data, format = import_constants12.GL.RGBA, type = import_constants12.GL.UNSIGNED_BYTE } = options;
3216
3217
  const imageDataMap = pixels || data;
3217
3218
  const resolvedFaces = yield Promise.all(
@@ -3227,9 +3228,9 @@ var _WEBGLTexture = class extends import_core10.Texture {
3227
3228
  }
3228
3229
  resolvedFaces[index].forEach((image, lodLevel) => {
3229
3230
  if (width && height) {
3230
- gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
3231
+ gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
3231
3232
  } else {
3232
- gl2.texImage2D(face, lodLevel, format, format, type, image);
3233
+ gl.texImage2D(face, lodLevel, format, format, type, image);
3233
3234
  }
3234
3235
  });
3235
3236
  });
@@ -3248,7 +3249,7 @@ var _WEBGLTexture = class extends import_core10.Texture {
3248
3249
  type = import_constants12.GL.UNSIGNED_BYTE
3249
3250
  // generateMipmap = false // TODO
3250
3251
  } = options;
3251
- const { gl: gl2 } = this;
3252
+ const { gl } = this;
3252
3253
  const imageData = pixels || data;
3253
3254
  this.bind();
3254
3255
  if (imageData instanceof Promise) {
@@ -3262,9 +3263,9 @@ var _WEBGLTexture = class extends import_core10.Texture {
3262
3263
  )
3263
3264
  );
3264
3265
  } else if (this.width || this.height) {
3265
- gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
3266
+ gl.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
3266
3267
  } else {
3267
- gl2.texImage2D(face, 0, format, format, type, imageData);
3268
+ gl.texImage2D(face, 0, format, format, type, imageData);
3268
3269
  }
3269
3270
  return this;
3270
3271
  }
@@ -3286,7 +3287,7 @@ var _WEBGLTexture = class extends import_core10.Texture {
3286
3287
  this.trackDeallocatedMemory("Texture");
3287
3288
  this.gl.bindTexture(this.target, this.handle);
3288
3289
  const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
3289
- withParameters(this.gl, parameters, () => {
3290
+ withGLParameters(this.gl, parameters, () => {
3290
3291
  if (ArrayBuffer.isView(data)) {
3291
3292
  this.gl.texImage3D(
3292
3293
  this.target,
@@ -3422,17 +3423,17 @@ var import_core12 = require("@luma.gl/core");
3422
3423
 
3423
3424
  // src/adapter/objects/constants-to-keys.ts
3424
3425
  var import_core11 = require("@luma.gl/core");
3425
- function getKeyValue(gl2, name2) {
3426
- if (typeof name2 !== "string") {
3427
- return name2;
3426
+ function getKeyValue(gl, name) {
3427
+ if (typeof name !== "string") {
3428
+ return name;
3428
3429
  }
3429
- const number = Number(name2);
3430
+ const number = Number(name);
3430
3431
  if (!isNaN(number)) {
3431
3432
  return number;
3432
3433
  }
3433
- name2 = name2.replace(/^.*\./, "");
3434
- const value = gl2[name2];
3435
- (0, import_core11.assert)(value !== void 0, `Accessing undefined constant GL.${name2}`);
3434
+ name = name.replace(/^.*\./, "");
3435
+ const value = gl[name];
3436
+ (0, import_core11.assert)(value !== void 0, `Accessing undefined constant GL.${name}`);
3436
3437
  return value;
3437
3438
  }
3438
3439
 
@@ -3445,11 +3446,11 @@ var WebGLResource = class extends import_core12.Resource {
3445
3446
  // Only meaningful for resources that allocate GPU memory
3446
3447
  this.byteLength = 0;
3447
3448
  this.device = WebGLDevice.attach(device);
3448
- const gl2 = this.device.gl;
3449
- assertWebGLContext(gl2);
3449
+ const gl = this.device.gl;
3450
+ assertWebGLContext(gl);
3450
3451
  const { id } = props || {};
3451
- this.gl = gl2;
3452
- this.gl2 = gl2;
3452
+ this.gl = gl;
3453
+ this.gl2 = gl;
3453
3454
  this.id = id || (0, import_core12.uid)(this.constructor.name);
3454
3455
  this._handle = props == null ? void 0 : props.handle;
3455
3456
  if (this._handle === void 0) {
@@ -3760,11 +3761,11 @@ var WEBGLFramebuffer = class extends import_core14.Framebuffer {
3760
3761
  // PRIVATE
3761
3762
  /** Check the status */
3762
3763
  _checkStatus() {
3763
- const { gl: gl2 } = this;
3764
- const prevHandle2 = gl2.bindFramebuffer(import_constants14.GL.FRAMEBUFFER, this.handle);
3765
- const status = gl2.checkFramebufferStatus(import_constants14.GL.FRAMEBUFFER);
3766
- gl2.bindFramebuffer(import_constants14.GL.FRAMEBUFFER, prevHandle2 || null);
3767
- if (status !== gl2.FRAMEBUFFER_COMPLETE) {
3764
+ const { gl } = this;
3765
+ const prevHandle = gl.bindFramebuffer(import_constants14.GL.FRAMEBUFFER, this.handle);
3766
+ const status = gl.checkFramebufferStatus(import_constants14.GL.FRAMEBUFFER);
3767
+ gl.bindFramebuffer(import_constants14.GL.FRAMEBUFFER, prevHandle || null);
3768
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
3768
3769
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
3769
3770
  }
3770
3771
  }
@@ -3833,25 +3834,25 @@ var WEBGLFramebuffer = class extends import_core14.Framebuffer {
3833
3834
  * @param level = 0 - mipmapLevel (must be 0 in WebGL1)
3834
3835
  */
3835
3836
  _attachTexture(attachment, texture, layer, level) {
3836
- const { gl: gl2, gl2: gl22 } = this.device;
3837
- gl2.bindTexture(texture.target, texture.handle);
3837
+ const { gl, gl2 } = this.device;
3838
+ gl.bindTexture(texture.target, texture.handle);
3838
3839
  switch (texture.target) {
3839
3840
  case import_constants14.GL.TEXTURE_2D_ARRAY:
3840
3841
  case import_constants14.GL.TEXTURE_3D:
3841
3842
  this.device.assertWebGL2();
3842
- gl22 == null ? void 0 : gl22.framebufferTextureLayer(import_constants14.GL.FRAMEBUFFER, attachment, texture.target, level, layer);
3843
+ gl2 == null ? void 0 : gl2.framebufferTextureLayer(import_constants14.GL.FRAMEBUFFER, attachment, texture.target, level, layer);
3843
3844
  break;
3844
3845
  case import_constants14.GL.TEXTURE_CUBE_MAP:
3845
3846
  const face = mapIndexToCubeMapFace(layer);
3846
- gl2.framebufferTexture2D(import_constants14.GL.FRAMEBUFFER, attachment, face, texture.handle, level);
3847
+ gl.framebufferTexture2D(import_constants14.GL.FRAMEBUFFER, attachment, face, texture.handle, level);
3847
3848
  break;
3848
3849
  case import_constants14.GL.TEXTURE_2D:
3849
- gl2.framebufferTexture2D(import_constants14.GL.FRAMEBUFFER, attachment, import_constants14.GL.TEXTURE_2D, texture.handle, level);
3850
+ gl.framebufferTexture2D(import_constants14.GL.FRAMEBUFFER, attachment, import_constants14.GL.TEXTURE_2D, texture.handle, level);
3850
3851
  break;
3851
3852
  default:
3852
3853
  (0, import_core14.assert)(false, "Illegal texture type");
3853
3854
  }
3854
- gl2.bindTexture(texture.target, null);
3855
+ gl.bindTexture(texture.target, null);
3855
3856
  }
3856
3857
  };
3857
3858
  function mapIndexToCubeMapFace(layer) {
@@ -3990,9 +3991,9 @@ var import_core17 = require("@luma.gl/core");
3990
3991
  var import_constants15 = require("@luma.gl/constants");
3991
3992
  var import_env = require("@probe.gl/env");
3992
3993
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
3993
- function getContextData2(gl2) {
3994
- gl2.luma = gl2.luma || {};
3995
- return gl2.luma;
3994
+ function getContextData2(gl) {
3995
+ gl.luma = gl.luma || {};
3996
+ return gl.luma;
3996
3997
  }
3997
3998
  function loadWebGLDeveloperTools() {
3998
3999
  return __async(this, null, function* () {
@@ -4003,28 +4004,28 @@ function loadWebGLDeveloperTools() {
4003
4004
  }
4004
4005
  });
4005
4006
  }
4006
- function makeDebugContext(gl2, props = {}) {
4007
- if (!gl2) {
4007
+ function makeDebugContext(gl, props = {}) {
4008
+ if (!gl) {
4008
4009
  return null;
4009
4010
  }
4010
- return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
4011
+ return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
4011
4012
  }
4012
- function getRealContext(gl2) {
4013
- const data = getContextData2(gl2);
4014
- return data.realContext ? data.realContext : gl2;
4013
+ function getRealContext(gl) {
4014
+ const data = getContextData2(gl);
4015
+ return data.realContext ? data.realContext : gl;
4015
4016
  }
4016
- function getDebugContext(gl2, props) {
4017
+ function getDebugContext(gl, props) {
4017
4018
  if (!globalThis.WebGLDebugUtils) {
4018
4019
  import_core17.log.warn("webgl-debug not loaded")();
4019
- return gl2;
4020
+ return gl;
4020
4021
  }
4021
- const data = getContextData2(gl2);
4022
+ const data = getContextData2(gl);
4022
4023
  if (data.debugContext) {
4023
4024
  return data.debugContext;
4024
4025
  }
4025
- globalThis.WebGLDebugUtils.init(__spreadValues(__spreadValues({}, import_constants15.GL), gl2));
4026
+ globalThis.WebGLDebugUtils.init(__spreadValues(__spreadValues({}, import_constants15.GL), gl));
4026
4027
  const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(
4027
- gl2,
4028
+ gl,
4028
4029
  onGLError.bind(null, props),
4029
4030
  onValidateGLFunc.bind(null, props)
4030
4031
  );
@@ -4035,10 +4036,10 @@ function getDebugContext(gl2, props) {
4035
4036
  }
4036
4037
  class WebGLDebugContext {
4037
4038
  }
4038
- Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
4039
+ Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));
4039
4040
  Object.setPrototypeOf(WebGLDebugContext, glDebug);
4040
4041
  const debugContext = Object.create(WebGLDebugContext);
4041
- data.realContext = gl2;
4042
+ data.realContext = gl;
4042
4043
  data.debugContext = debugContext;
4043
4044
  debugContext.debug = true;
4044
4045
  return debugContext;
@@ -4405,13 +4406,13 @@ var BufferWithAccessor = class extends WEBGLBuffer {
4405
4406
  */
4406
4407
  copyData(options) {
4407
4408
  const { sourceBuffer, readOffset = 0, writeOffset = 0, size } = options;
4408
- const { gl: gl2, gl2: gl22 } = this;
4409
- assertWebGL2Context(gl2);
4410
- gl2.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, sourceBuffer.handle);
4411
- gl2.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, this.handle);
4412
- gl22 == null ? void 0 : gl22.copyBufferSubData(import_constants18.GL.COPY_READ_BUFFER, import_constants18.GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
4413
- gl2.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, null);
4414
- gl2.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, null);
4409
+ const { gl, gl2 } = this;
4410
+ assertWebGL2Context(gl);
4411
+ gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, sourceBuffer.handle);
4412
+ gl.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, this.handle);
4413
+ gl2 == null ? void 0 : gl2.copyBufferSubData(import_constants18.GL.COPY_READ_BUFFER, import_constants18.GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
4414
+ gl.bindBuffer(import_constants18.GL.COPY_READ_BUFFER, null);
4415
+ gl.bindBuffer(import_constants18.GL.COPY_WRITE_BUFFER, null);
4415
4416
  this.debugData = null;
4416
4417
  return this;
4417
4418
  }
@@ -4664,15 +4665,15 @@ var WEBGLShader = class extends import_core20.Shader {
4664
4665
  const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
4665
4666
  ${source2}`;
4666
4667
  source = addGLSLVersion(source);
4667
- const { gl: gl2 } = this.device;
4668
- gl2.shaderSource(this.handle, source);
4669
- gl2.compileShader(this.handle);
4670
- const compileStatus = gl2.getShaderParameter(this.handle, import_constants19.GL.COMPILE_STATUS);
4668
+ const { gl } = this.device;
4669
+ gl.shaderSource(this.handle, source);
4670
+ gl.compileShader(this.handle);
4671
+ const compileStatus = gl.getShaderParameter(this.handle, import_constants19.GL.COMPILE_STATUS);
4671
4672
  if (!compileStatus) {
4672
- const shaderLog = gl2.getShaderInfoLog(this.handle);
4673
+ const shaderLog = gl.getShaderInfoLog(this.handle);
4673
4674
  const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
4674
4675
  const messages = parsedLog.filter((message2) => message2.type === "error");
4675
- const formattedLog = (0, import_core20.formatCompilerLog)(messages, source);
4676
+ const formattedLog = (0, import_core20.formatCompilerLog)(messages, source, { showSourceCode: true });
4676
4677
  const shaderName = getShaderInfo(source).name;
4677
4678
  const shaderDescription = `${this.stage} shader ${shaderName}`;
4678
4679
  import_core20.log.error(`GLSL compilation errors in ${shaderDescription}
@@ -4744,6 +4745,7 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4744
4745
  parameters[import_constants20.GL.STENCIL_REF] = parameters.stencilReference;
4745
4746
  }
4746
4747
  this.glParameters = glParameters;
4748
+ setGLParameters(this.device, glParameters);
4747
4749
  }
4748
4750
  // Internal
4749
4751
  /**
@@ -4765,7 +4767,7 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4765
4767
  glParameters.clearStencil = this.props.clearStencil;
4766
4768
  }
4767
4769
  if (clearMask !== 0) {
4768
- withParameters(this.device, glParameters, () => {
4770
+ withGLParameters(this.device, glParameters, () => {
4769
4771
  this.device.gl.clear(clearMask);
4770
4772
  });
4771
4773
  }
@@ -4774,7 +4776,7 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4774
4776
  * WebGL2 - clear a specific color buffer
4775
4777
  */
4776
4778
  clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
4777
- withParameters(this.device.gl2, { framebuffer: this.props.framebuffer }, () => {
4779
+ withGLParameters(this.device.gl2, { framebuffer: this.props.framebuffer }, () => {
4778
4780
  switch (value.constructor) {
4779
4781
  case Int32Array:
4780
4782
  this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);
@@ -4810,9 +4812,9 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
4810
4812
  };
4811
4813
 
4812
4814
  // src/adapter/resources/webgl-render-pipeline.ts
4815
+ var import_core22 = require("@luma.gl/core");
4813
4816
  var import_core23 = require("@luma.gl/core");
4814
- var import_core24 = require("@luma.gl/core");
4815
- var import_constants25 = require("@luma.gl/constants");
4817
+ var import_constants24 = require("@luma.gl/constants");
4816
4818
 
4817
4819
  // src/adapter/helpers/get-shader-layout.ts
4818
4820
  var import_constants22 = require("@luma.gl/constants");
@@ -4895,13 +4897,13 @@ function decodeGLAttributeType(glAttributeType) {
4895
4897
  }
4896
4898
 
4897
4899
  // src/adapter/helpers/get-shader-layout.ts
4898
- function getShaderLayout(gl2, program) {
4900
+ function getShaderLayout(gl, program) {
4899
4901
  const shaderLayout = {
4900
4902
  attributes: [],
4901
4903
  bindings: []
4902
4904
  };
4903
- shaderLayout.attributes = readAttributeDeclarations(gl2, program);
4904
- const uniformBlocks = readUniformBlocks(gl2, program);
4905
+ shaderLayout.attributes = readAttributeDeclarations(gl, program);
4906
+ const uniformBlocks = readUniformBlocks(gl, program);
4905
4907
  for (const uniformBlock of uniformBlocks) {
4906
4908
  const uniforms2 = uniformBlock.uniforms.map((uniform) => ({
4907
4909
  name: uniform.name,
@@ -4919,7 +4921,7 @@ function getShaderLayout(gl2, program) {
4919
4921
  uniforms: uniforms2
4920
4922
  });
4921
4923
  }
4922
- const uniforms = readUniformBindings(gl2, program);
4924
+ const uniforms = readUniformBindings(gl, program);
4923
4925
  let textureUnit = 0;
4924
4926
  for (const uniform of uniforms) {
4925
4927
  if (isSamplerUniform(uniform.type)) {
@@ -4938,31 +4940,31 @@ function getShaderLayout(gl2, program) {
4938
4940
  if (uniforms.length) {
4939
4941
  shaderLayout.uniforms = uniforms;
4940
4942
  }
4941
- const varyings = readVaryings(gl2, program);
4943
+ const varyings = readVaryings(gl, program);
4942
4944
  if (varyings == null ? void 0 : varyings.length) {
4943
4945
  shaderLayout.varyings = varyings;
4944
4946
  }
4945
4947
  return shaderLayout;
4946
4948
  }
4947
- function readAttributeDeclarations(gl2, program) {
4949
+ function readAttributeDeclarations(gl, program) {
4948
4950
  const attributes = [];
4949
- const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
4951
+ const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
4950
4952
  for (let index = 0; index < count; index++) {
4951
- const activeInfo = gl2.getActiveAttrib(program, index);
4953
+ const activeInfo = gl.getActiveAttrib(program, index);
4952
4954
  if (!activeInfo) {
4953
4955
  throw new Error("activeInfo");
4954
4956
  }
4955
4957
  const {
4956
- name: name2,
4958
+ name,
4957
4959
  type: compositeType
4958
4960
  /* , size*/
4959
4961
  } = activeInfo;
4960
- const location = gl2.getAttribLocation(program, name2);
4962
+ const location = gl.getAttribLocation(program, name);
4961
4963
  if (location >= 0) {
4962
4964
  const { attributeType } = decodeGLAttributeType(compositeType);
4963
- const stepMode = /instance/i.test(name2) ? "instance" : "vertex";
4965
+ const stepMode = /instance/i.test(name) ? "instance" : "vertex";
4964
4966
  attributes.push({
4965
- name: name2,
4967
+ name,
4966
4968
  location,
4967
4969
  stepMode,
4968
4970
  type: attributeType
@@ -4973,42 +4975,42 @@ function readAttributeDeclarations(gl2, program) {
4973
4975
  attributes.sort((a, b) => a.location - b.location);
4974
4976
  return attributes;
4975
4977
  }
4976
- function readVaryings(gl2, program) {
4977
- if (!isWebGL2(gl2)) {
4978
+ function readVaryings(gl, program) {
4979
+ if (!isWebGL2(gl)) {
4978
4980
  return [];
4979
4981
  }
4980
- const gl22 = gl2;
4982
+ const gl2 = gl;
4981
4983
  const varyings = [];
4982
- const count = gl2.getProgramParameter(program, import_constants22.GL.TRANSFORM_FEEDBACK_VARYINGS);
4984
+ const count = gl.getProgramParameter(program, import_constants22.GL.TRANSFORM_FEEDBACK_VARYINGS);
4983
4985
  for (let location = 0; location < count; location++) {
4984
- const activeInfo = gl22.getTransformFeedbackVarying(program, location);
4986
+ const activeInfo = gl2.getTransformFeedbackVarying(program, location);
4985
4987
  if (!activeInfo) {
4986
4988
  throw new Error("activeInfo");
4987
4989
  }
4988
- const { name: name2, type: compositeType, size } = activeInfo;
4990
+ const { name, type: compositeType, size } = activeInfo;
4989
4991
  const { glType, components } = decodeGLUniformType(compositeType);
4990
4992
  const accessor = new Accessor({ type: glType, size: size * components });
4991
- const varying = { location, name: name2, accessor };
4993
+ const varying = { location, name, accessor };
4992
4994
  varyings.push(varying);
4993
4995
  }
4994
4996
  varyings.sort((a, b) => a.location - b.location);
4995
4997
  return varyings;
4996
4998
  }
4997
- function readUniformBindings(gl2, program) {
4999
+ function readUniformBindings(gl, program) {
4998
5000
  const uniforms = [];
4999
- const uniformCount = gl2.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORMS);
5001
+ const uniformCount = gl.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORMS);
5000
5002
  for (let i = 0; i < uniformCount; i++) {
5001
- const activeInfo = gl2.getActiveUniform(program, i);
5003
+ const activeInfo = gl.getActiveUniform(program, i);
5002
5004
  if (!activeInfo) {
5003
5005
  throw new Error("activeInfo");
5004
5006
  }
5005
5007
  const { name: rawName, size, type } = activeInfo;
5006
- const { name: name2, isArray: isArray2 } = parseUniformName(rawName);
5007
- let webglLocation = gl2.getUniformLocation(program, name2);
5008
+ const { name, isArray: isArray2 } = parseUniformName(rawName);
5009
+ let webglLocation = gl.getUniformLocation(program, name);
5008
5010
  const uniformInfo = {
5009
5011
  // WebGL locations are uniquely typed but just numbers
5010
5012
  location: webglLocation,
5011
- name: name2,
5013
+ name,
5012
5014
  size,
5013
5015
  type,
5014
5016
  isArray: isArray2
@@ -5016,8 +5018,8 @@ function readUniformBindings(gl2, program) {
5016
5018
  uniforms.push(uniformInfo);
5017
5019
  if (uniformInfo.size > 1) {
5018
5020
  for (let j = 0; j < uniformInfo.size; j++) {
5019
- const elementName = `${name2}[${j}]`;
5020
- webglLocation = gl2.getUniformLocation(program, elementName);
5021
+ const elementName = `${name}[${j}]`;
5022
+ webglLocation = gl.getUniformLocation(program, elementName);
5021
5023
  const arrayElementUniformInfo = __spreadProps(__spreadValues({}, uniformInfo), {
5022
5024
  name: elementName,
5023
5025
  location: webglLocation
@@ -5028,17 +5030,17 @@ function readUniformBindings(gl2, program) {
5028
5030
  }
5029
5031
  return uniforms;
5030
5032
  }
5031
- function readUniformBlocks(gl2, program) {
5032
- if (!isWebGL2(gl2)) {
5033
+ function readUniformBlocks(gl, program) {
5034
+ if (!isWebGL2(gl)) {
5033
5035
  return [];
5034
5036
  }
5035
- const gl22 = gl2;
5036
- const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
5037
+ const gl2 = gl;
5038
+ const getBlockParameter = (blockIndex, pname) => gl2.getActiveUniformBlockParameter(program, blockIndex, pname);
5037
5039
  const uniformBlocks = [];
5038
- const blockCount = gl22.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORM_BLOCKS);
5040
+ const blockCount = gl2.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORM_BLOCKS);
5039
5041
  for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
5040
5042
  const blockInfo = {
5041
- name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
5043
+ name: gl2.getActiveUniformBlockName(program, blockIndex) || "",
5042
5044
  location: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_BINDING),
5043
5045
  byteLength: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_DATA_SIZE),
5044
5046
  vertex: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
@@ -5047,12 +5049,12 @@ function readUniformBlocks(gl2, program) {
5047
5049
  uniforms: []
5048
5050
  };
5049
5051
  const uniformIndices = getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
5050
- const uniformType = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_TYPE);
5051
- const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_SIZE);
5052
- const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_OFFSET);
5053
- const uniformStride = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_ARRAY_STRIDE);
5052
+ const uniformType = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_TYPE);
5053
+ const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_SIZE);
5054
+ const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_OFFSET);
5055
+ const uniformStride = gl2.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_ARRAY_STRIDE);
5054
5056
  for (let i = 0; i < blockInfo.uniformCount; ++i) {
5055
- const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
5057
+ const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);
5056
5058
  if (!activeInfo) {
5057
5059
  throw new Error("activeInfo");
5058
5060
  }
@@ -5097,18 +5099,18 @@ function getSamplerInfo(type) {
5097
5099
  const [viewDimension, sampleType] = sampler;
5098
5100
  return { viewDimension, sampleType };
5099
5101
  }
5100
- function parseUniformName(name2) {
5101
- if (name2[name2.length - 1] !== "]") {
5102
+ function parseUniformName(name) {
5103
+ if (name[name.length - 1] !== "]") {
5102
5104
  return {
5103
- name: name2,
5105
+ name,
5104
5106
  length: 1,
5105
5107
  isArray: false
5106
5108
  };
5107
5109
  }
5108
5110
  const UNIFORM_NAME_REGEXP = /([^[]*)(\[[0-9]+\])?/;
5109
- const matches = UNIFORM_NAME_REGEXP.exec(name2);
5111
+ const matches = UNIFORM_NAME_REGEXP.exec(name);
5110
5112
  if (!matches || matches.length < 2) {
5111
- throw new Error(`Failed to parse GLSL uniform name ${name2}`);
5113
+ throw new Error(`Failed to parse GLSL uniform name ${name}`);
5112
5114
  }
5113
5115
  return {
5114
5116
  name: matches[1],
@@ -5119,8 +5121,8 @@ function parseUniformName(name2) {
5119
5121
 
5120
5122
  // src/adapter/helpers/set-uniform.ts
5121
5123
  var import_constants23 = require("@luma.gl/constants");
5122
- function setUniform(gl2, location, type, value) {
5123
- const gl22 = gl2;
5124
+ function setUniform(gl, location, type, value) {
5125
+ const gl2 = gl;
5124
5126
  let uniformValue = value;
5125
5127
  if (uniformValue === true) {
5126
5128
  uniformValue = 1;
@@ -5148,241 +5150,64 @@ function setUniform(gl2, location, type, value) {
5148
5150
  if (typeof value !== "number") {
5149
5151
  throw new Error("samplers must be set to integers");
5150
5152
  }
5151
- return gl2.uniform1i(location, value);
5153
+ return gl.uniform1i(location, value);
5152
5154
  case import_constants23.GL.FLOAT:
5153
- return gl2.uniform1fv(location, arrayValue);
5155
+ return gl.uniform1fv(location, arrayValue);
5154
5156
  case import_constants23.GL.FLOAT_VEC2:
5155
- return gl2.uniform2fv(location, arrayValue);
5157
+ return gl.uniform2fv(location, arrayValue);
5156
5158
  case import_constants23.GL.FLOAT_VEC3:
5157
- return gl2.uniform3fv(location, arrayValue);
5159
+ return gl.uniform3fv(location, arrayValue);
5158
5160
  case import_constants23.GL.FLOAT_VEC4:
5159
- return gl2.uniform4fv(location, arrayValue);
5161
+ return gl.uniform4fv(location, arrayValue);
5160
5162
  case import_constants23.GL.INT:
5161
- return gl2.uniform1iv(location, arrayValue);
5163
+ return gl.uniform1iv(location, arrayValue);
5162
5164
  case import_constants23.GL.INT_VEC2:
5163
- return gl2.uniform2iv(location, arrayValue);
5165
+ return gl.uniform2iv(location, arrayValue);
5164
5166
  case import_constants23.GL.INT_VEC3:
5165
- return gl2.uniform3iv(location, arrayValue);
5167
+ return gl.uniform3iv(location, arrayValue);
5166
5168
  case import_constants23.GL.INT_VEC4:
5167
- return gl2.uniform4iv(location, arrayValue);
5169
+ return gl.uniform4iv(location, arrayValue);
5168
5170
  case import_constants23.GL.BOOL:
5169
- return gl2.uniform1iv(location, arrayValue);
5171
+ return gl.uniform1iv(location, arrayValue);
5170
5172
  case import_constants23.GL.BOOL_VEC2:
5171
- return gl2.uniform2iv(location, arrayValue);
5173
+ return gl.uniform2iv(location, arrayValue);
5172
5174
  case import_constants23.GL.BOOL_VEC3:
5173
- return gl2.uniform3iv(location, arrayValue);
5175
+ return gl.uniform3iv(location, arrayValue);
5174
5176
  case import_constants23.GL.BOOL_VEC4:
5175
- return gl2.uniform4iv(location, arrayValue);
5177
+ return gl.uniform4iv(location, arrayValue);
5176
5178
  case import_constants23.GL.UNSIGNED_INT:
5177
- return gl22.uniform1uiv(location, arrayValue, 1);
5179
+ return gl2.uniform1uiv(location, arrayValue, 1);
5178
5180
  case import_constants23.GL.UNSIGNED_INT_VEC2:
5179
- return gl22.uniform2uiv(location, arrayValue, 2);
5181
+ return gl2.uniform2uiv(location, arrayValue, 2);
5180
5182
  case import_constants23.GL.UNSIGNED_INT_VEC3:
5181
- return gl22.uniform3uiv(location, arrayValue, 3);
5183
+ return gl2.uniform3uiv(location, arrayValue, 3);
5182
5184
  case import_constants23.GL.UNSIGNED_INT_VEC4:
5183
- return gl22.uniform4uiv(location, arrayValue, 4);
5185
+ return gl2.uniform4uiv(location, arrayValue, 4);
5184
5186
  case import_constants23.GL.FLOAT_MAT2:
5185
- return gl2.uniformMatrix2fv(location, false, arrayValue);
5187
+ return gl.uniformMatrix2fv(location, false, arrayValue);
5186
5188
  case import_constants23.GL.FLOAT_MAT3:
5187
- return gl2.uniformMatrix3fv(location, false, arrayValue);
5189
+ return gl.uniformMatrix3fv(location, false, arrayValue);
5188
5190
  case import_constants23.GL.FLOAT_MAT4:
5189
- return gl2.uniformMatrix4fv(location, false, arrayValue);
5191
+ return gl.uniformMatrix4fv(location, false, arrayValue);
5190
5192
  case import_constants23.GL.FLOAT_MAT2x3:
5191
- return gl22.uniformMatrix2x3fv(location, false, arrayValue);
5193
+ return gl2.uniformMatrix2x3fv(location, false, arrayValue);
5192
5194
  case import_constants23.GL.FLOAT_MAT2x4:
5193
- return gl22.uniformMatrix2x4fv(location, false, arrayValue);
5195
+ return gl2.uniformMatrix2x4fv(location, false, arrayValue);
5194
5196
  case import_constants23.GL.FLOAT_MAT3x2:
5195
- return gl22.uniformMatrix3x2fv(location, false, arrayValue);
5197
+ return gl2.uniformMatrix3x2fv(location, false, arrayValue);
5196
5198
  case import_constants23.GL.FLOAT_MAT3x4:
5197
- return gl22.uniformMatrix3x4fv(location, false, arrayValue);
5199
+ return gl2.uniformMatrix3x4fv(location, false, arrayValue);
5198
5200
  case import_constants23.GL.FLOAT_MAT4x2:
5199
- return gl22.uniformMatrix4x2fv(location, false, arrayValue);
5201
+ return gl2.uniformMatrix4x2fv(location, false, arrayValue);
5200
5202
  case import_constants23.GL.FLOAT_MAT4x3:
5201
- return gl22.uniformMatrix4x3fv(location, false, arrayValue);
5203
+ return gl2.uniformMatrix4x3fv(location, false, arrayValue);
5202
5204
  }
5203
5205
  throw new Error("Illegal uniform");
5204
5206
  }
5205
5207
 
5206
- // src/adapter/objects/webgl-vertex-array-object.ts
5207
- var import_core22 = require("@luma.gl/core");
5208
- var import_constants24 = require("@luma.gl/constants");
5209
- var import_env2 = require("@probe.gl/env");
5210
- var ERR_ELEMENTS = "elements must be GL.ELEMENT_ARRAY_BUFFER";
5211
- var WEBGLVertexArrayObject = class extends WebGLResource {
5212
- // Create a VertexArray
5213
- constructor(device, props) {
5214
- super(device, props, __spreadProps(__spreadValues({}, import_core22.Resource.defaultProps), { constantAttributeZero: false }));
5215
- /** Buffer constant */
5216
- this.buffer = null;
5217
- this.bufferValue = null;
5218
- Object.seal(this);
5219
- }
5220
- get [Symbol.toStringTag]() {
5221
- return "BaseVertexArrayObject";
5222
- }
5223
- static isConstantAttributeZeroSupported(device) {
5224
- return device.info.type === "webgl2" || (0, import_env2.getBrowser)() === "Chrome";
5225
- }
5226
- destroy() {
5227
- var _a;
5228
- super.destroy();
5229
- if (this.buffer) {
5230
- (_a = this.buffer) == null ? void 0 : _a.destroy();
5231
- }
5232
- }
5233
- _createHandle() {
5234
- return this.gl2.createVertexArray();
5235
- }
5236
- _deleteHandle() {
5237
- this.gl2.deleteVertexArray(this.handle);
5238
- return [this.elements];
5239
- }
5240
- _bindHandle(handle) {
5241
- this.gl2.bindVertexArray(handle);
5242
- }
5243
- /**
5244
- * Enabling an attribute location makes it reference the currently bound buffer
5245
- * Disabling an attribute location makes it reference the global constant value
5246
- * TODO - handle single values for size 1 attributes?
5247
- * TODO - convert classic arrays based on known type?
5248
- */
5249
- enable(location, enable2 = true) {
5250
- const canDisableAttributeZero = this.device.isWebGL2 || (0, import_env2.getBrowser)() === "Chrome";
5251
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
5252
- if (enable2 || canDisableAttribute) {
5253
- location = Number(location);
5254
- this.bind(
5255
- () => enable2 ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location)
5256
- );
5257
- }
5258
- }
5259
- // Set (bind) an elements buffer, for indexed rendering.
5260
- // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
5261
- setElementBuffer(elementBuffer = null, opts = {}) {
5262
- (0, import_core22.assert)(!elementBuffer || elementBuffer.glTarget === import_constants24.GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
5263
- this.bind(() => {
5264
- this.gl.bindBuffer(import_constants24.GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
5265
- });
5266
- }
5267
- /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
5268
- setBuffer(location, buffer, accessor) {
5269
- if (buffer.glTarget === import_constants24.GL.ELEMENT_ARRAY_BUFFER) {
5270
- this.setElementBuffer(buffer, accessor);
5271
- return;
5272
- }
5273
- const { size, type, stride, offset, normalized, integer, divisor } = accessor;
5274
- const { gl: gl2, gl2: gl22 } = this;
5275
- location = Number(location);
5276
- this.bind(() => {
5277
- gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
5278
- if (integer) {
5279
- this.device.assertWebGL2();
5280
- gl22.vertexAttribIPointer(location, size, type, stride, offset);
5281
- } else {
5282
- gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
5283
- }
5284
- gl2.enableVertexAttribArray(location);
5285
- gl22.vertexAttribDivisor(location, divisor || 0);
5286
- });
5287
- }
5288
- /**
5289
- * Set an attribute to a constant value
5290
- * @param device
5291
- * @param location
5292
- * @param array
5293
- *
5294
- * @note Constants are stored globally on the WebGL context, not the VAO
5295
- * so they need to be updated before every render
5296
- * @todo - use known type (in configuration or passed in) to allow non-typed arrays?
5297
- * @todo - remember/cache values to avoid setting them unnecessarily?
5298
- */
5299
- setConstant(location, array) {
5300
- switch (array.constructor) {
5301
- case Float32Array:
5302
- setConstantFloatArray(this.device, location, array);
5303
- break;
5304
- case Int32Array:
5305
- setConstantIntArray(this.device, location, array);
5306
- break;
5307
- case Uint32Array:
5308
- setConstantUintArray(this.device, location, array);
5309
- break;
5310
- default:
5311
- (0, import_core22.assert)(false);
5312
- }
5313
- }
5314
- /**
5315
- * Provide a means to create a buffer that is equivalent to a constant.
5316
- * NOTE: Desktop OpenGL cannot disable attribute 0.
5317
- * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
5318
- * this-has-significant-performance-penalty
5319
- */
5320
- getConstantBuffer(elementCount, value) {
5321
- const constantValue = normalizeConstantArrayValue(value);
5322
- const byteLength = constantValue.byteLength * elementCount;
5323
- const length = constantValue.length * elementCount;
5324
- let updateNeeded = !this.buffer;
5325
- this.buffer = this.buffer || this.device.createBuffer({ byteLength });
5326
- updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
5327
- updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
5328
- if (updateNeeded) {
5329
- const typedArray = (0, import_core22.getScratchArray)(value.constructor, length);
5330
- (0, import_core22.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
5331
- this.buffer.subData(typedArray);
5332
- this.bufferValue = value;
5333
- }
5334
- return this.buffer;
5335
- }
5336
- };
5337
- function setConstantFloatArray(device, location, array) {
5338
- switch (array.length) {
5339
- case 1:
5340
- device.gl.vertexAttrib1fv(location, array);
5341
- break;
5342
- case 2:
5343
- device.gl.vertexAttrib2fv(location, array);
5344
- break;
5345
- case 3:
5346
- device.gl.vertexAttrib3fv(location, array);
5347
- break;
5348
- case 4:
5349
- device.gl.vertexAttrib4fv(location, array);
5350
- break;
5351
- default:
5352
- (0, import_core22.assert)(false);
5353
- }
5354
- }
5355
- function setConstantIntArray(device, location, array) {
5356
- var _a;
5357
- device.assertWebGL2();
5358
- (_a = device.gl2) == null ? void 0 : _a.vertexAttribI4iv(location, array);
5359
- }
5360
- function setConstantUintArray(device, location, array) {
5361
- var _a;
5362
- device.assertWebGL2();
5363
- (_a = device.gl2) == null ? void 0 : _a.vertexAttribI4uiv(location, array);
5364
- }
5365
- function normalizeConstantArrayValue(arrayValue) {
5366
- if (Array.isArray(arrayValue)) {
5367
- return new Float32Array(arrayValue);
5368
- }
5369
- return arrayValue;
5370
- }
5371
- function compareConstantArrayValues(v1, v2) {
5372
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
5373
- return false;
5374
- }
5375
- for (let i = 0; i < v1.length; ++i) {
5376
- if (v1[i] !== v2[i]) {
5377
- return false;
5378
- }
5379
- }
5380
- return true;
5381
- }
5382
-
5383
5208
  // src/adapter/resources/webgl-render-pipeline.ts
5384
5209
  var LOG_PROGRAM_PERF_PRIORITY = 4;
5385
- var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5210
+ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
5386
5211
  // TODO are these used?
5387
5212
  constructor(device, props) {
5388
5213
  var _a;
@@ -5391,8 +5216,6 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5391
5216
  this.uniforms = {};
5392
5217
  /** Bindings set on this model */
5393
5218
  this.bindings = {};
5394
- /** Any constant attributes */
5395
- this.constantAttributes = {};
5396
5219
  /** WebGL varyings */
5397
5220
  this.varyings = null;
5398
5221
  this._textureUniforms = {};
@@ -5402,9 +5225,9 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5402
5225
  this.device = device;
5403
5226
  this.handle = this.props.handle || this.device.gl.createProgram();
5404
5227
  this.device.setSpectorMetadata(this.handle, { id: this.props.id });
5405
- this.vs = (0, import_core23.cast)(props.vs);
5406
- this.fs = (0, import_core23.cast)(props.fs);
5407
- const { varyings, bufferMode = import_constants25.GL.SEPARATE_ATTRIBS } = props;
5228
+ this.vs = (0, import_core22.cast)(props.vs);
5229
+ this.fs = (0, import_core22.cast)(props.fs);
5230
+ const { varyings, bufferMode = import_constants24.GL.SEPARATE_ATTRIBS } = props;
5408
5231
  if (varyings && varyings.length > 0) {
5409
5232
  this.device.assertWebGL2();
5410
5233
  this.varyings = varyings;
@@ -5412,9 +5235,7 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5412
5235
  }
5413
5236
  this._compileAndLink();
5414
5237
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
5415
- this.shaderLayout = (0, import_core24.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
5416
- this.bufferLayout = props.bufferLayout || [];
5417
- this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
5238
+ this.shaderLayout = (0, import_core23.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
5418
5239
  }
5419
5240
  destroy() {
5420
5241
  if (this.handle) {
@@ -5422,83 +5243,50 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5422
5243
  this.destroyed = true;
5423
5244
  }
5424
5245
  }
5425
- setIndexBuffer(indexBuffer) {
5426
- const webglBuffer = (0, import_core23.cast)(indexBuffer);
5427
- this.vertexArrayObject.setElementBuffer(webglBuffer);
5428
- this._indexBuffer = webglBuffer;
5429
- }
5430
- /** @todo needed for portable model */
5431
- setAttributes(buffers) {
5432
- const attributeInfos = (0, import_core24.getAttributeInfosFromLayouts)(this.shaderLayout, this.bufferLayout);
5433
- for (const [bufferName, buffer] of Object.entries(buffers)) {
5434
- let set = false;
5435
- for (const attributeInfo of Object.values(attributeInfos)) {
5436
- if (attributeInfo.bufferName !== bufferName) {
5437
- continue;
5438
- }
5439
- const webglBuffer = (0, import_core23.cast)(buffer);
5440
- const glType = getGLFromVertexType(attributeInfo.bufferDataType);
5441
- import_core23.log.log(2, {
5442
- setAttribute: attributeInfo.attributeName,
5443
- toBuffer: bufferName,
5444
- size: attributeInfo.bufferComponents,
5445
- type: glType,
5446
- stride: attributeInfo.byteStride,
5447
- offset: attributeInfo.byteOffset,
5448
- normalized: attributeInfo.normalized,
5449
- // it is the shader attribute declaration, not the vertex memory format,
5450
- // that determines if the data in the buffer will be treated as integers.
5451
- // /
5452
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
5453
- // but as far as we can tell, WebGPU does not.
5454
- integer: attributeInfo.integer,
5455
- divisor: attributeInfo.stepMode === "instance" ? 1 : 0
5456
- })();
5457
- this.vertexArrayObject.setBuffer(attributeInfo.location, webglBuffer, {
5458
- size: attributeInfo.bufferComponents,
5459
- type: glType,
5460
- stride: attributeInfo.byteStride,
5461
- offset: attributeInfo.byteOffset,
5462
- normalized: attributeInfo.normalized,
5463
- // it is the shader attribute declaration, not the vertex memory format,
5464
- // that determines if the data in the buffer will be treated as integers.
5465
- // /
5466
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
5467
- // but as far as we can tell, WebGPU does not.
5468
- integer: attributeInfo.integer,
5469
- divisor: attributeInfo.stepMode === "instance" ? 1 : 0
5470
- });
5471
- set = true;
5472
- }
5473
- if (!set) {
5474
- import_core23.log.warn(
5475
- `setAttributes(): Ignoring (buffer "${buffer.id}" for unknown attribute "${name}" in pipeline "${this.id}"`
5476
- )();
5477
- }
5478
- }
5479
- }
5480
- /**
5481
- * Constant attributes are only supported in WebGL, not in WebGPU
5482
- * Any attribute that is disabled in the current vertex array object
5483
- * is read from the context's global constant value for that attribute location.
5484
- * @param attributes
5485
- */
5486
- setConstantAttributes(attributes) {
5487
- Object.assign(this.constantAttributes, attributes);
5488
- }
5246
+ // setIndexBuffer(indexBuffer: Buffer): void {
5247
+ // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
5248
+ // this.vertexArrayObject.setElementBuffer(webglBuffer);
5249
+ // this._indexBuffer = indexBuffer;
5250
+ // }
5251
+ // /** @todo needed for portable model */
5252
+ // setAttributes(attributes: Record<string, Buffer>): void {
5253
+ // for (const [name, buffer] of Object.entries(attributes)) {
5254
+ // const webglBuffer = cast<WEBGLBuffer>(buffer);
5255
+ // const attribute = getAttributeLayout(this.layout, name);
5256
+ // if (!attribute) {
5257
+ // log.warn(
5258
+ // `Ignoring buffer supplied for unknown attribute "${name}" in pipeline "${this.id}" (buffer "${buffer.id}")`
5259
+ // )();
5260
+ // continue;
5261
+ // }
5262
+ // const decoded = decodeVertexFormat(attribute.format);
5263
+ // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;
5264
+ // const divisor = attribute.stepMode === 'instance' ? 1 : 0;
5265
+ // const type = getWebGLDataType(typeString);
5266
+ // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
5267
+ // size,
5268
+ // type,
5269
+ // stride,
5270
+ // offset: 0,
5271
+ // normalized,
5272
+ // integer,
5273
+ // divisor
5274
+ // });
5275
+ // }
5276
+ // }
5489
5277
  /**
5490
5278
  * Bindings include: textures, samplers and uniform buffers
5491
5279
  * @todo needed for portable model
5492
5280
  */
5493
5281
  setBindings(bindings) {
5494
- for (const [name2, value] of Object.entries(bindings)) {
5495
- const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2);
5282
+ for (const [name, value] of Object.entries(bindings)) {
5283
+ const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name);
5496
5284
  if (!binding) {
5497
- import_core23.log.warn(`Unknown binding ${name2} in render pipeline ${this.id}`)();
5285
+ import_core22.log.warn(`Unknown binding ${name} in render pipeline ${this.id}`)();
5498
5286
  continue;
5499
5287
  }
5500
5288
  if (!value) {
5501
- import_core23.log.warn(`Unsetting binding ${name2} in render pipeline ${this.id}`)();
5289
+ import_core22.log.warn(`Unsetting binding ${name} in render pipeline ${this.id}`)();
5502
5290
  }
5503
5291
  switch (binding.type) {
5504
5292
  case "uniform":
@@ -5512,12 +5300,12 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5512
5300
  }
5513
5301
  break;
5514
5302
  case "sampler":
5515
- import_core23.log.warn(`Ignoring sampler ${name2}`)();
5303
+ import_core22.log.warn(`Ignoring sampler ${name}`)();
5516
5304
  break;
5517
5305
  default:
5518
5306
  throw new Error(binding.type);
5519
5307
  }
5520
- this.bindings[name2] = value;
5308
+ this.bindings[name] = value;
5521
5309
  }
5522
5310
  }
5523
5311
  setUniforms(uniforms) {
@@ -5531,6 +5319,7 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5531
5319
  var _a;
5532
5320
  const {
5533
5321
  renderPass,
5322
+ vertexArray,
5534
5323
  vertexCount,
5535
5324
  // indexCount,
5536
5325
  instanceCount,
@@ -5539,75 +5328,72 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5539
5328
  // firstInstance,
5540
5329
  // baseVertex
5541
5330
  } = options;
5542
- const drawMode = getGLDrawMode(this.props.topology);
5543
- const isIndexed = Boolean(this._indexBuffer);
5544
- const indexType = (_a = this._indexBuffer) == null ? void 0 : _a.glIndexType;
5545
- const isInstanced = Number(options.instanceCount) > 0;
5546
- if (!this._areTexturesRenderable() || options.vertexCount === 0) {
5331
+ const glDrawMode = getGLDrawMode(this.props.topology);
5332
+ const isIndexed = Boolean(vertexArray.indexBuffer);
5333
+ const glIndexType = (_a = vertexArray.indexBuffer) == null ? void 0 : _a.glIndexType;
5334
+ const isInstanced = Number(instanceCount) > 0;
5335
+ if (!this._areTexturesRenderable() || vertexCount === 0) {
5547
5336
  return false;
5548
5337
  }
5549
5338
  this.device.gl.useProgram(this.handle);
5550
- this.vertexArrayObject.bind(() => {
5551
- const primitiveMode = getGLPrimitive(this.props.topology);
5552
- const transformFeedback = null;
5339
+ vertexArray.bindBeforeRender(renderPass);
5340
+ const primitiveMode = getGLPrimitive(this.props.topology);
5341
+ const transformFeedback = null;
5342
+ if (transformFeedback) {
5343
+ transformFeedback.begin(primitiveMode);
5344
+ }
5345
+ this._applyBindings();
5346
+ this._applyUniforms();
5347
+ const webglRenderPass = renderPass;
5348
+ withDeviceAndGLParameters(this.device, this.props.parameters, webglRenderPass.glParameters, () => {
5349
+ var _a2, _b;
5350
+ if (isIndexed && isInstanced) {
5351
+ (_a2 = this.device.gl2) == null ? void 0 : _a2.drawElementsInstanced(
5352
+ glDrawMode,
5353
+ vertexCount || 0,
5354
+ // indexCount?
5355
+ glIndexType,
5356
+ firstVertex,
5357
+ instanceCount || 0
5358
+ );
5359
+ } else if (isIndexed) {
5360
+ this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex);
5361
+ } else if (isInstanced) {
5362
+ (_b = this.device.gl2) == null ? void 0 : _b.drawArraysInstanced(
5363
+ glDrawMode,
5364
+ firstVertex,
5365
+ vertexCount || 0,
5366
+ instanceCount || 0
5367
+ );
5368
+ } else {
5369
+ this.device.gl.drawArrays(glDrawMode, firstVertex, vertexCount || 0);
5370
+ }
5553
5371
  if (transformFeedback) {
5554
- transformFeedback.begin(primitiveMode);
5372
+ transformFeedback.end();
5555
5373
  }
5556
- this._applyBindings();
5557
- this._applyUniforms();
5558
- this._applyConstantAttributes();
5559
- const webglRenderPass = renderPass;
5560
- withDeviceParameters(this.device, this.props.parameters, () => {
5561
- withGLParameters(this.device, webglRenderPass.glParameters, () => {
5562
- var _a2, _b;
5563
- if (isIndexed && isInstanced) {
5564
- (_a2 = this.device.gl2) == null ? void 0 : _a2.drawElementsInstanced(
5565
- drawMode,
5566
- vertexCount || 0,
5567
- // indexCount?
5568
- indexType,
5569
- firstVertex,
5570
- instanceCount || 0
5571
- );
5572
- } else if (isIndexed) {
5573
- this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex);
5574
- } else if (isInstanced) {
5575
- (_b = this.device.gl2) == null ? void 0 : _b.drawArraysInstanced(
5576
- drawMode,
5577
- firstVertex,
5578
- vertexCount || 0,
5579
- instanceCount || 0
5580
- );
5581
- } else {
5582
- this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);
5583
- }
5584
- });
5585
- if (transformFeedback) {
5586
- transformFeedback.end();
5587
- }
5588
- });
5589
5374
  });
5375
+ vertexArray.unbindAfterRender(renderPass);
5590
5376
  return true;
5591
5377
  }
5592
5378
  // setAttributes(attributes: Record<string, Buffer>): void {}
5593
5379
  // setBindings(bindings: Record<string, Binding>): void {}
5594
5380
  _compileAndLink() {
5595
- const { gl: gl2 } = this.device;
5596
- gl2.attachShader(this.handle, this.vs.handle);
5597
- gl2.attachShader(this.handle, this.fs.handle);
5598
- import_core23.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5599
- gl2.linkProgram(this.handle);
5600
- import_core23.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5601
- if (gl2.debug || import_core23.log.level > 0) {
5602
- const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
5603
- if (!linked) {
5604
- throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
5605
- }
5606
- gl2.validateProgram(this.handle);
5607
- const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
5608
- if (!validated) {
5609
- throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
5610
- }
5381
+ const { gl } = this.device;
5382
+ gl.attachShader(this.handle, this.vs.handle);
5383
+ gl.attachShader(this.handle, this.fs.handle);
5384
+ import_core22.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5385
+ gl.linkProgram(this.handle);
5386
+ import_core22.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
5387
+ if (!gl.debug && import_core22.log.level === 0) {
5388
+ }
5389
+ const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);
5390
+ if (!linked) {
5391
+ throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);
5392
+ }
5393
+ gl.validateProgram(this.handle);
5394
+ const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);
5395
+ if (!validated) {
5396
+ throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);
5611
5397
  }
5612
5398
  }
5613
5399
  // PRIVATE METHODS
@@ -5634,21 +5420,22 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5634
5420
  * Any attribute that is disabled in the current vertex array object
5635
5421
  * is read from the context's global constant value for that attribute location.
5636
5422
  * @note Constant attributes are only supported in WebGL, not in WebGPU
5637
- */
5638
- _applyConstantAttributes() {
5639
- const attributeInfos = (0, import_core24.getAttributeInfosFromLayouts)(this.shaderLayout, this.bufferLayout);
5640
- for (const [name2, value] of Object.entries(this.constantAttributes)) {
5641
- const attributeInfo = attributeInfos[name2];
5423
+ *
5424
+ _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {
5425
+ const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
5426
+ for (const [name, value] of Object.entries(this.)) {
5427
+ const attributeInfo = attributeInfos[name];
5642
5428
  if (!attributeInfo) {
5643
- import_core23.log.warn(
5644
- `Ignoring constant value supplied for unknown attribute "${name2}" in pipeline "${this.id}"`
5429
+ log.warn(
5430
+ `Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`
5645
5431
  )();
5646
- continue;
5432
+ continue; // eslint-disable-line no-continue
5647
5433
  }
5648
- this.vertexArrayObject.setConstant(attributeInfo.location, value);
5649
- this.vertexArrayObject.enable(attributeInfo.location, false);
5434
+ vertexArray.setConstant(attributeInfo.location, value);
5435
+ vertexArray.enable(attributeInfo.location, false);
5650
5436
  }
5651
5437
  }
5438
+ */
5652
5439
  /** Apply any bindings (before each draw call) */
5653
5440
  _applyBindings() {
5654
5441
  this.device.gl.useProgram(this.handle);
@@ -5665,20 +5452,23 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5665
5452
  }
5666
5453
  switch (binding.type) {
5667
5454
  case "uniform":
5668
- const { name: name2 } = binding;
5669
- const location = gl2.getUniformBlockIndex(this.handle, name2);
5670
- if (location === import_constants25.GL.INVALID_INDEX) {
5671
- throw new Error(`Invalid uniform block name ${name2}`);
5455
+ const { name } = binding;
5456
+ const location = gl2.getUniformBlockIndex(this.handle, name);
5457
+ if (location === import_constants24.GL.INVALID_INDEX) {
5458
+ throw new Error(`Invalid uniform block name ${name}`);
5672
5459
  }
5673
5460
  gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);
5674
5461
  if (value instanceof WEBGLBuffer) {
5675
- gl2.bindBufferBase(import_constants25.GL.UNIFORM_BUFFER, uniformBufferIndex, value.handle);
5462
+ gl2.bindBufferBase(import_constants24.GL.UNIFORM_BUFFER, uniformBufferIndex, value.handle);
5676
5463
  } else {
5677
5464
  gl2.bindBufferRange(
5678
- import_constants25.GL.UNIFORM_BUFFER,
5465
+ import_constants24.GL.UNIFORM_BUFFER,
5679
5466
  uniformBufferIndex,
5467
+ // @ts-expect-error
5680
5468
  value.buffer.handle,
5469
+ // @ts-expect-error
5681
5470
  value.offset || 0,
5471
+ // @ts-expect-error
5682
5472
  value.size || value.buffer.byteLength - value.offset
5683
5473
  );
5684
5474
  }
@@ -5689,7 +5479,7 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5689
5479
  throw new Error("texture");
5690
5480
  }
5691
5481
  const texture = value;
5692
- gl2.activeTexture(import_constants25.GL.TEXTURE0 + textureUnit);
5482
+ gl2.activeTexture(import_constants24.GL.TEXTURE0 + textureUnit);
5693
5483
  gl2.bindTexture(texture.target, texture.handle);
5694
5484
  textureUnit += 1;
5695
5485
  break;
@@ -5708,8 +5498,8 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5708
5498
  _applyUniforms() {
5709
5499
  var _a;
5710
5500
  for (const uniformLayout of this.shaderLayout.uniforms || []) {
5711
- const { name: name2, location, type, textureUnit } = uniformLayout;
5712
- const value = (_a = this.uniforms[name2]) != null ? _a : textureUnit;
5501
+ const { name, location, type, textureUnit } = uniformLayout;
5502
+ const value = (_a = this.uniforms[name]) != null ? _a : textureUnit;
5713
5503
  if (value !== void 0) {
5714
5504
  setUniform(this.device.gl, location, type, value);
5715
5505
  }
@@ -5719,19 +5509,19 @@ var WEBGLRenderPipeline = class extends import_core23.RenderPipeline {
5719
5509
  function getGLDrawMode(topology) {
5720
5510
  switch (topology) {
5721
5511
  case "point-list":
5722
- return import_constants25.GL.POINTS;
5512
+ return import_constants24.GL.POINTS;
5723
5513
  case "line-list":
5724
- return import_constants25.GL.LINES;
5514
+ return import_constants24.GL.LINES;
5725
5515
  case "line-strip":
5726
- return import_constants25.GL.LINE_STRIP;
5516
+ return import_constants24.GL.LINE_STRIP;
5727
5517
  case "line-loop-webgl":
5728
- return import_constants25.GL.LINE_LOOP;
5518
+ return import_constants24.GL.LINE_LOOP;
5729
5519
  case "triangle-list":
5730
- return import_constants25.GL.TRIANGLES;
5520
+ return import_constants24.GL.TRIANGLES;
5731
5521
  case "triangle-strip":
5732
- return import_constants25.GL.TRIANGLE_STRIP;
5522
+ return import_constants24.GL.TRIANGLE_STRIP;
5733
5523
  case "triangle-fan-webgl":
5734
- return import_constants25.GL.TRIANGLE_FAN;
5524
+ return import_constants24.GL.TRIANGLE_FAN;
5735
5525
  default:
5736
5526
  throw new Error(topology);
5737
5527
  }
@@ -5739,34 +5529,34 @@ function getGLDrawMode(topology) {
5739
5529
  function getGLPrimitive(topology) {
5740
5530
  switch (topology) {
5741
5531
  case "point-list":
5742
- return import_constants25.GL.POINTS;
5532
+ return import_constants24.GL.POINTS;
5743
5533
  case "line-list":
5744
- return import_constants25.GL.LINES;
5534
+ return import_constants24.GL.LINES;
5745
5535
  case "line-strip":
5746
- return import_constants25.GL.LINES;
5536
+ return import_constants24.GL.LINES;
5747
5537
  case "line-loop-webgl":
5748
- return import_constants25.GL.LINES;
5538
+ return import_constants24.GL.LINES;
5749
5539
  case "triangle-list":
5750
- return import_constants25.GL.TRIANGLES;
5540
+ return import_constants24.GL.TRIANGLES;
5751
5541
  case "triangle-strip":
5752
- return import_constants25.GL.TRIANGLES;
5542
+ return import_constants24.GL.TRIANGLES;
5753
5543
  case "triangle-fan-webgl":
5754
- return import_constants25.GL.TRIANGLES;
5544
+ return import_constants24.GL.TRIANGLES;
5755
5545
  default:
5756
5546
  throw new Error(topology);
5757
5547
  }
5758
5548
  }
5759
5549
 
5760
5550
  // src/adapter/resources/webgl-command-encoder.ts
5761
- var import_core26 = require("@luma.gl/core");
5551
+ var import_core25 = require("@luma.gl/core");
5762
5552
 
5763
5553
  // src/adapter/resources/webgl-command-buffer.ts
5764
- var import_core25 = require("@luma.gl/core");
5765
- var import_constants26 = require("@luma.gl/constants");
5554
+ var import_core24 = require("@luma.gl/core");
5555
+ var import_constants25 = require("@luma.gl/constants");
5766
5556
  function cast3(value) {
5767
5557
  return value;
5768
5558
  }
5769
- var WEBGLCommandBuffer = class extends import_core25.CommandBuffer {
5559
+ var WEBGLCommandBuffer = class extends import_core24.CommandBuffer {
5770
5560
  constructor(device) {
5771
5561
  super({});
5772
5562
  this.commands = [];
@@ -5797,17 +5587,17 @@ function _copyBufferToBuffer(device, options) {
5797
5587
  const destination = cast3(options.destination);
5798
5588
  const gl2 = device.assertWebGL2();
5799
5589
  if (gl2) {
5800
- gl2.bindBuffer(import_constants26.GL.COPY_READ_BUFFER, source.handle);
5801
- gl2.bindBuffer(import_constants26.GL.COPY_WRITE_BUFFER, destination.handle);
5590
+ gl2.bindBuffer(import_constants25.GL.COPY_READ_BUFFER, source.handle);
5591
+ gl2.bindBuffer(import_constants25.GL.COPY_WRITE_BUFFER, destination.handle);
5802
5592
  gl2.copyBufferSubData(
5803
- import_constants26.GL.COPY_READ_BUFFER,
5804
- import_constants26.GL.COPY_WRITE_BUFFER,
5593
+ import_constants25.GL.COPY_READ_BUFFER,
5594
+ import_constants25.GL.COPY_WRITE_BUFFER,
5805
5595
  (_a = options.sourceOffset) != null ? _a : 0,
5806
5596
  (_b = options.destinationOffset) != null ? _b : 0,
5807
5597
  options.size
5808
5598
  );
5809
- gl2.bindBuffer(import_constants26.GL.COPY_READ_BUFFER, null);
5810
- gl2.bindBuffer(import_constants26.GL.COPY_WRITE_BUFFER, null);
5599
+ gl2.bindBuffer(import_constants25.GL.COPY_READ_BUFFER, null);
5600
+ gl2.bindBuffer(import_constants25.GL.COPY_WRITE_BUFFER, null);
5811
5601
  } else {
5812
5602
  throw new Error("copyBufferToBuffer not implemented in WebGL1");
5813
5603
  }
@@ -5858,10 +5648,10 @@ function _copyTextureToBuffer(device, options) {
5858
5648
  const webglBuffer = destination;
5859
5649
  const sourceWidth = width || framebuffer.width;
5860
5650
  const sourceHeight = height || framebuffer.height;
5861
- const sourceFormat = import_constants26.GL.RGBA;
5862
- const sourceType = import_constants26.GL.UNSIGNED_BYTE;
5863
- gl2.bindBuffer(import_constants26.GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
5864
- gl2.bindFramebuffer(import_constants26.GL.FRAMEBUFFER, framebuffer.handle);
5651
+ const sourceFormat = import_constants25.GL.RGBA;
5652
+ const sourceType = import_constants25.GL.UNSIGNED_BYTE;
5653
+ gl2.bindBuffer(import_constants25.GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
5654
+ gl2.bindFramebuffer(import_constants25.GL.FRAMEBUFFER, framebuffer.handle);
5865
5655
  gl2.readPixels(
5866
5656
  origin[0],
5867
5657
  origin[1],
@@ -5872,8 +5662,8 @@ function _copyTextureToBuffer(device, options) {
5872
5662
  byteOffset
5873
5663
  );
5874
5664
  } finally {
5875
- gl2.bindBuffer(import_constants26.GL.PIXEL_PACK_BUFFER, null);
5876
- gl2.bindFramebuffer(import_constants26.GL.FRAMEBUFFER, null);
5665
+ gl2.bindBuffer(import_constants25.GL.PIXEL_PACK_BUFFER, null);
5666
+ gl2.bindFramebuffer(import_constants25.GL.FRAMEBUFFER, null);
5877
5667
  if (destroyFramebuffer) {
5878
5668
  framebuffer.destroy();
5879
5669
  }
@@ -5904,11 +5694,11 @@ function _copyTextureToTexture(device, options) {
5904
5694
  // depthOrArrayLayers = 0
5905
5695
  } = options;
5906
5696
  const destinationMipmaplevel = 0;
5907
- const destinationInternalFormat = import_constants26.GL.RGBA;
5697
+ const destinationInternalFormat = import_constants25.GL.RGBA;
5908
5698
  const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
5909
5699
  const [sourceX, sourceY] = origin;
5910
5700
  const isSubCopy = false;
5911
- device.gl.bindFramebuffer(import_constants26.GL.FRAMEBUFFER, framebuffer.handle);
5701
+ device.gl.bindFramebuffer(import_constants25.GL.FRAMEBUFFER, framebuffer.handle);
5912
5702
  let texture = null;
5913
5703
  let textureTarget;
5914
5704
  if (destination instanceof WEBGLTexture) {
@@ -5937,14 +5727,13 @@ function _copyTextureToTexture(device, options) {
5937
5727
  if (texture) {
5938
5728
  texture.unbind();
5939
5729
  }
5940
- device.gl.bindFramebuffer(import_constants26.GL.FRAMEBUFFER, prevHandle || null);
5941
5730
  if (destroyFramebuffer) {
5942
5731
  framebuffer.destroy();
5943
5732
  }
5944
5733
  return texture;
5945
5734
  }
5946
5735
  function getFramebuffer(source) {
5947
- if (source instanceof import_core25.Texture) {
5736
+ if (source instanceof import_core24.Texture) {
5948
5737
  const { width, height, id } = source;
5949
5738
  const framebuffer = source.device.createFramebuffer({
5950
5739
  id: `framebuffer-for-${id}`,
@@ -5958,7 +5747,7 @@ function getFramebuffer(source) {
5958
5747
  }
5959
5748
 
5960
5749
  // src/adapter/resources/webgl-command-encoder.ts
5961
- var WEBGLCommandEncoder = class extends import_core26.CommandEncoder {
5750
+ var WEBGLCommandEncoder = class extends import_core25.CommandEncoder {
5962
5751
  constructor(device, props) {
5963
5752
  super(device, props);
5964
5753
  this.device = device;
@@ -6000,6 +5789,204 @@ var WEBGLCommandEncoder = class extends import_core26.CommandEncoder {
6000
5789
  // }): void;
6001
5790
  };
6002
5791
 
5792
+ // src/adapter/resources/webgl-vertex-array.ts
5793
+ var import_core26 = require("@luma.gl/core");
5794
+ var import_constants26 = require("@luma.gl/constants");
5795
+ var import_env2 = require("@probe.gl/env");
5796
+ var WEBGLVertexArray = class extends import_core26.VertexArray {
5797
+ // Create a VertexArray
5798
+ constructor(device, props) {
5799
+ super(device, props);
5800
+ /** Attribute 0 buffer constant */
5801
+ this.buffer = null;
5802
+ this.bufferValue = null;
5803
+ this.init = false;
5804
+ this.device = device;
5805
+ this.handle = this.device.gl2.createVertexArray();
5806
+ }
5807
+ get [Symbol.toStringTag]() {
5808
+ return "VertexArray";
5809
+ }
5810
+ /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
5811
+ static isConstantAttributeZeroSupported(device) {
5812
+ return device.info.type === "webgl2" || (0, import_env2.getBrowser)() === "Chrome";
5813
+ }
5814
+ destroy() {
5815
+ var _a;
5816
+ super.destroy();
5817
+ if (this.buffer) {
5818
+ (_a = this.buffer) == null ? void 0 : _a.destroy();
5819
+ }
5820
+ if (this.handle) {
5821
+ this.device.gl2.deleteVertexArray(this.handle);
5822
+ this.handle = void 0;
5823
+ }
5824
+ }
5825
+ /**
5826
+ // Set (bind) an elements buffer, for indexed rendering.
5827
+ // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
5828
+ *
5829
+ * @param elementBuffer
5830
+ */
5831
+ setIndexBuffer(indexBuffer) {
5832
+ const buffer = indexBuffer;
5833
+ if (buffer && buffer.glTarget !== import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5834
+ throw new Error("Use .setBuffer()");
5835
+ }
5836
+ this.device.gl2.bindVertexArray(this.handle);
5837
+ this.device.gl2.bindBuffer(import_constants26.GL.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
5838
+ this.indexBuffer = buffer;
5839
+ }
5840
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
5841
+ setBuffer(location, attributeBuffer) {
5842
+ const buffer = attributeBuffer;
5843
+ if (buffer.glTarget === import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5844
+ throw new Error("Use .setIndexBuffer()");
5845
+ }
5846
+ const { size, type, stride, offset, normalized, integer, divisor } = this._getAccessor(location);
5847
+ this.device.gl2.bindVertexArray(this.handle);
5848
+ this.device.gl.bindBuffer(import_constants26.GL.ARRAY_BUFFER, buffer.handle);
5849
+ if (integer) {
5850
+ this.device.assertWebGL2();
5851
+ this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
5852
+ } else {
5853
+ this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
5854
+ }
5855
+ this.device.gl.enableVertexAttribArray(location);
5856
+ this.device.gl2.vertexAttribDivisor(location, divisor || 0);
5857
+ this.attributes[location] = buffer;
5858
+ }
5859
+ /** Set a location in vertex attributes array to a constant value, disables the location */
5860
+ setConstant(location, value) {
5861
+ this._enable(location, false);
5862
+ this.attributes[location] = value;
5863
+ }
5864
+ bindBeforeRender() {
5865
+ this.device.gl2.bindVertexArray(this.handle);
5866
+ if (!this.init) {
5867
+ const webglBuffer = this.indexBuffer;
5868
+ this.device.gl2.bindBuffer(import_constants26.GL.ELEMENT_ARRAY_BUFFER, (webglBuffer == null ? void 0 : webglBuffer.handle) || null);
5869
+ this.init = true;
5870
+ }
5871
+ this._applyConstantAttributes();
5872
+ }
5873
+ unbindAfterRender() {
5874
+ this.device.gl2.bindVertexArray(null);
5875
+ }
5876
+ // Internal methods
5877
+ /**
5878
+ * Constant attributes need to be reset before every draw call
5879
+ * Any attribute that is disabled in the current vertex array object
5880
+ * is read from the context's global constant value for that attribute location.
5881
+ * @note Constant attributes are only supported in WebGL, not in WebGPU
5882
+ */
5883
+ _applyConstantAttributes() {
5884
+ for (let location = 0; location < this.maxVertexAttributes; ++location) {
5885
+ const constant = this.attributes[location];
5886
+ if (ArrayBuffer.isView(constant)) {
5887
+ this.device.setConstantAttribute(location, constant);
5888
+ }
5889
+ }
5890
+ }
5891
+ /**
5892
+ * Set a location in vertex attributes array to a buffer, enables the location, sets divisor
5893
+ * @note requires vertex array to be bound
5894
+ */
5895
+ // protected _setAttributeLayout(location: number): void {
5896
+ // const {size, type, stride, offset, normalized, integer, divisor} = this._getAccessor(location);
5897
+ // // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
5898
+ // if (integer) {
5899
+ // this.device.assertWebGL2();
5900
+ // this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
5901
+ // } else {
5902
+ // // Attaches ARRAY_BUFFER with specified buffer format to location
5903
+ // this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
5904
+ // }
5905
+ // this.device.gl2.vertexAttribDivisor(location, divisor || 0);
5906
+ // }
5907
+ /** Get an accessor from the */
5908
+ _getAccessor(location) {
5909
+ const attributeInfo = this.attributeInfos[location];
5910
+ if (!attributeInfo) {
5911
+ throw new Error(`Unknown attribute location ${location}`);
5912
+ }
5913
+ const glType = getGLFromVertexType(attributeInfo.bufferDataType);
5914
+ return {
5915
+ size: attributeInfo.bufferComponents,
5916
+ type: glType,
5917
+ stride: attributeInfo.byteStride,
5918
+ offset: attributeInfo.byteOffset,
5919
+ normalized: attributeInfo.normalized,
5920
+ // it is the shader attribute declaration, not the vertex memory format,
5921
+ // that determines if the data in the buffer will be treated as integers.
5922
+ //
5923
+ // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
5924
+ // but as far as we can tell, WebGPU does not.
5925
+ integer: attributeInfo.integer,
5926
+ divisor: attributeInfo.stepMode === "instance" ? 1 : 0
5927
+ };
5928
+ }
5929
+ /**
5930
+ * Enabling an attribute location makes it reference the currently bound buffer
5931
+ * Disabling an attribute location makes it reference the global constant value
5932
+ * TODO - handle single values for size 1 attributes?
5933
+ * TODO - convert classic arrays based on known type?
5934
+ */
5935
+ _enable(location, enable2 = true) {
5936
+ const canDisableAttributeZero = WEBGLVertexArray.isConstantAttributeZeroSupported(this.device);
5937
+ const canDisableAttribute = canDisableAttributeZero || location !== 0;
5938
+ if (enable2 || canDisableAttribute) {
5939
+ location = Number(location);
5940
+ this.device.gl2.bindVertexArray(this.handle);
5941
+ if (enable2) {
5942
+ this.device.gl.enableVertexAttribArray(location);
5943
+ } else {
5944
+ this.device.gl.disableVertexAttribArray(location);
5945
+ }
5946
+ this.device.gl2.bindVertexArray(null);
5947
+ }
5948
+ }
5949
+ /**
5950
+ * Provide a means to create a buffer that is equivalent to a constant.
5951
+ * NOTE: Desktop OpenGL cannot disable attribute 0.
5952
+ * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
5953
+ * this-has-significant-performance-penalty
5954
+ */
5955
+ getConstantBuffer(elementCount, value) {
5956
+ const constantValue = normalizeConstantArrayValue(value);
5957
+ const byteLength = constantValue.byteLength * elementCount;
5958
+ const length = constantValue.length * elementCount;
5959
+ let updateNeeded = !this.buffer;
5960
+ this.buffer = this.buffer || this.device.createBuffer({ byteLength });
5961
+ updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
5962
+ updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
5963
+ if (updateNeeded) {
5964
+ const typedArray = (0, import_core26.getScratchArray)(value.constructor, length);
5965
+ (0, import_core26.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
5966
+ this.buffer.subData(typedArray);
5967
+ this.bufferValue = value;
5968
+ }
5969
+ return this.buffer;
5970
+ }
5971
+ };
5972
+ function normalizeConstantArrayValue(arrayValue) {
5973
+ if (Array.isArray(arrayValue)) {
5974
+ return new Float32Array(arrayValue);
5975
+ }
5976
+ return arrayValue;
5977
+ }
5978
+ function compareConstantArrayValues(v1, v2) {
5979
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
5980
+ return false;
5981
+ }
5982
+ for (let i = 0; i < v1.length; ++i) {
5983
+ if (v1[i] !== v2[i]) {
5984
+ return false;
5985
+ }
5986
+ }
5987
+ return true;
5988
+ }
5989
+
6003
5990
  // src/adapter/webgl-device.ts
6004
5991
  var LOG_LEVEL2 = 1;
6005
5992
  var _WebGLDevice = class extends import_core27.Device {
@@ -6033,13 +6020,13 @@ var _WebGLDevice = class extends import_core27.Device {
6033
6020
  message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
6034
6021
  });
6035
6022
  };
6036
- let gl2 = props.gl || null;
6037
- gl2 = gl2 || ((0, import_env3.isBrowser)() ? createBrowserContext(this.canvasContext.canvas, __spreadProps(__spreadValues({}, props), { onContextLost })) : null);
6038
- gl2 = gl2 || (!(0, import_env3.isBrowser)() ? createHeadlessContext(__spreadProps(__spreadValues({}, props), { onContextLost })) : null);
6039
- if (!gl2) {
6023
+ let gl = props.gl || null;
6024
+ gl = gl || ((0, import_env3.isBrowser)() ? createBrowserContext(this.canvasContext.canvas, __spreadProps(__spreadValues({}, props), { onContextLost })) : null);
6025
+ gl = gl || (!(0, import_env3.isBrowser)() ? createHeadlessContext(__spreadProps(__spreadValues({}, props), { onContextLost })) : null);
6026
+ if (!gl) {
6040
6027
  throw new Error("WebGL context creation failed");
6041
6028
  }
6042
- this.handle = gl2;
6029
+ this.handle = gl;
6043
6030
  this.gl = this.handle;
6044
6031
  this.gl2 = this.gl;
6045
6032
  this.isWebGL2 = isWebGL22(this.gl);
@@ -6089,17 +6076,17 @@ var _WebGLDevice = class extends import_core27.Device {
6089
6076
  * @param gl
6090
6077
  * @returns
6091
6078
  */
6092
- static attach(gl2) {
6093
- if (gl2 instanceof _WebGLDevice) {
6094
- return gl2;
6079
+ static attach(gl) {
6080
+ if (gl instanceof _WebGLDevice) {
6081
+ return gl;
6095
6082
  }
6096
- if ((gl2 == null ? void 0 : gl2.device) instanceof import_core27.Device) {
6097
- return gl2.device;
6083
+ if ((gl == null ? void 0 : gl.device) instanceof import_core27.Device) {
6084
+ return gl.device;
6098
6085
  }
6099
- if (!isWebGL3(gl2)) {
6086
+ if (!isWebGL3(gl)) {
6100
6087
  throw new Error("Invalid WebGLRenderingContext");
6101
6088
  }
6102
- return new _WebGLDevice({ gl: gl2 });
6089
+ return new _WebGLDevice({ gl });
6103
6090
  }
6104
6091
  static create() {
6105
6092
  return __async(this, arguments, function* (props = {}) {
@@ -6180,6 +6167,9 @@ var _WebGLDevice = class extends import_core27.Device {
6180
6167
  createRenderPipeline(props) {
6181
6168
  return new WEBGLRenderPipeline(this, props);
6182
6169
  }
6170
+ createVertexArray(props) {
6171
+ return new WEBGLVertexArray(this, props);
6172
+ }
6183
6173
  beginRenderPass(props) {
6184
6174
  return new WEBGLRenderPass(this, props);
6185
6175
  }
@@ -6239,48 +6229,114 @@ var _WebGLDevice = class extends import_core27.Device {
6239
6229
  popState() {
6240
6230
  popContextState(this.gl);
6241
6231
  }
6242
- /**
6243
- * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
6232
+ /**
6233
+ * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
6244
6234
  * luma.gl ids and props can be inspected
6245
6235
  */
6246
6236
  setSpectorMetadata(handle, props) {
6247
6237
  handle.__SPECTOR_Metadata = props;
6248
6238
  }
6249
- /**
6239
+ /**
6250
6240
  * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
6251
6241
  * Be aware that there are some duplicates especially for constants that are 0,
6252
6242
  * so this isn't guaranteed to return the right key in all cases.
6253
6243
  */
6254
- getGLKey(value, gl2) {
6255
- gl2 = gl2 || this.gl2 || this.gl;
6244
+ getGLKey(value, gl) {
6245
+ gl = gl || this.gl2 || this.gl;
6256
6246
  const number = Number(value);
6257
- for (const key in gl2) {
6258
- if (gl2[key] === number) {
6247
+ for (const key in gl) {
6248
+ if (gl[key] === number) {
6259
6249
  return `GL.${key}`;
6260
6250
  }
6261
6251
  }
6262
6252
  return String(value);
6263
6253
  }
6254
+ /**
6255
+ * Set a constant value for a location. Disabled attributes at that location will read from this value
6256
+ * @note WebGL constants are stored globally on the WebGL context, not the VertexArray
6257
+ * so they need to be updated before every render
6258
+ * @todo - remember/cache values to avoid setting them unnecessarily?
6259
+ */
6260
+ setConstantAttribute(location, constant) {
6261
+ this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
6262
+ const currentConstant = this._constants[location];
6263
+ if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
6264
+ import_core27.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
6265
+ }
6266
+ this._constants[location] = constant;
6267
+ switch (constant.constructor) {
6268
+ case Float32Array:
6269
+ setConstantFloatArray(this, location, constant);
6270
+ break;
6271
+ case Int32Array:
6272
+ setConstantIntArray(this, location, constant);
6273
+ break;
6274
+ case Uint32Array:
6275
+ setConstantUintArray(this, location, constant);
6276
+ break;
6277
+ default:
6278
+ (0, import_core27.assert)(false);
6279
+ }
6280
+ }
6264
6281
  };
6265
6282
  var WebGLDevice = _WebGLDevice;
6266
6283
  //
6267
6284
  // Public `Device` API
6268
6285
  //
6269
6286
  WebGLDevice.type = "webgl";
6270
- function isWebGL3(gl2) {
6271
- if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
6287
+ function isWebGL3(gl) {
6288
+ if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
6272
6289
  return true;
6273
6290
  }
6274
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
6291
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
6275
6292
  return true;
6276
6293
  }
6277
- return Boolean(gl2 && Number.isFinite(gl2._version));
6294
+ return Boolean(gl && Number.isFinite(gl._version));
6278
6295
  }
6279
- function isWebGL22(gl2) {
6280
- if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
6296
+ function isWebGL22(gl) {
6297
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
6281
6298
  return true;
6282
6299
  }
6283
- return Boolean(gl2 && gl2._version === 2);
6300
+ return Boolean(gl && gl._version === 2);
6301
+ }
6302
+ function setConstantFloatArray(device, location, array) {
6303
+ switch (array.length) {
6304
+ case 1:
6305
+ device.gl.vertexAttrib1fv(location, array);
6306
+ break;
6307
+ case 2:
6308
+ device.gl.vertexAttrib2fv(location, array);
6309
+ break;
6310
+ case 3:
6311
+ device.gl.vertexAttrib3fv(location, array);
6312
+ break;
6313
+ case 4:
6314
+ device.gl.vertexAttrib4fv(location, array);
6315
+ break;
6316
+ default:
6317
+ (0, import_core27.assert)(false);
6318
+ }
6319
+ }
6320
+ function setConstantIntArray(device, location, array) {
6321
+ var _a;
6322
+ device.assertWebGL2();
6323
+ (_a = device.gl2) == null ? void 0 : _a.vertexAttribI4iv(location, array);
6324
+ }
6325
+ function setConstantUintArray(device, location, array) {
6326
+ var _a;
6327
+ device.assertWebGL2();
6328
+ (_a = device.gl2) == null ? void 0 : _a.vertexAttribI4uiv(location, array);
6329
+ }
6330
+ function compareConstantArrayValues2(v1, v2) {
6331
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
6332
+ return false;
6333
+ }
6334
+ for (let i = 0; i < v1.length; ++i) {
6335
+ if (v1[i] !== v2[i]) {
6336
+ return false;
6337
+ }
6338
+ }
6339
+ return true;
6284
6340
  }
6285
6341
 
6286
6342
  // src/classic/clear.ts
@@ -6289,8 +6345,8 @@ var GL_DEPTH_BUFFER_BIT2 = 256;
6289
6345
  var GL_STENCIL_BUFFER_BIT2 = 1024;
6290
6346
  var GL_COLOR_BUFFER_BIT2 = 16384;
6291
6347
  var ERR_ARGUMENTS = "clear: bad arguments";
6292
- function clear(gl2, options) {
6293
- const device = WebGLDevice.attach(gl2);
6348
+ function clear(gl, options) {
6349
+ const device = WebGLDevice.attach(gl);
6294
6350
  const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
6295
6351
  const parameters = {};
6296
6352
  if (framebuffer) {
@@ -6316,7 +6372,7 @@ function clear(gl2, options) {
6316
6372
  }
6317
6373
  }
6318
6374
  (0, import_core28.assert)(clearFlags !== 0, ERR_ARGUMENTS);
6319
- withParameters(device.gl, parameters, () => {
6375
+ withGLParameters(device.gl, parameters, () => {
6320
6376
  device.gl.clear(clearFlags);
6321
6377
  });
6322
6378
  }
@@ -6366,10 +6422,15 @@ function glTypeToBytes(type) {
6366
6422
 
6367
6423
  // src/classic/copy-and-blit.ts
6368
6424
  function readPixelsToArray(source, options) {
6369
- const { sourceX = 0, sourceY = 0, sourceFormat = import_constants28.GL.RGBA } = options || {};
6370
- let {
6371
- sourceAttachment = import_constants28.GL.COLOR_ATTACHMENT0,
6425
+ var _a;
6426
+ const {
6427
+ sourceX = 0,
6428
+ sourceY = 0,
6429
+ sourceFormat = import_constants28.GL.RGBA,
6430
+ sourceAttachment = import_constants28.GL.COLOR_ATTACHMENT0
6372
6431
  // TODO - support gl.readBuffer
6432
+ } = options || {};
6433
+ let {
6373
6434
  target = null,
6374
6435
  // following parameters are auto deduced if not provided
6375
6436
  sourceWidth,
@@ -6378,19 +6439,16 @@ function readPixelsToArray(source, options) {
6378
6439
  } = options || {};
6379
6440
  const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
6380
6441
  (0, import_core30.assert)(framebuffer);
6381
- const { gl: gl2, handle } = framebuffer;
6442
+ const { gl, handle } = framebuffer;
6382
6443
  sourceWidth = sourceWidth || framebuffer.width;
6383
6444
  sourceHeight = sourceHeight || framebuffer.height;
6384
- if (sourceAttachment === import_constants28.GL.COLOR_ATTACHMENT0 && handle === null) {
6385
- sourceAttachment = import_constants28.GL.FRONT;
6386
- }
6387
6445
  const attachment = sourceAttachment - import_constants28.GL.COLOR_ATTACHMENT0;
6388
- sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
6446
+ sourceType = sourceType || ((_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.type) || import_constants28.GL.UNSIGNED_BYTE;
6389
6447
  target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
6390
6448
  sourceType = sourceType || getGLTypeFromTypedArray(target);
6391
- const prevHandle2 = gl2.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6392
- gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
6393
- gl2.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle2 || null);
6449
+ const prevHandle = gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6450
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
6451
+ gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle || null);
6394
6452
  if (deleteFramebuffer) {
6395
6453
  framebuffer.destroy();
6396
6454
  }
@@ -6413,7 +6471,7 @@ function readPixelsToBuffer(source, options) {
6413
6471
  target = new BufferWithAccessor(gl2, { byteLength, accessor: { type: sourceType, size: components } });
6414
6472
  }
6415
6473
  target.bind({ glTarget: import_constants28.GL.PIXEL_PACK_BUFFER });
6416
- withParameters(gl2, { framebuffer }, () => {
6474
+ withGLParameters(gl2, { framebuffer }, () => {
6417
6475
  gl2.readPixels(
6418
6476
  sourceX,
6419
6477
  sourceY,
@@ -6455,7 +6513,7 @@ function copyToTexture(source, target, options) {
6455
6513
  targetX = targetX || 0;
6456
6514
  targetY = targetY || 0;
6457
6515
  targetZ = targetZ || 0;
6458
- const prevHandle2 = device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6516
+ const prevHandle = device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
6459
6517
  (0, import_core30.assert)(target);
6460
6518
  let texture = null;
6461
6519
  let textureTarget;
@@ -6516,7 +6574,7 @@ function copyToTexture(source, target, options) {
6516
6574
  if (texture) {
6517
6575
  texture.unbind();
6518
6576
  }
6519
- gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle2 || null);
6577
+ device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle || null);
6520
6578
  if (deleteFramebuffer) {
6521
6579
  framebuffer.destroy();
6522
6580
  }
@@ -6530,16 +6588,12 @@ function getFramebuffer2(source) {
6530
6588
  }
6531
6589
  function toFramebuffer(texture, props) {
6532
6590
  const { device, width, height, id } = texture;
6533
- const framebuffer = device.createFramebuffer(
6534
- __spreadProps(__spreadValues({}, props), {
6535
- id: `framebuffer-for-${id}`,
6536
- width,
6537
- height,
6538
- colorAttachments: [
6539
- texture
6540
- ]
6541
- })
6542
- );
6591
+ const framebuffer = device.createFramebuffer(__spreadProps(__spreadValues({}, props), {
6592
+ id: `framebuffer-for-${id}`,
6593
+ width,
6594
+ height,
6595
+ colorAttachments: [texture]
6596
+ }));
6543
6597
  return framebuffer;
6544
6598
  }
6545
6599
  function getPixelArray(pixelArray, type, format, width, height) {