Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Add support for circle-pitch-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jul 7, 2016
1 parent c8e8712 commit c09fb0f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ auto makePaintPropertySetters() {
result["circle-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleOpacity);
result["circle-translate"] = makePropertySetter<V>(&CircleLayer::setCircleTranslate);
result["circle-translate-anchor"] = makePropertySetter<V>(&CircleLayer::setCircleTranslateAnchor);
result["circle-pitch-scale"] = makePropertySetter<V>(&CircleLayer::setCirclePitchScale);

result["raster-opacity"] = makePropertySetter<V>(&RasterLayer::setRasterOpacity);
result["raster-hue-rotate"] = makePropertySetter<V>(&RasterLayer::setRasterHueRotate);
Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class CircleLayer : public Layer {
PropertyValue<TranslateAnchorType> getCircleTranslateAnchor() const;
void setCircleTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {});

PropertyValue<CirclePitchScaleType> getCirclePitchScale() const;
void setCirclePitchScale(PropertyValue<CirclePitchScaleType>, const optional<std::string>& klass = {});

// Private implementation

class Impl;
Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/style/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ enum class RotateAnchorType : bool {
Viewport,
};

enum class CirclePitchScaleType : bool {
Map,
Viewport,
};

enum class SymbolPlacementType : bool {
Point,
Line,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"csscolorparser": "^1.0.2",
"ejs": "^2.4.1",
"express": "^4.11.1",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#d3a10d1a46b99d3da264cf2d1903cbde6fea3185",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#194fc55b6a7dd54c1e2cf2dd9048fbb5e836716d",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#725bd7410b612d5ddba918f6da82045e3340644e",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#4d1f89514bf03536c8e682439df165c33a37122a",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#83b1a3e5837d785af582efd5ed1a212f2df6a4ae",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#d4c5c157397a2df619ba1eecf69a08b34159b3e1",
"node-gyp": "^3.3.1",
"request": "^2.72.0",
"tape": "^4.5.1"
Expand Down
16 changes: 12 additions & 4 deletions src/mbgl/renderer/painter_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ void Painter::renderCircle(CircleBucket& bucket,
config.program = circleShader.getID();

circleShader.u_matrix = vtxMatrix;
circleShader->u_extrude_scale = {{
pixelsToGLUnits[0] * state.getAltitude(),
pixelsToGLUnits[1] * state.getAltitude()
}};

if (properties.circlePitchScale == CirclePitchScaleType::Map) {
circleShader.u_extrude_scale = {{
pixelsToGLUnits[0] * state.getAltitude(),
pixelsToGLUnits[1] * state.getAltitude()
}};
circleShader.u_scale_with_map = true;
} else {
circleShader.u_extrude_scale = pixelsToGLUnits;
circleShader.u_scale_with_map = false;
}

circleShader.u_devicepixelratio = frame.pixelRatio;
circleShader.u_color = properties.circleColor;
circleShader.u_radius = properties.circleRadius;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/shader/circle_shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CircleShader : public Shader {
Uniform<GLfloat> u_radius = {"u_radius", *this};
Uniform<GLfloat> u_blur = {"u_blur", *this};
Uniform<GLfloat> u_opacity = {"u_opacity", *this};
Uniform<GLint> u_scale_with_map = {"u_scale_with_map", *this};
};

} // namespace mbgl
8 changes: 8 additions & 0 deletions src/mbgl/style/layers/circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,13 @@ void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> va
impl->paint.circleTranslateAnchor.set(value, klass);
}

PropertyValue<CirclePitchScaleType> CircleLayer::getCirclePitchScale() const {
return impl->paint.circlePitchScale.get();
}

void CircleLayer::setCirclePitchScale(PropertyValue<CirclePitchScaleType> value, const optional<std::string>& klass) {
impl->paint.circlePitchScale.set(value, klass);
}

} // namespace style
} // namespace mbgl
2 changes: 2 additions & 0 deletions src/mbgl/style/layers/circle_layer_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void CirclePaintProperties::cascade(const CascadeParameters& parameters) {
circleOpacity.cascade(parameters);
circleTranslate.cascade(parameters);
circleTranslateAnchor.cascade(parameters);
circlePitchScale.cascade(parameters);
}

bool CirclePaintProperties::recalculate(const CalculationParameters& parameters) {
Expand All @@ -23,6 +24,7 @@ bool CirclePaintProperties::recalculate(const CalculationParameters& parameters)
hasTransitions |= circleOpacity.calculate(parameters);
hasTransitions |= circleTranslate.calculate(parameters);
hasTransitions |= circleTranslateAnchor.calculate(parameters);
hasTransitions |= circlePitchScale.calculate(parameters);

return hasTransitions;
}
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/style/layers/circle_layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CirclePaintProperties {
PaintProperty<float> circleOpacity { 1 };
PaintProperty<std::array<float, 2>> circleTranslate { {{ 0, 0 }} };
PaintProperty<TranslateAnchorType> circleTranslateAnchor { TranslateAnchorType::Map };
PaintProperty<CirclePitchScaleType> circlePitchScale { CirclePitchScaleType::Map };
};

} // namespace style
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/style/property_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ template <> std::array<float, 4> defaultStopsValue() { return {{ 0, 0, 0, 0 }};
template <> std::string defaultStopsValue() { return {}; }
template <> TranslateAnchorType defaultStopsValue() { return {}; }
template <> RotateAnchorType defaultStopsValue() { return {}; }
template <> CirclePitchScaleType defaultStopsValue() { return {}; }
template <> LineCapType defaultStopsValue() { return {}; }
template <> LineJoinType defaultStopsValue() { return {}; }
template <> SymbolPlacementType defaultStopsValue() { return {}; }
Expand Down Expand Up @@ -94,6 +95,7 @@ template class PropertyEvaluator<std::array<float, 4>>;
template class PropertyEvaluator<std::string>;
template class PropertyEvaluator<TranslateAnchorType>;
template class PropertyEvaluator<RotateAnchorType>;
template class PropertyEvaluator<CirclePitchScaleType>;
template class PropertyEvaluator<LineCapType>;
template class PropertyEvaluator<LineJoinType>;
template class PropertyEvaluator<SymbolPlacementType>;
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/style/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ MBGL_DEFINE_ENUM(RotateAnchorType, {
{ RotateAnchorType::Viewport, "viewport" },
});

MBGL_DEFINE_ENUM(CirclePitchScaleType, {
{ CirclePitchScaleType::Map, "map" },
{ CirclePitchScaleType::Viewport, "viewport" },
});

MBGL_DEFINE_ENUM(LineCapType, {
{ LineCapType::Round, "round" },
{ LineCapType::Butt, "butt" },
Expand Down

0 comments on commit c09fb0f

Please sign in to comment.