Skip to content

Commit

Permalink
Add deck instance to layer context (#2805)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgios-uber committed Mar 16, 2019
1 parent 963c117 commit d26e455
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api-reference/layer.md
Expand Up @@ -344,6 +344,7 @@ The context object stores information that are shared by all layers.

* `gl` ([WebGLRenderingContext](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext)) - WebGL context of the current canvas.
* `viewport` ([Viewport](/docs/api-reference/viewport.md)) - The current viewport
* `deck` ([Deck](/docs/api-reference/deck.md)) - The current deck.gl instance

##### `state` (Object)

Expand Down
1 change: 1 addition & 0 deletions modules/core/src/lib/deck.js
Expand Up @@ -528,6 +528,7 @@ export default class Deck {
const viewport = this.viewManager.getViewports()[0];
// Note: avoid React setState due GL animation loop / setState timing issue
this.layerManager = new LayerManager(gl, {
deck: this,
stats: this.stats,
viewport
});
Expand Down
5 changes: 3 additions & 2 deletions modules/core/src/lib/layer-manager.js
Expand Up @@ -43,6 +43,7 @@ const LOG_PRIORITY_LIFECYCLE_MINOR = 4;
// CONTEXT IS EXPOSED TO LAYERS
const INITIAL_CONTEXT = Object.seal({
layerManager: null,
deck: null,
gl: null,

// Settings
Expand All @@ -64,7 +65,7 @@ const layerName = layer => (layer instanceof Layer ? `${layer}` : !layer ? 'null

export default class LayerManager {
// eslint-disable-next-line
constructor(gl, {stats, viewport = null} = {}) {
constructor(gl, {deck, stats, viewport = null} = {}) {
// Currently deck.gl expects the DeckGL.layers array to be different
// whenever React rerenders. If the same layers array is used, the
// LayerManager's diffing algorithm will generate a fatal error and
Expand All @@ -79,7 +80,7 @@ export default class LayerManager {

this.context = Object.assign({}, INITIAL_CONTEXT, {
layerManager: this,

deck,
gl,
// Enabling luma.gl Program caching using private API (_cachePrograms)
shaderCache: gl && new ShaderCache({gl, _cachePrograms: true}),
Expand Down

0 comments on commit d26e455

Please sign in to comment.