@luma.gl/engine 9.1.0-alpha.9 → 9.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/animation/key-frames.js +1 -0
  2. package/dist/animation/key-frames.js.map +1 -0
  3. package/dist/animation/timeline.js +1 -0
  4. package/dist/animation/timeline.js.map +1 -0
  5. package/dist/animation-loop/animation-loop-template.js +1 -0
  6. package/dist/animation-loop/animation-loop-template.js.map +1 -0
  7. package/dist/animation-loop/animation-loop.d.ts +2 -0
  8. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  9. package/dist/animation-loop/animation-loop.js +24 -6
  10. package/dist/animation-loop/animation-loop.js.map +1 -0
  11. package/dist/animation-loop/animation-props.js +1 -0
  12. package/dist/animation-loop/animation-props.js.map +1 -0
  13. package/dist/animation-loop/make-animation-loop.d.ts +5 -1
  14. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  15. package/dist/animation-loop/make-animation-loop.js +3 -1
  16. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  17. package/dist/animation-loop/request-animation-frame.d.ts +4 -2
  18. package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
  19. package/dist/animation-loop/request-animation-frame.js +5 -3
  20. package/dist/animation-loop/request-animation-frame.js.map +1 -0
  21. package/dist/application-utils/load-file.d.ts +1 -1
  22. package/dist/application-utils/load-file.d.ts.map +1 -1
  23. package/dist/application-utils/load-file.js +2 -2
  24. package/dist/application-utils/load-file.js.map +1 -0
  25. package/dist/application-utils/random.js +1 -0
  26. package/dist/application-utils/random.js.map +1 -0
  27. package/dist/async-texture/async-texture.d.ts +14 -2
  28. package/dist/async-texture/async-texture.d.ts.map +1 -1
  29. package/dist/async-texture/async-texture.js +31 -0
  30. package/dist/async-texture/async-texture.js.map +1 -0
  31. package/dist/compute/buffer-transform.d.ts +41 -0
  32. package/dist/compute/buffer-transform.d.ts.map +1 -0
  33. package/dist/{transform → compute}/buffer-transform.js +19 -12
  34. package/dist/compute/buffer-transform.js.map +1 -0
  35. package/dist/{computation.d.ts → compute/computation.d.ts} +3 -3
  36. package/dist/compute/computation.d.ts.map +1 -0
  37. package/dist/{computation.js → compute/computation.js} +7 -8
  38. package/dist/compute/computation.js.map +1 -0
  39. package/dist/compute/swap.d.ts +48 -0
  40. package/dist/compute/swap.d.ts.map +1 -0
  41. package/dist/compute/swap.js +91 -0
  42. package/dist/compute/swap.js.map +1 -0
  43. package/dist/{transform → compute}/texture-transform.d.ts +0 -6
  44. package/dist/compute/texture-transform.d.ts.map +1 -0
  45. package/dist/{transform → compute}/texture-transform.js +10 -15
  46. package/dist/compute/texture-transform.js.map +1 -0
  47. package/dist/debug/copy-texture-to-image.js +1 -0
  48. package/dist/debug/copy-texture-to-image.js.map +1 -0
  49. package/dist/debug/debug-framebuffer.js +2 -1
  50. package/dist/debug/debug-framebuffer.js.map +1 -0
  51. package/dist/debug/debug-shader-layout.js +2 -1
  52. package/dist/debug/debug-shader-layout.js.map +1 -0
  53. package/dist/debug/pixel-data-utils.js +1 -0
  54. package/dist/debug/pixel-data-utils.js.map +1 -0
  55. package/dist/dist.dev.js +2697 -5857
  56. package/dist/dist.min.js +420 -103
  57. package/dist/{lib → factories}/pipeline-factory.d.ts +11 -1
  58. package/dist/factories/pipeline-factory.d.ts.map +1 -0
  59. package/dist/factories/pipeline-factory.js +181 -0
  60. package/dist/factories/pipeline-factory.js.map +1 -0
  61. package/dist/{lib → factories}/shader-factory.d.ts +5 -1
  62. package/dist/factories/shader-factory.d.ts.map +1 -0
  63. package/dist/{lib → factories}/shader-factory.js +39 -4
  64. package/dist/factories/shader-factory.js.map +1 -0
  65. package/dist/geometries/cone-geometry.js +1 -0
  66. package/dist/geometries/cone-geometry.js.map +1 -0
  67. package/dist/geometries/cube-geometry.js +1 -0
  68. package/dist/geometries/cube-geometry.js.map +1 -0
  69. package/dist/geometries/cylinder-geometry.js +1 -0
  70. package/dist/geometries/cylinder-geometry.js.map +1 -0
  71. package/dist/geometries/ico-sphere-geometry.js +1 -0
  72. package/dist/geometries/ico-sphere-geometry.js.map +1 -0
  73. package/dist/geometries/plane-geometry.js +1 -0
  74. package/dist/geometries/plane-geometry.js.map +1 -0
  75. package/dist/geometries/sphere-geometry.js +1 -0
  76. package/dist/geometries/sphere-geometry.js.map +1 -0
  77. package/dist/geometries/truncated-cone-geometry.js +1 -0
  78. package/dist/geometries/truncated-cone-geometry.js.map +1 -0
  79. package/dist/geometry/geometry-table.js +1 -0
  80. package/dist/geometry/geometry-table.js.map +1 -0
  81. package/dist/geometry/geometry-utils.js +1 -0
  82. package/dist/geometry/geometry-utils.js.map +1 -0
  83. package/dist/geometry/geometry.js +1 -0
  84. package/dist/geometry/geometry.js.map +1 -0
  85. package/dist/geometry/gpu-geometry.js +1 -0
  86. package/dist/geometry/gpu-geometry.js.map +1 -0
  87. package/dist/geometry/gpu-table.js +1 -0
  88. package/dist/geometry/gpu-table.js.map +1 -0
  89. package/dist/index.cjs +1416 -209
  90. package/dist/index.cjs.map +4 -4
  91. package/dist/index.d.ts +23 -12
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +19 -9
  94. package/dist/index.js.map +1 -0
  95. package/dist/model/model.d.ts +11 -10
  96. package/dist/model/model.d.ts.map +1 -1
  97. package/dist/model/model.js +93 -70
  98. package/dist/model/model.js.map +1 -0
  99. package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
  100. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  101. package/dist/model/split-uniforms-and-bindings.js +2 -1
  102. package/dist/model/split-uniforms-and-bindings.js.map +1 -0
  103. package/dist/models/billboard-texture-model.d.ts +23 -0
  104. package/dist/models/billboard-texture-model.d.ts.map +1 -0
  105. package/dist/models/billboard-texture-model.js +78 -0
  106. package/dist/models/billboard-texture-model.js.map +1 -0
  107. package/dist/models/billboard-texture-module.d.ts +10 -0
  108. package/dist/models/billboard-texture-module.d.ts.map +1 -0
  109. package/dist/models/billboard-texture-module.js +37 -0
  110. package/dist/models/billboard-texture-module.js.map +1 -0
  111. package/dist/{lib → models}/clip-space.d.ts +3 -1
  112. package/dist/models/clip-space.d.ts.map +1 -0
  113. package/dist/models/clip-space.js +77 -0
  114. package/dist/models/clip-space.js.map +1 -0
  115. package/dist/modules/picking/color-picking.d.ts +28 -0
  116. package/dist/modules/picking/color-picking.d.ts.map +1 -0
  117. package/dist/modules/picking/color-picking.js +177 -0
  118. package/dist/modules/picking/color-picking.js.map +1 -0
  119. package/dist/modules/picking/index-picking.d.ts +32 -0
  120. package/dist/modules/picking/index-picking.d.ts.map +1 -0
  121. package/dist/modules/picking/index-picking.js +148 -0
  122. package/dist/modules/picking/index-picking.js.map +1 -0
  123. package/dist/modules/picking/legacy-picking-manager.d.ts +27 -0
  124. package/dist/modules/picking/legacy-picking-manager.d.ts.map +1 -0
  125. package/dist/modules/picking/legacy-picking-manager.js +76 -0
  126. package/dist/modules/picking/legacy-picking-manager.js.map +1 -0
  127. package/dist/modules/picking/picking-manager.d.ts +45 -0
  128. package/dist/modules/picking/picking-manager.d.ts.map +1 -0
  129. package/dist/modules/picking/picking-manager.js +101 -0
  130. package/dist/modules/picking/picking-manager.js.map +1 -0
  131. package/dist/modules/picking/picking-uniforms.d.ts +79 -0
  132. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -0
  133. package/dist/modules/picking/picking-uniforms.js +109 -0
  134. package/dist/modules/picking/picking-uniforms.js.map +1 -0
  135. package/dist/passes/get-fragment-shader.d.ts +12 -0
  136. package/dist/passes/get-fragment-shader.d.ts.map +1 -0
  137. package/dist/passes/get-fragment-shader.js +117 -0
  138. package/dist/passes/get-fragment-shader.js.map +1 -0
  139. package/dist/passes/shader-pass-renderer.d.ts +63 -0
  140. package/dist/passes/shader-pass-renderer.d.ts.map +1 -0
  141. package/dist/passes/shader-pass-renderer.js +197 -0
  142. package/dist/passes/shader-pass-renderer.js.map +1 -0
  143. package/dist/scenegraph/group-node.js +1 -0
  144. package/dist/scenegraph/group-node.js.map +1 -0
  145. package/dist/scenegraph/model-node.js +1 -0
  146. package/dist/scenegraph/model-node.js.map +1 -0
  147. package/dist/scenegraph/scenegraph-node.js +1 -0
  148. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  149. package/dist/shader-inputs.d.ts +8 -21
  150. package/dist/shader-inputs.d.ts.map +1 -1
  151. package/dist/shader-inputs.js +15 -11
  152. package/dist/shader-inputs.js.map +1 -0
  153. package/dist/utils/deep-equal.js +1 -0
  154. package/dist/utils/deep-equal.js.map +1 -0
  155. package/dist/utils/uid.js +1 -0
  156. package/dist/utils/uid.js.map +1 -0
  157. package/package.json +6 -6
  158. package/src/animation-loop/animation-loop.ts +27 -6
  159. package/src/animation-loop/make-animation-loop.ts +8 -3
  160. package/src/animation-loop/request-animation-frame.ts +4 -3
  161. package/src/application-utils/load-file.ts +2 -4
  162. package/src/async-texture/async-texture.ts +39 -7
  163. package/src/{transform → compute}/buffer-transform.ts +30 -14
  164. package/src/{computation.ts → compute/computation.ts} +14 -8
  165. package/src/compute/swap.ts +116 -0
  166. package/src/{transform → compute}/texture-transform.ts +9 -18
  167. package/src/debug/debug-framebuffer.ts +1 -1
  168. package/src/debug/debug-shader-layout.ts +1 -1
  169. package/src/factories/pipeline-factory.ts +222 -0
  170. package/src/{lib → factories}/shader-factory.ts +41 -5
  171. package/src/index.ts +35 -16
  172. package/src/model/model.ts +133 -78
  173. package/src/model/split-uniforms-and-bindings.ts +4 -4
  174. package/src/models/billboard-texture-model.ts +98 -0
  175. package/src/models/billboard-texture-module.ts +49 -0
  176. package/src/models/clip-space.ts +88 -0
  177. package/src/modules/picking/README.md +88 -0
  178. package/src/modules/picking/color-picking.ts +190 -0
  179. package/src/modules/picking/index-picking.ts +156 -0
  180. package/src/modules/picking/legacy-picking-manager.ts +99 -0
  181. package/src/modules/picking/picking-manager.ts +137 -0
  182. package/src/modules/picking/picking-uniforms.ts +179 -0
  183. package/src/passes/get-fragment-shader.ts +129 -0
  184. package/src/passes/shader-pass-renderer.ts +252 -0
  185. package/src/shader-inputs.ts +27 -48
  186. package/dist/computation.d.ts.map +0 -1
  187. package/dist/lib/clip-space.d.ts.map +0 -1
  188. package/dist/lib/clip-space.js +0 -46
  189. package/dist/lib/pipeline-factory.d.ts.map +0 -1
  190. package/dist/lib/pipeline-factory.js +0 -98
  191. package/dist/lib/shader-factory.d.ts.map +0 -1
  192. package/dist/transform/buffer-transform.d.ts +0 -35
  193. package/dist/transform/buffer-transform.d.ts.map +0 -1
  194. package/dist/transform/texture-transform.d.ts.map +0 -1
  195. package/src/lib/clip-space.ts +0 -53
  196. package/src/lib/pipeline-factory.ts +0 -126
