@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.
Files changed (41) hide show
  1. package/dist/index.d.ts +17 -7
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +8 -7
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/animation-loop.d.ts +57 -28
  6. package/dist/lib/animation-loop.d.ts.map +1 -1
  7. package/dist/lib/animation-loop.js +71 -62
  8. package/dist/lib/animation-loop.js.map +1 -1
  9. package/dist/lib/model.d.ts +16 -4
  10. package/dist/lib/model.d.ts.map +1 -1
  11. package/dist/lib/model.js +15 -9
  12. package/dist/lib/model.js.map +1 -1
  13. package/dist/lib/program-manager.d.ts +6 -5
  14. package/dist/lib/program-manager.d.ts.map +1 -1
  15. package/dist/lib/program-manager.js +8 -9
  16. package/dist/lib/program-manager.js.map +1 -1
  17. package/dist/lib/render-loop.d.ts +27 -0
  18. package/dist/lib/render-loop.d.ts.map +1 -0
  19. package/dist/lib/render-loop.js +56 -0
  20. package/dist/lib/render-loop.js.map +1 -0
  21. package/dist/transform/buffer-transform.d.ts.map +1 -1
  22. package/dist/transform/buffer-transform.js +2 -3
  23. package/dist/transform/buffer-transform.js.map +1 -1
  24. package/dist/transform/texture-transform.d.ts.map +1 -1
  25. package/dist/transform/texture-transform.js.map +1 -1
  26. package/dist/transform/transform-types.d.ts +1 -0
  27. package/dist/transform/transform-types.d.ts.map +1 -1
  28. package/dist/transform/transform.d.ts +21 -2
  29. package/dist/transform/transform.d.ts.map +1 -1
  30. package/dist/transform/transform.js +26 -11
  31. package/dist/transform/transform.js.map +1 -1
  32. package/package.json +7 -7
  33. package/src/index.ts +18 -13
  34. package/src/lib/animation-loop.ts +141 -125
  35. package/src/lib/model.ts +42 -15
  36. package/src/lib/program-manager.ts +12 -13
  37. package/src/lib/render-loop.ts +56 -0
  38. package/src/transform/buffer-transform.ts +2 -3
  39. package/src/transform/texture-transform.ts +2 -3
  40. package/src/transform/transform-types.ts +1 -0
  41. package/src/transform/transform.ts +38 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "8.6.0-alpha.1",
3
+ "version": "8.6.0-alpha.2",
4
4
  "description": "WebGL2 Components for High Performance Rendering and Computation",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -31,12 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.0.0",
34
- "@luma.gl/constants": "8.6.0-alpha.1",
35
- "@luma.gl/gltools": "8.6.0-alpha.1",
36
- "@luma.gl/shadertools": "8.6.0-alpha.1",
37
- "@luma.gl/webgl": "8.6.0-alpha.1",
34
+ "@luma.gl/constants": "8.6.0-alpha.2",
35
+ "@luma.gl/shadertools": "8.6.0-alpha.2",
36
+ "@luma.gl/webgl": "8.6.0-alpha.2",
38
37
  "@math.gl/core": "^3.5.0",
39
- "probe.gl": "^3.4.0"
38
+ "@probe.gl/log": "3.5.0-alpha.5",
39
+ "@probe.gl/stats": "3.5.0-alpha.5"
40
40
  },
41
- "gitHead": "e3895ce8a6dd376394c6662bb8cf0e1ad1f233f3"
41
+ "gitHead": "bdcebda76c1b4e47b127cdbd3f426ea6cbae44f1"
42
42
  }
package/src/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  // CORE
2
+ export type {AnimationLoopProps, AnimationProps} from './lib/animation-loop';
2
3
  export {default as AnimationLoop} from './lib/animation-loop';
4
+ export {RenderLoop} from './lib/render-loop';
5
+
6
+ export type {ModelProps} from './lib/model';
3
7
  export {default as Model} from './lib/model';
4
8
  export {default as ProgramManager} from './lib/program-manager';
5
9
  export {default as Transform} from './transform/transform';
@@ -8,19 +12,20 @@ export {default as Transform} from './transform/transform';
8
12
  export {default as Geometry} from './geometry/geometry';
9
13
 
10
14
  // Primitives
