@deck.gl/arcgis 9.0.0-beta.6 → 9.0.0-beta.8

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/src/commons.ts CHANGED
@@ -2,13 +2,28 @@
2
2
 
3
3
  import type {Device} from '@luma.gl/core';
4
4
  import {Model} from '@luma.gl/engine';
5
- import {GL} from '@luma.gl/constants';
6
-
7
5
  import {Deck} from '@deck.gl/core';
6
+ import {WebGLDevice} from '@luma.gl/webgl';
8
7
 
9
8
  export function initializeResources(device: Device) {
10
- // What is `this` referring to this function???
11
- this.buffer = device.createBuffer(new Int8Array([-1, -1, 1, -1, -1, 1, 1, 1]));
9
+ // 'this' refers to the BaseLayerViewGL2D class from
10
+ // import BaseLayerViewGL2D from "@arcgis/core/views/2d/layers/BaseLayerViewGL2D.js";
11
+
12
+ const deckglTexture = device.createTexture({
13
+ format: 'rgba8unorm',
14
+ width: 1,
15
+ height: 1,
16
+ sampler: {
17
+ minFilter: 'linear',
18
+ magFilter: 'linear',
19
+ addressModeU: 'clamp-to-edge',
20
+ addressModeV: 'clamp-to-edge'
21
+ }
22
+ });
23
+
24
+ this.deckglTexture = deckglTexture;
25
+
26
+ this.buffer = device.createBuffer(new Int8Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1]));
12
27
 
13
28
  this.model = new Model(device, {
14
29
  vs: `\
@@ -23,24 +38,38 @@ void main(void) {
23
38
  fs: `\
24
39
  #version 300 es
25
40
  precision mediump float;
26
- uniform sampler2D u_texture;
41
+ uniform sampler2D deckglTexture;
27
42
  in vec2 v_texcoord;
28
43
  out vec4 fragColor;
44
+
29
45
  void main(void) {
30
- vec4 rgba = texture(u_texture, v_texcoord);
31
- rgba.rgb *= rgba.a;
32
- fragColor = rgba;
46
+ vec4 imageColor = texture(deckglTexture, v_texcoord);
47
+ imageColor.rgb *= imageColor.a;
48
+ fragColor = imageColor;
33
49
  }
34
50
  `,
51
+ bufferLayout: [{name: 'a_pos', format: 'sint8x2'}],
52
+ bindings: {
53
+ deckglTexture
54
+ },
55
+ parameters: {
56
+ depthWriteEnabled: true,
57
+ depthCompare: 'less-equal'
58
+ },
35
59
  attributes: {
36
60
  // eslint-disable-next-line camelcase
37
61
  a_pos: this.buffer
38
62
  },
39
- vertexCount: 4,
40
- drawMode: GL.TRIANGLE_STRIP
63
+ vertexCount: 6,
64
+ topology: 'triangle-strip'
41
65
  });
42
66
 
43
- this.deckFbo = device.createFramebuffer({width: 1, height: 1});
67
+ this.deckFbo = device.createFramebuffer({
68
+ id: 'deckfbo',
69
+ width: 1,
70
+ height: 1,
71
+ colorAttachments: [deckglTexture]
72
+ });
44
73
 
45
74
  this.deckInstance = new Deck({
46
75
  // The view state will be set dynamically to track the MapView current extent.
@@ -50,7 +79,7 @@ void main(void) {
50
79
  controller: false,
51
80
 
52
81
  // We use the same WebGL context as the ArcGIS API for JavaScript.
53
- gl: device.gl,
82
+ gl: (device as WebGLDevice).gl,
54
83
 
55
84
  // We need depth testing in general; we don't know what layers might be added to the deck.
56
85
  parameters: {
@@ -89,17 +118,25 @@ export function render({gl, width, height, viewState}) {
89
118
  this.deckInstance.redraw('arcgis');
90
119
 
91
120
  // We overlay the texture on top of the map using the full-screen quad.
92
- const device: Device = this.deckInstance.deck.device;
121
+ const device: WebGLDevice = this.deckInstance.device;
122
+
123
+ const textureToScreenPass = device.beginRenderPass({
124
+ framebuffer: screenFbo,
125
+ parameters: {viewport: [0, 0, width, height]},
126
+ clearColor: [0, 0, 0, 0],
127
+ clearDepth: 1
128
+ });
129
+
93
130
  device.withParametersWebGL(
94
131
  {
95
132
  blend: true,
96
- blendFunc: [gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
97
- framebuffer: screenFbo,
98
- viewport: [0, 0, width, height]
133
+ blendFunc: [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]
99
134
  },
100
135
  () => {
101
- // eslint-disable-next-line camelcase
102
- this.model.setUniforms({u_texture: this.deckFbo}).draw(this.context.renderPass);
136
+ this.model.setBindings({
137
+ deckglTexture: this.deckFbo.colorAttachments[0]
138
+ });
139
+ this.model.draw(textureToScreenPass);
103
140
  }
104
141
  );
105
142
  }
@@ -111,4 +148,5 @@ export function finalizeResources() {
111
148
  this.model?.delete();
112
149
  this.buffer?.delete();
113
150
  this.deckFbo?.delete();
151
+ this.deckglTexture?.delete();
114
152
  }
@@ -1,3 +1,4 @@
1
+ import {WebGLDevice} from '@luma.gl/webgl';
1
2
  import {initializeResources, render, finalizeResources} from './commons';
2
3
 
3
4
  export default function createDeckLayerView2D(BaseLayerViewGL2D) {
@@ -14,7 +15,9 @@ export default function createDeckLayerView2D(BaseLayerViewGL2D) {
14
15
  // We use a full-screen quad and shaders to composite the frame rendered
15
16
  // with deck.gl on top of the MapView. Composition uses the MapView context.
16
17
  const gl = this.context;
17
- initializeResources.call(this, gl);
18
+ const device = WebGLDevice.attach(gl);
19
+
20
+ initializeResources.call(this, device);
18
21
 
19
22
  // Update deck props
20
23
  this.layer.deck.on('change', props => this.deckInstance.setProps(props));