@luma.gl/engine 9.0.0-alpha.4 → 9.0.0-alpha.6

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.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  export type { AnimationProps } from './lib/animation-props';
2
+ export type { AnimationLoopProps } from './lib/animation-loop';
3
+ export { AnimationLoop } from './lib/animation-loop';
2
4
  export { RenderLoop } from './lib/render-loop';
3
5
  export type { ModelProps } from './lib/model';
4
6
  export { default as Model } from './lib/model';
5
- export type { AnimationLoopProps } from './lib/animation-loop';
6
- export { default as AnimationLoop } from './lib/animation-loop';
7
+ export { PipelineFactory } from './lib/pipeline-factory';
8
+ export { Timeline } from './animation/timeline';
9
+ export { KeyFrames } from './animation/key-frames';
7
10
  export { default as Geometry } from './geometry/geometry';
8
11
  export type { ConeGeometryProps } from './geometries/cone-geometry';
9
12
  export { ConeGeometry } from './geometries/cone-geometry';
@@ -19,6 +22,4 @@ export type { SphereGeometryProps } from './geometries/sphere-geometry';
19
22
  export { SphereGeometry } from './geometries/sphere-geometry';
20
23
  export type { TruncatedConeGeometryProps } from './geometries/truncated-cone-geometry';
21
24
  export { TruncatedConeGeometry } from './geometries/truncated-cone-geometry';
22
- export { Timeline } from './animation/timeline';
23
- export { KeyFrames } from './animation/key-frames';
24
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,OAAO,IAAI,KAAK,EAAC,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAC,OAA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Y,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,OAAO,IAAI,KAAK,EAAC,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AAMjD,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAGxD,YAAY,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,YAAY,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,YAAY,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAChE,YAAY,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,YAAY,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,YAAY,EAAC,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAC5D,YAAY,EAAC,0BAA0B,EAAC,MAAM,sCAAsC,CAAC;AACrF,OAAO,EAAC,qBAAqB,EAAC,MAAM,sCAAsC,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
+ export { AnimationLoop } from './lib/animation-loop';
1
2
  export { RenderLoop } from './lib/render-loop';
2
3
  export { default as Model } from './lib/model';
3
- export { default as AnimationLoop } from './lib/animation-loop';
4
+ export { PipelineFactory } from './lib/pipeline-factory';
5
+ export { Timeline } from './animation/timeline';
6
+ export { KeyFrames } from './animation/key-frames';
4
7
  export { default as Geometry } from './geometry/geometry';
5
8
  export { ConeGeometry } from './geometries/cone-geometry';
6
9
  export { CubeGeometry } from './geometries/cube-geometry';
@@ -9,6 +12,4 @@ export { IcoSphereGeometry } from './geometries/ico-sphere-geometry';
9
12
  export { PlaneGeometry } from './geometries/plane-geometry';
10
13
  export { SphereGeometry } from './geometries/sphere-geometry';
11
14
  export { TruncatedConeGeometry } from './geometries/truncated-cone-geometry';
