@luma.gl/engine 8.6.0-alpha.1 → 8.6.0-alpha.2
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/index.d.ts +17 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +57 -28
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +71 -62
- package/dist/lib/animation-loop.js.map +1 -1
- package/dist/lib/model.d.ts +16 -4
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +15 -9
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/program-manager.d.ts +6 -5
- package/dist/lib/program-manager.d.ts.map +1 -1
- package/dist/lib/program-manager.js +8 -9
- package/dist/lib/program-manager.js.map +1 -1
- package/dist/lib/render-loop.d.ts +27 -0
- package/dist/lib/render-loop.d.ts.map +1 -0
- package/dist/lib/render-loop.js +56 -0
- package/dist/lib/render-loop.js.map +1 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -1
- package/dist/transform/buffer-transform.js +2 -3
- package/dist/transform/buffer-transform.js.map +1 -1
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js.map +1 -1
- package/dist/transform/transform-types.d.ts +1 -0
- package/dist/transform/transform-types.d.ts.map +1 -1
- package/dist/transform/transform.d.ts +21 -2
- package/dist/transform/transform.d.ts.map +1 -1
- package/dist/transform/transform.js +26 -11
- package/dist/transform/transform.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +18 -13
- package/src/lib/animation-loop.ts +141 -125
- package/src/lib/model.ts +42 -15
- package/src/lib/program-manager.ts +12 -13
- package/src/lib/render-loop.ts +56 -0
- package/src/transform/buffer-transform.ts +2 -3
- package/src/transform/texture-transform.ts +2 -3
- package/src/transform/transform-types.ts +1 -0
- package/src/transform/transform.ts +38 -22
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {Device} from '@luma.gl/api/';
|
|
1
2
|
import {assembleShaders} from '@luma.gl/shadertools';
|
|
2
3
|
import {Program} from '@luma.gl/webgl';
|
|
3
4
|
|
|
@@ -15,7 +16,7 @@ type GetProgramOptions = {
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export default class ProgramManager {
|
|
18
|
-
readonly
|
|
19
|
+
readonly device: Device;
|
|
19
20
|
|
|
20
21
|
stateHash = 0; // Used change hashing if hooks are modified
|
|
21
22
|
private _hashCounter = 0;
|
|
@@ -28,17 +29,15 @@ export default class ProgramManager {
|
|
|
28
29
|
private readonly _hookFunctions = [];
|
|
29
30
|
private _defaultModules = [];
|
|
30
31
|
|
|
31
|
-
static getDefaultProgramManager(
|
|
32
|
+
static getDefaultProgramManager(device: Device): ProgramManager {
|
|
32
33
|
// @ts-expect-error
|
|
33
|
-
|
|
34
|
+
device.defaultProgramManager = device.defaultProgramManager || new ProgramManager(device);
|
|
34
35
|
// @ts-expect-error
|
|
35
|
-
|
|
36
|
-
// @ts-expect-error
|
|
37
|
-
return gl.luma.defaultProgramManager;
|
|
36
|
+
return device.defaultProgramManager;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
constructor(
|
|
41
|
-
this.
|
|
39
|
+
constructor(device: Device) {
|
|
40
|
+
this.device = device;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
addDefaultModule(module: Module): void {
|
|
@@ -56,17 +55,16 @@ export default class ProgramManager {
|
|
|
56
55
|
this.stateHash++;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
addShaderHook(hook, opts) {
|
|
58
|
+
addShaderHook(hook, opts?): void {
|
|
60
59
|
if (opts) {
|
|
61
60
|
hook = Object.assign(opts, {hook});
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
this._hookFunctions.push(hook);
|
|
65
|
-
|
|
66
64
|
this.stateHash++;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
get(props: GetProgramOptions = {}) {
|
|
67
|
+
get(props: GetProgramOptions = {}): Program {
|
|
70
68
|
const {
|
|
71
69
|
vs = '',
|
|
72
70
|
fs = '',
|
|
@@ -107,7 +105,7 @@ export default class ProgramManager {
|
|
|
107
105
|
}`;
|
|
108
106
|
|
|
109
107
|
if (!this._programCache[hash]) {
|
|
110
|
-
const assembled = assembleShaders(this.
|
|
108
|
+
const assembled = assembleShaders(this.device, {
|
|
111
109
|
vs,
|
|
112
110
|
fs,
|
|
113
111
|
modules,
|
|
@@ -117,7 +115,8 @@ export default class ProgramManager {
|
|
|
117
115
|
transpileToGLSL100
|
|
118
116
|
});
|
|
119
117
|
|
|
120
|
-
|
|
118
|
+
// @ts-expect-error TODO - program should be created from device
|
|
119
|
+
this._programCache[hash] = new Program(this.device.gl, {
|
|
121
120
|
hash,
|
|
122
121
|
vs: assembled.vs,
|
|
123
122
|
fs: assembled.fs,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {Stats} from '@probe.gl/stats';
|
|
2
|
+
import type {AnimationProps} from './animation-loop';
|
|
3
|
+
import AnimationLoop from './animation-loop';
|
|
4
|
+
import {Timeline} from '../animation/timeline'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal animation loop that initializes models in constructor
|
|
8
|
+
* Simplifying type management
|
|
9
|
+
*/
|
|
10
|
+
export abstract class RenderLoop {
|
|
11
|
+
constructor(animationProps?: AnimationProps) {}
|
|
12
|
+
onRender(animationProps: AnimationProps) {}
|
|
13
|
+
onFinalize(animationProps: AnimationProps) {}
|
|
14
|
+
|
|
15
|
+
static getAnimationLoop(RenderLoopConstructor: typeof RenderLoop) {
|
|
16
|
+
return new WrappedAnimationLoop(RenderLoopConstructor);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Instantiates and runs the render loop */
|
|
20
|
+
static run(RenderLoopConstructor: typeof RenderLoop, options?: {start?: boolean}): WrappedAnimationLoop {
|
|
21
|
+
const animationLoop = RenderLoop.getAnimationLoop(RenderLoopConstructor);
|
|
22
|
+
if (options?.start !== false) {
|
|
23
|
+
animationLoop.start();
|
|
24
|
+
}
|
|
25
|
+
return animationLoop;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class WrappedAnimationLoop extends AnimationLoop {
|
|
30
|
+
RenderLoopConstructor: typeof RenderLoop;
|
|
31
|
+
renderLoop: RenderLoop;
|
|
32
|
+
|
|
33
|
+
getInfo() {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return this.RenderLoopConstructor.info;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor(RenderLoopConstructor: typeof RenderLoop) {
|
|
39
|
+
super();
|
|
40
|
+
this.RenderLoopConstructor = RenderLoopConstructor;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onInitialize(animationProps: AnimationProps) {
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
this.renderLoop = new this.RenderLoopConstructor(animationProps);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
onRender(animationProps: AnimationProps) {
|
|
49
|
+
this.renderLoop.onRender(animationProps);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onFinalize(animationProps: AnimationProps) {
|
|
53
|
+
this.renderLoop?.onFinalize?.(animationProps);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {Buffer, TransformFeedback} from '@luma.gl/webgl';
|
|
3
|
-
import {assert} from '@luma.gl/webgl';
|
|
1
|
+
import {assert} from '@luma.gl/api';
|
|
2
|
+
import {Buffer, TransformFeedback, isWebGL2} from '@luma.gl/webgl';
|
|
4
3
|
import type {TransformProps, TransformDrawOptions, TransformRunOptions, TransformBinding} from './transform-types';
|
|
5
4
|
|
|
6
5
|
// import {TransformDrawOptions, TransformModelProps} from './resource-transform';
|
|
@@ -125,7 +125,7 @@ export default class TextureTransform {
|
|
|
125
125
|
// readPixels returns 4 elements for each pixel, pack the elements when requested
|
|
126
126
|
const ArrayType = pixels.constructor;
|
|
127
127
|
const channelCount = typeToChannelCount(this.targetTextureType);
|
|
128
|
-
// @ts-
|
|
128
|
+
// @ts-expect-error
|
|
129
129
|
const packedPixels = new ArrayType((pixels.length * channelCount) / 4);
|
|
130
130
|
let packCount = 0;
|
|
131
131
|
for (let i = 0; i < pixels.length; i += 4) {
|
|
@@ -148,7 +148,6 @@ export default class TextureTransform {
|
|
|
148
148
|
this.ownTexture.delete();
|
|
149
149
|
}
|
|
150
150
|
if (this.elementIDBuffer) {
|
|
151
|
-
// @ts-ignore
|
|
152
151
|
this.elementIDBuffer.delete();
|
|
153
152
|
}
|
|
154
153
|
}
|
|
@@ -317,7 +316,7 @@ export default class TextureTransform {
|
|
|
317
316
|
// build and return shader releated parameters
|
|
318
317
|
_processVertexShader(props: TransformProps = {}) {
|
|
319
318
|
const {sourceTextures, targetTexture} = this.bindings[this.currentIndex];
|
|
320
|
-
// @ts-
|
|
319
|
+
// @ts-expect-error TODO - uniforms is not present
|
|
321
320
|
const {vs, uniforms, targetTextureType, inject, samplerTextureMap} = updateForTextures({
|
|
322
321
|
vs: props.vs,
|
|
323
322
|
sourceTextureMap: sourceTextures,
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
+
import {Device, assert} from '@luma.gl/api';
|
|
1
2
|
import GL from '@luma.gl/constants';
|
|
2
3
|
import {getShaderInfo, getPassthroughFS} from '@luma.gl/shadertools';
|
|
3
|
-
import {isWebGL2} from '@luma.gl/gltools';
|
|
4
4
|
import type {Framebuffer, Buffer} from '@luma.gl/webgl';
|
|
5
|
-
import {
|
|
5
|
+
import {WebGLDevice, isObjectEmpty} from '@luma.gl/webgl';
|
|
6
6
|
|
|
7
7
|
import Model from '../lib/model';
|
|
8
8
|
import BufferTransform from './buffer-transform';
|
|
9
9
|
import TextureTransform from './texture-transform';
|
|
10
10
|
import {TransformProps, TransformRunOptions, TransformDrawOptions} from './transform-types';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Takes source and target buffers/textures and sets up the pipeline
|
|
14
|
+
*/
|
|
13
15
|
export default class Transform {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Check if Transforms are supported (they are not under WebGL1)
|
|
18
|
+
* @todo differentiate writing to buffer vs not
|
|
19
|
+
*/
|
|
20
|
+
static isSupported(device: Device | WebGL2RenderingContext): boolean {
|
|
21
|
+
try {
|
|
22
|
+
const webglDevice = WebGLDevice.attach(device);
|
|
23
|
+
return webglDevice.isWebGL2;
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
28
|
|
|
29
|
+
readonly device: WebGLDevice;
|
|
19
30
|
readonly gl: WebGL2RenderingContext;
|
|
20
31
|
model: Model | null = null;
|
|
21
32
|
elementCount = 0;
|
|
@@ -23,14 +34,16 @@ export default class Transform {
|
|
|
23
34
|
textureTransform = null;
|
|
24
35
|
elementIDBuffer = null;
|
|
25
36
|
|
|
26
|
-
constructor(
|
|
27
|
-
this.
|
|
37
|
+
constructor(device: Device | WebGL2RenderingContext, props: TransformProps = {}) {
|
|
38
|
+
this.device = WebGLDevice.attach(device);
|
|
39
|
+
// TODO assert webgl2?
|
|
40
|
+
this.gl = this.device.gl2;
|
|
28
41
|
this._initialize(props);
|
|
29
42
|
Object.seal(this);
|
|
30
43
|
}
|
|
31
44
|
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
/** Delete owned resources. */
|
|
46
|
+
destroy(): void {
|
|
34
47
|
const {model, bufferTransform, textureTransform} = this;
|
|
35
48
|
if (model) {
|
|
36
49
|
model.delete();
|
|
@@ -43,7 +56,12 @@ export default class Transform {
|
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
/** @deprecated Use destroy*() */
|
|
60
|
+
delete(): void {
|
|
61
|
+
this.destroy();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Run one transform loop. */
|
|
47
65
|
run(options?: TransformRunOptions): void {
|
|
48
66
|
const {clearRenderTarget = true} = options || {};
|
|
49
67
|
|
|
@@ -56,7 +74,7 @@ export default class Transform {
|
|
|
56
74
|
this.model.transform(updatedOpts);
|
|
57
75
|
}
|
|
58
76
|
|
|
59
|
-
|
|
77
|
+
/** swap resources if a map is provided */
|
|
60
78
|
swap(): void {
|
|
61
79
|
let swapped = false;
|
|
62
80
|
const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
@@ -66,16 +84,15 @@ export default class Transform {
|
|
|
66
84
|
assert(swapped, 'Nothing to swap');
|
|
67
85
|
}
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
/** Return Buffer object for given varying name. */
|
|
70
88
|
getBuffer(varyingName: string = null): Buffer {
|
|
71
89
|
return this.bufferTransform && this.bufferTransform.getBuffer(varyingName);
|
|
72
90
|
}
|
|
73
91
|
|
|
74
|
-
|
|
92
|
+
/** Return data either from Buffer or from Texture */
|
|
75
93
|
getData(options: {packed?: boolean; varyingName?: string} = {}) {
|
|
76
94
|
const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
77
95
|
for (const resourceTransform of resourceTransforms) {
|
|
78
|
-
// @ts-ignore
|
|
79
96
|
const data = resourceTransform.getData(options);
|
|
80
97
|
if (data) {
|
|
81
98
|
return data;
|
|
@@ -84,15 +101,14 @@ export default class Transform {
|
|
|
84
101
|
return null;
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
|
|
104
|
+
/** Return framebuffer object if rendering to textures */
|
|
88
105
|
getFramebuffer(): Framebuffer | null {
|
|
89
106
|
return this.textureTransform && this.textureTransform.getFramebuffer();
|
|
90
107
|
}
|
|
91
108
|
|
|
92
|
-
|
|
109
|
+
/** Update some or all buffer/texture bindings. */
|
|
93
110
|
update(props: TransformProps): void {
|
|
94
111
|
if ('elementCount' in props) {
|
|
95
|
-
// @ts-ignore TODO
|
|
96
112
|
this.model.setVertexCount(props.elementCount);
|
|
97
113
|
}
|
|
98
114
|
const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
|
|
@@ -109,7 +125,7 @@ export default class Transform {
|
|
|
109
125
|
|
|
110
126
|
props = this._updateModelProps(props);
|
|
111
127
|
this.model = new Model(
|
|
112
|
-
|
|
128
|
+
this.device,
|
|
113
129
|
Object.assign({}, props, {
|
|
114
130
|
fs: props.fs || getPassthroughFS({version: getShaderInfo(props.vs).version}),
|
|
115
131
|
id: props.id || 'transform-model',
|
|
@@ -118,9 +134,9 @@ export default class Transform {
|
|
|
118
134
|
})
|
|
119
135
|
);
|
|
120
136
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
if (this.bufferTransform) {
|
|
138
|
+
this.bufferTransform.setupResources({model: this.model});
|
|
139
|
+
}
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
_updateModelProps(props: TransformProps): TransformProps {
|