Skip to content

Commit

Permalink
Merge fa401c2 into ec86cc3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Oct 3, 2019
2 parents ec86cc3 + fa401c2 commit ce9228d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 19 deletions.
37 changes: 36 additions & 1 deletion docs/api-reference/deck.md
Expand Up @@ -49,7 +49,42 @@ The array of deck.gl layers to be rendered. This array is expected to be an arra

##### `layerFilter` (Function)

Optionally takes a function `({layer, viewport, isPicking}) => Boolean` that is called before a layer is rendered. Gives the application an opportunity to filter out layers from the layer list during either rendering or picking. Filtering can be done per viewport or per layer or both. This enables techniques like adding helper layers that work as masks during picking but do not show up during rendering. All the lifecycle methods are still triggered even a if a layer is filtered out using this prop.
Default: `null`

If supplied, will be called before a layer is drawn to determine whether it should be rendered. This gives the application an opportunity to filter out layers from the layer list during either rendering or picking. Filtering can be done per viewport or per layer or both. This enables techniques like adding helper layers that work as masks during picking but do not show up during rendering.

```js
new Deck({
// ...
layerFilter: ({layer, viewport}) => {
if (viewport.id !== 'minimap' && layer.id === 'geofence') {
// only display geofence in the minimap
return false;
}
return true;
}
}
```
Notes:
- `layerFilter` does not override the visibility defined by the layer's `visible` and `pickable` props.
- All the lifecycle methods are still triggered even a if a layer is filtered out using this prop.
Arguments:
- `layer` (Layer) - the layer to be drawn
- `viewport` (Viewport) - the current viewport
- `isPicking` (Boolean) - whether this is a picking pass
- `renderPass` (String) - the name of the current render pass. Some standard passes are:
+ `'screen'` - drawing to screen
+ `'picking:hover'` - drawing to offscreen picking buffer due to pointer move
+ `'picking:query'` - drawing to offscreen picking buffer due to user-initiated query, e.g. calling `deck.pickObject`.
+ `'shadow'` - drawing to shadow map
Returns:
`true` if the layer should be drawn.
##### `getCursor` (Function)
Expand Down
2 changes: 1 addition & 1 deletion examples/layer-browser/src/map.js
Expand Up @@ -135,7 +135,7 @@ export default class Map extends PureComponent {
}

