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

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 (82) 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 +0 -1
  8. package/dist/adapter/helpers/webgl-texture-utils.d.ts +4 -4
  9. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  10. package/dist/adapter/helpers/webgl-texture-utils.js +11 -9
  11. package/dist/adapter/resources/webgl-framebuffer.js +1 -1
  12. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pass.js +17 -4
  14. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgl-render-pipeline.js +1 -1
  16. package/dist/adapter/resources/webgl-shader.js +1 -1
  17. package/dist/adapter/resources/webgl-texture.d.ts +21 -3
  18. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  19. package/dist/adapter/resources/webgl-texture.js +23 -29
  20. package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
  21. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgl-vertex-array.js +3 -0
  23. package/dist/adapter/webgl-adapter.d.ts +21 -0
  24. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  25. package/dist/adapter/webgl-adapter.js +91 -0
  26. package/dist/adapter/webgl-device.d.ts +15 -27
  27. package/dist/adapter/webgl-device.d.ts.map +1 -1
  28. package/dist/adapter/webgl-device.js +32 -112
  29. package/dist/classic/copy-and-blit.d.ts +1 -0
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +11 -10
  32. package/dist/context/debug/spector-types.d.ts +1108 -0
  33. package/dist/context/debug/spector-types.d.ts.map +1 -0
  34. package/dist/context/debug/spector-types.js +697 -0
  35. package/dist/context/debug/spector.d.ts +12 -8
  36. package/dist/context/debug/spector.d.ts.map +1 -1
  37. package/dist/context/debug/spector.js +23 -17
  38. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  39. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  40. package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
  41. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  42. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  43. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +44 -74
  44. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  45. package/dist/context/state-tracker/with-parameters.js +5 -4
  46. package/dist/dist.dev.js +352 -236
  47. package/dist/dist.min.js +2 -2
  48. package/dist/index.cjs +355 -238
  49. package/dist/index.cjs.map +4 -4
  50. package/dist/index.d.ts +3 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +3 -2
  53. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  54. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  55. package/dist/utils/uid.d.ts +7 -0
  56. package/dist/utils/uid.d.ts.map +1 -0
  57. package/dist/utils/uid.js +14 -0
  58. package/package.json +3 -3
  59. package/src/adapter/converters/device-parameters.ts +18 -12
  60. package/src/adapter/converters/texture-formats.ts +12 -20
  61. package/src/adapter/device-helpers/webgl-device-features.ts +0 -1
  62. package/src/adapter/helpers/webgl-texture-utils.ts +12 -9
  63. package/src/adapter/resources/webgl-framebuffer.ts +1 -1
  64. package/src/adapter/resources/webgl-render-pass.ts +17 -4
  65. package/src/adapter/resources/webgl-render-pipeline.ts +2 -1
  66. package/src/adapter/resources/webgl-shader.ts +1 -1
  67. package/src/adapter/resources/webgl-texture.ts +42 -29
  68. package/src/adapter/resources/webgl-transform-feedback.ts +1 -1
  69. package/src/adapter/resources/webgl-vertex-array.ts +3 -0
  70. package/src/adapter/webgl-adapter.ts +113 -0
  71. package/src/adapter/webgl-device.ts +32 -135
  72. package/src/classic/copy-and-blit.ts +14 -9
  73. package/src/context/debug/spector-types.ts +1154 -0
  74. package/src/context/debug/spector.ts +38 -29
  75. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  76. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
  77. package/src/context/state-tracker/with-parameters.ts +5 -4
  78. package/src/index.ts +5 -7
  79. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  80. package/src/utils/uid.ts +16 -0
  81. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  82. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
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,20 +32,22 @@ __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_core23 = require("@luma.gl/core");
50
+
54
51
  // dist/adapter/webgl-device.js
55
52
  var import_core22 = require("@luma.gl/core");
56
53
 