@@ -2,37 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {UniformValue, Texture, Sampler} from '@luma.gl/core';
5
+ import type {Binding, UniformValue} from '@luma.gl/core';
6
6
  import {log} from '@luma.gl/core';
7
7
  // import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
8
8
  import {getShaderModuleDependencies, ShaderModule} from '@luma.gl/shadertools';
9
9
  import {splitUniformsAndBindings} from './model/split-uniforms-and-bindings';
10
10
 
11
- type BindingValue = Buffer | Texture | Sampler;
12
-
13
- /** Minimal ShaderModule subset, we don't need shader code etc */
14
- export type ShaderModuleInputs<
15
- PropsT extends Record<string, unknown> = Record<string, unknown>,
16
- UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>,
17
- BindingsT extends Record<string, BindingValue> = Record<string, BindingValue>
18
- > = {
19
- defaultUniforms?: UniformsT;
20
- getUniforms?: (props?: any, oldProps?: any) => Record<string, BindingValue | UniformValue>;
21
-
22
- /** Not used. Used to access props type */
23
- props?: PropsT;
24
-
25
- bindings?: Record<
26
- keyof BindingsT,
27
- {
28
- location: number;
29
- type: 'texture' | 'sampler' | 'uniforms';
30
- }
31
- >;
32
-
33
- uniformTypes?: any;
34
- };
35
-
36
11
  /**
37
12
  * ShaderInputs holds uniform and binding values for one or more shader modules,
38
13
  * - It can generate binary data for any uniform buffer
@@ -50,12 +25,12 @@ export class ShaderInputs<
50
25
  * @todo should should this include the resolved dependencies?
51
26
  */
