Skip to content

Commit

Permalink
derive paint attribute names from properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Nov 5, 2016
1 parent 19f4f05 commit c04f3e7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
8 changes: 4 additions & 4 deletions js/data/bucket/circle_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const circleInterface = {
elementArrayType: createElementArrayType(),

paintAttributes: [
{name: 'a_color', paintProperty: 'circle-color', type: 'Uint8'},
{name: 'a_radius', paintProperty: 'circle-radius', type: 'Uint16', multiplier: 10},
{name: 'a_blur', paintProperty: 'circle-blur', type: 'Uint16', multiplier: 10},
{name: 'a_opacity', paintProperty: 'circle-opacity', type: 'Uint8', multiplier: 255}
{property: 'circle-color', type: 'Uint8'},
{property: 'circle-radius', type: 'Uint16', multiplier: 10},
{property: 'circle-blur', type: 'Uint16', multiplier: 10},
{property: 'circle-opacity', type: 'Uint8', multiplier: 255}
]
};

Expand Down
6 changes: 3 additions & 3 deletions js/data/bucket/fill_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const fillInterface = {
elementArrayType2: createElementArrayType(2),

paintAttributes: [
{name: 'a_color', paintProperty: 'fill-color', type: 'Uint8'},
{name: 'a_outline_color', paintProperty: 'fill-outline-color', type: 'Uint8'},
{name: 'a_opacity', paintProperty: 'fill-opacity', type: 'Uint8', multiplier: 255}
{property: 'fill-color', type: 'Uint8'},
{property: 'fill-outline-color', type: 'Uint8'},
{property: 'fill-opacity', type: 'Uint8', multiplier: 255}
]
};

Expand Down
6 changes: 3 additions & 3 deletions js/data/bucket/fill_extrusion_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const fillExtrusionInterface = {
elementArrayType: createElementArrayType(3),

paintAttributes: [
{name: 'a_base', paintProperty: 'fill-extrusion-base', type: 'Uint16'},
{name: 'a_height', paintProperty: 'fill-extrusion-height', type: 'Uint16'},
{name: 'a_color', paintProperty: 'fill-extrusion-color', type: 'Uint8'}
{property: 'fill-extrusion-base', type: 'Uint16'},
{property: 'fill-extrusion-height', type: 'Uint16'},
{property: 'fill-extrusion-color', type: 'Uint8'}
]
};

Expand Down
2 changes: 1 addition & 1 deletion js/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const lineInterface = {
{name: 'a_data', components: 4, type: 'Uint8'}
]),
paintAttributes: [
{name: 'a_color', paintProperty: 'line-color', type: 'Uint8'}
{property: 'line-color', type: 'Uint8'}
],
elementArrayType: createElementArrayType()
};
Expand Down
28 changes: 14 additions & 14 deletions js/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const createVertexArrayType = require('./vertex_array_type');
const util = require('../util/util');
const assert = require('assert');

