@luma.gl/engine 9.0.0-beta.5 → 9.0.0-beta.7
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/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +3 -3
- package/dist/animation-loop/animation-loop-template.d.ts +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop-template.js +3 -1
- package/dist/animation-loop/animation-loop.d.ts +2 -2
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +14 -6
- package/dist/animation-loop/animation-props.d.ts +2 -2
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts +2 -2
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +4 -2
- package/dist/computation.d.ts +95 -0
- package/dist/computation.d.ts.map +1 -0
- package/dist/computation.js +248 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
- package/dist/debug/copy-texture-to-image.js +5 -2
- package/dist/debug/debug-framebuffer.d.ts.map +1 -1
- package/dist/debug/debug-framebuffer.js +0 -1
- package/dist/debug/pixel-data-utils.d.ts.map +1 -1
- package/dist/debug/pixel-data-utils.js +2 -1
- package/dist/dist.dev.js +713 -329
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +1 -1
- package/dist/geometries/cube-geometry.d.ts +1 -1
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +16 -14
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/plane-geometry.d.ts +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +2 -2
- package/dist/geometries/sphere-geometry.d.ts +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +1 -1
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js +3 -0
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +3 -0
- package/dist/geometry/gpu-geometry.d.ts +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +4 -5
- package/dist/index.cjs +661 -291
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +43 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -23
- package/dist/lib/clip-space.d.ts +1 -1
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +8 -10
- package/dist/lib/pipeline-factory.d.ts +10 -6
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +47 -22
- package/dist/lib/shader-factory.d.ts +17 -0
- package/dist/lib/shader-factory.d.ts.map +1 -0
- package/dist/lib/shader-factory.js +46 -0
- package/dist/model/model.d.ts +58 -45
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +213 -120
- package/dist/scenegraph/group-node.d.ts +1 -1
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +10 -5
- package/dist/scenegraph/model-node.d.ts +3 -3
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js +2 -2
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +3 -0
- package/dist/transform/buffer-transform.d.ts +1 -1
- package/dist/transform/buffer-transform.d.ts.map +1 -1
- package/dist/transform/buffer-transform.js +7 -6
- package/dist/transform/texture-transform.d.ts +1 -1
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js +10 -8
- package/dist.min.js +2 -2
- package/package.json +2 -2
- package/src/animation/timeline.ts +20 -20
- package/src/animation-loop/animation-loop-template.ts +10 -8
- package/src/animation-loop/animation-loop.ts +20 -10
- package/src/animation-loop/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +17 -8
- package/src/computation.ts +346 -0
- package/src/debug/copy-texture-to-image.ts +8 -6
- package/src/debug/debug-framebuffer.ts +16 -3
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/debug/pixel-data-utils.ts +3 -6
- package/src/geometries/cube-geometry.ts +17 -13
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +2 -1
- package/src/geometry/geometry-table.ts +9 -6
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +9 -6
- package/src/geometry/gpu-geometry.ts +18 -11
- package/src/index.ts +3 -0
- package/src/lib/clip-space.ts +14 -18
- package/src/lib/pipeline-factory.ts +62 -28
- package/src/lib/shader-factory.ts +57 -0
- package/src/model/model.ts +249 -146
- package/src/scenegraph/group-node.ts +14 -10
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +2 -2
- package/src/shader-inputs.ts +19 -12
- package/src/transform/buffer-transform.ts +15 -7
- package/src/transform/texture-transform.ts +14 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model.d.ts","source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A;KAAC,GAC5C,IAAI;IAkCP;;;;;;;OAOG;IACH,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAgBnE;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAI;IAQzD;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAUtD,0FAA0F;IAC1F,2BAA2B,IAAI,MAAM;IAcrC;;;;OAIG;IACH,sBAAsB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAqBtD,sCAAsC;IACtC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK7C,gCAAgC;IAChC,eAAe,IAAI,cAAc;IAsDjC,iCAAiC;IACjC,YAAY,SAAK;IACjB,QAAQ,UAAS;IAEjB,iBAAiB,IAAI,IAAI;IAazB,eAAe,IAAI,IAAI;IAwBvB,SAAS,CAAC,UAAU,SAAK;IACzB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAe7C,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;CAMlF;AAkBD,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAS5D"}
|
package/dist/model/model.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
|
-
import { Buffer,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { Buffer, Texture, TextureView, Sampler } from '@luma.gl/core';
|
|
5
|
+
import { RenderPipeline, UniformStore } from '@luma.gl/core';
|
|
6
|
+
import { log, uid, deepEqual, isObjectEmpty, splitUniformsAndBindings } from '@luma.gl/core';
|
|
7
|
+
import { getTypedArrayFromDataType, getAttributeInfosFromLayouts } from '@luma.gl/core';
|
|
6
8
|
import { ShaderAssembler, getShaderLayoutFromWGSL } from '@luma.gl/shadertools';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { PipelineFactory } from
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { makeGPUGeometry } from "../geometry/gpu-geometry.js";
|
|
10
|
+
import { ShaderInputs } from "../shader-inputs.js";
|
|
11
|
+
import { PipelineFactory } from "../lib/pipeline-factory.js";
|
|
12
|
+
import { ShaderFactory } from "../lib/shader-factory.js";
|
|
13
|
+
import { getDebugTableForShaderLayout } from "../debug/debug-shader-layout.js";
|
|
14
|
+
import { debugFramebuffer } from "../debug/debug-framebuffer.js";
|
|
12
15
|
const LOG_DRAW_PRIORITY = 2;
|
|
13
16
|
const LOG_DRAW_TIMEOUT = 10000;
|
|
14
17
|
/**
|
|
@@ -38,14 +41,19 @@ export class Model {
|
|
|
38
41
|
varyings: [],
|
|
39
42
|
shaderInputs: undefined,
|
|
40
43
|
pipelineFactory: undefined,
|
|
44
|
+
shaderFactory: undefined,
|
|
41
45
|
transformFeedback: undefined,
|
|
42
|
-
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
|
|
46
|
+
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler(),
|
|
47
|
+
debugShaders: undefined,
|
|
48
|
+
ignoreUnknownAttributes: undefined
|
|
43
49
|
};
|
|
44
50
|
device;
|
|
45
51
|
id;
|
|
52
|
+
source;
|
|
46
53
|
vs;
|
|
47
54
|
fs;
|
|
48
55
|
pipelineFactory;
|
|
56
|
+
shaderFactory;
|
|
49
57
|
userData = {};
|
|
50
58
|
// Fixed properties (change can trigger pipeline rebuild)
|
|
51
59
|
/** The render pipeline GPU parameters, depth testing etc */
|
|
@@ -82,11 +90,15 @@ export class Model {
|
|
|
82
90
|
/** ShaderInputs instance */
|
|
83
91
|
shaderInputs;
|
|
84
92
|
_uniformStore;
|
|
85
|
-
_pipelineNeedsUpdate = 'newly created';
|
|
86
93
|
_attributeInfos = {};
|
|
87
94
|
_gpuGeometry = null;
|
|
88
95
|
_getModuleUniforms;
|
|
89
96
|
props;
|
|
97
|
+
_pipelineNeedsUpdate = 'newly created';
|
|
98
|
+
_needsRedraw = 'initializing';
|
|
99
|
+
_destroyed = false;
|
|
100
|
+
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
101
|
+
_lastDrawTimestamp = -1;
|
|
90
102
|
constructor(device, props) {
|
|
91
103
|
this.props = { ...Model.defaultProps, ...props };
|
|
92
104
|
props = this.props;
|
|
@@ -96,32 +108,36 @@ export class Model {
|
|
|
96
108
|
// Setup shader module inputs
|
|
97
109
|
const moduleMap = Object.fromEntries(this.props.modules?.map(module => [module.name, module]) || []);
|
|
98
110
|
this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
|
|
99
|
-
const isWebGPU = this.device.info.type === 'webgpu';
|
|
100
|
-
// TODO - hack to support unified WGSL shader
|
|
101
|
-
// TODO - this is wrong, compile a single shader
|
|
102
|
-
if (this.props.source) {
|
|
103
|
-
if (isWebGPU) {
|
|
104
|
-
this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.source);
|
|
105
|
-
}
|
|
106
|
-
this.props.fs = this.props.source;
|
|
107
|
-
this.props.vs = this.props.source;
|
|
108
|
-
}
|
|
109
|
-
// Support WGSL shader layout introspection
|
|
110
|
-
if (isWebGPU && typeof this.props.vs !== 'string') {
|
|
111
|
-
this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.vs.wgsl);
|
|
112
|
-
}
|
|
113
111
|
// Setup shader assembler
|
|
114
112
|
const platformInfo = getPlatformInfo(device);
|
|
115
113
|
// Extract modules from shader inputs if not supplied
|
|
116
114
|
const modules = (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
const isWebGPU = this.device.type === 'webgpu';
|
|
116
|
+
// WebGPU
|
|
117
|
+
// TODO - hack to support unified WGSL shader
|
|
118
|
+
// TODO - this is wrong, compile a single shader
|
|
119
|
+
if (isWebGPU && this.props.source) {
|
|
120
|
+
// WGSL
|
|
121
|
+
this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.source);
|
|
122
|
+
const { source, getUniforms } = this.props.shaderAssembler.assembleShader({
|
|
123
|
+
platformInfo,
|
|
124
|
+
...this.props,
|
|
125
|
+
modules
|
|
126
|
+
});
|
|
127
|
+
this.source = source;
|
|
128
|
+
this._getModuleUniforms = getUniforms;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// GLSL
|
|
132
|
+
const { vs, fs, getUniforms } = this.props.shaderAssembler.assembleShaderPair({
|
|
133
|
+
platformInfo,
|
|
134
|
+
...this.props,
|
|
135
|
+
modules
|
|
136
|
+
});
|
|
137
|
+
this.vs = vs;
|
|
138
|
+
this.fs = fs;
|
|
139
|
+
this._getModuleUniforms = getUniforms;
|
|
140
|
+
}
|
|
125
141
|
this.vertexCount = this.props.vertexCount;
|
|
126
142
|
this.instanceCount = this.props.instanceCount;
|
|
127
143
|
this.topology = this.props.topology;
|
|
@@ -129,10 +145,11 @@ export class Model {
|
|
|
129
145
|
this.parameters = this.props.parameters;
|
|
130
146
|
// Geometry, if provided, sets topology and vertex cound
|
|
131
147
|
if (props.geometry) {
|
|
132
|
-
this.
|
|
148
|
+
this.setGeometry(props.geometry);
|
|
133
149
|
}
|
|
134
150
|
this.pipelineFactory =
|
|
135
151
|
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
152
|
+
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
136
153
|
// Create the pipeline
|
|
137
154
|
// @note order is important
|
|
138
155
|
this.pipeline = this._updatePipeline();
|
|
@@ -158,7 +175,9 @@ export class Model {
|
|
|
158
175
|
this.setIndexBuffer(props.indexBuffer);
|
|
159
176
|
}
|
|
160
177
|
if (props.attributes) {
|
|
161
|
-
this.setAttributes(props.attributes
|
|
178
|
+
this.setAttributes(props.attributes, {
|
|
179
|
+
ignoreUnknownAttributes: props.ignoreUnknownAttributes
|
|
180
|
+
});
|
|
162
181
|
}
|
|
163
182
|
if (props.constantAttributes) {
|
|
164
183
|
this.setConstantAttributes(props.constantAttributes);
|
|
@@ -176,34 +195,63 @@ export class Model {
|
|
|
176
195
|
if (props.transformFeedback) {
|
|
177
196
|
this.transformFeedback = props.transformFeedback;
|
|
178
197
|
}
|
|
179
|
-
// TODO - restore?
|
|
180
|
-
// this.setUniforms(this._getModuleUniforms()); // Get all default module uniforms
|
|
181
198
|
// Catch any access to non-standard props
|
|
182
199
|
Object.seal(this);
|
|
183
200
|
}
|
|
184
201
|
destroy() {
|
|
202
|
+
if (this._destroyed)
|
|
203
|
+
return;
|
|
185
204
|
this.pipelineFactory.release(this.pipeline);
|
|
205
|
+
this.shaderFactory.release(this.pipeline.vs);
|
|
206
|
+
if (this.pipeline.fs) {
|
|
207
|
+
this.shaderFactory.release(this.pipeline.fs);
|
|
208
|
+
}
|
|
186
209
|
this._uniformStore.destroy();
|
|
210
|
+
// TODO - mark resource as managed and destroyIfManaged() ?
|
|
211
|
+
this._gpuGeometry?.destroy();
|
|
212
|
+
this._destroyed = true;
|
|
187
213
|
}
|
|
188
214
|
// Draw call
|
|
215
|
+
/** Query redraw status. Clears the status. */
|
|
216
|
+
needsRedraw() {
|
|
217
|
+
// Catch any writes to already bound resources
|
|
218
|
+
if (this._getBindingsUpdateTimestamp() > this._lastDrawTimestamp) {
|
|
219
|
+
this.setNeedsRedraw('contents of bound textures or buffers updated');
|
|
220
|
+
}
|
|
221
|
+
const needsRedraw = this._needsRedraw;
|
|
222
|
+
this._needsRedraw = false;
|
|
223
|
+
return needsRedraw;
|
|
224
|
+
}
|
|
225
|
+
/** Mark the model as needing a redraw */
|
|
226
|
+
setNeedsRedraw(reason) {
|
|
227
|
+
this._needsRedraw ||= reason;
|
|
228
|
+
}
|
|
189
229
|
predraw() {
|
|
190
230
|
// Update uniform buffers if needed
|
|
191
231
|
this.updateShaderInputs();
|
|
232
|
+
// Check if the pipeline is invalidated
|
|
233
|
+
this.pipeline = this._updatePipeline();
|
|
192
234
|
}
|
|
193
235
|
draw(renderPass) {
|
|
194
236
|
this.predraw();
|
|
237
|
+
let drawSuccess;
|
|
195
238
|
try {
|
|
196
239
|
this._logDrawCallStart();
|
|
197
|
-
//
|
|
198
|
-
// TODO -
|
|
240
|
+
// Update the pipeline if invalidated
|
|
241
|
+
// TODO - inside RenderPass is likely the worst place to do this from performance perspective.
|
|
242
|
+
// Application can call Model.predraw() to avoid this.
|
|
199
243
|
this.pipeline = this._updatePipeline();
|
|
200
244
|
// Set pipeline state, we may be sharing a pipeline so we need to set all state on every draw
|
|
201
245
|
// Any caching needs to be done inside the pipeline functions
|
|
202
246
|
this.pipeline.setBindings(this.bindings);
|
|
203
|
-
|
|
247
|
+
if (!isObjectEmpty(this.uniforms)) {
|
|
248
|
+
this.pipeline.setUniformsWebGL(this.uniforms);
|
|
249
|
+
}
|
|
204
250
|
const { indexBuffer } = this.vertexArray;
|
|
205
|
-
const indexCount = indexBuffer
|
|
206
|
-
|
|
251
|
+
const indexCount = indexBuffer
|
|
252
|
+
? indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)
|
|
253
|
+
: undefined;
|
|
254
|
+
drawSuccess = this.pipeline.draw({
|
|
207
255
|
renderPass,
|
|
208
256
|
vertexArray: this.vertexArray,
|
|
209
257
|
vertexCount: this.vertexCount,
|
|
@@ -216,6 +264,15 @@ export class Model {
|
|
|
216
264
|
this._logDrawCallEnd();
|
|
217
265
|
}
|
|
218
266
|
this._logFramebuffer(renderPass);
|
|
267
|
+
// Update needsRedraw flag
|
|
268
|
+
if (drawSuccess) {
|
|
269
|
+
this._lastDrawTimestamp = this.device.timestamp;
|
|
270
|
+
this._needsRedraw = false;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
this._needsRedraw = 'waiting for resource initialization';
|
|
274
|
+
}
|
|
275
|
+
return drawSuccess;
|
|
219
276
|
}
|
|
220
277
|
// Update fixed fields (can trigger pipeline rebuild)
|
|
221
278
|
/**
|
|
@@ -224,33 +281,16 @@ export class Model {
|
|
|
224
281
|
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
225
282
|
*/
|
|
226
283
|
setGeometry(geometry) {
|
|
284
|
+
this._gpuGeometry?.destroy();
|
|
227
285
|
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.
|
|
232
|
-
|
|
233
|
-
return gpuGeometry;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Updates the optional geometry attributes
|
|
237
|
-
* Geometry, sets several attributes, indexBuffer, and also vertex count
|
|
238
|
-
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
239
|
-
*/
|
|
240
|
-
_setGeometryAttributes(gpuGeometry) {
|
|
241
|
-
// Filter geometry attribute so that we don't issue warnings for unused attributes
|
|
242
|
-
const attributes = { ...gpuGeometry.attributes };
|
|
243
|
-
for (const [attributeName] of Object.entries(attributes)) {
|
|
244
|
-
if (!this.pipeline.shaderLayout.attributes.find(layout => layout.name === attributeName) &&
|
|
245
|
-
attributeName !== 'positions') {
|
|
246
|
-
delete attributes[attributeName];
|
|
286
|
+
if (gpuGeometry) {
|
|
287
|
+
this.setTopology(gpuGeometry.topology || 'triangle-list');
|
|
288
|
+
this.bufferLayout = mergeBufferLayouts(gpuGeometry.bufferLayout, this.bufferLayout);
|
|
289
|
+
if (this.vertexArray) {
|
|
290
|
+
this._setGeometryAttributes(gpuGeometry);
|
|
247
291
|
}
|
|
248
292
|
}
|
|
249
|
-
|
|
250
|
-
this.vertexCount = gpuGeometry.vertexCount;
|
|
251
|
-
this.setIndexBuffer(gpuGeometry.indices);
|
|
252
|
-
this.setAttributes(gpuGeometry.attributes, 'ignore-unknown');
|
|
253
|
-
this.setAttributes(attributes);
|
|
293
|
+
this._gpuGeometry = gpuGeometry;
|
|
254
294
|
}
|
|
255
295
|
/**
|
|
256
296
|
* Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
|
|
@@ -264,13 +304,12 @@ export class Model {
|
|
|
264
304
|
}
|
|
265
305
|
/**
|
|
266
306
|
* Updates the buffer layout.
|
|
267
|
-
* @note Triggers a pipeline rebuild / pipeline cache fetch
|
|
307
|
+
* @note Triggers a pipeline rebuild / pipeline cache fetch
|
|
268
308
|
*/
|
|
269
309
|
setBufferLayout(bufferLayout) {
|
|
270
310
|
this.bufferLayout = this._gpuGeometry
|
|
271
311
|
? mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout)
|
|
272
312
|
: bufferLayout;
|
|
273
|
-
this._setPipelineNeedsUpdate('bufferLayout');
|
|
274
313
|
// Recreate the pipeline
|
|
275
314
|
this.pipeline = this._updatePipeline();
|
|
276
315
|
// vertex array needs to be updated if we update buffer layout,
|
|
@@ -282,6 +321,7 @@ export class Model {
|
|
|
282
321
|
if (this._gpuGeometry) {
|
|
283
322
|
this._setGeometryAttributes(this._gpuGeometry);
|
|
284
323
|
}
|
|
324
|
+
this._setPipelineNeedsUpdate('bufferLayout');
|
|
285
325
|
}
|
|
286
326
|
/**
|
|
287
327
|
* Set GPU parameters.
|
|
@@ -301,6 +341,7 @@ export class Model {
|
|
|
301
341
|
*/
|
|
302
342
|
setVertexCount(vertexCount) {
|
|
303
343
|
this.vertexCount = vertexCount;
|
|
344
|
+
this.setNeedsRedraw('vertexCount');
|
|
304
345
|
}
|
|
305
346
|
/**
|
|
306
347
|
* Updates the instance count (used in draw calls)
|
|
@@ -308,6 +349,7 @@ export class Model {
|
|
|
308
349
|
*/
|
|
309
350
|
setInstanceCount(instanceCount) {
|
|
310
351
|
this.instanceCount = instanceCount;
|
|
352
|
+
this.setNeedsRedraw('instanceCount');
|
|
311
353
|
}
|
|
312
354
|
setShaderInputs(shaderInputs) {
|
|
313
355
|
this.shaderInputs = shaderInputs;
|
|
@@ -317,51 +359,26 @@ export class Model {
|
|
|
317
359
|
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
|
|
318
360
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
319
361
|
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Updates shader module settings (which results in uniforms being set)
|
|
323
|
-
*/
|
|
324
|
-
setShaderModuleProps(props) {
|
|
325
|
-
const uniforms = this._getModuleUniforms(props);
|
|
326
|
-
// Extract textures & framebuffers set by the modules
|
|
327
|
-
// TODO better way to extract bindings
|
|
328
|
-
const keys = Object.keys(uniforms).filter(k => {
|
|
329
|
-
const uniform = uniforms[k];
|
|
330
|
-
return !isNumberArray(uniform) && typeof uniform !== 'number' && typeof uniform !== 'boolean';
|
|
331
|
-
});
|
|
332
|
-
const bindings = {};
|
|
333
|
-
for (const k of keys) {
|
|
334
|
-
bindings[k] = uniforms[k];
|
|
335
|
-
delete uniforms[k];
|
|
336
|
-
}
|
|
362
|
+
this.setNeedsRedraw('shaderInputs');
|
|
337
363
|
}
|
|
338
364
|
updateShaderInputs() {
|
|
339
365
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
* @deprecated Updates shader module settings (which results in uniforms being set)
|
|
343
|
-
*/
|
|
344
|
-
updateModuleSettings(props) {
|
|
345
|
-
log.warn('Model.updateModuleSettings is deprecated. Use Model.shaderInputs.setProps()')();
|
|
346
|
-
const { bindings, uniforms } = splitUniformsAndBindings(this._getModuleUniforms(props));
|
|
347
|
-
Object.assign(this.bindings, bindings);
|
|
348
|
-
Object.assign(this.uniforms, uniforms);
|
|
366
|
+
// TODO - this is already tracked through buffer/texture update times?
|
|
367
|
+
this.setNeedsRedraw('shaderInputs');
|
|
349
368
|
}
|
|
350
369
|
/**
|
|
351
370
|
* Sets bindings (textures, samplers, uniform buffers)
|
|
352
371
|
*/
|
|
353
372
|
setBindings(bindings) {
|
|
354
373
|
Object.assign(this.bindings, bindings);
|
|
374
|
+
this.setNeedsRedraw('bindings');
|
|
355
375
|
}
|
|
356
376
|
/**
|
|
357
|
-
*
|
|
358
|
-
* @deprecated WebGL only, use uniform buffers for portability
|
|
359
|
-
* @param uniforms
|
|
360
|
-
* @returns self for chaining
|
|
377
|
+
* Updates optional transform feedback. WebGL only.
|
|
361
378
|
*/
|
|
362
|
-
|
|
363
|
-
this.
|
|
364
|
-
|
|
379
|
+
setTransformFeedback(transformFeedback) {
|
|
380
|
+
this.transformFeedback = transformFeedback;
|
|
381
|
+
this.setNeedsRedraw('transformFeedback');
|
|
365
382
|
}
|
|
366
383
|
/**
|
|
367
384
|
* Sets the index buffer
|
|
@@ -369,18 +386,13 @@ export class Model {
|
|
|
369
386
|
*/
|
|
370
387
|
setIndexBuffer(indexBuffer) {
|
|
371
388
|
this.vertexArray.setIndexBuffer(indexBuffer);
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Updates optional transform feedback. WebGL only.
|
|
375
|
-
*/
|
|
376
|
-
setTransformFeedback(transformFeedback) {
|
|
377
|
-
this.transformFeedback = transformFeedback;
|
|
389
|
+
this.setNeedsRedraw('indexBuffer');
|
|
378
390
|
}
|
|
379
391
|
/**
|
|
380
392
|
* Sets attributes (buffers)
|
|
381
393
|
* @note Overrides any attributes previously set with the same name
|
|
382
394
|
*/
|
|
383
|
-
setAttributes(buffers,
|
|
395
|
+
setAttributes(buffers, options) {
|
|
384
396
|
if (buffers.indices) {
|
|
385
397
|
log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
|
|
386
398
|
}
|
|
@@ -400,10 +412,11 @@ export class Model {
|
|
|
400
412
|
set = true;
|
|
401
413
|
}
|
|
402
414
|
}
|
|
403
|
-
if (!set &&
|
|
415
|
+
if (!set && (options?.ignoreUnknownAttributes || this.props.ignoreUnknownAttributes)) {
|
|
404
416
|
log.warn(`Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`)();
|
|
405
417
|
}
|
|
406
418
|
}
|
|
419
|
+
this.setNeedsRedraw('attributes');
|
|
407
420
|
}
|
|
408
421
|
/**
|
|
409
422
|
* Sets constant attributes
|
|
@@ -417,34 +430,109 @@ export class Model {
|
|
|
417
430
|
for (const [attributeName, value] of Object.entries(attributes)) {
|
|
418
431
|
const attributeInfo = this._attributeInfos[attributeName];
|
|
419
432
|
if (attributeInfo) {
|
|
420
|
-
this.vertexArray.
|
|
433
|
+
this.vertexArray.setConstantWebGL(attributeInfo.location, value);
|
|
421
434
|
}
|
|
422
435
|
else {
|
|
423
436
|
log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`)();
|
|
424
437
|
}
|
|
425
438
|
}
|
|
439
|
+
this.setNeedsRedraw('constants');
|
|
440
|
+
}
|
|
441
|
+
// DEPRECATED METHODS
|
|
442
|
+
/**
|
|
443
|
+
* Sets individual uniforms
|
|
444
|
+
* @deprecated WebGL only, use uniform buffers for portability
|
|
445
|
+
* @param uniforms
|
|
446
|
+
*/
|
|
447
|
+
setUniforms(uniforms) {
|
|
448
|
+
if (!isObjectEmpty(uniforms)) {
|
|
449
|
+
this.pipeline.setUniformsWebGL(uniforms);
|
|
450
|
+
Object.assign(this.uniforms, uniforms);
|
|
451
|
+
}
|
|
452
|
+
this.setNeedsRedraw('uniforms');
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* @deprecated Updates shader module settings (which results in uniforms being set)
|
|
456
|
+
*/
|
|
457
|
+
updateModuleSettings(props) {
|
|
458
|
+
log.warn('Model.updateModuleSettings is deprecated. Use Model.shaderInputs.setProps()')();
|
|
459
|
+
const { bindings, uniforms } = splitUniformsAndBindings(this._getModuleUniforms(props));
|
|
460
|
+
Object.assign(this.bindings, bindings);
|
|
461
|
+
Object.assign(this.uniforms, uniforms);
|
|
462
|
+
this.setNeedsRedraw('moduleSettings');
|
|
463
|
+
}
|
|
464
|
+
// Internal methods
|
|
465
|
+
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
466
|
+
_getBindingsUpdateTimestamp() {
|
|
467
|
+
let timestamp = 0;
|
|
468
|
+
for (const binding of Object.values(this.bindings)) {
|
|
469
|
+
if (binding instanceof TextureView) {
|
|
470
|
+
timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
|
|
471
|
+
}
|
|
472
|
+
else if (binding instanceof Buffer || binding instanceof Texture) {
|
|
473
|
+
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
474
|
+
}
|
|
475
|
+
else if (!(binding instanceof Sampler)) {
|
|
476
|
+
timestamp = Math.max(timestamp, binding.buffer.updateTimestamp);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return timestamp;
|
|
426
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* Updates the optional geometry attributes
|
|
483
|
+
* Geometry, sets several attributes, indexBuffer, and also vertex count
|
|
484
|
+
* @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
|
|
485
|
+
*/
|
|
486
|
+
_setGeometryAttributes(gpuGeometry) {
|
|
487
|
+
// Filter geometry attribute so that we don't issue warnings for unused attributes
|
|
488
|
+
const attributes = { ...gpuGeometry.attributes };
|
|
489
|
+
for (const [attributeName] of Object.entries(attributes)) {
|
|
490
|
+
if (!this.pipeline.shaderLayout.attributes.find(layout => layout.name === attributeName) &&
|
|
491
|
+
attributeName !== 'positions') {
|
|
492
|
+
delete attributes[attributeName];
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// TODO - delete previous geometry?
|
|
496
|
+
this.vertexCount = gpuGeometry.vertexCount;
|
|
497
|
+
this.setIndexBuffer(gpuGeometry.indices);
|
|
498
|
+
this.setAttributes(gpuGeometry.attributes, { ignoreUnknownAttributes: true });
|
|
499
|
+
this.setAttributes(attributes, { ignoreUnknownAttributes: this.props.ignoreUnknownAttributes });
|
|
500
|
+
this.setNeedsRedraw('geometry attributes');
|
|
501
|
+
}
|
|
502
|
+
/** Mark pipeline as needing update */
|
|
427
503
|
_setPipelineNeedsUpdate(reason) {
|
|
428
|
-
this._pipelineNeedsUpdate
|
|
504
|
+
this._pipelineNeedsUpdate ||= reason;
|
|
505
|
+
this.setNeedsRedraw(reason);
|
|
429
506
|
}
|
|
507
|
+
/** Update pipeline if needed */
|
|
430
508
|
_updatePipeline() {
|
|
431
509
|
if (this._pipelineNeedsUpdate) {
|
|
510
|
+
let prevShaderVs = null;
|
|
511
|
+
let prevShaderFs = null;
|
|
432
512
|
if (this.pipeline) {
|
|
433
513
|
log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
514
|
+
prevShaderVs = this.pipeline.vs;
|
|
515
|
+
prevShaderFs = this.pipeline.fs;
|
|
434
516
|
}
|
|
435
517
|
this._pipelineNeedsUpdate = false;
|
|
436
|
-
const vs = this.
|
|
518
|
+
const vs = this.shaderFactory.createShader({
|
|
437
519
|
id: `${this.id}-vertex`,
|
|
438
520
|
stage: 'vertex',
|
|
439
|
-
source: this.vs
|
|
521
|
+
source: this.source || this.vs,
|
|
522
|
+
debug: this.props.debugShaders
|
|
440
523
|
});
|
|
441
|
-
|
|
442
|
-
|
|
524
|
+
let fs = null;
|
|
525
|
+
if (this.source) {
|
|
526
|
+
fs = vs;
|
|
527
|
+
}
|
|
528
|
+
else if (this.fs) {
|
|
529
|
+
fs = this.shaderFactory.createShader({
|
|
443
530
|
id: `${this.id}-fragment`,
|
|
444
531
|
stage: 'fragment',
|
|
445
|
-
source: this.fs
|
|
446
|
-
|
|
447
|
-
|
|
532
|
+
source: this.source || this.fs,
|
|
533
|
+
debug: this.props.debugShaders
|
|
534
|
+
});
|
|
535
|
+
}
|
|
448
536
|
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
449
537
|
...this.props,
|
|
450
538
|
bufferLayout: this.bufferLayout,
|
|
@@ -454,6 +542,10 @@ export class Model {
|
|
|
454
542
|
fs
|
|
455
543
|
});
|
|
456
544
|
this._attributeInfos = getAttributeInfosFromLayouts(this.pipeline.shaderLayout, this.bufferLayout);
|
|
545
|
+
if (prevShaderVs)
|
|
546
|
+
this.shaderFactory.release(prevShaderVs);
|
|
547
|
+
if (prevShaderFs)
|
|
548
|
+
this.shaderFactory.release(prevShaderFs);
|
|
457
549
|
}
|
|
458
550
|
return this.pipeline;
|
|
459
551
|
}
|
|
@@ -494,7 +586,7 @@ export class Model {
|
|
|
494
586
|
const debugFramebuffers = log.get('framebuffer');
|
|
495
587
|
this._drawCount++;
|
|
496
588
|
// Update first 3 frames and then every 60 frames
|
|
497
|
-
if (!debugFramebuffers || (
|
|
589
|
+
if (!debugFramebuffers || (this._drawCount++ > 3 && this._drawCount % 60)) {
|
|
498
590
|
return;
|
|
499
591
|
}
|
|
500
592
|
// TODO - display framebuffer output in debug window
|
|
@@ -551,10 +643,11 @@ function mergeBufferLayouts(layouts1, layouts2) {
|
|
|
551
643
|
/** Create a shadertools platform info from the Device */
|
|
552
644
|
export function getPlatformInfo(device) {
|
|
553
645
|
return {
|
|
554
|
-
type: device.
|
|
646
|
+
type: device.type,
|
|
555
647
|
shaderLanguage: device.info.shadingLanguage,
|
|
556
648
|
shaderLanguageVersion: device.info.shadingLanguageVersion,
|
|
557
649
|
gpu: device.info.gpu,
|
|
650
|
+
// HACK - we pretend that the DeviceFeatures is a Set, it has a similar API
|
|
558
651
|
features: device.features
|
|
559
652
|
};
|
|
560
653
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Matrix4 } from '@math.gl/core';
|
|
2
|
-
import { ScenegraphNode, ScenegraphNodeProps } from
|
|
2
|
+
import { ScenegraphNode, ScenegraphNodeProps } from "./scenegraph-node.js";
|
|
3
3
|
export type GroupNodeProps = ScenegraphNodeProps & {
|
|
4
4
|
children?: ScenegraphNode[];
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-node.d.ts","sourceRoot":"","sources":["../../src/scenegraph/group-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAU,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,
|
|
1
|
+
{"version":3,"file":"group-node.d.ts","sourceRoot":"","sources":["../../src/scenegraph/group-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAU,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,6BAA0B;AAEtE,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG;IACjD,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF,qBAAa,SAAU,SAAQ,cAAc;IAC3C,QAAQ,EAAE,cAAc,EAAE,CAAC;gBAEf,QAAQ,EAAE,cAAc,EAAE;gBAC1B,KAAK,CAAC,EAAE,cAAc;IAazB,SAAS,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI;IAmCxC,OAAO,IAAI,IAAI;IAOxB,GAAG,CAAC,GAAG,QAAQ,EAAE,CAAC,cAAc,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,IAAI;IAW7D,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IASnC,SAAS,IAAI,IAAI;IAKjB,QAAQ,CACN,OAAO,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE;QAAC,WAAW,EAAE,OAAO,CAAA;KAAC,KAAK,IAAI,EACxE,EAAC,WAA2B,EAAC;;KAAK;CAYrC"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
2
2
|
import { log } from '@luma.gl/core';
|
|
3
|
-
import { ScenegraphNode } from
|
|
3
|
+
import { ScenegraphNode } from "./scenegraph-node.js";
|
|
4
4
|
export class GroupNode extends ScenegraphNode {
|
|
5
5
|
children;
|
|
6
6
|
constructor(props = {}) {
|
|
7
7
|
props = Array.isArray(props) ? { children: props } : props;
|
|
8
8
|
const { children = [] } = props;
|
|
9
|
-
log.assert(children.every(
|
|
9
|
+
log.assert(children.every(child => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
|
|
10
10
|
super(props);
|
|
11
11
|
this.children = children;
|
|
12
12
|
}
|
|
13
13
|
getBounds() {
|
|
14
|
-
const result = [
|
|
14
|
+
const result = [
|
|
15
|
+
[Infinity, Infinity, Infinity],
|
|
16
|
+
[-Infinity, -Infinity, -Infinity]
|
|
17
|
+
];
|
|
15
18
|
this.traverse((node, { worldMatrix }) => {
|
|
16
19
|
const bounds = node.getBounds();
|
|
17
20
|
if (!bounds) {
|
|
@@ -24,7 +27,9 @@ export class GroupNode extends ScenegraphNode {
|
|
|
24
27
|
worldMatrix.transformAsVector(halfSize, halfSize);
|
|
25
28
|
for (let v = 0; v < 8; v++) {
|
|
26
29
|
// Test all 8 corners of the box
|
|
27
|
-
const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1)
|
|
30
|
+
const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1)
|
|
31
|
+
.multiply(halfSize)
|
|
32
|
+
.add(center);
|
|
28
33
|
for (let i = 0; i < 3; i++) {
|
|
29
34
|
result[0][i] = Math.min(result[0][i], position[i]);
|
|
30
35
|
result[1][i] = Math.max(result[1][i], position[i]);
|
|
@@ -37,7 +42,7 @@ export class GroupNode extends ScenegraphNode {
|
|
|
37
42
|
return result;
|
|
38
43
|
}
|
|
39
44
|
destroy() {
|
|
40
|
-
this.children.forEach(
|
|
45
|
+
this.children.forEach(child => child.destroy());
|
|
41
46
|
this.removeAll();
|
|
42
47
|
super.destroy();
|
|
43
48
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RenderPass } from '@luma.gl/core';
|
|
2
|
-
import { ScenegraphNode, ScenegraphNodeProps } from
|
|
3
|
-
import { Model } from
|
|
2
|
+
import { ScenegraphNode, ScenegraphNodeProps } from "./scenegraph-node.js";
|
|
3
|
+
import { Model } from "../model/model.js";
|
|
4
4
|
export type ModelNodeProps = ScenegraphNodeProps & {
|
|
5
5
|
model: Model;
|
|
6
6
|
managedResources?: any[];
|
|
@@ -13,6 +13,6 @@ export declare class ModelNode extends ScenegraphNode {
|
|
|
13
13
|
constructor(props: ModelNodeProps);
|
|
14
14
|
getBounds(): [number[], number[]] | null;
|
|
15
15
|
destroy(): void;
|
|
16
|
-
draw(renderPass?: RenderPass):
|
|
16
|
+
draw(renderPass?: RenderPass): boolean;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=model-node.d.ts.map
|