@luma.gl/engine 9.0.0-alpha.5 → 9.0.0-alpha.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/LICENSE +3 -1
  2. package/dist/animation/key-frames.d.ts +1 -1
  3. package/dist/animation/key-frames.d.ts.map +1 -1
  4. package/dist/animation/key-frames.js +6 -27
  5. package/dist/animation/key-frames.js.map +1 -1
  6. package/dist/animation/timeline.d.ts +9 -9
  7. package/dist/animation/timeline.d.ts.map +1 -1
  8. package/dist/animation/timeline.js +18 -49
  9. package/dist/animation/timeline.js.map +1 -1
  10. package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -31
  11. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  12. package/dist/{lib → animation-loop}/animation-loop.js +115 -199
  13. package/dist/animation-loop/animation-loop.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-props.d.ts +6 -7
  15. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  16. package/dist/animation-loop/animation-props.js.map +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  19. package/dist/animation-loop/make-animation-loop.js +28 -0
  20. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  21. package/dist/animation-loop/render-loop.d.ts +23 -0
  22. package/dist/animation-loop/render-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/render-loop.js +7 -0
  24. package/dist/animation-loop/render-loop.js.map +1 -0
  25. package/dist/dist.dev.js +7064 -0
  26. package/dist/geometries/cone-geometry.d.ts +1 -1
  27. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/cone-geometry.js +6 -5
  29. package/dist/geometries/cone-geometry.js.map +1 -1
  30. package/dist/geometries/cube-geometry.d.ts +2 -2
  31. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  32. package/dist/geometries/cube-geometry.js +15 -8
  33. package/dist/geometries/cube-geometry.js.map +1 -1
  34. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  35. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  36. package/dist/geometries/cylinder-geometry.js +6 -5
  37. package/dist/geometries/cylinder-geometry.js.map +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  39. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  40. package/dist/geometries/ico-sphere-geometry.js +10 -19
  41. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  42. package/dist/geometries/plane-geometry.d.ts +2 -2
  43. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  44. package/dist/geometries/plane-geometry.js +14 -23
  45. package/dist/geometries/plane-geometry.js.map +1 -1
  46. package/dist/geometries/sphere-geometry.d.ts +2 -2
  47. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  48. package/dist/geometries/sphere-geometry.js +9 -13
  49. package/dist/geometries/sphere-geometry.js.map +1 -1
  50. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  51. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  52. package/dist/geometries/truncated-cone-geometry.js +9 -25
  53. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  54. package/dist/geometry/geometry-table.d.ts +2 -2
  55. package/dist/geometry/geometry-table.d.ts.map +1 -1
  56. package/dist/geometry/geometry-table.js.map +1 -1
  57. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  58. package/dist/geometry/geometry-utils.js +0 -9
  59. package/dist/geometry/geometry-utils.js.map +1 -1
  60. package/dist/geometry/geometry.d.ts +50 -59
  61. package/dist/geometry/geometry.d.ts.map +1 -1
  62. package/dist/geometry/geometry.js +32 -97
  63. package/dist/geometry/geometry.js.map +1 -1
  64. package/dist/geometry/gpu-geometry.d.ts +37 -0
  65. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  66. package/dist/geometry/gpu-geometry.js +107 -0
  67. package/dist/geometry/gpu-geometry.js.map +1 -0
  68. package/dist/geometry/gpu-table.d.ts +1 -0
  69. package/dist/geometry/gpu-table.d.ts.map +1 -0
  70. package/dist/geometry/gpu-table.js +2 -0
  71. package/dist/geometry/gpu-table.js.map +1 -0
  72. package/dist/index.cjs +2959 -0
  73. package/dist/index.d.ts +26 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +23 -13
  76. package/dist/index.js.map +1 -1
  77. package/dist/lib/clip-space.d.ts +8 -0
  78. package/dist/lib/clip-space.d.ts.map +1 -1
  79. package/dist/lib/clip-space.js +47 -0
  80. package/dist/lib/clip-space.js.map +1 -1
  81. package/dist/lib/pipeline-factory.d.ts +12 -40
  82. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  83. package/dist/lib/pipeline-factory.js +50 -148
  84. package/dist/lib/pipeline-factory.js.map +1 -1
  85. package/dist/model/model.d.ts +192 -0
  86. package/dist/model/model.d.ts.map +1 -0
  87. package/dist/model/model.js +312 -0
  88. package/dist/model/model.js.map +1 -0
  89. package/dist/scenegraph/group-node.d.ts +21 -0
  90. package/dist/scenegraph/group-node.d.ts.map +1 -0
  91. package/dist/scenegraph/group-node.js +94 -0
  92. package/dist/scenegraph/group-node.js.map +1 -0
  93. package/dist/scenegraph/model-node.d.ts +18 -0
  94. package/dist/scenegraph/model-node.d.ts.map +1 -0
  95. package/dist/scenegraph/model-node.js +28 -0
  96. package/dist/scenegraph/model-node.js.map +1 -0
  97. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  98. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  99. package/dist/scenegraph/scenegraph-node.js +141 -0
  100. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  101. package/dist/shader-inputs.d.ts +62 -0
  102. package/dist/shader-inputs.d.ts.map +1 -0
  103. package/dist/shader-inputs.js +49 -0
  104. package/dist/shader-inputs.js.map +1 -0
  105. package/dist/transform/buffer-transform.d.ts +35 -0
  106. package/dist/transform/buffer-transform.d.ts.map +1 -0
  107. package/dist/transform/buffer-transform.js +62 -0
  108. package/dist/transform/buffer-transform.js.map +1 -0
  109. package/dist/transform/texture-transform.d.ts +57 -0
  110. package/dist/transform/texture-transform.d.ts.map +1 -0
  111. package/dist/transform/texture-transform.js +122 -0
  112. package/dist/transform/texture-transform.js.map +1 -0
  113. package/dist.min.js +286 -0
  114. package/package.json +21 -12
  115. package/src/animation/timeline.ts +16 -15
  116. package/src/{lib → animation-loop}/animation-loop.ts +120 -107
  117. package/src/{lib → animation-loop}/animation-props.ts +5 -5
  118. package/src/animation-loop/make-animation-loop.ts +44 -0
  119. package/src/animation-loop/render-loop.ts +23 -0
  120. package/src/geometries/cone-geometry.ts +1 -1
  121. package/src/geometries/cube-geometry.ts +6 -3
  122. package/src/geometries/cylinder-geometry.ts +2 -2
  123. package/src/geometries/ico-sphere-geometry.ts +7 -6
  124. package/src/geometries/plane-geometry.ts +5 -4
  125. package/src/geometries/sphere-geometry.ts +4 -3
  126. package/src/geometries/truncated-cone-geometry.ts +4 -13
  127. package/src/geometry/geometry-table.ts +1 -1
  128. package/src/geometry/geometry-utils.ts +3 -3
  129. package/src/geometry/geometry.ts +79 -119
  130. package/src/geometry/gpu-geometry.ts +124 -0
  131. package/src/geometry/gpu-table.ts +41 -0
  132. package/src/index.ts +38 -12
  133. package/src/lib/clip-space.ts +22 -21
  134. package/src/lib/pipeline-factory.ts +60 -168
  135. package/src/model/model.ts +549 -0
  136. package/src/scenegraph/group-node.ts +103 -0
  137. package/src/scenegraph/model-node.ts +50 -0
  138. package/src/scenegraph/scenegraph-node.ts +204 -0
  139. package/src/shader-inputs.ts +132 -0
  140. package/src/transform/buffer-transform.ts +94 -0
  141. package/src/transform/texture-transform.ts +169 -0
  142. package/dist/bundle.d.ts +0 -2
  143. package/dist/bundle.d.ts.map +0 -1
  144. package/dist/bundle.js +0 -5
  145. package/dist/bundle.js.map +0 -1
  146. package/dist/geometry/primitive-utils.d.ts +0 -1
  147. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  148. package/dist/geometry/primitive-utils.js +0 -2
  149. package/dist/geometry/primitive-utils.js.map +0 -1
  150. package/dist/lib/animation-loop.d.ts.map +0 -1
  151. package/dist/lib/animation-loop.js.map +0 -1
  152. package/dist/lib/animation-props.d.ts.map +0 -1
  153. package/dist/lib/animation-props.js.map +0 -1
  154. package/dist/lib/model-utils.d.ts +0 -5
  155. package/dist/lib/model-utils.d.ts.map +0 -1
  156. package/dist/lib/model-utils.js +0 -45
  157. package/dist/lib/model-utils.js.map +0 -1
  158. package/dist/lib/model.d.ts +0 -41
  159. package/dist/lib/model.d.ts.map +0 -1
  160. package/dist/lib/model.js +0 -176
  161. package/dist/lib/model.js.map +0 -1
  162. package/dist/lib/render-loop.d.ts +0 -14
  163. package/dist/lib/render-loop.d.ts.map +0 -1
  164. package/dist/lib/render-loop.js +0 -49
  165. package/dist/lib/render-loop.js.map +0 -1
  166. package/src/bundle.ts +0 -4
  167. package/src/geometry/primitive-utils.ts +0 -30
  168. package/src/lib/model-utils.ts +0 -124
  169. package/src/lib/model.ts +0 -179
  170. package/src/lib/render-loop.ts +0 -58
  171. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
