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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/animation/animator.d.ts +42 -0
  2. package/dist/animation/animator.d.ts.map +1 -0
  3. package/dist/animation/animator.js +53 -0
  4. package/dist/animation/animator.js.map +1 -0
  5. package/dist/animation-loop/animation-loop.d.ts +14 -2
  6. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  7. package/dist/animation-loop/animation-loop.js +40 -22
  8. package/dist/animation-loop/animation-loop.js.map +1 -1
  9. package/dist/animation-loop/animation-props.d.ts +2 -0
  10. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  11. package/dist/animation-loop/make-animation-loop.d.ts +1 -0
  12. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  13. package/dist/animation-loop/make-animation-loop.js +3 -0
  14. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  15. package/dist/application-utils/load-file.d.ts +2 -0
  16. package/dist/application-utils/load-file.d.ts.map +1 -1
  17. package/dist/application-utils/load-file.js +31 -5
  18. package/dist/application-utils/load-file.js.map +1 -1
  19. package/dist/compute/buffer-transform.d.ts +5 -1
  20. package/dist/compute/buffer-transform.d.ts.map +1 -1
  21. package/dist/compute/buffer-transform.js +7 -3
  22. package/dist/compute/buffer-transform.js.map +1 -1
  23. package/dist/compute/computation.d.ts +20 -8
  24. package/dist/compute/computation.d.ts.map +1 -1
  25. package/dist/compute/computation.js +34 -13
  26. package/dist/compute/computation.js.map +1 -1
  27. package/dist/compute/swap.d.ts.map +1 -1
  28. package/dist/compute/swap.js +17 -0
  29. package/dist/compute/swap.js.map +1 -1
  30. package/dist/dist.dev.js +4100 -1979
  31. package/dist/dist.min.js +288 -42
  32. package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
  33. package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
  34. package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
  35. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
  36. package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
  37. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  38. package/dist/dynamic-texture/dynamic-texture.js +31 -2
  39. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  40. package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
  41. package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
  42. package/dist/dynamic-texture/texture-binding-source.js +55 -0
  43. package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
  44. package/dist/dynamic-texture/texture-data.d.ts +5 -3
  45. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  46. package/dist/dynamic-texture/texture-data.js +5 -0
  47. package/dist/dynamic-texture/texture-data.js.map +1 -1
  48. package/dist/dynamic-texture/video-texture.d.ts +101 -0
  49. package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
  50. package/dist/dynamic-texture/video-texture.js +272 -0
  51. package/dist/dynamic-texture/video-texture.js.map +1 -0
  52. package/dist/geometries/cube-geometry.d.ts +1 -0
  53. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  54. package/dist/geometries/cube-geometry.js +22 -2
  55. package/dist/geometries/cube-geometry.js.map +1 -1
  56. package/dist/geometries/plane-geometry.d.ts +10 -0
  57. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  58. package/dist/geometries/plane-geometry.js.map +1 -1
  59. package/dist/geometry/geometry-utils.d.ts +36 -1
  60. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  61. package/dist/geometry/geometry-utils.js +137 -2
  62. package/dist/geometry/geometry-utils.js.map +1 -1
  63. package/dist/geometry/geometry.d.ts +52 -33
  64. package/dist/geometry/geometry.d.ts.map +1 -1
  65. package/dist/geometry/geometry.js +70 -19
  66. package/dist/geometry/geometry.js.map +1 -1
  67. package/dist/geometry/gpu-geometry.d.ts +37 -4
  68. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  69. package/dist/geometry/gpu-geometry.js +44 -36
  70. package/dist/geometry/gpu-geometry.js.map +1 -1
  71. package/dist/index.cjs +3990 -1961
  72. package/dist/index.cjs.map +4 -4
  73. package/dist/index.d.ts +20 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +8 -5
  76. package/dist/index.js.map +1 -1
  77. package/dist/material/material-factory.d.ts +2 -1
  78. package/dist/material/material-factory.d.ts.map +1 -1
  79. package/dist/material/material-factory.js.map +1 -1
  80. package/dist/material/material.d.ts +29 -10
  81. package/dist/material/material.d.ts.map +1 -1
  82. package/dist/material/material.js +84 -21
  83. package/dist/material/material.js.map +1 -1
  84. package/dist/model/model.d.ts +81 -23
  85. package/dist/model/model.d.ts.map +1 -1
  86. package/dist/model/model.js +312 -78
  87. package/dist/model/model.js.map +1 -1
  88. package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
  89. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  90. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  91. package/dist/models/billboard-texture-model.d.ts +5 -2
  92. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  93. package/dist/models/billboard-texture-model.js +28 -10
  94. package/dist/models/billboard-texture-model.js.map +1 -1
  95. package/dist/modules/picking/index-color-picking.d.ts +24 -0
  96. package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
  97. package/dist/modules/picking/index-color-picking.js +205 -0
  98. package/dist/modules/picking/index-color-picking.js.map +1 -0
  99. package/dist/modules/picking/index-picking.d.ts +3 -3
  100. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  101. package/dist/modules/picking/index-picking.js +23 -6
  102. package/dist/modules/picking/index-picking.js.map +1 -1
  103. package/dist/modules/picking/picking-manager.d.ts +21 -0
  104. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  105. package/dist/modules/picking/picking-manager.js +100 -0
  106. package/dist/modules/picking/picking-manager.js.map +1 -1
  107. package/dist/modules/picking/picking-uniforms.d.ts +4 -4
  108. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  109. package/dist/modules/picking/picking-uniforms.js +3 -0
  110. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  111. package/dist/modules/picking/picking.d.ts +5 -1
  112. package/dist/modules/picking/picking.d.ts.map +1 -1
  113. package/dist/modules/picking/picking.js +6 -0
  114. package/dist/modules/picking/picking.js.map +1 -1
  115. package/dist/passes/get-fragment-shader.js +4 -4
  116. package/dist/passes/shader-pass-renderer.d.ts +92 -25
  117. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  118. package/dist/passes/shader-pass-renderer.js +466 -72
  119. package/dist/passes/shader-pass-renderer.js.map +1 -1
  120. package/dist/passes/texture-transform-module.d.ts +10 -0
  121. package/dist/passes/texture-transform-module.d.ts.map +1 -0
  122. package/dist/passes/texture-transform-module.js +50 -0
  123. package/dist/passes/texture-transform-module.js.map +1 -0
  124. package/dist/shader-inputs.d.ts +33 -16
  125. package/dist/shader-inputs.d.ts.map +1 -1
  126. package/dist/shader-inputs.js +42 -12
  127. package/dist/shader-inputs.js.map +1 -1
  128. package/dist/utils/buffer-layout-helper.d.ts +0 -1
  129. package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
  130. package/dist/utils/buffer-layout-helper.js +2 -11
  131. package/dist/utils/buffer-layout-helper.js.map +1 -1
  132. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  133. package/dist/utils/buffer-layout-order.js +4 -15
  134. package/dist/utils/buffer-layout-order.js.map +1 -1
  135. package/dist/utils/shader-module-utils.d.ts +2 -0
  136. package/dist/utils/shader-module-utils.d.ts.map +1 -1
  137. package/dist/utils/shader-module-utils.js +64 -3
  138. package/dist/utils/shader-module-utils.js.map +1 -1
  139. package/package.json +2 -2
  140. package/src/animation/animator.ts +79 -0
  141. package/src/animation-loop/animation-loop.ts +56 -22
  142. package/src/animation-loop/animation-props.ts +2 -0
  143. package/src/animation-loop/make-animation-loop.ts +4 -0
  144. package/src/application-utils/load-file.ts +38 -5
  145. package/src/compute/buffer-transform.ts +14 -5
  146. package/src/compute/computation.ts +53 -21
  147. package/src/compute/swap.ts +19 -0
  148. package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
  149. package/src/dynamic-texture/dynamic-texture.ts +36 -3
  150. package/src/dynamic-texture/texture-binding-source.ts +94 -0
  151. package/src/dynamic-texture/texture-data.ts +12 -4
  152. package/src/dynamic-texture/video-texture.ts +334 -0
  153. package/src/geometries/cube-geometry.ts +24 -2
  154. package/src/geometries/plane-geometry.ts +10 -0
  155. package/src/geometry/geometry-utils.ts +209 -4
  156. package/src/geometry/geometry.ts +113 -36
  157. package/src/geometry/gpu-geometry.ts +61 -41
  158. package/src/index.ts +50 -14
  159. package/src/material/material-factory.ts +5 -1
  160. package/src/material/material.ts +123 -27
  161. package/src/model/model.ts +441 -102
  162. package/src/model/split-uniforms-and-bindings.ts +7 -3
  163. package/src/models/billboard-texture-model.ts +33 -12
  164. package/src/modules/picking/index-color-picking.ts +212 -0
  165. package/src/modules/picking/index-picking.ts +23 -6
  166. package/src/modules/picking/picking-manager.ts +141 -0
  167. package/src/modules/picking/picking-uniforms.ts +7 -4
  168. package/src/modules/picking/picking.ts +8 -0
  169. package/src/passes/get-fragment-shader.ts +4 -4
  170. package/src/passes/shader-pass-renderer.ts +691 -89
  171. package/src/passes/texture-transform-module.ts +52 -0
  172. package/src/shader-inputs.ts +65 -17
  173. package/src/utils/buffer-layout-helper.ts +2 -14
  174. package/src/utils/buffer-layout-order.ts +14 -24
  175. package/src/utils/shader-module-utils.ts +109 -3
  176. package/dist/geometry/gpu-table.d.ts +0 -1
  177. package/dist/geometry/gpu-table.d.ts.map +0 -1
  178. package/dist/geometry/gpu-table.js +0 -46
  179. package/dist/geometry/gpu-table.js.map +0 -1
  180. package/src/dynamic-texture/texture-data.ts.disabled +0 -296
  181. package/src/geometry/gpu-table.ts +0 -45
