@luma.gl/engine 9.3.5 → 9.4.0-alpha.1

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 (181) hide show
  1. package/dist/animation/animator.d.ts +42 -0
  2. package/dist/animation/animator.d.ts.map +1 -0
  3. package/dist/animation/animator.js +53 -0
  4. package/dist/animation/animator.js.map +1 -0
  5. package/dist/animation-loop/animation-loop.d.ts +14 -2
  6. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  7. package/dist/animation-loop/animation-loop.js +40 -22
  8. package/dist/animation-loop/animation-loop.js.map +1 -1
  9. package/dist/animation-loop/animation-props.d.ts +2 -0
  10. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  11. package/dist/animation-loop/make-animation-loop.d.ts +1 -0
  12. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  13. package/dist/animation-loop/make-animation-loop.js +3 -0
  14. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  15. package/dist/application-utils/load-file.d.ts +2 -0
  16. package/dist/application-utils/load-file.d.ts.map +1 -1
  17. package/dist/application-utils/load-file.js +31 -5
  18. package/dist/application-utils/load-file.js.map +1 -1
  19. package/dist/compute/buffer-transform.d.ts +5 -1
  20. package/dist/compute/buffer-transform.d.ts.map +1 -1
  21. package/dist/compute/buffer-transform.js +7 -3
  22. package/dist/compute/buffer-transform.js.map +1 -1
  23. package/dist/compute/computation.d.ts +20 -8
  24. package/dist/compute/computation.d.ts.map +1 -1
  25. package/dist/compute/computation.js +34 -13
  26. package/dist/compute/computation.js.map +1 -1
  27. package/dist/compute/swap.d.ts.map +1 -1
  28. package/dist/compute/swap.js +17 -0
  29. package/dist/compute/swap.js.map +1 -1
  30. package/dist/dist.dev.js +4100 -1979
  31. package/dist/dist.min.js +288 -42
  32. package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
  33. package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
  34. package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
  35. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
  36. package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
  37. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  38. package/dist/dynamic-texture/dynamic-texture.js +31 -2
  39. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  40. package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
  41. package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
  42. package/dist/dynamic-texture/texture-binding-source.js +55 -0
  43. package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
  44. package/dist/dynamic-texture/texture-data.d.ts +5 -3
  45. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  46. package/dist/dynamic-texture/texture-data.js +5 -0
  47. package/dist/dynamic-texture/texture-data.js.map +1 -1
  48. package/dist/dynamic-texture/video-texture.d.ts +101 -0
  49. package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
  50. package/dist/dynamic-texture/video-texture.js +272 -0
  51. package/dist/dynamic-texture/video-texture.js.map +1 -0
  52. package/dist/geometries/cube-geometry.d.ts +1 -0
  53. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  54. package/dist/geometries/cube-geometry.js +22 -2
  55. package/dist/geometries/cube-geometry.js.map +1 -1
  56. package/dist/geometries/plane-geometry.d.ts +10 -0
  57. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  58. package/dist/geometries/plane-geometry.js.map +1 -1
  59. package/dist/geometry/geometry-utils.d.ts +36 -1
  60. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  61. package/dist/geometry/geometry-utils.js +137 -2
  62. package/dist/geometry/geometry-utils.js.map +1 -1
  63. package/dist/geometry/geometry.d.ts +52 -33
  64. package/dist/geometry/geometry.d.ts.map +1 -1
  65. package/dist/geometry/geometry.js +70 -19
  66. package/dist/geometry/geometry.js.map +1 -1
  67. package/dist/geometry/gpu-geometry.d.ts +37 -4
  68. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  69. package/dist/geometry/gpu-geometry.js +44 -36
  70. package/dist/geometry/gpu-geometry.js.map +1 -1
  71. package/dist/index.cjs +3990 -1961
  72. package/dist/index.cjs.map +4 -4
  73. package/dist/index.d.ts +20 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +8 -5
  76. package/dist/index.js.map +1 -1
  77. package/dist/material/material-factory.d.ts +2 -1
  78. package/dist/material/material-factory.d.ts.map +1 -1
  79. package/dist/material/material-factory.js.map +1 -1
  80. package/dist/material/material.d.ts +29 -10
  81. package/dist/material/material.d.ts.map +1 -1
  82. package/dist/material/material.js +84 -21
  83. package/dist/material/material.js.map +1 -1
  84. package/dist/model/model.d.ts +81 -23
  85. package/dist/model/model.d.ts.map +1 -1
  86. package/dist/model/model.js +312 -78
  87. package/dist/model/model.js.map +1 -1
  88. package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
  89. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  90. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  91. package/dist/models/billboard-texture-model.d.ts +5 -2
  92. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  93. package/dist/models/billboard-texture-model.js +28 -10
  94. package/dist/models/billboard-texture-model.js.map +1 -1
  95. package/dist/modules/picking/index-color-picking.d.ts +24 -0
  96. package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
  97. package/dist/modules/picking/index-color-picking.js +205 -0
  98. package/dist/modules/picking/index-color-picking.js.map +1 -0
  99. package/dist/modules/picking/index-picking.d.ts +3 -3
  100. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  101. package/dist/modules/picking/index-picking.js +23 -6
  102. package/dist/modules/picking/index-picking.js.map +1 -1
  103. package/dist/modules/picking/picking-manager.d.ts +21 -0
  104. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  105. package/dist/modules/picking/picking-manager.js +100 -0
  106. package/dist/modules/picking/picking-manager.js.map +1 -1
  107. package/dist/modules/picking/picking-uniforms.d.ts +4 -4
  108. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  109. package/dist/modules/picking/picking-uniforms.js +3 -0
  110. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  111. package/dist/modules/picking/picking.d.ts +5 -1
  112. package/dist/modules/picking/picking.d.ts.map +1 -1
  113. package/dist/modules/picking/picking.js +6 -0
  114. package/dist/modules/picking/picking.js.map +1 -1
  115. package/dist/passes/get-fragment-shader.js +4 -4
  116. package/dist/passes/shader-pass-renderer.d.ts +92 -25
  117. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  118. package/dist/passes/shader-pass-renderer.js +466 -72
  119. package/dist/passes/shader-pass-renderer.js.map +1 -1
  120. package/dist/passes/texture-transform-module.d.ts +10 -0
  121. package/dist/passes/texture-transform-module.d.ts.map +1 -0
  122. package/dist/passes/texture-transform-module.js +50 -0
  123. package/dist/passes/texture-transform-module.js.map +1 -0
  124. package/dist/shader-inputs.d.ts +33 -16
  125. package/dist/shader-inputs.d.ts.map +1 -1
  126. package/dist/shader-inputs.js +42 -12
  127. package/dist/shader-inputs.js.map +1 -1
  128. package/dist/utils/buffer-layout-helper.d.ts +0 -1
  129. package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
  130. package/dist/utils/buffer-layout-helper.js +2 -11
  131. package/dist/utils/buffer-layout-helper.js.map +1 -1
  132. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  133. package/dist/utils/buffer-layout-order.js +4 -15
  134. package/dist/utils/buffer-layout-order.js.map +1 -1
  135. package/dist/utils/shader-module-utils.d.ts +2 -0
  136. package/dist/utils/shader-module-utils.d.ts.map +1 -1
  137. package/dist/utils/shader-module-utils.js +64 -3
  138. package/dist/utils/shader-module-utils.js.map +1 -1
  139. package/package.json +2 -2
  140. package/src/animation/animator.ts +79 -0
  141. package/src/animation-loop/animation-loop.ts +56 -22
  142. package/src/animation-loop/animation-props.ts +2 -0
  143. package/src/animation-loop/make-animation-loop.ts +4 -0
  144. package/src/application-utils/load-file.ts +38 -5
  145. package/src/compute/buffer-transform.ts +14 -5
  146. package/src/compute/computation.ts +53 -21
  147. package/src/compute/swap.ts +19 -0
  148. package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
  149. package/src/dynamic-texture/dynamic-texture.ts +36 -3
  150. package/src/dynamic-texture/texture-binding-source.ts +94 -0
  151. package/src/dynamic-texture/texture-data.ts +12 -4
  152. package/src/dynamic-texture/video-texture.ts +334 -0
  153. package/src/geometries/cube-geometry.ts +24 -2
  154. package/src/geometries/plane-geometry.ts +10 -0
  155. package/src/geometry/geometry-utils.ts +209 -4
  156. package/src/geometry/geometry.ts +113 -36
  157. package/src/geometry/gpu-geometry.ts +61 -41
  158. package/src/index.ts +50 -14
  159. package/src/material/material-factory.ts +5 -1
  160. package/src/material/material.ts +123 -27
  161. package/src/model/model.ts +441 -102
  162. package/src/model/split-uniforms-and-bindings.ts +7 -3
  163. package/src/models/billboard-texture-model.ts +33 -12
  164. package/src/modules/picking/index-color-picking.ts +212 -0
  165. package/src/modules/picking/index-picking.ts +23 -6
  166. package/src/modules/picking/picking-manager.ts +141 -0
  167. package/src/modules/picking/picking-uniforms.ts +7 -4
  168. package/src/modules/picking/picking.ts +8 -0
  169. package/src/passes/get-fragment-shader.ts +4 -4
  170. package/src/passes/shader-pass-renderer.ts +691 -89
  171. package/src/passes/texture-transform-module.ts +52 -0
  172. package/src/shader-inputs.ts +65 -17
  173. package/src/utils/buffer-layout-helper.ts +2 -14
  174. package/src/utils/buffer-layout-order.ts +14 -24
  175. package/src/utils/shader-module-utils.ts +109 -3
  176. package/dist/geometry/gpu-table.d.ts +0 -1
  177. package/dist/geometry/gpu-table.d.ts.map +0 -1
  178. package/dist/geometry/gpu-table.js +0 -46
  179. package/dist/geometry/gpu-table.js.map +0 -1
  180. package/src/dynamic-texture/texture-data.ts.disabled +0 -296
  181. package/src/geometry/gpu-table.ts +0 -45
