@luma.gl/webgl 9.1.0-alpha.1 → 9.1.0-alpha.12

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 (109) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +18 -11
  3. package/dist/adapter/converters/texture-formats.d.ts +1 -1
  4. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  5. package/dist/adapter/converters/texture-formats.js +9 -16
  6. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  7. package/dist/adapter/device-helpers/webgl-device-features.js +1 -3
  8. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  9. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  10. package/dist/adapter/helpers/get-shader-layout.js +1 -3
  11. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  12. package/dist/adapter/helpers/webgl-texture-utils.d.ts +89 -22
  13. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  14. package/dist/adapter/helpers/webgl-texture-utils.js +220 -26
  15. package/dist/adapter/resources/webgl-framebuffer.js +1 -1
  16. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgl-render-pass.js +17 -4
  18. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -3
  19. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgl-render-pipeline.js +1 -1
  21. package/dist/adapter/resources/webgl-shader.js +1 -1
  22. package/dist/adapter/resources/webgl-texture.d.ts +21 -3
  23. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgl-texture.js +49 -30
  25. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  26. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-vertex-array.js +3 -0
  28. package/dist/adapter/webgl-adapter.d.ts +21 -0
  29. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  30. package/dist/adapter/webgl-adapter.js +91 -0
  31. package/dist/adapter/webgl-device.d.ts +16 -29
  32. package/dist/adapter/webgl-device.d.ts.map +1 -1
  33. package/dist/adapter/webgl-device.js +34 -114
  34. package/dist/context/debug/spector-types.d.ts +1108 -0
  35. package/dist/context/debug/spector-types.d.ts.map +1 -0
  36. package/dist/context/debug/spector-types.js +697 -0
  37. package/dist/context/debug/spector.d.ts +12 -8
  38. package/dist/context/debug/spector.d.ts.map +1 -1
  39. package/dist/context/debug/spector.js +23 -17
  40. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  41. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  42. package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
  43. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  44. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  45. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +44 -74
  46. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  47. package/dist/context/state-tracker/with-parameters.js +5 -4
  48. package/dist/deprecated/accessor.d.ts.map +1 -0
  49. package/dist/{classic → deprecated}/accessor.js +36 -1
  50. package/dist/deprecated/clear.d.ts.map +1 -0
  51. package/dist/{classic → deprecated}/clear.js +2 -0
  52. package/dist/dist.dev.js +816 -642
  53. package/dist/dist.min.js +2 -2
  54. package/dist/index.cjs +815 -648
  55. package/dist/index.cjs.map +4 -4
  56. package/dist/index.d.ts +4 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +4 -3
  59. package/dist/utils/fill-array.d.ts +4 -4
  60. package/dist/utils/fill-array.d.ts.map +1 -1
  61. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  62. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  63. package/dist/utils/uid.d.ts +7 -0
  64. package/dist/utils/uid.d.ts.map +1 -0
  65. package/dist/utils/uid.js +14 -0
  66. package/package.json +5 -5
  67. package/src/adapter/converters/device-parameters.ts +18 -12
  68. package/src/adapter/converters/texture-formats.ts +12 -20
  69. package/src/adapter/device-helpers/webgl-device-features.ts +5 -3
  70. package/src/adapter/helpers/get-shader-layout.ts +1 -3
  71. package/src/adapter/helpers/webgl-texture-utils.ts +366 -44
  72. package/src/adapter/resources/webgl-framebuffer.ts +1 -1
  73. package/src/adapter/resources/webgl-render-pass.ts +20 -7
  74. package/src/adapter/resources/webgl-render-pipeline.ts +12 -4
  75. package/src/adapter/resources/webgl-shader.ts +1 -1
  76. package/src/adapter/resources/webgl-texture.ts +76 -30
  77. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  78. package/src/adapter/resources/webgl-vertex-array.ts +3 -0
  79. package/src/adapter/webgl-adapter.ts +113 -0
  80. package/src/adapter/webgl-device.ts +45 -139
  81. package/src/context/debug/spector-types.ts +1154 -0
  82. package/src/context/debug/spector.ts +38 -29
  83. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  84. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
  85. package/src/context/state-tracker/with-parameters.ts +5 -4
  86. package/src/{classic → deprecated}/accessor.ts +44 -3
  87. package/src/{classic → deprecated}/clear.ts +3 -1
  88. package/src/index.ts +6 -8
  89. package/src/utils/fill-array.ts +4 -4
  90. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  91. package/src/utils/uid.ts +16 -0
  92. package/dist/classic/accessor.d.ts.map +0 -1
  93. package/dist/classic/clear.d.ts.map +0 -1
  94. package/dist/classic/copy-and-blit.d.ts +0 -63
  95. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  96. package/dist/classic/copy-and-blit.js +0 -193
  97. package/dist/classic/format-utils.d.ts.map +0 -1
  98. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  99. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  100. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
  101. package/src/classic/copy-and-blit.ts +0 -318
  102. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  103. /package/dist/{classic → adapter/helpers}/format-utils.js +0 -0
  104. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  105. /package/dist/{classic → adapter/helpers}/typed-array-utils.js +0 -0
  106. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  107. /package/dist/{classic → deprecated}/clear.d.ts +0 -0
  108. /package/src/{classic → adapter/helpers}/format-utils.ts +0 -0
  109. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
package/dist/index.cjs CHANGED
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
5
  var __export = (target, all) => {
7
6
  for (var name in all)
8
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
16
15
  return to;
17
16
  };
18
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __publicField = (obj, key, value) => {
20
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- return value;
22
- };
23
18
 
24
19
  // dist/index.js
25
20
  var dist_exports = {};
@@ -37,22 +32,24 @@ __export(dist_exports, {
37
32
  WEBGLVertexArray: () => WEBGLVertexArray,
38
33
  WebGLCanvasContext: () => WebGLCanvasContext,
39
34
  WebGLDevice: () => WebGLDevice,
35
+ WebGLStateTracker: () => WebGLStateTracker,
40
36
  _TEXTURE_FORMATS: () => TEXTURE_FORMATS,
41
37
  getGLParameters: () => getGLParameters,
42
38
  getShaderLayout: () => getShaderLayout,
43
- popContextState: () => popContextState,
44
- pushContextState: () => pushContextState,
45
39
  resetGLParameters: () => resetGLParameters,
46
40
  setDeviceParameters: () => setDeviceParameters,
47
41
  setGLParameters: () => setGLParameters,
48
- trackContextState: () => trackContextState,
42
+ webgl2Adapter: () => webgl2Adapter,
49
43
  withDeviceParameters: () => withDeviceParameters,
50
44
  withGLParameters: () => withGLParameters
51
45
  });
52
46
  module.exports = __toCommonJS(dist_exports);
53
47
 
48
+ // dist/adapter/webgl-adapter.js
49
+ var import_core24 = require("@luma.gl/core");
50
+
54
51
  // dist/adapter/webgl-device.js
55
- var import_core22 = require("@luma.gl/core");
52
+ var import_core23 = require("@luma.gl/core");
56
53
 
57
54
  // dist/context/parameters/webgl-parameter-tables.js
58
55
  var import_constants = require("@luma.gl/constants");
@@ -594,24 +591,22 @@ function deepArrayEqual(x, y) {
594
591
  return false;
595
592
  }
596
593
 