package/src/index.ts CHANGED
@@ -1,16 +1,43 @@
1
1
  // luma.gl Engine API
2
- export type {AnimationProps} from './lib/animation-props';
3
- export {RenderLoop} from './lib/render-loop';
4
- export type {ModelProps} from './lib/model';
5
- export {default as Model} from './lib/model';
6
- export type {AnimationLoopProps} from './lib/animation-loop';
7
- export {default as AnimationLoop} from './lib/animation-loop';
2
+
3
+ // Animation
4
+ export {Timeline} from './animation/timeline';
5
+ export {KeyFrames} from './animation/key-frames';
6
+ export type {AnimationProps} from './animation-loop/animation-props';
7
+
8
+ export {AnimationLoopTemplate} from './animation-loop/render-loop';
9
+
10
+ export type {AnimationLoopProps} from './animation-loop/animation-loop';
11
+ export {AnimationLoop} from './animation-loop/animation-loop';
12
+
13
+ export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
14
+ export {makeAnimationLoop} from './animation-loop/make-animation-loop';
15
+
16
+ export type {ModelProps} from './model/model';
17
+ export {Model} from './model/model';
18
+
19
+ // Transforms
20
+ export type {BufferTransformProps} from './transform/buffer-transform';
21
+ export {BufferTransform} from './transform/buffer-transform';
22
+ export type {TextureTransformProps} from './transform/texture-transform';
23
+ export {TextureTransform} from './transform/texture-transform';
24
+
25
+ export {PipelineFactory} from './lib/pipeline-factory';
8
26
 