@@ -0,0 +1,79 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {log} from '@luma.gl/core';
6
+
7
+ /** Construction props shared by all animation clip controllers. */
8
+ export type AnimationClipControllerProps = {
9
+ /** Application-visible clip name. */
10
+ name?: string;
11
+ /** Start time in seconds relative to wall-clock playback time. */
12
+ startTime?: number;
13
+ /** Whether playback is active. */
14
+ playing?: boolean;
15
+ /** Playback speed multiplier. */
16
+ speed?: number;
17
+ };
18
+
19
+ /** Generic playback controller for one animation clip. */
20
+ export abstract class AnimationClipController {
21
+ /** Application-visible clip name. */
22
+ name: string;
23
+ /** Whether playback is currently enabled. */
24
+ playing: boolean = true;
25
+ /** Playback speed multiplier. */
26
+ speed: number = 1;
27
+ /** Start time in seconds relative to wall-clock playback time. */
28
+ startTime: number = 0;
29
+
30
+ constructor(props: AnimationClipControllerProps = {}) {
31
+ this.name = props.name || 'unnamed';
32
+ Object.assign(this, props);
33
+ }
34
+
35
+ /** Advances the clip to the supplied wall-clock time in milliseconds. */
36
+ setTime(timeMs: number): void {
37
+ if (!this.playing) {
38
+ return;
39
+ }
40
+
41
+ const absoluteTimeSeconds = timeMs / 1000;
42
+ const localTimeSeconds = (absoluteTimeSeconds - this.startTime) * this.speed;
43
+ this.applyTime(localTimeSeconds);
44
+ }
45
+
46
+ /** Applies the resolved local clip time in seconds. */
47
+ protected abstract applyTime(localTimeSeconds: number): void;
48
+ }
49
+
50
+ /** Generic manager for a set of time-driven animation clips. */
51
+ export class Animator<TClip extends AnimationClipController> {
52
+ /** Managed clip list. */
53
+ readonly clips: TClip[];
54
+ /** Compatibility alias for clip list. */
55
+ readonly animations: TClip[];
56
+
57
+ constructor(clips: TClip[]) {
58
+ this.clips = clips;
59
+ this.animations = clips;
60
+ }
61
+
62
+ /** @deprecated Use .setTime(). */
63
+ animate(timeMs: number): void {
64
+ log.warn(
65
+ `${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`
66
+ )();
67
+ this.setTime(timeMs);
68
+ }
69
+
70
+ /** Advances every clip to the supplied wall-clock time in milliseconds. */
71
+ setTime(timeMs: number): void {
72
+ this.clips.forEach(clip => clip.setTime(timeMs));
73
+ }
74
+
75
+ /** Returns the managed animation clips. */
76
+ getAnimations(): TClip[] {
77
+ return this.clips;
78
+ }
79
+ }
@@ -14,6 +14,20 @@ import {Stats, Stat} from '@probe.gl/stats';
14
14
  let statIdCounter = 0;
