Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dedup featureMap by moving it to the ProgramConfigurationSet #8965

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,11 @@ export default class ProgramConfiguration {
layoutAttributes: Array<StructArrayMember>;

_buffers: Array<VertexBuffer>;
_featureMap: FeaturePositionMap;
_bufferOffset: number;

constructor() {
this.binders = {};
this.cacheKey = '';
this._buffers = [];
this._featureMap = new FeaturePositionMap();
this._bufferOffset = 0;
}

static createDynamic<Layer: TypedStyleLayer>(layer: Layer, zoom: number, filterProperties: (string) => boolean) {
Expand Down Expand Up @@ -617,10 +613,6 @@ export default class ProgramConfiguration {
const binder = this.binders[property];
binder.populatePaintArray(newLength, feature, imagePositions, formattedSection);
}
if (feature.id !== undefined) {
this._featureMap.add(+feature.id, index, this._bufferOffset, newLength);
}
this._bufferOffset = newLength;
}
setConstantPatternPositions(posTo: ImagePosition, posFrom: ImagePosition) {
for (const property in this.binders) {
Expand All @@ -629,10 +621,10 @@ export default class ProgramConfiguration {
}
}

updatePaintArrays(featureStates: FeatureStates, vtLayer: VectorTileLayer, layer: TypedStyleLayer, imagePositions: {[string]: ImagePosition}): boolean {
updatePaintArrays(featureStates: FeatureStates, featureMap: FeaturePositionMap, vtLayer: VectorTileLayer, layer: TypedStyleLayer, imagePositions: {[string]: ImagePosition}): boolean {
let dirty: boolean = false;
for (const id in featureStates) {
const positions = this._featureMap.getPositions(+id);
const positions = featureMap.getPositions(+id);

for (const pos of positions) {
const feature = vtLayer.feature(pos.index);
Expand Down Expand Up @@ -734,6 +726,8 @@ export default class ProgramConfiguration {
export class ProgramConfigurationSet<Layer: TypedStyleLayer> {
programConfigurations: {[string]: ProgramConfiguration};
needsUpload: boolean;
_featureMap: FeaturePositionMap;
_bufferOffset: number;

constructor(layoutAttributes: Array<StructArrayMember>, layers: $ReadOnlyArray<Layer>, zoom: number, filterProperties: (string) => boolean = () => true) {
this.programConfigurations = {};
Expand All @@ -742,18 +736,26 @@ export class ProgramConfigurationSet<Layer: TypedStyleLayer> {
this.programConfigurations[layer.id].layoutAttributes = layoutAttributes;
}
this.needsUpload = false;
this._featureMap = new FeaturePositionMap();
this._bufferOffset = 0;
}

populatePaintArrays(length: number, feature: Feature, index: number, imagePositions: {[string]: ImagePosition}, formattedSection?: FormattedSection) {
for (const key in this.programConfigurations) {
this.programConfigurations[key].populatePaintArrays(length, feature, index, imagePositions, formattedSection);
}

if (feature.id !== undefined) {
this._featureMap.add(+feature.id, index, this._bufferOffset, length);
}
this._bufferOffset = length;

this.needsUpload = true;
}

updatePaintArrays(featureStates: FeatureStates, vtLayer: VectorTileLayer, layers: $ReadOnlyArray<TypedStyleLayer>, imagePositions: {[string]: ImagePosition}) {
for (const layer of layers) {
this.needsUpload = this.programConfigurations[layer.id].updatePaintArrays(featureStates, vtLayer, layer, imagePositions) || this.needsUpload;
this.needsUpload = this.programConfigurations[layer.id].updatePaintArrays(featureStates, this._featureMap, vtLayer, layer, imagePositions) || this.needsUpload;
}
}

Expand Down