@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
@@ -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 gl: WebGLRenderingContext;
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(gl: WebGLRenderingContext): ProgramManager {
32
+ static getDefaultProgramManager(device: Device): ProgramManager {
32
33
  // @ts-expect-error
33
- gl.luma = gl.luma || {};
34
+ device.defaultProgramManager = device.defaultProgramManager || new ProgramManager(device);
34
35
  // @ts-expect-error
35
- gl.luma.defaultProgramManager = gl.luma.defaultProgramManager || new ProgramManager(gl);
36
- // @ts-expect-error
37
- return gl.luma.defaultProgramManager;
36
+ return device.defaultProgramManager;
38
37
  }
39
38
 
40
- constructor(gl: WebGLRenderingContext) {
41
- this.gl = gl;
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.gl, {
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
- this._programCache[hash] = new Program(this.gl, {
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 {isWebGL2} from '@luma.gl/gltools';
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-ignore
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-ignore TODO - uniforms is not present
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,
@@ -12,6 +12,7 @@ export type TransformProps = {
12
12
  uniforms?: any;
13
13
  parameters?: any;
14
14
  discard?: boolean;
15
+ isIndexed?: boolean;
15
16
  _sourceTextures?: any;
16
17
  _targetTexture?: any;
17
18
  _targetTextureVarying?: string;
@@ -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 {assert, isObjectEmpty} from '@luma.gl/webgl';
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
- // takes source and target buffers/textures and setsup the pipeline
12
+ /**
13
+ * Takes source and target buffers/textures and sets up the pipeline
14
+ */
13
15
  export default class Transform {
14
- static isSupported(gl: WebGLRenderingContext): boolean {
15
- // TODO : differentiate writing to buffer vs not
16
- return isWebGL2(gl);
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(gl: WebGL2RenderingContext, props: TransformProps = {}) {
27
- this.gl = gl;
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
- // Delete owned resources.
33
- delete(): void {
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
- // Run one transform loop.
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
- // swap resources if a map is provided
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
- // Return Buffer object for given varying name.
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
- // Return data either from Buffer or from Texture
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
- // Return framebuffer object if rendering to textures
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
- // Update some or all buffer/texture bindings.
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
- gl,
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
- /* eslint-disable no-unused-expressions */
122
- this.bufferTransform && this.bufferTransform.setupResources({model: this.model});
123
- /* eslint-enable no-unused-expressions */
137
+ if (this.bufferTransform) {
138
+ this.bufferTransform.setupResources({model: this.model});
139
+ }
124
140
  }
125
141
 
126
142
  _updateModelProps(props: TransformProps): TransformProps {