@luma.gl/engine 9.2.6 → 9.3.0-alpha.10
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/animation-loop/animation-loop.d.ts +11 -5
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +83 -47
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +7 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +23 -6
- package/dist/animation-loop/request-animation-frame.js.map +1 -1
- package/dist/compute/computation.d.ts +3 -7
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +16 -13
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts +2 -0
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +10 -5
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +2639 -1290
- package/dist/dist.min.js +325 -210
- package/dist/dynamic-texture/dynamic-texture.d.ts +102 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.js +556 -0
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +144 -0
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-data.js +208 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -0
- package/dist/geometries/cone-geometry.d.ts +3 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +2 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +8 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +2497 -1212
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +20 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +73 -0
- package/dist/material/material-factory.d.ts.map +1 -0
- package/dist/material/material-factory.js +111 -0
- package/dist/material/material-factory.js.map +1 -0
- package/dist/material/material.d.ts +84 -0
- package/dist/material/material.d.ts.map +1 -0
- package/dist/material/material.js +176 -0
- package/dist/material/material.js.map +1 -0
- package/dist/model/model.d.ts +47 -16
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +113 -47
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +8 -5
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +77 -23
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/billboard-texture-module.d.ts +1 -1
- package/dist/models/billboard-texture-module.js +1 -1
- package/dist/models/clip-space.js +7 -7
- package/dist/models/directional-light-model.d.ts +7 -0
- package/dist/models/directional-light-model.d.ts.map +1 -0
- package/dist/models/directional-light-model.js +23 -0
- package/dist/models/directional-light-model.js.map +1 -0
- package/dist/models/light-model-utils.d.ts +69 -0
- package/dist/models/light-model-utils.d.ts.map +1 -0
- package/dist/models/light-model-utils.js +395 -0
- package/dist/models/light-model-utils.js.map +1 -0
- package/dist/models/point-light-model.d.ts +7 -0
- package/dist/models/point-light-model.d.ts.map +1 -0
- package/dist/models/point-light-model.js +22 -0
- package/dist/models/point-light-model.js.map +1 -0
- package/dist/models/spot-light-model.d.ts +7 -0
- package/dist/models/spot-light-model.d.ts.map +1 -0
- package/dist/models/spot-light-model.js +23 -0
- package/dist/models/spot-light-model.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +5 -9
- package/dist/modules/picking/color-picking.d.ts.map +1 -1
- package/dist/modules/picking/color-picking.js +122 -115
- package/dist/modules/picking/color-picking.js.map +1 -1
- package/dist/modules/picking/index-picking.d.ts +4 -4
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +36 -16
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
- package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/legacy-color-picking.js +7 -0
- package/dist/modules/picking/legacy-color-picking.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +29 -3
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +188 -41
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +13 -12
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +27 -14
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +25 -0
- package/dist/modules/picking/picking.d.ts.map +1 -0
- package/dist/modules/picking/picking.js +18 -0
- package/dist/modules/picking/picking.js.map +1 -0
- package/dist/passes/get-fragment-shader.js +12 -27
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +5 -7
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +16 -42
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/scenegraph/group-node.d.ts +5 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +12 -0
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +23 -15
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/shader-inputs.d.ts +9 -7
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +84 -4
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +12 -2
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +7 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -0
- package/dist/utils/shader-module-utils.js +46 -0
- package/dist/utils/shader-module-utils.js.map +1 -0
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +89 -50
- package/src/animation-loop/make-animation-loop.ts +13 -5
- package/src/animation-loop/request-animation-frame.ts +32 -6
- package/src/compute/computation.ts +32 -17
- package/src/compute/swap.ts +13 -7
- package/src/dynamic-texture/dynamic-texture.ts +732 -0
- package/src/dynamic-texture/texture-data.ts +336 -0
- package/src/geometries/cone-geometry.ts +6 -1
- package/src/geometries/cylinder-geometry.ts +5 -1
- package/src/geometry/gpu-geometry.ts +8 -3
- package/src/index.ts +38 -8
- package/src/material/material-factory.ts +157 -0
- package/src/material/material.ts +254 -0
- package/src/model/model.ts +158 -67
- package/src/model/split-uniforms-and-bindings.ts +8 -6
- package/src/models/billboard-texture-model.ts +88 -27
- package/src/models/billboard-texture-module.ts +1 -1
- package/src/models/clip-space.ts +7 -7
- package/src/models/directional-light-model.ts +32 -0
- package/src/models/light-model-utils.ts +587 -0
- package/src/models/point-light-model.ts +31 -0
- package/src/models/spot-light-model.ts +32 -0
- package/src/modules/picking/color-picking.ts +123 -122
- package/src/modules/picking/index-picking.ts +36 -16
- package/src/modules/picking/legacy-color-picking.ts +8 -0
- package/src/modules/picking/picking-manager.ts +252 -50
- package/src/modules/picking/picking-uniforms.ts +39 -24
- package/src/modules/picking/picking.ts +22 -0
- package/src/passes/get-fragment-shader.ts +12 -27
- package/src/passes/shader-pass-renderer.ts +25 -48
- package/src/scenegraph/group-node.ts +16 -0
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +27 -16
- package/src/shader-inputs.ts +165 -15
- package/src/utils/buffer-layout-order.ts +18 -2
- package/src/utils/shader-module-utils.ts +65 -0
- package/dist/async-texture/async-texture.d.ts +0 -166
- package/dist/async-texture/async-texture.d.ts.map +0 -1
- package/dist/async-texture/async-texture.js +0 -386
- package/dist/async-texture/async-texture.js.map +0 -1
- package/dist/factories/pipeline-factory.d.ts +0 -37
- package/dist/factories/pipeline-factory.d.ts.map +0 -1
- package/dist/factories/pipeline-factory.js +0 -181
- package/dist/factories/pipeline-factory.js.map +0 -1
- package/dist/factories/shader-factory.d.ts +0 -22
- package/dist/factories/shader-factory.d.ts.map +0 -1
- package/dist/factories/shader-factory.js +0 -88
- package/dist/factories/shader-factory.js.map +0 -1
- package/src/async-texture/async-texture.ts +0 -551
- package/src/factories/pipeline-factory.ts +0 -224
- package/src/factories/shader-factory.ts +0 -103
- /package/src/{async-texture/texture-setters.ts.disabled → dynamic-texture/texture-data.ts.disabled} +0 -0
package/dist/model/model.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import type { ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
|
|
1
|
+
import { type TypedArray } from '@math.gl/types';
|
|
2
|
+
import { type RenderPipelineProps, type RenderPipelineParameters, type BufferLayout, type VertexArray, type TransformFeedback, type AttributeInfo, type Binding, type BindingsByGroup, type PrimitiveTopology, Device, Buffer, RenderPipeline, RenderPass, PipelineFactory, ShaderFactory, UniformStore } from '@luma.gl/core';
|
|
3
|
+
import type { ShaderBindingDebugRow, ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
|
|
5
4
|
import { ShaderAssembler } from '@luma.gl/shadertools';
|
|
6
5
|
import type { Geometry } from "../geometry/geometry.js";
|
|
7
6
|
import { GPUGeometry } from "../geometry/gpu-geometry.js";
|
|
8
|
-
import { PipelineFactory } from "../factories/pipeline-factory.js";
|
|
9
|
-
import { ShaderFactory } from "../factories/shader-factory.js";
|
|
10
7
|
import { ShaderInputs } from "../shader-inputs.js";
|
|
11
|
-
import {
|
|
8
|
+
import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
|
|
9
|
+
import { Material } from "../material/material.js";
|
|
12
10
|
export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
13
11
|
source?: string;
|
|
14
12
|
vs?: string | null;
|
|
@@ -19,8 +17,12 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
19
17
|
defines?: Record<string, boolean>;
|
|
20
18
|
/** Shader inputs, used to generated uniform buffers and bindings */
|
|
21
19
|
shaderInputs?: ShaderInputs;
|
|
20
|
+
/** Material-owned group-3 bindings */
|
|
21
|
+
material?: Material;
|
|
22
22
|
/** Bindings */
|
|
23
|
-
bindings?: Record<string, Binding |
|
|
23
|
+
bindings?: Record<string, Binding | DynamicTexture>;
|
|
24
|
+
/** WebGL-only uniforms */
|
|
25
|
+
uniforms?: Record<string, unknown>;
|
|
24
26
|
/** Parameters that are built into the pipeline */
|
|
25
27
|
parameters?: RenderPipelineParameters;
|
|
26
28
|
/** Geometry */
|
|
@@ -51,22 +53,37 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
51
53
|
shaderAssembler?: ShaderAssembler;
|
|
52
54
|
};
|
|
53
55
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* High level draw API for luma.gl.
|
|
57
|
+
*
|
|
58
|
+
* A `Model` encapsulates shaders, geometry attributes, bindings and render
|
|
59
|
+
* pipeline state into a single object. It automatically reuses and rebuilds
|
|
60
|
+
* pipelines as render parameters change and exposes convenient hooks for
|
|
61
|
+
* updating uniforms and attributes.
|
|
62
|
+
*
|
|
63
|
+
* Features:
|
|
64
|
+
* - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
|
|
65
|
+
* - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
|
|
66
|
+
* - Manages geometry attributes and buffer bindings.
|
|
67
|
+
* - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
|
|
68
|
+
* - Provides detailed debug logging and optional shader source inspection.
|
|
60
69
|
*/
|
|
61
70
|
export declare class Model {
|
|
62
71
|
static defaultProps: Required<ModelProps>;
|
|
72
|
+
/** Device that created this model */
|
|
63
73
|
readonly device: Device;
|
|
74
|
+
/** Application provided identifier */
|
|
64
75
|
readonly id: string;
|
|
76
|
+
/** WGSL shader source when using unified shader */
|
|
65
77
|
readonly source: string;
|
|
78
|
+
/** GLSL vertex shader source */
|
|
66
79
|
readonly vs: string;
|
|
80
|
+
/** GLSL fragment shader source */
|
|
67
81
|
readonly fs: string;
|
|
82
|
+
/** Factory used to create render pipelines */
|
|
68
83
|
readonly pipelineFactory: PipelineFactory;
|
|
84
|
+
/** Factory used to create shaders */
|
|
69
85
|
readonly shaderFactory: ShaderFactory;
|
|
86
|
+
/** User-supplied per-model data */
|
|
70
87
|
userData: {
|
|
71
88
|
[key: string]: any;
|
|
72
89
|
};
|
|
@@ -89,7 +106,7 @@ export declare class Model {
|
|
|
89
106
|
/** Constant-valued attributes */
|
|
90
107
|
constantAttributes: Record<string, TypedArray>;
|
|
91
108
|
/** Bindings (textures, samplers, uniform buffers) */
|
|
92
|
-
bindings: Record<string, Binding |
|
|
109
|
+
bindings: Record<string, Binding | DynamicTexture>;
|
|
93
110
|
/**
|
|
94
111
|
* VertexArray
|
|
95
112
|
* @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
|
|
@@ -102,6 +119,7 @@ export declare class Model {
|
|
|
102
119
|
pipeline: RenderPipeline;
|
|
103
120
|
/** ShaderInputs instance */
|
|
104
121
|
shaderInputs: ShaderInputs;
|
|
122
|
+
material: Material | null;
|
|
105
123
|
_uniformStore: UniformStore;
|
|
106
124
|
_attributeInfos: Record<string, AttributeInfo>;
|
|
107
125
|
_gpuGeometry: GPUGeometry | null;
|
|
@@ -111,6 +129,7 @@ export declare class Model {
|
|
|
111
129
|
private _destroyed;
|
|
112
130
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
113
131
|
_lastDrawTimestamp: number;
|
|
132
|
+
private _bindingTable;
|
|
114
133
|
get [Symbol.toStringTag](): string;
|
|
115
134
|
toString(): string;
|
|
116
135
|
constructor(device: Device, props: ModelProps);
|
|
@@ -119,7 +138,15 @@ export declare class Model {
|
|
|
119
138
|
needsRedraw(): false | string;
|
|
120
139
|
/** Mark the model as needing a redraw */
|
|
121
140
|
setNeedsRedraw(reason: string): void;
|
|
141
|
+
/** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
|
|
142
|
+
getBindingDebugTable(): readonly ShaderBindingDebugRow[];
|
|
143
|
+
/** Update uniforms and pipeline state prior to drawing. */
|
|
122
144
|
predraw(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Issue one draw call.
|
|
147
|
+
* @param renderPass - render pass to draw into
|
|
148
|
+
* @returns `true` if the draw call was executed, `false` if resources were not ready.
|
|
149
|
+
*/
|
|
123
150
|
draw(renderPass: RenderPass): boolean;
|
|
124
151
|
/**
|
|
125
152
|
* Updates the optional geometry
|
|
@@ -155,12 +182,13 @@ export declare class Model {
|
|
|
155
182
|
setVertexCount(vertexCount: number): void;
|
|
156
183
|
/** Set the shader inputs */
|
|
157
184
|
setShaderInputs(shaderInputs: ShaderInputs): void;
|
|
185
|
+
setMaterial(material: Material | null): void;
|
|
158
186
|
/** Update uniform buffers from the model's shader inputs */
|
|
159
187
|
updateShaderInputs(): void;
|
|
160
188
|
/**
|
|
161
189
|
* Sets bindings (textures, samplers, uniform buffers)
|
|
162
190
|
*/
|
|
163
|
-
setBindings(bindings: Record<string, Binding |
|
|
191
|
+
setBindings(bindings: Record<string, Binding | DynamicTexture>): void;
|
|
164
192
|
/**
|
|
165
193
|
* Updates optional transform feedback. WebGL only.
|
|
166
194
|
*/
|
|
@@ -192,6 +220,8 @@ export declare class Model {
|
|
|
192
220
|
_areBindingsLoading(): string | false;
|
|
193
221
|
/** Extracts texture view from loaded async textures. Returns null if any textures have not yet been loaded. */
|
|
194
222
|
_getBindings(): Record<string, Binding>;
|
|
223
|
+
_getBindGroups(): BindingsByGroup;
|
|
224
|
+
_getBindGroupCacheKeys(): Partial<Record<number, object>>;
|
|
195
225
|
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
196
226
|
_getBindingsUpdateTimestamp(): number;
|
|
197
227
|
/**
|
|
@@ -213,6 +243,7 @@ export declare class Model {
|
|
|
213
243
|
_logFramebuffer(renderPass: RenderPass): void;
|
|
214
244
|
_getAttributeDebugTable(): Record<string, Record<string, unknown>>;
|
|
215
245
|
_getBufferOrConstantValues(attribute: Buffer | TypedArray, dataType: any): string;
|
|
246
|
+
private _getNonMaterialBindings;
|
|
216
247
|
}
|
|
217
248
|
/** Create a shadertools platform info from the Device */
|
|
218
249
|
export declare function getPlatformInfo(device: Device): PlatformInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAEjB,KAAK,WAAW,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uBAAuB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA4BlE,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,MAAM;IAOjF,OAAO,CAAC,uBAAuB;CAehC;AAID,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAS5D"}
|
package/dist/model/model.js
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { Buffer, Texture, TextureView, Sampler, RenderPipeline, UniformStore, log,
|
|
5
|
-
import { ShaderAssembler
|
|
4
|
+
import { Buffer, Texture, TextureView, Sampler, RenderPipeline, PipelineFactory, ShaderFactory, UniformStore, log, dataTypeDecoder, getAttributeInfosFromLayouts, normalizeBindingsByGroup } from '@luma.gl/core';
|
|
5
|
+
import { ShaderAssembler } from '@luma.gl/shadertools';
|
|
6
6
|
import { makeGPUGeometry } from "../geometry/gpu-geometry.js";
|
|
7
|
-
import { PipelineFactory } from "../factories/pipeline-factory.js";
|
|
8
|
-
import { ShaderFactory } from "../factories/shader-factory.js";
|
|
9
7
|
import { getDebugTableForShaderLayout } from "../debug/debug-shader-layout.js";
|
|
10
8
|
import { debugFramebuffer } from "../debug/debug-framebuffer.js";
|
|
11
9
|
import { deepEqual } from "../utils/deep-equal.js";
|
|
12
10
|
import { BufferLayoutHelper } from "../utils/buffer-layout-helper.js";
|
|
13
11
|
import { sortedBufferLayoutByShaderSourceLocations } from "../utils/buffer-layout-order.js";
|
|
12
|
+
import { mergeShaderModuleBindingsIntoLayout, shaderModuleHasUniforms } from "../utils/shader-module-utils.js";
|
|
14
13
|
import { uid } from "../utils/uid.js";
|
|
15
14
|
import { ShaderInputs } from "../shader-inputs.js";
|
|
16
|
-
import {
|
|
15
|
+
import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
|
|
17
16
|
const LOG_DRAW_PRIORITY = 2;
|
|
18
17
|
const LOG_DRAW_TIMEOUT = 10000;
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
19
|
+
* High level draw API for luma.gl.
|
|
20
|
+
*
|
|
21
|
+
* A `Model` encapsulates shaders, geometry attributes, bindings and render
|
|
22
|
+
* pipeline state into a single object. It automatically reuses and rebuilds
|
|
23
|
+
* pipelines as render parameters change and exposes convenient hooks for
|
|
24
|
+
* updating uniforms and attributes.
|
|
25
|
+
*
|
|
26
|
+
* Features:
|
|
27
|
+
* - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
|
|
28
|
+
* - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
|
|
29
|
+
* - Manages geometry attributes and buffer bindings.
|
|
30
|
+
* - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
|
|
31
|
+
* - Provides detailed debug logging and optional shader source inspection.
|
|
26
32
|
*/
|
|
27
33
|
export class Model {
|
|
28
34
|
static defaultProps = {
|
|
@@ -39,11 +45,14 @@ export class Model {
|
|
|
39
45
|
indexBuffer: null,
|
|
40
46
|
attributes: {},
|
|
41
47
|
constantAttributes: {},
|
|
48
|
+
bindings: {},
|
|
49
|
+
uniforms: {},
|
|
42
50
|
varyings: [],
|
|
43
51
|
isInstanced: undefined,
|
|
44
52
|
instanceCount: 0,
|
|
45
53
|
vertexCount: 0,
|
|
46
54
|
shaderInputs: undefined,
|
|
55
|
+
material: undefined,
|
|
47
56
|
pipelineFactory: undefined,
|
|
48
57
|
shaderFactory: undefined,
|
|
49
58
|
transformFeedback: undefined,
|
|
@@ -51,16 +60,24 @@ export class Model {
|
|
|
51
60
|
debugShaders: undefined,
|
|
52
61
|
disableWarnings: undefined
|
|
53
62
|
};
|
|
63
|
+
/** Device that created this model */
|
|
54
64
|
device;
|
|
65
|
+
/** Application provided identifier */
|
|
55
66
|
id;
|
|
67
|
+
/** WGSL shader source when using unified shader */
|
|
56
68
|
// @ts-expect-error assigned in function called from constructor
|
|
57
69
|
source;
|
|
70
|
+
/** GLSL vertex shader source */
|
|
58
71
|
// @ts-expect-error assigned in function called from constructor
|
|
59
72
|
vs;
|
|
73
|
+
/** GLSL fragment shader source */
|
|
60
74
|
// @ts-expect-error assigned in function called from constructor
|
|
61
75
|
fs;
|
|
76
|
+
/** Factory used to create render pipelines */
|
|
62
77
|
pipelineFactory;
|
|
78
|
+
/** Factory used to create shaders */
|
|
63
79
|
shaderFactory;
|
|
80
|
+
/** User-supplied per-model data */
|
|
64
81
|
userData = {};
|
|
65
82
|
// Fixed properties (change can trigger pipeline rebuild)
|
|
66
83
|
/** The render pipeline GPU parameters, depth testing etc */
|
|
@@ -97,6 +114,7 @@ export class Model {
|
|
|
97
114
|
/** ShaderInputs instance */
|
|
98
115
|
// @ts-expect-error Assigned in function called by constructor
|
|
99
116
|
shaderInputs;
|
|
117
|
+
material = null;
|
|
100
118
|
// @ts-expect-error Assigned in function called by constructor
|
|
101
119
|
_uniformStore;
|
|
102
120
|
_attributeInfos = {};
|
|
@@ -107,6 +125,7 @@ export class Model {
|
|
|
107
125
|
_destroyed = false;
|
|
108
126
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
109
127
|
_lastDrawTimestamp = -1;
|
|
128
|
+
_bindingTable = [];
|
|
110
129
|
get [Symbol.toStringTag]() {
|
|
111
130
|
return 'Model';
|
|
112
131
|
}
|
|
@@ -119,6 +138,7 @@ export class Model {
|
|
|
119
138
|
this.id = props.id || uid('model');
|
|
120
139
|
this.device = device;
|
|
121
140
|
Object.assign(this.userData, props.userData);
|
|
141
|
+
this.material = props.material || null;
|
|
122
142
|
// Setup shader module inputs
|
|
123
143
|
const moduleMap = Object.fromEntries(this.props.modules?.map(module => [module.name, module]) || []);
|
|
124
144
|
const shaderInputs = props.shaderInputs ||
|
|
@@ -131,13 +151,15 @@ export class Model {
|
|
|
131
151
|
const modules =
|
|
132
152
|
// @ts-ignore shaderInputs is assigned in setShaderInputs above.
|
|
133
153
|
(this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
|
|
154
|
+
this.props.shaderLayout =
|
|
155
|
+
mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
|
|
134
156
|
const isWebGPU = this.device.type === 'webgpu';
|
|
135
157
|
// WebGPU
|
|
136
158
|
// TODO - hack to support unified WGSL shader
|
|
137
159
|
// TODO - this is wrong, compile a single shader
|
|
138
160
|
if (isWebGPU && this.props.source) {
|
|
139
161
|
// WGSL
|
|
140
|
-
const { source, getUniforms } = this.props.shaderAssembler.assembleWGSLShader({
|
|
162
|
+
const { source, getUniforms, bindingTable } = this.props.shaderAssembler.assembleWGSLShader({
|
|
141
163
|
platformInfo,
|
|
142
164
|
...this.props,
|
|
143
165
|
modules
|
|
@@ -145,8 +167,11 @@ export class Model {
|
|
|
145
167
|
this.source = source;
|
|
146
168
|
// @ts-expect-error
|
|
147
169
|
this._getModuleUniforms = getUniforms;
|
|
170
|
+
this._bindingTable = bindingTable;
|
|
148
171
|
// Extract shader layout after modules have been added to WGSL source, to include any bindings added by modules
|
|
149
|
-
|
|
172
|
+
const inferredShaderLayout = device.getShaderLayout?.(this.source);
|
|
173
|
+
this.props.shaderLayout =
|
|
174
|
+
mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout || inferredShaderLayout || null, modules) || null;
|
|
150
175
|
}
|
|
151
176
|
else {
|
|
152
177
|
// GLSL
|
|
@@ -159,6 +184,7 @@ export class Model {
|
|
|
159
184
|
this.fs = fs;
|
|
160
185
|
// @ts-expect-error
|
|
161
186
|
this._getModuleUniforms = getUniforms;
|
|
187
|
+
this._bindingTable = [];
|
|
162
188
|
}
|
|
163
189
|
this.vertexCount = this.props.vertexCount;
|
|
164
190
|
this.instanceCount = this.props.instanceCount;
|
|
@@ -208,8 +234,6 @@ export class Model {
|
|
|
208
234
|
if (props.transformFeedback) {
|
|
209
235
|
this.transformFeedback = props.transformFeedback;
|
|
210
236
|
}
|
|
211
|
-
// Catch any access to non-standard props
|
|
212
|
-
Object.seal(this);
|
|
213
237
|
}
|
|
214
238
|
destroy() {
|
|
215
239
|
if (!this._destroyed) {
|
|
@@ -217,7 +241,7 @@ export class Model {
|
|
|
217
241
|
this.pipelineFactory.release(this.pipeline);
|
|
218
242
|
// Release the shaders
|
|
219
243
|
this.shaderFactory.release(this.pipeline.vs);
|
|
220
|
-
if (this.pipeline.fs) {
|
|
244
|
+
if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
|
|
221
245
|
this.shaderFactory.release(this.pipeline.fs);
|
|
222
246
|
}
|
|
223
247
|
this._uniformStore.destroy();
|
|
@@ -241,12 +265,22 @@ export class Model {
|
|
|
241
265
|
setNeedsRedraw(reason) {
|
|
242
266
|
this._needsRedraw ||= reason;
|
|
243
267
|
}
|
|
268
|
+
/** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
|
|
269
|
+
getBindingDebugTable() {
|
|
270
|
+
return this._bindingTable;
|
|
271
|
+
}
|
|
272
|
+
/** Update uniforms and pipeline state prior to drawing. */
|
|
244
273
|
predraw() {
|
|
245
274
|
// Update uniform buffers if needed
|
|
246
275
|
this.updateShaderInputs();
|
|
247
276
|
// Check if the pipeline is invalidated
|
|
248
277
|
this.pipeline = this._updatePipeline();
|
|
249
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Issue one draw call.
|
|
281
|
+
* @param renderPass - render pass to draw into
|
|
282
|
+
* @returns `true` if the draw call was executed, `false` if resources were not ready.
|
|
283
|
+
*/
|
|
250
284
|
draw(renderPass) {
|
|
251
285
|
const loadingBinding = this._areBindingsLoading();
|
|
252
286
|
if (loadingBinding) {
|
|
@@ -268,13 +302,8 @@ export class Model {
|
|
|
268
302
|
// TODO - inside RenderPass is likely the worst place to do this from performance perspective.
|
|
269
303
|
// Application can call Model.predraw() to avoid this.
|
|
270
304
|
this.pipeline = this._updatePipeline();
|
|
271
|
-
// Set pipeline state, we may be sharing a pipeline so we need to set all state on every draw
|
|
272
|
-
// Any caching needs to be done inside the pipeline functions
|
|
273
|
-
// TODO this is a busy initialized check for all bindings every frame
|
|
274
305
|
const syncBindings = this._getBindings();
|
|
275
|
-
this.
|
|
276
|
-
disableWarnings: this.props.disableWarnings
|
|
277
|
-
});
|
|
306
|
+
const syncBindGroups = this._getBindGroups();
|
|
278
307
|
const { indexBuffer } = this.vertexArray;
|
|
279
308
|
const indexCount = indexBuffer
|
|
280
309
|
? indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)
|
|
@@ -287,6 +316,13 @@ export class Model {
|
|
|
287
316
|
instanceCount: this.instanceCount,
|
|
288
317
|
indexCount,
|
|
289
318
|
transformFeedback: this.transformFeedback || undefined,
|
|
319
|
+
// Pipelines may be shared across models when caching is enabled, so bindings
|
|
320
|
+
// and WebGL uniforms must be supplied on every draw instead of being stored
|
|
321
|
+
// on the pipeline instance.
|
|
322
|
+
bindings: syncBindings,
|
|
323
|
+
bindGroups: syncBindGroups,
|
|
324
|
+
_bindGroupCacheKeys: this._getBindGroupCacheKeys(),
|
|
325
|
+
uniforms: this.props.uniforms,
|
|
290
326
|
// WebGL shares underlying cached pipelines even for models that have different parameters and topology,
|
|
291
327
|
// so we must provide our unique parameters to each draw
|
|
292
328
|
// (In WebGPU most parameters are encoded in the pipeline and cannot be changed per draw call)
|
|
@@ -397,20 +433,24 @@ export class Model {
|
|
|
397
433
|
/** Set the shader inputs */
|
|
398
434
|
setShaderInputs(shaderInputs) {
|
|
399
435
|
this.shaderInputs = shaderInputs;
|
|
400
|
-
this._uniformStore = new UniformStore(this.shaderInputs.modules);
|
|
436
|
+
this._uniformStore = new UniformStore(this.device, this.shaderInputs.modules);
|
|
401
437
|
// Create uniform buffer bindings for all modules that actually have uniforms
|
|
402
438
|
for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
|
|
403
|
-
if (shaderModuleHasUniforms(module)) {
|
|
404
|
-
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(
|
|
439
|
+
if (shaderModuleHasUniforms(module) && !this.material?.ownsModule(moduleName)) {
|
|
440
|
+
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
|
|
405
441
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
406
442
|
}
|
|
407
443
|
}
|
|
408
444
|
this.setNeedsRedraw('shaderInputs');
|
|
409
445
|
}
|
|
446
|
+
setMaterial(material) {
|
|
447
|
+
this.material = material;
|
|
448
|
+
this.setNeedsRedraw('material');
|
|
449
|
+
}
|
|
410
450
|
/** Update uniform buffers from the model's shader inputs */
|
|
411
451
|
updateShaderInputs() {
|
|
412
452
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
413
|
-
this.setBindings(this.shaderInputs.getBindingValues());
|
|
453
|
+
this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues()));
|
|
414
454
|
// TODO - this is already tracked through buffer/texture update times?
|
|
415
455
|
this.setNeedsRedraw('shaderInputs');
|
|
416
456
|
}
|
|
@@ -502,7 +542,12 @@ export class Model {
|
|
|
502
542
|
/** Check that bindings are loaded. Returns id of first binding that is still loading. */
|
|
503
543
|
_areBindingsLoading() {
|
|
504
544
|
for (const binding of Object.values(this.bindings)) {
|
|
505
|
-
if (binding instanceof
|
|
545
|
+
if (binding instanceof DynamicTexture && !binding.isReady) {
|
|
546
|
+
return binding.id;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
for (const binding of Object.values(this.material?.bindings || {})) {
|
|
550
|
+
if (binding instanceof DynamicTexture && !binding.isReady) {
|
|
506
551
|
return binding.id;
|
|
507
552
|
}
|
|
508
553
|
}
|
|
@@ -512,7 +557,7 @@ export class Model {
|
|
|
512
557
|
_getBindings() {
|
|
513
558
|
const validBindings = {};
|
|
514
559
|
for (const [name, binding] of Object.entries(this.bindings)) {
|
|
515
|
-
if (binding instanceof
|
|
560
|
+
if (binding instanceof DynamicTexture) {
|
|
516
561
|
// Check that async textures are loaded
|
|
517
562
|
if (binding.isReady) {
|
|
518
563
|
validBindings[name] = binding.texture;
|
|
@@ -524,6 +569,27 @@ export class Model {
|
|
|
524
569
|
}
|
|
525
570
|
return validBindings;
|
|
526
571
|
}
|
|
572
|
+
_getBindGroups() {
|
|
573
|
+
const shaderLayout = this.pipeline?.shaderLayout || this.props.shaderLayout || { bindings: [] };
|
|
574
|
+
const bindGroups = shaderLayout.bindings.length
|
|
575
|
+
? normalizeBindingsByGroup(shaderLayout, this._getBindings())
|
|
576
|
+
: { 0: this._getBindings() };
|
|
577
|
+
if (!this.material) {
|
|
578
|
+
return bindGroups;
|
|
579
|
+
}
|
|
580
|
+
for (const [groupKey, groupBindings] of Object.entries(this.material.getBindingsByGroup())) {
|
|
581
|
+
const group = Number(groupKey);
|
|
582
|
+
bindGroups[group] = {
|
|
583
|
+
...(bindGroups[group] || {}),
|
|
584
|
+
...groupBindings
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
return bindGroups;
|
|
588
|
+
}
|
|
589
|
+
_getBindGroupCacheKeys() {
|
|
590
|
+
const bindGroupCacheKey = this.material?.getBindGroupCacheKey(3);
|
|
591
|
+
return bindGroupCacheKey ? { 3: bindGroupCacheKey } : {};
|
|
592
|
+
}
|
|
527
593
|
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
528
594
|
_getBindingsUpdateTimestamp() {
|
|
529
595
|
let timestamp = 0;
|
|
@@ -534,7 +600,7 @@ export class Model {
|
|
|
534
600
|
else if (binding instanceof Buffer || binding instanceof Texture) {
|
|
535
601
|
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
536
602
|
}
|
|
537
|
-
else if (binding instanceof
|
|
603
|
+
else if (binding instanceof DynamicTexture) {
|
|
538
604
|
timestamp = binding.texture
|
|
539
605
|
? Math.max(timestamp, binding.texture.updateTimestamp)
|
|
540
606
|
: // The texture will become available in the future
|
|
@@ -544,7 +610,7 @@ export class Model {
|
|
|
544
610
|
timestamp = Math.max(timestamp, binding.buffer.updateTimestamp);
|
|
545
611
|
}
|
|
546
612
|
}
|
|
547
|
-
return timestamp;
|
|
613
|
+
return Math.max(timestamp, this.material?.getBindingsUpdateTimestamp() || 0);
|
|
548
614
|
}
|
|
549
615
|
/**
|
|
550
616
|
* Updates the optional geometry attributes
|
|
@@ -603,20 +669,20 @@ export class Model {
|
|
|
603
669
|
}
|
|
604
670
|
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
605
671
|
...this.props,
|
|
672
|
+
bindings: undefined,
|
|
606
673
|
bufferLayout: this.bufferLayout,
|
|
607
674
|
topology: this.topology,
|
|
608
675
|
parameters: this.parameters,
|
|
609
|
-
|
|
610
|
-
// Should we expose a BindGroup abstraction?
|
|
611
|
-
bindings: this._getBindings(),
|
|
676
|
+
bindGroups: this._getBindGroups(),
|
|
612
677
|
vs,
|
|
613
678
|
fs
|
|
614
679
|
});
|
|
615
680
|
this._attributeInfos = getAttributeInfosFromLayouts(this.pipeline.shaderLayout, this.bufferLayout);
|
|
616
681
|
if (prevShaderVs)
|
|
617
682
|
this.shaderFactory.release(prevShaderVs);
|
|
618
|
-
if (prevShaderFs)
|
|
683
|
+
if (prevShaderFs && prevShaderFs !== prevShaderVs) {
|
|
619
684
|
this.shaderFactory.release(prevShaderFs);
|
|
685
|
+
}
|
|
620
686
|
}
|
|
621
687
|
return this.pipeline;
|
|
622
688
|
}
|
|
@@ -691,13 +757,22 @@ export class Model {
|
|
|
691
757
|
}
|
|
692
758
|
// TODO - fix typing of luma data types
|
|
693
759
|
_getBufferOrConstantValues(attribute, dataType) {
|
|
694
|
-
const TypedArrayConstructor = getTypedArrayConstructor(dataType);
|
|
760
|
+
const TypedArrayConstructor = dataTypeDecoder.getTypedArrayConstructor(dataType);
|
|
695
761
|
const typedArray = attribute instanceof Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
696
762
|
return typedArray.toString();
|
|
697
763
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
764
|
+
_getNonMaterialBindings(bindings) {
|
|
765
|
+
if (!this.material) {
|
|
766
|
+
return bindings;
|
|
767
|
+
}
|
|
768
|
+
const filteredBindings = {};
|
|
769
|
+
for (const [name, binding] of Object.entries(bindings)) {
|
|
770
|
+
if (!this.material.ownsBinding(name)) {
|
|
771
|
+
filteredBindings[name] = binding;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return filteredBindings;
|
|
775
|
+
}
|
|
701
776
|
}
|
|
702
777
|
// HELPERS
|
|
703
778
|
/** Create a shadertools platform info from the Device */
|
|
@@ -711,13 +786,4 @@ export function getPlatformInfo(device) {
|
|
|
711
786
|
features: device.features
|
|
712
787
|
};
|
|
713
788
|
}
|
|
714
|
-
/** Returns true if given object is empty, false otherwise. */
|
|
715
|
-
function isObjectEmpty(obj) {
|
|
716
|
-
// @ts-ignore key is unused
|
|
717
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
718
|
-
for (const key in obj) {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
return true;
|
|
722
|
-
}
|
|
723
789
|
//# sourceMappingURL=model.js.map
|