// Only show infovis layers in infovis mode and vice versa
_layerFilter({layer}) {
_layerFilter({layer, renderPass}) {
const {settings} = this.props;
const isIdentity = layer.props.coordinateSystem === COORDINATE_SYSTEM.IDENTITY;
return settings.infovis ? isIdentity : !isIdentity;
Expand Down
5 changes: 3 additions & 2 deletions modules/core/src/effects/lighting/lighting-effect.js
Expand Up @@ -57,7 +57,7 @@ export default class LightingEffect extends Effect {
this.shadow = this.directionalLights.some(light => light.shadow);
}

prepare(gl, {layers, viewports, onViewportActive, views}) {
prepare(gl, {layers, layerFilter, viewports, onViewportActive, views}) {
if (!this.shadow) return {};

// create light matrix every frame to make sure always updated from light source
Expand Down Expand Up @@ -86,7 +86,8 @@ export default class LightingEffect extends Effect {
for (let i = 0; i < this.shadowPasses.length; i++) {
const shadowPass = this.shadowPasses[i];
shadowPass.render({
layers: layers.filter(layer => layer.props.shadowEnabled !== false),
layers,
layerFilter,
viewports,
onViewportActive,
views,
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/lib/deck-picker.js
Expand Up @@ -162,6 +162,7 @@ export default class DeckPicker {
viewports,
onViewportActive,
deviceRect,
pass: `picking:${mode}`,
redrawReason: mode
});

Expand All @@ -181,6 +182,7 @@ export default class DeckPicker {
viewports,
onViewportActive,
deviceRect: {x: pickInfo.pickedX, y: pickInfo.pickedY, width: 1, height: 1},
pass: `picking:${mode}`,
redrawReason: 'pick-z',
pickZ: true
});
Expand Down Expand Up @@ -269,6 +271,7 @@ export default class DeckPicker {
viewports,
onViewportActive,
deviceRect,
pass: `picking:${mode}`,
redrawReason: mode
});

Expand Down Expand Up @@ -300,7 +303,7 @@ export default class DeckPicker {
}

// returns pickedColor or null if no pickable layers found.
_drawAndSample({layers, viewports, onViewportActive, deviceRect, redrawReason, pickZ}) {
_drawAndSample({layers, viewports, onViewportActive, deviceRect, pass, redrawReason, pickZ}) {
assert(deviceRect);
assert(Number.isFinite(deviceRect.width) && deviceRect.width > 0, '`width` must be > 0');
assert(Number.isFinite(deviceRect.height) && deviceRect.height > 0, '`height` must be > 0');
Expand All @@ -322,6 +325,7 @@ export default class DeckPicker {
onViewportActive,
pickingFBO,
deviceRect,
pass,
redrawReason,
effectProps,
pickZ
Expand Down
2 changes: 2 additions & 0 deletions modules/core/src/lib/deck-renderer.js
Expand Up @@ -46,6 +46,7 @@ export default class DeckRenderer {
const layerPass = this.drawPickingColors ? this.pickLayersPass : this.drawLayersPass;
const effectProps = this._prepareEffects({
layers,
layerFilter: this.layerFilter,
viewports,
onViewportActive,
views,
Expand All @@ -61,6 +62,7 @@ export default class DeckRenderer {
viewports,
views,
onViewportActive,
pass,
redrawReason,
clearCanvas,
effects,
Expand Down
15 changes: 10 additions & 5 deletions modules/core/src/passes/layers-pass.js
Expand Up @@ -44,7 +44,7 @@ export default class LayersPass extends Pass {
// intersect with the picking rect
drawLayersInViewport(
gl,
{layers, layerFilter, viewport, view, parameters, pass = 'draw', effects, effectProps}
{layers, layerFilter, viewport, view, parameters, pass = 'unknown', effects, effectProps}
) {
const glViewport = getGLViewport(gl, {viewport});

Expand Down Expand Up @@ -73,7 +73,7 @@ export default class LayersPass extends Pass {
// render layers in normal colors
layers.forEach((layer, layerIndex) => {
// Check if we should draw layer
const shouldDrawLayer = this.shouldDrawLayer(layer, viewport, layerFilter);
const shouldDrawLayer = this._shouldDrawLayer(layer, viewport, pass, layerFilter);

// Calculate stats
if (shouldDrawLayer && layer.props.pickable) {
Expand Down Expand Up @@ -102,15 +102,20 @@ export default class LayersPass extends Pass {
return renderStatus;
}

shouldDrawLayer(layer, viewport, layerFilter) {
let shouldDrawLayer = !layer.isComposite && layer.props.visible;
_shouldDrawLayer(layer, viewport, pass, layerFilter) {
let shouldDrawLayer = this.shouldDrawLayer(layer) && !layer.isComposite && layer.props.visible;

if (shouldDrawLayer && layerFilter) {
shouldDrawLayer = layerFilter({layer, viewport, isPicking: false});
shouldDrawLayer = layerFilter({layer, viewport, isPicking: false, renderPass: pass});
}
return shouldDrawLayer;
}

/* Methods for subclass overrides */
shouldDrawLayer(layer) {
return true;
}

getModuleParameters(layer) {
const moduleParameters = Object.assign(Object.create(layer.props), {
viewport: layer.context.viewport,
Expand Down
12 changes: 4 additions & 8 deletions modules/core/src/passes/pick-layers-pass.js
Expand Up @@ -21,6 +21,7 @@ export default class PickLayersPass extends LayersPass {
pickingFBO,
effectProps,
deviceRect: {x, y, width, height},
pass = 'picking',
redrawReason,
pickZ
}) {
Expand Down Expand Up @@ -64,7 +65,7 @@ export default class PickLayersPass extends LayersPass {
layerFilter,
viewports,
onViewportActive,
pass: 'picking',
pass,
redrawReason,
effectProps,
parameters
Expand All @@ -74,13 +75,8 @@ export default class PickLayersPass extends LayersPass {
}

// PRIVATE
shouldDrawLayer(layer, viewport, layerFilter) {
let shouldDrawLayer = !layer.isComposite && layer.props.visible && layer.props.pickable;

if (shouldDrawLayer && layerFilter) {
shouldDrawLayer = layerFilter({layer, viewport, isPicking: true});
}
return shouldDrawLayer;
shouldDrawLayer(layer) {
return layer.props.pickable;
}

getModuleParameters(layer, effects, effectProps) {
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/passes/shadow-pass.js
Expand Up @@ -61,11 +61,15 @@ export default class ShadowPass extends LayersPass {
target.resize({width, height});
}

super.render(Object.assign(params, {outputBuffer: target}));
super.render(Object.assign(params, {outputBuffer: target, pass: 'shadow'}));
}
);
}

shouldDrawLayer(layer) {
return layer.props.shadowEnabled !== false;
}

getModuleParameters(layer, effects, effectProps) {
const moduleParameters = Object.assign(Object.create(layer.props), {
viewport: layer.context.viewport,
Expand Down

0 comments on commit ce9228d

Please sign in to comment.