11
- export {ConeGeometry, ConeGeometryProps} from './geometries/cone-geometry';
12
- export {CubeGeometry, CubeGeometryProps} from './geometries/cube-geometry';
13
- export {CylinderGeometry, CylinderGeometryProps} from './geometries/cylinder-geometry';
14
- export {
15
- IcoSphereGeometry,
16
- IcoSphereGeometryProps
17
- } from './geometries/ico-sphere-geometry';
18
- export {PlaneGeometry, PlaneGeometryProps} from './geometries/plane-geometry';
19
- export {SphereGeometry, SphereGeometryProps} from './geometries/sphere-geometry';
20
- export {
21
- TruncatedConeGeometry,
22
- TruncatedConeGeometryProps
23
- } from './geometries/truncated-cone-geometry';
15
+ export type {ConeGeometryProps} from './geometries/cone-geometry';
16
+ export {ConeGeometry} from './geometries/cone-geometry';
17
+ export type {CubeGeometryProps} from './geometries/cube-geometry';
18
+ export {CubeGeometry} from './geometries/cube-geometry';
19
+ export type {CylinderGeometryProps} from './geometries/cylinder-geometry';
20
+ export {CylinderGeometry} from './geometries/cylinder-geometry';
21
+ export type {IcoSphereGeometryProps} from './geometries/ico-sphere-geometry';
22
+ export {IcoSphereGeometry} from './geometries/ico-sphere-geometry';
23
+ export type {PlaneGeometryProps} from './geometries/plane-geometry';
24
+ export {PlaneGeometry} from './geometries/plane-geometry';
25
+ export type {SphereGeometryProps} from './geometries/sphere-geometry';
26
+ export {SphereGeometry} from './geometries/sphere-geometry';
27
+ export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
28
+ export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
24
29
 
25
30
  // Animation
26
31
  export {Timeline} from './animation/timeline';
@@ -1,29 +1,37 @@
1
+ import {luma, Device} from '@luma.gl/api';
2
+ import {
3
+ lumaStats,
4
+ // TODO - remove dependency on framebuffer (bundle size impact)
5
+ log,
6
+ assert
7
+ } from '@luma.gl/api';
8
+ import type {WebGLDeviceProps} from '@luma.gl/webgl'
9
+ import {WebGLDevice} from '@luma.gl/webgl';
1
10
  import {
2
11
  isWebGL,
3
- createGLContext,
4
- instrumentGLContext,
5
- resizeGLContext,
12
+ // createGLContext,
13
+ // instrumentGLContext,
14
+ // resizeGLContext,
6
15
  resetParameters
7
- } from '@luma.gl/gltools';
16
+ } from '@luma.gl/webgl';
17
+
8
18
 
9
19
  import {
10
20
  requestAnimationFrame,
11
21
  cancelAnimationFrame,
12
22
  Query,
13
- lumaStats,
14
23
  // TODO - remove dependency on framebuffer (bundle size impact)
15
- Framebuffer,
16
- log,
17
- assert
24
+ Framebuffer
18
25
  } from '@luma.gl/webgl';
19
26
 
20
- import { Stats } from 'probe.gl'
21
- import { Timeline } from '../animation/timeline'
27
+ import { Stats, Stat } from '@probe.gl/stats'
28
+ import {isBrowser} from '@probe.gl/env';
22
29
 
23
- import type {GLContextOptions} from '@luma.gl/gltools'
30
+ import { Timeline } from '../animation/timeline'
24
31
 
25
- import {isBrowser} from 'probe.gl/env';
26
32
 
33
+ type DeviceProps = WebGLDeviceProps;
34
+ type ContextProps = WebGLDeviceProps;
27
35
 
28
36
  const isPage = isBrowser() && typeof document !== 'undefined';
29
37
 
@@ -31,17 +39,18 @@ let statIdCounter = 0;
31
39
 
32
40
  /** AnimationLoop properties */