9
27
  // Utils
10
- // export {default as ClipSpace} from './lib/clip-space';
28
+ export {ClipSpace} from './lib/clip-space';
29
+
30
+ // Scenegraph Core nodes
31
+ export {ScenegraphNode} from './scenegraph/scenegraph-node';
32
+ export {GroupNode} from './scenegraph/group-node';
33
+ export type {ModelNodeProps} from './scenegraph/model-node';
34
+ export {ModelNode} from './scenegraph/model-node';
11
35
 
12
36
  // Geometries
13
- export {default as Geometry} from './geometry/geometry';
37
+ export type {GeometryProps} from './geometry/geometry';
38
+ export {Geometry} from './geometry/geometry';
39
+ export type {GPUGeometryProps} from './geometry/gpu-geometry';
40
+ export {GPUGeometry} from './geometry/gpu-geometry';
14
41
 
15
42
  // Primitives
16
43
  export type {ConeGeometryProps} from './geometries/cone-geometry';
@@ -28,7 +55,6 @@ export {SphereGeometry} from './geometries/sphere-geometry';
28
55
  export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
29
56
  export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
30
57
 
31
- // Animation
32
- export {Timeline} from './animation/timeline';
33
- export {KeyFrames} from './animation/key-frames';
34
-
58
+ // EXPERIMENTAL
59
+ export type {ShaderModuleInputs} from './shader-inputs';
60
+ export {ShaderInputs as _ShaderInputs} from './shader-inputs';
@@ -1,18 +1,17 @@
1
1
 
2
2
  // ClipSpace