@@ -0,0 +1,52 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {ShaderModule} from '@luma.gl/shadertools';
6
+
7
+ export const textureTransform = {
8
+ name: 'textureTransform',
9
+ source: /* wgsl */ `
10
+ struct textureTransformUniforms {
11
+ scale: vec2<f32>,
12
+ flipY: i32,
13
+ };
14
+ @group(0) @binding(auto) var<uniform> textureTransform: textureTransformUniforms;
15
+
16
+ fn shaderPassRenderer_getTextureUV(uv: vec2f) -> vec2f {
17
+ var position = (uv - vec2f(0.5, 0.5)) / textureTransform.scale + vec2f(0.5, 0.5);
18
+ if (textureTransform.flipY != 0) {
19
+ position.y = 1.0 - position.y;
20
+ }
21
+ return position;
22
+ }
23
+
24
+ fn shaderPassRenderer_getRenderTargetUV(textureUV: vec2f) -> vec2f {
25
+ let unscaledCoord = (textureUV - vec2f(0.5, 0.5)) * textureTransform.scale + vec2f(0.5, 0.5);
26
+ return select(vec2f(unscaledCoord.x, 1.0 - unscaledCoord.y), unscaledCoord, textureTransform.flipY != 0);
27
+ }
28
+ `,
29
+ fs: /* glsl */ `
30
+ layout(std140) uniform textureTransformUniforms {
31
+ vec2 scale;
32
+ int flipY;
33
+ } textureTransform;
34
+
35
+ vec2 shaderPassRenderer_getTextureUV(vec2 coord) {
36
+ vec2 position = (coord - 0.5) / textureTransform.scale + 0.5;
37
+ if (textureTransform.flipY != 0) {
38
+ position.y = 1.0 - position.y;
39
+ }
40
+ return position;
41
+ }
42
+
43
+ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
44
+ vec2 unscaledCoord = (textureUV - 0.5) * textureTransform.scale + 0.5;
45
+ return textureTransform.flipY != 0 ? unscaledCoord : vec2(unscaledCoord.x, 1.0 - unscaledCoord.y);
46
+ }
47
+ `,
48
+ uniformTypes: {
49
+ scale: 'vec2<f32>',
50
+ flipY: 'i32'
51
+ }
52
+ } as const satisfies ShaderModule<{}, {scale: [number, number]; flipY: number}>;
@@ -11,11 +11,22 @@ import {
11
11
  ShaderModuleUniformValue
12
12
  } from '@luma.gl/shadertools';
