summaryrefslogtreecommitdiff
path: root/src/mbgl/programs
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-30 11:06:59 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-17 15:13:38 -0800
commit38fcbe21d48186c4630a3b8a76d1b20e156faadd (patch)
tree098f73bfea98deb5202fe1c13b1277e43e322755 /src/mbgl/programs
parentd4fc66af3924805d40576989c1e139ddafcc4670 (diff)
downloadqtlocation-mapboxgl-38fcbe21d48186c4630a3b8a76d1b20e156faadd.tar.gz
[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.
Diffstat (limited to 'src/mbgl/programs')
-rw-r--r--src/mbgl/programs/line_program.cpp44
-rw-r--r--src/mbgl/programs/line_program.hpp11
2 files changed, 28 insertions, 27 deletions
diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp
index 8c35df1b6e..2cadaa6c11 100644
--- a/src/mbgl/programs/line_program.cpp
+++ b/src/mbgl/programs/line_program.cpp
@@ -8,10 +8,12 @@
namespace mbgl {
+using namespace style;
+
static_assert(sizeof(LineAttributes::Vertex) == 8, "expected LineVertex size");
template <class Values, class...Args>
-Values makeValues(const style::LinePaintProperties& properties,
+Values makeValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state,
Args&&... args) {
@@ -27,14 +29,16 @@ Values makeValues(const style::LinePaintProperties& properties,
float x = state.getSize().height / 2.0f * std::tan(state.getPitch());
return Values {
- uniforms::u_matrix::Value{ tile.translatedMatrix(properties.lineTranslate.value,
- properties.lineTranslateAnchor.value,
- state) },
- uniforms::u_opacity::Value{ properties.lineOpacity.value },
- uniforms::u_width::Value{ properties.lineWidth.value },
- uniforms::u_gapwidth::Value{ properties.lineGapWidth.value },
- uniforms::u_blur::Value{ properties.lineBlur.value },
- uniforms::u_offset::Value{ properties.lineOffset.value },
+ uniforms::u_matrix::Value{
+ tile.translatedMatrix(properties.get<LineTranslate>(),
+ properties.get<LineTranslateAnchor>(),
+ state)
+ },
+ uniforms::u_opacity::Value{ properties.get<LineOpacity>() },
+ uniforms::u_width::Value{ properties.get<LineWidth>() },
+ uniforms::u_gapwidth::Value{ properties.get<LineGapWidth>() },
+ uniforms::u_blur::Value{ properties.get<LineBlur>() },
+ uniforms::u_offset::Value{ properties.get<LineOffset>() },
uniforms::u_antialiasingmatrix::Value{ antialiasingMatrix },
uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
uniforms::u_extra::Value{ (topedgelength + x) / topedgelength - 1.0f },
@@ -43,19 +47,19 @@ Values makeValues(const style::LinePaintProperties& properties,
}
LineProgram::UniformValues
-LineProgram::uniformValues(const style::LinePaintProperties& properties,
+LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state) {
return makeValues<LineProgram::UniformValues>(
properties,
tile,
state,
- uniforms::u_color::Value{ properties.lineColor.value }
+ uniforms::u_color::Value{ properties.get<LineColor>() }
);
}
LineSDFProgram::UniformValues
-LineSDFProgram::uniformValues(const style::LinePaintProperties& properties,
+LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
float pixelRatio,
const RenderTile& tile,
const TransformState& state,
@@ -63,8 +67,8 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties,
const LinePatternPos& posB,
float dashLineWidth,
float atlasWidth) {
- const float widthA = posA.width * properties.lineDasharray.value.fromScale * dashLineWidth;
- const float widthB = posB.width * properties.lineDasharray.value.toScale * dashLineWidth;
+ const float widthA = posA.width * properties.get<LineDasharray>().fromScale * dashLineWidth;
+ const float widthB = posB.width * properties.get<LineDasharray>().toScale * dashLineWidth;
std::array<float, 2> scaleA {{
1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()),
@@ -80,30 +84,30 @@ LineSDFProgram::uniformValues(const style::LinePaintProperties& properties,
properties,
tile,
state,
- uniforms::u_color::Value{ properties.lineColor.value },
+ uniforms::u_color::Value{ properties.get<LineColor>() },
uniforms::u_patternscale_a::Value{ scaleA },
uniforms::u_patternscale_b::Value{ scaleB },
uniforms::u_tex_y_a::Value{ posA.y },
uniforms::u_tex_y_b::Value{ posB.y },
- uniforms::u_mix::Value{ properties.lineDasharray.value.t },
+ uniforms::u_mix::Value{ properties.get<LineDasharray>().t },
uniforms::u_sdfgamma::Value{ atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f },
uniforms::u_image::Value{ 0 }
);
}
LinePatternProgram::UniformValues
-LinePatternProgram::uniformValues(const style::LinePaintProperties& properties,
+LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state,
const SpriteAtlasPosition& posA,
const SpriteAtlasPosition& posB) {
std::array<float, 2> sizeA {{
- tile.id.pixelsToTileUnits(posA.size[0] * properties.linePattern.value.fromScale, state.getIntegerZoom()),
+ tile.id.pixelsToTileUnits(posA.size[0] * properties.get<LinePattern>().fromScale, state.getIntegerZoom()),
posA.size[1]
}};
std::array<float, 2> sizeB {{
- tile.id.pixelsToTileUnits(posB.size[0] * properties.linePattern.value.toScale, state.getIntegerZoom()),
+ tile.id.pixelsToTileUnits(posB.size[0] * properties.get<LinePattern>().toScale, state.getIntegerZoom()),
posB.size[1]
}};
@@ -117,7 +121,7 @@ LinePatternProgram::uniformValues(const style::LinePaintProperties& properties,
uniforms::u_pattern_br_b::Value{ posB.br },
uniforms::u_pattern_size_a::Value{ sizeA },
uniforms::u_pattern_size_b::Value{ sizeB },
- uniforms::u_fade::Value{ properties.linePattern.value.t },
+ uniforms::u_fade::Value{ properties.get<LinePattern>().t },
uniforms::u_image::Value{ 0 }
);
}
diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp
index de3297de96..059806ffb2 100644
--- a/src/mbgl/programs/line_program.hpp
+++ b/src/mbgl/programs/line_program.hpp
@@ -6,16 +6,13 @@
#include <mbgl/shader/line.hpp>
#include <mbgl/shader/line_pattern.hpp>
#include <mbgl/shader/line_sdf.hpp>
+#include <mbgl/style/layers/line_layer_properties.hpp>
#include <mbgl/util/geometry.hpp>
#include <cmath>
namespace mbgl {
-namespace style {
-class LinePaintProperties;
-} // namespace style
-
class RenderTile;
class TransformState;
class LinePatternPos;
@@ -104,7 +101,7 @@ class LineProgram : public Program<
public:
using Program::Program;
- static UniformValues uniformValues(const style::LinePaintProperties&,
+ static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
const RenderTile&,
const TransformState&);
};
@@ -135,7 +132,7 @@ class LinePatternProgram : public Program<
public:
using Program::Program;
- static UniformValues uniformValues(const style::LinePaintProperties&,
+ static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
const RenderTile&,
const TransformState&,
const SpriteAtlasPosition& posA,
@@ -168,7 +165,7 @@ class LineSDFProgram : public Program<
public:
using Program::Program;
- static UniformValues uniformValues(const style::LinePaintProperties&,
+ static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
float pixelRatio,
const RenderTile&,
const TransformState&,