3
- /*
4
- import GL from '@luma.gl/constants';
5
- import Model, {ModelProps} from './model';
6
- import Geometry from '../geometry/geometry';
3
+ import {Device, glsl} from '@luma.gl/core';
4
+ import {Model, ModelProps} from '../model/model';
5
+ import {Geometry} from '../geometry/geometry';
7
6
 
8
- const CLIPSPACE_VERTEX_SHADER = `\
9
- attribute vec2 aClipSpacePosition;
10
- attribute vec2 aTexCoord;
11
- attribute vec2 aCoordinate;
7
+ const CLIPSPACE_VERTEX_SHADER = glsl`\
8
+ in vec2 aClipSpacePosition;
9
+ in vec2 aTexCoord;
10
+ in vec2 aCoordinate;
12
11
 
13
- varying vec2 position;
14
- varying vec2 coordinate;
15
- varying vec2 uv;
12
+ out vec2 position;
13
+ out vec2 coordinate;
14
+ out vec2 uv;
16
15
 
17
16
  void main(void) {
18
17
  gl_Position = vec4(aClipSpacePosition, 0., 1.);
@@ -22,20 +21,24 @@ void main(void) {
22
21
  }
23
22
  `;
24
23
 
25
- /* eslint-disable indent, no-multi-spaces *
24
+ /* eslint-disable indent, no-multi-spaces */
26
25
  const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
27
26
 