@@ -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",
@@ -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);
@@ -1858,7 +1828,7 @@ function copyCPUImageToMipLevel(gl, image, options) {
1858
1828
  const { dimension, width, height, depth = 0, level = 0 } = options;
1859
1829
  const { x = 0, y = 0, z = 0 } = options;
1860
1830
  const { glFormat, glType } = options;
1861
- const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1831
+ const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
1862
1832
  switch (dimension) {
1863
1833
  case "2d-array":
1864
1834
  case "3d":
@@ -1876,7 +1846,7 @@ function copyCPUDataToMipLevel(gl, typedArray, options) {
1876
1846
  const { dimension, width, height, depth = 0, level = 0, byteOffset = 0 } = options;
1877
1847
  const { x = 0, y = 0, z = 0 } = options;
1878
1848
  const { glFormat, glType, compressed } = options;
1879
- const glTarget = getCubeTargetWebGL(options.glTarget, dimension, depth);
1849
+ const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
1880
1850
  switch (dimension) {
1881
1851
  case "2d-array":
1882
1852
  case "3d":
@@ -1915,7 +1885,7 @@ function getWebGLTextureTarget(dimension) {
1915
1885
  }
1916
1886
  throw new Error(dimension);
1917
1887
  }
1918
- function getCubeTargetWebGL(glTarget, dimension, level) {
1888
+ function getWebGLCubeFaceTarget(glTarget, dimension, level) {
1919
1889
  return dimension === "cube" ? 34069 + level : glTarget;
1920
1890
  }
1921
1891
 
@@ -2008,7 +1978,7 @@ var WEBGLTexture = class extends import_core7.Texture {
2008
1978
  const data = props.data;
2009
1979
  let { width, height } = props;
2010
1980
  if (!width || !height) {
2011
- const textureSize = this.getTextureDataSize(data);
1981
+ const textureSize = import_core7.Texture.getTextureDataSize(data);
2012
1982
  width = (textureSize == null ? void 0 : textureSize.width) || 1;
2013
1983
  height = (textureSize == null ? void 0 : textureSize.height) || 1;
2014
1984
  }
@@ -2116,11 +2086,20 @@ var WEBGLTexture = class extends import_core7.Texture {
2116
2086
  this.gl.bindTexture(this.glTarget, null);
2117
2087
  }
2118
2088
  // Image Data Setters
2089
+ copyExternalImage(options) {
2090
+ const size = import_core7.Texture.getExternalImageSize(options.image);
2091
+ const opts = { ...import_core7.Texture.defaultCopyExternalImageOptions, ...size, ...options };
2092
+ const { depth, mipLevel: lodLevel, image } = opts;
2093
+ this.bind();
2094
+ this._setMipLevel(depth, lodLevel, image);
2095
+ this.unbind();
2096
+ return { width: opts.width, height: opts.height };
2097
+ }
2119
2098
  setTexture1DData(data) {
2120
2099
  throw new Error("setTexture1DData not supported in WebGL.");
2121
2100
  }
2122
2101
  /** Set a simple texture */
2123
- setTexture2DData(lodData, depth = 0, glTarget = this.glTarget) {
2102
+ setTexture2DData(lodData, depth = 0) {
2124
2103
  this.bind();
2125
2104
  const lodArray = normalizeTextureData(lodData, this);
2126
2105
  if (lodArray.length > 1 && this.props.mipmaps !== false) {
@@ -2141,7 +2120,9 @@ var WEBGLTexture = class extends import_core7.Texture {
2141
2120
  throw new Error(this.id);
2142
2121
  }
2143
2122
  if (ArrayBuffer.isView(data)) {
2123
+ this.bind();
2144
2124
  copyCPUDataToMipLevel(this.device.gl, data, this);
2125
+ this.unbind();
2145
2126
  }
2146
2127
  }
2147
2128
  /**
@@ -2154,6 +2135,9 @@ var WEBGLTexture = class extends import_core7.Texture {
2154
2135
  if (this.props.dimension !== "cube") {
2155
2136
  throw new Error(this.id);
2156
2137
  }
2138
+ for (const face of import_core7.Texture.CubeFaces) {
2139
+ this.setTextureCubeFaceData(data[face], face);
2140
+ }
2157
2141
  }
2158
2142
  /**
2159
2143
  * Sets an entire texture array
@@ -2176,8 +2160,8 @@ var WEBGLTexture = class extends import_core7.Texture {
2176
2160
  if (Array.isArray(lodData) && lodData.length > 1 && this.props.mipmaps !== false) {
2177
2161
  import_core7.log.warn(`${this.id} has mipmap and multiple LODs.`)();
2178
2162
  }
2179
- this.bind();
2180
- this.unbind();
2163
+ const faceDepth = import_core7.Texture.CubeFaces.indexOf(face);
2164
+ this.setTexture2DData(lodData, faceDepth);
2181
2165
  }
2182
2166
  // INTERNAL METHODS
2183
2167
  /** @todo update this method to accept LODs */
@@ -2311,16 +2295,17 @@ var WEBGLTexture = class extends import_core7.Texture {
2311
2295
  * Copy a region of data from a CPU memory buffer into this texture.
2312
2296
  * @todo - GLUnpackParameters parameters
2313
2297
  */
2314
- _setMipLevel(depth, level, textureData, offset = 0) {
2298
+ _setMipLevel(depth, level, textureData, glTarget = this.glTarget) {
2315
2299
  if (import_core7.Texture.isExternalImage(textureData)) {
2316
- copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level });
2300
+ copyCPUImageToMipLevel(this.device.gl, textureData, { ...this, depth, level, glTarget });
2317
2301
  return;
2318
2302
  }
2319
- if (this.isTextureLevelData(textureData)) {
2303
+ if (import_core7.Texture.isTextureLevelData(textureData)) {
2320
2304
  copyCPUDataToMipLevel(this.device.gl, textureData.data, {
2321
2305
  ...this,
2322
2306
  depth,
2323
- level
2307
+ level,
2308
+ glTarget
2324
2309
  });
2325
2310
  return;
2326
2311
  }
@@ -2453,7 +2438,7 @@ var WEBGLFramebuffer = class extends import_core8.Framebuffer {
2453
2438
  switch (texture.glTarget) {
2454
2439
  case 35866:
2455
2440
  case 32879:
2456
- gl.framebufferTextureLayer(36160, attachment, texture.glTarget, level, layer);
2441
+ gl.framebufferTextureLayer(36160, attachment, texture.handle, level, layer);
2457
2442
  break;
2458
2443
  case 34067:
2459
2444
  const face = mapIndexToCubeMapFace(layer);
@@ -2566,30 +2551,36 @@ async function loadScript(scriptUrl, scriptId) {
2566
2551
  }
2567
2552
 
2568
2553
  // 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
2554
  var LOG_LEVEL = 1;
2574
2555
  var spector = null;
2575
2556
  var initialized = false;
2557
+ var DEFAULT_SPECTOR_PROPS = {
2558
+ debugWithSpectorJS: import_core10.log.get("spector") || import_core10.log.get("spectorjs"),
2559
+ // https://github.com/BabylonJS/Spector.js#basic-usage
2560
+ // https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
2561
+ // spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
2562
+ spectorUrl: "https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js",
2563
+ gl: void 0
2564
+ };
2576
2565
  async function loadSpectorJS(props) {
2577
2566
  if (!globalThis.SPECTOR) {
2578
2567
  try {
2579
- await loadScript(SPECTOR_CDN_URL);
2568
+ await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
2580
2569
  } catch (error) {
2581
2570
  import_core10.log.warn(String(error));
2582
2571
  }
2583
2572
  }
2584
2573
  }
2585
2574
  function initializeSpectorJS(props) {
2575
+ var _a;
2586
2576
  props = { ...DEFAULT_SPECTOR_PROPS, ...props };
2587
- if (!(props == null ? void 0 : props.spector)) {
2577
+ if (!props.debugWithSpectorJS) {
2588
2578
  return null;
2589
2579
  }
2590
- if (!spector && globalThis.SPECTOR) {
2591
- import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized")();
2592
- spector = new globalThis.SPECTOR.Spector();
2580
+ if (!spector && globalThis.SPECTOR && !((_a = globalThis.luma) == null ? void 0 : _a.spector)) {
2581
+ import_core10.log.probe(LOG_LEVEL, "SPECTOR found and initialized. Start with `luma.spector.displayUI()`")();
2582
+ const { Spector } = globalThis.SPECTOR;
2583
+ spector = new Spector();
2593
2584
  if (globalThis.luma) {
2594
2585
  globalThis.luma.spector = spector;
2595
2586
  }
@@ -2608,11 +2599,11 @@ function initializeSpectorJS(props) {
2608
2599
  spector == null ? void 0 : spector.resultView.addCapture(capture);
2609
2600
  });
2610
2601
  }
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);
2602
+ if (props.gl) {
2603
+ const gl = props.gl;
2604
+ const device = gl.device;
2605
+ spector == null ? void 0 : spector.startCapture(props.gl, 500);
2606
+ gl.device = device;
2616
2607
  new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
2617
2608
  import_core10.log.info("Spector capture stopped after 2 seconds")();
2618
2609
  spector == null ? void 0 : spector.stopCapture();
@@ -2713,6 +2704,14 @@ function onValidateGLFunc(props, functionName, functionArgs) {
2713
2704
  }
2714
2705
  }
2715
2706
 
2707
+ // dist/utils/uid.js
2708
+ var uidCounters = {};
2709
+ function uid(id = "id") {
2710
+ uidCounters[id] = uidCounters[id] || 1;
2711
+ const count = uidCounters[id]++;
2712
+ return `${id}-${count}`;
2713
+ }
2714
+
2716
2715
  // dist/adapter/resources/webgl-buffer.js
2717
2716
  var import_core12 = require("@luma.gl/core");
2718
2717
  var import_constants13 = require("@luma.gl/constants");
@@ -2917,8 +2916,8 @@ var WEBGLShader = class extends import_core13.Shader {
2917
2916
  return this.getCompilationInfoSync();
2918
2917
  }
2919
2918
  getCompilationInfoSync() {
2920
- const log9 = this.device.gl.getShaderInfoLog(this.handle);
2921
- return log9 ? parseShaderCompilerLog(log9) : [];
2919
+ const log10 = this.device.gl.getShaderInfoLog(this.handle);
2920
+ return log10 ? parseShaderCompilerLog(log10) : [];
2922
2921
  }
2923
2922
  getTranslatedSource() {
2924
2923
  const extensions = this.device.getExtension("WEBGL_debug_shaders");
@@ -2928,7 +2927,7 @@ var WEBGLShader = class extends import_core13.Shader {
2928
2927
  // PRIVATE METHODS
2929
2928
  /** Compile a shader and get compilation status */
2930
2929
  async _compile(source) {
2931
- const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
2930
+ const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 300 es
2932
2931
  ${source2}`;
2933
2932
  source = addGLSLVersion(source);
2934
2933
  const { gl } = this.device;
@@ -2992,14 +2991,25 @@ var WEBGLRenderPass = class extends import_core14.RenderPass {
2992
2991
  /** Parameters that should be applied before each draw call */
2993
2992
  glParameters;
2994
2993
  constructor(device, props) {
2994
+ var _a;
2995
2995
  super(device, props);
2996
2996
  this.device = device;
2997
- pushContextState(this.device.gl);
2998
- this.setParameters(this.props.parameters);
2997
+ let viewport;
2998
+ if (!((_a = props == null ? void 0 : props.parameters) == null ? void 0 : _a.viewport)) {
2999
+ if (props == null ? void 0 : props.framebuffer) {
3000
+ const { width, height } = props.framebuffer;
3001
+ viewport = [0, 0, width, height];
3002
+ } else {
3003
+ const [width, height] = device.getCanvasContext().getDrawingBufferSize();
3004
+ viewport = [0, 0, width, height];
3005
+ }
3006
+ }
3007
+ this.device.pushState();
3008
+ this.setParameters({ viewport, ...this.props.parameters });
2999
3009
  this.clear();
3000
3010
  }
3001
3011
  end() {
3002
- popContextState(this.device.gl);
3012
+ this.device.popState();
3003
3013
  }
3004
3014
  pushDebugGroup(groupLabel) {
3005
3015
  }
@@ -3767,7 +3777,7 @@ var WEBGLRenderPipeline = class extends import_core15.RenderPipeline {
3767
3777
  if (!binding) {
3768
3778
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
3769
3779
  if (!(options == null ? void 0 : options.disableWarnings)) {
3770
- import_core15.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3780
+ import_core15.log.warn(`No binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`, value)();
3771
3781
  }
3772
3782
  continue;
3773
3783
  }
@@ -4364,6 +4374,7 @@ var WEBGLVertexArray = class extends import_core18.VertexArray {
4364
4374
  } else {
4365
4375
  this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
4366
4376
  }
4377
+ this.device.gl.bindBuffer(34962, null);
4367
4378
  this.device.gl.enableVertexAttribArray(location);
4368
4379
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
4369
4380
  this.attributes[location] = buffer;
@@ -4542,7 +4553,7 @@ var WEBGLTransformFeedback = class extends import_core19.TransformFeedback {
4542
4553
  }
4543
4554
  end() {
4544
4555
  this.gl.endTransformFeedback();
4545
- if (!this.bindOnUse) {
4556
+ if (this.bindOnUse) {
4546
4557
  this._unbindBuffers();
4547
4558
  }
4548
4559
  this.gl.bindTransformFeedback(36386, null);
@@ -4820,11 +4831,10 @@ function glTypeToBytes(type) {
4820
4831
 
4821
4832
  // dist/classic/copy-and-blit.js
4822
4833
  function readPixelsToArray(source, options) {
4823
- var _a, _b;
4834
+ var _a, _b, _c, _d, _e, _f;
4824
4835
  const {
4825
4836
  sourceX = 0,
4826
4837
  sourceY = 0,
4827
- sourceFormat = 6408,
4828
4838
  sourceAttachment = 36064
4829
4839
  // TODO - support gl.readBuffer
4830
4840
  } = options || {};
@@ -4833,15 +4843,19 @@ function readPixelsToArray(source, options) {
4833
4843
  // following parameters are auto deduced if not provided
4834
4844
  sourceWidth,
4835
4845
  sourceHeight,
4846
+ sourceDepth,
4847
+ sourceFormat,
4836
4848
  sourceType
4837
4849
  } = options || {};
4838
4850
  const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
4839
4851
  const { gl, handle } = framebuffer;
4840
- sourceWidth = sourceWidth || framebuffer.width;
4841
- sourceHeight = sourceHeight || framebuffer.height;
4842
4852
  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);
4853
+ sourceWidth ||= framebuffer.width;
4854
+ sourceHeight ||= framebuffer.height;
4855
+ sourceDepth = ((_b = (_a = framebuffer.colorAttachments[attachment]) == null ? void 0 : _a.texture) == null ? void 0 : _b.depth) || 1;
4856
+ sourceFormat ||= ((_d = (_c = framebuffer.colorAttachments[attachment]) == null ? void 0 : _c.texture) == null ? void 0 : _d.glFormat) || 6408;
4857
+ sourceType ||= ((_f = (_e = framebuffer.colorAttachments[attachment]) == null ? void 0 : _e.texture) == null ? void 0 : _f.glType) || 5121;
4858
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
4845
4859
  sourceType = sourceType || getGLTypeFromTypedArray(target);
4846
4860
  const prevHandle = gl.bindFramebuffer(36160, handle);
4847
4861
  gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
@@ -4898,7 +4912,7 @@ function toFramebuffer(texture, props) {
4898
4912
  });
4899
4913
  return framebuffer;
4900
4914
  }
4901
- function getPixelArray(pixelArray, type, format, width, height) {
4915
+ function getPixelArray(pixelArray, type, format, width, height, depth) {
4902
4916
  if (pixelArray) {
4903
4917
  return pixelArray;
4904
4918
  }
@@ -4944,8 +4958,10 @@ function clear(device, options) {
4944
4958
  }
4945
4959
 
4946
4960
  // dist/adapter/webgl-device.js
4947
- var LOG_LEVEL2 = 1;
4948
- var _WebGLDevice = class extends import_core22.Device {
4961
+ var WebGLDevice = class extends import_core22.Device {
4962
+ //
4963
+ // Public `Device` API
4964
+ //
4949
4965
  /** type of this device */
4950
4966
  type = "webgl";
4951
4967
  /** The underlying WebGL context */
@@ -4956,68 +4972,22 @@ var _WebGLDevice = class extends import_core22.Device {
4956
4972
  canvasContext;
4957
4973
  lost;
4958
4974
  _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
- }
4975
+ /** WebGL2 context. */
4976
+ gl;
4977
+ debug = false;
4978
+ /** State used by luma.gl classes: TODO - move to canvasContext*/
4979
+ _canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
4980
+ /** State used by luma.gl classes - TODO - not used? */
4981
+ _extensions = {};
4982
+ _polyfilled = false;
4983
+ /** Instance of Spector.js (if initialized) */
4984
+ spectorJS;
5015
4985
  //
5016
4986
  // Public API
5017
4987
  //
5018
4988
  constructor(props) {
5019
4989
  var _a, _b;
5020
- super({ ...props, id: props.id || "webgl-device" });
4990
+ super({ ...props, id: props.id || uid("webgl-device") });
5021
4991
  const device = (_a = props.gl) == null ? void 0 : _a.device;
5022
4992
  if (device) {
5023
4993
  throw new Error(`WebGL context already attached to device ${device.id}`);
@@ -5027,8 +4997,7 @@ var _WebGLDevice = class extends import_core22.Device {
5027
4997
  this.lost = new Promise((resolve) => {
5028
4998
  this._resolveContextLost = resolve;
5029
4999
  });
5030
- let gl = props.gl || null;
5031
- gl ||= createBrowserContext(this.canvasContext.canvas, {
5000
+ this.handle = createBrowserContext(this.canvasContext.canvas, {
5032
5001
  ...props,
5033
5002
  onContextLost: (event) => {
5034
5003
  var _a2;
@@ -5038,11 +5007,11 @@ var _WebGLDevice = class extends import_core22.Device {
5038
5007
  });
5039
5008
  }
5040
5009
  });
5041
- if (!gl) {
5010
+ this.gl = this.handle;
5011
+ if (!this.handle) {
5042
5012
  throw new Error("WebGL context creation failed");
5043
5013
  }
5044
- this.handle = gl;
5045
- this.gl = gl;
5014
+ this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
5046
5015
  this.gl.device = this;
5047
5016
  this.gl._version = 2;
5048
5017
  this.info = getDeviceInfo(this.gl, this._extensions);
@@ -5052,21 +5021,16 @@ var _WebGLDevice = class extends import_core22.Device {
5052
5021
  this.features.initializeFeatures();
5053
5022
  }
5054
5023
  this.canvasContext.resize();
5055
- const { enable: enable2 = true, copyState = false } = props;
5056
- trackContextState(this.gl, {
5057
- enable: enable2,
5058
- copyState,
5024
+ const glState = new WebGLStateTracker(this.gl, {
5059
5025
  log: (...args) => import_core22.log.log(1, ...args)()
5060
5026
  });
5027
+ glState.trackState(this.gl, { copyState: false });
5061
5028
  if (props.debug) {
5062
5029
  this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
5063
5030
  this.debug = true;
5064
5031
  import_core22.log.level = Math.max(import_core22.log.level, 1);
5065
5032
  import_core22.log.warn("WebGL debug mode activated. Performance reduced.")();
5066
5033
  }
5067
- if (props.spector) {
5068
- this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
5069
- }
5070
5034
  }
5071
5035
  /**
5072
5036
  * Destroys the context
@@ -5077,9 +5041,6 @@ var _WebGLDevice = class extends import_core22.Device {
5077
5041
  get isLost() {
5078
5042
  return this.gl.isContextLost();
5079
5043
  }
5080
- getSize() {
5081
- return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
5082
- }
5083
5044
  isTextureFormatSupported(format) {
5084
5045
  return isTextureFormatSupported(this.gl, format, this._extensions);
5085
5046
  }
@@ -5178,16 +5139,6 @@ var _WebGLDevice = class extends import_core22.Device {
5178
5139
  //
5179
5140
  // WebGL-only API (not part of `Device` API)
5180
5141
  //
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
5142
  /**
5192
5143
  * Triggers device (or WebGL context) loss.
5193
5144
  * @note primarily intended for testing how application reacts to device loss
@@ -5209,11 +5160,13 @@ var _WebGLDevice = class extends import_core22.Device {
5209
5160
  }
5210
5161
  /** Save current WebGL context state onto an internal stack */
5211
5162
  pushState() {
5212
- pushContextState(this.gl);
5163
+ const webglState = WebGLStateTracker.get(this.gl);
5164
+ webglState.push();
5213
5165
  }
5214
5166
  /** Restores previously saved context state */
5215
5167
  popState() {
5216
- popContextState(this.gl);
5168
+ const webglState = WebGLStateTracker.get(this.gl);
5169
+ webglState.pop();
5217
5170
  }
5218
5171
  /**
5219
5172
  * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
@@ -5273,18 +5226,6 @@ var _WebGLDevice = class extends import_core22.Device {
5273
5226
  return this._extensions;
5274
5227
  }
5275
5228
  };
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
5229
  function setConstantFloatArray(device, location, array) {
5289
5230
  switch (array.length) {
5290
5231
  case 1:
@@ -5319,4 +5260,180 @@ function compareConstantArrayValues2(v1, v2) {
5319
5260
  }
5320
5261
  return true;
5321
5262
  }
5263
+
5264
+ // dist/context/polyfills/polyfill-webgl1-extensions.js
5265
+ var import_constants29 = require("@luma.gl/constants");
5266
+ var WEBGL1_STATIC_EXTENSIONS = {
5267
+ WEBGL_depth_texture: {
5268
+ UNSIGNED_INT_24_8_WEBGL: 34042
5269
+ },
5270
+ OES_element_index_uint: {},
5271
+ OES_texture_float: {},
5272
+ OES_texture_half_float: {
5273
+ // @ts-expect-error different numbers?
5274
+ HALF_FLOAT_OES: 5131
5275
+ },
5276
+ EXT_color_buffer_float: {},
5277
+ OES_standard_derivatives: {
5278
+ FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723
5279
+ },
5280
+ EXT_frag_depth: {},
5281
+ EXT_blend_minmax: {
5282
+ MIN_EXT: 32775,
5283
+ MAX_EXT: 32776
5284
+ },
5285
+ EXT_shader_texture_lod: {}
5286
+ };
5287
+ var getWEBGL_draw_buffers = (gl) => ({
5288
+ drawBuffersWEBGL(buffers) {
5289
+ return gl.drawBuffers(buffers);
5290
+ },
5291
+ COLOR_ATTACHMENT0_WEBGL: 36064,
5292
+ COLOR_ATTACHMENT1_WEBGL: 36065,
5293
+ COLOR_ATTACHMENT2_WEBGL: 36066,
5294
+ COLOR_ATTACHMENT3_WEBGL: 36067
5295
+ });
5296
+ var getOES_vertex_array_object = (gl) => ({
5297
+ VERTEX_ARRAY_BINDING_OES: 34229,
5298
+ createVertexArrayOES() {
5299
+ return gl.createVertexArray();
5300
+ },
5301
+ deleteVertexArrayOES(vertexArray) {
5302
+ return gl.deleteVertexArray(vertexArray);
5303
+ },
5304
+ isVertexArrayOES(vertexArray) {
5305
+ return gl.isVertexArray(vertexArray);
5306
+ },
5307
+ bindVertexArrayOES(vertexArray) {
5308
+ return gl.bindVertexArray(vertexArray);
5309
+ }
5310
+ });
5311
+ var getANGLE_instanced_arrays = (gl) => ({
5312
+ VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 35070,
5313
+ drawArraysInstancedANGLE(...args) {
5314
+ return gl.drawArraysInstanced(...args);
5315
+ },
5316
+ drawElementsInstancedANGLE(...args) {
5317
+ return gl.drawElementsInstanced(...args);
5318
+ },
5319
+ vertexAttribDivisorANGLE(...args) {
5320
+ return gl.vertexAttribDivisor(...args);
5321
+ }
5322
+ });
5323
+ function enforceWebGL2(enforce = true) {
5324
+ const prototype = HTMLCanvasElement.prototype;
5325
+ if (!enforce && prototype.originalGetContext) {
5326
+ prototype.getContext = prototype.originalGetContext;
5327
+ prototype.originalGetContext = void 0;
5328
+ return;
5329
+ }
5330
+ prototype.originalGetContext = prototype.getContext;
5331
+ prototype.getContext = function(contextId, options) {
5332
+ if (contextId === "webgl" || contextId === "experimental-webgl") {
5333
+ const context = this.originalGetContext("webgl2", options);
5334
+ if (context instanceof HTMLElement) {
5335
+ polyfillWebGL1Extensions(context);
5336
+ }
5337
+ return context;
5338
+ }
5339
+ return this.originalGetContext(contextId, options);
5340
+ };
5341
+ }
5342
+ function polyfillWebGL1Extensions(gl) {
5343
+ gl.getExtension("EXT_color_buffer_float");
5344
+ const boundExtensions = {
5345
+ ...WEBGL1_STATIC_EXTENSIONS,
5346
+ WEBGL_disjoint_timer_query: gl.getExtension("EXT_disjoint_timer_query_webgl2"),
5347
+ WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
5348
+ OES_vertex_array_object: getOES_vertex_array_object(gl),
5349
+ ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
5350
+ };
5351
+ const originalGetExtension = gl.getExtension;
5352
+ gl.getExtension = function(extensionName) {
5353
+ const ext = originalGetExtension.call(gl, extensionName);
5354
+ if (ext) {
5355
+ return ext;
5356
+ }
5357
+ if (extensionName in boundExtensions) {
5358
+ return boundExtensions[extensionName];
5359
+ }
5360
+ return null;
5361
+ };
5362
+ const originalGetSupportedExtensions = gl.getSupportedExtensions;
5363
+ gl.getSupportedExtensions = function() {
5364
+ const extensions = originalGetSupportedExtensions.apply(gl) || [];
5365
+ return extensions == null ? void 0 : extensions.concat(Object.keys(boundExtensions));
5366
+ };
5367
+ }
5368
+
5369
+ // dist/adapter/webgl-adapter.js
5370
+ var LOG_LEVEL2 = 1;
5371
+ var WebGLAdapter = class extends import_core23.Adapter {
5372
+ /** type of device's created by this adapter */
5373
+ type = "webgl";
5374
+ constructor() {
5375
+ super();
5376
+ import_core23.Device.defaultProps = { ...import_core23.Device.defaultProps, ...DEFAULT_SPECTOR_PROPS };
5377
+ WebGLDevice.adapter = this;
5378
+ }
5379
+ /** Check if WebGL 2 is available */
5380
+ isSupported() {
5381
+ return typeof WebGL2RenderingContext !== "undefined";
5382
+ }
5383
+ /** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
5384
+ enforceWebGL2(enable2) {
5385
+ enforceWebGL2(enable2);
5386
+ }
5387
+ /**
5388
+ * Get a device instance from a GL context
5389
+ * Creates and instruments the device if not already created
5390
+ * @param gl
5391
+ * @returns
5392
+ */
5393
+ async attach(gl) {
5394
+ if (gl instanceof WebGLDevice) {
5395
+ return gl;
5396
+ }
5397
+ if ((gl == null ? void 0 : gl.device) instanceof import_core23.Device) {
5398
+ return gl.device;
5399
+ }
5400
+ if (!isWebGL(gl)) {
5401
+ throw new Error("Invalid WebGL2RenderingContext");
5402
+ }
5403
+ return new WebGLDevice({ gl });
5404
+ }
5405
+ async create(props = {}) {
5406
+ import_core23.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
5407
+ const promises = [];
5408
+ if (props.debug) {
5409
+ promises.push(loadWebGLDeveloperTools());
5410
+ }
5411
+ if (props.debugWithSpectorJS) {
5412
+ promises.push(loadSpectorJS(props));
5413
+ }
5414
+ if (typeof props.canvas === "string") {
5415
+ promises.push(import_core23.CanvasContext.pageLoaded);
5416
+ }
5417
+ const results = await Promise.allSettled(promises);
5418
+ for (const result of results) {
5419
+ if (result.status === "rejected") {
5420
+ import_core23.log.error(`Failed to initialize debug libraries ${result.reason}`)();
5421
+ }
5422
+ }
5423
+ import_core23.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
5424
+ const device = new WebGLDevice(props);
5425
+ const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5426
+ import_core23.log.probe(LOG_LEVEL2, message2)();
5427
+ import_core23.log.table(LOG_LEVEL2, device.info)();
5428
+ import_core23.log.groupEnd(LOG_LEVEL2)();
5429
+ return device;
5430
+ }
5431
+ };
5432
+ function isWebGL(gl) {
5433
+ if (typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext) {
5434
+ return true;
5435
+ }
5436
+ return Boolean(gl && Number.isFinite(gl._version));
5437
+ }
5438
+ var webgl2Adapter = new WebGLAdapter();
5322
5439
  //# sourceMappingURL=index.cjs.map