15
15
  const ANIMATION_LOOP_STATS = 'Animation Loop';
16
16
 
17
+ /** Experimental v10 callback shape for browser or custom animation frames. */
18
+ export type AnimationFrameCallback = (time: DOMHighResTimeStamp, animationFrame?: unknown) => void;
19
+
20
+ /** Experimental v10 work-in-progress animation frame source. */
21
+ export interface AnimationFrameProvider {
22
+ requestAnimationFrame(callback: AnimationFrameCallback): number;
23
+ cancelAnimationFrame(animationFrameId: number): void;
24
+ }
25
+
26
+ const defaultAnimationFrameProvider: AnimationFrameProvider = {
27
+ requestAnimationFrame: callback => requestAnimationFramePolyfill(callback),
28
+ cancelAnimationFrame: animationFrameId => cancelAnimationFramePolyfill(animationFrameId)
29
+ };
30
+
17
31
  /** AnimationLoop properties */
18
32
  export type AnimationLoopProps = {
19
33
  device: Device | Promise<Device>;
@@ -28,11 +42,15 @@ export type AnimationLoopProps = {
28
42
 
29
43
  // view parameters - TODO move to CanvasContext?
30
44
  autoResizeViewport?: boolean;
45
+ /** Experimental v10 work-in-progress frame source. */
46
+ animationFrameProvider?: AnimationFrameProvider;
31
47
  };
32
48
 
33
49
  export type MutableAnimationLoopProps = {
34
50
  // view parameters
35
51
  autoResizeViewport?: boolean;
52
+ /** Experimental v10 work-in-progress frame source. */
53
+ animationFrameProvider?: AnimationFrameProvider;
36
54
  };
37
55
 
38
56
  /** Convenient animation loop */
@@ -44,12 +62,16 @@ export class AnimationLoop {
44
62
  onInitialize: async () => null,
45
63
  onRender: () => {},
46
64
  onFinalize: () => {},
47
- onError: error => console.error(error), // eslint-disable-line no-console
65
+ onError: error => {
66
+ // biome-ignore lint/suspicious/noConsole: default fallback error reporting for app loops.
67
+ console.error(error);
68
+ },
48
69
 
49
70
  stats: undefined!,
50
71
 
51
72
  // view parameters
52
- autoResizeViewport: false
73
+ autoResizeViewport: false,
74
+ animationFrameProvider: defaultAnimationFrameProvider
53
75
  } as const satisfies Readonly<Required<AnimationLoopProps>>;
54
76
 
55
77
  device: Device | null = null;
@@ -96,7 +118,10 @@ export class AnimationLoop {
96
118
  this.cpuTime = this.stats.get('CPU Time');
97
119
  this.gpuTime = this.stats.get('GPU Time');
98
120
 
99
- this.setProps({autoResizeViewport: props.autoResizeViewport});
121
+ this.setProps({
122
+ autoResizeViewport: props.autoResizeViewport,
123
+ animationFrameProvider: props.animationFrameProvider
124
+ });
100
125
 
101
126
  // Bind methods
102
127
  this.start = this.start.bind(this);
@@ -139,6 +164,19 @@ export class AnimationLoop {
139
164
  if ('autoResizeViewport' in props) {
140
165
  this.props.autoResizeViewport = props.autoResizeViewport || false;
141
166
  }
167
+ if ('animationFrameProvider' in props) {
168
+ const animationFrameProvider = props.animationFrameProvider || defaultAnimationFrameProvider;
169
+ if (animationFrameProvider !== this.props.animationFrameProvider) {
170
+ const animationFrameWasScheduled = this._animationFrameId !== null;
171
+ if (animationFrameWasScheduled) {
172
+ this._cancelAnimationFrame();
173
+ }
174
+ this.props.animationFrameProvider = animationFrameProvider;
175
+ if (animationFrameWasScheduled) {
176
+ this._requestAnimationFrame();
177
+ }
178
+ }
179
+ }
142
180
  return this;
143
181
  }
144
182
 
@@ -205,7 +243,7 @@ export class AnimationLoop {
205
243
  }
206
244
 
207
245
  /** Explicitly draw a frame */
208
- redraw(time?: number): this {
246
+ redraw(time?: number, animationFrame: unknown | null = null): this {
209
247
  if (this.device?.isLost || this._error) {
210
248
  return this;
211
249
  }
@@ -213,6 +251,9 @@ export class AnimationLoop {
213
251
  this._beginFrameTimers(time);
214
252
 
215
253
  this._setupFrame();
254
+ if (this.animationProps) {
255
+ this.animationProps.animationFrame = animationFrame;
256
+ }
216
257
  this._updateAnimationProps();
217
258
 
218
259
  this._renderFrame(this._getAnimationProps());
@@ -298,13 +339,9 @@ export class AnimationLoop {
298
339
  return;
299
340
  }
300
341
 
301
- // VR display has a separate animation frame to sync with headset
302
- // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/
303
- // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame
304
- // if (this.display && this.display.requestAnimationFrame) {
305
- // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));
306
- // }
307
- this._animationFrameId = requestAnimationFramePolyfill(this._animationFrame.bind(this));
342
+ this._animationFrameId = this.props.animationFrameProvider.requestAnimationFrame(
343
+ this._animationFrame.bind(this)
344
+ );
308
345
  }
309
346
 
310
347
  _cancelAnimationFrame(): void {
@@ -312,21 +349,15 @@ export class AnimationLoop {
312
349
  return;
313
350
  }
314
351
 
315
- // VR display has a separate animation frame to sync with headset
316
- // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/
317
- // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame
318
- // if (this.display && this.display.cancelAnimationFramePolyfill) {
319
- // this.display.cancelAnimationFrame(this._animationFrameId);
320
- // }
321
- cancelAnimationFramePolyfill(this._animationFrameId);
352
+ this.props.animationFrameProvider.cancelAnimationFrame(this._animationFrameId);
322
353
  this._animationFrameId = null;
323
354
  }
324
355
 
325
- _animationFrame(time: number): void {
356
+ _animationFrame(time: number, animationFrame?: unknown): void {
326
357
  if (!this._running) {
327
358
  return;
328
359
  }
329
- this.redraw(time);
360
+ this.redraw(time, animationFrame ?? null);
330
361
  this._requestAnimationFrame();
331
362
  }
332
363
 
@@ -343,8 +374,10 @@ export class AnimationLoop {
343
374
  this.props.onRender(this._getAnimationProps());
344
375
  // end callback
345
376
 
346
- // Submit commands (necessary on WebGPU)
347
- this.device?.submit();
377
+ // Submit commands (necessary on WebGPU).
378
+ if (this.device) {
379
+ this.device.submit();
380
+ }
348
381
  }
349
382
 
350
383
  _clearNeedsRedraw(): void {
@@ -391,6 +424,7 @@ export class AnimationLoop {
391
424
  tock: 0,
392
425
 
393
426
  // Experimental
427
+ animationFrame: null,
394
428
  _mousePosition: null // Event props
395
429
  };
396
430
  }
@@ -29,5 +29,7 @@ export type AnimationProps = {
29
29
  timeline: Timeline | null;
30
30
 
31
31
  // Experimental
32
+ /** Experimental v10 work-in-progress frame payload from a custom animation frame provider. */
33
+ animationFrame: unknown | null;
32
34
  _mousePosition?: [number, number] | null; // [offsetX, offsetY],
33
35
  };
@@ -7,6 +7,7 @@ import {AnimationLoopTemplate} from './animation-loop-template';
7
7
  import {AnimationLoop, AnimationLoopProps} from './animation-loop';
8
8
  import type {AnimationProps} from './animation-props';
9
9
 
10
+ /** Props accepted while constructing an animation loop from a template. */
10
11
  export type MakeAnimationLoopProps = Omit<
11
12
  AnimationLoopProps,
12
13
  'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'
@@ -43,8 +44,11 @@ export function makeAnimationLoop(
43
44
  // Any async loading can be handled here
44
45
  return await renderLoop?.onInitialize(animationProps);
45
46
  } catch (error) {
47
+ // biome-ignore lint/suspicious/noConsole: fallback logging before rendering the in-canvas error banner.
46
48
  console.error(error);
49
+ renderLoop = null;
47
50
  setError(animationProps.animationLoop.device, error as Error);
51
+ animationProps.animationLoop.stop();
48
52
  return null;
49
53
  }
50
54
  },
@@ -11,6 +11,11 @@ export function setPathPrefix(prefix: string) {
11
11
  pathPrefix = prefix;
12
12
  }
13
13
 
14
+ /** @internal */
15
+ export function _resolveLoadFileUrl(url: string): string {
16
+ return isAbsoluteLoadFileUrl(url) ? url : pathPrefix + url;
17
+ }
18
+
14
19
  /**
15
20
  * Loads ImageBitmap asynchronously. Respects setPathPrefix.
16
21
  * image.crossOrigin can be set via opts.crossOrigin, default to 'anonymous'
@@ -21,10 +26,21 @@ export async function loadImageBitmap(
21
26
  opts?: {crossOrigin?: string} & ImageBitmapOptions
22
27
  ): Promise<ImageBitmap> {
23
28
  const image = new Image();
29
+ const resolvedUrl = _resolveLoadFileUrl(url);
24
30
  image.crossOrigin = opts?.crossOrigin || 'anonymous';
25
- image.src = url.startsWith('http') ? url : pathPrefix + url;
26
- await image.decode();
27
- return opts ? await createImageBitmap(image, opts) : await createImageBitmap(image);
31
+ image.src = resolvedUrl;
32
+
33
+ try {
34
+ await image.decode();
35
+ } catch (error) {
36
+ throw createImageBitmapLoadError('decode', resolvedUrl, error);
37
+ }
38
+
39
+ try {
40
+ return opts ? await createImageBitmap(image, opts) : await createImageBitmap(image);
41
+ } catch (error) {
42
+ throw createImageBitmapLoadError('create', resolvedUrl, error);
43
+ }
28
44
  }
29
45
 
30
46
  /**
@@ -40,12 +56,29 @@ export async function loadImage(
40
56
  return await new Promise((resolve, reject) => {
41
57
  try {
42
58
  const image = new Image();
59
+ const resolvedUrl = _resolveLoadFileUrl(url);
43
60
  image.onload = () => resolve(image);
44
- image.onerror = () => reject(new Error(`Could not load image ${url}.`));
61
+ image.onerror = () => reject(new Error(`Could not load image ${resolvedUrl}.`));
45
62
  image.crossOrigin = opts?.crossOrigin || 'anonymous';
46
- image.src = url.startsWith('http') ? url : pathPrefix + url;
63
+ image.src = resolvedUrl;
47
64
  } catch (error) {
48
65
  reject(error);
49
66
  }
50
67
  });
51
68
  }
69
+
70
+ function createImageBitmapLoadError(
71
+ phase: 'decode' | 'create',
72
+ resolvedUrl: string,
73
+ error: unknown
74
+ ): Error {
75
+ const reason = error instanceof Error ? error.message : String(error);
76
+ const message =
77
+ phase === 'decode'
78
+ ? `Could not decode source image "${resolvedUrl}": ${reason}`
79
+ : `Could not create ImageBitmap from decoded image "${resolvedUrl}": ${reason}`;
80
+ return new Error(message, {cause: error});
81
+ }
82
+ function isAbsoluteLoadFileUrl(url: string): boolean {
83
+ return url.startsWith('/') || /^[a-z][a-z\d+\-.]*:/i.test(url);
84
+ }
@@ -7,6 +7,9 @@ import {getPassthroughFS} from '@luma.gl/shadertools';
7
7
  import {Model} from '../model/model';
8
8
  import type {ModelProps} from '../model/model';
9
9
 
10
+ const GL_INTERLEAVED_ATTRIBS = 0x8c8c;
11
+ const GL_SEPARATE_ATTRIBS = 0x8c8d;
12
+
10
13
  /**
11
14
  * Properties for creating a {@link BufferTransform}
12
15
  * @note Only works under WebGL2.
@@ -14,6 +17,10 @@ import type {ModelProps} from '../model/model';
14
17
  export type BufferTransformProps = Omit<ModelProps, 'fs'> & {
15
18
  /** Optional fragment shader - normally not used in transforms */
16
19
  fs?: ModelProps['fs']; // override as optional
20
+ /** bufferMode when binding varyings
21
+ * https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
22
+ */
23
+ feedbackBufferMode?: 'interleaved' | 'separate';
17
24
  /** A list of named outputs corresponding to shader declarations (varyings in WebGL) */
18
25
  outputs?: string[];
19
26
  /** @deprecated Use run({outputBuffers}) instead - Map of output buffers that the shaders will write results of computations to */
@@ -31,6 +38,7 @@ export class BufferTransform {
31
38
 
32
39
  static defaultProps: Required<BufferTransformProps> = {
33
40
  ...Model.defaultProps,
41
+ feedbackBufferMode: 'separate',
34
42
  outputs: undefined!,
35
43
  feedbackBuffers: undefined!
36
44
  };
@@ -51,7 +59,10 @@ export class BufferTransform {
51
59
  fs: props.fs || getPassthroughFS(),
52
60
  topology: props.topology || 'point-list',
53
61
  varyings: props.outputs || props.varyings,
54
- ...props
62
+ ...props,
63
+ bufferMode:
64
+ props.bufferMode ||
65
+ (props.feedbackBufferMode === 'interleaved' ? GL_INTERLEAVED_ATTRIBS : GL_SEPARATE_ATTRIBS)
55
66
  });
56
67
 
57
68
  this.transformFeedback = this.device.createTransformFeedback({
@@ -61,8 +72,6 @@ export class BufferTransform {
61
72
  });
62
73
 
63
74
  this.model.setTransformFeedback(this.transformFeedback);
64
-
65
- Object.seal(this);
66
75
  }
67
76
 
68
77
  /** Destroy owned resources. */
@@ -81,7 +90,7 @@ export class BufferTransform {
81
90
  run(
82
91
  options?: RenderPassProps & {
83
92
  inputBuffers?: Record<string, Buffer>;
84
- outputBuffers?: Record<string, Buffer>;
93
+ outputBuffers?: Record<string, Buffer | BufferRange>;
85
94
  }
86
95
  ): void {
87
96
  if (options?.inputBuffers) {
@@ -90,7 +99,7 @@ export class BufferTransform {
90
99
  if (options?.outputBuffers) {
91
100
  this.transformFeedback.setBuffers(options.outputBuffers);
92
101
  }
93
- const renderPass = this.device.beginRenderPass(options);
102
+ const renderPass = this.device.beginRenderPass({discard: true, ...options});
94
103
  this.model.draw(renderPass);
95
104
  renderPass.end();
96
105
  }
@@ -7,6 +7,7 @@ import {
7
7
  type ComputePipelineProps,
8
8
  type Shader,
9
9
  type Binding,
10
+ type CommandEncoder,
10
11
  Device,
11
12
  Buffer,
12
13
  ComputePipeline,
@@ -17,10 +18,18 @@ import {
17
18
  log,
18
19
  dataTypeDecoder
19
20
  } from '@luma.gl/core';
20
- import {type ShaderModule, type PlatformInfo, ShaderAssembler} from '@luma.gl/shadertools';
21
+ import {
22
+ type ShaderModule,
23
+ type ShaderPlugin,
24
+ type PlatformInfo,
25
+ mergeShaderPluginModules,
26
+ resolveShaderPlugins,
27
+ ShaderAssembler
28
+ } from '@luma.gl/shadertools';
21
29
  import {type TypedArray, isNumericArray} from '@math.gl/types';
22
30
  import {ShaderInputs} from '../shader-inputs';
23
31
  import {
32
+ mergeShaderModules,
24
33
  mergeShaderModuleBindingsIntoLayout,
25
34
  shaderModuleHasUniforms
26
35
  } from '../utils/shader-module-utils';
@@ -33,13 +42,14 @@ const LOG_DRAW_TIMEOUT = 10000;
33
42
  export type ComputationProps = Omit<ComputePipelineProps, 'shader'> & {
34
43
  source?: string;
35
44
 
36
- /** shadertool shader modules (added to shader code) */
45
+ /** Shadertools shader modules added to shader code. */
37
46
  modules?: ShaderModule[];
38
- /** Shadertool module defines (configures shader code)*/
39
- defines?: Record<string, boolean>;
40
- // TODO - injections, hooks etc?
47
+ /** Shadertools boolean or numeric preprocessor defines that configure shader code. */
48
+ defines?: Record<string, boolean | number>;
49
+ /** Reusable shader assembly plugins resolved for WGSL compute assembly. */
50
+ plugins?: ShaderPlugin[];
41
51
 
42
- /** Shader inputs, used to generated uniform buffers and bindings */
52
+ /** Shader inputs, used to generate uniform buffers and bindings. */
43
53
  shaderInputs?: ShaderInputs;
44
54
 
45
55
  /** Bindings */
@@ -74,6 +84,7 @@ export class Computation {
74
84
  source: '',
75
85
  modules: [],
76
86
  defines: {},
87
+ plugins: [],
77
88
 
78
89
  bindings: undefined!,
79
90
  shaderInputs: undefined!,
@@ -129,20 +140,31 @@ export class Computation {
129
140
 
130
141
  Object.assign(this.userData, props.userData);
131
142
 
143
+ const platformInfo = getPlatformInfo(device);
144
+ const resolvedPlugins = resolveShaderPlugins(this.props.plugins, platformInfo.shaderLanguage);
145
+ if (
146
+ Object.keys(resolvedPlugins.vertexInputs).length > 0 ||
147
+ Object.keys(resolvedPlugins.varyings).length > 0
148
+ ) {
149
+ throw new Error('Computation does not support ShaderPlugin vertex inputs or varyings');
150
+ }
151
+
132
152
  // Setup shader module inputs
133
- const moduleMap = Object.fromEntries(
134
- this.props.modules?.map(module => [module.name, module]) || []
153
+ const shaderInputModules = mergeShaderPluginModules(
154
+ this.props.modules,
155
+ resolvedPlugins.modules
135
156
  );
157
+ const moduleMap = Object.fromEntries(shaderInputModules.map(module => [module.name, module]));
136
158
  // @ts-ignore TODO - fix up typing?
137
159
  this.shaderInputs = props.shaderInputs || new ShaderInputs(moduleMap);
160
+ if (props.shaderInputs && resolvedPlugins.modules.length > 0) {
161
+ this.shaderInputs.addModules(resolvedPlugins.modules);
162
+ }
138
163
  this.setShaderInputs(this.shaderInputs);
139
164
 
140
165
  // Setup shader assembler
141
- const platformInfo = getPlatformInfo(device);
142
-
143
- // Extract modules from shader inputs if not supplied
144
- const modules =
145
- (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
166
+ const modules = mergeShaderModules(this.props.modules, this.shaderInputs?.getModules());
167
+ const defines = {...resolvedPlugins.defines, ...this.props.defines};
146
168
 
147
169
  this.props.shaderLayout =
148
170
  mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
@@ -154,7 +176,9 @@ export class Computation {
154
176
  const {source, getUniforms} = this.props.shaderAssembler.assembleWGSLShader({
155
177
  platformInfo,
156
178
  ...this.props,
157
- modules
179
+ modules,
180
+ defines,
181
+ pluginInjections: resolvedPlugins.injections
158
182
  });
159
183
 
160
184
  this.source = source;
@@ -177,9 +201,6 @@ export class Computation {
177
201
  if (props.bindings) {
178
202
  this.setBindings(props.bindings);
179
203
  }
180
-
181
- // Catch any access to non-standard props
182
- Object.seal(this);
183
204
  }
184
205
 
185
206
  destroy(): void {
@@ -192,9 +213,13 @@ export class Computation {
192
213
 
193
214
  // Draw call
194
215
 
195
- predraw() {
216
+ /**
217
+ * Updates compute shader inputs before opening the compute pass that will
218
+ * consume them.
219
+ */
220
+ predraw(commandEncoder: CommandEncoder) {
196
221
  // Update uniform buffers if needed
197
- this.updateShaderInputs();
222
+ this.updateShaderInputs(commandEncoder);
198
223
  }
199
224
 
200
225
  dispatch(computePass: ComputePass, x: number, y?: number, z?: number): void {
@@ -271,8 +296,14 @@ export class Computation {
271
296
  }
272
297
  }
273
298
 
274
- updateShaderInputs(): void {
275
- this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
299
+ /**
300
+ * Flushes current shader-input values into the internal uniform store.
301
+ *
302
+ * @param commandEncoder - Optional encoder used to order uniform uploads with
303
+ * subsequent compute commands.
304
+ */
305
+ updateShaderInputs(commandEncoder?: CommandEncoder): void {
306
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(), commandEncoder);
276
307
  }
277
308
 
278
309
  /**
@@ -369,6 +400,7 @@ export function getPlatformInfo(device: Device): PlatformInfo {
369
400
  shaderLanguage: device.info.shadingLanguage,
370
401
  shaderLanguageVersion: device.info.shadingLanguageVersion as 100 | 300,
371
402
  gpu: device.info.gpu,
403
+ limits: device.limits as unknown as Record<string, number | undefined>,
372
404
  // HACK - we pretend that the DeviceFeatures is a Set, it has a similar API
373
405
  features: device.features as unknown as Set<DeviceFeature>
374
406
  };
@@ -75,6 +75,13 @@ export class SwapFramebuffers extends Swap<Framebuffer> {
75
75
  const next = device.createFramebuffer({...props, colorAttachments});
76
76
 
77
77
  super({current, next});
78
+
79
+ for (const [index, colorAttachment] of (props.colorAttachments || []).entries()) {
80
+ if (typeof colorAttachment === 'string') {
81
+ current.attachResource(current.colorAttachments[index].texture);
82
+ next.attachResource(next.colorAttachments[index].texture);
83
+ }
84
+ }
78
85
  }
79
86
 
80
87
  /**
@@ -89,15 +96,27 @@ export class SwapFramebuffers extends Swap<Framebuffer> {
89
96
  const {current, next} = this;
90
97
 
91
98
  this.current = current.clone(size);
99
+ attachFramebufferAttachments(this.current);
92
100
  current.destroy();
93
101
 
94
102
  this.next = next.clone(size);
103
+ attachFramebufferAttachments(this.next);
95
104
  next.destroy();
96
105
 
97
106
  return true;
98
107
  }
99
108
  }
100
109
 
110
+ /** Framebuffer.clone() creates fresh attachments that the replacement framebuffer must own. */
111
+ function attachFramebufferAttachments(framebuffer: Framebuffer): void {
112
+ for (const colorAttachment of framebuffer.colorAttachments) {
113
+ framebuffer.attachResource(colorAttachment.texture);
114
+ }
115
+ if (framebuffer.depthStencilAttachment) {
116
+ framebuffer.attachResource(framebuffer.depthStencilAttachment.texture);
117
+ }
118
+ }
119
+
101
120
  /** Helper for managing double-buffered GPU buffers */
102
121
  export class SwapBuffers extends Swap<Buffer> {
103
122
  constructor(device: Device, props: BufferProps) {