@luma.gl/webgl 9.0.0-alpha.46 → 9.0.0-alpha.48

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 (88) hide show
  1. package/LICENSE +34 -0
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +73 -40
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js +60 -61
  6. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  7. package/dist/adapter/converters/shader-formats.js +12 -13
  8. package/dist/adapter/converters/shader-formats.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +179 -180
  10. package/dist/adapter/converters/texture-formats.js.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +20 -21
  12. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  13. package/dist/adapter/device-helpers/device-features.js +2 -2
  14. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.js +53 -54
  16. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  17. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/get-device-info.js +23 -12
  19. package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
  20. package/dist/adapter/helpers/decode-webgl-types.js +31 -32
  21. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -1
  22. package/dist/adapter/helpers/get-shader-layout.js +29 -30
  23. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  24. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  25. package/dist/adapter/helpers/parse-shader-compiler-log.js +16 -4
  26. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
  27. package/dist/adapter/helpers/set-uniform.js +40 -41
  28. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  29. package/dist/adapter/helpers/webgl-topology-utils.js +38 -39
  30. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
  31. package/dist/adapter/objects/webgl-renderbuffer.js +5 -6
  32. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  33. package/dist/adapter/resources/webgl-buffer.js +14 -15
  34. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  35. package/dist/adapter/resources/webgl-command-buffer.js +25 -26
  36. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  37. package/dist/adapter/resources/webgl-framebuffer.js +22 -23
  38. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  39. package/dist/adapter/resources/webgl-render-pass.js +2 -3
  40. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  41. package/dist/adapter/resources/webgl-render-pipeline.js +7 -8
  42. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  43. package/dist/adapter/resources/webgl-sampler.js +2 -3
  44. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  45. package/dist/adapter/resources/webgl-shader.js +3 -4
  46. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  47. package/dist/adapter/resources/webgl-texture.js +27 -28
  48. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  49. package/dist/adapter/resources/webgl-transform-feedback.d.ts +5 -11
  50. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-transform-feedback.js +16 -13
  52. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
  53. package/dist/adapter/resources/webgl-vertex-array.d.ts +2 -2
  54. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-vertex-array.js +5 -6
  56. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
  57. package/dist/adapter/webgl-device.js.map +1 -1
  58. package/dist/classic/accessor.js +4 -5
  59. package/dist/classic/accessor.js.map +1 -1
  60. package/dist/classic/copy-and-blit.js +16 -17
  61. package/dist/classic/copy-and-blit.js.map +1 -1
  62. package/dist/classic/format-utils.js +14 -15
  63. package/dist/classic/format-utils.js.map +1 -1
  64. package/dist/classic/typed-array-utils.d.ts +2 -0
  65. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  66. package/dist/classic/typed-array-utils.js +18 -19
  67. package/dist/classic/typed-array-utils.js.map +1 -1
  68. package/dist/context/debug/webgl-developer-tools.js +0 -1
  69. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  70. package/dist/context/parameters/webgl-parameter-tables.js +256 -257
  71. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  72. package/dist/context/polyfill/get-parameter-polyfill.js +34 -35
  73. package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
  74. package/dist/context/polyfill/polyfill-table.js +9 -10
  75. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  76. package/dist/context/polyfill/polyfill-vertex-array-object.js +17 -17
  77. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +1 -1
  78. package/dist/dist.dev.js +987 -2700
  79. package/dist/index.cjs +390 -267
  80. package/dist.min.js +39 -28
  81. package/package.json +5 -5
  82. package/src/adapter/converters/device-parameters.ts +40 -25
  83. package/src/adapter/device-helpers/get-device-info.ts +36 -8
  84. package/src/adapter/helpers/parse-shader-compiler-log.ts +21 -7
  85. package/src/adapter/resources/webgl-transform-feedback.ts +13 -16
  86. package/src/adapter/resources/webgl-vertex-array.ts +4 -3
  87. package/src/adapter/webgl-device.ts +3 -2
  88. package/src/classic/typed-array-utils.ts +2 -0
