support dash arrays that are any length

This commit is contained in:
Ansis Brammanis
2015-01-14 22:24:44 -05:00
parent 84e9dbdc09
commit 2c615b613c
9 changed files with 32 additions and 17 deletions

View File

@@ -17,7 +17,7 @@ LineAtlas::LineAtlas(uint16_t w, uint16_t h)
LineAtlas::~LineAtlas() {
}
LinePatternPos LineAtlas::getDashPosition(std::vector<float> &dasharray, bool round) {
LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round) {
std::ostringstream sskey;
for (const float &part : dasharray) {
@@ -34,7 +34,7 @@ LinePatternPos LineAtlas::getDashPosition(std::vector<float> &dasharray, bool ro
return positions[key];
}
LinePatternPos LineAtlas::addDash(std::vector<float> &dasharray, bool round) {
LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round) {
int n = round ? 7 : 0;
int dashheight = 2 * n + 1;

View File

@@ -21,8 +21,8 @@ public:
void bind();
LinePatternPos getDashPosition(std::vector<float>&, bool);
LinePatternPos addDash(std::vector<float> &dasharray, bool round);
LinePatternPos getDashPosition(const std::vector<float>&, bool);
LinePatternPos addDash(const std::vector<float> &dasharray, bool round);
const int width;
const int height;

View File

@@ -70,7 +70,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
bucket.drawPoints(*linejoinShader);
}
if (properties.dash_array.size() && properties.dash_array[1] > 0) {
if (properties.dash_array.size()) {
useProgram(linesdfShader->program);
@@ -81,8 +81,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
linesdfShader->u_blur = blur;
linesdfShader->u_color = color;
std::vector<float> dash = { properties.dash_array[0], properties.dash_array[1] };
LinePatternPos pos = lineAtlas.getDashPosition(dash, false);
LinePatternPos pos = lineAtlas.getDashPosition(properties.dash_array, false);
lineAtlas.bind();
float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0;

View File

@@ -20,8 +20,6 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::LineWidth, defaultStyleProperties<LineProperties>().width },
{ PropertyKey::LineGapWidth, defaultStyleProperties<LineProperties>().gap_width },
{ PropertyKey::LineBlur, defaultStyleProperties<LineProperties>().blur },
{ PropertyKey::LineDashLand, defaultStyleProperties<LineProperties>().dash_array[0] },
{ PropertyKey::LineDashGap, defaultStyleProperties<LineProperties>().dash_array[1] },
{ PropertyKey::IconOpacity, defaultStyleProperties<SymbolProperties>().icon.opacity },
{ PropertyKey::IconRotate, defaultStyleProperties<SymbolProperties>().icon.rotate },

View File

@@ -24,8 +24,6 @@ enum class PropertyKey {
LineGapWidth,
LineBlur,
LineDashArray, // for transitions only
LineDashLand,
LineDashGap,
LineImage,
IconOpacity,

View File

@@ -5,6 +5,8 @@
#include <mbgl/style/function_properties.hpp>
#include <mbgl/style/types.hpp>
#include <vector>
namespace mbgl {
typedef mapbox::util::variant<
@@ -13,7 +15,8 @@ typedef mapbox::util::variant<
RotateAnchorType,
Function<bool>,
Function<float>,
Function<Color>
Function<Color>,
std::vector<float>
> PropertyValue;
}

View File

@@ -185,8 +185,7 @@ void StyleLayer::applyStyleProperties<LineProperties>(const float z, const times
applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now);
applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now);
applyTransitionedStyleProperty(PropertyKey::LineBlur, line.blur, z, now);
applyTransitionedStyleProperty(PropertyKey::LineDashLand, line.dash_array[0], z, now);
applyTransitionedStyleProperty(PropertyKey::LineDashGap, line.dash_array[1], z, now);
applyStyleProperty(PropertyKey::LineDashArray, line.dash_array, z, now);
applyStyleProperty(PropertyKey::LineImage, line.image, z, now);
// for scaling dasharrays

View File

@@ -332,6 +332,24 @@ template<> std::tuple<bool, std::string> StyleParser::parseProperty(JSVal value,
return std::tuple<bool, std::string> { true, { value.GetString(), value.GetStringLength() } };
}
template<> std::tuple<bool, std::vector<float>> StyleParser::parseProperty(JSVal value, const char *property_name) {
if (!value.IsArray()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be an array", property_name);
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
}
std::vector<float> vec;
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
JSVal part = value[i];
if (!part.IsNumber()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", property_name);
return std::tuple<bool, std::vector<float>> { false, std::vector<float>() };
}
vec.push_back(part.GetDouble());
}
return std::tuple<bool, std::vector<float>> { true, vec };
}
template<> std::tuple<bool, TranslateAnchorType> StyleParser::parseProperty(JSVal value, const char *property_name) {
if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
@@ -567,8 +585,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<PropertyTransition>("line-gap-width-transition", Key::LineGapWidth, klass, value);
parseOptionalProperty<Function<float>>("line-blur", Key::LineBlur, klass, value);
parseOptionalProperty<PropertyTransition>("line-blur-transition", Key::LineBlur, klass, value);
parseOptionalProperty<Function<float>>("line-dasharray", { Key::LineDashLand, Key::LineDashGap }, klass, value);
parseOptionalProperty<PropertyTransition>("line-dasharray-transition", Key::LineDashArray, klass, value);
parseOptionalProperty<std::vector<float>>("line-dasharray", Key::LineDashArray, klass, value);
parseOptionalProperty<std::string>("line-image", Key::LineImage, klass, value);
parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value);

View File

@@ -9,6 +9,7 @@
#include <string>
#include <type_traits>
#include <memory>
#include <vector>
namespace mbgl {
@@ -36,7 +37,7 @@ struct LineProperties {
float width = 1;
float gap_width = 0;
float blur = 0;
std::array<float, 2> dash_array = {{ 1, -1 }};
std::vector<float> dash_array;
float dash_line_width = 1;
std::string image;