@luma.gl/core 9.0.0-beta.9 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -116,7 +116,7 @@ var lumaStats = new StatsManager();
116
116
 
117
117
  // dist/init.js
118
118
  function initializeLuma() {
119
- const VERSION2 = true ? "9.0.0-beta.8" : "running from source";
119
+ const VERSION2 = true ? "9.0.2" : "running from source";
120
120
  const STARTUP_MESSAGE = "set luma.log.level=1 (or higher) to trace rendering";
121
121
  if (globalThis.luma && globalThis.luma.VERSION !== VERSION2) {
122
122
  throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION2}`);
@@ -647,61 +647,100 @@ function assert(condition, message) {
647
647
  }
648
648
 
649
649
  // dist/lib/luma.js
650
- var deviceList = /* @__PURE__ */ new Map();
650
+ var deviceMap = /* @__PURE__ */ new Map();
651
651
  var luma = class {
652
652
  static registerDevices(deviceClasses) {
653
653
  for (const deviceClass of deviceClasses) {
654
654
  assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
655
- deviceList.set(deviceClass.type, deviceClass);
655
+ deviceMap.set(deviceClass.type, deviceClass);
656
656
  }
657
657
  }
658
658
  static getAvailableDevices() {
659
- return Array.from(deviceList).map((Device2) => Device2.type);
659
+ return Array.from(deviceMap).map((Device2) => Device2.type);
660
660
  }
661
661
  static getSupportedDevices() {
662
- return Array.from(deviceList).filter((Device2) => Device2.isSupported()).map((Device2) => Device2.type);
662
+ return Array.from(deviceMap).filter((Device2) => Device2.isSupported()).map((Device2) => Device2.type);
663
663
  }
664
664
  static setDefaultDeviceProps(props) {
665
665
  Object.assign(Device.defaultProps, props);
666
666
  }
667
+ /** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
668
+ static async attachDevice(props) {
669
+ const devices = getDeviceMap(props.devices) || deviceMap;
670
+ if (props.handle instanceof WebGL2RenderingContext) {
671
+ const WebGLDevice = devices.get("webgl");
672
+ if (WebGLDevice) {
673
+ return await WebGLDevice.attach(props.handle);
674
+ }
675
+ }
676
+ if (props.handle === null) {
677
+ const UnknownDevice = devices.get("unknown");
678
+ if (UnknownDevice) {
679
+ return await UnknownDevice.attach(null);
680
+ }
681
+ }
682
+ throw new Error("Failed to attach device. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.");
683
+ }
667
684
  /** Creates a device. Asynchronously. */
668
685
  static async createDevice(props = {}) {
686
+ var _a, _b;
669
687
  props = { ...Device.defaultProps, ...props };
670
688
  if (props.gl) {
671
689
  props.type = "webgl";
672
690
  }
673
- let DeviceClass;
691
+ const devices = getDeviceMap(props.devices) || deviceMap;
674
692
  switch (props.type) {
675
693
  case "webgpu":
676
- DeviceClass = deviceList.get("webgpu");
677
- if (DeviceClass) {
678
- return await DeviceClass.create(props);
694
+ let WebGPUDevice = devices.get("webgpu");
695
+ if (WebGPUDevice) {
696
+ return await WebGPUDevice.create(props);
679
697
  }
680
698
  break;
681
699
  case "webgl":
682
- DeviceClass = deviceList.get("webgl");
683
- if (DeviceClass) {
684
- return await DeviceClass.create(props);
700
+ let WebGLDevice = devices.get("webgl");
701
+ if (WebGLDevice) {
702
+ return await WebGLDevice.create(props);
703
+ }
704
+ break;
705
+ case "unknown":
706
+ const UnknownDevice = devices.get("unknown");
707
+ if (UnknownDevice) {
708
+ return await UnknownDevice.create(props);
685
709
  }
686
710
  break;
687
711
  case "best-available":
688
- DeviceClass = deviceList.get("webgpu");
689
- if (DeviceClass && DeviceClass.isSupported()) {
690
- return await DeviceClass.create(props);
712
+ WebGPUDevice = devices.get("webgpu");
713
+ if ((_a = WebGPUDevice == null ? void 0 : WebGPUDevice.isSupported) == null ? void 0 : _a.call(WebGPUDevice)) {
714
+ return await WebGPUDevice.create(props);
691
715
  }
692
- DeviceClass = deviceList.get("webgl");
693
- if (DeviceClass && DeviceClass.isSupported()) {
694
- return await DeviceClass.create(props);
716
+ WebGLDevice = devices.get("webgl");
717
+ if ((_b = WebGLDevice == null ? void 0 : WebGLDevice.isSupported) == null ? void 0 : _b.call(WebGLDevice)) {
718
+ return await WebGLDevice.create(props);
695
719
  }
696
720
  break;
697
721
  }
698
722
  throw new Error("No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.");
699
723
  }
700
724
  };
725
+ __publicField(luma, "defaultProps", {
726
+ ...Device.defaultProps,
727
+ type: "best-available",
728
+ devices: void 0
729
+ });
701
730
  /** Global stats for all devices */
702
731
  __publicField(luma, "stats", lumaStats);
703
732
  /** Global log */
704
733
  __publicField(luma, "log", log);
734
+ function getDeviceMap(deviceClasses) {
735
+ if (!deviceClasses || (deviceClasses == null ? void 0 : deviceClasses.length) === 0) {
736
+ return null;
737
+ }
738
+ const map = /* @__PURE__ */ new Map();
739
+ for (const deviceClass of deviceClasses) {
740
+ map.set(deviceClass.type, deviceClass);
741
+ }
742
+ return map;
743
+ }
705
744
 
706
745
  // dist/adapter/canvas-context.js
707
746
  var import_env2 = require("@probe.gl/env");