/**
* ProgramConfiguration contains the logic for binding style layer properties and tile
Expand Down Expand Up @@ -34,14 +33,12 @@ class ProgramConfiguration {
const self = new ProgramConfiguration();

for (const attributeConfig of attributes) {

const attribute = normalizeAttribute(attributeConfig, layer);
assert(attribute.name.indexOf('a_') === 0);
const attribute = normalizePaintAttribute(attributeConfig, layer);
const name = attribute.name.slice(2);

if (layer.isPaintValueFeatureConstant(attribute.paintProperty)) {
if (layer.isPaintValueFeatureConstant(attribute.property)) {
self.addZoomDrivenAttribute(name, attribute);
} else if (layer.isPaintValueZoomConstant(attribute.paintProperty)) {
} else if (layer.isPaintValueZoomConstant(attribute.property)) {
self.addDataDrivenAttribute(name, attribute);
} else {
self.addDataAndZoomDrivenAttribute(name, attribute, layer, zoom);
Expand Down Expand Up @@ -102,7 +99,7 @@ class ProgramConfiguration {

// Pick the index of the first offset to add to the buffers.
let numStops = 0;
const zoomLevels = layer.getPaintValueStopZoomLevels(attribute.paintProperty);
const zoomLevels = layer.getPaintValueStopZoomLevels(attribute.property);
while (numStops < zoomLevels.length && zoomLevels[numStops] < zoom) numStops++;
const stopOffset = Math.max(0, Math.min(zoomLevels.length - 4, numStops - 2));

Expand All @@ -111,7 +108,7 @@ class ProgramConfiguration {
vert.define.push(`uniform lowp float ${tName};`);
this.interpolationUniforms.push({
name: tName,
paintProperty: attribute.paintProperty,
property: attribute.property,
stopOffset
});

Expand Down Expand Up @@ -166,10 +163,10 @@ class ProgramConfiguration {
let value;
if (attribute.zoomStops) {
// add one multi-component value like color0, or pack multiple single-component values into a four component attribute
const values = attribute.zoomStops.map((zoom) => layer.getPaintValue(attribute.paintProperty, util.extend({}, globalProperties, {zoom}), featureProperties));
const values = attribute.zoomStops.map((zoom) => layer.getPaintValue(attribute.property, util.extend({}, globalProperties, {zoom}), featureProperties));
value = values.length === 1 ? values[0] : values;
} else {
value = layer.getPaintValue(attribute.paintProperty, globalProperties, featureProperties);
value = layer.getPaintValue(attribute.property, globalProperties, featureProperties);
}

for (let i = start; i < length; i++) {
Expand All @@ -191,7 +188,7 @@ class ProgramConfiguration {

setUniforms(gl, program, layer, globalProperties) {
for (const uniform of this.uniforms) {
const value = layer.getPaintValue(uniform.paintProperty, globalProperties);
const value = layer.getPaintValue(uniform.property, globalProperties);
if (uniform.components === 4) {
gl.uniform4fv(program[uniform.name], value);
} else {
Expand All @@ -201,17 +198,20 @@ class ProgramConfiguration {
for (const uniform of this.interpolationUniforms) {
// stopInterp indicates which stops need to be interpolated.
// If stopInterp is 3.5 then interpolate half way between stops 3 and 4.
const stopInterp = layer.getPaintInterpolationT(uniform.paintProperty, globalProperties);
const stopInterp = layer.getPaintInterpolationT(uniform.property, globalProperties);
// We can only store four stop values in the buffers. stopOffset is the number of stops that come
// before the stops that were added to the buffers.
gl.uniform1f(program[uniform.name], Math.max(0, Math.min(4, stopInterp - uniform.stopOffset)));
}
}
}

function normalizeAttribute(attribute, layer) {
const isColor = layer._paintSpecifications[attribute.paintProperty].type === 'color';
function normalizePaintAttribute(attribute, layer) {
const name = attribute.property.replace(`${layer.type}-`, '').replace(/-/g, '_');
const isColor = layer._paintSpecifications[attribute.property].type === 'color';

return util.extend({
name: `a_${name}`,
components: isColor ? 4 : 1,
multiplier: isColor ? 255 : 1
}, attribute);
Expand Down
16 changes: 7 additions & 9 deletions test/js/data/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ test('Bucket', (t) => {
elementArrayType2: createElementArrayType(2),

paintAttributes: options.paintAttributes || [{
name: 'a_map',
type: 'Int16',
paintProperty: 'circle-opacity'
property: 'circle-opacity',
type: 'Int16'
}]
};

Expand Down Expand Up @@ -96,7 +95,7 @@ test('Bucket', (t) => {
const paintVertex = bucket.arrays.layerData.layerid.paintVertexArray;
t.equal(paintVertex.length, 1);
const p0 = paintVertex.get(0);
t.equal(p0.a_map, 17);
t.equal(p0.a_opacity, 17);

const testElement = bucket.arrays.elementArray;
t.equal(testElement.length, 1);
Expand Down Expand Up @@ -125,8 +124,8 @@ test('Bucket', (t) => {
const v0 = bucket.arrays.layoutVertexArray.get(0);
const a0 = bucket.arrays.layerData.one.paintVertexArray.get(0);
const b0 = bucket.arrays.layerData.two.paintVertexArray.get(0);
t.equal(a0.a_map, 17);
t.equal(b0.a_map, 17);
t.equal(a0.a_opacity, 17);
t.equal(b0.a_opacity, 17);
t.equal(v0.a_box0, 34);
t.equal(v0.a_box1, 84);

Expand All @@ -136,9 +135,8 @@ test('Bucket', (t) => {
t.test('add features, disabled attribute', (t) => {
const bucket = create({
paintAttributes: [{
name: 'a_map',
type: 'Int16',
paintProperty: 'circle-opacity'
property: 'circle-opacity',
type: 'Int16'
}],
layoutAttributes: [],
layers: [
Expand Down

0 comments on commit c04f3e7

Please sign in to comment.