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

Encapsulate SymbolBucket's unique requirements #3478

Merged
merged 2 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
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
40 changes: 24 additions & 16 deletions js/data/array_group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('../util/util');
const ProgramConfiguration = require('./program_configuration');

class Segment {
constructor(vertexOffset, primitiveOffset) {
Expand Down Expand Up @@ -31,7 +32,9 @@ class Segment {
* @private
*/
class ArrayGroup {
constructor(programInterface, programConfigurations) {
constructor(programInterface, layers, zoom) {
this.globalProperties = {zoom};

const LayoutVertexArrayType = programInterface.layoutVertexArrayType;
this.layoutVertexArray = new LayoutVertexArrayType();

Expand All @@ -41,12 +44,17 @@ class ArrayGroup {
const ElementArrayType2 = programInterface.elementArrayType2;
if (ElementArrayType2) this.elementArray2 = new ElementArrayType2();

this.paintVertexArrays = util.mapObject(programConfigurations, (programConfiguration) => {
this.layerData = {};
for (const layer of layers) {
const programConfiguration = ProgramConfiguration.createDynamic(
programInterface.paintAttributes || [], layer, zoom);
const PaintVertexArrayType = programConfiguration.paintVertexArrayType();
const paintVertexArray = new PaintVertexArrayType();
paintVertexArray.programConfiguration = programConfiguration;
return paintVertexArray;
});
this.layerData[layer.id] = {
layer: layer,
programConfiguration: programConfiguration,
paintVertexArray: new PaintVertexArrayType()
};
}

this.segments = [];
this.segments2 = [];
Expand All @@ -70,14 +78,14 @@ class ArrayGroup {
return segment;
}

populatePaintArrays(layers, globalProperties, featureProperties) {
for (const layer of layers) {
const paintArray = this.paintVertexArrays[layer.id];
paintArray.programConfiguration.populatePaintArray(
layer,
paintArray,
populatePaintArrays(featureProperties) {
for (const key in this.layerData) {
const layerData = this.layerData[key];
layerData.programConfiguration.populatePaintArray(
layerData.layer,
layerData.paintVertexArray,
this.layoutVertexArray.length,
globalProperties,
this.globalProperties,
featureProperties);
}
}
Expand All @@ -91,10 +99,10 @@ class ArrayGroup {
layoutVertexArray: this.layoutVertexArray.serialize(transferables),
elementArray: this.elementArray && this.elementArray.serialize(transferables),
elementArray2: this.elementArray2 && this.elementArray2.serialize(transferables),
paintVertexArrays: util.mapObject(this.paintVertexArrays, (array) => {
paintVertexArrays: util.mapObject(this.layerData, (layerData) => {
return {
array: array.serialize(transferables),
type: array.constructor.serialize()
array: layerData.paintVertexArray.serialize(transferables),
type: layerData.paintVertexArray.constructor.serialize()
};
}),
segments: this.segments,
Expand Down
52 changes: 8 additions & 44 deletions js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

const ArrayGroup = require('./array_group');
const BufferGroup = require('./buffer_group');
const ProgramConfiguration = require('./program_configuration');
const util = require('../util/util');

const FAKE_ZOOM_HISTORY = { lastIntegerZoom: Infinity, lastIntegerZoomTime: 0, lastZoom: 0 };

/**
* The `Bucket` class is the single point of knowledge about turning vector
* tiles into WebGL buffers.
Expand All @@ -26,31 +23,20 @@ class Bucket {
* built for this tile. This object facilitates sharing of `Buffer`s be
between `Bucket`s.
*/
constructor (options) {
constructor (options, programInterface) {
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.index = options.index;

this.programConfigurations = util.mapObject(this.programInterfaces, (programInterface) => {
const result = {};
for (const layer of this.layers) {
result[layer.id] = ProgramConfiguration.createDynamic(programInterface.paintAttributes || [], layer, options);
}
return result;
});

if (options.arrays) {
this.bufferGroups = util.mapObject(options.arrays, (arrayGroup, programName) => {
return new BufferGroup(arrayGroup, this.programInterfaces[programName]);
});
this.buffers = new BufferGroup(programInterface, options.layers, options.zoom, options.arrays);
} else {
this.arrays = new ArrayGroup(programInterface, options.layers, options.zoom);
}
}

populate(features, options) {
this.createArrays();
this.recalculateStyleLayers();

for (const feature of features) {
if (this.layers[0].filter(feature)) {
this.addFeature(feature);
Expand All @@ -59,42 +45,20 @@ class Bucket {
}
}

createArrays() {
this.arrays = {};
for (const programName in this.programInterfaces) {
this.arrays[programName] = new ArrayGroup(
this.programInterfaces[programName],
this.programConfigurations[programName]);
}
}

destroy() {
for (const programName in this.bufferGroups) {
this.bufferGroups[programName].destroy();
}
}

isEmpty() {
for (const programName in this.arrays) {
if (!this.arrays[programName].isEmpty()) {
return false;
}
}
return true;
return this.arrays.isEmpty();
}

serialize(transferables) {
return {
zoom: this.zoom,
layerIds: this.layers.map((l) => l.id),
arrays: util.mapObject(this.arrays, (a) => a.serialize(transferables))
arrays: this.arrays.serialize(transferables)
};
}

recalculateStyleLayers() {
for (const layer of this.layers) {
layer.recalculate(this.zoom, FAKE_ZOOM_HISTORY);
}
destroy() {
this.buffers.destroy();
}
}

Expand Down
107 changes: 52 additions & 55 deletions js/data/bucket/circle_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,54 @@ const ElementArrayType = require('../element_array_type');
const loadGeometry = require('../load_geometry');
const EXTENT = require('../extent');

const circleInterfaces = {
circle: {
layoutVertexArrayType: new VertexArrayType([{
name: 'a_pos',
components: 2,
type: 'Int16'
}]),
elementArrayType: new ElementArrayType(),

paintAttributes: [{
name: 'a_color',
components: 4,
type: 'Uint8',
getValue: (layer, globalProperties, featureProperties) => {
return layer.getPaintValue("circle-color", globalProperties, featureProperties);
},
multiplier: 255,
paintProperty: 'circle-color'
}, {
name: 'a_radius',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-radius", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'circle-radius'
}, {
name: 'a_blur',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-blur", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'circle-blur'
}, {
name: 'a_opacity',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-opacity", globalProperties, featureProperties)];
},
multiplier: 255,
paintProperty: 'circle-opacity'
}]
}
const circleInterface = {
layoutVertexArrayType: new VertexArrayType([{
name: 'a_pos',
components: 2,
type: 'Int16'
}]),
elementArrayType: new ElementArrayType(),

paintAttributes: [{
name: 'a_color',
components: 4,
type: 'Uint8',
getValue: (layer, globalProperties, featureProperties) => {
return layer.getPaintValue("circle-color", globalProperties, featureProperties);
},
multiplier: 255,
paintProperty: 'circle-color'
}, {
name: 'a_radius',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-radius", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'circle-radius'
}, {
name: 'a_blur',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-blur", globalProperties, featureProperties)];
},
multiplier: 10,
paintProperty: 'circle-blur'
}, {
name: 'a_opacity',
components: 1,
type: 'Uint16',
isLayerConstant: false,
getValue: (layer, globalProperties, featureProperties) => {
return [layer.getPaintValue("circle-opacity", globalProperties, featureProperties)];
},
multiplier: 255,
paintProperty: 'circle-opacity'
}]
};

function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
Expand All @@ -72,13 +70,12 @@ function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
* @private
*/
class CircleBucket extends Bucket {

get programInterfaces() {
return circleInterfaces;
constructor(options) {
super(options, circleInterface);
}

addFeature(feature) {
const arrays = this.arrays.circle;
const arrays = this.arrays;

for (const ring of loadGeometry(feature)) {
for (const point of ring) {
Expand Down Expand Up @@ -113,7 +110,7 @@ class CircleBucket extends Bucket {
}
}

arrays.populatePaintArrays(this.layers, {zoom: this.zoom}, feature.properties);
arrays.populatePaintArrays(feature.properties);
}
}

Expand Down
Loading