@deck.gl/arcgis 9.0.3 → 9.0.5

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/commons.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Model } from '@luma.gl/engine';
2
2
  import { Deck } from '@deck.gl/core';
3
- import type { Device, Texture, Framebuffer } from '@luma.gl/core';
3
+ import type { Texture, Framebuffer } from '@luma.gl/core';
4
4
  interface Renderer {
5
5
  redraw: () => void;
6
6
  }
@@ -10,7 +10,7 @@ export type RenderResources = {
10
10
  model: Model;
11
11
  fbo: Framebuffer;
12
12
  };
13
- export declare function initializeResources(this: Renderer, device: Device): RenderResources;
13
+ export declare function initializeResources(this: Renderer, gl: WebGL2RenderingContext): Promise<RenderResources>;
14
14
  export declare function render(resources: RenderResources, viewport: {
15
15
  width: number;
16
16
  height: number;
@@ -1 +1 @@
1
- {"version":3,"file":"commons.d.ts","sourceRoot":"","sources":["../src/commons.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAW,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAGhE,UAAU,QAAQ;IAChB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CA2FnF;AAED,wBAAgB,MAAM,CACpB,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE;IACR,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE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-2,7 +2,30 @@
2
2
  import { GL } from '@luma.gl/constants';
3
3
  import { Model, Geometry } from '@luma.gl/engine';
4
4
  import { Deck } from '@deck.gl/core';
5
- export function initializeResources(device) {
5
+ async function createDeckInstance(gl) {
6
+ return new Promise(resolve => {
7
+ const deckInstance = new Deck({
8
+ // The view state will be set dynamically to track the MapView current extent.
9
+ viewState: {},
10
+ // Input is handled by the ArcGIS API for JavaScript.
11
+ controller: false,
12
+ // We use the same WebGL context as the ArcGIS API for JavaScript.
13
+ gl,
14
+ // We need depth testing in general; we don't know what layers might be added to the deck.
15
+ parameters: {
16
+ depthCompare: 'less-equal'
17
+ },
18
+ // To disable canvas resizing, since the FBO is owned by the ArcGIS API for JavaScript.
19
+ width: null,
20
+ height: null,
21
+ onDeviceInitialized: (device) => {
22
+ resolve({ deckInstance, device });
23
+ }
24
+ });
25
+ });
26
+ }
27
+ export async function initializeResources(gl) {
28
+ const { deckInstance, device } = await createDeckInstance(gl);
6
29
  const texture = device.createTexture({
7
30
  format: 'rgba8unorm',
8
31
  width: 1,
@@ -42,7 +65,13 @@ void main(void) {
42
65
  },
43
66
  parameters: {
44
67
  depthWriteEnabled: true,
45
- depthCompare: 'less-equal'
68
+ depthCompare: 'less-equal',
69
+ blendColorSrcFactor: 'one',
70
+ blendColorDstFactor: 'one-minus-src-alpha',
71
+ blendAlphaSrcFactor: 'one',
72
+ blendAlphaDstFactor: 'one-minus-src-alpha',
73
+ blendColorOperation: 'add',
74
+ blendAlphaOperation: 'add'
46
75
  },
47
76
  geometry: new Geometry({
48
77
  topology: 'triangle-strip',
@@ -56,24 +85,12 @@ void main(void) {
56
85
  id: 'deckfbo',
57
86
  width: 1,
58
87
  height: 1,
59
- colorAttachments: [texture]
88
+ colorAttachments: [texture],
89
+ depthStencilAttachment: 'depth16unorm'
60
90
  });
61
- const deckInstance = new Deck({
62
- // The view state will be set dynamically to track the MapView current extent.
63
- viewState: {},
64
- // Input is handled by the ArcGIS API for JavaScript.
65
- controller: false,
66
- // We use the same WebGL context as the ArcGIS API for JavaScript.
67
- device,
68
- // We need depth testing in general; we don't know what layers might be added to the deck.
69
- parameters: {
70
- depthTest: true
71
- },
91
+ deckInstance.setProps({
72
92
  // This deck renders into an auxiliary framebuffer.
73
93
  _framebuffer: fbo,
74
- // To disable canvas resizing, since the FBO is owned by the ArcGIS API for JavaScript.
75
- width: null,
76
- height: null,
77
94
  _customRender: redrawReason => {
78
95
  if (redrawReason === 'arcgis') {
79
96
  deckInstance._drawLayers(redrawReason);
@@ -88,6 +105,7 @@ void main(void) {
88
105
  export function render(resources, viewport) {
89
106
  const { model, deck, fbo } = resources;
90
107
  const device = model.device;
108
+ // @ts-ignore device.getParametersWebGL should return `any` not `void`?
91
109
  const screenFbo = device.getParametersWebGL(36006);
92
110
  const { width, height, ...viewState } = viewport;
93
111
  /* global window */
@@ -102,15 +120,15 @@ export function render(resources, viewport) {
102
120
  const textureToScreenPass = device.beginRenderPass({
103
121
  framebuffer: screenFbo,
104
122
  parameters: { viewport: [0, 0, pixelWidth, pixelHeight] },
105
- clearColor: [0, 0, 0, 0],
106
- clearDepth: 1
123
+ clearColor: false,
124
+ clearDepth: false
107
125
  });
108
- device.withParametersWebGL({
109
- blend: true,
110
- blendFunc: [1, 771]
111
- }, () => {
126
+ try {
112
127
  model.draw(textureToScreenPass);
113
- });
128
+ }
129
+ finally {
130
+ textureToScreenPass.end();
131
+ }
114
132
  }
115
133
  export function finalizeResources(resources) {
116
134
  resources.deck.finalize();
@@ -1 +1 @@
1
- {"version":3,"file":"deck-layer-view-2d.d.ts","sourceRoot":"","sources":["../src/deck-layer-view-2d.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,iBAAiB,KAAA,OAiD9D"}
1
+ {"version":3,"file":"deck-layer-view-2d.d.ts","sourceRoot":"","sources":["../src/deck-layer-view-2d.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,iBAAiB,KAAA,OAgE9D"}
@@ -1,32 +1,45 @@
1
- import { WebGLDevice } from '@luma.gl/webgl';
2
1
  import { initializeResources, render, finalizeResources } from "./commons.js";
3
2
  export default function createDeckLayerView2D(BaseLayerViewGL2D) {
4
3
  return BaseLayerViewGL2D.createSubclass({
5
4
  properties: {
5
+ cancelInitialization: null,
6
6
  resources: null
7
7
  },
8
8
  // Attach is called as soon as the layer view is ready to start rendering.
9
- attach() {
9
+ async attach() {
10
10
  // We use a full-screen quad and shaders to composite the frame rendered
11
11
  // with deck.gl on top of the MapView. Composition uses the MapView context.
12
12
  const gl = this.context;
13
- const device = WebGLDevice.attach(gl);
14
- this.resources = initializeResources.call(this, device);
13
+ let cancelled = false;
14
+ this.cancelInitialization = () => (cancelled = true);
15
+ const resources = await initializeResources.call(this, gl);
16
+ // If the layer got detached while awaiting, do not proceed
17
+ if (cancelled) {
18
+ finalizeResources(resources);
19
+ return;
20
+ }
21
+ this.resources = resources;
15
22
  // Update deck props
16
- this.layer.deck.on('change', props => this.resources.deck.setProps(props));
23
+ this.layer.deck.on('change', props => resources.deck.setProps(props));
17
24
  // We need to start drawing the deck.gl layer immediately.
18
- this.resources.deck.setProps(this.layer.deck.toJSON());
25
+ resources.deck.setProps(this.layer.deck.toJSON());
19
26
  },
20
27
  redraw() {
21
28
  this.requestRender();
22
29
  },
23
30
  // Called when the layer must be destroyed.
24
31
  detach() {
25
- finalizeResources(this.resources);
26
- this.resources = null;
32
+ this.cancelInitialization?.();
33
+ if (this.resources) {
34
+ finalizeResources(this.resources);
35
+ this.resources = null;
36
+ }
27
37
  },
28
38
  // Called every time that the layer view must be rendered.
29
39
  render(renderParameters) {
40
+ if (!this.resources) {
41
+ return;
42
+ }
30
43
  const [width, height] = this.view.state.size;
31
44
  // The view state must be kept in-sync with the MapView of the ArcGIS API.
32
45
  const state = renderParameters.state;
@@ -5,7 +5,8 @@ export default function createDeckRenderer(DeckProps: any, externalRenderers: an
5
5
  view: SceneView;
6
6
  deck: any;
7
7
  resources: RenderResources | null;
8
- setup(context: any): void;
8
+ cancelInitialization: (() => void) | null;
9
+ setup(context: any): Promise<void>;
9
10
  dispose(): void;
10
11
  redraw(): void;
11
12
  render(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"deck-renderer.d.ts","sourceRoot":"","sources":["../src/deck-renderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiD,eAAe,EAAC,qBAAkB;AAE1F,OAAO,SAAS,MAAM,8BAA8B,CAAC;AAWrD,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,SAAS,KAAA,EAAE,iBAAiB,KAAA;eAMjD,SAAS,SAAS,SAAS;cAJvC,SAAS;cACT,GAAG;mBACE,eAAe,GAAG,IAAI;;;;;;EA6CpC"}
1
+ {"version":3,"file":"deck-renderer.d.ts","sourceRoot":"","sources":["../src/deck-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAiD,eAAe,EAAC,qBAAkB;AAE1F,OAAO,SAAS,MAAM,8BAA8B,CAAC;AAWrD,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,SAAS,KAAA,EAAE,iBAAiB,KAAA;eAOjD,SAAS,SAAS,SAAS;cALvC,SAAS;cACT,GAAG;mBACE,eAAe,GAAG,IAAI;8BACX,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;;;;;;EAqD5C"}
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable no-invalid-this */
2
- import { WebGLDevice } from '@luma.gl/webgl';
3
2
  import { initializeResources, render, finalizeResources } from "./commons.js";
4
3
  /** Convert ArcGIS FOV to WebMercatorViewport altitude */
5
4
  function arcgisFOVToDeckAltitude(fov, aspectRatio) {
@@ -12,18 +11,26 @@ export default function createDeckRenderer(DeckProps, externalRenderers) {
12
11
  class DeckRenderer {
13
12
  constructor(view, props) {
14
13
  this.resources = null;
14
+ this.cancelInitialization = null;
15
15
  this.view = view;
16
16
  this.deck = new DeckProps(props);
17
17
  }
18
- setup(context) {
18
+ async setup(context) {
19
19
  const gl = context.gl;
20
- const device = WebGLDevice.attach(gl);
21
- const resources = initializeResources.call(this, device);
20
+ let cancelled = false;
21
+ this.cancelInitialization = () => (cancelled = true);
22
+ const resources = await initializeResources.call(this, gl);
23
+ // If the renderer got disposed while awaiting, do not proceed
24
+ if (cancelled) {
25
+ finalizeResources(resources);
26
+ return;
27
+ }
22
28
  this.deck.on('change', props => resources.deck.setProps(props));
23
29
  resources.deck.setProps(this.deck.toJSON());
24
30
  this.resources = resources;
25
31
  }
26
32
  dispose() {
33
+ this.cancelInitialization?.();
27
34
  if (this.resources) {
28
35
  finalizeResources(this.resources);
29
36
  }