52
27
  // @ts-expect-error Fix typings
53
- modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModuleInputs<ShaderPropsT[P]>}>;
28
+ modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModule<ShaderPropsT[P]>}>;
54
29
 
55
30
  /** Stores the uniform values for each module */
56
31
  moduleUniforms: Record<keyof ShaderPropsT, Record<string, UniformValue>>;
57
32
  /** Stores the uniform bindings for each module */
58
- moduleBindings: Record<keyof ShaderPropsT, Record<string, Texture | Sampler>>;
33
+ moduleBindings: Record<keyof ShaderPropsT, Record<string, Binding>>;
59
34
  /** Tracks if uniforms have changed */
60
35
  // moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
61
36
 
@@ -64,7 +39,7 @@ export class ShaderInputs<
64
39
  * @param modules
65
40
  */
66
41
  // @ts-expect-error Fix typings
67
- constructor(modules: {[P in keyof ShaderPropsT]?: ShaderModuleInputs<ShaderPropsT[P]>}) {
42
+ constructor(modules: {[P in keyof ShaderPropsT]?: ShaderModule<ShaderPropsT[P], any>}) {
68
43
  // Extract modules with dependencies
69
44
  const resolvedModules = getShaderModuleDependencies(
70
45
  Object.values(modules).filter(module => module.dependencies)
@@ -78,17 +53,16 @@ export class ShaderInputs<
78
53
 
79
54
  // Store the module definitions and create storage for uniform values and binding values, per module
80
55
  // @ts-expect-error Fix typings
81
- this.modules = modules;
56
+ this.modules = modules as {[P in keyof ShaderPropsT]: ShaderModule<ShaderPropsT[P]>};
82
57
  this.moduleUniforms = {} as Record<keyof ShaderPropsT, Record<string, UniformValue>>;
83
- this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Texture | Sampler>>;
58
+ this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Binding>>;
84
59
 
85
60
  // Initialize the modules
86
61
  for (const [name, module] of Object.entries(modules)) {
87
- const moduleName = name as keyof ShaderPropsT;
88
-
89
- // Get default uniforms from module
90
- this.moduleUniforms[moduleName] = module.defaultUniforms || {};
91
- this.moduleBindings[moduleName] = {};
62
+ this._addModule(module);
63
+ if (module.name && name !== module.name) {
64
+ log.warn(`Module name: ${name} vs ${module.name}`)();
65
+ }
92
66
  }
93
67
  }
94
68
 
@@ -109,10 +83,10 @@ export class ShaderInputs<
109
83
  continue; // eslint-disable-line no-continue
110
84
  }
111
85
 
112
- const oldUniforms = this.moduleUniforms[moduleName];
86
+ const oldUniforms = this.moduleUniforms[moduleName] as (typeof module)['uniforms'];
113
87
  const oldBindings = this.moduleBindings[moduleName];
114
- let uniformsAndBindings = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]);
115
- uniformsAndBindings ||= {...this.moduleUniforms[moduleName], ...moduleProps};
88
+ const uniformsAndBindings =
89
+ module.getUniforms?.(moduleProps, oldUniforms) || (moduleProps as any);
116
90
 