28
-
29
- export default class ClipSpace extends Model {
30
- constructor(gl: WebGLRenderingContext, opts?: ModelProps) {
27
+ /**
28
+ * A flat geometry that covers the "visible area" that the GPU renders.
29
+ */
30
+ export class ClipSpace extends Model {
31
+ constructor(device: Device, opts?: ModelProps) {
31
32
  const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));
32
33
 
33
34
  super(
34
- gl,
35
- Object.assign({}, opts, {
35
+ device,
36
+ {
37
+ ...opts,
36
38
  vs: CLIPSPACE_VERTEX_SHADER,
39
+ vertexCount: 4,
37
40
  geometry: new Geometry({
38
- drawMode: GL.TRIANGLE_STRIP,
41
+ topology: 'triangle-strip',
39
42
  vertexCount: 4,
40
43
  attributes: {
41
44
  aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
@@ -43,9 +46,7 @@ export default class ClipSpace extends Model {
43
46
  aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
44
47
  }
45
48
  })
46
- })
49
+ }
47
50
  );
48
- this.setVertexCount(4);
49
51
  }
50
52
  }
51
- */
@@ -1,122 +1,60 @@
1
- import type {RenderPipelineProps, RenderPipelineParameters} from '@luma.gl/api';
2
- import {Device, RenderPipeline, ComputePipeline} from '@luma.gl/api/';
3
- import type { ShaderModule } from '@luma.gl/shadertools';
4
- import {assembleShaders} from '@luma.gl/shadertools';
5
-
6
- export type GetRenderPipelineOptions = {
7
- vs: string,
8
- fs: string,
9
- topology;
10
- parameters?: RenderPipelineParameters;
11
-
12
- modules?: ShaderModule[];
13
- defines?: Record<string, string>,
14
- inject?: Record<string, string>,
15
- transpileToGLSL100?: boolean;
16
-
17
- varyings?: string[],
18
- bufferMode?: number,
1
+ // luma.gl, MIT license
2
+ import type {RenderPipelineProps} from '@luma.gl/core';
3
+ import {Device, RenderPipeline} from '@luma.gl/core';
4
+
5
+ /** Todo - should be same as RenderPipelineProps */
6
+ export type PipelineFactoryProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
7
+ // Only accepts string shaders
8
+ vs: string;
9
+ fs: string;
19
10
  };
20
11
 
21
- export type GetComputePipelineOptions = {
22
- cs: string,
23
- parameters?: RenderPipelineParameters;
24
-
25
- modules?: ShaderModule[];
26
- defines?: Record<string, string>,
27
- inject?: Record<string, string>,
28
- transpileToGLSL100?: boolean;
29
-
30
- varyings?: string[],
31
- bufferMode?: number,
32
- };
33
-
34
- const DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {
35
- vs: '',
36
- fs: '',
37
- modules: [],
38
- defines: {},
39
- inject: {},
40
- transpileToGLSL100: false,
41
-
42
- varyings: [],
43
- bufferMode: 0x8c8d, // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS
44
- topology: 'triangle-list',
45
- parameters: {}
46
- };
12
+ /**
13
+ * Efficiently creates / caches pipelines
14
+ */
15
+ export class PipelineFactory {
16
+ static defaultProps: Required<PipelineFactoryProps> = {
17
+ ...RenderPipeline.defaultProps,
18
+ vs: undefined!,
19
+ fs: undefined!
20
+ }
47
21
 
48
- /** Efficiently create shared pipelines with varying parameters */
49
- export default class PipelineFactory {
50
22
  readonly device: Device;
51
23
 
52
- stateHash: number = 0; // Used to change hashing if hooks are modified
53
24
  private _hashCounter: number = 0;
54
25
  private readonly _hashes: Record<string, number> = {};
55
26
  private readonly _useCounts: Record<string, number> = {};
56
-
57
27
  private readonly _pipelineCache: Record<string, RenderPipeline> = {};
58
28
 
59
- private readonly _getUniforms: Record<string, any> = {};
60
- private readonly _hookFunctions: any[] = [];
61
- private _defaultModules: any[] = [];
62
- // private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl
63
-
64
29
  static getDefaultPipelineFactory(device: Device): PipelineFactory {
65
- // @ts-expect-error Add to device
66
- device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);
67
- // @ts-expect-error Add to device
68
- return device.defaultPipelineFactory;
30
+ device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
31
+ return device._lumaData.defaultPipelineFactory as PipelineFactory;
69
32
  }
70
33
 
71
34
  constructor(device: Device) {
72
35
  this.device = device;
73
36
  }
74
37
 
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
-
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
-
88
- addShaderHook(hook, opts?): void {
89
- if (opts) {
90
- hook = Object.assign(opts, {hook});
91
- }
92
- this._hookFunctions.push(hook);
93
- this.stateHash++;
94
- }
95
-
96
- createRenderPipeline(options: GetRenderPipelineOptions): {
97
- renderPipeline: RenderPipeline;
98
- getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>;
99
- } {
100
- const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};
101
-
102
- const modules = this._getModuleList(props.modules); // Combine with default modules
38
+ createRenderPipeline(options: PipelineFactoryProps): RenderPipeline {
39
+ const props: Required<PipelineFactoryProps> = {...PipelineFactory.defaultProps, ...options};
103
40
 
104
- const hash = this._hashRenderPipeline({...props, modules});
41
+ const hash = this._hashRenderPipeline({...props});
105
42
 
106
43
  if (!this._pipelineCache[hash]) {
107
- const {renderPipeline, getUniforms} = this._createRenderPipeline({...props, modules});
108
- renderPipeline.hash = hash;
109
- this._pipelineCache[hash] = renderPipeline;
110
- this._getUniforms[hash] = getUniforms || ((x: Record<string, Record<string, any>>) => {});
44
+ const pipeline = this.device.createRenderPipeline({
45
+ ...props,
46
+ vs: this.device.createShader({stage: 'vertex', source: props.vs}),
47
+ fs: props.fs ? this.device.createShader({stage: 'fragment', source: props.fs}) : null,
48
+ });
49
+
50
+ pipeline.hash = hash;
51
+ this._pipelineCache[hash] = pipeline;
111
52
  this._useCounts[hash] = 0;
112
53
  }
113
54
 
114
55
  this._useCounts[hash]++;
115
56
 
116
- return {
117
- renderPipeline: this._pipelineCache[hash],
118
- getUniforms: this._getUniforms[hash]
119
- };
57
+ return this._pipelineCache[hash];
120
58
  }
121
59
 
122
60
  release(pipeline: RenderPipeline): void {
@@ -125,68 +63,48 @@ export default class PipelineFactory {
125
63
  if (this._useCounts[hash] === 0) {
126
64
  this._pipelineCache[hash].destroy();
127
65
  delete this._pipelineCache[hash];
128
- delete this._getUniforms[hash];
129
66
  delete this._useCounts[hash];
130
67
  }
131
68
  }
132
69
 
133
- getUniforms(pipeline: RenderPipeline) {
134
- return this._getUniforms[pipeline.hash] || null;
135
- }
136
-
137
70
  // PRIVATE
138
71
 
139
- _createRenderPipeline(props: GetRenderPipelineOptions): {
140
- renderPipeline: RenderPipeline,
141
- getUniforms: (props: Record<string, Record<string, any>>) => Record<string, any>
142
- } {
143
- const platformInfo = {
144
- gpu: this.device.info.gpu,
145
- features: this.device.features
146
- };
147
-
148
- const assembled = assembleShaders(platformInfo, {...props, hookFunctions: this._hookFunctions});
72
+ _createRenderPipeline(props: PipelineFactoryProps): RenderPipeline {
73
+ if (!props.fs) {
74
+ throw new Error('fs');
75
+ }
149
76
 
150
- const renderPipeline = this.device.createRenderPipeline({
77
+ const pipeline = this.device.createRenderPipeline({
151
78
  ...props,
152
- vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),
153
- fs: assembled.fs && this.device.createShader({stage: 'fragment', source: assembled.fs}),
79
+ vs: this.device.createShader({stage: 'vertex', source: props.vs}),
80
+ fs: props.fs ? this.device.createShader({stage: 'fragment', source: props.fs}) : null,
154
81
  });
155
82
 
156
- return {renderPipeline, getUniforms: assembled.getUniforms};
83
+ return pipeline;
157
84
  }
158
85
 
159
86
  /** Calculate a hash based on all the inputs for a render pipeline */
160
- _hashRenderPipeline(props: GetRenderPipelineOptions): string {
87
+ _hashRenderPipeline(props: PipelineFactoryProps): string {
161
88
  const vsHash = this._getHash(props.vs);
162
- const fsHash = this._getHash(props.fs);
163
-
164
- const moduleHashes = props.modules.map((m) => this._getHash(typeof m === 'string' ? m : m.name)).sort();
165
- const varyingHashes = props.varyings.map((v) => this._getHash(v));
166
-
167
- const defineKeys = Object.keys(props.defines).sort();
168
- const injectKeys = Object.keys(props.inject).sort();
169
- const defineHashes = [];
170
- const injectHashes = [];
171
-
172
- for (const key of defineKeys) {
173
- defineHashes.push(this._getHash(key));
174
- defineHashes.push(this._getHash(props.defines[key]));
175
- }
176
-
177
- for (const key of injectKeys) {
178
- injectHashes.push(this._getHash(key));
179
- injectHashes.push(this._getHash(props.inject[key]));
89
+ const fsHash = props.fs ? this._getHash(props.fs) : 0;
90
+
91
+ // WebGL specific
92
+ // const {varyings = [], bufferMode = {}} = props;
93
+ // const varyingHashes = varyings.map((v) => this._getHash(v));
94
+ const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
95
+
96
+ switch (this.device.info.type) {
97
+ case 'webgpu':
98
+ // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
99
+ const parameterHash = this._getHash(JSON.stringify(props.parameters));
100
+ const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
101
+ // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
102
+ // create a deepHash() to deduplicate?
103
+ return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
104
+ default:
105
+ // WebGL is more dynamic
106
+ return `${vsHash}/${fsHash}V${varyingHash}`;
180
107
  }
181
-
182
- // TODO - hash parameters!
183
- const parameterHash = JSON.stringify(props.parameters);
184
-
185
- return `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(
186
- '/'
187
- )}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${props.bufferMode}${
188
- props.transpileToGLSL100 ? 'T' : ''
189
- }P${parameterHash}`;
190
108
  }
191
109
 
192
110
  _getHash(key: string): number {
@@ -195,31 +113,5 @@ export default class PipelineFactory {
195
113
  }
196
114
  return this._hashes[key];
197
115
  }
198
-
199
- // Dedupe and combine with default modules
200
- _getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {
201
- const modules = new Array(this._defaultModules.length + appModules.length);
202
- const seen: Record<string, boolean> = {};
203
- let count = 0;
204
-
205
- for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
206
- const module = this._defaultModules[i];
207
- const name = module.name;
208
- modules[count++] = module;
209
- seen[name] = true;
210
- }
211
-
212
- for (let i = 0, len = appModules.length; i < len; ++i) {
213
- const module = appModules[i];
214
- const name = module.name;
215
- if (!seen[name]) {
216
- modules[count++] = module;
217
- seen[name] = true;
218
- }
219
- }
220
-
221
- modules.length = count;
222
-
223
- return modules;
224
- }
225
116
  }
117
+