597
- // dist/context/state-tracker/track-context-state.js
598
- var GLState = class {
594
+ // dist/context/state-tracker/webgl-state-tracker.js
595
+ var WebGLStateTracker = class {
596
+ static get(gl) {
597
+ return gl.state;
598
+ }
599
599
  gl;
600
600
  program = null;
601
601
  stateStack = [];
602
602
  enable = true;
603
- cache;
603
+ cache = null;
604
604
  log;
605
- constructor(gl, {
606
- copyState = false,
607
- // Copy cache from params (slow) or initialize from WebGL defaults (fast)
608
- log: log9 = () => {
609
- }
610
- // Logging function, called when gl parameter change calls are actually issued
611
- } = {}) {
605
+ initialized = false;
606
+ constructor(gl, props) {
612
607
  this.gl = gl;
613
- this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
614
- this.log = log9;
608
+ this.log = (props == null ? void 0 : props.log) || (() => {
609
+ });
615
610
  this._updateCache = this._updateCache.bind(this);
616
611
  Object.seal(this);
617
612
  }
@@ -623,6 +618,29 @@ var GLState = class {
623
618
  setGLParameters(this.gl, oldValues);
624
619
  this.stateStack.pop();
625
620
  }
621
+ /**
622
+ * Initialize WebGL state caching on a context
623
+ * can be called multiple times to enable/disable
624
+ *
625
+ * @note After calling this function, context state will be cached
626
+ * .push() and .pop() will be available for saving,
627
+ * temporarily modifying, and then restoring state.
628
+ */
629
+ trackState(gl, options) {
630
+ this.cache = options.copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
631
+ if (this.initialized) {
632
+ throw new Error("WebGLStateTracker");
633
+ }
634
+ this.initialized = true;
635
+ this.gl.state = this;
636
+ installProgramSpy(gl);
637
+ for (const key in GL_HOOKED_SETTERS) {
638
+ const setter = GL_HOOKED_SETTERS[key];
639
+ installSetterSpy(gl, key, setter);
640
+ }
641
+ installGetterOverride(gl, "getParameter");
642
+ installGetterOverride(gl, "isEnabled");
643
+ }
626
644
  /**
627
645
  // interceptor for context set functions - update our cache and our stack
628
646
  // values (Object) - the key values for this setter
@@ -648,44 +666,13 @@ var GLState = class {
648
666
  return { valueChanged, oldValue };
649
667
  }
650
668
  };
651
- function getContextState(gl) {
652
- return gl.state;
653
- }
654
- function trackContextState(gl, options) {
655
- const { enable: enable2 = true, copyState } = options || {};
656
- if (!gl.state) {
657
- gl.state = new GLState(gl, { copyState });
658
- installProgramSpy(gl);
659
- for (const key in GL_HOOKED_SETTERS) {
660
- const setter = GL_HOOKED_SETTERS[key];
661
- installSetterSpy(gl, key, setter);
662
- }
663
- installGetterOverride(gl, "getParameter");
664
- installGetterOverride(gl, "isEnabled");
665
- }
666
- const glState = getContextState(gl);
667
- glState.enable = enable2;
668
- return gl;
669
- }
670
- function pushContextState(gl) {
671
- let glState = getContextState(gl);
672
- if (!glState) {
673
- trackContextState(gl, { copyState: false });
674
- glState = getContextState(gl);
675
- }
676
- glState.push();
677
- }
678
- function popContextState(gl) {
679
- const glState = getContextState(gl);
680
- glState.pop();
681
- }
682
669
  function installGetterOverride(gl, functionName) {
683
670
  const originalGetterFunc = gl[functionName].bind(gl);
684
671
  gl[functionName] = function get(pname) {
685
672
  if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
686
673
  return originalGetterFunc(pname);
687
674
  }
688
- const glState = getContextState(gl);
675
+ const glState = WebGLStateTracker.get(gl);
689
676
  if (!(pname in glState.cache)) {
690
677
  glState.cache[pname] = originalGetterFunc(pname);
691
678
  }
@@ -708,7 +695,7 @@ function installSetterSpy(gl, functionName, setter) {
708
695
  }
709
696
  const originalSetterFunc = gl[functionName].bind(gl);
710
697
  gl[functionName] = function set(...params) {
711
- const glState = getContextState(gl);
698
+ const glState = WebGLStateTracker.get(gl);
712
699
  const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
713
700
  if (valueChanged) {
714
701
  originalSetterFunc(...params);
@@ -723,7 +710,7 @@ function installSetterSpy(gl, functionName, setter) {
723
710
  function installProgramSpy(gl) {
724
711
  const originalUseProgram = gl.useProgram.bind(gl);
725
712
  gl.useProgram = function useProgramLuma(handle) {
726
- const glState = getContextState(gl);
713
+ const glState = WebGLStateTracker.get(gl);
727
714
  if (glState.program !== handle) {
728
715
  originalUseProgram(handle);
729
716
  glState.program = handle;
@@ -941,26 +928,6 @@ function checkTextureFeature(gl, feature, extensions) {
941
928
  return textureExtensions.every((extension) => getWebGLExtension(gl, extension, extensions));
942
929
  }
943
930
  var TEXTURE_FORMATS = {
944
- // Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
945
- "rgb8unorm-unsized": {
946
- gl: 6407,
947
- b: 4,
948
- c: 2,
949
- bpp: 4,
950
- dataFormat: 6407,
951
- types: [5121, 33635]
952
- },
953
- "rgba8unorm-unsized": {
954
- gl: 6408,
955
- b: 4,
956
- c: 2,
957
- bpp: 4,
958
- dataFormat: 6408,
959
- types: [5121, 32819, 32820]
960
- },
961
- // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
962
- // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
963
- // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
964
931
  // 8-bit formats
965
932
  "r8unorm": { gl: 33321, b: 1, c: 1, rb: true },
966
933
  "r8snorm": { gl: 36756, b: 1, c: 1, render: snorm8_renderable },
@@ -1075,17 +1042,6 @@ var TEXTURE_FORMATS = {
1075
1042
  dataFormat: 34041,
1076
1043
  types: [34042]
1077
1044
  },
1078
- // "depth24unorm-stencil8" feature
1079
- "depth24unorm-stencil8": {
1080
- gl: 35056,
1081
- b: 4,
1082
- c: 2,
1083
- p: 1,
1084
- attachment: 33306,
1085
- dataFormat: 34041,
1086
- types: [34042],
1087
- rb: true
1088
- },
1089
1045
  // "depth32float-stencil8" feature - TODO below is render buffer only?
1090
1046
  "depth32float-stencil8": {
1091
1047
  gl: 36013,
@@ -1175,6 +1131,10 @@ function isTextureFormatSupported(gl, format, extensions) {
1175
1131
  if (info.gl === void 0) {
1176
1132
  return false;
1177
1133
  }
1134
+ const feature = info.f;
1135
+ if (feature) {
1136
+ return checkTextureFeature(gl, feature, extensions);
1137
+ }
1178
1138
  const extension = info.x || info.gl2ext;
1179
1139
  if (extension) {
1180
1140
  return Boolean(getWebGLExtension(gl, extension, extensions));
@@ -1220,11 +1180,10 @@ function getTextureFormatWebGL(format) {
1220
1180
  const decoded = (0, import_core.decodeTextureFormat)(format);
1221
1181
  return {
1222
1182
  internalFormat: webglFormat,
1223
- format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
1183
+ format: (formatData == null ? void 0 : formatData.dataFormat) || getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
1224
1184
  // depth formats don't have a type
1225
1185
  type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : ((_a = formatData == null ? void 0 : formatData.types) == null ? void 0 : _a[0]) || 5121,
1226
- // @ts-expect-error
1227
- compressed: decoded.compressed
1186
+ compressed: decoded.compressed || false
1228
1187
  };
1229
1188
  }
1230
1189
  function getDepthStencilAttachmentWebGL(format) {
@@ -1234,11 +1193,11 @@ function getDepthStencilAttachmentWebGL(format) {
1234
1193
  }
1235
1194
  return info.attachment;
1236
1195
  }
1237
- function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
1196
+ function getWebGLPixelDataFormat(channels, integer, normalized, format) {
1238
1197
  if (format === 6408 || format === 6407) {
1239
1198
  return format;
1240
1199
  }
1241
- switch (dataFormat) {
1200
+ switch (channels) {
1242
1201
  case "r":
1243
1202
  return integer && !normalized ? 36244 : 6403;
1244
1203
  case "rg":
@@ -1247,6 +1206,8 @@ function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
1247
1206
  return integer && !normalized ? 36248 : 6407;
1248
1207
  case "rgba":
1249
1208
  return integer && !normalized ? 36249 : 6408;
1209
+ case "bgra":
1210
+ throw new Error("bgra pixels not supported by WebGL");
1250
1211
  default:
1251
1212
  return 6408;
1252
1213
  }
@@ -1268,7 +1229,6 @@ var WEBGL_FEATURES = {
1268
1229
  // 'timestamp-query' // GPUQueryType "timestamp-query"
1269
1230
  // "indirect-first-instance"
1270
1231
  // Textures are handled by getTextureFeatures()
1271
- // 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
1272
1232
  // 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
1273
1233
  // optional WebGL features
1274
1234
  "timer-query-webgl": "EXT_disjoint_timer_query_webgl2",
@@ -1446,15 +1406,15 @@ var WebGLDeviceLimits = class extends import_core3.DeviceLimits {
1446
1406
  };
1447
1407
 
1448
1408
  // dist/adapter/webgl-canvas-context.js
1449
- var import_core9 = require("@luma.gl/core");
1409
+ var import_core10 = require("@luma.gl/core");
1450
1410
 
1451
1411
  // dist/adapter/resources/webgl-framebuffer.js
1452
- var import_core8 = require("@luma.gl/core");
1453
- var import_constants11 = require("@luma.gl/constants");
1412
+ var import_core9 = require("@luma.gl/core");
1413
+ var import_constants13 = require("@luma.gl/constants");
1454
1414
 
1455
1415
  // dist/adapter/resources/webgl-texture.js
1456
- var import_core7 = require("@luma.gl/core");
1457
- var import_constants10 = require("@luma.gl/constants");
1416
+ var import_core8 = require("@luma.gl/core");
1417
+ var import_constants12 = require("@luma.gl/constants");
1458
1418
 
1459
1419
  // dist/context/state-tracker/with-parameters.js
1460
1420
  function withGLParameters(gl, parameters, func) {
@@ -1462,17 +1422,18 @@ function withGLParameters(gl, parameters, func) {
1462
1422
  return func(gl);
1463
1423
  }
1464
1424
  const { nocatch = true } = parameters;
1465
- pushContextState(gl);
1425
+ const webglState = WebGLStateTracker.get(gl);
1426
+ webglState.push();
1466
1427
  setGLParameters(gl, parameters);
1467
1428
  let value;
1468
1429
  if (nocatch) {
1469
1430
  value = func(gl);
1470
- popContextState(gl);
1431
+ webglState.pop();
1471
1432
  } else {
1472
1433
  try {
1473
1434
  value = func(gl);
1474
1435
  } finally {
1475
- popContextState(gl);
1436
+ webglState.pop();
1476
1437
  }
1477
1438
  }
1478
1439
  return value;
@@ -1495,25 +1456,26 @@ function withDeviceAndGLParameters(device, parameters, glParameters, func) {
1495
1456
  return func(device);
1496
1457
  }
1497
1458
  const webglDevice = device;
1498
- pushContextState(webglDevice.gl);
1459
+ webglDevice.pushState();
1499
1460
  try {
1500
1461
  setDeviceParameters(device, parameters);
1501
1462
  setGLParameters(webglDevice.gl, glParameters);
1502
1463
  return func(device);
1503
1464
  } finally {
1504
- popContextState(webglDevice.gl);
1465
+ webglDevice.popState();
1505
1466
  }
1506
1467
  }
1507
1468
  function withDeviceParameters(device, parameters, func) {
1508
1469
  if (isObjectEmpty3(parameters)) {
1509
1470
  return func(device);
1510
1471
  }
1511
- pushContextState(device.gl);
1472
+ const webglDevice = device;
1473
+ webglDevice.pushState();
1512
1474
  try {
1513
1475
  setDeviceParameters(device, parameters);
1514
1476
  return func(device);
1515
1477
  } finally {
1516
- popContextState(device.gl);
1478
+ webglDevice.popState();
1517
1479
  }
1518
1480
  }
1519
1481
  function setDeviceParameters(device, parameters) {
@@ -1632,8 +1594,16 @@ function setDeviceParameters(device, parameters) {
1632
1594
  gl.stencilOpSeparate(1028, sfail, dpfail, dppass);
1633
1595
  gl.stencilOpSeparate(1029, sfail, dpfail, dppass);
1634
1596
  }
1597
+ switch (parameters.blend) {
1598
+ case true:
1599
+ gl.enable(3042);
1600
+ break;
1601
+ case false:
1602
+ gl.disable(3042);
1603
+ break;
1604
+ default:
1605
+ }
1635
1606
  if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
1636
- gl.enable(3042);
1637
1607
  const colorEquation = convertBlendOperationToEquation("blendColorOperation", parameters.blendColorOperation || "add");
1638
1608
  const alphaEquation = convertBlendOperationToEquation("blendAlphaOperation", parameters.blendAlphaOperation || "add");
1639
1609
  gl.blendEquationSeparate(colorEquation, alphaEquation);
@@ -1840,7 +1810,97 @@ var WEBGLTextureView = class extends import_core6.TextureView {
1840
1810
  };
1841
1811
 
1842
1812
  // dist/adapter/helpers/webgl-texture-utils.js
1813
+ var import_core7 = require("@luma.gl/core");
1814
+ var import_constants11 = require("@luma.gl/constants");
1815
+
1816
+ // dist/adapter/helpers/typed-array-utils.js
1843
1817
  var import_constants9 = require("@luma.gl/constants");
1818
+ var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
1819
+ function getGLTypeFromTypedArray(arrayOrType) {
1820
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
1821
+ switch (type) {
1822
+ case Float32Array:
1823
+ return 5126;
1824
+ case Uint16Array:
1825
+ return 5123;
1826
+ case Uint32Array:
1827
+ return 5125;
1828
+ case Uint8Array:
1829
+ return 5121;
1830
+ case Uint8ClampedArray:
1831
+ return 5121;
1832
+ case Int8Array:
1833
+ return 5120;
1834
+ case Int16Array:
1835
+ return 5122;
1836
+ case Int32Array:
1837
+ return 5124;
1838
+ default:
1839
+ throw new Error(ERR_TYPE_DEDUCTION);
1840
+ }
1841
+ }
1842
+ function getTypedArrayFromGLType(glType, options) {
1843
+ const { clamped = true } = options || {};
1844
+ switch (glType) {
1845
+ case 5126:
1846
+ return Float32Array;
1847
+ case 5123:
1848
+ case 33635:
1849
+ case 32819:
1850
+ case 32820:
1851
+ return Uint16Array;
1852
+ case 5125:
1853
+ return Uint32Array;
1854
+ case 5121:
1855
+ return clamped ? Uint8ClampedArray : Uint8Array;
1856
+ case 5120:
1857
+ return Int8Array;
1858
+ case 5122:
1859
+ return Int16Array;
1860
+ case 5124:
1861
+ return Int32Array;
1862
+ default:
1863
+ throw new Error("Failed to deduce typed array type from GL constant");
1864
+ }
1865
+ }
1866
+
1867
+ // dist/adapter/helpers/format-utils.js
1868
+ var import_constants10 = require("@luma.gl/constants");
1869
+ function glFormatToComponents(format) {
1870
+ switch (format) {
1871
+ case 6406:
1872
+ case 33326:
1873
+ case 6403:
1874
+ return 1;
1875
+ case 33328:
1876
+ case 33319:
1877
+ return 2;
1878
+ case 6407:
1879
+ case 34837:
1880
+ return 3;
1881
+ case 6408:
1882
+ case 34836:
1883
+ return 4;
1884
+ default:
1885
+ return 0;
1886
+ }
1887
+ }
1888
+ function glTypeToBytes(type) {
1889
+ switch (type) {
1890
+ case 5121:
1891
+ return 1;
1892
+ case 33635:
1893
+ case 32819:
1894
+ case 32820:
1895
+ return 2;
1896
+ case 5126:
1897
+ return 4;
1898
+ default:
1899
+ return 0;
1900
+ }
1901
+ }
1902
+
1903
+ // dist/adapter/helpers/webgl-texture-utils.js
1844
1904
  function initializeTextureStorage(gl, levels, options) {
1845
1905
  const { dimension, width, height, depth = 0 } = options;
1846
1906
  const { glInternalFormat } = options;
@@ -1854,44 +1914,49 @@ function initializeTextureStorage(gl, levels, options) {
1854
1914
  gl.texStorage2D(glTarget, levels, glInternalFormat, width, height);
1855
1915
  }
1856
1916
  }
1857
- function copyCPUImageToMipLevel(gl, image, options) {
1858
- const { dimension, width, height, depth = 0, level = 0 } = options;
1917
+ function copyExternalImageToMipLevel(gl, handle, image, options) {
1918
+ const { width, height } = options;
1919
+ const { dimension, depth = 0, mipLevel = 0 } = options;
1859
1920
  const { x = 0, y = 0, z = 0 } = options;
1860
1921
  const { glFormat, glType } = options;
1861
- const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1922
+ const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
1862
1923
  switch (dimension) {
1863
1924
  case "2d-array":
1864
1925
  case "3d":
1865
- gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, image);
1926
+ gl.bindTexture(glTarget, handle);
1927
+ gl.texSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, glType, image);
1928
+ gl.bindTexture(glTarget, null);
1866
1929
  break;
1867
1930
  case "2d":
1868
1931
  case "cube":
1869
- gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, image);
1932
+ gl.bindTexture(glTarget, handle);
1933
+ gl.texSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, glType, image);
1934
+ gl.bindTexture(glTarget, null);
1870
1935
  break;
1871
1936
  default:
1872
1937
  throw new Error(dimension);
1873
1938
  }
1874
1939
  }
1875
1940
  function copyCPUDataToMipLevel(gl, typedArray, options) {
1876
- const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
1941
+ const { dimension, width, height, depth = 0, mipLevel = 0, byteOffset = 0 } = options;
1877
1942
  const { x = 0, y = 0, z = 0 } = options;
1878
1943
  const { glFormat, glType, compressed } = options;
1879
- const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1944
+ const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
1880
1945
  switch (dimension) {
1881
1946
  case "2d-array":
1882
1947
  case "3d":
1883
1948
  if (compressed) {
1884
- gl.compressedTexSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, typedArray, byteOffset);
1949
+ gl.compressedTexSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, typedArray, byteOffset);
1885
1950
  } else {
1886
- gl.texSubImage3D(glTarget, level, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset);
1951
+ gl.texSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset);
1887
1952
  }
1888
1953
  break;
1889
1954
  case "2d":
1890
1955
  case "cube":
1891
1956
  if (compressed) {
1892
- gl.compressedTexSubImage2D(glTarget, level, x, y, width, height, glFormat, typedArray, byteOffset);
1957
+ gl.compressedTexSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, typedArray, byteOffset);
1893
1958
  } else {
1894
- gl.texSubImage2D(glTarget, level, x, y, width, height, glFormat, glType, typedArray, byteOffset);
1959
+ gl.texSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, glType, typedArray, byteOffset);
1895
1960
  }
1896
1961
  break;
1897
1962
  default:
@@ -1915,9 +1980,100 @@ function getWebGLTextureTarget(dimension) {
1915
1980
  }
1916
1981
  throw new Error(dimension);
1917
1982
  }
1918
- function getCubeTargetWebGL(glTarget, dimension, level) {
1983
+ function getWebGLCubeFaceTarget(glTarget, dimension, level) {
1919
1984
  return dimension === "cube" ? 34069 + level : glTarget;
1920
1985
  }
1986
+ function readPixelsToArray(source, options) {
1987
+ var _a, _b, _c, _d, _e, _f;
1988
+ const {
1989
+ sourceX = 0,
1990
+ sourceY = 0,
1991
+ sourceAttachment = 36064
1992
+ // TODO - support gl.readBuffer
1993
+ } = options || {};
1994
+ let {
1995
+ target = null,
1996
+ // following parameters are auto deduced if not provided
1997
+ sourceWidth,
1998
+ sourceHeight,
1999
+ sourceDepth,
2000
+ sourceFormat,
2001
+ sourceType
2002
+ } = options || {};
2003
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
2004
+ const { gl, handle } = framebuffer;
2005
+ const attachment = sourceAttachment - 36064;
2006
+ sourceWidth ||= framebuffer.width;
2007
+ sourceHeight ||= framebuffer.height;
2008
+ sourceDepth = ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.depth) || 1;
2009
+ sourceFormat ||= ((_d = (_c = framebuffer.colorAttachments[attachment]) == null ? void 0 : _c.texture) == null ? void 0 : _d.glFormat) || 6408;
2010
+ sourceType ||= ((_f = (_e = framebuffer.colorAttachments[attachment]) == null ? void 0 : _e.texture) == null ? void 0 : _f.glType) || 5121;
2011
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
2012
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
2013
+ const prevHandle = gl.bindFramebuffer(36160, handle);
2014
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
2015
+ gl.bindFramebuffer(36160, prevHandle || null);
2016
+ if (deleteFramebuffer) {
2017
+ framebuffer.destroy();
2018
+ }
2019
+ return target;
2020
+ }
2021
+ function readPixelsToBuffer(source, options) {
2022
+ const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
2023
+ let { sourceWidth, sourceHeight, sourceType } = options || {};
2024
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
2025
+ sourceWidth = sourceWidth || framebuffer.width;
2026
+ sourceHeight = sourceHeight || framebuffer.height;
2027
+ const webglFramebuffer = framebuffer;
2028
+ sourceType = sourceType || 5121;
2029
+ let webglBufferTarget = target;
2030
+ if (!webglBufferTarget) {
2031
+ const components = glFormatToComponents(sourceFormat);
2032
+ const byteCount = glTypeToBytes(sourceType);
2033
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
2034
+ webglBufferTarget = webglFramebuffer.device.createBuffer({ byteLength });
2035
+ }
2036
+ const commandEncoder = source.device.createCommandEncoder();
2037
+ commandEncoder.copyTextureToBuffer({
2038
+ source,
2039
+ width: sourceWidth,
2040
+ height: sourceHeight,
2041
+ origin: [sourceX, sourceY],
2042
+ destination: webglBufferTarget,
2043
+ byteOffset: targetByteOffset
2044
+ });
2045
+ commandEncoder.destroy();
2046
+ if (deleteFramebuffer) {
2047
+ framebuffer.destroy();
2048
+ }
2049
+ return webglBufferTarget;
2050
+ }
2051
+ function getFramebuffer(source) {
2052
+ if (!(source instanceof import_core7.Framebuffer)) {
2053
+ return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
2054
+ }
2055
+ return { framebuffer: source, deleteFramebuffer: false };
2056
+ }
2057
+ function toFramebuffer(texture, props) {
2058
+ const { device, width, height, id } = texture;
2059
+ const framebuffer = device.createFramebuffer({
2060
+ ...props,
2061
+ id: `framebuffer-for-${id}`,
2062
+ width,
2063
+ height,
2064
+ colorAttachments: [texture]
2065
+ });
2066
+ return framebuffer;
2067
+ }
2068
+ function getPixelArray(pixelArray, type, format, width, height, depth) {
2069
+ if (pixelArray) {
2070
+ return pixelArray;
2071
+ }
2072
+ type = type || 5121;
2073
+ const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
2074
+ const components = glFormatToComponents(format);
2075
+ return new ArrayType(width * height * components);
2076
+ }
1921
2077
 
1922
2078
  // dist/adapter/resources/webgl-texture.js
1923
2079
  function normalizeTextureData(data, options) {
@@ -1939,7 +2095,7 @@ function normalizeTextureData(data, options) {
1939
2095
  }
1940
2096
  return lodArray;
1941
2097
  }
1942
- var WEBGLTexture = class extends import_core7.Texture {
2098
+ var WEBGLTexture = class extends import_core8.Texture {
1943
2099
  MAX_ATTRIBUTES;
1944
2100
  device;
1945
2101
  gl;
@@ -1980,7 +2136,7 @@ var WEBGLTexture = class extends import_core7.Texture {
1980
2136
  /** For automatically updating video */
1981
2137
  _video = null;
1982
2138
  constructor(device, props) {
1983
- super(device, { ...import_core7.Texture.defaultProps, ...props, data: void 0 });
2139
+ super(device, { ...import_core8.Texture.defaultProps, ...props, data: void 0 });
1984
2140
  this.device = device;
1985
2141
  this.gl = this.device.gl;
1986
2142
  this.glTarget = getWebGLTextureTarget(this.props.dimension);
@@ -2008,7 +2164,7 @@ var WEBGLTexture = class extends import_core7.Texture {
2008
2164
  const data = props.data;
2009
2165
  let { width, height } = props;
2010
2166
  if (!width || !height) {
2011
- const textureSize = this.getTextureDataSize(data);
2167
+ const textureSize = import_core8.Texture.getTextureDataSize(data);
2012
2168
  width = (textureSize == null ? void 0 : textureSize.width) || 1;
2013
2169
  height = (textureSize == null ? void 0 : textureSize.height) || 1;
2014
2170
  }
@@ -2101,7 +2257,7 @@ var WEBGLTexture = class extends import_core7.Texture {
2101
2257
  }
2102
2258
  /** Update external texture (video frame or canvas) */
2103
2259
  update() {
2104
- import_core7.log.warn("Texture.update() not implemented");
2260
+ import_core8.log.warn("Texture.update() not implemented");
2105
2261
  }
2106
2262
  // Call to regenerate mipmaps after modifying texture(s)
2107
2263
  generateMipmap(params = {}) {
@@ -2116,15 +2272,42 @@ var WEBGLTexture = class extends import_core7.Texture {
2116
2272
  this.gl.bindTexture(this.glTarget, null);
2117
2273
  }
2118
2274
  // Image Data Setters
2275
+ copyExternalImage(options) {
2276
+ const size = import_core8.Texture.getExternalImageSize(options.image);
2277
+ const opts = { ...import_core8.Texture.defaultCopyExternalImageOptions, ...size, ...options };
2278
+ const { image, depth, mipLevel, x, y, z } = opts;
2279
+ let { width, height } = opts;
2280
+ const { dimension, glTarget, glFormat, glInternalFormat, glType } = this;
2281
+ width = Math.min(width, size.width - x);
2282
+ height = Math.min(height, size.height - y);
2283
+ if (options.sourceX || options.sourceY) {
2284
+ throw new Error("WebGL does not yet support sourceX/sourceY in copyExternalImage; requires copyTexSubImage2D from a framebuffer");
2285
+ }
2286
+ copyExternalImageToMipLevel(this.device.gl, this.handle, image, {
2287
+ dimension,
2288
+ mipLevel,
2289
+ x,
2290
+ y,
2291
+ z,
2292
+ width,
2293
+ height,
2294
+ depth,
2295
+ glFormat,
2296
+ glInternalFormat,
2297
+ glType,
2298
+ glTarget
2299
+ });
2300
+ return { width: opts.width, height: opts.height };
2301
+ }
2119
2302
  setTexture1DData(data) {
2120
2303
  throw new Error("setTexture1DData not supported in WebGL.");
2121
2304
  }
2122
2305
  /** Set a simple texture */
2123
- setTexture2DData(lodData, depth = 0, glTarget = this.glTarget) {
2306
+ setTexture2DData(lodData, depth = 0) {
2124
2307
  this.bind();
2125
2308
  const lodArray = normalizeTextureData(lodData, this);
2126
2309
  if (lodArray.length > 1 && this.props.mipmaps !== false) {
2127
- import_core7.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
2310
+ import_core8.log.warn(`Texture ${this.id} mipmap and multiple LODs.`)();
2128
2311
  }
2129
2312
  for (let lodLevel = 0; lodLevel < lodArray.length; lodLevel++) {
2130
2313
  const imageData = lodArray[lodLevel];
@@ -2141,7 +2324,9 @@ var WEBGLTexture = class extends import_core7.Texture {
2141
2324
  throw new Error(this.id);
2142
2325
  }
2143
2326
  if (ArrayBuffer.isView(data)) {
2327
+ this.bind();
2144
2328
  copyCPUDataToMipLevel(this.device.gl, data, this);
2329
+ this.unbind();
2145
2330
  }
2146
2331
  }
2147
2332
  /**
@@ -2154,6 +2339,9 @@ var WEBGLTexture = class extends import_core7.Texture {
2154
2339
  if (this.props.dimension !== "cube") {
2155
2340
  throw new Error(this.id);
2156
2341
  }
2342
+ for (const face of import_core8.Texture.CubeFaces) {
2343
+ this.setTextureCubeFaceData(data[face], face);
2344
+ }
2157
2345
  }
2158
2346
  /**
2159
2347
  * Sets an entire texture array
@@ -2174,10 +2362,10 @@ var WEBGLTexture = class extends import_core7.Texture {
2174
2362
  }
2175
2363
  setTextureCubeFaceData(lodData, face, depth = 0) {
2176
2364
  if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
2177
- import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
2365
+ import_core8.log.warn(`${this.id} has mipmap and multiple LODs.`)();
2178
2366
  }
2179
- this.bind();
2180
- this.unbind();
2367
+ const faceDepth = import_core8.Texture.CubeFaces.indexOf(face);
2368
+ this.setTexture2DData(lodData, faceDepth);
2181
2369
  }
2182
2370
  // INTERNAL METHODS
2183
2371
  /** @todo update this method to accept LODs */
@@ -2208,8 +2396,8 @@ var WEBGLTexture = class extends import_core7.Texture {
2208
2396
  }
2209
2397
  }
2210
2398
  _getImageDataMap(faceData) {
2211
- for (let i = 0; i < import_core7.Texture.CubeFaces.length; ++i) {
2212
- const faceName = import_core7.Texture.CubeFaces[i];
2399
+ for (let i = 0; i < import_core8.Texture.CubeFaces.length; ++i) {
2400
+ const faceName = import_core8.Texture.CubeFaces[i];
2213
2401
  if (faceData[faceName]) {
2214
2402
  faceData[34069 + i] = faceData[faceName];
2215
2403
  delete faceData[faceName];
@@ -2222,7 +2410,7 @@ var WEBGLTexture = class extends import_core7.Texture {
2222
2410
  * Sets sampler parameters on texture
2223
2411
  */
2224
2412
  _setSamplerParameters(parameters) {
2225
- import_core7.log.log(1, "texture sampler parameters", parameters)();
2413
+ import_core8.log.log(1, "texture sampler parameters", parameters)();
2226
2414
  this.gl.bindTexture(this.glTarget, this.handle);
2227
2415
  for (const [pname, pvalue] of Object.entries(parameters)) {
2228
2416
  const param = Number(pname);
@@ -2311,16 +2499,22 @@ var WEBGLTexture = class extends import_core7.Texture {
2311
2499
  * Copy a region of data from a CPU memory buffer into this texture.
2312
2500
  * @todo - GLUnpackParameters parameters
2313
2501
  */
2314
- _setMipLevel(depth, level, textureData, offset = 0) {
2315
- if (import_core7.Texture.isExternalImage(textureData)) {
2316
- copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
2502
+ _setMipLevel(depth, mipLevel, textureData, glTarget = this.glTarget) {
2503
+ if (import_core8.Texture.isExternalImage(textureData)) {
2504
+ copyExternalImageToMipLevel(this.device.gl, this.handle, textureData, {
2505
+ ...this,
2506
+ depth,
2507
+ mipLevel,
2508
+ glTarget
2509
+ });
2317
2510
  return;
2318
2511
  }
2319
- if (this.isTextureLevelData(textureData)) {
2512
+ if (import_core8.Texture.isTextureLevelData(textureData)) {
2320
2513
  copyCPUDataToMipLevel(this.device.gl, textureData.data, {
2321
2514
  ...this,
2322
2515
  depth,
2323
- level
2516
+ mipLevel,
2517
+ glTarget
2324
2518
  });
2325
2519
  return;
2326
2520
  }
@@ -2351,7 +2545,7 @@ var WEBGLTexture = class extends import_core7.Texture {
2351
2545
  };
2352
2546
 
2353
2547
  // dist/adapter/resources/webgl-framebuffer.js
2354
- var WEBGLFramebuffer = class extends import_core8.Framebuffer {
2548
+ var WEBGLFramebuffer = class extends import_core9.Framebuffer {
2355
2549
  device;
2356
2550
  gl;
2357
2551
  handle;
@@ -2453,7 +2647,7 @@ var WEBGLFramebuffer = class extends import_core8.Framebuffer {
2453
2647
  switch (texture.glTarget) {
2454
2648
  case 35866:
2455
2649
  case 32879:
2456
- gl.framebufferTextureLayer(36160, attachment, texture.glTarget, level, layer);
2650
+ gl.framebufferTextureLayer(36160, attachment, texture.handle, level, layer);
2457
2651
  break;
2458
2652
  case 34067:
2459
2653
  const face = mapIndexToCubeMapFace(layer);
@@ -2491,7 +2685,7 @@ function _getFrameBufferStatus(status) {
2491
2685
  }
2492
2686
 
2493
2687
  // dist/adapter/webgl-canvas-context.js
2494
- var WebGLCanvasContext = class extends import_core9.CanvasContext {
2688
+ var WebGLCanvasContext = class extends import_core10.CanvasContext {
2495
2689
  device;
2496
2690
  format = "rgba8unorm";
2497
2691
  depthStencilFormat = "depth24plus";
@@ -2544,7 +2738,7 @@ var WebGLCanvasContext = class extends import_core9.CanvasContext {
2544
2738
  };
2545
2739
 
2546
2740
  // dist/context/debug/spector.js
2547
- var import_core10 = require("@luma.gl/core");
2741
+ var import_core11 = require("@luma.gl/core");
2548
2742
 
2549
2743
  // dist/utils/load-script.js
2550
2744
  async function loadScript(scriptUrl, scriptId) {
@@ -2566,30 +2760,36 @@ async function loadScript(scriptUrl, scriptId) {
2566
2760
  }
2567
2761
 
2568
2762
  // dist/context/debug/spector.js
2569
- var DEFAULT_SPECTOR_PROPS = {
2570
- spector: import_core10.log.get("spector") || import_core10.log.get("inspect")
2571
- };
2572
- var SPECTOR_CDN_URL = "https://spectorcdn.babylonjs.com/spector.bundle.js";
2573
2763
  var LOG_LEVEL = 1;
2574
2764
  var spector = null;
2575
2765
  var initialized = false;
2766
+ var DEFAULT_SPECTOR_PROPS = {
2767
+ debugWithSpectorJS: import_core11.log.get("spector") || import_core11.log.get("spectorjs"),
2768
+ // https://github.com/BabylonJS/Spector.js#basic-usage
2769
+ // https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
2770
+ // spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
2771
+ spectorUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
2772
+ gl: void 0
2773
+ };
2576
2774
  async function loadSpectorJS(props) {
2577
2775
  if (!globalThis.SPECTOR) {
2578
2776
  try {
2579
- await loadScript(SPECTOR_CDN_URL);
2777
+ await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
2580
2778
  } catch (error) {
2581
- import_core10.log.warn(String(error));
2779
+ import_core11.log.warn(String(error));
2582
2780
  }
2583
2781
  }
2584
2782
  }
2585
2783
  function initializeSpectorJS(props) {
2784
+ var _a;
2586
2785
  props = { ...DEFAULT_SPECTOR_PROPS, ...props };
2587
- if (!(props == null ? void 0 : props.spector)) {
2786
+ if (!props.debugWithSpectorJS) {
2588
2787
  return null;
2589
2788
  }
2590
- if (!spector && globalThis.SPECTOR) {
2591
- import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
2592
- spector = new globalThis.SPECTOR.Spector();
2789
+ if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
2790
+ import_core11.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
2791
+ const { Spector } = globalThis.SPECTOR;
2792
+ spector = new Spector();
2593
2793
  if (globalThis.luma) {
2594
2794
  globalThis.luma.spector = spector;
2595
2795
  }
@@ -2600,21 +2800,21 @@ function initializeSpectorJS(props) {
2600
2800
  if (!initialized) {
2601
2801
  initialized = true;
2602
2802
  spector.spyCanvases();
2603
- spector == null ? void 0 : spector.onCaptureStarted.add((capture) => import_core10.log.info("Spector capture started:", capture)());
2803
+ spector == null ? void 0 : spector.onCaptureStarted.add((capture) => import_core11.log.info("Spector capture started:", capture)());
2604
2804
  spector == null ? void 0 : spector.onCapture.add((capture) => {
2605
- import_core10.log.info("Spector capture complete:", capture)();
2805
+ import_core11.log.info("Spector capture complete:", capture)();
2606
2806
  spector == null ? void 0 : spector.getResultUI();
2607
2807
  spector == null ? void 0 : spector.resultView.display();
2608
2808
  spector == null ? void 0 : spector.resultView.addCapture(capture);
2609
2809
  });
2610
2810
  }
2611
- if (props == null ? void 0 : props.canvas) {
2612
- if (typeof props.spector === "string" && props.spector !== props.canvas.id) {
2613
- return spector;
2614
- }
2615
- spector == null ? void 0 : spector.startCapture(props == null ? void 0 : props.canvas, 500);
2811
+ if (props.gl) {
2812
+ const gl = props.gl;
2813
+ const device = gl.device;
2814
+ spector == null ? void 0 : spector.startCapture(props.gl, 500);
2815
+ gl.device = device;
2616
2816
  new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
2617
- import_core10.log.info("Spector capture stopped after 2 seconds")();
2817
+ import_core11.log.info("Spector capture stopped after 2 seconds")();
2618
2818
  spector == null ? void 0 : spector.stopCapture();
2619
2819
  });
2620
2820
  }
@@ -2622,8 +2822,8 @@ function initializeSpectorJS(props) {
2622
2822
  }
2623
2823
 
2624
2824
  // dist/context/debug/webgl-developer-tools.js
2625
- var import_core11 = require("@luma.gl/core");
2626
- var import_constants12 = require("@luma.gl/constants");
2825
+ var import_core12 = require("@luma.gl/core");
2826
+ var import_constants14 = require("@luma.gl/constants");
2627
2827
  var import_env = require("@probe.gl/env");
2628
2828
  var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
2629
2829
  function getWebGLContextData(gl) {
@@ -2646,18 +2846,18 @@ function getRealContext(gl) {
2646
2846
  }
2647
2847
  function getDebugContext(gl, props) {
2648
2848
  if (!globalThis.WebGLDebugUtils) {
2649
- import_core11.log.warn("webgl-debug not loaded")();
2849
+ import_core12.log.warn("webgl-debug not loaded")();
2650
2850
  return gl;
2651
2851
  }
2652
2852
  const data = getWebGLContextData(gl);
2653
2853
  if (data.debugContext) {
2654
2854
  return data.debugContext;
2655
2855
  }
2656
- globalThis.WebGLDebugUtils.init({ ...import_constants12.GL, ...gl });
2856
+ globalThis.WebGLDebugUtils.init({ ...import_constants14.GL, ...gl });
2657
2857
  const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(gl, onGLError.bind(null, props), onValidateGLFunc.bind(null, props));
2658
- for (const key in import_constants12.GL) {
2659
- if (!(key in glDebug) && typeof import_constants12.GL[key] === "number") {
2660
- glDebug[key] = import_constants12.GL[key];
2858
+ for (const key in import_constants14.GL) {
2859
+ if (!(key in glDebug) && typeof import_constants14.GL[key] === "number") {
2860
+ glDebug[key] = import_constants14.GL[key];
2661
2861
  }
2662
2862
  }
2663
2863
  class WebGLDebugContext {
@@ -2681,7 +2881,7 @@ function onGLError(props, err, functionName, args) {
2681
2881
  const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
2682
2882
  const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
2683
2883
  const message2 = `${errorMessage} in gl.${functionName}(${functionArgs})`;
2684
- import_core11.log.error(message2)();
2884
+ import_core12.log.error(message2)();
2685
2885
  debugger;
2686
2886
  if (props.throwOnError) {
2687
2887
  throw new Error(message2);
@@ -2689,9 +2889,9 @@ function onGLError(props, err, functionName, args) {
2689
2889
  }
2690
2890
  function onValidateGLFunc(props, functionName, functionArgs) {
2691
2891
  let functionString = "";
2692
- if (import_core11.log.level >= 1) {
2892
+ if (import_core12.log.level >= 1) {
2693
2893
  functionString = getFunctionString(functionName, functionArgs);
2694
- import_core11.log.log(1, functionString)();
2894
+ import_core12.log.log(1, functionString)();
2695
2895
  }
2696
2896
  if (props.break && props.break.length > 0) {
2697
2897
  functionString = functionString || getFunctionString(functionName, functionArgs);
@@ -2706,17 +2906,25 @@ function onValidateGLFunc(props, functionName, functionArgs) {
2706
2906
  if (props.throwOnError) {
2707
2907
  throw new Error(`Undefined argument: ${functionString}`);
2708
2908
  } else {
2709
- import_core11.log.error(`Undefined argument: ${functionString}`)();
2909
+ import_core12.log.error(`Undefined argument: ${functionString}`)();
2710
2910
  debugger;
2711
2911
  }
2712
2912
  }
2713
2913
  }
2714
2914
  }
2715
2915
 
2916
+ // dist/utils/uid.js
2917
+ var uidCounters = {};
2918
+ function uid(id = "id") {
2919
+ uidCounters[id] = uidCounters[id] || 1;
2920
+ const count = uidCounters[id]++;
2921
+ return `${id}-${count}`;
2922
+ }
2923
+
2716
2924
  // dist/adapter/resources/webgl-buffer.js
2717
- var import_core12 = require("@luma.gl/core");
2718
- var import_constants13 = require("@luma.gl/constants");
2719
- var WEBGLBuffer = class extends import_core12.Buffer {
2925
+ var import_core13 = require("@luma.gl/core");
2926
+ var import_constants15 = require("@luma.gl/constants");
2927
+ var WEBGLBuffer = class extends import_core13.Buffer {
2720
2928
  device;
2721
2929
  gl;
2722
2930
  handle;
@@ -2814,33 +3022,33 @@ var WEBGLBuffer = class extends import_core12.Buffer {
2814
3022
  }
2815
3023
  };
2816
3024
  function getWebGLTarget(usage) {
2817
- if (usage & import_core12.Buffer.INDEX) {
3025
+ if (usage & import_core13.Buffer.INDEX) {
2818
3026
  return 34963;
2819
3027
  }
2820
- if (usage & import_core12.Buffer.VERTEX) {
3028
+ if (usage & import_core13.Buffer.VERTEX) {
2821
3029
  return 34962;
2822
3030
  }
2823
- if (usage & import_core12.Buffer.UNIFORM) {
3031
+ if (usage & import_core13.Buffer.UNIFORM) {
2824
3032
  return 35345;
2825
3033
  }
2826
3034
  return 34962;
2827
3035
  }
2828
3036
  function getWebGLUsage(usage) {
2829
- if (usage & import_core12.Buffer.INDEX) {
3037
+ if (usage & import_core13.Buffer.INDEX) {
2830
3038
  return 35044;
2831
3039
  }
2832
- if (usage & import_core12.Buffer.VERTEX) {
3040
+ if (usage & import_core13.Buffer.VERTEX) {
2833
3041
  return 35044;
2834
3042
  }
2835
- if (usage & import_core12.Buffer.UNIFORM) {
3043
+ if (usage & import_core13.Buffer.UNIFORM) {
2836
3044
  return 35048;
2837
3045
  }
2838
3046
  return 35044;
2839
3047
  }
2840
3048
 
2841
3049
  // dist/adapter/resources/webgl-shader.js
2842
- var import_core13 = require("@luma.gl/core");
2843
- var import_constants14 = require("@luma.gl/constants");
3050
+ var import_core14 = require("@luma.gl/core");
3051
+ var import_constants16 = require("@luma.gl/constants");
2844
3052
 
2845
3053
  // dist/adapter/helpers/parse-shader-compiler-log.js
2846
3054
  function parseShaderCompilerLog(errLog) {
@@ -2887,7 +3095,7 @@ function getMessageType(messageType) {
2887
3095
  }
2888
3096
 
2889
3097
  // dist/adapter/resources/webgl-shader.js
2890
- var WEBGLShader = class extends import_core13.Shader {
3098
+ var WEBGLShader = class extends import_core14.Shader {
2891
3099
  device;
2892
3100
  handle;
2893
3101
  constructor(device, props) {
@@ -2917,8 +3125,8 @@ var WEBGLShader = class extends import_core13.Shader {
2917
3125
  return this.getCompilationInfoSync();
2918
3126
  }
2919
3127
  getCompilationInfoSync() {
2920
- const log9 = this.device.gl.getShaderInfoLog(this.handle);
2921
- return log9 ? parseShaderCompilerLog(log9) : [];
3128
+ const log12 = this.device.gl.getShaderInfoLog(this.handle);
3129
+ return log12 ? parseShaderCompilerLog(log12) : [];
2922
3130
  }
2923
3131
  getTranslatedSource() {
2924
3132
  const extensions = this.device.getExtension("WEBGL_debug_shaders");
@@ -2928,13 +3136,13 @@ var WEBGLShader = class extends import_core13.Shader {
2928
3136
  // PRIVATE METHODS
2929
3137
  /** Compile a shader and get compilation status */
2930
3138
  async _compile(source) {
2931
- const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
3139
+ const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 300 es
2932
3140
  ${source2}`;
2933
3141
  source = addGLSLVersion(source);
2934
3142
  const { gl } = this.device;
2935
3143
  gl.shaderSource(this.handle, source);
2936
3144
  gl.compileShader(this.handle);
2937
- if (import_core13.log.level === 0) {
3145
+ if (import_core14.log.level === 0) {
2938
3146
  this.compilationStatus = "pending";
2939
3147
  return;
2940
3148
  }
@@ -2946,9 +3154,9 @@ ${source2}`;
2946
3154
  }
2947
3155
  return;
2948
3156
  }
2949
- import_core13.log.once(1, "Shader compilation is asynchronous")();
3157
+ import_core14.log.once(1, "Shader compilation is asynchronous")();
2950
3158
  await this._waitForCompilationComplete();
2951
- import_core13.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
3159
+ import_core14.log.info(2, `Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)();
2952
3160
  this._getCompilationStatus();
2953
3161
  this.debugShader();
2954
3162
  }
@@ -2980,26 +3188,37 @@ ${source2}`;
2980
3188
  };
2981
3189
 
2982
3190
  // dist/adapter/resources/webgl-render-pass.js
2983
- var import_core14 = require("@luma.gl/core");
2984
- var import_constants15 = require("@luma.gl/constants");
3191
+ var import_core15 = require("@luma.gl/core");
3192
+ var import_constants17 = require("@luma.gl/constants");
2985
3193
  var GL_DEPTH_BUFFER_BIT = 256;
2986
3194
  var GL_STENCIL_BUFFER_BIT = 1024;
2987
3195
  var GL_COLOR_BUFFER_BIT = 16384;
2988
3196
  var GL_COLOR = 6144;
2989
3197
  var COLOR_CHANNELS = [1, 2, 4, 8];
2990
- var WEBGLRenderPass = class extends import_core14.RenderPass {
3198
+ var WEBGLRenderPass = class extends import_core15.RenderPass {
2991
3199
  device;
2992
3200
  /** Parameters that should be applied before each draw call */
2993
3201
  glParameters;
2994
3202
  constructor(device, props) {
3203
+ var _a;
2995
3204
  super(device, props);
2996
3205
  this.device = device;
2997
- pushContextState(this.device.gl);
2998
- this.setParameters(this.props.parameters);
3206
+ let viewport;
3207
+ if (!((_a = props == null ? void 0 : props.parameters) == null ? void 0 : _a.viewport)) {
3208
+ if (props == null ? void 0 : props.framebuffer) {
3209
+ const { width, height } = props.framebuffer;
3210
+ viewport = [0, 0, width, height];
3211
+ } else {
3212
+ const [width, height] = device.getCanvasContext().getDrawingBufferSize();
3213
+ viewport = [0, 0, width, height];
3214
+ }
3215
+ }
3216
+ this.device.pushState();
3217
+ this.setParameters({ viewport, ...this.props.parameters });
2999
3218
  this.clear();
3000
3219
  }
3001
3220
  end() {
3002
- popContextState(this.device.gl);
3221
+ this.device.popState();
3003
3222
  }
3004
3223
  pushDebugGroup(groupLabel) {
3005
3224
  }
@@ -3101,184 +3320,12 @@ var WEBGLRenderPass = class extends import_core14.RenderPass {
3101
3320
  };
3102
3321
 
3103
3322
  // dist/adapter/resources/webgl-render-pipeline.js
3104
- var import_core15 = require("@luma.gl/core");
3323
+ var import_core16 = require("@luma.gl/core");
3105
3324
  var import_constants22 = require("@luma.gl/constants");
3106
3325
 
3107
3326
  // dist/adapter/helpers/get-shader-layout.js
3108
3327
  var import_constants19 = require("@luma.gl/constants");
3109
3328
 
3110
- // dist/classic/accessor.js
3111
- var import_constants17 = require("@luma.gl/constants");
3112
-
3113
- // dist/classic/typed-array-utils.js
3114
- var import_constants16 = require("@luma.gl/constants");
3115
- var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
3116
- function getGLTypeFromTypedArray(arrayOrType) {
3117
- const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
3118
- switch (type) {
3119
- case Float32Array:
3120
- return 5126;
3121
- case Uint16Array:
3122
- return 5123;
3123
- case Uint32Array:
3124
- return 5125;
3125
- case Uint8Array:
3126
- return 5121;
3127
- case Uint8ClampedArray:
3128
- return 5121;
3129
- case Int8Array:
3130
- return 5120;
3131
- case Int16Array:
3132
- return 5122;
3133
- case Int32Array:
3134
- return 5124;
3135
- default:
3136
- throw new Error(ERR_TYPE_DEDUCTION);
3137
- }
3138
- }
3139
- function getTypedArrayFromGLType(glType, options) {
3140
- const { clamped = true } = options || {};
3141
- switch (glType) {
3142
- case 5126:
3143
- return Float32Array;
3144
- case 5123:
3145
- case 33635:
3146
- case 32819:
3147
- case 32820:
3148
- return Uint16Array;
3149
- case 5125:
3150
- return Uint32Array;
3151
- case 5121:
3152
- return clamped ? Uint8ClampedArray : Uint8Array;
3153
- case 5120:
3154
- return Int8Array;
3155
- case 5122:
3156
- return Int16Array;
3157
- case 5124:
3158
- return Int32Array;
3159
- default:
3160
- throw new Error("Failed to deduce typed array type from GL constant");
3161
- }
3162
- }
3163
-
3164
- // dist/classic/accessor.js
3165
- var DEFAULT_ACCESSOR_VALUES = {
3166
- offset: 0,
3167
- stride: 0,
3168
- type: 5126,
3169
- size: 1,
3170
- divisor: 0,
3171
- normalized: false,
3172
- integer: false
3173
- };
3174
- var Accessor = class {
3175
- offset;
3176
- stride;
3177
- type;
3178
- size;
3179
- divisor;
3180
- normalized;
3181
- integer;
3182
- buffer;
3183
- index;
3184
- static getBytesPerElement(accessor) {
3185
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
3186
- return ArrayType.BYTES_PER_ELEMENT;
3187
- }
3188
- static getBytesPerVertex(accessor) {
3189
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
3190
- return ArrayType.BYTES_PER_ELEMENT * accessor.size;
3191
- }
3192
- // Combines (merges) a list of accessors. On top of default values
3193
- // Usually [programAccessor, bufferAccessor, appAccessor]
3194
- // All props will be set in the returned object.
3195
- // TODO check for conflicts between values in the supplied accessors
3196
- static resolve(...accessors) {
3197
- return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
3198
- }
3199
- constructor(...accessors) {
3200
- accessors.forEach((accessor) => this._assign(accessor));
3201
- Object.freeze(this);
3202
- }
3203
- toString() {
3204
- return JSON.stringify(this);
3205
- }
3206
- // ACCESSORS
3207
- // TODO - remove>
3208
- get BYTES_PER_ELEMENT() {
3209
- return Accessor.getBytesPerElement(this);
3210
- }
3211
- get BYTES_PER_VERTEX() {
3212
- return Accessor.getBytesPerVertex(this);
3213
- }
3214
- // PRIVATE
3215
- // eslint-disable-next-line complexity, max-statements
3216
- _assign(props = {}) {
3217
- if (props.type !== void 0) {
3218
- this.type = props.type;
3219
- if (props.type === 5124 || props.type === 5125) {
3220
- this.integer = true;
3221
- }
3222
- }
3223
- if (props.size !== void 0) {
3224
- this.size = props.size;
3225
- }
3226
- if (props.offset !== void 0) {
3227
- this.offset = props.offset;
3228
- }
3229
- if (props.stride !== void 0) {
3230
- this.stride = props.stride;
3231
- }
3232
- if (props.normalize !== void 0) {
3233
- this.normalized = props.normalize;
3234
- }
3235
- if (props.normalized !== void 0) {
3236
- this.normalized = props.normalized;
3237
- }
3238
- if (props.integer !== void 0) {
3239
- this.integer = props.integer;
3240
- }
3241
- if (props.divisor !== void 0) {
3242
- this.divisor = props.divisor;
3243
- }
3244
- if (props.buffer !== void 0) {
3245
- this.buffer = props.buffer;
3246
- }
3247
- if (props.index !== void 0) {
3248
- if (typeof props.index === "boolean") {
3249
- this.index = props.index ? 1 : 0;
3250
- } else {
3251
- this.index = props.index;
3252
- }
3253
- }
3254
- if (props.instanced !== void 0) {
3255
- this.divisor = props.instanced ? 1 : 0;
3256
- }
3257
- if (props.isInstanced !== void 0) {
3258
- this.divisor = props.isInstanced ? 1 : 0;
3259
- }
3260
- if (this.offset === void 0)
3261
- delete this.offset;
3262
- if (this.stride === void 0)
3263
- delete this.stride;
3264
- if (this.type === void 0)
3265
- delete this.type;
3266
- if (this.size === void 0)
3267
- delete this.size;
3268
- if (this.divisor === void 0)
3269
- delete this.divisor;
3270
- if (this.normalized === void 0)
3271
- delete this.normalized;
3272
- if (this.integer === void 0)
3273
- delete this.integer;
3274
- if (this.buffer === void 0)
3275
- delete this.buffer;
3276
- if (this.index === void 0)
3277
- delete this.index;
3278
- return this;
3279
- }
3280
- };
3281
-
3282
3329
  // dist/adapter/helpers/decode-webgl-types.js
3283
3330
  var import_constants18 = require("@luma.gl/constants");
3284
3331
  function isSamplerUniform(type) {
@@ -3445,8 +3492,7 @@ function readVaryings(gl, program) {
3445
3492
  }
3446
3493
  const { name, type: compositeType, size } = activeInfo;
3447
3494
  const { glType, components } = decodeGLUniformType(compositeType);
3448
- const accessor = new Accessor({ type: glType, size: size * components });
3449
- const varying = { location, name, accessor };
3495
+ const varying = { location, name, type: glType, size: size * components };
3450
3496
  varyings.push(varying);
3451
3497
  }
3452
3498
  varyings.sort((a, b) => a.location - b.location);
@@ -3713,7 +3759,7 @@ function getGLPrimitive(topology) {
3713
3759
 
3714
3760
  // dist/adapter/resources/webgl-render-pipeline.js
3715
3761
  var LOG_PROGRAM_PERF_PRIORITY = 4;
3716
- var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3762
+ var WEBGLRenderPipeline = class extends import_core16.RenderPipeline {
3717
3763
  /** The WebGL device that created this render pipeline */
3718
3764
  device;
3719
3765
  /** Handle to underlying WebGL program */
@@ -3746,9 +3792,9 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3746
3792
  this.device.gl.transformFeedbackVaryings(this.handle, varyings, bufferMode);
3747
3793
  }
3748
3794
  this._linkShaders();
3749
- import_core15.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3795
+ import_core16.log.time(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3750
3796
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
3751
- import_core15.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3797
+ import_core16.log.timeEnd(1, `RenderPipeline ${this.id} - shaderLayout introspection`)();
3752
3798
  this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
3753
3799
  }
3754
3800
  destroy() {
@@ -3767,12 +3813,12 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3767
3813
  if (!binding) {
3768
3814
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
3769
3815
  if (!(options == null ? void 0 : options.disableWarnings)) {
3770
- import_core15.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3816
+ import_core16.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
3771
3817
  }
3772
3818
  continue;
3773
3819
  }
3774
3820
  if (!value) {
3775
- import_core15.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
3821
+ import_core16.log.warn(`Unsetting binding "${name}" in render pipeline "${this.id}"`)();
3776
3822
  }
3777
3823
  switch (binding.type) {
3778
3824
  case "uniform":
@@ -3786,7 +3832,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3786
3832
  }
3787
3833
  break;
3788
3834
  case "sampler":
3789
- import_core15.log.warn(`Ignoring sampler ${name}`)();
3835
+ import_core16.log.warn(`Ignoring sampler ${name}`)();
3790
3836
  break;
3791
3837
  default:
3792
3838
  throw new Error(binding.type);
@@ -3819,11 +3865,11 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3819
3865
  const isIndexed = Boolean(vertexArray.indexBuffer);
3820
3866
  const glIndexType = (_a = vertexArray.indexBuffer) == null ? void 0 : _a.glIndexType;
3821
3867
  if (this.linkStatus !== "success") {
3822
- import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
3868
+ import_core16.log.info(2, `RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)();
3823
3869
  return false;
3824
3870
  }
3825
3871
  if (!this._areTexturesRenderable()) {
3826
- import_core15.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
3872
+ import_core16.log.info(2, `RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)();
3827
3873
  return false;
3828
3874
  }
3829
3875
  this.device.gl.useProgram(this.handle);
@@ -3862,7 +3908,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3862
3908
  setUniformsWebGL(uniforms) {
3863
3909
  const { bindings } = splitUniformsAndBindings(uniforms);
3864
3910
  Object.keys(bindings).forEach((name) => {
3865
- import_core15.log.warn(`Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
3911
+ import_core16.log.warn(`Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
3866
3912
  });
3867
3913
  Object.assign(this.uniforms, uniforms);
3868
3914
  }
@@ -3873,19 +3919,19 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3873
3919
  const { gl } = this.device;
3874
3920
  gl.attachShader(this.handle, this.vs.handle);
3875
3921
  gl.attachShader(this.handle, this.fs.handle);
3876
- import_core15.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3922
+ import_core16.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3877
3923
  gl.linkProgram(this.handle);
3878
- import_core15.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3879
- if (import_core15.log.level === 0) {
3924
+ import_core16.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
3925
+ if (import_core16.log.level === 0) {
3880
3926
  }
3881
3927
  if (!this.device.features.has("compilation-status-async-webgl")) {
3882
3928
  const status2 = this._getLinkStatus();
3883
3929
  this._reportLinkStatus(status2);
3884
3930
  return;
3885
3931
  }
3886
- import_core15.log.once(1, "RenderPipeline linking is asynchronous")();
3932
+ import_core16.log.once(1, "RenderPipeline linking is asynchronous")();
3887
3933
  await this._waitForLinkComplete();
3888
- import_core15.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
3934
+ import_core16.log.info(2, `RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();
3889
3935
  const status = this._getLinkStatus();
3890
3936
  this._reportLinkStatus(status);
3891
3937
  }
@@ -3954,7 +4000,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3954
4000
  let texturesRenderable = true;
3955
4001
  for (const bindingInfo of this.shaderLayout.bindings) {
3956
4002
  if (!this.bindings[bindingInfo.name] && !this.bindings[bindingInfo.name.replace(/Uniforms$/, "")]) {
3957
- import_core15.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
4003
+ import_core16.log.warn(`Binding ${bindingInfo.name} not found in ${this.id}`)();
3958
4004
  texturesRenderable = false;
3959
4005
  }
3960
4006
  }
@@ -4013,7 +4059,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
4013
4059
  } else if (value instanceof WEBGLTexture) {
4014
4060
  texture = value;
4015
4061
  } else if (value instanceof WEBGLFramebuffer && value.colorAttachments[0] instanceof WEBGLTextureView) {
4016
- import_core15.log.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")();
4062
+ import_core16.log.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")();
4017
4063
  texture = value.colorAttachments[0].texture;
4018
4064
  } else {
4019
4065
  throw new Error("No texture");
@@ -4052,7 +4098,7 @@ function mergeShaderLayout(baseLayout, overrideLayout) {
4052
4098
  for (const attribute of (overrideLayout == null ? void 0 : overrideLayout.attributes) || []) {
4053
4099
  const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
4054
4100
  if (!baseAttribute) {
4055
- import_core15.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
4101
+ import_core16.log.warn(`shader layout attribute ${attribute.name} not present in shader`);
4056
4102
  } else {
4057
4103
  baseAttribute.type = attribute.type || baseAttribute.type;
4058
4104
  baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
@@ -4062,12 +4108,12 @@ function mergeShaderLayout(baseLayout, overrideLayout) {
4062
4108
  }
4063
4109
 
4064
4110
  // dist/adapter/resources/webgl-command-encoder.js
4065
- var import_core17 = require("@luma.gl/core");
4111
+ var import_core18 = require("@luma.gl/core");
4066
4112
 
4067
4113
  // dist/adapter/resources/webgl-command-buffer.js
4068
- var import_core16 = require("@luma.gl/core");
4114
+ var import_core17 = require("@luma.gl/core");
4069
4115
  var import_constants23 = require("@luma.gl/constants");
4070
- var WEBGLCommandBuffer = class extends import_core16.CommandBuffer {
4116
+ var WEBGLCommandBuffer = class extends import_core17.CommandBuffer {
4071
4117
  device;
4072
4118
  commands = [];
4073
4119
  constructor(device) {
@@ -4142,7 +4188,7 @@ function _copyTextureToBuffer(device, options) {
4142
4188
  if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
4143
4189
  throw new Error("not implemented");
4144
4190
  }
4145
- const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
4191
+ const { framebuffer, destroyFramebuffer } = getFramebuffer2(source);
4146
4192
  let prevHandle;
4147
4193
  try {
4148
4194
  const webglBuffer = destination;
@@ -4190,7 +4236,7 @@ function _copyTextureToTexture(device, options) {
4190
4236
  height = options.destination.height
4191
4237
  // depthOrArrayLayers = 0
4192
4238
  } = options;
4193
- const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
4239
+ const { framebuffer, destroyFramebuffer } = getFramebuffer2(source);
4194
4240
  const [sourceX, sourceY] = origin;
4195
4241
  const [destinationX, destinationY, destinationZ] = destinationOrigin;
4196
4242
  const prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
@@ -4224,8 +4270,8 @@ function _copyTextureToTexture(device, options) {
4224
4270
  framebuffer.destroy();
4225
4271
  }
4226
4272
  }
4227
- function getFramebuffer(source) {
4228
- if (source instanceof import_core16.Texture) {
4273
+ function getFramebuffer2(source) {
4274
+ if (source instanceof import_core17.Texture) {
4229
4275
  const { width, height, id } = source;
4230
4276
  const framebuffer = source.device.createFramebuffer({
4231
4277
  id: `framebuffer-for-${id}`,
@@ -4239,7 +4285,7 @@ function getFramebuffer(source) {
4239
4285
  }
4240
4286
 
4241
4287
  // dist/adapter/resources/webgl-command-encoder.js
4242
- var WEBGLCommandEncoder = class extends import_core17.CommandEncoder {
4288
+ var WEBGLCommandEncoder = class extends import_core18.CommandEncoder {
4243
4289
  device;
4244
4290
  commandBuffer;
4245
4291
  constructor(device, props) {
@@ -4278,7 +4324,7 @@ var WEBGLCommandEncoder = class extends import_core17.CommandEncoder {
4278
4324
  };
4279
4325
 
4280
4326
  // dist/adapter/resources/webgl-vertex-array.js
4281
- var import_core18 = require("@luma.gl/core");
4327
+ var import_core19 = require("@luma.gl/core");
4282
4328
  var import_constants24 = require("@luma.gl/constants");
4283
4329
  var import_env2 = require("@probe.gl/env");
4284
4330
 
@@ -4304,7 +4350,7 @@ function fillArray(options) {
4304
4350
  }
4305
4351
 
4306
4352
  // dist/adapter/resources/webgl-vertex-array.js
4307
- var WEBGLVertexArray = class extends import_core18.VertexArray {
4353
+ var WEBGLVertexArray = class extends import_core19.VertexArray {
4308
4354
  get [Symbol.toStringTag]() {
4309
4355
  return "VertexArray";
4310
4356
  }
@@ -4364,6 +4410,7 @@ var WEBGLVertexArray = class extends import_core18.VertexArray {
4364
4410
  } else {
4365
4411
  this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
4366
4412
  }
4413
+ this.device.gl.bindBuffer(34962, null);
4367
4414
  this.device.gl.enableVertexAttribArray(location);
4368
4415
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
4369
4416
  this.attributes[location] = buffer;
@@ -4470,7 +4517,7 @@ var WEBGLVertexArray = class extends import_core18.VertexArray {
4470
4517
  this.buffer = this.buffer || this.device.createBuffer({ byteLength });
4471
4518
  updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
4472
4519
  if (updateNeeded) {
4473
- const typedArray = (0, import_core18.getScratchArray)(value.constructor, length);
4520
+ const typedArray = (0, import_core19.getScratchArray)(value.constructor, length);
4474
4521
  fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
4475
4522
  this.buffer.write(typedArray);
4476
4523
  this.bufferValue = value;
@@ -4497,9 +4544,9 @@ function compareConstantArrayValues(v1, v2) {
4497
4544
  }
4498
4545
 
4499
4546
  // dist/adapter/resources/webgl-transform-feedback.js
4500
- var import_core19 = require("@luma.gl/core");
4547
+ var import_core20 = require("@luma.gl/core");
4501
4548
  var import_constants25 = require("@luma.gl/constants");
4502
- var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
4549
+ var WEBGLTransformFeedback = class extends import_core20.TransformFeedback {
4503
4550
  device;
4504
4551
  gl;
4505
4552
  handle;
@@ -4542,7 +4589,7 @@ var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
4542
4589
  }
4543
4590
  end() {
4544
4591
  this.gl.endTransformFeedback();
4545
- if (!this.bindOnUse) {
4592
+ if (this.bindOnUse) {
4546
4593
  this._unbindBuffers();
4547
4594
  }
4548
4595
  this.gl.bindTransformFeedback(36386, null);
@@ -4562,7 +4609,7 @@ var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
4562
4609
  const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferOrRange);
4563
4610
  if (location < 0) {
4564
4611
  this.unusedBuffers[locationOrName] = buffer;
4565
- import_core19.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
4612
+ import_core20.log.warn(`${this.id} unusedBuffers varying buffer ${locationOrName}`)();
4566
4613
  return;
4567
4614
  }
4568
4615
  this.buffers[location] = { buffer, byteLength, byteOffset };
@@ -4649,9 +4696,9 @@ function isIndex(value) {
4649
4696
  }
4650
4697
 
4651
4698
  // dist/adapter/resources/webgl-query-set.js
4652
- var import_core20 = require("@luma.gl/core");
4699
+ var import_core21 = require("@luma.gl/core");
4653
4700
  var import_constants26 = require("@luma.gl/constants");
4654
- var WEBGLQuerySet = class extends import_core20.QuerySet {
4701
+ var WEBGLQuerySet = class extends import_core21.QuerySet {
4655
4702
  device;
4656
4703
  handle;
4657
4704
  target = null;
@@ -4778,152 +4825,24 @@ var WEBGLQuerySet = class extends import_core20.QuerySet {
4778
4825
  }
4779
4826
  };
4780
4827
 
4781
- // dist/classic/copy-and-blit.js
4782
- var import_core21 = require("@luma.gl/core");
4783
- var import_constants28 = require("@luma.gl/constants");
4784
-
4785
- // dist/classic/format-utils.js
4786
- var import_constants27 = require("@luma.gl/constants");
4787
- function glFormatToComponents(format) {
4788
- switch (format) {
4789
- case 6406:
4790
- case 33326:
4791
- case 6403:
4792
- return 1;
4793
- case 33328:
4794
- case 33319:
4795
- return 2;
4796
- case 6407:
4797
- case 34837:
4798
- return 3;
4799
- case 6408:
4800
- case 34836:
4801
- return 4;
4802
- default:
4803
- return 0;
4828
+ // dist/deprecated/clear.js
4829
+ var import_core22 = require("@luma.gl/core");
4830
+ var GL_DEPTH_BUFFER_BIT2 = 256;
4831
+ var GL_STENCIL_BUFFER_BIT2 = 1024;
4832
+ var GL_COLOR_BUFFER_BIT2 = 16384;
4833
+ function clear(device, options) {
4834
+ import_core22.log.warn("clear will be removed in next minor release");
4835
+ const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
4836
+ const parameters = {};
4837
+ if (framebuffer) {
4838
+ parameters.framebuffer = framebuffer;
4804
4839
  }
4805
- }
4806
- function glTypeToBytes(type) {
4807
- switch (type) {
4808
- case 5121:
4809
- return 1;
4810
- case 33635:
4811
- case 32819:
4812
- case 32820:
4813
- return 2;
4814
- case 5126:
4815
- return 4;
4816
- default:
4817
- return 0;
4818
- }
4819
- }
4820
-
4821
- // dist/classic/copy-and-blit.js
4822
- function readPixelsToArray(source, options) {
4823
- var _a, _b;
4824
- const {
4825
- sourceX = 0,
4826
- sourceY = 0,
4827
- sourceFormat = 6408,
4828
- sourceAttachment = 36064
4829
- // TODO - support gl.readBuffer
4830
- } = options || {};
4831
- let {
4832
- target = null,
4833
- // following parameters are auto deduced if not provided
4834
- sourceWidth,
4835
- sourceHeight,
4836
- sourceType
4837
- } = options || {};
4838
- const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
4839
- const { gl, handle } = framebuffer;
4840
- sourceWidth = sourceWidth || framebuffer.width;
4841
- sourceHeight = sourceHeight || framebuffer.height;
4842
- const attachment = sourceAttachment - 36064;
4843
- sourceType = sourceType || ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.glType) || 5121;
4844
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
4845
- sourceType = sourceType || getGLTypeFromTypedArray(target);
4846
- const prevHandle = gl.bindFramebuffer(36160, handle);
4847
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
4848
- gl.bindFramebuffer(36160, prevHandle || null);
4849
- if (deleteFramebuffer) {
4850
- framebuffer.destroy();
4851
- }
4852
- return target;
4853
- }
4854
- function readPixelsToBuffer(source, options) {
4855
- const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
4856
- let { sourceWidth, sourceHeight, sourceType } = options || {};
4857
- const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
4858
- sourceWidth = sourceWidth || framebuffer.width;
4859
- sourceHeight = sourceHeight || framebuffer.height;
4860
- const webglFramebuffer = framebuffer;
4861
- sourceType = sourceType || 5121;
4862
- let webglBufferTarget = target;
4863
- if (!webglBufferTarget) {
4864
- const components = glFormatToComponents(sourceFormat);
4865
- const byteCount = glTypeToBytes(sourceType);
4866
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
4867
- webglBufferTarget = webglFramebuffer.device.createBuffer({ byteLength });
4868
- }
4869
- const commandEncoder = source.device.createCommandEncoder();
4870
- commandEncoder.copyTextureToBuffer({
4871
- source,
4872
- width: sourceWidth,
4873
- height: sourceHeight,
4874
- origin: [sourceX, sourceY],
4875
- destination: webglBufferTarget,
4876
- byteOffset: targetByteOffset
4877
- });
4878
- commandEncoder.destroy();
4879
- if (deleteFramebuffer) {
4880
- framebuffer.destroy();
4881
- }
4882
- return webglBufferTarget;
4883
- }
4884
- function getFramebuffer2(source) {
4885
- if (!(source instanceof import_core21.Framebuffer)) {
4886
- return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
4887
- }
4888
- return { framebuffer: source, deleteFramebuffer: false };
4889
- }
4890
- function toFramebuffer(texture, props) {
4891
- const { device, width, height, id } = texture;
4892
- const framebuffer = device.createFramebuffer({
4893
- ...props,
4894
- id: `framebuffer-for-${id}`,
4895
- width,
4896
- height,
4897
- colorAttachments: [texture]
4898
- });
4899
- return framebuffer;
4900
- }
4901
- function getPixelArray(pixelArray, type, format, width, height) {
4902
- if (pixelArray) {
4903
- return pixelArray;
4904
- }
4905
- type = type || 5121;
4906
- const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
4907
- const components = glFormatToComponents(format);
4908
- return new ArrayType(width * height * components);
4909
- }
4910
-
4911
- // dist/classic/clear.js
4912
- var GL_DEPTH_BUFFER_BIT2 = 256;
4913
- var GL_STENCIL_BUFFER_BIT2 = 1024;
4914
- var GL_COLOR_BUFFER_BIT2 = 16384;
4915
- function clear(device, options) {
4916
- const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
4917
- const parameters = {};
4918
- if (framebuffer) {
4919
- parameters.framebuffer = framebuffer;
4920
- }
4921
- let clearFlags = 0;
4922
- if (color) {
4923
- clearFlags |= GL_COLOR_BUFFER_BIT2;
4924
- if (color !== true) {
4925
- parameters.clearColor = color;
4926
- }
4840
+ let clearFlags = 0;
4841
+ if (color) {
4842
+ clearFlags |= GL_COLOR_BUFFER_BIT2;
4843
+ if (color !== true) {
4844
+ parameters.clearColor = color;
4845
+ }
4927
4846
  }
4928
4847
  if (depth) {
4929
4848
  clearFlags |= GL_DEPTH_BUFFER_BIT2;
@@ -4944,8 +4863,10 @@ function clear(device, options) {
4944
4863
  }
4945
4864
 
4946
4865
  // dist/adapter/webgl-device.js
4947
- var LOG_LEVEL2 = 1;
4948
- var _WebGLDevice = class extends import_core22.Device {
4866
+ var WebGLDevice = class extends import_core23.Device {
4867
+ //
4868
+ // Public `Device` API
4869
+ //
4949
4870
  /** type of this device */
4950
4871
  type = "webgl";
4951
4872
  /** The underlying WebGL context */
@@ -4956,68 +4877,22 @@ var _WebGLDevice = class extends import_core22.Device {
4956
4877
  canvasContext;
4957
4878
  lost;
4958
4879
  _resolveContextLost;
4959
- //
4960
- // Static methods, expected to be present by `luma.createDevice()`
4961
- //
4962
- /** Check if WebGL 2 is available */
4963
- static isSupported() {
4964
- return typeof WebGL2RenderingContext !== "undefined";
4965
- }
4966
- /**
4967
- * Get a device instance from a GL context
4968
- * Creates and instruments the device if not already created
4969
- * @param gl
4970
- * @returns
4971
- */
4972
- static attach(gl) {
4973
- if (gl instanceof _WebGLDevice) {
4974
- return gl;
4975
- }
4976
- if ((gl == null ? void 0 : gl.device) instanceof import_core22.Device) {
4977
- return gl.device;
4978
- }
4979
- if (!isWebGL(gl)) {
4980
- throw new Error("Invalid WebGL2RenderingContext");
4981
- }
4982
- return new _WebGLDevice({ gl });
4983
- }
4984
- static async create(props = {}) {
4985
- var _a;
4986
- import_core22.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
4987
- const promises = [];
4988
- if (props.debug) {
4989
- promises.push(loadWebGLDeveloperTools());
4990
- }
4991
- if (props.spector) {
4992
- promises.push(loadSpectorJS());
4993
- }
4994
- if (typeof props.canvas === "string") {
4995
- promises.push(import_core22.CanvasContext.pageLoaded);
4996
- }
4997
- const results = await Promise.allSettled(promises);
4998
- for (const result of results) {
4999
- if (result.status === "rejected") {
5000
- import_core22.log.error(`Failed to initialize debug libraries ${result.reason}`)();
5001
- }
5002
- }
5003
- import_core22.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5004
- if ((_a = props.gl) == null ? void 0 : _a.device) {
5005
- import_core22.log.warn("reattaching existing device")();
5006
- return _WebGLDevice.attach(props.gl);
5007
- }
5008
- const device = new _WebGLDevice(props);
5009
- const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5010
- import_core22.log.probe(LOG_LEVEL2, message2)();
5011
- import_core22.log.table(LOG_LEVEL2, device.info)();
5012
- import_core22.log.groupEnd(LOG_LEVEL2)();
5013
- return device;
5014
- }
4880
+ /** WebGL2 context. */
4881
+ gl;
4882
+ debug = false;
4883
+ /** State used by luma.gl classes: TODO - move to canvasContext*/
4884
+ _canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
4885
+ /** State used by luma.gl classes - TODO - not used? */
4886
+ _extensions = {};
4887
+ _polyfilled = false;
4888
+ /** Instance of Spector.js (if initialized) */
4889
+ spectorJS;
5015
4890
  //
5016
4891
  // Public API
5017
4892
  //
5018
4893
  constructor(props) {
5019
4894
  var _a, _b;
5020
- super({ ...props, id: props.id || "webgl-device" });
4895
+ super({ ...props, id: props.id || uid("webgl-device") });
5021
4896
  const device = (_a = props.gl) == null ? void 0 : _a.device;
5022
4897
  if (device) {
5023
4898
  throw new Error(`WebGL context already attached to device ${device.id}`);
@@ -5027,8 +4902,7 @@ var _WebGLDevice = class extends import_core22.Device {
5027
4902
  this.lost = new Promise((resolve) => {
5028
4903
  this._resolveContextLost = resolve;
5029
4904
  });
5030
- let gl = props.gl || null;
5031
- gl ||= createBrowserContext(this.canvasContext.canvas, {
4905
+ this.handle = createBrowserContext(this.canvasContext.canvas, {
5032
4906
  ...props,
5033
4907
  onContextLost: (event) => {
5034
4908
  var _a2;
@@ -5038,11 +4912,11 @@ var _WebGLDevice = class extends import_core22.Device {
5038
4912
  });
5039
4913
  }
5040
4914
  });
5041
- if (!gl) {
4915
+ this.gl = this.handle;
4916
+ if (!this.handle) {
5042
4917
  throw new Error("WebGL context creation failed");
5043
4918
  }
5044
- this.handle = gl;
5045
- this.gl = gl;
4919
+ this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
5046
4920
  this.gl.device = this;
5047
4921
  this.gl._version = 2;
5048
4922
  this.info = getDeviceInfo(this.gl, this._extensions);
@@ -5052,20 +4926,15 @@ var _WebGLDevice = class extends import_core22.Device {
5052
4926
  this.features.initializeFeatures();
5053
4927
  }
5054
4928
  this.canvasContext.resize();
5055
- const { enable: enable2 = true, copyState = false } = props;
5056
- trackContextState(this.gl, {
5057
- enable: enable2,
5058
- copyState,
5059
- log: (...args) => import_core22.log.log(1, ...args)()
4929
+ const glState = new WebGLStateTracker(this.gl, {
4930
+ log: (...args) => import_core23.log.log(1, ...args)()
5060
4931
  });
4932
+ glState.trackState(this.gl, { copyState: false });
5061
4933
  if (props.debug) {
5062
4934
  this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
5063
4935
  this.debug = true;
5064
- import_core22.log.level = Math.max(import_core22.log.level, 1);
5065
- import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
5066
- }
5067
- if (props.spector) {
5068
- this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
4936
+ import_core23.log.level = Math.max(import_core23.log.level, 1);
4937
+ import_core23.log.warn("WebGL debug mode activated. Performance reduced.")();
5069
4938
  }
5070
4939
  }
5071
4940
  /**
@@ -5077,9 +4946,6 @@ var _WebGLDevice = class extends import_core22.Device {
5077
4946
  get isLost() {
5078
4947
  return this.gl.isContextLost();
5079
4948
  }
5080
- getSize() {
5081
- return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
5082
- }
5083
4949
  isTextureFormatSupported(format) {
5084
4950
  return isTextureFormatSupported(this.gl, format, this._extensions);
5085
4951
  }
@@ -5172,22 +5038,12 @@ var _WebGLDevice = class extends import_core22.Device {
5172
5038
  clear(this, options);
5173
5039
  }
5174
5040
  resetWebGL() {
5175
- import_core22.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
5041
+ import_core23.log.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")();
5176
5042
  resetGLParameters(this.gl);
5177
5043
  }
5178
5044
  //
5179
5045
  // WebGL-only API (not part of `Device` API)
5180
5046
  //
5181
- /** WebGL2 context. */
5182
- gl;
5183
- debug = false;
5184
- /** State used by luma.gl classes: TODO - move to canvasContext*/
5185
- _canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
5186
- /** State used by luma.gl classes - TODO - not used? */
5187
- _extensions = {};
5188
- _polyfilled = false;
5189
- /** Instance of Spector.js (if initialized) */
5190
- spectorJS;
5191
5047
  /**
5192
5048
  * Triggers device (or WebGL context) loss.
5193
5049
  * @note primarily intended for testing how application reacts to device loss
@@ -5209,11 +5065,13 @@ var _WebGLDevice = class extends import_core22.Device {
5209
5065
  }
5210
5066
  /** Save current WebGL context state onto an internal stack */
5211
5067
  pushState() {
5212
- pushContextState(this.gl);
5068
+ const webglState = WebGLStateTracker.get(this.gl);
5069
+ webglState.push();
5213
5070
  }
5214
5071
  /** Restores previously saved context state */
5215
5072
  popState() {
5216
- popContextState(this.gl);
5073
+ const webglState = WebGLStateTracker.get(this.gl);
5074
+ webglState.pop();
5217
5075
  }
5218
5076
  /**
5219
5077
  * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
@@ -5250,7 +5108,7 @@ var _WebGLDevice = class extends import_core22.Device {
5250
5108
  this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
5251
5109
  const currentConstant = this._constants[location];
5252
5110
  if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
5253
- import_core22.log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
5111
+ import_core23.log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
5254
5112
  }
5255
5113
  this._constants[location] = constant;
5256
5114
  switch (constant.constructor) {
@@ -5273,18 +5131,6 @@ var _WebGLDevice = class extends import_core22.Device {
5273
5131
  return this._extensions;
5274
5132
  }
5275
5133
  };
5276
- var WebGLDevice = _WebGLDevice;
5277
- //
5278
- // Public `Device` API
5279
- //
5280
- /** type of this device */
5281
- __publicField(WebGLDevice, "type", "webgl");
5282
- function isWebGL(gl) {
5283
- if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
5284
- return true;
5285
- }
5286
- return Boolean(gl && Number.isFinite(gl._version));
5287
- }
5288
5134
  function setConstantFloatArray(device, location, array) {
5289
5135
  switch (array.length) {
5290
5136
  case 1:
@@ -5319,4 +5165,325 @@ function compareConstantArrayValues2(v1, v2) {
5319
5165
  }
5320
5166
  return true;
5321
5167
  }
5168
+
5169
+ // dist/context/polyfills/polyfill-webgl1-extensions.js
5170
+ var import_constants27 = require("@luma.gl/constants");
5171
+ var WEBGL1_STATIC_EXTENSIONS = {
5172
+ WEBGL_depth_texture: {
5173
+ UNSIGNED_INT_24_8_WEBGL: 34042
5174
+ },
5175
+ OES_element_index_uint: {},
5176
+ OES_texture_float: {},
5177
+ OES_texture_half_float: {
5178
+ // @ts-expect-error different numbers?
5179
+ HALF_FLOAT_OES: 5131
5180
+ },
5181
+ EXT_color_buffer_float: {},
5182
+ OES_standard_derivatives: {
5183
+ FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723
5184
+ },
5185
+ EXT_frag_depth: {},
5186
+ EXT_blend_minmax: {
5187
+ MIN_EXT: 32775,
5188
+ MAX_EXT: 32776
5189
+ },
5190
+ EXT_shader_texture_lod: {}
5191
+ };
5192
+ var getWEBGL_draw_buffers = (gl) => ({
5193
+ drawBuffersWEBGL(buffers) {
5194
+ return gl.drawBuffers(buffers);
5195
+ },
5196
+ COLOR_ATTACHMENT0_WEBGL: 36064,
5197
+ COLOR_ATTACHMENT1_WEBGL: 36065,
5198
+ COLOR_ATTACHMENT2_WEBGL: 36066,
5199
+ COLOR_ATTACHMENT3_WEBGL: 36067
5200
+ });
5201
+ var getOES_vertex_array_object = (gl) => ({
5202
+ VERTEX_ARRAY_BINDING_OES: 34229,
5203
+ createVertexArrayOES() {
5204
+ return gl.createVertexArray();
5205
+ },
5206
+ deleteVertexArrayOES(vertexArray) {
5207
+ return gl.deleteVertexArray(vertexArray);
5208
+ },
5209
+ isVertexArrayOES(vertexArray) {
5210
+ return gl.isVertexArray(vertexArray);
5211
+ },
5212
+ bindVertexArrayOES(vertexArray) {
5213
+ return gl.bindVertexArray(vertexArray);
5214
+ }
5215
+ });
5216
+ var getANGLE_instanced_arrays = (gl) => ({
5217
+ VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 35070,
5218
+ drawArraysInstancedANGLE(...args) {
5219
+ return gl.drawArraysInstanced(...args);
5220
+ },
5221
+ drawElementsInstancedANGLE(...args) {
5222
+ return gl.drawElementsInstanced(...args);
5223
+ },
5224
+ vertexAttribDivisorANGLE(...args) {
5225
+ return gl.vertexAttribDivisor(...args);
5226
+ }
5227
+ });
5228
+ function enforceWebGL2(enforce = true) {
5229
+ const prototype = HTMLCanvasElement.prototype;
5230
+ if (!enforce && prototype.originalGetContext) {
5231
+ prototype.getContext = prototype.originalGetContext;
5232
+ prototype.originalGetContext = void 0;
5233
+ return;
5234
+ }
5235
+ prototype.originalGetContext = prototype.getContext;
5236
+ prototype.getContext = function(contextId, options) {
5237
+ if (contextId === "webgl" || contextId === "experimental-webgl") {
5238
+ const context = this.originalGetContext("webgl2", options);
5239
+ if (context instanceof HTMLElement) {
5240
+ polyfillWebGL1Extensions(context);
5241
+ }
5242
+ return context;
5243
+ }
5244
+ return this.originalGetContext(contextId, options);
5245
+ };
5246
+ }
5247
+ function polyfillWebGL1Extensions(gl) {
5248
+ gl.getExtension("EXT_color_buffer_float");
5249
+ const boundExtensions = {
5250
+ ...WEBGL1_STATIC_EXTENSIONS,
5251
+ WEBGL_disjoint_timer_query: gl.getExtension("EXT_disjoint_timer_query_webgl2"),
5252
+ WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
5253
+ OES_vertex_array_object: getOES_vertex_array_object(gl),
5254
+ ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
5255
+ };
5256
+ const originalGetExtension = gl.getExtension;
5257
+ gl.getExtension = function(extensionName) {
5258
+ const ext = originalGetExtension.call(gl, extensionName);
5259
+ if (ext) {
5260
+ return ext;
5261
+ }
5262
+ if (extensionName in boundExtensions) {
5263
+ return boundExtensions[extensionName];
5264
+ }
5265
+ return null;
5266
+ };
5267
+ const originalGetSupportedExtensions = gl.getSupportedExtensions;
5268
+ gl.getSupportedExtensions = function() {
5269
+ const extensions = originalGetSupportedExtensions.apply(gl) || [];
5270
+ return extensions == null ? void 0 : extensions.concat(Object.keys(boundExtensions));
5271
+ };
5272
+ }
5273
+
5274
+ // dist/adapter/webgl-adapter.js
5275
+ var LOG_LEVEL2 = 1;
5276
+ var WebGLAdapter = class extends import_core24.Adapter {
5277
+ /** type of device's created by this adapter */
5278
+ type = "webgl";
5279
+ constructor() {
5280
+ super();
5281
+ import_core24.Device.defaultProps = { ...import_core24.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
5282
+ WebGLDevice.adapter = this;
5283
+ }
5284
+ /** Check if WebGL 2 is available */
5285
+ isSupported() {
5286
+ return typeof WebGL2RenderingContext !== "undefined";
5287
+ }
5288
+ /** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
5289
+ enforceWebGL2(enable2) {
5290
+ enforceWebGL2(enable2);
5291
+ }
5292
+ /**
5293
+ * Get a device instance from a GL context
5294
+ * Creates and instruments the device if not already created
5295
+ * @param gl
5296
+ * @returns
5297
+ */
5298
+ async attach(gl) {
5299
+ if (gl instanceof WebGLDevice) {
5300
+ return gl;
5301
+ }
5302
+ if ((gl == null ? void 0 : gl.device) instanceof import_core24.Device) {
5303
+ return gl.device;
5304
+ }
5305
+ if (!isWebGL(gl)) {
5306
+ throw new Error("Invalid WebGL2RenderingContext");
5307
+ }
5308
+ return new WebGLDevice({ gl });
5309
+ }
5310
+ async create(props = {}) {
5311
+ import_core24.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
5312
+ const promises = [];
5313
+ if (props.debug) {
5314
+ promises.push(loadWebGLDeveloperTools());
5315
+ }
5316
+ if (props.debugWithSpectorJS) {
5317
+ promises.push(loadSpectorJS(props));
5318
+ }
5319
+ if (typeof props.canvas === "string") {
5320
+ promises.push(import_core24.CanvasContext.pageLoaded);
5321
+ }
5322
+ const results = await Promise.allSettled(promises);
5323
+ for (const result of results) {
5324
+ if (result.status === "rejected") {
5325
+ import_core24.log.error(`Failed to initialize debug libraries ${result.reason}`)();
5326
+ }
5327
+ }
5328
+ import_core24.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5329
+ const device = new WebGLDevice(props);
5330
+ const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5331
+ import_core24.log.probe(LOG_LEVEL2, message2)();
5332
+ import_core24.log.table(LOG_LEVEL2, device.info)();
5333
+ import_core24.log.groupEnd(LOG_LEVEL2)();
5334
+ return device;
5335
+ }
5336
+ };
5337
+ function isWebGL(gl) {
5338
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
5339
+ return true;
5340
+ }
5341
+ return Boolean(gl && Number.isFinite(gl._version));
5342
+ }
5343
+ var webgl2Adapter = new WebGLAdapter();
5344
+
5345
+ // dist/deprecated/accessor.js
5346
+ var import_core25 = require("@luma.gl/core");
5347
+ var import_constants28 = require("@luma.gl/constants");
5348
+ var DEFAULT_ACCESSOR_VALUES = {
5349
+ offset: 0,
5350
+ stride: 0,
5351
+ type: 5126,
5352
+ size: 1,
5353
+ divisor: 0,
5354
+ normalized: false,
5355
+ integer: false
5356
+ };
5357
+ var Accessor = class {
5358
+ offset;
5359
+ stride;
5360
+ type;
5361
+ size;
5362
+ divisor;
5363
+ normalized;
5364
+ integer;
5365
+ buffer;
5366
+ index;
5367
+ static getBytesPerElement(accessor) {
5368
+ const ArrayType = getTypedArrayFromGLType2(accessor.type || 5126);
5369
+ return ArrayType.BYTES_PER_ELEMENT;
5370
+ }
5371
+ static getBytesPerVertex(accessor) {
5372
+ const ArrayType = getTypedArrayFromGLType2(accessor.type || 5126);
5373
+ return ArrayType.BYTES_PER_ELEMENT * accessor.size;
5374
+ }
5375
+ // Combines (merges) a list of accessors. On top of default values
5376
+ // Usually [programAccessor, bufferAccessor, appAccessor]
5377
+ // All props will be set in the returned object.
5378
+ // TODO check for conflicts between values in the supplied accessors
5379
+ static resolve(...accessors) {
5380
+ return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
5381
+ }
5382
+ constructor(...accessors) {
5383
+ import_core25.log.warn("Accessor will be removed in next minor release");
5384
+ accessors.forEach((accessor) => this._assign(accessor));
5385
+ Object.freeze(this);
5386
+ }
5387
+ toString() {
5388
+ return JSON.stringify(this);
5389
+ }
5390
+ // ACCESSORS
5391
+ // TODO - remove>
5392
+ get BYTES_PER_ELEMENT() {
5393
+ return Accessor.getBytesPerElement(this);
5394
+ }
5395
+ get BYTES_PER_VERTEX() {
5396
+ return Accessor.getBytesPerVertex(this);
5397
+ }
5398
+ // PRIVATE
5399
+ // eslint-disable-next-line complexity, max-statements
5400
+ _assign(props = {}) {
5401
+ if (props.type !== void 0) {
5402
+ this.type = props.type;
5403
+ if (props.type === 5124 || props.type === 5125) {
5404
+ this.integer = true;
5405
+ }
5406
+ }
5407
+ if (props.size !== void 0) {
5408
+ this.size = props.size;
5409
+ }
5410
+ if (props.offset !== void 0) {
5411
+ this.offset = props.offset;
5412
+ }
5413
+ if (props.stride !== void 0) {
5414
+ this.stride = props.stride;
5415
+ }
5416
+ if (props.normalize !== void 0) {
5417
+ this.normalized = props.normalize;
5418
+ }
5419
+ if (props.normalized !== void 0) {
5420
+ this.normalized = props.normalized;
5421
+ }
5422
+ if (props.integer !== void 0) {
5423
+ this.integer = props.integer;
5424
+ }
5425
+ if (props.divisor !== void 0) {
5426
+ this.divisor = props.divisor;
5427
+ }
5428
+ if (props.buffer !== void 0) {
5429
+ this.buffer = props.buffer;
5430
+ }
5431
+ if (props.index !== void 0) {
5432
+ if (typeof props.index === "boolean") {
5433
+ this.index = props.index ? 1 : 0;
5434
+ } else {
5435
+ this.index = props.index;
5436
+ }
5437
+ }
5438
+ if (props.instanced !== void 0) {
5439
+ this.divisor = props.instanced ? 1 : 0;
5440
+ }
5441
+ if (props.isInstanced !== void 0) {
5442
+ this.divisor = props.isInstanced ? 1 : 0;
5443
+ }
5444
+ if (this.offset === void 0)
5445
+ delete this.offset;
5446
+ if (this.stride === void 0)
5447
+ delete this.stride;
5448
+ if (this.type === void 0)
5449
+ delete this.type;
5450
+ if (this.size === void 0)
5451
+ delete this.size;
5452
+ if (this.divisor === void 0)
5453
+ delete this.divisor;
5454
+ if (this.normalized === void 0)
5455
+ delete this.normalized;
5456
+ if (this.integer === void 0)
5457
+ delete this.integer;
5458
+ if (this.buffer === void 0)
5459
+ delete this.buffer;
5460
+ if (this.index === void 0)
5461
+ delete this.index;
5462
+ return this;
5463
+ }
5464
+ };
5465
+ function getTypedArrayFromGLType2(glType, options) {
5466
+ const { clamped = true } = options || {};
5467
+ switch (glType) {
5468
+ case 5126:
5469
+ return Float32Array;
5470
+ case 5123:
5471
+ case 33635:
5472
+ case 32819:
5473
+ case 32820:
5474
+ return Uint16Array;
5475
+ case 5125:
5476
+ return Uint32Array;
5477
+ case 5121:
5478
+ return clamped ? Uint8ClampedArray : Uint8Array;
5479
+ case 5120:
5480
+ return Int8Array;
5481
+ case 5122:
5482
+ return Int16Array;
5483
+ case 5124:
5484
+ return Int32Array;
5485
+ default:
5486
+ throw new Error("Failed to deduce typed array type from GL constant");
5487
+ }
5488
+ }
5322
5489
  //# sourceMappingURL=index.cjs.map