@luma.gl/engine 8.6.0-alpha.5 → 9.0.0-alpha.3
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 +1 -1
- 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 +30 -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 +34 -7
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +33 -11
- 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 +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +14 -73
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +39 -160
- 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 +108 -505
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +55 -0
- package/dist/lib/pipeline-factory.d.ts.map +1 -0
- package/dist/lib/pipeline-factory.js +191 -0
- package/dist/lib/pipeline-factory.js.map +1 -0
- package/dist/lib/render-loop.d.ts +4 -17
- package/dist/lib/render-loop.d.ts.map +1 -1
- package/dist/lib/render-loop.js +14 -21
- package/dist/lib/render-loop.js.map +1 -1
- package/package.json +5 -5
- package/src/animation/key-frames.ts +1 -0
- package/src/animation/timeline.ts +1 -1
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +159 -8
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- 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 +58 -13
- package/src/geometry/primitive-utils.ts +30 -0
- package/src/index.ts +7 -8
- package/src/lib/animation-loop.ts +85 -274
- 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 +126 -642
- package/src/lib/pipeline-factory.ts +225 -0
- package/src/lib/render-loop.ts +21 -19
- 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
|
@@ -1,142 +1,62 @@
|
|
|
1
|
-
import {luma, Device} from '@luma.gl/api';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
assert
|
|
7
|
-
} from '@luma.gl/api';
|
|
8
|
-
import type {WebGLDeviceProps} from '@luma.gl/webgl'
|
|
9
|
-
import {WebGLDevice} from '@luma.gl/webgl';
|
|
10
|
-
import {
|
|
11
|
-
isWebGL,
|
|
12
|
-
// createGLContext,
|
|
13
|
-
// instrumentGLContext,
|
|
14
|
-
// resizeGLContext,
|
|
15
|
-
resetParameters
|
|
16
|
-
} from '@luma.gl/webgl';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
requestAnimationFrame,
|
|
21
|
-
cancelAnimationFrame,
|
|
22
|
-
Query,
|
|
23
|
-
// TODO - remove dependency on framebuffer (bundle size impact)
|
|
24
|
-
Framebuffer
|
|
25
|
-
} from '@luma.gl/webgl';
|
|
26
|
-
|
|
27
|
-
import { Stats, Stat } from '@probe.gl/stats'
|
|
1
|
+
import {luma, Device, DeviceProps} from '@luma.gl/api';
|
|
2
|
+
import {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';
|
|
3
|
+
import {Timeline} from '../animation/timeline';
|
|
4
|
+
import {AnimationProps} from '../lib/animation-props';
|
|
5
|
+
import {Stats, Stat} from '@probe.gl/stats';
|
|
28
6
|
import {isBrowser} from '@probe.gl/env';
|
|
29
7
|
|
|
30
|
-
import { Timeline } from '../animation/timeline'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type DeviceProps = WebGLDeviceProps;
|
|
34
|
-
type ContextProps = WebGLDeviceProps;
|
|
35
|
-
|
|
36
8
|
const isPage = isBrowser() && typeof document !== 'undefined';
|
|
37
9
|
|
|
38
10
|
let statIdCounter = 0;
|
|
39
11
|
|
|
12
|
+
type ContextProps = DeviceProps;
|
|
13
|
+
|
|
40
14
|
/** AnimationLoop properties */
|
|
41
15
|
export type AnimationLoopProps = {
|
|
42
|
-
onCreateDevice?: (props: DeviceProps) => Device
|
|
43
|
-
onCreateContext?: (props: ContextProps) => WebGLRenderingContext; // TODO: signature from createGLContext
|
|
16
|
+
onCreateDevice?: (props: DeviceProps) => Promise<Device>;
|
|
44
17
|
onAddHTML?: (div: HTMLDivElement) => string; // innerHTML
|
|
45
|
-
onInitialize?: (animationProps: AnimationProps) =>
|
|
18
|
+
onInitialize?: (animationProps: AnimationProps) => void;
|
|
46
19
|
onRender?: (animationProps: AnimationProps) => void;
|
|
47
20
|
onFinalize?: (animationProps: AnimationProps) => void;
|
|
48
|
-
onError?: (reason:
|
|
49
|
-
|
|
50
|
-
stats?: Stats;
|
|
21
|
+
onError?: (reason: Error) => void;
|
|
51
22
|
|
|
52
23
|
device?: Device;
|
|
53
|
-
|
|
54
|
-
|
|
24
|
+
deviceProps?: DeviceProps;
|
|
25
|
+
stats?: Stats;
|
|
55
26
|
|
|
56
27
|
// view parameters
|
|
28
|
+
debug?: boolean;
|
|
57
29
|
autoResizeViewport?: boolean;
|
|
58
30
|
autoResizeDrawingBuffer?: boolean;
|
|
59
31
|
useDevicePixels?: number | boolean;
|
|
60
|
-
|
|
61
|
-
/** @deprecated Use .device */
|
|
62
|
-
gl?: WebGLRenderingContext
|
|
63
|
-
/** @deprecated Will be removed */
|
|
64
|
-
createFramebuffer?: boolean;
|
|
65
32
|
};
|
|
66
33
|
|
|
67
|
-
export type AnimationProps = {
|
|
68
|
-
device: Device;
|
|
69
|
-
|
|
70
|
-
stop: () => AnimationLoop
|
|
71
|
-
canvas: HTMLCanvasElement | OffscreenCanvas
|
|
72
|
-
// Initial values
|
|
73
|
-
useDevicePixels: number | boolean
|
|
74
|
-
needsRedraw?: string
|
|
75
|
-
// Animation props
|
|
76
|
-
startTime: number
|
|
77
|
-
engineTime: number
|
|
78
|
-
tick: number
|
|
79
|
-
tock: number
|
|
80
|
-
|
|
81
|
-
// Timeline time for back compatibility
|
|
82
|
-
time: number
|
|
83
|
-
|
|
84
|
-
width: number
|
|
85
|
-
height: number
|
|
86
|
-
aspect: number
|
|
87
|
-
|
|
88
|
-
timeline: Timeline
|
|
89
|
-
animationLoop: AnimationLoop
|
|
90
|
-
|
|
91
|
-
// Experimental
|
|
92
|
-
_mousePosition?: [number, number] // [offsetX, offsetY],
|
|
93
|
-
|
|
94
|
-
/** @deprecated Will be removed, create your own Framebuffer */
|
|
95
|
-
framebuffer: Framebuffer
|
|
96
|
-
/** @deprecated Use .device */
|
|
97
|
-
gl: WebGLRenderingContext
|
|
98
|
-
|
|
99
|
-
/** @deprecated Use .timeline */
|
|
100
|
-
_timeline: Timeline
|
|
101
|
-
/** @deprecated Use .animationLoop */
|
|
102
|
-
_loop: AnimationLoop
|
|
103
|
-
/** @deprecated Use .animationLoop */
|
|
104
|
-
_animationLoop: AnimationLoop
|
|
105
|
-
}
|
|
106
|
-
|
|
107
34
|
const DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {
|
|
108
|
-
onCreateDevice: (props: DeviceProps) => luma.createDevice(props),
|
|
109
|
-
|
|
110
|
-
onAddHTML: null,
|
|
35
|
+
onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),
|
|
36
|
+
onAddHTML: undefined,
|
|
111
37
|
onInitialize: () => ({}),
|
|
112
38
|
onRender: () => {},
|
|
113
39
|
onFinalize: () => {},
|
|
114
40
|
onError: (error) => console.error(error), // eslint-disable-line no-console
|
|
115
41
|
|
|
116
|
-
device:
|
|
42
|
+
device: undefined,
|
|
43
|
+
deviceProps: {},
|
|
117
44
|
debug: false,
|
|
45
|
+
stats: luma.stats.get(`animation-loop-${statIdCounter++}`),
|
|
118
46
|
|
|
119
47
|
// view parameters
|
|
120
48
|
useDevicePixels: true,
|
|
121
49
|
autoResizeViewport: true,
|
|
122
50
|
autoResizeDrawingBuffer: true,
|
|
123
|
-
stats: lumaStats.get(`animation-loop-${statIdCounter++}`),
|
|
124
|
-
|
|
125
|
-
// deprecated
|
|
126
|
-
// onCreateContext: (opts) => createGLContext(opts),
|
|
127
|
-
gl: null,
|
|
128
|
-
glOptions: {},
|
|
129
|
-
createFramebuffer: false
|
|
130
51
|
};
|
|
131
52
|
|
|
132
53
|
/** Convenient animation loop */
|
|
133
54
|
export default class AnimationLoop {
|
|
134
55
|
device: Device;
|
|
135
|
-
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
56
|
+
canvas: HTMLCanvasElement; // | OffscreenCanvas;
|
|
136
57
|
|
|
137
58
|
props: Required<AnimationLoopProps>;
|
|
138
59
|
animationProps: AnimationProps;
|
|
139
|
-
framebuffer: Framebuffer = null;
|
|
140
60
|
timeline: Timeline = null;
|
|
141
61
|
stats: Stats;
|
|
142
62
|
cpuTime: Stat;
|
|
@@ -150,15 +70,11 @@ export default class AnimationLoop {
|
|
|
150
70
|
_initialized: boolean = false;
|
|
151
71
|
_running: boolean = false;
|
|
152
72
|
_animationFrameId = null;
|
|
153
|
-
_pageLoadPromise: Promise<{}> | null = null;
|
|
154
73
|
_nextFramePromise: Promise<AnimationLoop> | null = null;
|
|
155
74
|
_resolveNextFrame: ((AnimationLoop) => void) | null = null;
|
|
156
75
|
_cpuStartTime: number = 0;
|
|
157
76
|
|
|
158
|
-
_gpuTimeQuery: Query | null = null;
|
|
159
|
-
|
|
160
|
-
/** @deprecated */
|
|
161
|
-
gl: WebGLRenderingContext;
|
|
77
|
+
// _gpuTimeQuery: Query | null = null;
|
|
162
78
|
|
|
163
79
|
/*
|
|
164
80
|
* @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context
|
|
@@ -169,12 +85,6 @@ export default class AnimationLoop {
|
|
|
169
85
|
|
|
170
86
|
let {useDevicePixels = true} = this.props;
|
|
171
87
|
|
|
172
|
-
if ('useDevicePixelRatio' in props) {
|
|
173
|
-
log.deprecated('useDevicePixelRatio', 'useDevicePixels')();
|
|
174
|
-
// @ts-expect-error
|
|
175
|
-
useDevicePixels = props.useDevicePixelRatio;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
88
|
// state
|
|
179
89
|
this.device = props.device;
|
|
180
90
|
// @ts-expect-error
|
|
@@ -214,6 +124,7 @@ export default class AnimationLoop {
|
|
|
214
124
|
return this;
|
|
215
125
|
}
|
|
216
126
|
|
|
127
|
+
// TODO - move to CanvasContext
|
|
217
128
|
setProps(props: AnimationLoopProps): this {
|
|
218
129
|
if ('autoResizeViewport' in props) {
|
|
219
130
|
this.props.autoResizeViewport = props.autoResizeViewport;
|
|
@@ -227,25 +138,14 @@ export default class AnimationLoop {
|
|
|
227
138
|
return this;
|
|
228
139
|
}
|
|
229
140
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** Starts a render loop if not already running
|
|
236
|
-
* @param {Object} context - contains frame specific info (E.g. tick, width, height, etc)
|
|
237
|
-
*/
|
|
238
|
-
async _start(opts) {
|
|
141
|
+
/** Starts a render loop if not already running */
|
|
142
|
+
async start() {
|
|
239
143
|
if (this._running) {
|
|
240
144
|
return this;
|
|
241
145
|
}
|
|
242
146
|
this._running = true;
|
|
243
147
|
|
|
244
|
-
// console.debug(`Starting ${this.constructor.name}`);
|
|
245
|
-
// Wait for start promise before rendering frame
|
|
246
148
|
try {
|
|
247
|
-
await this._getPageLoadPromise();
|
|
248
|
-
|
|
249
149
|
// check that we haven't been stopped
|
|
250
150
|
if (!this._running) {
|
|
251
151
|
return null;
|
|
@@ -254,11 +154,12 @@ export default class AnimationLoop {
|
|
|
254
154
|
let appContext;
|
|
255
155
|
if (!this._initialized) {
|
|
256
156
|
this._initialized = true;
|
|
257
|
-
|
|
157
|
+
// Create the WebGL context
|
|
158
|
+
await this._createDevice();
|
|
159
|
+
this._initialize();
|
|
258
160
|
|
|
259
|
-
// Note: onIntialize can return a promise (in case app needs to load resources)
|
|
260
|
-
|
|
261
|
-
this._addCallbackData(appContext || {});
|
|
161
|
+
// Note: onIntialize can return a promise (e.g. in case app needs to load resources)
|
|
162
|
+
await this.onInitialize(this.animationProps);
|
|
262
163
|
}
|
|
263
164
|
|
|
264
165
|
// check that we haven't been stopped
|
|
@@ -274,16 +175,17 @@ export default class AnimationLoop {
|
|
|
274
175
|
}
|
|
275
176
|
|
|
276
177
|
return this;
|
|
277
|
-
} catch (
|
|
178
|
+
} catch (err: unknown) {
|
|
179
|
+
const error = err instanceof Error ? err : new Error('Unknown error')
|
|
278
180
|
this.props.onError(error);
|
|
279
181
|
// this._running = false; // TODO
|
|
280
|
-
|
|
182
|
+
throw error;
|
|
281
183
|
}
|
|
282
184
|
}
|
|
283
185
|
|
|
284
186
|
/** Explicitly draw a frame */
|
|
285
187
|
redraw(): this {
|
|
286
|
-
if (this.
|
|
188
|
+
if (this.device.isLost) {
|
|
287
189
|
return this;
|
|
288
190
|
}
|
|
289
191
|
|
|
@@ -312,7 +214,9 @@ export default class AnimationLoop {
|
|
|
312
214
|
stop() {
|
|
313
215
|
// console.debug(`Stopping ${this.constructor.name}`);
|
|
314
216
|
if (this._running) {
|
|
315
|
-
|
|
217
|
+
// call callback
|
|
218
|
+
this.onFinalize(this.animationProps);
|
|
219
|
+
|
|
316
220
|
this._cancelAnimationFrame();
|
|
317
221
|
this._nextFramePromise = null;
|
|
318
222
|
this._resolveNextFrame = null;
|
|
@@ -343,17 +247,11 @@ export default class AnimationLoop {
|
|
|
343
247
|
|
|
344
248
|
async toDataURL() {
|
|
345
249
|
this.setNeedsRedraw('toDataURL');
|
|
346
|
-
|
|
347
250
|
await this.waitForRender();
|
|
348
|
-
|
|
349
|
-
return this.gl.canvas.toDataURL();
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
isContextLost(): boolean {
|
|
353
|
-
return this.gl.isContextLost();
|
|
251
|
+
return this.canvas.toDataURL();
|
|
354
252
|
}
|
|
355
253
|
|
|
356
|
-
onCreateDevice(deviceProps: DeviceProps) {
|
|
254
|
+
onCreateDevice(deviceProps: DeviceProps): Promise<Device> {
|
|
357
255
|
return this.props.onCreateDevice(deviceProps);
|
|
358
256
|
}
|
|
359
257
|
|
|
@@ -369,26 +267,9 @@ export default class AnimationLoop {
|
|
|
369
267
|
return this.props.onFinalize(animationProps);
|
|
370
268
|
}
|
|
371
269
|
|
|
372
|
-
// DEPRECATED/REMOVED METHODS
|
|
373
|
-
|
|
374
|
-
/** @deprecated Use .onCreateDevice() */
|
|
375
|
-
onCreateContext(props: ContextProps) {
|
|
376
|
-
return this.props.onCreateContext(props);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/** @deprecated */
|
|
380
|
-
getHTMLControlValue(id, defaultValue = 1) {
|
|
381
|
-
const element = document.getElementById(id);
|
|
382
|
-
// @ts-expect-error Not all html elements have value
|
|
383
|
-
return element ? Number(element.value) : defaultValue;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
270
|
// PRIVATE METHODS
|
|
387
271
|
|
|
388
|
-
_initialize(
|
|
389
|
-
// Create the WebGL context
|
|
390
|
-
this._createDevice(props);
|
|
391
|
-
this._createFramebuffer();
|
|
272
|
+
_initialize() {
|
|
392
273
|
this._startEventHandling();
|
|
393
274
|
|
|
394
275
|
// Initialize the callback data
|
|
@@ -399,24 +280,7 @@ export default class AnimationLoop {
|
|
|
399
280
|
this._resizeCanvasDrawingBuffer();
|
|
400
281
|
this._resizeViewport();
|
|
401
282
|
|
|
402
|
-
this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
_getPageLoadPromise() {
|
|
406
|
-
if (!this._pageLoadPromise) {
|
|
407
|
-
this._pageLoadPromise = isPage
|
|
408
|
-
? new Promise((resolve, reject) => {
|
|
409
|
-
if (isPage && document.readyState === 'complete') {
|
|
410
|
-
resolve(document);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
window.addEventListener('load', () => {
|
|
414
|
-
resolve(document);
|
|
415
|
-
});
|
|
416
|
-
})
|
|
417
|
-
: Promise.resolve({});
|
|
418
|
-
}
|
|
419
|
-
return this._pageLoadPromise;
|
|
283
|
+
// this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;
|
|
420
284
|
}
|
|
421
285
|
|
|
422
286
|
_setDisplay(display) {
|
|
@@ -458,7 +322,7 @@ export default class AnimationLoop {
|
|
|
458
322
|
// if (this.display && this.display.cancelAnimationFrame) {
|
|
459
323
|
// this.display.cancelAnimationFrame(this._animationFrameId);
|
|
460
324
|
// }
|
|
461
|
-
|
|
325
|
+
cancelAnimationFrame(this._animationFrameId);
|
|
462
326
|
this._animationFrameId = null;
|
|
463
327
|
}
|
|
464
328
|
|
|
@@ -491,43 +355,34 @@ export default class AnimationLoop {
|
|
|
491
355
|
_setupFrame() {
|
|
492
356
|
this._resizeCanvasDrawingBuffer();
|
|
493
357
|
this._resizeViewport();
|
|
494
|
-
this._resizeFramebuffer();
|
|
495
358
|
}
|
|
496
359
|
|
|
497
360
|
// Initialize the object that will be passed to app callbacks
|
|
498
361
|
_initializeCallbackData() {
|
|
499
|
-
// @ts-expect-error
|
|
500
362
|
this.animationProps = {
|
|
363
|
+
animationLoop: this,
|
|
501
364
|
device: this.device,
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
stop: this.stop,
|
|
505
|
-
canvas: this.gl.canvas,
|
|
365
|
+
canvas: this.device.canvasContext.canvas,
|
|
366
|
+
timeline: this.timeline,
|
|
506
367
|
|
|
507
368
|
// Initial values
|
|
508
369
|
useDevicePixels: this.props.useDevicePixels,
|
|
509
370
|
needsRedraw: null,
|
|
510
371
|
|
|
372
|
+
// Placeholders
|
|
373
|
+
width: 1,
|
|
374
|
+
height: 1,
|
|
375
|
+
aspect: 1,
|
|
376
|
+
|
|
511
377
|
// Animation props
|
|
378
|
+
time: 0,
|
|
512
379
|
startTime: Date.now(),
|
|
513
380
|
engineTime: 0,
|
|
514
381
|
tick: 0,
|
|
515
382
|
tock: 0,
|
|
516
383
|
|
|
517
|
-
timeline: this.timeline,
|
|
518
|
-
animationLoop: this,
|
|
519
|
-
|
|
520
|
-
// Timeline time for back compatibility
|
|
521
|
-
time: 0,
|
|
522
|
-
|
|
523
384
|
// Experimental
|
|
524
|
-
_mousePosition: null
|
|
525
|
-
|
|
526
|
-
// Deprecated
|
|
527
|
-
framebuffer: this.framebuffer,
|
|
528
|
-
_timeline: this.timeline,
|
|
529
|
-
_loop: this,
|
|
530
|
-
_animationLoop: this
|
|
385
|
+
_mousePosition: null // Event props
|
|
531
386
|
};
|
|
532
387
|
}
|
|
533
388
|
|
|
@@ -563,43 +418,17 @@ export default class AnimationLoop {
|
|
|
563
418
|
: this.animationProps.engineTime;
|
|
564
419
|
}
|
|
565
420
|
|
|
566
|
-
_finalizeCallbackData() {
|
|
567
|
-
// call callback
|
|
568
|
-
this.onFinalize(this.animationProps);
|
|
569
|
-
// end callback
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/** Add application's data to the app context object */
|
|
573
|
-
_addCallbackData(appContext) {
|
|
574
|
-
if (typeof appContext === 'object' && appContext !== null) {
|
|
575
|
-
this.animationProps = Object.assign({}, this.animationProps, appContext);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
421
|
/** Either uses supplied or existing context, or calls provided callback to create one */
|
|
580
|
-
_createDevice(
|
|
581
|
-
const deviceProps = {...this.props, ...
|
|
582
|
-
|
|
583
|
-
// TODO - support this.onCreateContext
|
|
584
|
-
// Create the WebGL context if necessary
|
|
585
|
-
// this.gl = this.props.gl ? instrumentGLContext(this.props.gl, deviceProps) : this.onCreateContext(deviceProps);
|
|
586
|
-
|
|
587
|
-
this.device = this.onCreateDevice(deviceProps);
|
|
422
|
+
async _createDevice() {
|
|
423
|
+
const deviceProps = {...this.props, ...this.props.deviceProps};
|
|
424
|
+
this.device = await this.onCreateDevice(deviceProps);
|
|
588
425
|
// @ts-expect-error
|
|
589
|
-
this.
|
|
590
|
-
|
|
591
|
-
if (!isWebGL(this.gl)) {
|
|
592
|
-
throw new Error('AnimationLoop.onCreateContext - illegal context returned');
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// Reset the WebGL context.
|
|
596
|
-
resetParameters(this.gl);
|
|
597
|
-
|
|
426
|
+
this.canvas = this.device.canvasContext.canvas;
|
|
598
427
|
this._createInfoDiv();
|
|
599
428
|
}
|
|
600
429
|
|
|
601
430
|
_createInfoDiv() {
|
|
602
|
-
if (this.
|
|
431
|
+
if (this.canvas && this.props.onAddHTML) {
|
|
603
432
|
const wrapperDiv = document.createElement('div');
|
|
604
433
|
document.body.appendChild(wrapperDiv);
|
|
605
434
|
wrapperDiv.style.position = 'relative';
|
|
@@ -609,7 +438,7 @@ export default class AnimationLoop {
|
|
|
609
438
|
div.style.bottom = '10px';
|
|
610
439
|
div.style.width = '300px';
|
|
611
440
|
div.style.background = 'white';
|
|
612
|
-
wrapperDiv.appendChild(this.
|
|
441
|
+
wrapperDiv.appendChild(this.canvas);
|
|
613
442
|
wrapperDiv.appendChild(div);
|
|
614
443
|
const html = this.props.onAddHTML(div);
|
|
615
444
|
if (html) {
|
|
@@ -620,14 +449,15 @@ export default class AnimationLoop {
|
|
|
620
449
|
|
|
621
450
|
_getSizeAndAspect() {
|
|
622
451
|
// https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
|
|
623
|
-
const width = this.
|
|
624
|
-
const height = this.gl.drawingBufferHeight;
|
|
452
|
+
const [width, height] = this.device.canvasContext.getPixelSize();
|
|
625
453
|
|
|
626
454
|
// https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
|
|
627
455
|
let aspect = 1;
|
|
628
|
-
const
|
|
456
|
+
const canvas = this.device.canvasContext.canvas;
|
|
629
457
|
|
|
458
|
+
// @ts-expect-error
|
|
630
459
|
if (canvas && canvas.clientHeight) {
|
|
460
|
+
// @ts-expect-error
|
|
631
461
|
aspect = canvas.clientWidth / canvas.clientHeight;
|
|
632
462
|
} else if (width > 0 && height > 0) {
|
|
633
463
|
aspect = width / height;
|
|
@@ -638,18 +468,20 @@ export default class AnimationLoop {
|
|
|
638
468
|
|
|
639
469
|
/** Default viewport setup */
|
|
640
470
|
_resizeViewport() {
|
|
641
|
-
|
|
642
|
-
|
|
471
|
+
// @ts-expect-error Expose on canvasContext
|
|
472
|
+
if (this.props.autoResizeViewport && this.device.gl) {
|
|
473
|
+
// @ts-expect-error Expose canvasContext
|
|
474
|
+
this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);
|
|
643
475
|
}
|
|
644
476
|
}
|
|
645
477
|
|
|
646
|
-
/**
|
|
478
|
+
/**
|
|
647
479
|
* Resize the render buffer of the canvas to match canvas client size
|
|
648
480
|
* Optionally multiplying with devicePixel ratio
|
|
649
481
|
*/
|
|
650
482
|
_resizeCanvasDrawingBuffer() {
|
|
651
483
|
if (this.props.autoResizeDrawingBuffer) {
|
|
652
|
-
|
|
484
|
+
this.device.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});
|
|
653
485
|
}
|
|
654
486
|
}
|
|
655
487
|
|
|
@@ -660,38 +492,37 @@ export default class AnimationLoop {
|
|
|
660
492
|
// Check if timer for last frame has completed.
|
|
661
493
|
// GPU timer results are never available in the same
|
|
662
494
|
// frame they are captured.
|
|
663
|
-
if (
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
) {
|
|
668
|
-
|
|
669
|
-
}
|
|
495
|
+
// if (
|
|
496
|
+
// this._gpuTimeQuery &&
|
|
497
|
+
// this._gpuTimeQuery.isResultAvailable() &&
|
|
498
|
+
// !this._gpuTimeQuery.isTimerDisjoint()
|
|
499
|
+
// ) {
|
|
500
|
+
// this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());
|
|
501
|
+
// }
|
|
670
502
|
|
|
671
|
-
if (this._gpuTimeQuery) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
503
|
+
// if (this._gpuTimeQuery) {
|
|
504
|
+
// // GPU time query start
|
|
505
|
+
// this._gpuTimeQuery.beginTimeElapsedQuery();
|
|
506
|
+
// }
|
|
675
507
|
|
|
676
|
-
this.cpuTime.timeStart();
|
|
508
|
+
// this.cpuTime.timeStart();
|
|
677
509
|
}
|
|
678
510
|
|
|
679
511
|
_endTimers() {
|
|
680
512
|
this.cpuTime.timeEnd();
|
|
681
513
|
|
|
682
|
-
if (this._gpuTimeQuery) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
514
|
+
// if (this._gpuTimeQuery) {
|
|
515
|
+
// // GPU time query end. Results will be available on next frame.
|
|
516
|
+
// this._gpuTimeQuery.end();
|
|
517
|
+
// }
|
|
686
518
|
}
|
|
687
519
|
|
|
688
520
|
// Event handling
|
|
689
521
|
|
|
690
522
|
_startEventHandling() {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
canvas.addEventListener('
|
|
694
|
-
canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
523
|
+
if (this.canvas) {
|
|
524
|
+
this.canvas.addEventListener('mousemove', this._onMousemove);
|
|
525
|
+
this.canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
695
526
|
}
|
|
696
527
|
}
|
|
697
528
|
|
|
@@ -701,24 +532,4 @@ export default class AnimationLoop {
|
|
|
701
532
|
_onMouseleave(e) {
|
|
702
533
|
this.animationProps._mousePosition = null;
|
|
703
534
|
}
|
|
704
|
-
|
|
705
|
-
// Deprecated
|
|
706
|
-
|
|
707
|
-
/** @deprecated */
|
|
708
|
-
_createFramebuffer() {
|
|
709
|
-
// Setup default framebuffer
|
|
710
|
-
if (this.props.createFramebuffer) {
|
|
711
|
-
this.framebuffer = new Framebuffer(this.gl);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/** @deprecated */
|
|
716
|
-
_resizeFramebuffer() {
|
|
717
|
-
if (this.framebuffer) {
|
|
718
|
-
this.framebuffer.resize({
|
|
719
|
-
width: this.gl.drawingBufferWidth,
|
|
720
|
-
height: this.gl.drawingBufferHeight
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
535
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Device} from '@luma.gl/api';
|
|
2
|
+
import {Timeline} from '../animation/timeline'
|
|
3
|
+
import type AnimationLoop from './animation-loop';
|
|
4
|
+
|
|
5
|
+
/** Properties passed to every render frame */
|
|
6
|
+
export type AnimationProps = {
|
|
7
|
+
device: Device;
|
|
8
|
+
animationLoop: AnimationLoop;
|
|
9
|
+
|
|
10
|
+
/** @todo Should be canvasContext */
|
|
11
|
+
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
12
|
+
useDevicePixels: number | boolean;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
aspect: number;
|
|
16
|
+
|
|
17
|
+
// Animation props
|
|
18
|
+
time: number;
|
|
19
|
+
startTime: number;
|
|
20
|
+
engineTime: number;
|
|
21
|
+
tick: number;
|
|
22
|
+
tock: number;
|
|
23
|
+
|
|
24
|
+
// Initial values
|
|
25
|
+
needsRedraw?: string;
|
|
26
|
+
|
|
27
|
+
timeline: Timeline;
|
|
28
|
+
|
|
29
|
+
// Experimental
|
|
30
|
+
_mousePosition?: [number, number]; // [offsetX, offsetY],
|
|
31
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
|
|
1
2
|
// ClipSpace
|
|
3
|
+
/*
|
|
2
4
|
import GL from '@luma.gl/constants';
|
|
3
|
-
import Model, {ModelProps} from '
|
|
5
|
+
import Model, {ModelProps} from './model';
|
|
4
6
|
import Geometry from '../geometry/geometry';
|
|
5
7
|
|
|
6
8
|
const CLIPSPACE_VERTEX_SHADER = `\
|
|
@@ -20,7 +22,7 @@ void main(void) {
|
|
|
20
22
|
}
|
|
21
23
|
`;
|
|
22
24
|
|
|
23
|
-
/* eslint-disable indent, no-multi-spaces
|
|
25
|
+
/* eslint-disable indent, no-multi-spaces *
|
|
24
26
|
const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
25
27
|
|
|
26
28
|
|
|
@@ -46,3 +48,4 @@ export default class ClipSpace extends Model {
|
|
|
46
48
|
this.setVertexCount(4);
|
|
47
49
|
}
|
|
48
50
|
}
|
|
51
|
+
*/
|