package/dist/index.cjs CHANGED
@@ -1,24 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
6
  var __export = (target, all) => {
23
7
  for (var name in all)
24
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -32,25 +16,9 @@ var __copyProps = (to, from, except, desc) => {
32
16
  return to;
33
17
  };
34
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
- var __async = (__this, __arguments, generator) => {
36
- return new Promise((resolve, reject) => {
37
- var fulfilled = (value) => {
38
- try {
39
- step(generator.next(value));
40
- } catch (e) {
41
- reject(e);
42
- }
43
- };
44
- var rejected = (value) => {
45
- try {
46
- step(generator.throw(value));
47
- } catch (e) {
48
- reject(e);
49
- }
50
- };
51
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
- step((generator = generator.apply(__this, __arguments)).next());
53
- });
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
54
22
  };
55
23
 
56
24
  // src/index.ts
@@ -116,7 +84,7 @@ function isHeadlessGLRegistered() {
116
84
  return headlessGL !== null;
117
85
  }
118
86
  function createHeadlessContext(options) {
119
- options = __spreadValues(__spreadValues({}, CONTEXT_DEFAULTS), options);
87
+ options = { ...CONTEXT_DEFAULTS, ...options };
120
88
  const { width, height, webgl1, webgl2 } = options;
121
89
  if (webgl2 && !webgl1) {
122
90
  throw new Error("headless-gl does not support WebGL2");
@@ -1354,6 +1322,12 @@ function deepArrayEqual(x, y) {
1354
1322
 
1355
1323
  // src/context/state-tracker/track-context-state.ts
1356
1324
  var GLState = class {
1325
+ gl;
1326
+ program = null;
1327
+ stateStack = [];
1328
+ enable = true;
1329
+ cache;
1330
+ log;
1357
1331
  constructor(gl, {
1358
1332
  copyState = false,
1359
1333
  // Copy cache from params (slow) or initialize from WebGL defaults (fast)
@@ -1361,9 +1335,6 @@ var GLState = class {
1361
1335
  }
1362
1336
  // Logging function, called when gl parameter change calls are actually issued
1363
1337
  } = {}) {
1364
- this.program = null;
1365
- this.stateStack = [];
1366
- this.enable = true;
1367
1338
  this.gl = gl;
1368
1339
  this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
1369
1340
  this.log = log10;
@@ -1504,16 +1475,16 @@ var DEFAULT_CONTEXT_PROPS = {
1504
1475
  onContextRestored: () => console.info("WebGL context restored")
1505
1476
  };
1506
1477
  function createBrowserContext(canvas, props) {
1507
- props = __spreadValues(__spreadValues({}, DEFAULT_CONTEXT_PROPS), props);
1478
+ props = { ...DEFAULT_CONTEXT_PROPS, ...props };
1508
1479
  let errorMessage = null;
1509
1480
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
1510
1481
  canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
1511
1482
  let gl = null;
1512
1483
  if (props.type === "webgl2") {
1513
- props = __spreadProps(__spreadValues({}, props), { webgl1: false });
1484
+ props = { ...props, webgl1: false };
1514
1485
  }
1515
1486
  if (props.type === "webgl1") {
1516
- props = __spreadProps(__spreadValues({}, props), { webgl2: false });
1487
+ props = { ...props, webgl2: false };
1517
1488
  }
1518
1489
  if (!gl && props.webgl2) {
1519
1490
  gl = canvas.getContext("webgl2", props);
@@ -1552,17 +1523,20 @@ function getDeviceInfo(gl) {
1552
1523
  const rendererUnmasked = gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : import_constants4.GL.RENDERER);
1553
1524
  const vendor = vendorUnmasked || vendorMasked;
1554
1525
  const renderer = rendererUnmasked || rendererMasked;
1526
+ const version = gl.getParameter(import_constants4.GL.VERSION);
1555
1527
  const gpu = identifyGPUVendor(vendor, renderer);
1528
+ const gpuBackend = identifyGPUBackend(vendor, renderer);
1529
+ const shadingLanguage = "glsl";
1530
+ const shadingLanguageVersion = isWebGL2(gl) ? 300 : 100;
1556
1531
  return {
1557
1532
  type: isWebGL2(gl) ? "webgl2" : "webgl",
1558
1533
  gpu,
1559
- vendor: vendorUnmasked || vendorMasked,
1560
- renderer: rendererUnmasked || rendererMasked,
1561
- version: gl.getParameter(import_constants4.GL.VERSION),
1562
- shadingLanguages: ["glsl"],
1563
- shadingLanguageVersions: {
1564
- "glsl": gl.getParameter(import_constants4.GL.SHADING_LANGUAGE_VERSION)
1565
- }
1534
+ gpuBackend,
1535
+ vendor,
1536
+ renderer,
1537
+ version,
1538
+ shadingLanguage,
1539
+ shadingLanguageVersion
1566
1540
  };
1567
1541
  }
1568
1542
  function identifyGPUVendor(vendor, renderer) {
@@ -1583,6 +1557,15 @@ function identifyGPUVendor(vendor, renderer) {
1583
1557
  }
1584
1558
  return "unknown";
1585
1559
  }
1560
+ function identifyGPUBackend(vendor, renderer) {
1561
+ if (/ANGLE/i.exec(vendor) || /ANGLE/i.exec(renderer)) {
1562
+ return "angle";
1563
+ }
1564
+ if (/Metal/i.exec(vendor) || /Metal/i.exec(renderer)) {
1565
+ return "metal";
1566
+ }
1567
+ return "unknown";
1568
+ }
1586
1569
 
1587
1570
  // src/adapter/device-helpers/is-old-ie.ts
1588
1571
  function isOldIE(opts = {}) {
@@ -1938,7 +1921,7 @@ function isTextureFormatFilterable(gl, formatOrGL) {
1938
1921
  if (decoded.signed) {
1939
1922
  return false;
1940
1923
  }
1941
- } catch (e) {
1924
+ } catch {
1942
1925
  return false;
1943
1926
  }
1944
1927
  if (format.endsWith("32float")) {
@@ -2418,6 +2401,17 @@ function setDeviceParameters(device, parameters) {
2418
2401
  gl.stencilOpSeparate(import_constants8.GL.FRONT, sfail, dpfail, dppass);
2419
2402
  gl.stencilOpSeparate(import_constants8.GL.BACK, sfail, dpfail, dppass);
2420
2403
  }
2404
+ if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
2405
+ gl.enable(import_constants8.GL.BLEND);
2406
+ const colorEquation = convertBlendOperationToEquation("blendColorOperation", parameters.blendColorOperation || "add");
2407
+ const alphaEquation = convertBlendOperationToEquation("blendAlphaOperation", parameters.blendAlphaOperation || "add");
2408
+ gl.blendEquationSeparate(colorEquation, alphaEquation);
2409
+ const colorSrcFactor = convertBlendFactorToFunction("blendColorSrcFactor", parameters.blendColorSrcFactor || "one");
2410
+ const colorDstFactor = convertBlendFactorToFunction("blendColorDstFactor", parameters.blendColorDstFactor || "zero");
2411
+ const alphaSrcFactor = convertBlendFactorToFunction("blendAlphaSrcFactor", parameters.blendAlphaSrcFactor || "one");
2412
+ const alphaDstFactor = convertBlendFactorToFunction("blendAlphaDstFactor", parameters.blendAlphaDstFactor || "zero");
2413
+ gl.blendFuncSeparate(colorSrcFactor, colorDstFactor, alphaSrcFactor, alphaDstFactor);
2414
+ }
2421
2415
  }
2422
2416
  function convertCompareFunction(parameter, value) {
2423
2417
  return map(parameter, value, {
@@ -2443,6 +2437,30 @@ function convertStencilOperation(parameter, value) {
2443
2437
  "decrement-wrap": import_constants8.GL.DECR_WRAP
2444
2438
  });
2445
2439
  }
2440
+ function convertBlendOperationToEquation(parameter, value) {
2441
+ return map(parameter, value, {
2442
+ "add": import_constants8.GL.FUNC_ADD,
2443
+ "subtract": import_constants8.GL.FUNC_SUBTRACT,
2444
+ "reverse-subtract": import_constants8.GL.FUNC_REVERSE_SUBTRACT,
2445
+ // When using a WebGL 2 context, the following values are available additionally:
2446
+ "min": import_constants8.GL.MIN,
2447
+ "max": import_constants8.GL.MAX
2448
+ });
2449
+ }
2450
+ function convertBlendFactorToFunction(parameter, value) {
2451
+ return map(parameter, value, {
2452
+ "one": import_constants8.GL.ONE,
2453
+ "zero": import_constants8.GL.ZERO,
2454
+ "src-color": import_constants8.GL.SRC_COLOR,
2455
+ "one-minus-src-color": import_constants8.GL.ONE_MINUS_SRC_COLOR,
2456
+ "dst-color": import_constants8.GL.DST_COLOR,
2457
+ "one-minus-dst-color": import_constants8.GL.ONE_MINUS_DST_COLOR,
2458
+ "src-alpha": import_constants8.GL.SRC_ALPHA,
2459
+ "one-minus-src-alpha": import_constants8.GL.ONE_MINUS_SRC_ALPHA,
2460
+ "dst-alpha": import_constants8.GL.DST_ALPHA,
2461
+ "one-minus-dst-alpha": import_constants8.GL.ONE_MINUS_DST_ALPHA
2462
+ });
2463
+ }
2446
2464
  function message(parameter, value) {
2447
2465
  return `Illegal parameter ${value} for ${parameter}`;
2448
2466
  }
@@ -2521,7 +2539,7 @@ function convertMinFilterMode(minFilter, mipmapFilter) {
2521
2539
  }
2522
2540
  }
2523
2541
  function updateSamplerParametersForNPOT(parameters) {
2524
- const newParameters = __spreadValues({}, parameters);
2542
+ const newParameters = { ...parameters };
2525
2543
  if (parameters[import_constants9.GL.TEXTURE_MIN_FILTER] !== import_constants9.GL.NEAREST) {
2526
2544
  newParameters[import_constants9.GL.TEXTURE_MIN_FILTER] = import_constants9.GL.LINEAR;
2527
2545
  }
@@ -2535,18 +2553,30 @@ var import_core7 = require("@luma.gl/core");
2535
2553
  var import_constants10 = require("@luma.gl/constants");
2536
2554
  var DEBUG_DATA_LENGTH = 10;
2537
2555
  var WEBGLBuffer = class extends import_core7.Buffer {
2556
+ device;
2557
+ gl;
2558
+ gl2;
2559
+ handle;
2560
+ /** Target in OpenGL defines the type of buffer */
2561
+ glTarget;
2562
+ /** Usage is a hint on how frequently the buffer will be updates */
2563
+ glUsage;
2564
+ /** Index type is needed when issuing draw calls, so we pre-compute it */
2565
+ glIndexType = import_constants10.GL.UNSIGNED_SHORT;
2566
+ /** Number of bytes allocated on the GPU for this buffer */
2567
+ byteLength;
2568
+ /** Number of bytes used */
2569
+ bytesUsed;
2570
+ /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
2571
+ debugData = null;
2538
2572
  constructor(device, props = {}) {
2539
2573
  super(device, props);
2540
- /** Index type is needed when issuing draw calls, so we pre-compute it */
2541
- this.glIndexType = import_constants10.GL.UNSIGNED_SHORT;
2542
- /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
2543
- this.debugData = null;
2544
2574
  this.device = device;
2545
2575
  this.gl = this.device.gl;
2546
2576
  this.gl2 = this.device.gl2;
2547
2577
  const handle = typeof props === "object" ? props.handle : void 0;
2548
2578
  this.handle = handle || this.gl.createBuffer();
2549
- device.setSpectorMetadata(this.handle, __spreadProps(__spreadValues({}, this.props), { data: typeof this.props.data }));
2579
+ device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
2550
2580
  this.glTarget = getWebGLTarget(this.props.usage);
2551
2581
  this.glUsage = getWebGLUsage(this.props.usage);
2552
2582
  this.glIndexType = this.props.indexType === "uint32" ? import_constants10.GL.UNSIGNED_INT : import_constants10.GL.UNSIGNED_SHORT;
@@ -2611,17 +2641,15 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2611
2641
  this.gl.bindBuffer(glTarget, null);
2612
2642
  }
2613
2643
  /** Read data from the buffer */
2614
- readAsync(byteOffset = 0, byteLength) {
2615
- return __async(this, null, function* () {
2616
- this.device.assertWebGL2();
2617
- byteLength = byteLength != null ? byteLength : this.byteLength;
2618
- const data = new Uint8Array(byteLength);
2619
- const dstOffset = 0;
2620
- this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, this.handle);
2621
- this.gl2.getBufferSubData(import_constants10.GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
2622
- this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, null);
2623
- return data;
2624
- });
2644
+ async readAsync(byteOffset = 0, byteLength) {
2645
+ this.device.assertWebGL2();
2646
+ byteLength = byteLength ?? this.byteLength;
2647
+ const data = new Uint8Array(byteLength);
2648
+ const dstOffset = 0;
2649
+ this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, this.handle);
2650
+ this.gl2.getBufferSubData(import_constants10.GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
2651
+ this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, null);
2652
+ return data;
2625
2653
  }
2626
2654
  // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
2627
2655
  _invalidateDebugData() {
@@ -2663,6 +2691,9 @@ function getWebGLUsage(usage) {
2663
2691
  var import_core8 = require("@luma.gl/core");
2664
2692
  var import_constants11 = require("@luma.gl/constants");
2665
2693
  var WEBGLSampler = class extends import_core8.Sampler {
2694
+ device;
2695
+ handle;
2696
+ parameters;
2666
2697
  constructor(device, props) {
2667
2698
  super(device, props);
2668
2699
  this.device = device;
@@ -2710,28 +2741,44 @@ var DEFAULT_WEBGL_TEXTURE_PROPS = {
2710
2741
  target: void 0
2711
2742
  };
2712
2743
  var _WEBGLTexture = class extends import_core10.Texture {
2744
+ MAX_ATTRIBUTES;
2745
+ device;
2746
+ gl;
2747
+ gl2;
2748
+ handle;
2749
+ /** Sampler object (currently unused) */
2750
+ sampler = void 0;
2751
+ // data;
2752
+ glFormat = void 0;
2753
+ type = void 0;
2754
+ dataFormat = void 0;
2755
+ mipmaps = void 0;
2756
+ /**
2757
+ * @note `target` cannot be modified by bind:
2758
+ * textures are special because when you first bind them to a target,
2759
+ * they get special information. When you first bind a texture as a
2760
+ * GL_TEXTURE_2D, you are saying that this texture is a 2D texture.
2761
+ * And it will always be a 2D texture; this state cannot be changed ever.
2762
+ * A texture that was first bound as a GL_TEXTURE_2D, must always be bound as a GL_TEXTURE_2D;
2763
+ * attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
2764
+ * */
2765
+ target;
2766
+ textureUnit = void 0;
2767
+ /**
2768
+ * Program.draw() checks the loaded flag of all textures to avoid
2769
+ * Textures that are still loading from promises
2770
+ * Set to true as soon as texture has been initialized with valid data
2771
+ */
2772
+ loaded = false;
2773
+ _video;
2713
2774
  constructor(device, props) {
2714
2775
  var _a;
2715
- super(device, __spreadValues(__spreadProps(__spreadValues({}, DEFAULT_WEBGL_TEXTURE_PROPS), { format: "rgba8unorm" }), props));
2716
- /** Sampler object (currently unused) */
2717
- this.sampler = void 0;
2718
- // data;
2719
- this.glFormat = void 0;
2720
- this.type = void 0;
2721
- this.dataFormat = void 0;
2722
- this.mipmaps = void 0;
2723
- this.textureUnit = void 0;
2724
- /**
2725
- * Program.draw() checks the loaded flag of all textures to avoid
2726
- * Textures that are still loading from promises
2727
- * Set to true as soon as texture has been initialized with valid data
2728
- */
2729
- this.loaded = false;
2776
+ super(device, { ...DEFAULT_WEBGL_TEXTURE_PROPS, format: "rgba8unorm", ...props });
2730
2777
  this.device = (0, import_core10.cast)(device);
2731
2778
  this.gl = this.device.gl;
2732
2779
  this.gl2 = this.device.gl2;
2733
2780
  this.handle = this.props.handle || this.gl.createTexture();
2734
- this.device.setSpectorMetadata(this.handle, __spreadProps(__spreadValues({}, this.props), { data: typeof this.props.data }));
2781
+ this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data });
2735
2782
  this.glFormat = import_constants12.GL.RGBA;
2736
2783
  this.target = getWebGLTextureTarget(this.props);
2737
2784
  this.loaded = false;
@@ -3212,32 +3259,30 @@ var _WEBGLTexture = class extends import_core10.Texture {
3212
3259
  }
3213
3260
  // CUBE MAP METHODS
3214
3261
  /* eslint-disable max-statements, max-len */
3215
- setCubeMapImageData(options) {
3216
- return __async(this, null, function* () {
3217
- const { gl } = this;
3218
- const { width, height, pixels, data, format = import_constants12.GL.RGBA, type = import_constants12.GL.UNSIGNED_BYTE } = options;
3219
- const imageDataMap = pixels || data;
3220
- const resolvedFaces = yield Promise.all(
3221
- _WEBGLTexture.FACES.map((face) => {
3222
- const facePixels = imageDataMap[face];
3223
- return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
3224
- })
3225
- );
3226
- this.bind();
3227
- _WEBGLTexture.FACES.forEach((face, index) => {
3228
- if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
3229
- import_core10.log.warn(`${this.id} has mipmap and multiple LODs.`)();
3262
+ async setCubeMapImageData(options) {
3263
+ const { gl } = this;
3264
+ const { width, height, pixels, data, format = import_constants12.GL.RGBA, type = import_constants12.GL.UNSIGNED_BYTE } = options;
3265
+ const imageDataMap = pixels || data;
3266
+ const resolvedFaces = await Promise.all(
3267
+ _WEBGLTexture.FACES.map((face) => {
3268
+ const facePixels = imageDataMap[face];
3269
+ return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
3270
+ })
3271
+ );
3272
+ this.bind();
3273
+ _WEBGLTexture.FACES.forEach((face, index) => {
3274
+ if (resolvedFaces[index].length > 1 && this.props.mipmaps !== false) {
3275
+ import_core10.log.warn(`${this.id} has mipmap and multiple LODs.`)();
3276
+ }
3277
+ resolvedFaces[index].forEach((image, lodLevel) => {
3278
+ if (width && height) {
3279
+ gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
3280
+ } else {
3281
+ gl.texImage2D(face, lodLevel, format, format, type, image);
3230
3282
  }
3231
- resolvedFaces[index].forEach((image, lodLevel) => {
3232
- if (width && height) {
3233
- gl.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
3234
- } else {
3235
- gl.texImage2D(face, lodLevel, format, format, type, image);
3236
- }
3237
- });
3238
3283
  });
3239
- this.unbind();
3240
3284
  });
3285
+ this.unbind();
3241
3286
  }
3242
3287
  /** @todo update this method to accept LODs */
3243
3288
  setImageDataForFace(options) {
@@ -3382,14 +3427,14 @@ var _WEBGLTexture = class extends import_core10.Texture {
3382
3427
  };
3383
3428
  var WEBGLTexture = _WEBGLTexture;
3384
3429
  // TODO - remove?
3385
- WEBGLTexture.FACES = [
3430
+ __publicField(WEBGLTexture, "FACES", [
3386
3431
  import_constants12.GL.TEXTURE_CUBE_MAP_POSITIVE_X,
3387
3432
  import_constants12.GL.TEXTURE_CUBE_MAP_NEGATIVE_X,
3388
3433
  import_constants12.GL.TEXTURE_CUBE_MAP_POSITIVE_Y,
3389
3434
  import_constants12.GL.TEXTURE_CUBE_MAP_NEGATIVE_Y,
3390
3435
  import_constants12.GL.TEXTURE_CUBE_MAP_POSITIVE_Z,
3391
3436
  import_constants12.GL.TEXTURE_CUBE_MAP_NEGATIVE_Z
3392
- ];
3437
+ ]);
3393
3438
  function getWebGLTextureTarget(props) {
3394
3439
  switch (props.dimension) {
3395
3440
  case "2d":
@@ -3442,11 +3487,15 @@ function getKeyValue(gl, name) {
3442
3487
  // src/adapter/objects/webgl-resource.ts
3443
3488
  var ERR_RESOURCE_METHOD_UNDEFINED = "Resource subclass must define virtual methods";
3444
3489
  var WebGLResource = class extends import_core12.Resource {
3490
+ device;
3491
+ gl;
3492
+ gl2;
3493
+ _handle;
3494
+ _bound = false;
3495
+ // Only meaningful for resources that allocate GPU memory
3496
+ byteLength = 0;
3445
3497
  constructor(device, props, defaultProps) {
3446
3498
  super(device, props, defaultProps);
3447
- this._bound = false;
3448
- // Only meaningful for resources that allocate GPU memory
3449
- this.byteLength = 0;
3450
3499
  this.device = WebGLDevice.attach(device);
3451
3500
  const gl = this.device.gl;
3452
3501
  assertWebGLContext(gl);
@@ -3643,14 +3692,6 @@ var WebGLResource = class extends import_core12.Resource {
3643
3692
 
3644
3693
  // src/adapter/objects/webgl-renderbuffer.ts
3645
3694
  var _WEBGLRenderbuffer = class extends WebGLResource {
3646
- constructor(device, props) {
3647
- if (typeof props.format === "number") {
3648
- throw new Error("Renderbuffer");
3649
- }
3650
- super(device, props, _WEBGLRenderbuffer.defaultProps);
3651
- this.glFormat = convertTextureFormatToGL(this.props.format, device.isWebGL2);
3652
- this._initialize(this.props);
3653
- }
3654
3695
  get [Symbol.toStringTag]() {
3655
3696
  return "Renderbuffer";
3656
3697
  }
@@ -3669,12 +3710,22 @@ var _WEBGLRenderbuffer = class extends WebGLResource {
3669
3710
  get attachment() {
3670
3711
  return;
3671
3712
  }
3713
+ /** WebGL format constant */
3714
+ glFormat;
3672
3715
  static isTextureFormatSupported(device, format) {
3673
3716
  return isRenderbufferFormatSupported(device.gl, format);
3674
3717
  }
3718
+ constructor(device, props) {
3719
+ if (typeof props.format === "number") {
3720
+ throw new Error("Renderbuffer");
3721
+ }
3722
+ super(device, props, _WEBGLRenderbuffer.defaultProps);
3723
+ this.glFormat = convertTextureFormatToGL(this.props.format, device.isWebGL2);
3724
+ this._initialize(this.props);
3725
+ }
3675
3726
  resize(size) {
3676
3727
  if (size.width !== this.width || size.height !== this.height) {
3677
- Object.assign(this.props, __spreadProps(__spreadValues({}, size), { format: this.format, samples: this.samples }));
3728
+ Object.assign(this.props, { ...size, format: this.format, samples: this.samples });
3678
3729
  this._initialize(this.props);
3679
3730
  }
3680
3731
  }
@@ -3708,7 +3759,7 @@ var _WEBGLRenderbuffer = class extends WebGLResource {
3708
3759
  }
3709
3760
  };
3710
3761
  var WEBGLRenderbuffer = _WEBGLRenderbuffer;
3711
- WEBGLRenderbuffer.defaultProps = {
3762
+ __publicField(WEBGLRenderbuffer, "defaultProps", {
3712
3763
  id: void 0,
3713
3764
  handle: void 0,
3714
3765
  userData: void 0,
@@ -3717,10 +3768,16 @@ WEBGLRenderbuffer.defaultProps = {
3717
3768
  width: 1,
3718
3769
  height: 1,
3719
3770
  samples: 0
3720
- };
3771
+ });
3721
3772
 
3722
3773
  // src/adapter/resources/webgl-framebuffer.ts
3723
3774
  var WEBGLFramebuffer = class extends import_core14.Framebuffer {
3775
+ device;
3776
+ gl;
3777
+ handle;
3778
+ get texture() {
3779
+ return this.colorAttachments[0];
3780
+ }
3724
3781
  constructor(device, props) {
3725
3782
  super(device, props);
3726
3783
  const isDefaultFramebuffer = props.handle === null;
@@ -3750,9 +3807,6 @@ var WEBGLFramebuffer = class extends import_core14.Framebuffer {
3750
3807
  this._checkStatus();
3751
3808
  }
3752
3809
  }
3753
- get texture() {
3754
- return this.colorAttachments[0];
3755
- }
3756
3810
  /** destroys any auto created resources etc. */
3757
3811
  destroy() {
3758
3812
  super.destroy();
@@ -3881,9 +3935,11 @@ function _getFrameBufferStatus(status) {
3881
3935
 
3882
3936
  // src/adapter/webgl-canvas-context.ts
3883
3937
  var WebGLCanvasContext = class extends import_core15.CanvasContext {
3938
+ device;
3939
+ presentationSize;
3940
+ _framebuffer = null;
3884
3941
  constructor(device, props) {
3885
3942
  super(props);
3886
- this._framebuffer = null;
3887
3943
  this.device = device;
3888
3944
  this.presentationSize = [-1, -1];
3889
3945
  this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
@@ -3938,19 +3994,17 @@ var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
3938
3994
  var LOG_LEVEL = 1;
3939
3995
  var spector = null;
3940
3996
  var initialized = false;
3941
- function loadSpectorJS(props) {
3942
- return __async(this, null, function* () {
3943
- if (!globalThis.SPECTOR) {
3944
- try {
3945
- yield (0, import_core16.loadScript)(SPECTOR_CDN_URL);
3946
- } catch (error2) {
3947
- import_core16.log.warn(String(error2));
3948
- }
3997
+ async function loadSpectorJS(props) {
3998
+ if (!globalThis.SPECTOR) {
3999
+ try {
4000
+ await (0, import_core16.loadScript)(SPECTOR_CDN_URL);
4001
+ } catch (error2) {
4002
+ import_core16.log.warn(String(error2));
3949
4003
  }
3950
- });
4004
+ }
3951
4005
  }
3952
4006
  function initializeSpectorJS(props) {
3953
- props = __spreadValues(__spreadValues({}, DEFAULT_SPECTOR_PROPS), props);
4007
+ props = { ...DEFAULT_SPECTOR_PROPS, ...props };
3954
4008
  if (!(props == null ? void 0 : props.spector)) {
3955
4009
  return null;
3956
4010
  }
@@ -3997,14 +4051,12 @@ function getContextData2(gl) {
3997
4051
  gl.luma = gl.luma || {};
3998
4052
  return gl.luma;
3999
4053
  }
4000
- function loadWebGLDeveloperTools() {
4001
- return __async(this, null, function* () {
4002
- if ((0, import_env.isBrowser)() && !globalThis.WebGLDebugUtils) {
4003
- globalThis.global = globalThis.global || globalThis;
4004
- globalThis.global.module = {};
4005
- yield (0, import_core17.loadScript)(WEBGL_DEBUG_CDN_URL);
4006
- }
4007
- });
4054
+ async function loadWebGLDeveloperTools() {
4055
+ if ((0, import_env.isBrowser)() && !globalThis.WebGLDebugUtils) {
4056
+ globalThis.global = globalThis.global || globalThis;
4057
+ globalThis.global.module = {};
4058
+ await (0, import_core17.loadScript)(WEBGL_DEBUG_CDN_URL);
4059
+ }
4008
4060
  }
4009
4061
  function makeDebugContext(gl, props = {}) {
4010
4062
  if (!gl) {
@@ -4025,7 +4077,7 @@ function getDebugContext(gl, props) {
4025
4077
  if (data.debugContext) {
4026
4078
  return data.debugContext;
4027
4079
  }
4028
- globalThis.WebGLDebugUtils.init(__spreadValues(__spreadValues({}, import_constants15.GL), gl));
4080
+ globalThis.WebGLDebugUtils.init({ ...import_constants15.GL, ...gl });
4029
4081
  const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(
4030
4082
  gl,
4031
4083
  onGLError.bind(null, props),
@@ -4120,7 +4172,6 @@ function getShaderVersion(source) {
4120
4172
  }
4121
4173
 
4122
4174
  // src/adapter/helpers/parse-shader-compiler-log.ts
4123
- var MESSAGE_TYPES = ["warning", "error", "info"];
4124
4175
  function parseShaderCompilerLog(errLog) {
4125
4176
  const lines = errLog.split(/\r?\n/);
4126
4177
  const messages = [];
@@ -4129,6 +4180,16 @@ function parseShaderCompilerLog(errLog) {
4129
4180
  continue;
4130
4181
  }
4131
4182
  const segments = line.split(":");
4183
+ if (segments.length === 2) {
4184
+ const [messageType2, message2] = segments;
4185
+ messages.push({
4186
+ message: message2.trim(),
4187
+ type: getMessageType(messageType2),
4188
+ lineNum: 0,
4189
+ linePos: 0
4190
+ });
4191
+ continue;
4192
+ }
4132
4193
  const [messageType, linePosition, lineNumber, ...rest] = segments;
4133
4194
  let lineNum = parseInt(lineNumber, 10);
4134
4195
  if (isNaN(lineNum)) {
@@ -4138,11 +4199,9 @@ function parseShaderCompilerLog(errLog) {
4138
4199
  if (isNaN(linePos)) {
4139
4200
  linePos = 0;
4140
4201
  }
4141
- const lowerCaseType = messageType.toLowerCase();
4142
- const type = MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : "info";
4143
4202
  messages.push({
4144
4203
  message: rest.join(":").trim(),
4145
- type,
4204
+ type: getMessageType(messageType),
4146
4205
  lineNum,
4147
4206
  linePos
4148
4207
  // TODO
@@ -4150,11 +4209,18 @@ function parseShaderCompilerLog(errLog) {
4150
4209
  }
4151
4210
  return messages;
4152
4211
  }
4212
+ function getMessageType(messageType) {
4213
+ const MESSAGE_TYPES = ["warning", "error", "info"];
4214
+ const lowerCaseType = messageType.toLowerCase();
4215
+ return MESSAGE_TYPES.includes(lowerCaseType) ? lowerCaseType : "info";
4216
+ }
4153
4217
 
4154
4218
  // src/adapter/resources/webgl-shader.ts
4155
4219
  var WEBGLShader = class extends import_core18.Shader {
4220
+ device;
4221
+ handle;
4156
4222
  constructor(device, props) {
4157
- super(device, __spreadValues({ id: getShaderIdFromProps(props) }, props));
4223
+ super(device, { id: getShaderIdFromProps(props), ...props });
4158
4224
  this.device = device;
4159
4225
  switch (this.props.stage) {
4160
4226
  case "vertex":
@@ -4175,11 +4241,9 @@ var WEBGLShader = class extends import_core18.Shader {
4175
4241
  this.destroyed = true;
4176
4242
  }
4177
4243
  }
4178
- compilationInfo() {
4179
- return __async(this, null, function* () {
4180
- const log10 = this.device.gl.getShaderInfoLog(this.handle);
4181
- return log10 ? parseShaderCompilerLog(log10) : [];
4182
- });
4244
+ async compilationInfo() {
4245
+ const log10 = this.device.gl.getShaderInfoLog(this.handle);
4246
+ return log10 ? parseShaderCompilerLog(log10) : [];
4183
4247
  }
4184
4248
  // PRIVATE METHODS
4185
4249
  _compile(source) {
@@ -4215,6 +4279,9 @@ var GL_STENCIL_BUFFER_BIT = 1024;
4215
4279
  var GL_COLOR_BUFFER_BIT = 16384;
4216
4280
  var GL_COLOR = 6144;
4217
4281
  var WEBGLRenderPass = class extends import_core19.RenderPass {
4282
+ device;
4283
+ /** Parameters that should be applied before each draw call */
4284
+ glParameters;
4218
4285
  constructor(device, props) {
4219
4286
  super(device, props);
4220
4287
  this.device = device;
@@ -4278,7 +4345,7 @@ var WEBGLRenderPass = class extends import_core19.RenderPass {
4278
4345
  * Optionally clears depth, color and stencil buffers based on parameters
4279
4346
  */
4280
4347
  clear() {
4281
- const glParameters = __spreadValues({}, this.glParameters);
4348
+ const glParameters = { ...this.glParameters };
4282
4349
  let clearMask = 0;
4283
4350
  if (this.props.clearColor !== false) {
4284
4351
  clearMask |= GL_COLOR_BUFFER_BIT;
@@ -4417,6 +4484,15 @@ var PROP_CHECKS = {
4417
4484
  }
4418
4485
  };
4419
4486
  var Accessor = class {
4487
+ offset;
4488
+ stride;
4489
+ type;
4490
+ size;
4491
+ divisor;
4492
+ normalized;
4493
+ integer;
4494
+ buffer;
4495
+ index;
4420
4496
  static getBytesPerElement(accessor) {
4421
4497
  const ArrayType = getTypedArrayFromGLType(accessor.type || import_constants19.GL.FLOAT);
4422
4498
  return ArrayType.BYTES_PER_ELEMENT;
@@ -4718,10 +4794,11 @@ function readUniformBindings(gl, program) {
4718
4794
  for (let j = 0; j < uniformInfo.size; j++) {
4719
4795
  const elementName = `${name}[${j}]`;
4720
4796
  webglLocation = gl.getUniformLocation(program, elementName);
4721
- const arrayElementUniformInfo = __spreadProps(__spreadValues({}, uniformInfo), {
4797
+ const arrayElementUniformInfo = {
4798
+ ...uniformInfo,
4722
4799
  name: elementName,
4723
4800
  location: webglLocation
4724
- });
4801
+ };
4725
4802
  uniforms.push(arrayElementUniformInfo);
4726
4803
  }
4727
4804
  }
@@ -4949,18 +5026,28 @@ function getGLPrimitive(topology) {
4949
5026
  // src/adapter/resources/webgl-render-pipeline.ts
4950
5027
  var LOG_PROGRAM_PERF_PRIORITY = 4;
4951
5028
  var WEBGLRenderPipeline = class extends import_core21.RenderPipeline {
5029
+ /** The WebGL device that created this render pipeline */
5030
+ device;
5031
+ /** Handle to underlying WebGL program */
5032
+ handle;
5033
+ /** vertex shader */
5034
+ vs;
5035
+ /** fragment shader */
5036
+ fs;
5037
+ /** The layout extracted from shader by WebGL introspection APIs */
5038
+ introspectedLayout;
5039
+ /** Uniforms set on this model */
5040
+ uniforms = {};
5041
+ /** Bindings set on this model */
5042
+ bindings = {};
5043
+ /** WebGL varyings */
5044
+ varyings = null;
5045
+ _uniformCount = 0;
5046
+ _uniformSetters = {};
4952
5047
  // TODO are these used?
4953
5048
  constructor(device, props) {
4954
5049
  var _a;
4955
5050
  super(device, props);
4956
- /** Uniforms set on this model */
4957
- this.uniforms = {};
4958
- /** Bindings set on this model */
4959
- this.bindings = {};
4960
- /** WebGL varyings */
4961
- this.varyings = null;
4962
- this._uniformCount = 0;
4963
- this._uniformSetters = {};
4964
5051
  this.device = device;
4965
5052
  this.handle = this.props.handle || this.device.gl.createProgram();
4966
5053
  this.device.setSpectorMetadata(this.handle, { id: this.props.id });
@@ -5255,10 +5342,9 @@ var WEBGLRenderPipeline = class extends import_core21.RenderPipeline {
5255
5342
  * (though caching will avoid redundant WebGL calls)
5256
5343
  */
5257
5344
  _applyUniforms() {
5258
- var _a;
5259
5345
  for (const uniformLayout of this.shaderLayout.uniforms || []) {
5260
5346
  const { name, location, type, textureUnit } = uniformLayout;
5261
- const value = (_a = this.uniforms[name]) != null ? _a : textureUnit;
5347
+ const value = this.uniforms[name] ?? textureUnit;
5262
5348
  if (value !== void 0) {
5263
5349
  setUniform(this.device.gl, location, type, value);
5264
5350
  }
@@ -5276,9 +5362,10 @@ function cast3(value) {
5276
5362
  return value;
5277
5363
  }
5278
5364
  var WEBGLCommandBuffer = class extends import_core23.CommandBuffer {
5365
+ device;
5366
+ commands = [];
5279
5367
  constructor(device) {
5280
5368
  super(device, {});
5281
- this.commands = [];
5282
5369
  this.device = device;
5283
5370
  }
5284
5371
  submitCommands(commands = this.commands) {
@@ -5301,7 +5388,6 @@ var WEBGLCommandBuffer = class extends import_core23.CommandBuffer {
5301
5388
  }
5302
5389
  };
5303
5390
  function _copyBufferToBuffer(device, options) {
5304
- var _a, _b;
5305
5391
  const source = cast3(options.source);
5306
5392
  const destination = cast3(options.destination);
5307
5393
  const gl2 = device.assertWebGL2();
@@ -5311,8 +5397,8 @@ function _copyBufferToBuffer(device, options) {
5311
5397
  gl2.copyBufferSubData(
5312
5398
  import_constants25.GL.COPY_READ_BUFFER,
5313
5399
  import_constants25.GL.COPY_WRITE_BUFFER,
5314
- (_a = options.sourceOffset) != null ? _a : 0,
5315
- (_b = options.destinationOffset) != null ? _b : 0,
5400
+ options.sourceOffset ?? 0,
5401
+ options.destinationOffset ?? 0,
5316
5402
  options.size
5317
5403
  );
5318
5404
  gl2.bindBuffer(import_constants25.GL.COPY_READ_BUFFER, null);
@@ -5468,6 +5554,8 @@ function getFramebuffer(source) {
5468
5554
 
5469
5555
  // src/adapter/resources/webgl-command-encoder.ts
5470
5556
  var WEBGLCommandEncoder = class extends import_core24.CommandEncoder {
5557
+ device;
5558
+ commandBuffer;
5471
5559
  constructor(device, props) {
5472
5560
  super(device, props);
5473
5561
  this.device = device;
@@ -5514,23 +5602,24 @@ var import_core25 = require("@luma.gl/core");
5514
5602
  var import_constants26 = require("@luma.gl/constants");
5515
5603
  var import_env2 = require("@probe.gl/env");
5516
5604
  var WEBGLVertexArray = class extends import_core25.VertexArray {
5517
- // Create a VertexArray
5518
- constructor(device, props) {
5519
- super(device, props);
5520
- /** Attribute 0 buffer constant */
5521
- this.buffer = null;
5522
- this.bufferValue = null;
5523
- this.init = false;
5524
- this.device = device;
5525
- this.handle = this.device.gl2.createVertexArray();
5526
- }
5527
5605
  get [Symbol.toStringTag]() {
5528
5606
  return "VertexArray";
5529
5607
  }
5608
+ device;
5609
+ handle;
5610
+ /** Attribute 0 buffer constant */
5611
+ buffer = null;
5612
+ bufferValue = null;
5530
5613
  /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
5531
5614
  static isConstantAttributeZeroSupported(device) {
5532
5615
  return device.info.type === "webgl2" || (0, import_env2.getBrowser)() === "Chrome";
5533
5616
  }
5617
+ // Create a VertexArray
5618
+ constructor(device, props) {
5619
+ super(device, props);
5620
+ this.device = device;
5621
+ this.handle = this.device.gl2.createVertexArray();
5622
+ }
5534
5623
  destroy() {
5535
5624
  var _a;
5536
5625
  super.destroy();
@@ -5543,14 +5632,14 @@ var WEBGLVertexArray = class extends import_core25.VertexArray {
5543
5632
  }
5544
5633
  }
5545
5634
  /**
5546
- // Set (bind) an elements buffer, for indexed rendering.
5547
- // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
5635
+ // Set (bind/unbind) an elements buffer, for indexed rendering.
5636
+ // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER or null. Constants not supported
5548
5637
  *
5549
5638
  * @param elementBuffer
5550
5639
  */
5551
5640
  setIndexBuffer(indexBuffer) {
5552
5641
  const buffer = indexBuffer;
5553
- if ((buffer == null ? void 0 : buffer.glTarget) !== import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5642
+ if (buffer && buffer.glTarget !== import_constants26.GL.ELEMENT_ARRAY_BUFFER) {
5554
5643
  throw new Error("Use .setBuffer()");
5555
5644
  }
5556
5645
  this.device.gl2.bindVertexArray(this.handle);
@@ -5581,6 +5670,7 @@ var WEBGLVertexArray = class extends import_core25.VertexArray {
5581
5670
  this._enable(location, false);
5582
5671
  this.attributes[location] = value;
5583
5672
  }
5673
+ init = false;
5584
5674
  bindBeforeRender() {
5585
5675
  this.device.gl2.bindVertexArray(this.handle);
5586
5676
  if (!this.init) {
@@ -5715,17 +5805,26 @@ function compareConstantArrayValues(v1, v2) {
5715
5805
  var import_core26 = require("@luma.gl/core");
5716
5806
  var import_constants27 = require("@luma.gl/constants");
5717
5807
  var WEBGLTransformFeedback = class extends import_core26.TransformFeedback {
5808
+ device;
5809
+ gl2;
5810
+ handle;
5811
+ /**
5812
+ * NOTE: The Model already has this information while drawing, but
5813
+ * TransformFeedback currently needs it internally, to look up
5814
+ * varying information outside of a draw() call.
5815
+ */
5816
+ layout;
5817
+ buffers = {};
5818
+ unusedBuffers = {};
5819
+ /**
5820
+ * Allows us to avoid a Chrome bug where a buffer that is already bound to a
5821
+ * different target cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
5822
+ * This a major workaround, see: https://github.com/KhronosGroup/WebGL/issues/2346
5823
+ */
5824
+ bindOnUse = true;
5825
+ _bound = false;
5718
5826
  constructor(device, props) {
5719
5827
  super(device, props);
5720
- this.buffers = {};
5721
- this.unusedBuffers = {};
5722
- /**
5723
- * Allows us to avoid a Chrome bug where a buffer that is already bound to a
5724
- * different target cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
5725
- * This a major workaround, see: https://github.com/KhronosGroup/WebGL/issues/2346
5726
- */
5727
- this.bindOnUse = true;
5728
- this._bound = false;
5729
5828
  device.assertWebGL2();
5730
5829
  this.device = device;
5731
5830
  this.gl2 = device.gl2;
@@ -5763,7 +5862,6 @@ var WEBGLTransformFeedback = class extends import_core26.TransformFeedback {
5763
5862
  this.setBuffer(bufferName, buffers[bufferName]);
5764
5863
  }
5765
5864
  });
5766
- return this;
5767
5865
  }
5768
5866
  setBuffer(locationOrName, bufferOrRange) {
5769
5867
  const location = this._getVaryingIndex(locationOrName);
@@ -5771,13 +5869,19 @@ var WEBGLTransformFeedback = class extends import_core26.TransformFeedback {
5771
5869
  if (location < 0) {
5772
5870
  this.unusedBuffers[locationOrName] = buffer;
5773
5871
  import_core26.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
5774
- return this;
5872
+ return;
5775
5873
  }
5776
5874
  this.buffers[location] = { buffer, byteLength, byteOffset };
5777
5875
  if (!this.bindOnUse) {
5778
5876
  this._bindBuffer(location, buffer, byteOffset, byteLength);
5779
5877
  }
5780
- return this;
5878
+ }
5879
+ getBuffer(locationOrName) {
5880
+ if (isIndex(locationOrName)) {
5881
+ return this.buffers[locationOrName] || null;
5882
+ }
5883
+ const location = this._getVaryingIndex(locationOrName);
5884
+ return location >= 0 ? this.buffers[location] : null;
5781
5885
  }
5782
5886
  bind(funcOrHandle = this.handle) {
5783
5887
  if (typeof funcOrHandle !== "function") {
@@ -5841,7 +5945,6 @@ var WEBGLTransformFeedback = class extends import_core26.TransformFeedback {
5841
5945
  } else {
5842
5946
  this.gl2.bindBufferRange(import_constants27.GL.TRANSFORM_FEEDBACK_BUFFER, index, handle, byteOffset, byteLength);
5843
5947
  }
5844
- return this;
5845
5948
  }
5846
5949
  };
5847
5950
  function isIndex(value) {
@@ -5854,21 +5957,69 @@ function isIndex(value) {
5854
5957
  // src/adapter/webgl-device.ts
5855
5958
  var LOG_LEVEL2 = 1;
5856
5959
  var _WebGLDevice = class extends import_core27.Device {
5960
+ static isSupported() {
5961
+ return typeof WebGLRenderingContext !== "undefined" || isHeadlessGLRegistered();
5962
+ }
5963
+ info;
5964
+ canvasContext;
5965
+ handle;
5966
+ get features() {
5967
+ this._features = this._features || getDeviceFeatures(this.gl);
5968
+ return this._features;
5969
+ }
5970
+ get limits() {
5971
+ this._limits = this._limits || getDeviceLimits(this.gl);
5972
+ return this._limits;
5973
+ }
5974
+ lost;
5975
+ _resolveContextLost;
5976
+ _features;
5977
+ _limits;
5978
+ //
5979
+ // Static methods, expected to be present by `luma.createDevice()`
5980
+ //
5981
+ /**
5982
+ * Get a device instance from a GL context
5983
+ * Creates and instruments the device if not already created
5984
+ * @param gl
5985
+ * @returns
5986
+ */
5987
+ static attach(gl) {
5988
+ if (gl instanceof _WebGLDevice) {
5989
+ return gl;
5990
+ }
5991
+ if ((gl == null ? void 0 : gl.device) instanceof import_core27.Device) {
5992
+ return gl.device;
5993
+ }
5994
+ if (!isWebGL3(gl)) {
5995
+ throw new Error("Invalid WebGLRenderingContext");
5996
+ }
5997
+ return new _WebGLDevice({ gl });
5998
+ }
5999
+ static async create(props = {}) {
6000
+ import_core27.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created");
6001
+ if (typeof props.canvas === "string") {
6002
+ await import_core27.CanvasContext.pageLoaded;
6003
+ }
6004
+ if (import_core27.log.get("debug") || props.debug) {
6005
+ await loadWebGLDeveloperTools();
6006
+ }
6007
+ const { spector: spector2 } = props;
6008
+ if (import_core27.log.get("spector") || spector2) {
6009
+ await loadSpectorJS();
6010
+ }
6011
+ import_core27.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
6012
+ if (props.gl && props.gl.device) {
6013
+ return _WebGLDevice.attach(props.gl);
6014
+ }
6015
+ return new _WebGLDevice(props);
6016
+ }
5857
6017
  //
5858
6018
  // Public API
5859
6019
  //
5860
6020
  constructor(props) {
5861
6021
  var _a;
5862
- super(__spreadProps(__spreadValues({}, props), { id: props.id || (0, import_core27.uid)("webgl-device") }));
5863
- this.renderPass = null;
5864
- /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
5865
- this.gl2 = null;
5866
- this.debug = false;
5867
- /** State used by luma.gl classes: TODO - move to canvasContext*/
5868
- this._canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
5869
- /** State used by luma.gl classes - TODO - not used? */
5870
- this._extensions = {};
5871
- this._polyfilled = false;
6022
+ super({ ...props, id: props.id || (0, import_core27.uid)("webgl-device") });
5872
6023
  const device = (_a = props.gl) == null ? void 0 : _a.device;
5873
6024
  if (device) {
5874
6025
  throw new Error(`WebGL context already attached to device ${device.id}`);
@@ -5885,8 +6036,8 @@ var _WebGLDevice = class extends import_core27.Device {
5885
6036
  });
5886
6037
  };
5887
6038
  let gl = props.gl || null;
5888
- gl = gl || ((0, import_env3.isBrowser)() ? createBrowserContext(this.canvasContext.canvas, __spreadProps(__spreadValues({}, props), { onContextLost })) : null);
5889
- gl = gl || (!(0, import_env3.isBrowser)() ? createHeadlessContext(__spreadProps(__spreadValues({}, props), { onContextLost })) : null);
6039
+ gl = gl || ((0, import_env3.isBrowser)() ? createBrowserContext(this.canvasContext.canvas, { ...props, onContextLost }) : null);
6040
+ gl = gl || (!(0, import_env3.isBrowser)() ? createHeadlessContext({ ...props, onContextLost }) : null);
5890
6041
  if (!gl) {
5891
6042
  throw new Error("WebGL context creation failed");
5892
6043
  }
@@ -5906,7 +6057,7 @@ var _WebGLDevice = class extends import_core27.Device {
5906
6057
  log: (...args) => import_core27.log.log(1, ...args)()
5907
6058
  });
5908
6059
  if ((0, import_env3.isBrowser)() && props.debug) {
5909
- this.gl = makeDebugContext(this.gl, __spreadProps(__spreadValues({}, props), { webgl2: this.isWebGL2, throwOnError: true }));
6060
+ this.gl = makeDebugContext(this.gl, { ...props, webgl2: this.isWebGL2, throwOnError: true });
5910
6061
  this.gl2 = this.gl;
5911
6062
  this.debug = true;
5912
6063
  import_core27.log.level = Math.max(import_core27.log.level, 1);
@@ -5914,64 +6065,12 @@ var _WebGLDevice = class extends import_core27.Device {
5914
6065
  }
5915
6066
  if ((0, import_env3.isBrowser)() && props.spector) {
5916
6067
  const canvas = this.handle.canvas || props.canvas;
5917
- this.spector = initializeSpectorJS(__spreadProps(__spreadValues({}, this.props), { canvas }));
6068
+ this.spector = initializeSpectorJS({ ...this.props, canvas });
5918
6069
  }
5919
6070
  const message2 = `Created ${this.info.type}${this.debug ? " debug" : ""} context: ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;
5920
6071
  import_core27.log.probe(LOG_LEVEL2, message2)();
5921
6072
  import_core27.log.groupEnd(LOG_LEVEL2)();
5922
6073
  }
5923
- static isSupported() {
5924
- return typeof WebGLRenderingContext !== "undefined" || isHeadlessGLRegistered();
5925
- }
5926
- get features() {
5927
- this._features = this._features || getDeviceFeatures(this.gl);
5928
- return this._features;
5929
- }
5930
- get limits() {
5931
- this._limits = this._limits || getDeviceLimits(this.gl);
5932
- return this._limits;
5933
- }
5934
- //
5935
- // Static methods, expected to be present by `luma.createDevice()`
5936
- //
5937
- /**
5938
- * Get a device instance from a GL context
5939
- * Creates and instruments the device if not already created
5940
- * @param gl
5941
- * @returns
5942
- */
5943
- static attach(gl) {
5944
- if (gl instanceof _WebGLDevice) {
5945
- return gl;
5946
- }
5947
- if ((gl == null ? void 0 : gl.device) instanceof import_core27.Device) {
5948
- return gl.device;
5949
- }
5950
- if (!isWebGL3(gl)) {
5951
- throw new Error("Invalid WebGLRenderingContext");
5952
- }
5953
- return new _WebGLDevice({ gl });
5954
- }
5955
- static create() {
5956
- return __async(this, arguments, function* (props = {}) {
5957
- import_core27.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created");
5958
- if (typeof props.canvas === "string") {
5959
- yield import_core27.CanvasContext.pageLoaded;
5960
- }
5961
- if (import_core27.log.get("debug") || props.debug) {
5962
- yield loadWebGLDeveloperTools();
5963
- }
5964
- const { spector: spector2 } = props;
5965
- if (import_core27.log.get("spector") || spector2) {
5966
- yield loadSpectorJS();
5967
- }
5968
- import_core27.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5969
- if (props.gl && props.gl.device) {
5970
- return _WebGLDevice.attach(props.gl);
5971
- }
5972
- return new _WebGLDevice(props);
5973
- });
5974
- }
5975
6074
  /**
5976
6075
  * Destroys the context
5977
6076
  * @note Has no effect for browser contexts, there is no browser API for destroying contexts
@@ -6046,6 +6145,7 @@ var _WebGLDevice = class extends import_core27.Device {
6046
6145
  createTransformFeedback(props) {
6047
6146
  return new WEBGLTransformFeedback(this, props);
6048
6147
  }
6148
+ renderPass = null;
6049
6149
  getDefaultRenderPass() {
6050
6150
  this.renderPass = this.renderPass || this.beginRenderPass({
6051
6151
  framebuffer: this.canvasContext.getCurrentFramebuffer()
@@ -6065,6 +6165,26 @@ var _WebGLDevice = class extends import_core27.Device {
6065
6165
  (_a = this.renderPass) == null ? void 0 : _a.end();
6066
6166
  this.renderPass = null;
6067
6167
  }
6168
+ //
6169
+ // WebGL-only API (not part of `Device` API)
6170
+ //
6171
+ /** WebGL1 typed context. Can always be used. */
6172
+ gl;
6173
+ /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
6174
+ gl2 = null;
6175
+ debug = false;
6176
+ /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
6177
+ isWebGL1;
6178
+ /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
6179
+ isWebGL2;
6180
+ /** State used by luma.gl classes: TODO - move to canvasContext*/
6181
+ _canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
6182
+ /** State used by luma.gl classes - TODO - not used? */
6183
+ _extensions = {};
6184
+ _polyfilled = false;
6185
+ /** Instance of Spector.js (if initialized) */
6186
+ spector;
6187
+ _webglLimits;
6068
6188
  /** Return WebGL specific limits */
6069
6189
  get webglLimits() {
6070
6190
  this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
@@ -6118,6 +6238,8 @@ var _WebGLDevice = class extends import_core27.Device {
6118
6238
  }
6119
6239
  return String(value);
6120
6240
  }
6241
+ /** Store constants */
6242
+ _constants;
6121
6243
  /**
6122
6244
  * Set a constant value for a location. Disabled attributes at that location will read from this value
6123
6245
  * @note WebGL constants are stored globally on the WebGL context, not the VertexArray
@@ -6150,7 +6272,7 @@ var WebGLDevice = _WebGLDevice;
6150
6272
  //
6151
6273
  // Public `Device` API
6152
6274
  //
6153
- WebGLDevice.type = "webgl";
6275
+ __publicField(WebGLDevice, "type", "webgl");
6154
6276
  function isWebGL3(gl) {
6155
6277
  if (typeof WebGLRenderingContext !== "undefined" && gl instanceof WebGLRenderingContext) {
6156
6278
  return true;
@@ -6451,12 +6573,13 @@ function getFramebuffer2(source) {
6451
6573
  }
6452
6574
  function toFramebuffer(texture, props) {
6453
6575
  const { device, width, height, id } = texture;
6454
- const framebuffer = device.createFramebuffer(__spreadProps(__spreadValues({}, props), {
6576
+ const framebuffer = device.createFramebuffer({
6577
+ ...props,
6455
6578
  id: `framebuffer-for-${id}`,
6456
6579
  width,
6457
6580
  height,
6458
6581
  colorAttachments: [texture]
6459
- }));
6582
+ });
6460
6583
  return framebuffer;
6461
6584
  }
6462
6585
  function getPixelArray(pixelArray, type, format, width, height) {