13
13
  import {splitUniformsAndBindings} from './model/split-uniforms-and-bindings';
14
+ import type {TextureBindingSource} from './dynamic-texture/texture-binding-source';
15
+
16
+ /** Shader binding accepted by ShaderInputs, including deferred texture binding sources. */
17
+ export type ShaderInputBinding = Binding | TextureBindingSource;
14
18
 
15
19
  export type ShaderInputsOptions = {
16
20
  disableWarnings?: boolean;
17
21
  };
18
22
 
23
+ export type ShaderInputsProps<
24
+ ShaderPropsT extends Partial<Record<string, Record<string, unknown>>>
25
+ > = Partial<{[P in keyof ShaderPropsT]?: Partial<ShaderPropsT[P]>}> & {
26
+ /** Shader resource bindings that are not owned by a shader module. */
27
+ bindings?: Record<string, ShaderInputBinding>;
28
+ };
29
+
19
30
  type ShaderInputsModule = Pick<
20
31
  ShaderModule<any, any, any>,
21
32
  'bindingLayout' | 'defaultUniforms' | 'dependencies' | 'getUniforms' | 'name' | 'uniformTypes'
@@ -37,23 +48,23 @@ export class ShaderInputs<
37
48
  disableWarnings: false
38
49
  };
39
50
 