117
91
  const {uniforms, bindings} = splitUniformsAndBindings(uniformsAndBindings);
118
92
  this.moduleUniforms[moduleName] = {...oldUniforms, ...uniforms};
@@ -123,11 +97,6 @@ export class ShaderInputs<
123
97
  }
124
98
  }
125
99
 
126
- /** Merges all bindings for the shader (from the various modules) */
127
- // getUniformBlocks(): Record<string, Texture | Sampler> {
128
- // return this.moduleUniforms;
129
- // }
130
-
131
100
  /**
132
101
  * Return the map of modules
133
102
  * @todo should should this include the resolved dependencies?
@@ -137,29 +106,39 @@ export class ShaderInputs<
137
106
  }
138
107
 
139
108
  /** Get all uniform values for all modules */
140
- getUniformValues(): Record<keyof ShaderPropsT, Record<string, UniformValue>> {
109
+ getUniformValues(): Partial<Record<keyof ShaderPropsT, Record<string, UniformValue>>> {
141
110
  return this.moduleUniforms;
142
111
  }
143
112
 
144
113
  /** Merges all bindings for the shader (from the various modules) */
145
- getBindings(): Record<string, Texture | Sampler> {
146
- const bindings = {} as Record<string, Texture | Sampler>;
114
+ getBindingValues(): Record<string, Binding> {
115
+ const bindings = {} as Record<string, Binding>;
147
116
  for (const moduleBindings of Object.values(this.moduleBindings)) {
148
117
  Object.assign(bindings, moduleBindings);
149
118
  }
150
119
  return bindings;
151
120
  }
152
121
 
122
+ // INTERNAL
123
+
124
+ /** Return a debug table that can be used for console.table() or log.table() */
153
125
  getDebugTable(): Record<string, Record<string, unknown>> {
154
126
  const table: Record<string, Record<string, unknown>> = {};
155
127
  for (const [moduleName, module] of Object.entries(this.moduleUniforms)) {
156
128
  for (const [key, value] of Object.entries(module)) {
157
129
  table[`${moduleName}.${key}`] = {
158
- type: this.modules[moduleName].uniformTypes?.[key],
130
+ type: this.modules[moduleName].uniformTypes?.[key as keyof ShaderPropsT],
159
131
  value: String(value)
160
132
  };
161
133
  }
162
134
  }
163
135
  return table;
164
136
  }
137
+
138
+ _addModule(module: ShaderModule): void {
139
+ const moduleName = module.name as keyof ShaderPropsT;
140
+ // Get default uniforms from module
141
+ this.moduleUniforms[moduleName] = module.defaultUniforms || {};
142
+ this.moduleBindings[moduleName] = {};
143
+ }
165
144
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"computation.d.ts","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,oBAAoB,EAAE,MAAM,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAGzF,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAC,eAAe,EAA0B,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAC,UAAU,EAAiB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,eAAe,EAAC,kCAA+B;AACvD,OAAO,EAAC,aAAa,EAAC,gCAA6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AS5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"clip-space.d.ts","sourceRoot":"","sources":["../../src/lib/clip-space.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,KAAK,EAAE,UAAU,EAAC,0BAAuB;AAwBjD;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,aAAa,GAAG,UAAU,CAAC;CAkBtF"}
@@ -1,46 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { Model } from "../model/model.js";
5
- import { Geometry } from "../geometry/geometry.js";
6
- const CLIPSPACE_VERTEX_SHADER = /* glsl */ `\
7
- #version 300 es
8
- in vec2 aClipSpacePosition;
9
- in vec2 aTexCoord;
10
- in vec2 aCoordinate;
11
-
12
- out vec2 position;
13
- out vec2 coordinate;
14
- out vec2 uv;
15
-
16
- void main(void) {
17
- gl_Position = vec4(aClipSpacePosition, 0., 1.);
18
- position = aClipSpacePosition;
19
- coordinate = aCoordinate;
20
- uv = aTexCoord;
21
- }
22
- `;
23
- /* eslint-disable indent, no-multi-spaces */
24
- const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
25
- /**
26
- * A flat geometry that covers the "visible area" that the GPU renders.
27
- */
28
- export class ClipSpace extends Model {
29
- constructor(device, opts) {
30
- const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord));
31
- super(device, {
32
- ...opts,
33
- vs: CLIPSPACE_VERTEX_SHADER,
34
- vertexCount: 4,
35
- geometry: new Geometry({
36
- topology: 'triangle-strip',
37
- vertexCount: 4,
38
- attributes: {
39
- aClipSpacePosition: { size: 2, value: new Float32Array(POSITIONS) },
40
- aTexCoord: { size: 2, value: new Float32Array(TEX_COORDS) },
41
- aCoordinate: { size: 2, value: new Float32Array(TEX_COORDS) }
42
- }
43
- })
44
- });
45
- }
46
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/lib/pipeline-factory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAEtE,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAKvD;;GAEG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAoC;IAEvF,0EAA0E;IAC1E,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe;IAMjE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO,CAAC;IAE3C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA+C;IACpF,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgD;gBAE1E,MAAM,EAAE,MAAM;IAK1B,4FAA4F;IAC5F,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,cAAc;IAkBhE,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe;IAkBnE,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI;IAczD,OAAO,CAAC,oBAAoB;IAK5B,qEAAqE;IACrE,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,QAAQ;CAMjB"}
@@ -1,98 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { RenderPipeline, ComputePipeline } from '@luma.gl/core';
5
- /**
6
- * Efficiently creates / caches pipelines
7
- */
8
- export class PipelineFactory {
9
- static defaultProps = { ...RenderPipeline.defaultProps };
10
- /** Get the singleton default pipeline factory for the specified device */
11
- static getDefaultPipelineFactory(device) {
12
- device._lumaData.defaultPipelineFactory =
13
- device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
14
- return device._lumaData.defaultPipelineFactory;
15
- }
16
- device;
17
- destroyPolicy;
18
- _hashCounter = 0;
19
- _hashes = {};
20
- _renderPipelineCache = {};
21
- _computePipelineCache = {};
22
- constructor(device) {
23
- this.device = device;
24
- this.destroyPolicy = device.props._factoryDestroyPolicy;
25
- }
26
- /** Return a RenderPipeline matching props. Reuses a similar pipeline if already created. */
27
- createRenderPipeline(props) {
28
- const allProps = { ...RenderPipeline.defaultProps, ...props };
29
- const hash = this._hashRenderPipeline(allProps);
30
- if (!this._renderPipelineCache[hash]) {
31
- const pipeline = this.device.createRenderPipeline({
32
- ...allProps,
33
- id: allProps.id ? `${allProps.id}-cached` : undefined
34
- });
35
- pipeline.hash = hash;
36
- this._renderPipelineCache[hash] = { pipeline, useCount: 0 };
37
- }
38
- this._renderPipelineCache[hash].useCount++;
39
- return this._renderPipelineCache[hash].pipeline;
40
- }
41
- createComputePipeline(props) {
42
- const allProps = { ...ComputePipeline.defaultProps, ...props };
43
- const hash = this._hashComputePipeline(allProps);
44
- if (!this._computePipelineCache[hash]) {
45
- const pipeline = this.device.createComputePipeline({
46
- ...allProps,
47
- id: allProps.id ? `${allProps.id}-cached` : undefined
48
- });
49
- pipeline.hash = hash;
50
- this._computePipelineCache[hash] = { pipeline, useCount: 0 };
51
- }
52
- this._computePipelineCache[hash].useCount++;
53
- return this._computePipelineCache[hash].pipeline;
54
- }
55
- release(pipeline) {
56
- const hash = pipeline.hash;
57
- const cache = pipeline instanceof ComputePipeline ? this._computePipelineCache : this._renderPipelineCache;
58
- cache[hash].useCount--;
59
- if (cache[hash].useCount === 0) {
60
- if (this.destroyPolicy === 'unused') {
61
- cache[hash].pipeline.destroy();
62
- delete cache[hash];
63
- }
64
- }
65
- }
66
- // PRIVATE
67
- _hashComputePipeline(props) {
68
- const shaderHash = this._getHash(props.shader.source);
69
- return `${shaderHash}`;
70
- }
71
- /** Calculate a hash based on all the inputs for a render pipeline */
72
- _hashRenderPipeline(props) {
73
- const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
74
- const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
75
- // WebGL specific
76
- // const {varyings = [], bufferMode = {}} = props;
77
- // const varyingHashes = varyings.map((v) => this._getHash(v));
78
- const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
79
- const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
80
- switch (this.device.type) {
81
- case 'webgl':
82
- // WebGL is more dynamic
83
- return `${vsHash}/${fsHash}V${varyingHash}BL${bufferLayoutHash}`;
84
- default:
85
- // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
86
- const parameterHash = this._getHash(JSON.stringify(props.parameters));
87
- // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
88
- // create a deepHash() to deduplicate?
89
- return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
90
- }
91
- }
92
- _getHash(key) {
93
- if (this._hashes[key] === undefined) {
94
- this._hashes[key] = this._hashCounter++;
95
- }
96
- return this._hashes[key];
97
- }
98
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"shader-factory.d.ts","sourceRoot":"","sources":["../../src/lib/shader-factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1D,kDAAkD;AAClD,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,CAA4B;IAE/E,iGAAiG;IACjG,MAAM,CAAC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IAK7D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0D;IAEjF,gBAAgB;gBACJ,MAAM,EAAE,MAAM;IAK1B,yFAAyF;IACzF,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM;IAgBxC,wFAAwF;IACxF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAgB7B,OAAO,CAAC,WAAW;CAGpB"}
@@ -1,35 +0,0 @@
1
- import { Device, Buffer, BufferRange, TransformFeedback, RenderPassProps } from '@luma.gl/core';
2
- import { Model } from "../model/model.js";
3
- import type { ModelProps } from "../model/model.js";
4
- /**
5
- * Properties for creating a {@link BufferTransform}
6
- * @deprecated
7
- */
8
- export type BufferTransformProps = Omit<ModelProps, 'fs'> & {
9
- fs?: ModelProps['fs'];
10
- feedbackBuffers?: Record<string, Buffer | BufferRange>;
11
- };
12
- /**
13
- * Creates a pipeline for buffer→buffer transforms.
14
- * @deprecated
15
- */
16
- export declare class BufferTransform {
17
- readonly device: Device;
18
- readonly model: Model;
19
- readonly transformFeedback: TransformFeedback;
20
- /** @deprecated Use device feature test. */
21
- static isSupported(device: Device): boolean;
22
- constructor(device: Device, props?: BufferTransformProps);
23
- /** Destroy owned resources. */
24
- destroy(): void;
25
- /** @deprecated Use {@link destroy}. */
26
- delete(): void;
27
- /** Run one transform loop. */
28
- run(options?: RenderPassProps): void;
29
- /** @deprecated */
30
- update(...args: any[]): void;
31
- /** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
32
- getBuffer(varyingName: string): Buffer | BufferRange | null;
33
- readAsync(varyingName: string): Promise<Uint8Array>;
34
- }
35
- //# sourceMappingURL=buffer-transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buffer-transform.d.ts","sourceRoot":"","sources":["../../src/transform/buffer-transform.ts"],"names":[],"mappings":"AAIA,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ChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAExB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;IA8BxD,OAAO,IAAI,IAAI;IAEf,uCAAuC;IACvC,MAAM,IAAI,IAAI;IAId,GAAG,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI;IAOpC,kBAAkB;IAClB,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAO5B,OAAO,CAAC,EAAC,MAAc,EAAC;;KAAK;IAM7B,gBAAgB,IAAI,OAAO;IAK3B,cAAc,IAAI,WAAW,GAAG,SAAS;IAOzC,WAAW,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI;IAI/C,eAAe,CAAC,KAAK,EAAE,qBAAqB;IAI5C,cAAc,CACZ,OAAO,EAAE,cAAc,EACvB,EAAC,aAAa,EAAE,cAAc,EAAE,aAAa,EAAC,EAAE,qBAAqB,GACpE,cAAc;IA8BjB,2BAA2B,IAAI,IAAI;CAOpC"}
@@ -1,53 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // ClipSpace
6
- import {Device} from '@luma.gl/core';
7
- import {Model, ModelProps} from '../model/model';
8
- import {Geometry} from '../geometry/geometry';
9
-
10
- const CLIPSPACE_VERTEX_SHADER = /* glsl */ `\
11
- #version 300 es
12
- in vec2 aClipSpacePosition;
13
- in vec2 aTexCoord;
14
- in vec2 aCoordinate;
15
-
16
- out vec2 position;
17
- out vec2 coordinate;
18
- out vec2 uv;
19
-
20
- void main(void) {
21
- gl_Position = vec4(aClipSpacePosition, 0., 1.);
22
- position = aClipSpacePosition;
23
- coordinate = aCoordinate;
24
- uv = aTexCoord;
25
- }
26
- `;
27
-
28
- /* eslint-disable indent, no-multi-spaces */
29
- const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
30
-
31
- /**
32
- * A flat geometry that covers the "visible area" that the GPU renders.
33
- */
34
- export class ClipSpace extends Model {
35
- constructor(device: Device, opts: Omit<ModelProps, 'vs' | 'vertexCount' | 'geometry'>) {
36
- const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord));
37
-
38
- super(device, {
39
- ...opts,
40
- vs: CLIPSPACE_VERTEX_SHADER,
41
- vertexCount: 4,
42
- geometry: new Geometry({
43
- topology: 'triangle-strip',
44
- vertexCount: 4,
45
- attributes: {
46
- aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
47
- aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)},
48
- aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
49
- }
50
- })
51
- });
52
- }
53
- }
@@ -1,126 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {RenderPipelineProps, ComputePipelineProps} from '@luma.gl/core';
6
- import {Device, RenderPipeline, ComputePipeline} from '@luma.gl/core';
7
-
8
- export type PipelineFactoryProps = RenderPipelineProps;
9
-
10
- type RenderPipelineCacheItem = {pipeline: RenderPipeline; useCount: number};
11
- type ComputePipelineCacheItem = {pipeline: ComputePipeline; useCount: number};
12
-
13
- /**
14
- * Efficiently creates / caches pipelines
15
- */
16
- export class PipelineFactory {
17
- static defaultProps: Required<PipelineFactoryProps> = {...RenderPipeline.defaultProps};
18
-
19
- /** Get the singleton default pipeline factory for the specified device */
20
- static getDefaultPipelineFactory(device: Device): PipelineFactory {
21
- device._lumaData.defaultPipelineFactory =
22
- device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
23
- return device._lumaData.defaultPipelineFactory as PipelineFactory;
24
- }
25
-
26
- readonly device: Device;
27
- readonly destroyPolicy: 'unused' | 'never';
28
-
29
- private _hashCounter: number = 0;
30
- private readonly _hashes: Record<string, number> = {};
31
- private readonly _renderPipelineCache: Record<string, RenderPipelineCacheItem> = {};
32
- private readonly _computePipelineCache: Record<string, ComputePipelineCacheItem> = {};
33
-
34
- constructor(device: Device) {
35
- this.device = device;
36
- this.destroyPolicy = device.props._factoryDestroyPolicy;
37
- }
38
-
39
- /** Return a RenderPipeline matching props. Reuses a similar pipeline if already created. */
40
- createRenderPipeline(props: RenderPipelineProps): RenderPipeline {
41
- const allProps: Required<RenderPipelineProps> = {...RenderPipeline.defaultProps, ...props};
42
-
43
- const hash = this._hashRenderPipeline(allProps);
44
-
45
- if (!this._renderPipelineCache[hash]) {
46
- const pipeline = this.device.createRenderPipeline({
47
- ...allProps,
48
- id: allProps.id ? `${allProps.id}-cached` : undefined
49
- });
50
- pipeline.hash = hash;
51
- this._renderPipelineCache[hash] = {pipeline, useCount: 0};
52
- }
53
-
54
- this._renderPipelineCache[hash].useCount++;
55
- return this._renderPipelineCache[hash].pipeline;
56
- }
57
-
58
- createComputePipeline(props: ComputePipelineProps): ComputePipeline {
59
- const allProps: Required<ComputePipelineProps> = {...ComputePipeline.defaultProps, ...props};
60
-
61
- const hash = this._hashComputePipeline(allProps);
62
-
63
- if (!this._computePipelineCache[hash]) {
64
- const pipeline = this.device.createComputePipeline({
65
- ...allProps,
66
- id: allProps.id ? `${allProps.id}-cached` : undefined
67
- });
68
- pipeline.hash = hash;
69
- this._computePipelineCache[hash] = {pipeline, useCount: 0};
70
- }
71
-
72
- this._computePipelineCache[hash].useCount++;
73
- return this._computePipelineCache[hash].pipeline;
74
- }
75
-
76
- release(pipeline: RenderPipeline | ComputePipeline): void {
77
- const hash = pipeline.hash;
78
- const cache =
79
- pipeline instanceof ComputePipeline ? this._computePipelineCache : this._renderPipelineCache;
80
- cache[hash].useCount--;
81
- if (cache[hash].useCount === 0) {
82
- if (this.destroyPolicy === 'unused') {
83
- cache[hash].pipeline.destroy();
84
- delete cache[hash];
85
- }
86
- }
87
- }
88
-
89
- // PRIVATE
90
- private _hashComputePipeline(props: ComputePipelineProps): string {
91
- const shaderHash = this._getHash(props.shader.source);
92
- return `${shaderHash}`;
93
- }
94
-
95
- /** Calculate a hash based on all the inputs for a render pipeline */
96
- private _hashRenderPipeline(props: RenderPipelineProps): string {
97
- const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
98
- const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
99
-
100
- // WebGL specific
101
- // const {varyings = [], bufferMode = {}} = props;
102
- // const varyingHashes = varyings.map((v) => this._getHash(v));
103
- const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
104
- const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
105
-
106
- switch (this.device.type) {
107
- case 'webgl':
108
- // WebGL is more dynamic
109
- return `${vsHash}/${fsHash}V${varyingHash}BL${bufferLayoutHash}`;
110
-
111
- default:
112
- // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
113
- const parameterHash = this._getHash(JSON.stringify(props.parameters));
114
- // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
115
- // create a deepHash() to deduplicate?
116
- return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
117
- }
118
- }
119
-
120
- private _getHash(key: string): number {
121
- if (this._hashes[key] === undefined) {
122
- this._hashes[key] = this._hashCounter++;
123
- }
124
- return this._hashes[key];
125
- }
126
- }