Skip to content

Commit

Permalink
modify file names
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Li <[email protected]>
  • Loading branch information
lixun910 committed Nov 2, 2023
1 parent 27d0043 commit b76ae9b
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/deckgl-layers/src/deckgl-extensions/filter-arrow-layer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {Layer, LayerExtension} from '@deck.gl/core';
import {LayerContext} from '@deck.gl/core/lib/layer';
import GL from '@luma.gl/constants';

import shaderModule from './filter-shader-module';

const VALUE_FILTERED = 1;

const defaultProps = {
getFiltered: {type: 'accessor', value: VALUE_FILTERED}
};

export type FilterArrowExtensionProps = {
getFiltered?: () => number;
};

/**
* FilterArrowExtension - a deck.gl extension to filter arrow layer
*
* A simple extension to filter arrow layer based on the result of CPU filteredIndex,
* so we can avoid filtering on the raw Arrow table and recreating geometry attributes.
* Specifically, an attribute `filtered` is added to the layer to indicate whether the feature has been Filtered
* the shader module is modified to discard the feature if filtered value is 0
* the accessor getFiltered is used to get the value of `filtered` based on the value `filteredIndex` in Arrowlayer
*/
export default class FilterArrowExtension extends LayerExtension {
static defaultProps = defaultProps;
static extensionName = 'FilterArrowExtension';

getShaders(extension: any) {
return {
modules: [shaderModule],
defines: {}
};
}

initializeState(this: Layer<FilterArrowExtensionProps>, context: LayerContext, extension: this) {
const attributeManager = this.getAttributeManager();
if (attributeManager) {
attributeManager.add({
filtered: {
size: 1,
type: GL.FLOAT,
accessor: 'getFiltered',
shaderAttributes: {
filtered: {
divisor: 0
},
instanceFiltered: {
divisor: 1
}
}
}
});
}
}
}
39 changes: 39 additions & 0 deletions src/deckgl-layers/src/deckgl-extensions/filter-shader-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {project} from '@deck.gl/core';

const vs = `
#ifdef NON_INSTANCED_MODEL
#define FILTER_ARROW_ATTRIB filtered
#else
#define FILTER_ARROW_ATTRIB instanceFiltered
#endif
attribute float FILTER_ARROW_ATTRIB;
`;

const fs = ``;

const inject = {
'vs:#decl': `
varying float is_filtered;
`,
'vs:#main-end': `
is_filtered = FILTER_ARROW_ATTRIB;
`,
'fs:#decl': `
varying float is_filtered;
`,
'fs:DECKGL_FILTER_COLOR': `
// abandon the fragments if it is not filtered
if (is_filtered == 0.) {
discard;
}
`
};

export default {
name: 'filter-arrow',
dependencies: [project],
vs: vs,
fs: fs,
inject: inject,
getUniforms: () => {}
};
Loading

0 comments on commit b76ae9b

Please sign in to comment.