@luma.gl/engine 9.0.0-alpha.48 → 9.0.0-alpha.50
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.js +1 -1
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/dist.dev.js +161 -54
- package/dist/index.cjs +125 -65
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js.map +1 -1
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +8 -7
- package/dist/shader-inputs.js.map +1 -1
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/{transform.js → buffer-transform.js} +13 -41
- package/dist/transform/buffer-transform.js.map +1 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +122 -0
- package/dist/transform/texture-transform.js.map +1 -0
- package/dist.min.js +67 -67
- package/package.json +5 -5
- package/src/animation-loop/animation-loop.ts +1 -1
- package/src/index.ts +5 -1
- package/src/model/model.ts +2 -0
- package/src/shader-inputs.ts +6 -5
- package/src/transform/buffer-transform.ts +94 -0
- package/src/transform/texture-transform.ts +169 -0
- package/dist/transform/transform.d.ts +0 -65
- package/dist/transform/transform.d.ts.map +0 -1
- package/dist/transform/transform.js.map +0 -1
- package/src/transform/transform.ts +0 -261
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
import {Device, Buffer, BufferRange, Framebuffer, TransformFeedback, assert, PrimitiveTopology, RenderPassParameters, BufferLayout} from '@luma.gl/core';
|
|
5
|
-
import {getShaderInfo, getPassthroughFS, ShaderModule} from '@luma.gl/shadertools';
|
|
6
|
-
import {Model} from '../model/model';
|
|
7
|
-
|
|
8
|
-
// import BufferTransform from './buffer-transform';
|
|
9
|
-
// import TextureTransform from './texture-transform';
|
|
10
|
-
|
|
11
|
-
/** Properties for creating Transforms */
|
|
12
|
-
export type TransformProps = {
|
|
13
|
-
id?: string;
|
|
14
|
-
vs?: string;
|
|
15
|
-
fs?: string;
|
|
16
|
-
vertexCount?: number;
|
|
17
|
-
sourceBuffers?: Record<string, Buffer>;
|
|
18
|
-
feedbackBuffers?: Record<string, Buffer | BufferRange>;
|
|
19
|
-
varyings?: string[];
|
|
20
|
-
feedbackMap?: Record<string, string>;
|
|
21
|
-
modules?: ShaderModule[];
|
|
22
|
-
attributes?: Record<string, any>;
|
|
23
|
-
bufferLayout?: BufferLayout[];
|
|
24
|
-
uniforms?: Record<string, any>;
|
|
25
|
-
defines?: Record<string, any>
|
|
26
|
-
// parameters?: GLParameters;
|
|
27
|
-
discard?: boolean;
|
|
28
|
-
// isIndexed?: boolean;
|
|
29
|
-
// inject?: Record<string, string>;
|
|
30
|
-
topology?: PrimitiveTopology;
|
|
31
|
-
// framebuffer?: Framebuffer;
|
|
32
|
-
// _sourceTextures?: Record<string, Texture>;
|
|
33
|
-
// _targetTexture?: string | Texture;
|
|
34
|
-
// _targetTextureVarying?: string;
|
|
35
|
-
// _swapTexture?: string | null;
|
|
36
|
-
// _fs?: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/** Options that can be provided when running a Transform */
|
|
40
|
-
export type TransformRunOptions = {
|
|
41
|
-
framebuffer?: Framebuffer;
|
|
42
|
-
// clearRenderTarget?: boolean;
|
|
43
|
-
/** @deprecated Use uniform buffers for portability. */
|
|
44
|
-
uniforms?: Record<string, any>;
|
|
45
|
-
parameters?: RenderPassParameters;
|
|
46
|
-
discard?: boolean;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/** Options that control drawing a Transform. Used by subclasses to return draw parameters */
|
|
50
|
-
// export type TransformDrawOptions = {
|
|
51
|
-
// attributes?: Record<string, any>;
|
|
52
|
-
// framebuffer?: any;
|
|
53
|
-
// uniforms?: object;
|
|
54
|
-
// discard?: boolean;
|
|
55
|
-
// parameters?: object;
|
|
56
|
-
// transformFeedback?: TransformFeedback;
|
|
57
|
-
// };
|
|
58
|
-
|
|
59
|
-
// export type TransformBinding = {
|
|
60
|
-
// sourceBuffers: Record<string, Buffer>;
|
|
61
|
-
// sourceTextures: Record<string, Texture>;
|
|
62
|
-
// feedbackBuffers?: Record<string, Buffer | BufferRange>;
|
|
63
|
-
// transformFeedback?: TransformFeedback;
|
|
64
|
-
// framebuffer?: Framebuffer;
|
|
65
|
-
// targetTexture?: Texture;
|
|
66
|
-
// };
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Takes source and target buffers/textures and sets up the pipeline
|
|
70
|
-
*/
|
|
71
|
-
export class Transform {
|
|
72
|
-
readonly device: Device;
|
|
73
|
-
readonly model: Model;
|
|
74
|
-
readonly transformFeedback: TransformFeedback;
|
|
75
|
-
|
|
76
|
-
/** @deprecated Use device feature test. */
|
|
77
|
-
static isSupported(device: Device): boolean {
|
|
78
|
-
return device.features.has('transform-feedback-webgl2');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// bufferTransform: BufferTransform | null = null;
|
|
82
|
-
// textureTransform: TextureTransform | null = null;
|
|
83
|
-
elementIDBuffer: Buffer | null = null;
|
|
84
|
-
|
|
85
|
-
constructor(device: Device, props: TransformProps = {}) {
|
|
86
|
-
assert(device.features.has('transform-feedback-webgl2'), 'Device must support transform feedback');
|
|
87
|
-
|
|
88
|
-
this.device = device;
|
|
89
|
-
|
|
90
|
-
// this._buildResourceTransforms(props);
|
|
91
|
-
|
|
92
|
-
// props = this._updateModelProps(props);
|
|
93
|
-
|
|
94
|
-
this.model = new Model(this.device, {
|
|
95
|
-
vs: props.vs,
|
|
96
|
-
fs: props.fs || getPassthroughFS({version: getShaderInfo(props.vs).version}),
|
|
97
|
-
id: props.id || 'transform-model',
|
|
98
|
-
varyings: props.varyings,
|
|
99
|
-
attributes: props.attributes,
|
|
100
|
-
bufferLayout: props.bufferLayout,
|
|
101
|
-
topology: props.topology || 'point-list',
|
|
102
|
-
vertexCount: props.vertexCount,
|
|
103
|
-
defines: props.defines,
|
|
104
|
-
modules: props.modules,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
this.transformFeedback = this.device.createTransformFeedback({
|
|
108
|
-
layout: this.model.pipeline.shaderLayout,
|
|
109
|
-
buffers: props.feedbackBuffers,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
this.model.setTransformFeedback(this.transformFeedback);
|
|
113
|
-
|
|
114
|
-
// if (this.bufferTransform) {
|
|
115
|
-
// this.bufferTransform.setupResources({model: this.model});
|
|
116
|
-
// }
|
|
117
|
-
|
|
118
|
-
Object.seal(this);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Destroy owned resources. */
|
|
122
|
-
destroy(): void {
|
|
123
|
-
if (this.model) {
|
|
124
|
-
this.model.destroy();
|
|
125
|
-
}
|
|
126
|
-
// if (this.bufferTransform) {
|
|
127
|
-
// this.bufferTransform.destroy();
|
|
128
|
-
// }
|
|
129
|
-
// if (this.textureTransform) {
|
|
130
|
-
// this.textureTransform.destroy();
|
|
131
|
-
// }
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Run one transform loop. */
|
|
135
|
-
run(options?: TransformRunOptions): void {
|
|
136
|
-
const {framebuffer, parameters, discard, uniforms} = options || {};
|
|
137
|
-
// const {clearRenderTarget = true} = options || {};
|
|
138
|
-
|
|
139
|
-
// const updatedOpts = this._updateDrawOptions(options);
|
|
140
|
-
|
|
141
|
-
// if (clearRenderTarget && updatedOpts.framebuffer) {
|
|
142
|
-
// clear(this.device, {framebuffer: updatedOpts.framebuffer, color: true});
|
|
143
|
-
// }
|
|
144
|
-
|
|
145
|
-
const renderPass = this.device.beginRenderPass({framebuffer, parameters, discard});
|
|
146
|
-
if (uniforms) this.model.setUniforms(uniforms);
|
|
147
|
-
this.model.draw(renderPass);
|
|
148
|
-
renderPass.end();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** swap resources if a map is provided */
|
|
152
|
-
swap(): void {
|
|
153
|
-
// let swapped = false;
|
|
154
|
-
// const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
155
|
-
// for (const resourceTransform of resourceTransforms) {
|
|
156
|
-
// swapped = swapped || Boolean(resourceTransform?.swap());
|
|
157
|
-
// }
|
|
158
|
-
// assert(swapped, 'Nothing to swap');
|
|
159
|
-
throw new Error('Not implemented');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
|
|
163
|
-
getBuffer(varyingName: string): Buffer | BufferRange | null {
|
|
164
|
-
return this.transformFeedback.getBuffer(varyingName);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
readAsync(varyingName: string): Promise<Uint8Array> {
|
|
168
|
-
const result = this.getBuffer(varyingName);
|
|
169
|
-
if (result instanceof Buffer) {
|
|
170
|
-
return result.readAsync();
|
|
171
|
-
}
|
|
172
|
-
const {buffer, byteOffset = 0, byteLength = buffer.byteLength} = result;
|
|
173
|
-
return buffer.readAsync(byteOffset, byteLength);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Return data either from Buffer or from Texture.
|
|
178
|
-
* @deprecated Prefer {@link readAsync}.
|
|
179
|
-
*/
|
|
180
|
-
getData(options: {packed?: boolean; varyingName?: string} = {}) {
|
|
181
|
-
// const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
182
|
-
// for (const resourceTransform of resourceTransforms) {
|
|
183
|
-
// const data = resourceTransform?.getData(options);
|
|
184
|
-
// if (data) {
|
|
185
|
-
// return data;
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
|
-
// return null;
|
|
189
|
-
throw new Error('Not implemented');
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** Return framebuffer object if rendering to textures */
|
|
193
|
-
getFramebuffer(): Framebuffer | null {
|
|
194
|
-
// return this.textureTransform?.getFramebuffer() || null;
|
|
195
|
-
throw new Error('Not implemented');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/** Update some or all buffer/texture bindings. */
|
|
199
|
-
update(props: TransformProps): void {
|
|
200
|
-
// if (props.elementCount !== undefined) {
|
|
201
|
-
// this.model.setVertexCount(props.elementCount);
|
|
202
|
-
// }
|
|
203
|
-
// const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
204
|
-
// for (const resourceTransform of resourceTransforms) {
|
|
205
|
-
// resourceTransform?.update(props);
|
|
206
|
-
// }
|
|
207
|
-
throw new Error('Not implemented');
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Private
|
|
211
|
-
|
|
212
|
-
_updateModelProps(props: TransformProps): TransformProps {
|
|
213
|
-
// const updatedProps: TransformProps = {...props};
|
|
214
|
-
// const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean) ;
|
|
215
|
-
// for (const resourceTransform of resourceTransforms) {
|
|
216
|
-
// updatedProps = resourceTransform.updateModelProps(updatedProps);
|
|
217
|
-
// }
|
|
218
|
-
// return updatedProps;
|
|
219
|
-
throw new Error('Not implemented');
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// _buildResourceTransforms(props: TransformProps) {
|
|
223
|
-
// if (canCreateBufferTransform(props)) {
|
|
224
|
-
// this.bufferTransform = new BufferTransform(this.device, props);
|
|
225
|
-
// }
|
|
226
|
-
// if (canCreateTextureTransform(props)) {
|
|
227
|
-
// this.textureTransform = new TextureTransform(this.device, props);
|
|
228
|
-
// }
|
|
229
|
-
// assert(
|
|
230
|
-
// this.bufferTransform || this.textureTransform,
|
|
231
|
-
// 'must provide source/feedback buffers or source/target textures'
|
|
232
|
-
// );
|
|
233
|
-
// }
|
|
234
|
-
|
|
235
|
-
// _updateDrawOptions(options: TransformRunOptions): TransformDrawOptions {
|
|
236
|
-
// const updatedOpts = {...options};
|
|
237
|
-
// const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean) ;
|
|
238
|
-
// for (const resourceTransform of resourceTransforms) {
|
|
239
|
-
// updatedOpts = Object.assign(updatedOpts, resourceTransform.getDrawOptions(updatedOpts));
|
|
240
|
-
// }
|
|
241
|
-
// return updatedOpts;
|
|
242
|
-
// }
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Helper Methods
|
|
246
|
-
|
|
247
|
-
// function canCreateBufferTransform(props: TransformProps): boolean {
|
|
248
|
-
// const canCreate =
|
|
249
|
-
// (props.feedbackBuffers && !isObjectEmpty(props.feedbackBuffers)) ||
|
|
250
|
-
// (props.feedbackMap && !isObjectEmpty(props.feedbackMap)) ||
|
|
251
|
-
// (props.varyings && props.varyings.length > 0);
|
|
252
|
-
// return Boolean(canCreate);
|
|
253
|
-
// }
|
|
254
|
-
|
|
255
|
-
// function canCreateTextureTransform(props: TransformProps): boolean {
|
|
256
|
-
// const canCreate =
|
|
257
|
-
// (props._sourceTextures && !isObjectEmpty(props._sourceTextures)) ||
|
|
258
|
-
// props._targetTexture ||
|
|
259
|
-
// props._targetTextureVarying;
|
|
260
|
-
// return Boolean(canCreate);
|
|
261
|
-
// }
|