[core] Convert style properties to a tuple-based approach
This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md. The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily. Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state.
This commit is contained in:
@@ -21,7 +21,7 @@ void Painter::renderLine(PaintParameters& parameters,
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& properties = layer.impl->paint;
|
||||
const LinePaintProperties::Evaluated& properties = layer.impl->paint.evaluated;
|
||||
|
||||
auto draw = [&] (auto& program, auto&& uniformValues) {
|
||||
program.draw(
|
||||
@@ -37,11 +37,11 @@ void Painter::renderLine(PaintParameters& parameters,
|
||||
);
|
||||
};
|
||||
|
||||
if (!properties.lineDasharray.value.from.empty()) {
|
||||
const LinePatternCap cap = bucket.layout.lineCap == LineCapType::Round
|
||||
if (!properties.get<LineDasharray>().from.empty()) {
|
||||
const LinePatternCap cap = bucket.layout.get<LineCap>() == LineCapType::Round
|
||||
? LinePatternCap::Round : LinePatternCap::Square;
|
||||
LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, cap);
|
||||
LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, cap);
|
||||
LinePatternPos posA = lineAtlas->getDashPosition(properties.get<LineDasharray>().from, cap);
|
||||
LinePatternPos posB = lineAtlas->getDashPosition(properties.get<LineDasharray>().to, cap);
|
||||
|
||||
lineAtlas->bind(context, 0);
|
||||
|
||||
@@ -56,11 +56,11 @@ void Painter::renderLine(PaintParameters& parameters,
|
||||
layer.impl->dashLineWidth,
|
||||
lineAtlas->getSize().width));
|
||||
|
||||
} else if (!properties.linePattern.value.from.empty()) {
|
||||
} else if (!properties.get<LinePattern>().from.empty()) {
|
||||
optional<SpriteAtlasPosition> posA = spriteAtlas->getPosition(
|
||||
properties.linePattern.value.from, SpritePatternMode::Repeating);
|
||||
properties.get<LinePattern>().from, SpritePatternMode::Repeating);
|
||||
optional<SpriteAtlasPosition> posB = spriteAtlas->getPosition(
|
||||
properties.linePattern.value.to, SpritePatternMode::Repeating);
|
||||
properties.get<LinePattern>().to, SpritePatternMode::Repeating);
|
||||
|
||||
if (!posA || !posB)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user