@luma.gl/webgl 9.1.0 → 9.1.2

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
@@ -4654,6 +4654,7 @@ var WebGLDevice = class extends import_core22.Device {
4654
4654
  //
4655
4655
  /** type of this device */
4656
4656
  type = "webgl";
4657
+ // Use the ! assertion to handle the case where _reuseDevices causes the constructor to return early
4657
4658
  /** The underlying WebGL context */
4658
4659
  handle;
4659
4660
  features;
@@ -4678,10 +4679,10 @@ var WebGLDevice = class extends import_core22.Device {
4678
4679
  constructor(props) {
4679
4680
  var _a, _b;
4680
4681
  super({ ...props, id: props.id || uid("webgl-device") });
4681
- if (!props.createCanvasContext) {
4682
+ const canvasContextProps = import_core22.Device._getCanvasContextProps(props);
4683
+ if (!canvasContextProps) {
4682
4684
  throw new Error("WebGLDevice requires props.createCanvasContext to be set");
4683
4685
  }
4684
- const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
4685
4686
  let device = (_b = (_a = canvasContextProps.canvas) == null ? void 0 : _a.gl) == null ? void 0 : _b.device;
4686
4687
  if (device) {
4687
4688
  throw new Error(`WebGL context already attached to device ${device.id}`);
@@ -4714,6 +4715,11 @@ var WebGLDevice = class extends import_core22.Device {
4714
4715
  }
4715
4716
  device = gl.device;
4716
4717
  if (device) {
4718
+ if (props._reuseDevices) {
4719
+ import_core22.log.log(1, `Not creating a new Device, instead returning a reference to Device ${device.id} already attached to WebGL context`, device)();
4720
+ device._reused = true;
4721
+ return device;
4722
+ }
4717
4723
  throw new Error(`WebGL context already attached to device ${device.id}`);
4718
4724
  }
4719
4725
  this.handle = gl;
@@ -4745,10 +4751,19 @@ var WebGLDevice = class extends import_core22.Device {
4745
4751
  }
4746
4752
  }
4747
4753
  /**
4748
- * Destroys the context
4749
- * @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
4754
+ * Destroys the device
4755
+ *
4756
+ * @note "Detaches" from the WebGL context unless _reuseDevices is true.
4757
+ *
4758
+ * @note The underlying WebGL context is not immediately destroyed,
4759
+ * but may be destroyed later through normal JavaScript garbage collection.
4760
+ * This is a fundamental limitation since WebGL does not offer any
4761
+ * browser API for destroying WebGL contexts.
4750
4762
  */
4751
4763
  destroy() {
4764
+ if (!this.props._reuseDevices && !this._reused) {
4765
+ delete this.gl.device;
4766
+ }
4752
4767
  }
4753
4768
  get isLost() {
4754
4769
  return this.gl.isContextLost();
@@ -5133,7 +5148,7 @@ var WebGLAdapter = class extends import_core23.Adapter {
5133
5148
  }
5134
5149
  }
5135
5150
  const device = new WebGLDevice(props);
5136
- const message2 = `Created ${device.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5151
+ const message2 = `${device._reused ? "Reusing" : "Created"} device with WebGL2 ${device.debug ? "debug " : ""}context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
5137
5152
  import_core23.log.probe(LOG_LEVEL2, message2)();
5138
5153
  import_core23.log.table(LOG_LEVEL2, device.info)();
5139
5154
  import_core23.log.groupEnd(LOG_LEVEL2)();