40
- /**
41
- * The map of modules
42
- * @todo should should this include the resolved dependencies?
43
- */
51
+ /** Registered shader modules, including resolved dependencies. */
44
52
  // @ts-ignore Fix typings
45
53
  modules: Readonly<{[P in keyof ShaderPropsT]: ShaderInputsModule}>;
46
54
 
47
55
  /** Stores the uniform values for each module */
48
56
  moduleUniforms: Record<keyof ShaderPropsT, Record<string, ShaderModuleUniformValue>>;
49
- /** Stores the uniform bindings for each module */
50
- moduleBindings: Record<keyof ShaderPropsT, Record<string, Binding>>;
57
+ /** Stores resource bindings for each module. */
58
+ moduleBindings: Record<keyof ShaderPropsT, Record<string, ShaderInputBinding>>;
59
+ /** Stores shader resource bindings that are not owned by a shader module. */
60
+ directBindings: Record<string, ShaderInputBinding> = {};
51
61
  /** Tracks if uniforms have changed */
52
62
  // moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
53
63
 
54
64
  /**
55
- * Create a new UniformStore instance
56
- * @param modules
65
+ * Creates shader input storage for one or more shader modules.
66
+ * @param modules Initial shader modules keyed by module name.
67
+ * @param options Shader input behavior options.
57
68
  */