33
41
  export type AnimationLoopProps = {
34
- onCreateContext?: (opts: GLContextOptions) => WebGLRenderingContext; // TODO: signature from createGLContext
42
+ onCreateDevice?: (props: DeviceProps) => Device;
43
+ onCreateContext?: (props: ContextProps) => WebGLRenderingContext; // TODO: signature from createGLContext
35
44
  onAddHTML?: (div: HTMLDivElement) => string; // innerHTML
36
- onInitialize?: ((animationProps: AnimationProps) => {}) | ((animationProps: AnimationProps) => {});
45
+ onInitialize?: (animationProps: AnimationProps) => {} | void;
37
46
  onRender?: (animationProps: AnimationProps) => void;
38
47
  onFinalize?: (animationProps: AnimationProps) => void;
39
48
  onError?: (reason: any) => void;
40
49
 
41
50
  stats?: Stats;
42
51
 
43
- gl?: WebGLRenderingContext
44
- glOptions?: GLContextOptions // createGLContext options
52
+ device?: Device;
53
+ glOptions?: ContextProps; // createGLContext options
45
54
  debug?: boolean;
46
55
 
47
56
  // view parameters
@@ -49,16 +58,17 @@ export type AnimationLoopProps = {
49
58
  autoResizeDrawingBuffer?: boolean;
50
59
  useDevicePixels?: number | boolean;
51
60
 
52
- /** @deprecated */
61
+ /** @deprecated Use .device */
62
+ gl?: WebGLRenderingContext
63
+ /** @deprecated Will be removed */
53
64
  createFramebuffer?: boolean;
54
65
  };
55
66
 
56
67
  export type AnimationProps = {
57
- gl: WebGLRenderingContext
68
+ device: Device;
58
69
 
59
70
  stop: () => AnimationLoop
60
71
  canvas: HTMLCanvasElement | OffscreenCanvas
61
- framebuffer: Framebuffer
62
72
  // Initial values
63
73
  useDevicePixels: number | boolean
64
74
  needsRedraw?: string
@@ -75,63 +85,63 @@ export type AnimationProps = {
75
85
  height: number
76
86
  aspect: number
77
87
 
88
+ timeline: Timeline
89
+ animationLoop: AnimationLoop
90
+
78
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 */
79
100
  _timeline: Timeline
101
+ /** @deprecated Use .animationLoop */
80
102
  _loop: AnimationLoop
103
+ /** @deprecated Use .animationLoop */
81
104
  _animationLoop: AnimationLoop
82
- _mousePosition?: [number, number] // [offsetX, offsetY]
83
- _offScreen: boolean
84
- }
85
-
86
- /* instance of parameters after construction
87
- type AnimationLoopPropsInternal = {
88
- onCreateContext: (opts: GLContextOptions) => WebGLRenderingContext // TODO: signature from createGLContext
89
- onAddHTML?: (div: HTMLDivElement) => string // innerHTML
90
- onInitialize: (animationProps: AnimationProps) => AnimationProps | Promise<AnimationProps>
91
- onRender: (animationProps: AnimationProps) => void
92
- onFinalize: (animationProps: AnimationProps) => void
93
- onError: (reason: any) => PromiseLike<never>
94
- gl?: WebGLRenderingContext
95
- glOptions: GLContextOptions // createGLContext options
96
- debug: boolean
97
- createFramebuffer: boolean
98
105
  }
99
- */
100
106
 
101
107
  const DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {
102
- onCreateContext: (opts) => createGLContext(opts),
108
+ onCreateDevice: (props: DeviceProps) => luma.createDevice(props),
109
+ onCreateContext: null,
103
110
  onAddHTML: null,
104
111
  onInitialize: () => ({}),
105
112
  onRender: () => {},
106
113
  onFinalize: () => {},
107
- // eslint-disable-next-line no-console
108
- onError: (error) => console.error(error),
114
+ onError: (error) => console.error(error), // eslint-disable-line no-console
109
115
 
110
- gl: null,
111
- glOptions: {},
116
+ device: null,
112
117
  debug: false,
113
118
 
114
- createFramebuffer: false,
115
-
116
119
  // view parameters
117
120
  useDevicePixels: true,
118
121
  autoResizeViewport: true,
119
122
  autoResizeDrawingBuffer: true,
120
- stats: lumaStats.get(`animation-loop-${statIdCounter++}`)
123
+ stats: lumaStats.get(`animation-loop-${statIdCounter++}`),
124
+
125
+ // deprecated
126
+ // onCreateContext: (opts) => createGLContext(opts),
127
+ gl: null,
128
+ glOptions: {},
129
+ createFramebuffer: false
121
130
  };
122
131
 
132
+ /** Convenient animation loop */
123
133
  export default class AnimationLoop {
124
- animationProps: AnimationProps;
125
- props: Required<AnimationLoopProps>;
126
- gl: WebGLRenderingContext;
134
+ device: Device;
127
135
  canvas: HTMLCanvasElement | OffscreenCanvas;
136
+
137
+ props: Required<AnimationLoopProps>;
138
+ animationProps: AnimationProps;
128
139
  framebuffer: Framebuffer = null;
129
140
  timeline: Timeline = null;
130
141
  stats: Stats;
131
- cpuTime: Stats;
132
- gpuTime: Stats;
133
- frameRate: Stats;
134
- offScreen: boolean;
142
+ cpuTime: Stat;
143
+ gpuTime: Stat;
144
+ frameRate: Stat;
135
145
 
136
146
  display: any;
137
147
 
@@ -147,6 +157,9 @@ export default class AnimationLoop {
147
157
 
148
158
  _gpuTimeQuery: Query | null = null;
149
159
 
160
+ /** @deprecated */
161
+ gl: WebGLRenderingContext;
162
+
150
163
  /*
151
164
  * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context
152
165
  */
@@ -158,12 +171,15 @@ export default class AnimationLoop {
158
171
 
159
172
  if ('useDevicePixelRatio' in props) {
160
173
  log.deprecated('useDevicePixelRatio', 'useDevicePixels')();
161
- // @ts-ignore
174
+ // @ts-expect-error
162
175
  useDevicePixels = props.useDevicePixelRatio;
163
176
  }
164
177
 
165
178
  // state
166
- this.gl = props.gl;
179
+ this.device = props.device;
180
+ // @ts-expect-error
181
+ this.gl = (this.device && this.device.gl) || props.gl;
182
+
167
183
  this.stats = props.stats;
168
184
  this.cpuTime = this.stats.get('CPU Time');
169
185
  this.gpuTime = this.stats.get('GPU Time');
@@ -179,16 +195,20 @@ export default class AnimationLoop {
179
195
  this.start = this.start.bind(this);
180
196
  this.stop = this.stop.bind(this);
181
197
 
182
-
183
198
  this._onMousemove = this._onMousemove.bind(this);
184
199
  this._onMouseleave = this._onMouseleave.bind(this);
185
200
  }
186
201
 
187
- delete(): void {
202
+ destroy(): void {
188
203
  this.stop();
189
204
  this._setDisplay(null);
190
205
  }
191
206
 
207
+ /** @deprecated Use .destroy() */
208
+ delete(): void {
209
+ this.destroy();
210
+ }
211
+
192
212
  setNeedsRedraw(reason: string): this {
193
213
  this.needsRedraw = this.needsRedraw || reason;
194
214
  return this;
@@ -277,15 +297,6 @@ export default class AnimationLoop {
277
297
  // clear needsRedraw flag
278
298
  this._clearNeedsRedraw();
279
299
 
280
- // Offscreen Canvas Support: Commit the frame
281
- // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit
282
- // Chrome's offscreen canvas does not require gl.commit
283
- // @ts-expect-error gl.commit is not officially part of WebGLRenderingContext
284
- if (this.offScreen && this.gl.commit) {
285
- // @ts-expect-error gl.commit is not officially part of WebGLRenderingContext
286
- this.gl.commit();
287
- }
288
-
289
300
  if (this._resolveNextFrame) {
290
301
  this._resolveNextFrame(this);
291
302
  this._nextFramePromise = null;
@@ -338,49 +349,45 @@ export default class AnimationLoop {
338
349
  return this.gl.canvas.toDataURL();
339
350
  }
340
351
 
341
- isContextLost() {
352
+ isContextLost(): boolean {
342
353
  return this.gl.isContextLost();
343
354
  }
344
355
 
345
- onCreateContext(...args) {
346
- // @ts-expect-error
347
- return this.props.onCreateContext(...args);
356
+ onCreateDevice(deviceProps: DeviceProps) {
357
+ return this.props.onCreateDevice(deviceProps);
348
358
  }
349
359
 
350
- onInitialize(...args) {
351
- // @ts-expect-error
352
- return this.props.onInitialize(...args);
360
+ onInitialize(animationProps: AnimationProps): {} | void {
361
+ return this.props.onInitialize(animationProps);
353
362
  }
354
363
 
355
- onRender(...args) {
356
- // @ts-expect-error
357
- return this.props.onRender(...args);
364
+ onRender(animationProps: AnimationProps) {
365
+ return this.props.onRender(animationProps);
358
366
  }
359
367
 
360
- onFinalize(...args) {
361
- // @ts-expect-error
362
- return this.props.onFinalize(...args);
368
+ onFinalize(animationProps: AnimationProps) {
369
+ return this.props.onFinalize(animationProps);
363
370
  }
364
371
 
365
372
  // DEPRECATED/REMOVED METHODS
366
373
 
374
+ /** @deprecated Use .onCreateDevice() */
375
+ onCreateContext(props: ContextProps) {
376
+ return this.props.onCreateContext(props);
377
+ }
378
+
379
+ /** @deprecated */
367
380
  getHTMLControlValue(id, defaultValue = 1) {
368
381
  const element = document.getElementById(id);
369
- // @ts-ignore Not all html elements have value
382
+ // @ts-expect-error Not all html elements have value
370
383
  return element ? Number(element.value) : defaultValue;
371
384
  }
372
385
 
373
- // Update parameters
374
- setViewParameters() {
375
- log.removed('AnimationLoop.setViewParameters', 'AnimationLoop.setProps')();
376
- return this;
377
- }
378
-
379
386
  // PRIVATE METHODS
380
387
 
381
- _initialize(opts) {
388
+ _initialize(props: AnimationLoopProps) {
382
389
  // Create the WebGL context
383
- this._createWebGLContext(opts);
390
+ this._createDevice(props);
384
391
  this._createFramebuffer();
385
392
  this._startEventHandling();
386
393
 
@@ -465,15 +472,15 @@ export default class AnimationLoop {
465
472
 
466
473
  // Called on each frame, can be overridden to call onRender multiple times
467
474
  // to support e.g. stereoscopic rendering
468
- _renderFrame(...args) {
475
+ _renderFrame(props: AnimationProps) {
469
476
  // Allow e.g. VR display to render multiple frames.
470
477
  if (this.display) {
471
- this.display._renderFrame(...args);
478
+ this.display._renderFrame(props);
472
479
  return;
473
480
  }
474
481
 
475
482
  // call callback
476
- this.onRender(...args);
483
+ this.onRender(props);
477
484
  // end callback
478
485
  }
479
486
 
@@ -491,11 +498,11 @@ export default class AnimationLoop {
491
498
  _initializeCallbackData() {
492
499
  // @ts-expect-error
493
500
  this.animationProps = {
501
+ device: this.device,
494
502
  gl: this.gl,
495
503
 
496
504
  stop: this.stop,
497
505
  canvas: this.gl.canvas,
498
- framebuffer: this.framebuffer,
499
506
 
500
507
  // Initial values
501
508
  useDevicePixels: this.props.useDevicePixels,
@@ -507,14 +514,20 @@ export default class AnimationLoop {
507
514
  tick: 0,
508
515
  tock: 0,
509
516
 
517
+ timeline: this.timeline,
518
+ animationLoop: this,
519
+
510
520
  // Timeline time for back compatibility
511
521
  time: 0,
512
522
 
513
523
  // Experimental
524
+ _mousePosition: null, // Event props
525
+
526
+ // Deprecated
527
+ framebuffer: this.framebuffer,
514
528
  _timeline: this.timeline,
515
529
  _loop: this,
516
- _animationLoop: this,
517
- _mousePosition: null // Event props
530
+ _animationLoop: this
518
531
  };
519
532
  }
520
533
 
@@ -548,9 +561,6 @@ export default class AnimationLoop {
548
561
  this.animationProps.time = this.timeline
549
562
  ? this.timeline.getTime()
550
563
  : this.animationProps.engineTime;
551
-
552
- // experimental
553
- this.animationProps._offScreen = this.offScreen;
554
564
  }
555
565
 
556
566
  _finalizeCallbackData() {
@@ -559,23 +569,24 @@ export default class AnimationLoop {
559
569
  // end callback
560
570
  }
561
571
 
562
- // Add application's data to the app context object
572
+ /** Add application's data to the app context object */
563
573
  _addCallbackData(appContext) {
564
574
  if (typeof appContext === 'object' && appContext !== null) {
565
575
  this.animationProps = Object.assign({}, this.animationProps, appContext);
566
576
  }
567
577
  }
568
578
 
569
- // Either uses supplied or existing context, or calls provided callback to create one
570
- _createWebGLContext(opts) {
571
- this.offScreen =
572
- opts.canvas &&
573
- typeof OffscreenCanvas !== 'undefined' &&
574
- opts.canvas instanceof OffscreenCanvas;
579
+ /** Either uses supplied or existing context, or calls provided callback to create one */
580
+ _createDevice(props: DeviceProps) {
581
+ const deviceProps = {...this.props, ...props, ...this.props.glOptions};
575
582
 
583
+ // TODO - support this.onCreateContext
576
584
  // Create the WebGL context if necessary
577
- opts = Object.assign({}, opts, this.props.glOptions);
578
- this.gl = this.props.gl ? instrumentGLContext(this.props.gl, opts) : this.onCreateContext(opts);
585
+ // this.gl = this.props.gl ? instrumentGLContext(this.props.gl, deviceProps) : this.onCreateContext(deviceProps);
586
+
587
+ this.device = this.onCreateDevice(deviceProps);
588
+ // @ts-expect-error
589
+ this.gl = this.device.gl;
579
590
 
580
591
  if (!isWebGL(this.gl)) {
581
592
  throw new Error('AnimationLoop.onCreateContext - illegal context returned');
@@ -625,35 +636,20 @@ export default class AnimationLoop {
625
636
  return {width, height, aspect};
626
637
  }
627
638
 
628
- // Default viewport setup
639
+ /** Default viewport setup */
629
640
  _resizeViewport() {
630
641
  if (this.props.autoResizeViewport) {
631
642
  this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight);
632
643
  }
633
644
  }
634
645
 
635
- // Resize the render buffer of the canvas to match canvas client size
636
- // Optionally multiplying with devicePixel ratio
646
+ /**
647
+ * Resize the render buffer of the canvas to match canvas client size
648
+ * Optionally multiplying with devicePixel ratio
649
+ */
637
650
  _resizeCanvasDrawingBuffer() {
638
651
  if (this.props.autoResizeDrawingBuffer) {
639
- resizeGLContext(this.gl, {useDevicePixels: this.props.useDevicePixels});
640
- }
641
- }
642
-
643
- // TBD - deprecated?
644
- _createFramebuffer() {
645
- // Setup default framebuffer
646
- if (this.props.createFramebuffer) {
647
- this.framebuffer = new Framebuffer(this.gl);
648
- }
649
- }
650
-
651
- _resizeFramebuffer() {
652
- if (this.framebuffer) {
653
- this.framebuffer.resize({
654
- width: this.gl.drawingBufferWidth,
655
- height: this.gl.drawingBufferHeight
656
- });
652
+ (this.device as WebGLDevice).resize({useDevicePixels: this.props.useDevicePixels});
657
653
  }
658
654
  }
659
655
 
@@ -705,4 +701,24 @@ export default class AnimationLoop {
705
701
  _onMouseleave(e) {
706
702
  this.animationProps._mousePosition = null;
707
703
  }
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
+ }
708
724
  }
package/src/lib/model.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // luma.gl, MIT license
2
+ import {Device} from '@luma.gl/api';
2
3
  import GL from '@luma.gl/constants';
3
- import {isWebGL} from '@luma.gl/gltools';
4
- import {ProgramProps} from '@luma.gl/webgl';
4
+ import type {ProgramProps} from '@luma.gl/webgl';
5
5
  import {
6
- Shader,
6
+ WebGLDevice,
7
7
  Program,
8
8
  VertexArray,
9
9
  clear,
@@ -31,9 +31,22 @@ const NOOP = () => {};
31
31
  const DRAW_PARAMS = {};
32
32
 
33
33
  export type ModelProps = ProgramProps & {
34
- id?: string
34
+ id?: string;
35
+
36
+ // program props
37
+ // vs,
38
+ // fs,
39
+ // varyings,
40
+ // bufferMode,
41
+
42
+ program?: Program;
43
+ modules?: any[];
44
+ defines?: Record<string, number | boolean>;
45
+ inject?: Record<string, any>;
46
+ transpileToGLSL100?: boolean;
47
+
35
48
  moduleSettings?: object; // UniformsOptions
36
- attributes?: object,
49
+ attributes?: object;
37
50
  uniforms?: object; // Uniforms
38
51
  geometry?: object; // Geometry
39
52
  vertexCount?: number
@@ -50,8 +63,12 @@ export type ModelProps = ProgramProps & {
50
63
  indexType?;
51
64
  indexOffset?: number;
52
65
  vertexArrayInstanced?: boolean;
66
+
67
+ /** @deprecated Use isInstanced */
68
+ instanced?: boolean
53
69
  };
54
70
 
71
+
55
72
  export type ModelDrawOptions = {
56
73
  moduleSettings?;
57
74
  framebuffer?;
@@ -102,8 +119,10 @@ interface TransformOpts extends DrawOpts {
102
119
  */
103
120
 
104
121
  export default class Model {
105
- readonly id: string;
122
+ readonly device: Device;
106
123
  readonly gl: WebGLRenderingContext;
124
+
125
+ readonly id: string;
107
126
  readonly animated: boolean = false;
108
127
  programManager: ProgramManager;
109
128
  vertexCount: number;
@@ -136,20 +155,24 @@ export default class Model {
136
155
  // TODO - just to unbreak deck.gl 7.0-beta, remove as soon as updated
137
156
  geometry = {};
138
157
 
139
- constructor(gl, props: ModelProps = {}) {
158
+ constructor(device: Device, props?: ModelProps);
159
+ /* @deprecated */
160
+ constructor(gl: WebGLRenderingContext, props?: ModelProps);
161
+ constructor(device, props: ModelProps = {}) {
140
162
  // Deduce a helpful id
141
163
  const {id = uid('model')} = props;
142
- assert(isWebGL(gl));
143
164
  this.id = id;
144
- this.gl = gl;
165
+ const webglDevice = WebGLDevice.attach(device);
166
+ this.device = webglDevice;
167
+ this.gl = webglDevice.gl;
145
168
  this.id = props.id || uid('Model');
146
169
  this.initialize(props);
147
170
  }
148
171
 
149
- initialize(props) {
172
+ initialize(props: ModelProps) {
150
173
  this.props = {};
151
174
 
152
- this.programManager = props.programManager || ProgramManager.getDefaultProgramManager(this.gl);
175
+ this.programManager = props.programManager || ProgramManager.getDefaultProgramManager(this.device);
153
176
  this._programManagerState = -1;
154
177
  this._managedProgram = false;
155
178
 
@@ -226,7 +249,7 @@ export default class Model {
226
249
  this._setModelProps(props);
227
250
  }
228
251
 
229
- delete() {
252
+ destroy(): void {
230
253
  // delete all attributes created by this model
231
254
  // TODO - should buffer deletes be handled by vertex array?
232
255
  for (const key in this._attributes) {
@@ -245,6 +268,11 @@ export default class Model {
245
268
  this._deleteGeometryBuffers();
246
269
  }
247
270
 
271
+ /** @deprecated Use .destroy() */
272
+ delete(): void {
273
+ this.destroy();
274
+ }
275
+
248
276
  // GETTERS
249
277
 
250
278
  getDrawMode() {
@@ -542,7 +570,6 @@ export default class Model {
542
570
  this.program = program;
543
571
 
544
572
  if (this.vertexArray) {
545
- // @ts-ignore TODO
546
573
  this.vertexArray.setProps({program: this.program, attributes: this.vertexArray.attributes});
547
574
  } else {
548
575
  this.vertexArray = new VertexArray(this.gl, {program: this.program});
@@ -618,7 +645,7 @@ export default class Model {
618
645
  const attributeTable = getDebugTableForVertexArray({
619
646
  vertexArray,
620
647
  header: `${this.id} attributes`,
621
- // @ts-ignore
648
+ // @ts-expect-error
622
649
  attributes: this._attributes
623
650
  });
624
651
 
@@ -661,6 +688,6 @@ export default class Model {
661
688
  framebuffer.log({logLevel: LOG_DRAW_PRIORITY, message: `Rendered to ${framebuffer.id}`});
662
689
  }
663
690
 
664
- log.groupEnd(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`)();
691
+ log.groupEnd(LOG_DRAW_PRIORITY)();
665
692
  }
666
693
  }