12
- export { Timeline } from './animation/timeline';
13
- export { KeyFrames } from './animation/key-frames';
14
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["RenderLoop","default","Model","AnimationLoop","Geometry","ConeGeometry","CubeGeometry","CylinderGeometry","IcoSphereGeometry","PlaneGeometry","SphereGeometry","TruncatedConeGeometry","Timeline","KeyFrames"],"mappings":"AAEA,SAAQA,UAAR,QAAyB,mBAAzB;AAEA,SAAQC,OAAO,IAAIC,KAAnB,QAA+B,aAA/B;AAEA,SAAQD,OAAO,IAAIE,aAAnB,QAAuC,sBAAvC;AAMA,SAAQF,OAAO,IAAIG,QAAnB,QAAkC,qBAAlC;AAIA,SAAQC,YAAR,QAA2B,4BAA3B;AAEA,SAAQC,YAAR,QAA2B,4BAA3B;AAEA,SAAQC,gBAAR,QAA+B,gCAA/B;AAEA,SAAQC,iBAAR,QAAgC,kCAAhC;AAEA,SAAQC,aAAR,QAA4B,6BAA5B;AAEA,SAAQC,cAAR,QAA6B,8BAA7B;AAEA,SAAQC,qBAAR,QAAoC,sCAApC;AAGA,SAAQC,QAAR,QAAuB,sBAAvB;AACA,SAAQC,SAAR,QAAwB,wBAAxB","sourcesContent":["// luma.gl Engine API\nexport type {AnimationProps} from './lib/animation-props';\nexport {RenderLoop} from './lib/render-loop';\nexport type {ModelProps} from './lib/model';\nexport {default as Model} from './lib/model';\nexport type {AnimationLoopProps} from './lib/animation-loop';\nexport {default as AnimationLoop} from './lib/animation-loop';\n\n// Utils\n// export {default as ClipSpace} from './lib/clip-space';\n\n// Geometries\nexport {default as Geometry} from './geometry/geometry';\n\n// Primitives\nexport type {ConeGeometryProps} from './geometries/cone-geometry';\nexport {ConeGeometry} from './geometries/cone-geometry';\nexport type {CubeGeometryProps} from './geometries/cube-geometry';\nexport {CubeGeometry} from './geometries/cube-geometry';\nexport type {CylinderGeometryProps} from './geometries/cylinder-geometry';\nexport {CylinderGeometry} from './geometries/cylinder-geometry';\nexport type {IcoSphereGeometryProps} from './geometries/ico-sphere-geometry';\nexport {IcoSphereGeometry} from './geometries/ico-sphere-geometry';\nexport type {PlaneGeometryProps} from './geometries/plane-geometry';\nexport {PlaneGeometry} from './geometries/plane-geometry';\nexport type {SphereGeometryProps} from './geometries/sphere-geometry';\nexport {SphereGeometry} from './geometries/sphere-geometry';\nexport type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';\nexport {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';\n\n// Animation\nexport {Timeline} from './animation/timeline';\nexport {KeyFrames} from './animation/key-frames';\n\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["AnimationLoop","RenderLoop","default","Model","PipelineFactory","Timeline","KeyFrames","Geometry","ConeGeometry","CubeGeometry","CylinderGeometry","IcoSphereGeometry","PlaneGeometry","SphereGeometry","TruncatedConeGeometry"],"mappings":"AAGA,SAAQA,aAAR,QAA4B,sBAA5B;AACA,SAAQC,UAAR,QAAyB,mBAAzB;AAEA,SAAQC,OAAO,IAAIC,KAAnB,QAA+B,aAA/B;AAEA,SAAQC,eAAR,QAA8B,wBAA9B;AAGA,SAAQC,QAAR,QAAuB,sBAAvB;AACA,SAAQC,SAAR,QAAwB,wBAAxB;AAMA,SAAQJ,OAAO,IAAIK,QAAnB,QAAkC,qBAAlC;AAIA,SAAQC,YAAR,QAA2B,4BAA3B;AAEA,SAAQC,YAAR,QAA2B,4BAA3B;AAEA,SAAQC,gBAAR,QAA+B,gCAA/B;AAEA,SAAQC,iBAAR,QAAgC,kCAAhC;AAEA,SAAQC,aAAR,QAA4B,6BAA5B;AAEA,SAAQC,cAAR,QAA6B,8BAA7B;AAEA,SAAQC,qBAAR,QAAoC,sCAApC","sourcesContent":["// luma.gl Engine API\nexport type {AnimationProps} from './lib/animation-props';\nexport type {AnimationLoopProps} from './lib/animation-loop';\nexport {AnimationLoop} from './lib/animation-loop';\nexport {RenderLoop} from './lib/render-loop';\nexport type {ModelProps} from './lib/model';\nexport {default as Model} from './lib/model';\n\nexport {PipelineFactory} from './lib/pipeline-factory';\n\n// Animation\nexport {Timeline} from './animation/timeline';\nexport {KeyFrames} from './animation/key-frames';\n\n// Utils\n// export {default as ClipSpace} from './lib/clip-space';\n\n// Geometries\nexport {default as Geometry} from './geometry/geometry';\n\n// Primitives\nexport type {ConeGeometryProps} from './geometries/cone-geometry';\nexport {ConeGeometry} from './geometries/cone-geometry';\nexport type {CubeGeometryProps} from './geometries/cube-geometry';\nexport {CubeGeometry} from './geometries/cube-geometry';\nexport type {CylinderGeometryProps} from './geometries/cylinder-geometry';\nexport {CylinderGeometry} from './geometries/cylinder-geometry';\nexport type {IcoSphereGeometryProps} from './geometries/ico-sphere-geometry';\nexport {IcoSphereGeometry} from './geometries/ico-sphere-geometry';\nexport type {PlaneGeometryProps} from './geometries/plane-geometry';\nexport {PlaneGeometry} from './geometries/plane-geometry';\nexport type {SphereGeometryProps} from './geometries/sphere-geometry';\nexport {SphereGeometry} from './geometries/sphere-geometry';\nexport type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';\nexport {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';\n\n"],"file":"index.js"}
@@ -19,7 +19,7 @@ export declare type AnimationLoopProps = {
19
19
  useDevicePixels?: number | boolean;
20
20
  };
21
21
  /** Convenient animation loop */
22
- export default class AnimationLoop {
22
+ export declare class AnimationLoop {
23
23
  device: Device;
24
24
  canvas: HTMLCanvasElement;
25
25
  props: Required<AnimationLoopProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,MAAM,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAS5C,+BAA+B;AAC/B,oBAAY,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACpD,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;IAElC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IAGd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC,CAAC;AAqBF,gCAAgC;AAChC,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,iBAAiB,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IAAI,OAAO,CAAC,aAAa,CAAC;IAWjC,SAAS;IAMf,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,YAAY,CAAC,cAAc,EAAE,cAAc,GAAG,EAAE,GAAG,IAAI;IAIvD,QAAQ,CAAC,cAAc,EAAE,cAAc;IAIvC,UAAU,CAAC,cAAc,EAAE,cAAc;IAMzC,WAAW;IAcX,WAAW,CAAC,OAAO,KAAA;IAcnB,sBAAsB;IActB,qBAAqB;IAerB,eAAe;IAUf,YAAY,CAAC,KAAK,EAAE,cAAc;IAYlC,iBAAiB;IAIjB,WAAW;IAMX,uBAAuB;IA6BvB,mBAAmB;IA+BnB,yFAAyF;IACnF,aAAa;IAQnB,cAAc;IAoBd,iBAAiB;;;;;IAmBjB,6BAA6B;IAC7B,eAAe;IAQf;;;OAGG;IACH,0BAA0B;IAM1B,YAAY;IAuBZ,UAAU;IAWV,mBAAmB;IAOnB,YAAY,CAAC,CAAC,KAAA;IAGd,aAAa,CAAC,CAAC,KAAA;CAGhB"}
@@ -19,7 +19,7 @@ const DEFAULT_ANIMATION_LOOP_PROPS = {
19
19
  autoResizeViewport: true,
20
20
  autoResizeDrawingBuffer: true
21
21
  };
22
- export default class AnimationLoop {
22
+ export class AnimationLoop {
23
23
  constructor(props = {}) {
24
24
  _defineProperty(this, "device", void 0);
25
25
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","undefined","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","debug","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","animationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","display","animationLoop","_animationFrameId","_animationFrame","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","getPixelSize","clientHeight","clientWidth","viewport","drawingBufferWidth","drawingBufferHeight","resize","timeEnd","timeStart","addEventListener","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBAAR,EAA+BC,oBAA/B,QAA0D,cAA1D;AAIA,SAAQC,SAAR,QAAwB,eAAxB;AAEA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAwBA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAyCT,IAAI,CAACU,YAAL,CAAkBD,KAAlB,CADQ;AAEjEE,EAAAA,SAAS,EAAEC,SAFsD;AAGjEC,EAAAA,YAAY,EAAE,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJ+C;AAKjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAL6C;AAMjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAN6C;AAQjEE,EAAAA,MAAM,EAAEP,SARyD;AASjEQ,EAAAA,WAAW,EAAE,EAToD;AAUjEC,EAAAA,KAAK,EAAE,KAV0D;AAWjEC,EAAAA,KAAK,EAAEtB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WiB,uBAAf,EAAwC;AACtC,WAAKP,MAAL,CAAY8D,aAAZ,CAA0BoC,MAA1B,CAAiC;AAAC7F,QAAAA,eAAe,EAAE,KAAKf,KAAL,CAAWe;AAA7B,OAAjC;AACD;AACF;;AAEDiC,EAAAA,YAAY,GAAG;AACb,SAAKzB,SAAL,CAAesF,OAAf;AACA,SAAKtF,SAAL,CAAeuF,SAAf;AAmBD;;AAEDvD,EAAAA,UAAU,GAAG;AACX,SAAKlC,OAAL,CAAawF,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKD,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYgD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKnF,YAA/C;AACA,WAAKmC,MAAL,CAAYgD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKlF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACoF,CAAD,EAAI;AACd,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,CAAC6B,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAArC;AACD;;AACDrF,EAAAA,aAAa,CAACmF,CAAD,EAAI;AACf,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,IAArC;AACD;;AAhegC","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: undefined,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: undefined,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport default class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement; // | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n // _gpuTimeQuery: Query | null = null;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n // TODO - move to CanvasContext\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n /** Starts a render loop if not already running */\n async start() {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n try {\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._createDevice();\n this._initialize();\n\n // Note: onIntialize can return a promise (e.g. in case app needs to load resources)\n await this.onInitialize(this.animationProps);\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error('Unknown error')\n this.props.onError(error);\n // this._running = false; // TODO\n throw error;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.device.isLost) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n // call callback\n this.onFinalize(this.animationProps);\n\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n return this.canvas.toDataURL();\n }\n\n onCreateDevice(deviceProps: DeviceProps): Promise<Device> {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n // this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n this.animationProps = {\n animationLoop: this,\n device: this.device,\n canvas: this.device.canvasContext.canvas,\n timeline: this.timeline,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Placeholders\n width: 1,\n height: 1,\n aspect: 1,\n\n // Animation props\n time: 0,\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n // Experimental\n _mousePosition: null // Event props\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n async _createDevice() {\n const deviceProps = {...this.props, ...this.props.deviceProps};\n this.device = await this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.canvas = this.device.canvasContext.canvas;\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device.canvasContext.getPixelSize();\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device.canvasContext.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
1
+ {"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","undefined","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","debug","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","animationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","display","animationLoop","_animationFrameId","_animationFrame","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","getPixelSize","clientHeight","clientWidth","viewport","drawingBufferWidth","drawingBufferHeight","resize","timeEnd","timeStart","addEventListener","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBAAR,EAA+BC,oBAA/B,QAA0D,cAA1D;AAIA,SAAQC,SAAR,QAAwB,eAAxB;AAEA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAwBA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAyCT,IAAI,CAACU,YAAL,CAAkBD,KAAlB,CADQ;AAEjEE,EAAAA,SAAS,EAAEC,SAFsD;AAGjEC,EAAAA,YAAY,EAAE,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJ+C;AAKjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAL6C;AAMjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAN6C;AAQjEE,EAAAA,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AAKhG,MAAL,CAAYU,EAAZ,CAAeuF,mBAAhF;AACD;AACF;;AAMDzC,EAAAA,0BAA0B,GAAG;AAC3B,QAAI,KAAKlE,KAAL,CAAWiB,uBAAf,EAAwC;AACtC,WAAKP,MAAL,CAAY8D,aAAZ,CAA0BoC,MAA1B,CAAiC;AAAC7F,QAAAA,eAAe,EAAE,KAAKf,KAAL,CAAWe;AAA7B,OAAjC;AACD;AACF;;AAEDiC,EAAAA,YAAY,GAAG;AACb,SAAKzB,SAAL,CAAesF,OAAf;AACA,SAAKtF,SAAL,CAAeuF,SAAf;AAmBD;;AAEDvD,EAAAA,UAAU,GAAG;AACX,SAAKlC,OAAL,CAAawF,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKD,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYgD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKnF,YAA/C;AACA,WAAKmC,MAAL,CAAYgD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKlF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACoF,CAAD,EAAI;AACd,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,CAAC6B,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAArC;AACD;;AACDrF,EAAAA,aAAa,CAACmF,CAAD,EAAI;AACf,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,IAArC;AACD;;AAhewB","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: undefined,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: undefined,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement; // | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n // _gpuTimeQuery: Query | null = null;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n // TODO - move to CanvasContext\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n /** Starts a render loop if not already running */\n async start() {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n try {\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._createDevice();\n this._initialize();\n\n // Note: onIntialize can return a promise (e.g. in case app needs to load resources)\n await this.onInitialize(this.animationProps);\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error('Unknown error')\n this.props.onError(error);\n // this._running = false; // TODO\n throw error;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.device.isLost) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n // call callback\n this.onFinalize(this.animationProps);\n\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n return this.canvas.toDataURL();\n }\n\n onCreateDevice(deviceProps: DeviceProps): Promise<Device> {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n // this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n this.animationProps = {\n animationLoop: this,\n device: this.device,\n canvas: this.device.canvasContext.canvas,\n timeline: this.timeline,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Placeholders\n width: 1,\n height: 1,\n aspect: 1,\n\n // Animation props\n time: 0,\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n // Experimental\n _mousePosition: null // Event props\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n async _createDevice() {\n const deviceProps = {...this.props, ...this.props.deviceProps};\n this.device = await this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.canvas = this.device.canvasContext.canvas;\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device.canvasContext.getPixelSize();\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device.canvasContext.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="offscreencanvas" />
2
2
  import { Device } from '@luma.gl/api';
3
3
  import { Timeline } from '../animation/timeline';
4
- import type AnimationLoop from './animation-loop';
4
+ import type { AnimationLoop } from './animation-loop';
5
5
  /** Properties passed to every render frame */
6
6
  export declare type AnimationProps = {
7
7
  device: Device;
@@ -1 +1 @@
1
- {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/lib/animation-props.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAElD,+CAA+C;AAC/C,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,QAAQ,CAAC;IAGnB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC"}
1
+ {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/lib/animation-props.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,+CAA+C;AAC/C,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,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AErF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAyC7C,OAAO,IAAI,IAAI;IAIf,IAAI,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI;IASnC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAmBjC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMtD,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMrC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAMvD,uBAAuB;IACvB,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAMpD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMhD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAWvC"}
package/dist/lib/model.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { RenderPipeline } from '@luma.gl/api';
3
3
  import { getAttributeBuffersFromGeometry, getIndexBufferFromGeometry } from './model-utils';
4
- import PipelineFactory from './pipeline-factory';
4
+ import { PipelineFactory } from './pipeline-factory';
5
5
  const DEFAULT_MODEL_PROPS = { ...RenderPipeline._DEFAULT_PROPS,
6
6
  vs: undefined,
7
7
  fs: undefined,
@@ -53,7 +53,7 @@ export default class Model {
53
53
  }
54
54
 
55
55
  const {
56
- renderPipeline,
56
+ pipeline,
57
57
  getUniforms
58
58
  } = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({ ...this.props,
59
59
  vs: this.vs,
@@ -62,7 +62,7 @@ export default class Model {
62
62
  parameters: props.parameters,
63
63
  layout: props.layout
64
64
  });
65
- this.pipeline = renderPipeline;
65
+ this.pipeline = pipeline;
66
66
  this._getModuleUniforms = getUniforms;
67
67
 
68
68
  if (this.props.geometry) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/model.ts"],"names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","undefined","fs","id","handle","userData","modules","moduleSettings","geometry","Model","constructor","device","props","getShaderSource","vertexCount","topology","renderPipeline","getUniforms","getDefaultPipelineFactory","createRenderPipeline","parameters","layout","pipeline","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","draw","renderPass","instanceCount","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","Object","assign","geometryBuffers","indexBuffer","shader","info","type","wgsl","Error","glsl"],"mappings":";AACA,SAAQA,cAAR,QAA2C,cAA3C;AAGA,SAAQC,+BAAR,EAAyCC,0BAAzC,QAA0E,eAA1E;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AAWA,MAAMC,mBAAyC,GAAG,EAChD,GAAGJ,cAAc,CAACK,cAD8B;AAEhDC,EAAAA,EAAE,EAAEC,SAF4C;AAGhDC,EAAAA,EAAE,EAAED,SAH4C;AAIhDE,EAAAA,EAAE,EAAE,SAJ4C;AAKhDC,EAAAA,MAAM,EAAEH,SALwC;AAMhDI,EAAAA,QAAQ,EAAE,EANsC;AAOhDC,EAAAA,OAAO,EAAE,EAPuC;AAQhDC,EAAAA,cAAc,EAAE,EARgC;AAShDC,EAAAA,QAAQ,EAAEP;AATsC,CAAlD;AAaA,eAAe,MAAMQ,KAAN,CAAY;AAYzBC,EAAAA,WAAW,CAACC,MAAD,EAAiBC,KAAjB,EAAoC;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAC7C,SAAKA,KAAL,GAAa,EAAC,GAAGd,mBAAJ;AAAyB,SAAGc;AAA5B,KAAb;AACAA,IAAAA,KAAK,GAAG,KAAKA,KAAb;AACA,SAAKT,EAAL,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AAd;AACD;;AACD,YAAM,IAAID,KAAJ,CAAU,qCAAV,CAAN;AAXJ;AAaD","sourcesContent":["import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding} from '@luma.gl/api';\nimport {RenderPipeline, Shader, cast} from '@luma.gl/api';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport type Geometry from '../geometry/geometry';\nimport {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';\nimport PipelineFactory from './pipeline-factory';\n\nexport type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {\n // Model also accepts a string\n vs?: {glsl?: string; wgsl?: string} | string;\n fs?: {glsl?: string; wgsl?: string} | string;\n modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline._DEFAULT_PROPS,\n vs: undefined,\n fs: undefined,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n modules: [],\n moduleSettings: {},\n geometry: undefined\n};\n\n/** v9 API */\nexport default class Model {\n readonly device: Device;\n readonly pipeline: RenderPipeline;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | undefined;\n readonly topology: string;\n readonly vertexCount;\n props: Required<ModelProps>;\n\n private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;\n\n constructor(device: Device, props: ModelProps) {\n this.props = {...DEFAULT_MODEL_PROPS, ...props};\n props = this.props;\n this.id = props.id;\n this.device = device;\n\n // Create the pipeline\n this.vs = getShaderSource(this.device, props.vs);\n if (props.fs) {\n this.fs = getShaderSource(this.device, props.fs);\n }\n\n this.vertexCount = this.props.vertexCount;\n this.topology = this.props.topology;\n\n if (this.props.geometry) {\n this.vertexCount = this.props.geometry.vertexCount;\n this.topology = this.props.geometry.topology;\n }\n\n const {renderPipeline, getUniforms} = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({\n ...this.props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n parameters: props.parameters,\n // Geometry in the vertex shader!\n // @ts-expect-error\n layout: props.layout\n });\n\n this.pipeline = renderPipeline;\n this._getModuleUniforms = getUniforms;\n\n if (this.props.geometry) {\n this._setGeometry(this.props.geometry);\n }\n this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms\n this.setProps(this.props);\n }\n\n destroy(): void {\n this.pipeline.destroy();\n }\n\n draw(renderPass?: RenderPass): this {\n this.pipeline.draw({\n renderPass,\n vertexCount: this.vertexCount,\n instanceCount: this.props.instanceCount\n });\n return this;\n }\n\n setProps(props: ModelProps): this {\n if (props.indices) {\n this.setIndexBuffer(props.indices);\n }\n if (props.attributes) {\n this.setAttributes(props.attributes);\n }\n if (props.bindings) {\n this.setBindings(props.bindings);\n }\n if (props.uniforms) {\n this.setUniforms(props.uniforms);\n }\n if (props.moduleSettings) {\n this.updateModuleSettings(props.moduleSettings);\n }\n return this;\n }\n\n updateModuleSettings(props: Record<string, any>): this {\n const uniforms = this._getModuleUniforms(props);\n this.setUniforms(uniforms);\n return this;\n }\n\n setIndexBuffer(indices: Buffer): this {\n this.pipeline.setIndexBuffer(indices);\n // this._indices = indices;\n return this;\n }\n\n setAttributes(attributes: Record<string, Buffer>): this {\n this.pipeline.setAttributes(attributes);\n Object.assign(this.props.attributes, attributes);\n return this;\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): this {\n this.pipeline.setBindings(bindings);\n Object.assign(this.props.bindings, bindings);\n return this;\n }\n\n setUniforms(uniforms: Record<string, any>): this {\n this.pipeline.setUniforms(uniforms);\n Object.assign(this.props.uniforms, uniforms);\n return this;\n }\n\n _setGeometry(geometry: Geometry): void {\n // this._deleteGeometryBuffers();\n\n const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);\n this.setAttributes(geometryBuffers);\n\n const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);\n if (indexBuffer) {\n this.setIndexBuffer(indexBuffer);\n }\n }\n}\n\n/** Create a shader from the different overloads */\nfunction getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {\n // TODO - detect WGSL/GLSL and throw an error if not supported\n if (typeof shader === 'string') {\n return shader;\n }\n\n switch (device.info.type) {\n case 'webgpu':\n if (shader?.wgsl) {\n return shader.wgsl;\n }\n throw new Error('WebGPU does not support GLSL shaders');\n\n default:\n if (shader?.glsl) {\n return shader.glsl;\n }\n throw new Error('WebGL does not support WGSL shaders');\n }\n}\n"],"file":"model.js"}
1
+ {"version":3,"sources":["../../src/lib/model.ts"],"names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","undefined","fs","id","handle","userData","modules","moduleSettings","geometry","Model","constructor","device","props","getShaderSource","vertexCount","topology","pipeline","getUniforms","getDefaultPipelineFactory","createRenderPipeline","parameters","layout","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","draw","renderPass","instanceCount","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","Object","assign","geometryBuffers","indexBuffer","shader","info","type","wgsl","Error","glsl"],"mappings":";AAGA,SAAQA,cAAR,QAA2C,cAA3C;AAGA,SAAQC,+BAAR,EAAyCC,0BAAzC,QAA0E,eAA1E;AACA,SAAQC,eAAR,QAA8B,oBAA9B;AAWA,MAAMC,mBAAyC,GAAG,EAChD,GAAGJ,cAAc,CAACK,cAD8B;AAEhDC,EAAAA,EAAE,EAAEC,SAF4C;AAGhDC,EAAAA,EAAE,EAAED,SAH4C;AAIhDE,EAAAA,EAAE,EAAE,SAJ4C;AAKhDC,EAAAA,MAAM,EAAEH,SALwC;AAMhDI,EAAAA,QAAQ,EAAE,EANsC;AAOhDC,EAAAA,OAAO,EAAE,EAPuC;AAQhDC,EAAAA,cAAc,EAAE,EARgC;AAShDC,EAAAA,QAAQ,EAAEP;AATsC,CAAlD;AAaA,eAAe,MAAMQ,KAAN,CAAY;AAYzBC,EAAAA,WAAW,CAACC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AIA,MAAJ,eAAIA,MAAM,CAAEG,IAAZ,EAAkB;AAChB,eAAOH,MAAM,CAACG,IAAd;AACD;;AACD,YAAM,IAAIC,KAAJ,CAAU,sCAAV,CAAN;;AAEF;AACE,UAAIJ,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEK,IAAZ,EAAkB;AAChB,eAAOL,MAAM,CAACK,IAAd;AACD;;AACD,YAAM,IAAID,KAAJ,CAAU,qCAAV,CAAN;AAXJ;AAaD","sourcesContent":["// luma.gl, MIT license\n\nimport type {Device, Buffer, RenderPipelineProps, RenderPass, Binding} from '@luma.gl/api';\nimport {RenderPipeline, Shader, cast} from '@luma.gl/api';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport type Geometry from '../geometry/geometry';\nimport {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';\nimport {PipelineFactory} from './pipeline-factory';\n\nexport type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {\n // Model also accepts a string\n vs?: {glsl?: string; wgsl?: string} | string;\n fs?: {glsl?: string; wgsl?: string} | string;\n modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline._DEFAULT_PROPS,\n vs: undefined,\n fs: undefined,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n modules: [],\n moduleSettings: {},\n geometry: undefined\n};\n\n/** v9 API */\nexport default class Model {\n readonly device: Device;\n readonly pipeline: RenderPipeline;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | undefined;\n readonly topology: string;\n readonly vertexCount;\n props: Required<ModelProps>;\n\n private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;\n\n constructor(device: Device, props: ModelProps) {\n this.props = {...DEFAULT_MODEL_PROPS, ...props};\n props = this.props;\n this.id = props.id;\n this.device = device;\n\n // Create the pipeline\n this.vs = getShaderSource(this.device, props.vs);\n if (props.fs) {\n this.fs = getShaderSource(this.device, props.fs);\n }\n\n this.vertexCount = this.props.vertexCount;\n this.topology = this.props.topology;\n\n if (this.props.geometry) {\n this.vertexCount = this.props.geometry.vertexCount;\n this.topology = this.props.geometry.topology;\n }\n\n const {pipeline, getUniforms} = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({\n ...this.props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n parameters: props.parameters,\n // Geometry in the vertex shader!\n // @ts-expect-error\n layout: props.layout\n });\n\n this.pipeline = pipeline;\n this._getModuleUniforms = getUniforms;\n\n if (this.props.geometry) {\n this._setGeometry(this.props.geometry);\n }\n this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms\n this.setProps(this.props);\n }\n\n destroy(): void {\n this.pipeline.destroy();\n }\n\n draw(renderPass?: RenderPass): this {\n this.pipeline.draw({\n renderPass,\n vertexCount: this.vertexCount,\n instanceCount: this.props.instanceCount\n });\n return this;\n }\n\n setProps(props: ModelProps): this {\n if (props.indices) {\n this.setIndexBuffer(props.indices);\n }\n if (props.attributes) {\n this.setAttributes(props.attributes);\n }\n if (props.bindings) {\n this.setBindings(props.bindings);\n }\n if (props.uniforms) {\n this.setUniforms(props.uniforms);\n }\n if (props.moduleSettings) {\n this.updateModuleSettings(props.moduleSettings);\n }\n return this;\n }\n\n updateModuleSettings(props: Record<string, any>): this {\n const uniforms = this._getModuleUniforms(props);\n this.setUniforms(uniforms);\n return this;\n }\n\n setIndexBuffer(indices: Buffer): this {\n this.pipeline.setIndexBuffer(indices);\n // this._indices = indices;\n return this;\n }\n\n setAttributes(attributes: Record<string, Buffer>): this {\n this.pipeline.setAttributes(attributes);\n Object.assign(this.props.attributes, attributes);\n return this;\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): this {\n this.pipeline.setBindings(bindings);\n Object.assign(this.props.bindings, bindings);\n return this;\n }\n\n setUniforms(uniforms: Record<string, any>): this {\n this.pipeline.setUniforms(uniforms);\n Object.assign(this.props.uniforms, uniforms);\n return this;\n }\n\n _setGeometry(geometry: Geometry): void {\n // this._deleteGeometryBuffers();\n\n const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);\n this.setAttributes(geometryBuffers);\n\n const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);\n if (indexBuffer) {\n this.setIndexBuffer(indexBuffer);\n }\n }\n}\n\n/** Create a shader from the different overloads */\nfunction getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {\n // TODO - detect WGSL/GLSL and throw an error if not supported\n if (typeof shader === 'string') {\n return shader;\n }\n\n switch (device.info.type) {\n case 'webgpu':\n if (shader?.wgsl) {\n return shader.wgsl;\n }\n throw new Error('WebGPU does not support GLSL shaders');\n\n default:\n if (shader?.glsl) {\n return shader.glsl;\n }\n throw new Error('WebGL does not support WGSL shaders');\n }\n}\n"],"file":"model.js"}
@@ -7,7 +7,7 @@ export declare type GetRenderPipelineOptions = {
7
7
  topology: any;
8
8
  parameters?: RenderPipelineParameters;
9
9
  modules?: ShaderModule[];
10
- defines?: Record<string, string>;
10
+ defines?: Record<string, string | number | boolean>;
11
11
  inject?: Record<string, string>;
12
12
  transpileToGLSL100?: boolean;
13
13
  varyings?: string[];
@@ -24,7 +24,7 @@ export declare type GetComputePipelineOptions = {
24
24
  bufferMode?: number;
25
25
  };
26
26
  /** Efficiently create shared pipelines with varying parameters */
27
- export default class PipelineFactory {
27
+ export declare class PipelineFactory {
28
28
  readonly device: Device;
29
29
  stateHash: number;
30
30
  private _hashCounter;
@@ -36,15 +36,17 @@ export default class PipelineFactory {
36
36
  private _defaultModules;
37
37
  static getDefaultPipelineFactory(device: Device): PipelineFactory;
38
38
  constructor(device: Device);
39
+ addDefaultModule(module: ShaderModule): void;
40
+ removeDefaultModule(module: ShaderModule): void;
39
41
  addShaderHook(hook: any, opts?: any): void;
40
42
  createRenderPipeline(options: GetRenderPipelineOptions): {
41
- renderPipeline: RenderPipeline;
43
+ pipeline: RenderPipeline;
42
44
  getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;
43
45
  };
44
46
  release(pipeline: RenderPipeline): void;
45
47
  getUniforms(pipeline: RenderPipeline): any;
46
48
  _createRenderPipeline(props: GetRenderPipelineOptions): {
47
- renderPipeline: RenderPipeline;
49
+ pipeline: RenderPipeline;
48
50
  getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;
49
51
  };
50
52
  /** Calculate a hash based on all the inputs for a render pipeline */
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/lib/pipeline-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,wBAAwB,EAAC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAC,MAAM,EAAE,cAAc,EAAkB,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,oBAAY,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,MAAC;IACT,UAAU,CAAC,EAAE,wBAAwB,CAAC;IAEtC,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,wBAAwB,CAAC;IAEtC,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MA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AW,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KACjF;IAiBD,qEAAqE;IACrE,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM;IAgC5D,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ7B,cAAc,CAAC,UAAU,GAAE,YAAY,EAAO,GAAG,YAAY,EAAE;CAyBhE"}
@@ -12,7 +12,7 @@ const DEFAULT_RENDER_PIPELINE_OPTIONS = {
12
12
  topology: 'triangle-list',
13
13
  parameters: {}
14
14
  };
15
- export default class PipelineFactory {
15
+ export class PipelineFactory {
16
16
  static getDefaultPipelineFactory(device) {
17
17
  device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);
18
18
  return device.defaultPipelineFactory;
@@ -40,6 +40,20 @@ export default class PipelineFactory {
40
40
  this.device = device;
41
41
  }
42
42
 
43
+ addDefaultModule(module) {
44
+ if (!this._defaultModules.find(m => m.name === (typeof module === 'string' ? module : module.name))) {
45
+ this._defaultModules.push(module);
46
+ }
47
+
48
+ this.stateHash++;
49
+ }
50
+
51
+ removeDefaultModule(module) {
52
+ const moduleName = typeof module === 'string' ? module : module.name;
53
+ this._defaultModules = this._defaultModules.filter(m => m.name !== moduleName);
54
+ this.stateHash++;
55
+ }
56
+
43
57
  addShaderHook(hook, opts) {
44
58
  if (opts) {
45
59
  hook = Object.assign(opts, {
@@ -65,14 +79,14 @@ export default class PipelineFactory {
65
79
 
66
80
  if (!this._pipelineCache[hash]) {
67
81
  const {
68
- renderPipeline,
82
+ pipeline,
69
83
  getUniforms
70
84
  } = this._createRenderPipeline({ ...props,
71
85
  modules
72
86
  });
73
87
 
74
- renderPipeline.hash = hash;
75
- this._pipelineCache[hash] = renderPipeline;
88
+ pipeline.hash = hash;
89
+ this._pipelineCache[hash] = pipeline;
76
90
 
77
91
  this._getUniforms[hash] = getUniforms || (x => {});
78
92
 
@@ -81,7 +95,7 @@ export default class PipelineFactory {
81
95
 
82
96
  this._useCounts[hash]++;
83
97
  return {
84
- renderPipeline: this._pipelineCache[hash],
98
+ pipeline: this._pipelineCache[hash],
85
99
  getUniforms: this._getUniforms[hash]
86
100
  };
87
101
  }
@@ -111,7 +125,7 @@ export default class PipelineFactory {
111
125
  const assembled = assembleShaders(platformInfo, { ...props,
112
126
  hookFunctions: this._hookFunctions
113
127
  });
114
- const renderPipeline = this.device.createRenderPipeline({ ...props,
128
+ const pipeline = this.device.createRenderPipeline({ ...props,
115
129
  vs: this.device.createShader({
116
130
  stage: 'vertex',
117
131
  source: assembled.vs
@@ -122,7 +136,7 @@ export default class PipelineFactory {
122
136
  })
123
137
  });
124
138
  return {
125
- renderPipeline,
139
+ pipeline,
126
140
  getUniforms: assembled.getUniforms
127
141
  };
128
142
  }
@@ -141,7 +155,7 @@ export default class PipelineFactory {
141
155
 
142
156
  for (const key of defineKeys) {
143
157
  defineHashes.push(this._getHash(key));
144
- defineHashes.push(this._getHash(props.defines[key]));
158
+ defineHashes.push(this._getHash(String(props.defines[key])));
145
159
  }
146
160
 
147
161
  for (const key of injectKeys) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/pipeline-factory.ts"],"names":["assembleShaders","DEFAULT_RENDER_PIPELINE_OPTIONS","vs","fs","modules","defines","inject","transpileToGLSL100","varyings","bufferMode","topology","parameters","PipelineFactory","getDefaultPipelineFactory","device","defaultPipelineFactory","constructor","addShaderHook","hook","opts","Object","assign","_hookFunctions","push","stateHash","createRenderPipeline","options","props","_getModuleList","hash","_hashRenderPipeline","_pipelineCache","renderPipeline","getUniforms","_createRenderPipeline","_getUniforms","x","_useCounts","release","pipeline","destroy","platformInfo","gpu","info","features","assembled","hookFunctions","createShader","stage","source","vsHash","_getHash","fsHash","moduleHashes","map","m","name","sort","varyingHashes","v","defineKeys","keys","injectKeys","defineHashes","injectHashes","key","parameterHash","JSON","stringify","join","_hashes","undefined","_hashCounter","appModules","Array","_defaultModules","length","seen","count","i","len","module"],"mappings":";AAGA,SAAQA,eAAR,QAA8B,sBAA9B;AA8BA,MAAMC,+BAAmE,GAAG;AAC1EC,EAAAA,EAAE,EAAE,EADsE;AAE1EC,EAAAA,EAAE,EAAE,EAFsE;AAG1EC,EAAAA,OAAO,EAAE,EAHiE;AAI1EC,EAAAA,OAAO,EAAE,EAJiE;AAK1EC,EAAAA,MAAM,EAAE,EALkE;AAM1EC,EAAAA,kBAAkB,EAAE,KANsD;AAQ1EC,EAAAA,QAAQ,EAAE,EARgE;AAS1EC,EAAAA,UAAU,EAAE,MAT8D;AAU1EC,EAAAA,QAAQ,EAAE,eAVgE;AAW1EC,EAAAA,UAAU,EAAE;AAX8D,CAA5E;AAeA,eAAe,MAAMC,eAAN,CAAsB;AAeH,SAAzBC,yBAAyB,CAACC,MAAD,EAAkC;AAEhEA,IAAAA,MAAM,CAACC,sBAAP,GAAgCD,MAAM,CAACC,sBAAP,IAAiC,IAAIH,eAAJ,CAAoBE,MAApB,CAAjE;AAEA,WAAOA,MAAM,CAACC,sBAAd;AACD;;AAEDC,EAAAA,WAAW,CAACF,MAAD,EAAiB;AAAA;;AAAA,uCAnBR,CAmBQ;;AAAA,0CAlBG,CAkBH;;AAAA,qCAjBuB,EAiBvB;;AAAA,wCAhB0B,EAgB1B;;AAAA,4CAdsC,EActC;;AAAA,0CAZyB,EAYzB;;AAAA,4CAXa,EAWb;;AAAA,6CAVK,EAUL;;AAC1B,SAAKA,MAAL,GAAcA,MAAd;AACD;;AAeDG,EAAAA,aAAa,CAACC,IAAD,EAAOC,IAAP,EAAoB;AAC/B,QAAIA,IAAJ,EAAU;AACRD,MAAAA,IAAI,GAAGE,MAAM,CAACC,MAAP,CAAcF,IAAd,EAAoB;AAACD,QAAAA;AAAD,OAApB,CAAP;AACD;;AACD,SAAKI,cAAL,CAAoBC,IAApB,CAAyBL,IAAzB;;AACA,SAAK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EAAkD,EAAED,CAApD,EAAuD;AACrD,YAAME,MAAM,GAAGR,UAAU,CAACM,CAAD,CAAzB;AACA,YAAMvB,IAAI,GAAGyB,MAAM,CAACzB,IAApB;;AACA,UAAI,CAACqB,IAAI,CAACrB,IAAD,CAAT,EAAiB;AACfpD,QAAAA,OAAO,CAAC0E,KAAK,EAAN,CAAP,GAAmBG,MAAnB;AACAJ,QAAAA,IAAI,CAACrB,IAAD,CAAJ,GAAa,IAAb;AACD;AACF;;AAEDpD,IAAAA,OAAO,CAACwE,MAAR,GAAiBE,KAAjB;AAEA,WAAO1E,OAAP;AACD;;AA/KkC","sourcesContent":["import type {RenderPipelineProps, RenderPipelineParameters} from '@luma.gl/api';\nimport {Device, RenderPipeline, ComputePipeline} from '@luma.gl/api/';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport {assembleShaders} from '@luma.gl/shadertools';\n\nexport type GetRenderPipelineOptions = {\n vs: string,\n fs: string,\n topology;\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string>,\n inject?: Record<string, string>,\n transpileToGLSL100?: boolean;\n\n varyings?: string[],\n bufferMode?: number, \n};\n\nexport type GetComputePipelineOptions = {\n cs: string,\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string>,\n inject?: Record<string, string>,\n transpileToGLSL100?: boolean;\n\n varyings?: string[],\n bufferMode?: number,\n};\n\nconst DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {\n vs: '',\n fs: '',\n modules: [],\n defines: {},\n inject: {},\n transpileToGLSL100: false,\n\n varyings: [],\n bufferMode: 0x8c8d, // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS\n topology: 'triangle-list',\n parameters: {} \n};\n\n/** Efficiently create shared pipelines with varying parameters */\nexport default class PipelineFactory {\n readonly device: Device;\n\n stateHash: number = 0; // Used to change hashing if hooks are modified\n private _hashCounter: number = 0;\n private readonly _hashes: Record<string, number> = {};\n private readonly _useCounts: Record<string, number> = {};\n\n private readonly _pipelineCache: Record<string, RenderPipeline> = {};\n\n private readonly _getUniforms: Record<string, any> = {};\n private readonly _hookFunctions: any[] = [];\n private _defaultModules: any[] = [];\n // private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl\n\n static getDefaultPipelineFactory(device: Device): PipelineFactory {\n // @ts-expect-error Add to device\n device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);\n // @ts-expect-error Add to device\n return device.defaultPipelineFactory;\n }\n\n constructor(device: Device) {\n this.device = device;\n }\n\n // addDefaultModule(module: ShaderModule): void {\n // if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {\n // this._defaultModules.push(module);\n // }\n // this.stateHash++;\n // }\n\n // removeDefaultModule(module: ShaderModule): void {\n // const moduleName = typeof module === 'string' ? module : module.name;\n // this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);\n // this.stateHash++;\n // }\n\n addShaderHook(hook, opts?): void {\n if (opts) {\n hook = Object.assign(opts, {hook});\n }\n this._hookFunctions.push(hook);\n this.stateHash++;\n }\n\n createRenderPipeline(options: GetRenderPipelineOptions): {\n renderPipeline: RenderPipeline;\n getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;\n } {\n const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};\n\n const modules = this._getModuleList(props.modules); // Combine with default modules\n\n const hash = this._hashRenderPipeline({...props, modules});\n\n if (!this._pipelineCache[hash]) {\n const {renderPipeline, getUniforms} = this._createRenderPipeline({...props, modules});\n renderPipeline.hash = hash;\n this._pipelineCache[hash] = renderPipeline;\n this._getUniforms[hash] = getUniforms || ((x: Record<string, Record<string, any>>) => {});\n this._useCounts[hash] = 0;\n }\n\n this._useCounts[hash]++;\n\n return {\n renderPipeline: this._pipelineCache[hash],\n getUniforms: this._getUniforms[hash]\n };\n }\n\n release(pipeline: RenderPipeline): void {\n const hash = pipeline.hash;\n this._useCounts[hash]--;\n if (this._useCounts[hash] === 0) {\n this._pipelineCache[hash].destroy();\n delete this._pipelineCache[hash];\n delete this._getUniforms[hash];\n delete this._useCounts[hash];\n }\n }\n\n getUniforms(pipeline: RenderPipeline) {\n return this._getUniforms[pipeline.hash] || null;\n }\n\n // PRIVATE\n\n _createRenderPipeline(props: GetRenderPipelineOptions): {\n renderPipeline: RenderPipeline,\n getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>\n } {\n const platformInfo = {\n gpu: this.device.info.gpu,\n features: this.device.features\n };\n\n const assembled = assembleShaders(platformInfo, {...props, hookFunctions: this._hookFunctions});\n\n const renderPipeline = this.device.createRenderPipeline({\n ...props,\n vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),\n fs: assembled.fs && this.device.createShader({stage: 'fragment', source: assembled.fs}),\n });\n\n return {renderPipeline, getUniforms: assembled.getUniforms};\n }\n\n /** Calculate a hash based on all the inputs for a render pipeline */\n _hashRenderPipeline(props: GetRenderPipelineOptions): string {\n const vsHash = this._getHash(props.vs);\n const fsHash = this._getHash(props.fs);\n\n const moduleHashes = props.modules.map((m) => this._getHash(typeof m === 'string' ? m : m.name)).sort();\n const varyingHashes = props.varyings.map((v) => this._getHash(v));\n\n const defineKeys = Object.keys(props.defines).sort();\n const injectKeys = Object.keys(props.inject).sort();\n const defineHashes = [];\n const injectHashes = [];\n\n for (const key of defineKeys) {\n defineHashes.push(this._getHash(key));\n defineHashes.push(this._getHash(props.defines[key]));\n }\n\n for (const key of injectKeys) {\n injectHashes.push(this._getHash(key));\n injectHashes.push(this._getHash(props.inject[key]));\n }\n\n // TODO - hash parameters!\n const parameterHash = JSON.stringify(props.parameters);\n\n return `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(\n '/'\n )}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${props.bufferMode}${\n props.transpileToGLSL100 ? 'T' : ''\n }P${parameterHash}`;\n }\n\n _getHash(key: string): number {\n if (this._hashes[key] === undefined) {\n this._hashes[key] = this._hashCounter++;\n }\n return this._hashes[key];\n }\n\n // Dedupe and combine with default modules\n _getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {\n const modules = new Array(this._defaultModules.length + appModules.length);\n const seen: Record<string, boolean> = {};\n let count = 0;\n\n for (let i = 0, len = this._defaultModules.length; i < len; ++i) {\n const module = this._defaultModules[i];\n const name = module.name;\n modules[count++] = module;\n seen[name] = true;\n }\n\n for (let i = 0, len = appModules.length; i < len; ++i) {\n const module = appModules[i];\n const name = module.name;\n if (!seen[name]) {\n modules[count++] = module;\n seen[name] = true;\n }\n }\n\n modules.length = count;\n\n return modules;\n }\n}\n"],"file":"pipeline-factory.js"}
1
+ {"version":3,"sources":["../../src/lib/pipeline-factory.ts"],"names":["assembleShaders","DEFAULT_RENDER_PIPELINE_OPTIONS","vs","fs","modules","defines","inject","transpileToGLSL100","varyings","bufferMode","topology","parameters","PipelineFactory","getDefaultPipelineFactory","device","defaultPipelineFactory","constructor","addDefaultModule","module","_defaultModules","find","m","name","push","stateHash","removeDefaultModule","moduleName","filter","addShaderHook","hook","opts","Object","assign","_hookFunctions","createRenderPipeline","options","props","_getModuleList","hash","_hashRenderPipeline","_pipelineCache","pipeline","getUniforms","_createRenderPipeline","_getUniforms","x","_useCounts","release","destroy","platformInfo","gpu","info","features","assembled","hookFunctions","createShader","stage","source","vsHash","_getHash","fsHash","moduleHashes","map","sort","varyingHashes","v","defineKeys","keys","injectKeys","defineHashes","injectHashes","key","String","parameterHash","JSON","stringify","join","_hashes","undefined","_hashCounter","appModules","Array","length","seen","count","i","len"],"mappings":";AAGA,SAAQA,eAAR,QAA8B,sBAA9B;AA8BA,MAAMC,+BAAmE,GAAG;AAC1EC,EAAAA,EAAE,EAAE,EADsE;AAE1EC,EAAAA,EAAE,EAAE,EAFsE;AAG1EC,EAAAA,OAAO,EAAE,EAHiE;AAI1EC,EAAAA,OAAO,EAAE,EAJiE;AAK1EC,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AAC/D,YAAMnE,MAAM,GAAG,KAAKC,eAAL,CAAqBkE,CAArB,CAAf;AACA,YAAM/D,IAAI,GAAGJ,MAAM,CAACI,IAApB;AACAlB,MAAAA,OAAO,CAACgF,KAAK,EAAN,CAAP,GAAmBlE,MAAnB;AACAiE,MAAAA,IAAI,CAAC7D,IAAD,CAAJ,GAAa,IAAb;AACD;;AAED,SAAK,IAAI+D,CAAC,GAAG,CAAR,EAAWC,GAAG,GAAGN,UAAU,CAACE,MAAjC,EAAyCG,CAAC,GAAGC,GAA7C,EAAkD,EAAED,CAApD,EAAuD;AACrD,YAAMnE,MAAM,GAAG8D,UAAU,CAACK,CAAD,CAAzB;AACA,YAAM/D,IAAI,GAAGJ,MAAM,CAACI,IAApB;;AACA,UAAI,CAAC6D,IAAI,CAAC7D,IAAD,CAAT,EAAiB;AACflB,QAAAA,OAAO,CAACgF,KAAK,EAAN,CAAP,GAAmBlE,MAAnB;AACAiE,QAAAA,IAAI,CAAC7D,IAAD,CAAJ,GAAa,IAAb;AACD;AACF;;AAEDlB,IAAAA,OAAO,CAAC8E,MAAR,GAAiBE,KAAjB;AAEA,WAAOhF,OAAP;AACD;;AA/K0B","sourcesContent":["import type {RenderPipelineProps, RenderPipelineParameters} from '@luma.gl/api';\nimport {Device, RenderPipeline, ComputePipeline} from '@luma.gl/api/';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport {assembleShaders} from '@luma.gl/shadertools';\n\nexport type GetRenderPipelineOptions = {\n vs: string,\n fs: string,\n topology;\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string | number | boolean>,\n inject?: Record<string, string>,\n transpileToGLSL100?: boolean;\n\n varyings?: string[],\n bufferMode?: number, \n};\n\nexport type GetComputePipelineOptions = {\n cs: string,\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string>,\n inject?: Record<string, string>,\n transpileToGLSL100?: boolean;\n\n varyings?: string[],\n bufferMode?: number,\n};\n\nconst DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {\n vs: '',\n fs: '',\n modules: [],\n defines: {},\n inject: {},\n transpileToGLSL100: false,\n\n varyings: [],\n bufferMode: 0x8c8d, // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS\n topology: 'triangle-list',\n parameters: {} \n};\n\n/** Efficiently create shared pipelines with varying parameters */\nexport class PipelineFactory {\n readonly device: Device;\n\n stateHash: number = 0; // Used to change hashing if hooks are modified\n private _hashCounter: number = 0;\n private readonly _hashes: Record<string, number> = {};\n private readonly _useCounts: Record<string, number> = {};\n\n private readonly _pipelineCache: Record<string, RenderPipeline> = {};\n\n private readonly _getUniforms: Record<string, any> = {};\n private readonly _hookFunctions: any[] = [];\n private _defaultModules: any[] = [];\n // private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl\n\n static getDefaultPipelineFactory(device: Device): PipelineFactory {\n // @ts-expect-error Add to device\n device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);\n // @ts-expect-error Add to device\n return device.defaultPipelineFactory;\n }\n\n constructor(device: Device) {\n this.device = device;\n }\n\n addDefaultModule(module: ShaderModule): void {\n if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {\n this._defaultModules.push(module);\n }\n this.stateHash++;\n }\n\n removeDefaultModule(module: ShaderModule): void {\n const moduleName = typeof module === 'string' ? module : module.name;\n this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);\n this.stateHash++;\n }\n\n addShaderHook(hook, opts?): void {\n if (opts) {\n hook = Object.assign(opts, {hook});\n }\n this._hookFunctions.push(hook);\n this.stateHash++;\n }\n\n createRenderPipeline(options: GetRenderPipelineOptions): {\n pipeline: RenderPipeline;\n getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;\n } {\n const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};\n\n const modules = this._getModuleList(props.modules); // Combine with default modules\n\n const hash = this._hashRenderPipeline({...props, modules});\n\n if (!this._pipelineCache[hash]) {\n const {pipeline, getUniforms} = this._createRenderPipeline({...props, modules});\n pipeline.hash = hash;\n this._pipelineCache[hash] = pipeline;\n this._getUniforms[hash] = getUniforms || ((x: Record<string, Record<string, any>>) => {});\n this._useCounts[hash] = 0;\n }\n\n this._useCounts[hash]++;\n\n return {\n pipeline: this._pipelineCache[hash],\n getUniforms: this._getUniforms[hash]\n };\n }\n\n release(pipeline: RenderPipeline): void {\n const hash = pipeline.hash;\n this._useCounts[hash]--;\n if (this._useCounts[hash] === 0) {\n this._pipelineCache[hash].destroy();\n delete this._pipelineCache[hash];\n delete this._getUniforms[hash];\n delete this._useCounts[hash];\n }\n }\n\n getUniforms(pipeline: RenderPipeline) {\n return this._getUniforms[pipeline.hash] || null;\n }\n\n // PRIVATE\n\n _createRenderPipeline(props: GetRenderPipelineOptions): {\n pipeline: RenderPipeline,\n getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>\n } {\n const platformInfo = {\n gpu: this.device.info.gpu,\n features: this.device.features\n };\n\n const assembled = assembleShaders(platformInfo, {...props, hookFunctions: this._hookFunctions});\n\n const pipeline = this.device.createRenderPipeline({\n ...props,\n vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),\n fs: assembled.fs && this.device.createShader({stage: 'fragment', source: assembled.fs}),\n });\n\n return {pipeline, getUniforms: assembled.getUniforms};\n }\n\n /** Calculate a hash based on all the inputs for a render pipeline */\n _hashRenderPipeline(props: GetRenderPipelineOptions): string {\n const vsHash = this._getHash(props.vs);\n const fsHash = this._getHash(props.fs);\n\n const moduleHashes = props.modules.map((m) => this._getHash(typeof m === 'string' ? m : m.name)).sort();\n const varyingHashes = props.varyings.map((v) => this._getHash(v));\n\n const defineKeys = Object.keys(props.defines).sort();\n const injectKeys = Object.keys(props.inject).sort();\n const defineHashes: number[] = [];\n const injectHashes: number[] = [];\n\n for (const key of defineKeys) {\n defineHashes.push(this._getHash(key));\n defineHashes.push(this._getHash(String(props.defines[key])));\n }\n\n for (const key of injectKeys) {\n injectHashes.push(this._getHash(key));\n injectHashes.push(this._getHash(props.inject[key]));\n }\n\n // TODO - hash parameters!\n const parameterHash = JSON.stringify(props.parameters);\n\n return `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(\n '/'\n )}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${props.bufferMode}${\n props.transpileToGLSL100 ? 'T' : ''\n }P${parameterHash}`;\n }\n\n _getHash(key: string): number {\n if (this._hashes[key] === undefined) {\n this._hashes[key] = this._hashCounter++;\n }\n return this._hashes[key];\n }\n\n // Dedupe and combine with default modules\n _getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {\n const modules = new Array(this._defaultModules.length + appModules.length);\n const seen: Record<string, boolean> = {};\n let count = 0;\n\n for (let i = 0, len = this._defaultModules.length; i < len; ++i) {\n const module = this._defaultModules[i];\n const name = module.name;\n modules[count++] = module;\n seen[name] = true;\n }\n\n for (let i = 0, len = appModules.length; i < len; ++i) {\n const module = appModules[i];\n const name = module.name;\n if (!seen[name]) {\n modules[count++] = module;\n seen[name] = true;\n }\n }\n\n modules.length = count;\n\n return modules;\n }\n}\n"],"file":"pipeline-factory.js"}
@@ -1,6 +1,6 @@
1
1
  import type { DeviceProps } from '@luma.gl/api';
2
2
  import type { AnimationProps } from '../lib/animation-props';
3
- import AnimationLoop from './animation-loop';
3
+ import { AnimationLoop } from './animation-loop';
4
4
  /**
5
5
  * Minimal animation loop that initializes models in constructor
6
6
  * Simplifying type management
@@ -1 +1 @@
1
- {"version":3,"file":"render-loop.d.ts","sourceRoot":"","sources":["../../src/lib/render-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C;;;;GAIG;AACH,8BAAsB,UAAU;gBAClB,cAAc,CAAC,EAAE,cAAc;IAE3C,4CAA4C;IAC5C,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa;CAS/F"}
1
+ {"version":3,"file":"render-loop.d.ts","sourceRoot":"","sources":["../../src/lib/render-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,8BAAsB,UAAU;gBAClB,cAAc,CAAC,EAAE,cAAc;IAE3C,4CAA4C;IAC5C,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa;CAS/F"}
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import AnimationLoop from './animation-loop';
2
+ import { AnimationLoop } from './animation-loop';
3
3
  export class RenderLoop {
4
4
  constructor(animationProps) {}
5
5
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/render-loop.ts"],"names":["AnimationLoop","RenderLoop","constructor","animationProps","run","RenderLoopConstructor","deviceProps","animationLoop","SyncInitAnimationLoop","getInfo","info","onInitialize","renderLoop","onRender","frame","onFinalize","destroy"],"mappings":";AAEA,OAAOA,aAAP,MAA0B,kBAA1B;AAOA,OAAO,MAAeC,UAAf,CAA0B;AAC/BC,EAAAA,WAAW,CAACC,cAAD,EAAkC,CAAE;;AAGrC,SAAHC,GAAG,CAACC,qBAAD,EAA2CC,WAA3C,EAAqF;AAE7F,UAAMC,aAAa,GAAG,IAAIC,qBAAJ,CAA0BH,qBAA1B,EAAiDC,WAAjD,CAAtB;AAKA,WAAOC,aAAP;AACD;;AAZ8B;;AAgBjC,MAAMC,qBAAN,SAAoCR,aAApC,CAAkD;AAIhDS,EAAAA,OAAO,GAAG;AAER,WAAO,KAAKJ,qBAAL,CAA2BK,IAAlC;AACD;;AAEDR,EAAAA,WAAW,CAACG,qBAAD,EAA2CC,WAA3C,EAAsE;AAC/E,UAAM;AAACA,MAAAA;AAAD,KAAN;;AAD+E;;AAAA;;AAE/E,SAAKD,qBAAL,GAA6BA,qBAA7B;AACD;;AAEDM,EAAAA,YAAY,CAACR,cAAD,EAAiC;AAE3C,SAAKS,UAAL,GAAkB,IAAI,KAAKP,qBAAT,CAA+BF,cAA/B,CAAlB;AACD;;AAEDU,EAAAA,QAAQ,CAACV,cAAD,EAAiC;AAAA;;AAEvC,6BAAKS,UAAL,+FAAiBC,QAAjB,uGAA4BV,cAA5B;AAEA,8BAAKS,UAAL,iGAAiBE,KAAjB,wGAAyBX,cAAzB;AACD;;AAEDY,EAAAA,UAAU,CAACZ,cAAD,EAAiC;AAAA;;AAEzC,8BAAKS,UAAL,iGAAiBG,UAAjB,wGAA8BZ,cAA9B;AAEA,8BAAKS,UAAL,iGAAiBI,OAAjB,wGAA2Bb,cAA3B;AACD;;AA/B+C","sourcesContent":["import type {DeviceProps} from '@luma.gl/api';\nimport type {AnimationProps} from '../lib/animation-props';\nimport AnimationLoop from './animation-loop';\n\n/**\n * Minimal animation loop that initializes models in constructor\n * Simplifying type management\n * v9 API\n */\nexport abstract class RenderLoop {\n constructor(animationProps?: AnimationProps) {}\n\n /** Instantiates and runs the render loop */\n static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {\n // Create an animation loop;\n const animationLoop = new SyncInitAnimationLoop(RenderLoopConstructor, deviceProps);\n\n // Start the loop automatically\n // animationLoop.start();\n\n return animationLoop;\n }\n}\n\n/** Instantiates the RenderLoop once the device is created */\nclass SyncInitAnimationLoop extends AnimationLoop {\n RenderLoopConstructor: typeof RenderLoop;\n renderLoop: RenderLoop;\n\n getInfo() {\n // @ts-ignore\n return this.RenderLoopConstructor.info;\n }\n\n constructor(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps) {\n super({deviceProps});\n this.RenderLoopConstructor = RenderLoopConstructor;\n }\n\n onInitialize(animationProps: AnimationProps) {\n // @ts-expect-error\n this.renderLoop = new this.RenderLoopConstructor(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onRender?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.frame?.(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onFinalize?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.destroy?.(animationProps);\n }\n}\n"],"file":"render-loop.js"}
1
+ {"version":3,"sources":["../../src/lib/render-loop.ts"],"names":["AnimationLoop","RenderLoop","constructor","animationProps","run","RenderLoopConstructor","deviceProps","animationLoop","SyncInitAnimationLoop","getInfo","info","onInitialize","renderLoop","onRender","frame","onFinalize","destroy"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,kBAA5B;AAOA,OAAO,MAAeC,UAAf,CAA0B;AAC/BC,EAAAA,WAAW,CAACC,cAAD,EAAkC,CAAE;;AAGrC,SAAHC,GAAG,CAACC,qBAAD,EAA2CC,WAA3C,EAAqF;AAE7F,UAAMC,aAAa,GAAG,IAAIC,qBAAJ,CAA0BH,qBAA1B,EAAiDC,WAAjD,CAAtB;AAKA,WAAOC,aAAP;AACD;;AAZ8B;;AAgBjC,MAAMC,qBAAN,SAAoCR,aAApC,CAAkD;AAIhDS,EAAAA,OAAO,GAAG;AAER,WAAO,KAAKJ,qBAAL,CAA2BK,IAAlC;AACD;;AAEDR,EAAAA,WAAW,CAACG,qBAAD,EAA2CC,WAA3C,EAAsE;AAC/E,UAAM;AAACA,MAAAA;AAAD,KAAN;;AAD+E;;AAAA;;AAE/E,SAAKD,qBAAL,GAA6BA,qBAA7B;AACD;;AAEDM,EAAAA,YAAY,CAACR,cAAD,EAAiC;AAE3C,SAAKS,UAAL,GAAkB,IAAI,KAAKP,qBAAT,CAA+BF,cAA/B,CAAlB;AACD;;AAEDU,EAAAA,QAAQ,CAACV,cAAD,EAAiC;AAAA;;AAEvC,6BAAKS,UAAL,+FAAiBC,QAAjB,uGAA4BV,cAA5B;AAEA,8BAAKS,UAAL,iGAAiBE,KAAjB,wGAAyBX,cAAzB;AACD;;AAEDY,EAAAA,UAAU,CAACZ,cAAD,EAAiC;AAAA;;AAEzC,8BAAKS,UAAL,iGAAiBG,UAAjB,wGAA8BZ,cAA9B;AAEA,8BAAKS,UAAL,iGAAiBI,OAAjB,wGAA2Bb,cAA3B;AACD;;AA/B+C","sourcesContent":["import type {DeviceProps} from '@luma.gl/api';\nimport type {AnimationProps} from '../lib/animation-props';\nimport {AnimationLoop} from './animation-loop';\n\n/**\n * Minimal animation loop that initializes models in constructor\n * Simplifying type management\n * v9 API\n */\nexport abstract class RenderLoop {\n constructor(animationProps?: AnimationProps) {}\n\n /** Instantiates and runs the render loop */\n static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {\n // Create an animation loop;\n const animationLoop = new SyncInitAnimationLoop(RenderLoopConstructor, deviceProps);\n\n // Start the loop automatically\n // animationLoop.start();\n\n return animationLoop;\n }\n}\n\n/** Instantiates the RenderLoop once the device is created */\nclass SyncInitAnimationLoop extends AnimationLoop {\n RenderLoopConstructor: typeof RenderLoop;\n renderLoop: RenderLoop;\n\n getInfo() {\n // @ts-ignore\n return this.RenderLoopConstructor.info;\n }\n\n constructor(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps) {\n super({deviceProps});\n this.RenderLoopConstructor = RenderLoopConstructor;\n }\n\n onInitialize(animationProps: AnimationProps) {\n // @ts-expect-error\n this.renderLoop = new this.RenderLoopConstructor(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onRender?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.frame?.(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onFinalize?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.destroy?.(animationProps);\n }\n}\n"],"file":"render-loop.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "9.0.0-alpha.4",
3
+ "version": "9.0.0-alpha.6",
4
4
  "description": "WebGL2 Components for High Performance Rendering and Computation",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -31,12 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.0.0",
34
- "@luma.gl/constants": "9.0.0-alpha.4",
35
- "@luma.gl/shadertools": "9.0.0-alpha.4",
36
- "@luma.gl/webgl": "9.0.0-alpha.4",
34
+ "@luma.gl/constants": "9.0.0-alpha.6",
35
+ "@luma.gl/shadertools": "9.0.0-alpha.6",
36
+ "@luma.gl/webgl": "9.0.0-alpha.6",
37
37
  "@math.gl/core": "^3.5.0",
38
38
  "@probe.gl/log": "^3.5.0",
39
39
  "@probe.gl/stats": "^3.5.0"
40
40
  },
41
- "gitHead": "c1bbfa21e6e2cce41378a284b305ebfac39e998b"
41
+ "gitHead": "d4a92477c1d76f6242ec0fe377e238669e0667c0"
42
42
  }
package/src/index.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  // luma.gl Engine API
2
2
  export type {AnimationProps} from './lib/animation-props';
3
+ export type {AnimationLoopProps} from './lib/animation-loop';
4
+ export {AnimationLoop} from './lib/animation-loop';
3
5
  export {RenderLoop} from './lib/render-loop';
4
6
  export type {ModelProps} from './lib/model';
5
7
  export {default as Model} from './lib/model';
6
- export type {AnimationLoopProps} from './lib/animation-loop';
7
- export {default as AnimationLoop} from './lib/animation-loop';
8
+
9
+ export {PipelineFactory} from './lib/pipeline-factory';
10
+
11
+ // Animation
12
+ export {Timeline} from './animation/timeline';
13
+ export {KeyFrames} from './animation/key-frames';
8
14
 
9
15
  // Utils
10
16
  // export {default as ClipSpace} from './lib/clip-space';
@@ -28,7 +34,3 @@ export {SphereGeometry} from './geometries/sphere-geometry';
28
34
  export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
29
35
  export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
30
36
 
31
- // Animation
32
- export {Timeline} from './animation/timeline';
33
- export {KeyFrames} from './animation/key-frames';
34
-
@@ -51,7 +51,7 @@ const DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {
51
51
  };
52
52
 
53
53
  /** Convenient animation loop */
54
- export default class AnimationLoop {
54
+ export class AnimationLoop {
55
55
  device: Device;
56
56
  canvas: HTMLCanvasElement; // | OffscreenCanvas;
57
57
 
@@ -1,6 +1,6 @@
1
1
  import {Device} from '@luma.gl/api';
2
2
  import {Timeline} from '../animation/timeline'
3
- import type AnimationLoop from './animation-loop';
3
+ import type {AnimationLoop} from './animation-loop';
4
4
 
5
5
  /** Properties passed to every render frame */
6
6
  export type AnimationProps = {
package/src/lib/model.ts CHANGED
@@ -1,9 +1,11 @@
1
+ // luma.gl, MIT license
2
+
1
3
  import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding} from '@luma.gl/api';
2
4
  import {RenderPipeline, Shader, cast} from '@luma.gl/api';
3
5
  import type { ShaderModule } from '@luma.gl/shadertools';
4
6
  import type Geometry from '../geometry/geometry';
5
7
  import {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';
6
- import PipelineFactory from './pipeline-factory';
8
+ import {PipelineFactory} from './pipeline-factory';
7
9
 
8
10
  export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
9
11
  // Model also accepts a string
@@ -59,7 +61,7 @@ export default class Model {
59
61
  this.topology = this.props.geometry.topology;
60
62
  }
61
63
 
62
- const {renderPipeline, getUniforms} = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({
64
+ const {pipeline, getUniforms} = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({
63
65
  ...this.props,
64
66
  vs: this.vs,
65
67
  fs: this.fs,
@@ -70,7 +72,7 @@ export default class Model {
70
72
  layout: props.layout
71
73
  });
72
74
 
73
- this.pipeline = renderPipeline;
75
+ this.pipeline = pipeline;
74
76
  this._getModuleUniforms = getUniforms;
75
77
 
76
78
  if (this.props.geometry) {
@@ -10,7 +10,7 @@ export type GetRenderPipelineOptions = {
10
10
  parameters?: RenderPipelineParameters;
11
11
 
12
12
  modules?: ShaderModule[];
13
- defines?: Record<string, string>,
13
+ defines?: Record<string, string | number | boolean>,
14
14
  inject?: Record<string, string>,
15
15
  transpileToGLSL100?: boolean;
16
16
 
@@ -46,7 +46,7 @@ const DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {
46
46
  };
47
47
 
48
48
  /** Efficiently create shared pipelines with varying parameters */
49
- export default class PipelineFactory {
49
+ export class PipelineFactory {
50
50
  readonly device: Device;
51
51
 
52
52
  stateHash: number = 0; // Used to change hashing if hooks are modified
@@ -72,18 +72,18 @@ export default class PipelineFactory {
72
72
  this.device = device;
73
73
  }
74
74
 
75
- // addDefaultModule(module: ShaderModule): void {
76
- // if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {
77
- // this._defaultModules.push(module);
78
- // }
79
- // this.stateHash++;
80
- // }
75
+ addDefaultModule(module: ShaderModule): void {
76
+ if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {
77
+ this._defaultModules.push(module);
78
+ }
79
+ this.stateHash++;
80
+ }
81
81
 
82
- // removeDefaultModule(module: ShaderModule): void {
83
- // const moduleName = typeof module === 'string' ? module : module.name;
84
- // this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
85
- // this.stateHash++;
86
- // }
82
+ removeDefaultModule(module: ShaderModule): void {
83
+ const moduleName = typeof module === 'string' ? module : module.name;
84
+ this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
85
+ this.stateHash++;
86
+ }
87
87
 
88
88
  addShaderHook(hook, opts?): void {
89
89
  if (opts) {
@@ -94,7 +94,7 @@ export default class PipelineFactory {
94
94
  }
95
95
 
96
96
  createRenderPipeline(options: GetRenderPipelineOptions): {
97
- renderPipeline: RenderPipeline;
97
+ pipeline: RenderPipeline;
98
98
  getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;
99
99
  } {
100
100
  const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};
@@ -104,9 +104,9 @@ export default class PipelineFactory {
104
104
  const hash = this._hashRenderPipeline({...props, modules});
105
105
 
106
106
  if (!this._pipelineCache[hash]) {
107
- const {renderPipeline, getUniforms} = this._createRenderPipeline({...props, modules});
108
- renderPipeline.hash = hash;
109
- this._pipelineCache[hash] = renderPipeline;
107
+ const {pipeline, getUniforms} = this._createRenderPipeline({...props, modules});
108
+ pipeline.hash = hash;
109
+ this._pipelineCache[hash] = pipeline;
110
110
  this._getUniforms[hash] = getUniforms || ((x: Record<string, Record<string, any>>) => {});
111
111
  this._useCounts[hash] = 0;
112
112
  }
@@ -114,7 +114,7 @@ export default class PipelineFactory {
114
114
  this._useCounts[hash]++;
115
115
 
116
116
  return {
117
- renderPipeline: this._pipelineCache[hash],
117
+ pipeline: this._pipelineCache[hash],
118
118
  getUniforms: this._getUniforms[hash]
119
119
  };
120
120
  }
@@ -137,7 +137,7 @@ export default class PipelineFactory {
137
137
  // PRIVATE
138
138
 
139
139
  _createRenderPipeline(props: GetRenderPipelineOptions): {
140
- renderPipeline: RenderPipeline,
140
+ pipeline: RenderPipeline,
141
141
  getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>
142
142
  } {
143
143
  const platformInfo = {
@@ -147,13 +147,13 @@ export default class PipelineFactory {
147
147
 
148
148
  const assembled = assembleShaders(platformInfo, {...props, hookFunctions: this._hookFunctions});
149
149
 
150
- const renderPipeline = this.device.createRenderPipeline({
150
+ const pipeline = this.device.createRenderPipeline({
151
151
  ...props,
152
152
  vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),
153
153
  fs: assembled.fs && this.device.createShader({stage: 'fragment', source: assembled.fs}),
154
154
  });
155
155
 
156
- return {renderPipeline, getUniforms: assembled.getUniforms};
156
+ return {pipeline, getUniforms: assembled.getUniforms};
157
157
  }
158
158
 
159
159
  /** Calculate a hash based on all the inputs for a render pipeline */
@@ -166,12 +166,12 @@ export default class PipelineFactory {
166
166
 
167
167
  const defineKeys = Object.keys(props.defines).sort();
168
168
  const injectKeys = Object.keys(props.inject).sort();
169
- const defineHashes = [];
170
- const injectHashes = [];
169
+ const defineHashes: number[] = [];
170
+ const injectHashes: number[] = [];
171
171
 
172
172
  for (const key of defineKeys) {
173
173
  defineHashes.push(this._getHash(key));
174
- defineHashes.push(this._getHash(props.defines[key]));
174
+ defineHashes.push(this._getHash(String(props.defines[key])));
175
175
  }
176
176
 
177
177
  for (const key of injectKeys) {
@@ -1,6 +1,6 @@
1
1
  import type {DeviceProps} from '@luma.gl/api';
2
2
  import type {AnimationProps} from '../lib/animation-props';
3
- import AnimationLoop from './animation-loop';
3
+ import {AnimationLoop} from './animation-loop';
4
4
 
5
5
  /**
6
6
  * Minimal animation loop that initializes models in constructor