@luma.gl/engine 8.6.0-alpha.4 → 9.0.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/key-frames.d.ts +1 -0
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +2 -2
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +4 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +31 -7
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +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/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +15 -3
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +29 -15
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +15 -0
- package/dist/geometry/geometry-table.d.ts.map +1 -0
- package/dist/geometry/geometry-table.js +2 -0
- package/dist/{transform/transform-types.js.map → geometry/geometry-table.js.map} +1 -1
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +32 -14
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +57 -34
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/primitive-utils.d.ts +1 -0
- package/dist/geometry/primitive-utils.d.ts.map +1 -0
- package/dist/geometry/primitive-utils.js +2 -0
- package/dist/geometry/primitive-utils.js.map +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +23 -84
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +106 -193
- package/dist/lib/animation-loop.js.map +1 -1
- package/dist/lib/animation-props.d.ts +24 -0
- package/dist/lib/animation-props.d.ts.map +1 -0
- package/dist/lib/animation-props.js +2 -0
- package/dist/lib/animation-props.js.map +1 -0
- package/dist/lib/clip-space.d.ts +1 -0
- package/dist/lib/clip-space.d.ts.map +1 -0
- package/dist/lib/clip-space.js +2 -0
- package/dist/lib/clip-space.js.map +1 -0
- package/dist/lib/model-utils.d.ts +4 -3
- package/dist/lib/model-utils.d.ts.map +1 -1
- package/dist/lib/model-utils.js +24 -70
- package/dist/lib/model-utils.js.map +1 -1
- package/dist/lib/model.d.ts +34 -104
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +111 -502
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +60 -0
- package/dist/lib/pipeline-factory.d.ts.map +1 -0
- package/dist/lib/pipeline-factory.js +219 -0
- package/dist/lib/pipeline-factory.js.map +1 -0
- package/dist/lib/render-loop.d.ts +5 -18
- package/dist/lib/render-loop.d.ts.map +1 -1
- package/dist/lib/render-loop.js +16 -23
- package/dist/lib/render-loop.js.map +1 -1
- package/package.json +6 -6
- package/src/animation/key-frames.ts +1 -0
- package/src/animation/timeline.ts +2 -2
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +160 -8
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +2 -2
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/sphere-geometry.ts +2 -2
- package/src/geometries/truncated-cone-geometry.ts +30 -12
- package/src/geometry/geometry-table.ts +16 -0
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +97 -47
- package/src/geometry/primitive-utils.ts +30 -0
- package/src/index.ts +13 -12
- package/src/lib/animation-loop.ts +136 -314
- package/src/lib/animation-props.ts +31 -0
- package/src/{utils → lib}/clip-space.ts +5 -2
- package/src/lib/model-utils.ts +60 -32
- package/src/lib/model.ts +127 -639
- package/src/lib/pipeline-factory.ts +234 -0
- package/src/lib/render-loop.ts +24 -22
- package/dist/lib/program-manager.d.ts +0 -39
- package/dist/lib/program-manager.d.ts.map +0 -1
- package/dist/lib/program-manager.js +0 -175
- package/dist/lib/program-manager.js.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -36
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/buffer-transform.js +0 -255
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.d.ts +0 -57
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.js +0 -412
- package/dist/transform/texture-transform.js.map +0 -1
- package/dist/transform/transform-shader-utils.d.ts +0 -26
- package/dist/transform/transform-shader-utils.d.ts.map +0 -1
- package/dist/transform/transform-shader-utils.js +0 -149
- package/dist/transform/transform-shader-utils.js.map +0 -1
- package/dist/transform/transform-types.d.ts +0 -44
- package/dist/transform/transform-types.d.ts.map +0 -1
- package/dist/transform/transform-types.js +0 -2
- package/dist/transform/transform.d.ts +0 -47
- package/dist/transform/transform.d.ts.map +0 -1
- package/dist/transform/transform.js +0 -198
- package/dist/transform/transform.js.map +0 -1
- package/dist/utils/clip-space.d.ts +0 -5
- package/dist/utils/clip-space.d.ts.map +0 -1
- package/dist/utils/clip-space.js +0 -34
- package/dist/utils/clip-space.js.map +0 -1
- package/src/lib/program-manager.ts +0 -187
- package/src/transform/buffer-transform.ts +0 -214
- package/src/transform/texture-transform.ts +0 -344
- package/src/transform/transform-shader-utils.ts +0 -169
- package/src/transform/transform-types.ts +0 -42
- package/src/transform/transform.ts +0 -189
package/src/lib/model.ts
CHANGED
|
@@ -1,695 +1,183 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import {Device} from '@luma.gl/api';
|
|
3
|
-
import GL from '@luma.gl/constants';
|
|
4
|
-
import type {ProgramProps} from '@luma.gl/webgl';
|
|
5
|
-
import {
|
|
6
|
-
WebGLDevice,
|
|
7
|
-
Program,
|
|
8
|
-
VertexArray,
|
|
9
|
-
clear,
|
|
10
|
-
TransformFeedback,
|
|
11
|
-
Buffer,
|
|
12
|
-
log,
|
|
13
|
-
isObjectEmpty,
|
|
14
|
-
uid,
|
|
15
|
-
assert
|
|
16
|
-
} from '@luma.gl/webgl';
|
|
17
|
-
import {
|
|
18
|
-
getDebugTableForUniforms,
|
|
19
|
-
getDebugTableForVertexArray,
|
|
20
|
-
getDebugTableForProgramConfiguration
|
|
21
|
-
} from '@luma.gl/webgl';
|
|
22
|
-
import ProgramManager from './program-manager';
|
|
23
|
-
import {getBuffersFromGeometry} from './model-utils';
|
|
24
2
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
varyings?: string[];
|
|
40
|
-
bufferMode?;
|
|
41
|
-
|
|
42
|
-
program?: Program;
|
|
43
|
-
modules?: any[];
|
|
44
|
-
defines?: Record<string, number | boolean>;
|
|
45
|
-
inject?: Record<string, any>;
|
|
46
|
-
transpileToGLSL100?: boolean;
|
|
47
|
-
|
|
48
|
-
moduleSettings?: object; // UniformsOptions
|
|
49
|
-
attributes?: object;
|
|
50
|
-
uniforms?: object; // Uniforms
|
|
51
|
-
geometry?: object; // Geometry
|
|
52
|
-
vertexCount?: number
|
|
53
|
-
drawMode?: number
|
|
54
|
-
isInstanced?: boolean
|
|
55
|
-
instanceCount?: number
|
|
56
|
-
programManager?: ProgramManager
|
|
57
|
-
onBeforeRender?: () => void
|
|
58
|
-
onAfterRender?: () => void
|
|
59
|
-
_feedbackBuffers?: object; // FeedbackBuffers
|
|
60
|
-
|
|
61
|
-
// Deprecated?
|
|
62
|
-
isIndexed?: boolean;
|
|
63
|
-
indexType?;
|
|
64
|
-
indexOffset?: number;
|
|
65
|
-
vertexArrayInstanced?: boolean;
|
|
66
|
-
|
|
67
|
-
/** @deprecated Use isInstanced */
|
|
68
|
-
instanced?: boolean
|
|
3
|
+
import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';
|
|
4
|
+
import {RenderPipeline, Shader, cast} from '@luma.gl/api';
|
|
5
|
+
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
6
|
+
import type Geometry from '../geometry/geometry';
|
|
7
|
+
import {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';
|
|
8
|
+
import {PipelineFactory} from './pipeline-factory';
|
|
9
|
+
|
|
10
|
+
export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
|
|
11
|
+
// Model also accepts a string
|
|
12
|
+
vs?: {glsl?: string; wgsl?: string} | string | null;
|
|
13
|
+
fs?: {glsl?: string; wgsl?: string} | string | null;
|
|
14
|
+
modules?: ShaderModule[];
|
|
15
|
+
moduleSettings?: Record<string, Record<string, any>>;
|
|
16
|
+
geometry?: Geometry | null;
|
|
69
17
|
};
|
|
70
18
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
19
|
+
const DEFAULT_MODEL_PROPS: Required<ModelProps> = {
|
|
20
|
+
...RenderPipeline._DEFAULT_PROPS,
|
|
21
|
+
vs: null,
|
|
22
|
+
fs: null,
|
|
23
|
+
id: 'unnamed',
|
|
24
|
+
handle: undefined,
|
|
25
|
+
userData: {},
|
|
26
|
+
modules: [],
|
|
27
|
+
moduleSettings: {},
|
|
28
|
+
geometry: null
|
|
80
29
|
};
|
|
81
30
|
|
|
82
|
-
|
|
83
|
-
interface ModelProps extends ProgramProps {
|
|
84
|
-
id?: string
|
|
85
|
-
moduleSettings?: UniformsOptions
|
|
86
|
-
uniforms?: Uniforms
|
|
87
|
-
geometry?: Geometry
|
|
88
|
-
vertexCount?: number
|
|
89
|
-
drawMode?: number
|
|
90
|
-
programManager?: ProgramManager
|
|
91
|
-
onBeforeRender?: () => void
|
|
92
|
-
onAfterRender?: () => void
|
|
93
|
-
_feedbackBuffers?: FeedbackBuffers
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface DrawOpts {
|
|
97
|
-
moduleSettings?: UniformsOptions
|
|
98
|
-
framebuffer: Framebuffer
|
|
99
|
-
uniforms?: Uniforms
|
|
100
|
-
attributes?: Attributes
|
|
101
|
-
parameters?: Parameters
|
|
102
|
-
transformFeedback?: TransformFeedback
|
|
103
|
-
vertexArray?: VertexArray
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface ClearOpts {
|
|
107
|
-
framebuffer?: Framebuffer
|
|
108
|
-
color?: boolean
|
|
109
|
-
depth?: boolean
|
|
110
|
-
stencil?: boolean
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface TransformOpts extends DrawOpts {
|
|
114
|
-
discard: boolean
|
|
115
|
-
feedbackBuffers: FeedbackBuffers
|
|
116
|
-
unbindModels: Array<Model>
|
|
117
|
-
parameters: Parameters
|
|
118
|
-
}
|
|
119
|
-
*/
|
|
120
|
-
|
|
31
|
+
/** v9 API */
|
|
121
32
|
export default class Model {
|
|
122
33
|
readonly device: Device;
|
|
123
|
-
readonly
|
|
124
|
-
|
|
34
|
+
readonly pipeline: RenderPipeline;
|
|
125
35
|
readonly id: string;
|
|
126
|
-
readonly
|
|
127
|
-
|
|
128
|
-
|
|
36
|
+
readonly vs: string;
|
|
37
|
+
readonly fs: string | null = null;
|
|
38
|
+
readonly topology: PrimitiveTopology;
|
|
39
|
+
readonly vertexCount;
|
|
40
|
+
props: Required<ModelProps>;
|
|
129
41
|
|
|
130
|
-
|
|
42
|
+
private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;
|
|
131
43
|
|
|
132
|
-
props: ModelProps
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
uniforms: Record<string, any> = {};
|
|
138
|
-
|
|
139
|
-
drawMode;
|
|
140
|
-
instanceCount: number;
|
|
141
|
-
pickable: boolean = true;
|
|
142
|
-
|
|
143
|
-
programProps: ProgramProps & {program?: Program; modules; inject; defines; varyings; bufferMode; transpileToGLSL100;};
|
|
144
|
-
vertexArray: VertexArray;
|
|
145
|
-
program: Program;
|
|
146
|
-
transformFeedback: TransformFeedback | undefined;
|
|
147
|
-
_programDirty = true;
|
|
148
|
-
_programManagerState;
|
|
149
|
-
_managedProgram;
|
|
150
|
-
|
|
151
|
-
// Track buffers created by setGeometry
|
|
152
|
-
geometryBuffers = {};
|
|
153
|
-
// geometry might have set drawMode and vertexCount
|
|
154
|
-
isInstanced: boolean;
|
|
155
|
-
// TODO - just to unbreak deck.gl 7.0-beta, remove as soon as updated
|
|
156
|
-
geometry = {};
|
|
157
|
-
|
|
158
|
-
constructor(device: Device, props?: ModelProps);
|
|
159
|
-
/* @deprecated */
|
|
160
|
-
constructor(gl: WebGLRenderingContext, props?: ModelProps);
|
|
161
|
-
constructor(device, props: ModelProps = {}) {
|
|
162
|
-
// Deduce a helpful id
|
|
163
|
-
const {id = uid('model')} = props;
|
|
164
|
-
this.id = id;
|
|
165
|
-
const webglDevice = WebGLDevice.attach(device);
|
|
166
|
-
this.device = webglDevice;
|
|
167
|
-
this.gl = webglDevice.gl;
|
|
168
|
-
this.id = props.id || uid('Model');
|
|
169
|
-
this.initialize(props);
|
|
170
|
-
}
|
|
44
|
+
constructor(device: Device, props: ModelProps) {
|
|
45
|
+
this.props = {...DEFAULT_MODEL_PROPS, ...props};
|
|
46
|
+
props = this.props;
|
|
47
|
+
this.id = this.props.id;
|
|
48
|
+
this.device = device;
|
|
171
49
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.programManager = props.programManager || ProgramManager.getDefaultProgramManager(this.device);
|
|
176
|
-
this._programManagerState = -1;
|
|
177
|
-
this._managedProgram = false;
|
|
178
|
-
|
|
179
|
-
const {
|
|
180
|
-
program = null,
|
|
181
|
-
vs,
|
|
182
|
-
fs,
|
|
183
|
-
modules,
|
|
184
|
-
defines,
|
|
185
|
-
inject,
|
|
186
|
-
varyings,
|
|
187
|
-
bufferMode,
|
|
188
|
-
transpileToGLSL100
|
|
189
|
-
} = props;
|
|
190
|
-
|
|
191
|
-
this.programProps = {
|
|
192
|
-
program,
|
|
193
|
-
modules,
|
|
194
|
-
vs,
|
|
195
|
-
fs,
|
|
196
|
-
defines,
|
|
197
|
-
inject,
|
|
198
|
-
varyings,
|
|
199
|
-
bufferMode,
|
|
200
|
-
transpileToGLSL100
|
|
201
|
-
};
|
|
202
|
-
this.program = null;
|
|
203
|
-
this.vertexArray = null;
|
|
204
|
-
this._programDirty = true;
|
|
205
|
-
|
|
206
|
-
// Initialize state
|
|
207
|
-
this.userData = {};
|
|
208
|
-
this.needsRedraw = true;
|
|
209
|
-
|
|
210
|
-
// Attributes and buffers
|
|
211
|
-
// Model manages auto Buffer creation from typed arrays
|
|
212
|
-
this._attributes = {}; // All attributes
|
|
213
|
-
this.attributes = {}; // User defined attributes
|
|
214
|
-
|
|
215
|
-
// Model manages uniform animation
|
|
216
|
-
this.uniforms = {};
|
|
217
|
-
|
|
218
|
-
// picking options
|
|
219
|
-
this.pickable = true;
|
|
220
|
-
|
|
221
|
-
this._checkProgram();
|
|
222
|
-
|
|
223
|
-
this.setUniforms(
|
|
224
|
-
Object.assign(
|
|
225
|
-
{},
|
|
226
|
-
this.getModuleUniforms(props.moduleSettings) // Get unforms for supplied parameters
|
|
227
|
-
)
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
this.drawMode = props.drawMode !== undefined ? props.drawMode : GL.TRIANGLES;
|
|
231
|
-
this.vertexCount = props.vertexCount || 0;
|
|
232
|
-
|
|
233
|
-
// Track buffers created by setGeometry
|
|
234
|
-
this.geometryBuffers = {};
|
|
235
|
-
|
|
236
|
-
// geometry might have set drawMode and vertexCount
|
|
237
|
-
this.isInstanced = props.isInstanced || props.instanced || props.instanceCount > 0;
|
|
238
|
-
|
|
239
|
-
this._setModelProps(props);
|
|
240
|
-
|
|
241
|
-
// TODO - just to unbreak deck.gl 7.0-beta, remove as soon as updated
|
|
242
|
-
this.geometry = {};
|
|
243
|
-
|
|
244
|
-
// assert(program || program instanceof Program);
|
|
245
|
-
assert(this.drawMode !== undefined && Number.isFinite(this.vertexCount), ERR_MODEL_PARAMS);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
setProps(props) {
|
|
249
|
-
this._setModelProps(props);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
destroy(): void {
|
|
253
|
-
// delete all attributes created by this model
|
|
254
|
-
// TODO - should buffer deletes be handled by vertex array?
|
|
255
|
-
for (const key in this._attributes) {
|
|
256
|
-
if (this._attributes[key] !== this.attributes[key]) {
|
|
257
|
-
this._attributes[key].delete();
|
|
258
|
-
}
|
|
50
|
+
// Create the pipeline
|
|
51
|
+
if (!props.vs) {
|
|
52
|
+
throw new Error('no vertex shader');
|
|
259
53
|
}
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
this.
|
|
263
|
-
this._managedProgram = false;
|
|
54
|
+
this.vs = getShaderSource(this.device, props.vs);
|
|
55
|
+
if (props.fs) {
|
|
56
|
+
this.fs = getShaderSource(this.device, props.fs);
|
|
264
57
|
}
|
|
265
58
|
|
|
266
|
-
this.
|
|
59
|
+
this.vertexCount = this.props.vertexCount;
|
|
60
|
+
this.topology = this.props.topology;
|
|
267
61
|
|
|
268
|
-
this.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
delete(): void {
|
|
273
|
-
this.destroy();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// GETTERS
|
|
277
|
-
|
|
278
|
-
getDrawMode() {
|
|
279
|
-
return this.drawMode;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
getVertexCount(): number {
|
|
283
|
-
return this.vertexCount;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
getInstanceCount(): number {
|
|
287
|
-
return this.instanceCount;
|
|
288
|
-
}
|
|
62
|
+
if (this.props.geometry) {
|
|
63
|
+
this.vertexCount = this.props.geometry.vertexCount;
|
|
64
|
+
this.topology = this.props.geometry.topology || 'triangle-list';
|
|
65
|
+
}
|
|
289
66
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
67
|
+
const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
68
|
+
const {pipeline, getUniforms} = pipelineFactory.createRenderPipeline({
|
|
69
|
+
...this.props,
|
|
70
|
+
vs: this.vs,
|
|
71
|
+
fs: this.fs,
|
|
72
|
+
topology: this.topology,
|
|
73
|
+
parameters: props.parameters,
|
|
74
|
+
layout: props.layout
|
|
75
|
+
});
|
|
293
76
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
77
|
+
this.pipeline = pipeline;
|
|
78
|
+
this._getModuleUniforms = getUniforms;
|
|
297
79
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.
|
|
302
|
-
|
|
303
|
-
vs,
|
|
304
|
-
fs,
|
|
305
|
-
modules,
|
|
306
|
-
defines,
|
|
307
|
-
inject,
|
|
308
|
-
varyings,
|
|
309
|
-
bufferMode,
|
|
310
|
-
transpileToGLSL100
|
|
311
|
-
};
|
|
312
|
-
this._programDirty = true;
|
|
80
|
+
if (this.props.geometry) {
|
|
81
|
+
this._setGeometry(this.props.geometry);
|
|
82
|
+
}
|
|
83
|
+
this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms
|
|
84
|
+
this.setProps(this.props);
|
|
313
85
|
}
|
|
314
86
|
|
|
315
|
-
|
|
316
|
-
|
|
87
|
+
destroy(): void {
|
|
88
|
+
this.pipeline.destroy();
|
|
317
89
|
}
|
|
318
90
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
91
|
+
draw(renderPass?: RenderPass): this {
|
|
92
|
+
this.pipeline.draw({
|
|
93
|
+
renderPass,
|
|
94
|
+
vertexCount: this.vertexCount,
|
|
95
|
+
instanceCount: this.props.instanceCount
|
|
96
|
+
});
|
|
323
97
|
return this;
|
|
324
98
|
}
|
|
325
99
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
100
|
+
setProps(props: ModelProps): this {
|
|
101
|
+
if (props.indices) {
|
|
102
|
+
this.setIndexBuffer(props.indices);
|
|
103
|
+
}
|
|
104
|
+
if (props.attributes) {
|
|
105
|
+
this.setAttributes(props.attributes);
|
|
106
|
+
}
|
|
107
|
+
if (props.bindings) {
|
|
108
|
+
this.setBindings(props.bindings);
|
|
109
|
+
}
|
|
110
|
+
if (props.uniforms) {
|
|
111
|
+
this.setUniforms(props.uniforms);
|
|
112
|
+
}
|
|
113
|
+
if (props.moduleSettings) {
|
|
114
|
+
this.updateModuleSettings(props.moduleSettings);
|
|
115
|
+
}
|
|
329
116
|
return this;
|
|
330
117
|
}
|
|
331
118
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.
|
|
119
|
+
updateModuleSettings(props: Record<string, any>): this {
|
|
120
|
+
const uniforms = this._getModuleUniforms(props);
|
|
121
|
+
this.setUniforms(uniforms);
|
|
335
122
|
return this;
|
|
336
123
|
}
|
|
337
124
|
|
|
338
|
-
|
|
339
|
-
this.
|
|
340
|
-
this.
|
|
341
|
-
|
|
342
|
-
this._deleteGeometryBuffers();
|
|
343
|
-
|
|
344
|
-
this.geometryBuffers = getBuffersFromGeometry(this.gl, geometry);
|
|
345
|
-
this.vertexArray.setAttributes(this.geometryBuffers);
|
|
125
|
+
setIndexBuffer(indices: Buffer): this {
|
|
126
|
+
this.pipeline.setIndexBuffer(indices);
|
|
127
|
+
// this._indices = indices;
|
|
346
128
|
return this;
|
|
347
129
|
}
|
|
348
130
|
|
|
349
|
-
setAttributes(attributes
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const normalizedAttributes = {};
|
|
356
|
-
for (const name in attributes) {
|
|
357
|
-
const attribute = attributes[name];
|
|
358
|
-
// The `getValue` call provides support for deck.gl `Attribute` class
|
|
359
|
-
// TODO - remove once deck refactoring completes
|
|
360
|
-
normalizedAttributes[name] = attribute.getValue ? attribute.getValue() : attribute;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
this.vertexArray.setAttributes(normalizedAttributes);
|
|
131
|
+
setAttributes(attributes: Record<string, Buffer>): this {
|
|
132
|
+
this.pipeline.setAttributes(attributes);
|
|
133
|
+
Object.assign(this.props.attributes, attributes);
|
|
364
134
|
return this;
|
|
365
135
|
}
|
|
366
136
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
137
|
+
/** Set the bindings */
|
|
138
|
+
setBindings(bindings: Record<string, Binding>): this {
|
|
139
|
+
this.pipeline.setBindings(bindings);
|
|
140
|
+
Object.assign(this.props.bindings, bindings);
|
|
370
141
|
return this;
|
|
371
142
|
}
|
|
372
143
|
|
|
373
|
-
|
|
374
|
-
this.
|
|
375
|
-
|
|
376
|
-
const getUniforms = this.programManager.getUniforms(this.program);
|
|
377
|
-
|
|
378
|
-
if (getUniforms) {
|
|
379
|
-
return getUniforms(opts);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return {};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
updateModuleSettings(opts?): this {
|
|
386
|
-
const uniforms = this.getModuleUniforms(opts || {});
|
|
387
|
-
return this.setUniforms(uniforms);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// DRAW CALLS
|
|
391
|
-
|
|
392
|
-
clear(opts): this {
|
|
393
|
-
clear(this.program.gl, opts);
|
|
144
|
+
setUniforms(uniforms: Record<string, any>): this {
|
|
145
|
+
this.pipeline.setUniforms(uniforms);
|
|
146
|
+
Object.assign(this.props.uniforms, uniforms);
|
|
394
147
|
return this;
|
|
395
148
|
}
|
|
396
149
|
|
|
397
|
-
|
|
398
|
-
//
|
|
399
|
-
this._checkProgram();
|
|
400
|
-
|
|
401
|
-
const {
|
|
402
|
-
moduleSettings = null,
|
|
403
|
-
framebuffer,
|
|
404
|
-
uniforms = {},
|
|
405
|
-
attributes = {},
|
|
406
|
-
transformFeedback = this.transformFeedback,
|
|
407
|
-
parameters = {},
|
|
408
|
-
vertexArray = this.vertexArray
|
|
409
|
-
} = opts;
|
|
150
|
+
_setGeometry(geometry: Geometry): void {
|
|
151
|
+
// this._deleteGeometryBuffers();
|
|
410
152
|
|
|
411
|
-
|
|
412
|
-
this.setAttributes(
|
|
413
|
-
this.updateModuleSettings(moduleSettings);
|
|
414
|
-
this.setUniforms(uniforms);
|
|
153
|
+
const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);
|
|
154
|
+
this.setAttributes(geometryBuffers);
|
|
415
155
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
logPriority = this._logDrawCallStart(LOG_DRAW_PRIORITY);
|
|
156
|
+
const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);
|
|
157
|
+
if (indexBuffer) {
|
|
158
|
+
this.setIndexBuffer(indexBuffer);
|
|
420
159
|
}
|
|
421
|
-
|
|
422
|
-
const drawParams = this.vertexArray.getDrawParams();
|
|
423
|
-
const {
|
|
424
|
-
isIndexed = drawParams.isIndexed,
|
|
425
|
-
indexType = drawParams.indexType,
|
|
426
|
-
indexOffset = drawParams.indexOffset,
|
|
427
|
-
vertexArrayInstanced = drawParams.isInstanced
|
|
428
|
-
} = this.props;
|
|
429
|
-
|
|
430
|
-
if (vertexArrayInstanced && !this.isInstanced) {
|
|
431
|
-
log.warn('Found instanced attributes on non-instanced model', this.id)();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const {isInstanced, instanceCount} = this;
|
|
435
|
-
|
|
436
|
-
const {onBeforeRender = NOOP, onAfterRender = NOOP} = this.props;
|
|
437
|
-
|
|
438
|
-
onBeforeRender();
|
|
439
|
-
|
|
440
|
-
this.program.setUniforms(this.uniforms);
|
|
441
|
-
|
|
442
|
-
const didDraw = this.program.draw(
|
|
443
|
-
Object.assign(DRAW_PARAMS, opts, {
|
|
444
|
-
logPriority,
|
|
445
|
-
uniforms: null, // Already set (may contain "function values" not understood by Program)
|
|
446
|
-
framebuffer,
|
|
447
|
-
parameters,
|
|
448
|
-
drawMode: this.getDrawMode(),
|
|
449
|
-
vertexCount: this.getVertexCount(),
|
|
450
|
-
vertexArray,
|
|
451
|
-
transformFeedback,
|
|
452
|
-
isIndexed,
|
|
453
|
-
indexType,
|
|
454
|
-
isInstanced,
|
|
455
|
-
instanceCount,
|
|
456
|
-
offset: isIndexed ? indexOffset : 0
|
|
457
|
-
})
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
onAfterRender();
|
|
461
|
-
|
|
462
|
-
if (log.priority >= LOG_DRAW_PRIORITY) {
|
|
463
|
-
this._logDrawCallEnd(logPriority, vertexArray, framebuffer);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return didDraw;
|
|
467
160
|
}
|
|
161
|
+
}
|
|
468
162
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
let {parameters} = opts;
|
|
475
|
-
|
|
476
|
-
if (feedbackBuffers) {
|
|
477
|
-
this._setFeedbackBuffers(feedbackBuffers);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (discard) {
|
|
481
|
-
parameters = Object.assign({}, parameters, {[GL.RASTERIZER_DISCARD]: discard});
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
unbindModels.forEach((model) => model.vertexArray.unbindBuffers());
|
|
485
|
-
try {
|
|
486
|
-
this.draw(Object.assign({}, opts, {parameters}));
|
|
487
|
-
} finally {
|
|
488
|
-
unbindModels.forEach((model) => model.vertexArray.bindBuffers());
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
return this;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// DEPRECATED METHODS
|
|
495
|
-
|
|
496
|
-
render(uniforms = {}): boolean {
|
|
497
|
-
log.warn('Model.render() is deprecated. Use Model.setUniforms() and Model.draw()')();
|
|
498
|
-
return this.setUniforms(uniforms).draw();
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// PRIVATE METHODS
|
|
502
|
-
|
|
503
|
-
_setModelProps(props): void {
|
|
504
|
-
Object.assign(this.props, props);
|
|
505
|
-
|
|
506
|
-
if ('uniforms' in props) {
|
|
507
|
-
this.setUniforms(props.uniforms);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
if ('pickable' in props) {
|
|
511
|
-
this.pickable = props.pickable;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if ('instanceCount' in props) {
|
|
515
|
-
this.instanceCount = props.instanceCount;
|
|
516
|
-
}
|
|
517
|
-
if ('geometry' in props) {
|
|
518
|
-
this.setGeometry(props.geometry);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// webgl settings
|
|
522
|
-
if ('attributes' in props) {
|
|
523
|
-
this.setAttributes(props.attributes);
|
|
524
|
-
}
|
|
525
|
-
if ('_feedbackBuffers' in props) {
|
|
526
|
-
this._setFeedbackBuffers(props._feedbackBuffers);
|
|
527
|
-
}
|
|
163
|
+
/** Create a shader from the different overloads */
|
|
164
|
+
function getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {
|
|
165
|
+
// TODO - detect WGSL/GLSL and throw an error if not supported
|
|
166
|
+
if (typeof shader === 'string') {
|
|
167
|
+
return shader;
|
|
528
168
|
}
|
|
529
169
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
if (!needsUpdate) {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
let {program} = this.programProps;
|
|
539
|
-
|
|
540
|
-
if (program) {
|
|
541
|
-
this._managedProgram = false;
|
|
542
|
-
} else {
|
|
543
|
-
const {vs, fs, modules, inject, defines, varyings, bufferMode, transpileToGLSL100} =
|
|
544
|
-
this.programProps;
|
|
545
|
-
program = this.programManager.get({
|
|
546
|
-
// @ts-expect-error
|
|
547
|
-
vs,
|
|
548
|
-
// @ts-expect-error
|
|
549
|
-
fs,
|
|
550
|
-
modules,
|
|
551
|
-
inject,
|
|
552
|
-
defines,
|
|
553
|
-
varyings,
|
|
554
|
-
bufferMode,
|
|
555
|
-
transpileToGLSL100
|
|
556
|
-
});
|
|
557
|
-
if (this.program && this._managedProgram) {
|
|
558
|
-
this.programManager.release(this.program);
|
|
170
|
+
switch (device.info.type) {
|
|
171
|
+
case 'webgpu':
|
|
172
|
+
if (shader?.wgsl) {
|
|
173
|
+
return shader.wgsl;
|
|
559
174
|
}
|
|
560
|
-
|
|
561
|
-
this._managedProgram = true;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
assert(program instanceof Program, 'Model needs a program');
|
|
175
|
+
throw new Error('WebGPU does not support GLSL shaders');
|
|
565
176
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
this.program = program;
|
|
573
|
-
|
|
574
|
-
if (this.vertexArray) {
|
|
575
|
-
this.vertexArray.setProps({program: this.program, attributes: this.vertexArray.attributes});
|
|
576
|
-
} else {
|
|
577
|
-
this.vertexArray = new VertexArray(this.gl, {program: this.program});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// Make sure we have some reasonable default uniforms in place
|
|
581
|
-
this.setUniforms(
|
|
582
|
-
Object.assign(
|
|
583
|
-
{},
|
|
584
|
-
this.getModuleUniforms() // Get all default uniforms,
|
|
585
|
-
)
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
_deleteGeometryBuffers(): void {
|
|
590
|
-
for (const name in this.geometryBuffers) {
|
|
591
|
-
// Buffer is raw value (for indices) or first element of [buffer, accessor] pair
|
|
592
|
-
const buffer = this.geometryBuffers[name][0] || this.geometryBuffers[name];
|
|
593
|
-
if (buffer instanceof Buffer) {
|
|
594
|
-
buffer.destroy();
|
|
177
|
+
default:
|
|
178
|
+
if (shader?.glsl) {
|
|
179
|
+
return shader.glsl;
|
|
595
180
|
}
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Updates (evaluates) all function valued uniforms based on a new set of animationProps
|
|
600
|
-
// experimental
|
|
601
|
-
_setAnimationProps(animationProps): void {
|
|
602
|
-
if (this.animated) {
|
|
603
|
-
assert(animationProps, 'Model.draw(): animated uniforms but no animationProps');
|
|
604
|
-
// const animatedUniforms = this._evaluateAnimateUniforms(animationProps);
|
|
605
|
-
// Object.assign(this.uniforms, animatedUniforms);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// Transform Feedback
|
|
610
|
-
|
|
611
|
-
_setFeedbackBuffers(feedbackBuffers = {}): this {
|
|
612
|
-
// Avoid setting needsRedraw if no feedbackBuffers
|
|
613
|
-
if (isObjectEmpty(feedbackBuffers)) {
|
|
614
|
-
return this;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
const {gl} = this.program;
|
|
618
|
-
this.transformFeedback =
|
|
619
|
-
this.transformFeedback ||
|
|
620
|
-
new TransformFeedback(gl, {
|
|
621
|
-
program: this.program
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
this.transformFeedback.setBuffers(feedbackBuffers);
|
|
625
|
-
return this;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
_logDrawCallStart(logLevel: number): number {
|
|
629
|
-
const logDrawTimeout = logLevel > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
630
|
-
if (Date.now() - this.lastLogTime < logDrawTimeout) {
|
|
631
|
-
return undefined;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
this.lastLogTime = Date.now();
|
|
635
|
-
|
|
636
|
-
log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, {collapsed: log.level <= 2})();
|
|
637
|
-
|
|
638
|
-
return logLevel;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
_logDrawCallEnd(logLevel, vertexArray, uniforms, framebuffer?): void {
|
|
642
|
-
// HACK: logLevel === undefined means logDrawCallStart didn't run
|
|
643
|
-
if (logLevel === undefined) {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
const attributeTable = getDebugTableForVertexArray({
|
|
648
|
-
vertexArray,
|
|
649
|
-
header: `${this.id} attributes`,
|
|
650
|
-
// @ts-expect-error
|
|
651
|
-
attributes: this._attributes
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
const {
|
|
655
|
-
table: uniformTable,
|
|
656
|
-
unusedTable,
|
|
657
|
-
unusedCount
|
|
658
|
-
} = getDebugTableForUniforms({
|
|
659
|
-
header: `${this.id} uniforms`,
|
|
660
|
-
program: this.program,
|
|
661
|
-
uniforms: Object.assign({}, this.program.uniforms, uniforms)
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
// log missing uniforms
|
|
665
|
-
const {table: missingTable, count: missingCount} = getDebugTableForUniforms({
|
|
666
|
-
header: `${this.id} uniforms`,
|
|
667
|
-
program: this.program,
|
|
668
|
-
uniforms: Object.assign({}, this.program.uniforms, uniforms),
|
|
669
|
-
undefinedOnly: true
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
if (missingCount > 0) {
|
|
673
|
-
log.log('MISSING UNIFORMS', Object.keys(missingTable))();
|
|
674
|
-
// log.table(logLevel, missingTable)();
|
|
675
|
-
}
|
|
676
|
-
if (unusedCount > 0) {
|
|
677
|
-
log.log('UNUSED UNIFORMS', Object.keys(unusedTable))();
|
|
678
|
-
// log.log(logLevel, 'Unused uniforms ', unusedTable)();
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
const configTable = getDebugTableForProgramConfiguration(this.vertexArray.configuration);
|
|
682
|
-
|
|
683
|
-
log.table(logLevel, attributeTable)();
|
|
684
|
-
|
|
685
|
-
log.table(logLevel, uniformTable)();
|
|
686
|
-
|
|
687
|
-
log.table(logLevel + 1, configTable)();
|
|
688
|
-
|
|
689
|
-
if (framebuffer) {
|
|
690
|
-
framebuffer.log({logLevel: LOG_DRAW_PRIORITY, message: `Rendered to ${framebuffer.id}`});
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
log.groupEnd(LOG_DRAW_PRIORITY)();
|
|
181
|
+
throw new Error('WebGL does not support WGSL shaders');
|
|
694
182
|
}
|
|
695
183
|
}
|