58
69
  constructor(
59
70
  // @ts-ignore Fix typings
@@ -80,7 +91,7 @@ export class ShaderInputs<
80
91
  keyof ShaderPropsT,
81
92
  Record<string, ShaderModuleUniformValue>
82
93
  >;
83
- this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Binding>>;
94
+ this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, ShaderInputBinding>>;
84
95
 
85
96
  // Initialize the modules
86
97
  for (const [name, module] of Object.entries(modules)) {
@@ -99,8 +110,16 @@ export class ShaderInputs<
99
110
  /**
100
111
  * Set module props
101
112
  */
102
- setProps(props: Partial<{[P in keyof ShaderPropsT]?: Partial<ShaderPropsT[P]>}>): void {
113
+ setProps(props: ShaderInputsProps<ShaderPropsT>): void {
114
+ if (props.bindings) {
115
+ Object.assign(this.directBindings, props.bindings);
116
+ }
117
+
103
118
  for (const name of Object.keys(props)) {
119
+ if (name === 'bindings') {
120
+ continue;
121
+ }
122
+
104
123
  const moduleName = name as keyof ShaderPropsT;
105
124
  const moduleProps = props[moduleName] || {};
106
125
  const module = this.modules[moduleName];
@@ -132,14 +151,29 @@ export class ShaderInputs<
132
151
  }
133
152
  }
134
153
 
135
- /**
136
- * Return the map of modules
137
- * @todo should should this include the resolved dependencies?
138
- */
154
+ /** Returns registered shader modules, including resolved dependencies. */
139
155
  getModules(): ShaderModule[] {
140
156
  return Object.values(this.modules) as ShaderModule[];
141
157
  }
142
158
 
159
+ /**
160
+ * Adds shader modules that should participate in subsequent uniform and binding updates.
161
+ * Module dependencies are resolved before new module state is initialized.
162
+ * @param modules Shader modules to register after construction.
163
+ */
164
+ addModules(modules: ShaderInputsModule[]): void {
165
+ const modulesToAdd = getShaderModuleDependencies(modules);
166
+
167
+ for (const module of modulesToAdd) {
168
+ const moduleName = module.name as keyof ShaderPropsT;
169
+ if (!this.modules[moduleName]) {
170
+ // @ts-ignore The ShaderInputs module registry is intentionally extended at runtime.
171
+ this.modules[moduleName] = module;
172
+ this._addModule(module);
173
+ }
174
+ }
175
+ }
176
+
143
177
  /** Get all uniform values for all modules */
144
178
  getUniformValues(): Partial<
145
179
  Record<keyof ShaderPropsT, Record<string, ShaderModuleUniformValue>>
@@ -147,15 +181,29 @@ export class ShaderInputs<
147
181
  return this.moduleUniforms;
148
182
  }
149
183
 
150
- /** Merges all bindings for the shader (from the various modules) */
151
- getBindingValues(): Record<string, Binding> {
152
- const bindings = {} as Record<string, Binding>;
184
+ /** Merges concrete and deferred bindings for the shader from the registered modules. */
185
+ getBindingValues(): Record<string, ShaderInputBinding> {
186
+ const bindings = {} as Record<string, ShaderInputBinding>;
153
187
  for (const moduleBindings of Object.values(this.moduleBindings)) {
154
188
  Object.assign(bindings, moduleBindings);
155
189
  }
190
+ Object.assign(bindings, this.directBindings);
156
191
  return bindings;
157
192
  }
158
193
 
194
+ /**
195
+ * Gets binding values for a single shader module without flattening them into the full shader map.
196
+ *
197
+ * This is used by systems such as {@link ShaderPassRenderer} that execute one shader module at a
198
+ * time and need the defaults for just that module.
199
+ */
200
+ getModuleBindingValues(
201
+ moduleName: keyof ShaderPropsT | string
202
+ ): Record<string, ShaderInputBinding> {
203
+ const moduleBindings = this.moduleBindings[moduleName as keyof ShaderPropsT];
204
+ return moduleBindings ? {...moduleBindings} : {};
205
+ }
206
+
159
207
  // INTERNAL
160
208
 
161
209
  /** Return a debug table that can be used for console.table() or log.table() */
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {log, type BufferLayout} from '@luma.gl/core';
5
+ import {getBufferLayoutAttributeNames, type BufferLayout} from '@luma.gl/core';
6
6
 
7
7
  /** BufferLayoutHelper is a helper class that should not be used directly by applications */
8
8
  export class BufferLayoutHelper {
@@ -18,9 +18,7 @@ export class BufferLayoutHelper {
18
18
 
19
19
  /** Get attribute names from a BufferLayout */
20
20
  getAttributeNamesForBuffer(bufferLayout: BufferLayout): string[] {
21
- return bufferLayout.attributes
22
- ? bufferLayout.attributes?.map(layout => layout.attribute)
23
- : [bufferLayout.name];
21
+ return getBufferLayoutAttributeNames(bufferLayout);
24
22
  }
25
23
 
26
24
  mergeBufferLayouts(
@@ -38,14 +36,4 @@ export class BufferLayoutHelper {
38
36
  }
39
37
  return mergedLayouts;
40
38
  }
41
-
42
- getBufferIndex(bufferName: string): number {
43
- const bufferIndex = this.bufferLayouts.findIndex(layout => layout.name === bufferName);
44
-
45
- if (bufferIndex === -1) {
46
- log.warn(`BufferLayout: Missing buffer for "${bufferName}".`)();
47
- }
48
-
49
- return bufferIndex;
50
- }
51
39
  }
@@ -2,38 +2,28 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {type BufferLayout, type ShaderLayout} from '@luma.gl/core';
6
-
7
- function getMinLocation(
8
- attributeNames: string[],
9
- shaderLayoutMap: Record<string, number | undefined>
10
- ): number {
11
- let minLocation = Infinity;
12
-
13
- for (const name of attributeNames) {
14
- const location = shaderLayoutMap[name];
15
- if (location !== undefined) {
16
- minLocation = Math.min(minLocation, location);
17
- }
18
- }
19
-
20
- return minLocation;
21
- }
5
+ import {
6
+ getBufferLayoutAttributeNames,
7
+ getMinimumAttributeLocation,
8
+ getShaderAttributeLocationMap,
9
+ type BufferLayout,
10
+ type ShaderLayout
11
+ } from '@luma.gl/core';
22
12
 
23
13
  export function sortedBufferLayoutByShaderSourceLocations(
24
14
  shaderLayout: ShaderLayout,
25
15
  bufferLayout: BufferLayout[]
26
16
  ): BufferLayout[] {
27
- const shaderLayoutMap = Object.fromEntries(
28
- shaderLayout.attributes.map(attr => [attr.name, attr.location])
29
- );
17
+ const shaderLayoutMap = getShaderAttributeLocationMap(shaderLayout);
30
18
 
31
19
  const sortedLayout = bufferLayout.slice();
32
20
  sortedLayout.sort((a, b) => {
33
- const attributeNamesA = a.attributes ? a.attributes.map(attr => attr.attribute) : [a.name];
34
- const attributeNamesB = b.attributes ? b.attributes.map(attr => attr.attribute) : [b.name];
35
- const minLocationA = getMinLocation(attributeNamesA, shaderLayoutMap);
36
- const minLocationB = getMinLocation(attributeNamesB, shaderLayoutMap);
21
+ const minLocationA = getMinimumAttributeLocation(
22
+ getBufferLayoutAttributeNames(a).map(attributeName => shaderLayoutMap[attributeName])
23
+ );
24
+ const minLocationB = getMinimumAttributeLocation(
25
+ getBufferLayoutAttributeNames(b).map(attributeName => shaderLayoutMap[attributeName])
26
+ );
37
27
 
38
28
  return minLocationA - minLocationB;
39
29
  });
@@ -33,6 +33,9 @@ export function mergeShaderModuleBindingsIntoLayout<TShaderLayout extends AnySha
33
33
  if (binding?.group === 0) {
34
34
  binding.group = bindingLayout.group;
35
35
  }
36
+ if (binding && bindingLayout.visibility !== undefined) {
37
+ binding.visibility = bindingLayout.visibility;
38
+ }
36
39
  }
37
40
  }
38
41
  }
@@ -40,10 +43,53 @@ export function mergeShaderModuleBindingsIntoLayout<TShaderLayout extends AnySha
40
43
  return mergedLayout;
41
44
  }
42
45
 
46
+ export function mergeInferredShaderLayout(
47
+ shaderLayout: ShaderLayout | null | undefined,
48
+ inferredShaderLayout: ShaderLayout | null | undefined,
49
+ inferredAttributeNames: readonly string[] = []
50
+ ): ShaderLayout | null | undefined {
51
+ if (!shaderLayout) {
52
+ return inferredShaderLayout;
53
+ }
54
+ if (!inferredShaderLayout) {
55
+ return shaderLayout;
56
+ }
57
+
58
+ return {
59
+ ...shaderLayout,
60
+ attributes: shaderLayout.attributes.length
61
+ ? mergeAttributeLayouts(
62
+ shaderLayout.attributes,
63
+ inferredShaderLayout.attributes.filter(attribute =>
64
+ inferredAttributeNames.includes(attribute.name)
65
+ )
66
+ )
67
+ : inferredShaderLayout.attributes,
68
+ bindings: mergeBindingLayouts(shaderLayout.bindings, inferredShaderLayout.bindings)
69
+ };
70
+ }
71
+
43
72
  export function shaderModuleHasUniforms(module: ShaderModule): boolean {
44
73
  return Boolean(module.uniformTypes && !isObjectEmpty(module.uniformTypes));
45
74
  }
46
75
 
76
+ export function mergeShaderModules(
77
+ explicitModules: ShaderModule[] | undefined,
78
+ shaderInputModules: ShaderModule[] | undefined
79
+ ): ShaderModule[] {
80
+ const modules: ShaderModule[] = [];
81
+ const moduleNames = new Set<string>();
82
+
83
+ for (const module of [...(explicitModules || []), ...(shaderInputModules || [])]) {
84
+ if (!moduleNames.has(module.name)) {
85
+ moduleNames.add(module.name);
86
+ modules.push(module);
87
+ }
88
+ }
89
+
90
+ return modules;
91
+ }
92
+
47
93
  /** Returns binding-name aliases that should share the module-declared bind group. */
48
94
  function getRelatedBindingNames(bindingName: string): string[] {
49
95
  const bindingNames = new Set<string>([bindingName, `${bindingName}Uniforms`]);
@@ -56,10 +102,70 @@ function getRelatedBindingNames(bindingName: string): string[] {
56
102
  }
57
103
 
58
104
  function isObjectEmpty(obj: object): boolean {
59
- // @ts-ignore key is intentionally unused
60
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
- for (const key in obj) {
105
+ for (const _key in obj) {
62
106
  return false;
63
107
  }
64
108
  return true;
65
109
  }
110
+
111
+ function mergeBindingLayouts<TBindingLayout extends ShaderLayout['bindings'][number]>(
112
+ explicitBindings: TBindingLayout[],
113
+ inferredBindings: TBindingLayout[]
114
+ ): TBindingLayout[] {
115
+ const mergedBindings = explicitBindings.map(binding => ({...binding}));
116
+ const explicitBindingNames = new Set(explicitBindings.map(binding => binding.name));
117
+ const explicitBindingLocations = new Set(
118
+ explicitBindings.map(binding => `${binding.group}:${binding.location}`)
119
+ );
120
+
121
+ for (const inferredBinding of inferredBindings) {
122
+ const inferredBindingLocation = `${inferredBinding.group}:${inferredBinding.location}`;
123
+ if (
124
+ !explicitBindingNames.has(inferredBinding.name) &&
125
+ !explicitBindingLocations.has(inferredBindingLocation)
126
+ ) {
127
+ mergedBindings.push({...inferredBinding});
128
+ }
129
+ }
130
+
131
+ return mergedBindings;
132
+ }
133
+
134
+ function mergeAttributeLayouts(
135
+ explicitAttributes: ShaderLayout['attributes'],
136
+ inferredAttributes: ShaderLayout['attributes']
137
+ ): ShaderLayout['attributes'] {
138
+ const mergedAttributes = explicitAttributes.map(attribute => ({...attribute}));
139
+ const explicitAttributesByName = new Map(
140
+ explicitAttributes.map(attribute => [attribute.name, attribute])
141
+ );
142
+ const explicitAttributesByLocation = new Map(
143
+ explicitAttributes.map(attribute => [attribute.location, attribute])
144
+ );
145
+
146
+ for (const inferredAttribute of inferredAttributes) {
147
+ const explicitByName = explicitAttributesByName.get(inferredAttribute.name);
148
+ if (explicitByName) {
149
+ if (
150
+ explicitByName.type !== inferredAttribute.type ||
151
+ explicitByName.location !== inferredAttribute.location
152
+ ) {
153
+ throw new Error(
154
+ `Shader attribute "${inferredAttribute.name}" conflicts with its inferred type or location`
155
+ );
156
+ }
157
+ continue;
158
+ }
159
+
160
+ const explicitByLocation = explicitAttributesByLocation.get(inferredAttribute.location);
161
+ if (explicitByLocation) {
162
+ throw new Error(
163
+ `Shader attributes "${explicitByLocation.name}" and "${inferredAttribute.name}" both use location ${inferredAttribute.location}`
164
+ );
165
+ }
166
+
167
+ mergedAttributes.push({...inferredAttribute});
168
+ }
169
+
170
+ return mergedAttributes;
171
+ }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=gpu-table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gpu-table.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-table.ts"],"names":[],"mappings":""}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- // luma.gl
3
- // SPDX-License-Identifier: MIT
4
- // Copyright (c) vis.gl contributors
5
- /*
6
- export function getAttributeLayoutsFromGeometry(geometry: Geometry) {
7
- const layouts: Record<string, {}> = {};
8
- let indices = geometry.indices;
9
-
10
- for (const [name, attribute] of Object.entries(geometry.attributes)) {
11
- const remappedName = mapAttributeName(name);
12
-
13
- if (attribute.constant) {
14
- throw new Error('constant attributes not supported');
15
- } else {
16
- const typedArray = attribute.value;
17
- // Create accessor by copying the attribute and removing `value``
18
- const accessor = {...attribute};
19
- delete accessor.value;
20
- buffers[remappedName] = [device.createBuffer(typedArray), accessor];
21
-
22
- inferAttributeAccessor(name, accessor);
23
- }
24
- }
25
- }
26
-
27
- export class Table {
28
- length: number;
29
- // columns: Record<string, TypedArray> = {};
30
- }
31
-
32
- export class GPUTable {
33
- length: number;
34
- columns: Record<string, Buffer> = {};
35
- }
36
-
37
- export function convertTableToGPUTable(table: Table) {
38
- // for (const ) {}
39
- }
40
-
41
- export function renameTableColumns(table: Table, map: (name: string) => string) {
42
- const newColumns = table.columns.reduce()
43
- table.clone();
44
- }
45
- */
46
- //# sourceMappingURL=gpu-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gpu-table.js","sourceRoot":"","sources":["../../src/geometry/gpu-table.ts"],"names":[],"mappings":";AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCE"}