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

Commit

Permalink
[core] Render fill-extrusion layers (#8431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick authored Apr 27, 2017
1 parent 839ad87 commit f6e79d7
Show file tree
Hide file tree
Showing 111 changed files with 4,855 additions and 235 deletions.
25 changes: 21 additions & 4 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ set(MBGL_CORE_FILES
src/mbgl/programs/collision_box_program.cpp
src/mbgl/programs/collision_box_program.hpp
src/mbgl/programs/debug_program.hpp
src/mbgl/programs/extrusion_texture_program.cpp
src/mbgl/programs/extrusion_texture_program.hpp
src/mbgl/programs/fill_extrusion_program.cpp
src/mbgl/programs/fill_extrusion_program.hpp
src/mbgl/programs/fill_program.cpp
src/mbgl/programs/fill_program.hpp
src/mbgl/programs/line_program.cpp
Expand All @@ -162,6 +166,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/debug_bucket.hpp
src/mbgl/renderer/fill_bucket.cpp
src/mbgl/renderer/fill_bucket.hpp
src/mbgl/renderer/fill_extrusion_bucket.cpp
src/mbgl/renderer/fill_extrusion_bucket.hpp
src/mbgl/renderer/frame_history.cpp
src/mbgl/renderer/frame_history.hpp
src/mbgl/renderer/group_by_layout.cpp
Expand All @@ -176,6 +182,7 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/painter_clipping.cpp
src/mbgl/renderer/painter_debug.cpp
src/mbgl/renderer/painter_fill.cpp
src/mbgl/renderer/painter_fill_extrusion.cpp
src/mbgl/renderer/painter_line.cpp
src/mbgl/renderer/painter_raster.cpp
src/mbgl/renderer/painter_symbol.cpp
Expand Down Expand Up @@ -213,8 +220,14 @@ set(MBGL_CORE_FILES
src/mbgl/shaders/collision_box.hpp
src/mbgl/shaders/debug.cpp
src/mbgl/shaders/debug.hpp
src/mbgl/shaders/extrusion_texture.cpp
src/mbgl/shaders/extrusion_texture.hpp
src/mbgl/shaders/fill.cpp
src/mbgl/shaders/fill.hpp
src/mbgl/shaders/fill_extrusion.cpp
src/mbgl/shaders/fill_extrusion.hpp
src/mbgl/shaders/fill_extrusion_pattern.cpp
src/mbgl/shaders/fill_extrusion_pattern.hpp
src/mbgl/shaders/fill_outline.cpp
src/mbgl/shaders/fill_outline.hpp
src/mbgl/shaders/fill_outline_pattern.cpp
Expand Down Expand Up @@ -270,6 +283,8 @@ set(MBGL_CORE_FILES
include/mbgl/style/image.hpp
include/mbgl/style/layer.hpp
include/mbgl/style/layer_type.hpp
include/mbgl/style/light.hpp
include/mbgl/style/position.hpp
include/mbgl/style/property_value.hpp
include/mbgl/style/query.hpp
include/mbgl/style/source.hpp
Expand All @@ -288,6 +303,7 @@ set(MBGL_CORE_FILES
src/mbgl/style/layer_impl.hpp
src/mbgl/style/layer_observer.hpp
src/mbgl/style/layout_property.hpp
src/mbgl/style/light_impl.hpp
src/mbgl/style/observer.hpp
src/mbgl/style/paint_property.hpp
src/mbgl/style/paint_property_binder.hpp
Expand All @@ -304,10 +320,9 @@ set(MBGL_CORE_FILES
src/mbgl/style/source_observer.hpp
src/mbgl/style/style.cpp
src/mbgl/style/style.hpp
src/mbgl/style/style.hpp
src/mbgl/style/style.hpp
src/mbgl/style/tile_source_impl.cpp
src/mbgl/style/tile_source_impl.hpp
src/mbgl/style/transitioning_property.hpp
src/mbgl/style/types.cpp
src/mbgl/style/update_batch.hpp
src/mbgl/style/update_parameters.hpp
Expand All @@ -320,7 +335,9 @@ set(MBGL_CORE_FILES
include/mbgl/style/conversion/geojson.hpp
include/mbgl/style/conversion/geojson_options.hpp
include/mbgl/style/conversion/layer.hpp
include/mbgl/style/conversion/light.hpp
include/mbgl/style/conversion/make_property_setters.hpp
include/mbgl/style/conversion/position.hpp
include/mbgl/style/conversion/property_setter.hpp
include/mbgl/style/conversion/property_value.hpp
include/mbgl/style/conversion/source.hpp
Expand Down Expand Up @@ -474,6 +491,7 @@ set(MBGL_CORE_FILES
include/mbgl/util/geometry.hpp
include/mbgl/util/ignore.hpp
include/mbgl/util/image.hpp
include/mbgl/util/indexed_tuple.hpp
include/mbgl/util/interpolate.hpp
include/mbgl/util/logging.hpp
include/mbgl/util/noncopyable.hpp
Expand All @@ -487,6 +505,7 @@ set(MBGL_CORE_FILES
include/mbgl/util/tileset.hpp
include/mbgl/util/timer.hpp
include/mbgl/util/traits.hpp
include/mbgl/util/type_list.hpp
include/mbgl/util/unitbezier.hpp
include/mbgl/util/util.hpp
include/mbgl/util/variant.hpp
Expand Down Expand Up @@ -514,7 +533,6 @@ set(MBGL_CORE_FILES
src/mbgl/util/http_timeout.hpp
src/mbgl/util/i18n.cpp
src/mbgl/util/i18n.hpp
src/mbgl/util/indexed_tuple.hpp
src/mbgl/util/interpolate.cpp
src/mbgl/util/intersection_tests.cpp
src/mbgl/util/intersection_tests.hpp
Expand Down Expand Up @@ -548,7 +566,6 @@ set(MBGL_CORE_FILES
src/mbgl/util/tile_cover.cpp
src/mbgl/util/tile_cover.hpp
src/mbgl/util/token.hpp
src/mbgl/util/type_list.hpp
src/mbgl/util/url.cpp
src/mbgl/util/url.hpp
src/mbgl/util/utf.hpp
Expand Down
2 changes: 2 additions & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ set(MBGL_TEST_FILES
test/style/conversion/function.test.cpp
test/style/conversion/geojson_options.test.cpp
test/style/conversion/layer.test.cpp
test/style/conversion/light.test.cpp
test/style/conversion/stringify.test.cpp

# style
Expand Down Expand Up @@ -125,6 +126,7 @@ set(MBGL_TEST_FILES
test/util/merge_lines.test.cpp
test/util/number_conversions.test.cpp
test/util/offscreen_texture.test.cpp
test/util/position.test.cpp
test/util/projection.test.cpp
test/util/run_loop.test.cpp
test/util/text_conversions.test.cpp
Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace style {
class Image;
class Source;
class Layer;
class Light;
} // namespace style

class Map : private util::noncopyable {
Expand Down Expand Up @@ -179,6 +180,10 @@ class Map : private util::noncopyable {
void removeImage(const std::string&);
const style::Image* getImage(const std::string&);

// Light
void setLight(std::unique_ptr<style::Light>);
style::Light* getLight();

// Defaults
std::string getStyleName() const;
LatLng getDefaultLatLng() const;
Expand Down
49 changes: 15 additions & 34 deletions include/mbgl/style/conversion/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/string.hpp>

#include <array>
#include <string>
Expand Down Expand Up @@ -92,45 +93,25 @@ struct Converter<Color> {
}
};

template <>
struct Converter<std::array<float, 2>> {
template <size_t N>
struct Converter<std::array<float, N>> {
template <class V>
optional<std::array<float, 2>> operator()(const V& value, Error& error) const {
if (!isArray(value) || arrayLength(value) != 2) {
error = { "value must be an array of two numbers" };
optional<std::array<float, N>> operator()(const V& value, Error& error) const {
if (!isArray(value) || arrayLength(value) != N) {
error = { "value must be an array of " + util::toString(N) + " numbers" };
return {};
}

optional<float> first = toNumber(arrayMember(value, 0));
optional<float> second = toNumber(arrayMember(value, 1));
if (!first || !second) {
error = { "value must be an array of two numbers" };
return {};
}

return std::array<float, 2> {{ *first, *second }};
}
};

template <>
struct Converter<std::array<float, 4>> {
template <class V>
optional<std::array<float, 4>> operator()(const V& value, Error& error) const {
if (!isArray(value) || arrayLength(value) != 4) {
error = { "value must be an array of four numbers" };
return {};
}

optional<float> first = toNumber(arrayMember(value, 0));
optional<float> second = toNumber(arrayMember(value, 1));
optional<float> third = toNumber(arrayMember(value, 2));
optional<float> fourth = toNumber(arrayMember(value, 3));
if (!first || !second) {
error = { "value must be an array of four numbers" };
return {};
std::array<float, N> result;
for (size_t i = 0; i < N; i++) {
optional<float> n = toNumber(arrayMember(value, i));
if (!n) {
error = { "value must be an array of " + util::toString(N) + " numbers" };
return {};
}
result[i] = *n;
}

return std::array<float, 4> {{ *first, *second, *third, *fourth }};
return result;
}
};

Expand Down
3 changes: 3 additions & 0 deletions include/mbgl/style/conversion/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
Expand Down Expand Up @@ -92,6 +93,8 @@ struct Converter<std::unique_ptr<Layer>> {

if (*type == "fill") {
converted = convertVectorLayer<FillLayer>(*id, value, error);
} else if (*type == "fill-extrusion") {
converted = convertVectorLayer<FillExtrusionLayer>(*id, value, error);
} else if (*type == "line") {
converted = convertVectorLayer<LineLayer>(*id, value, error);
} else if (*type == "circle") {
Expand Down
122 changes: 122 additions & 0 deletions include/mbgl/style/conversion/light.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#pragma once

#include <mbgl/style/light.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/position.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/transition_options.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<Light> {
public:
template <class V>
optional<Light> operator()(const V& value, Error& error) const {
if (!isObject(value)) {
error = { "light must be an object" };
return {};
}

Light light;

const auto anchor = objectMember(value, "anchor");
if (anchor) {
optional<PropertyValue<LightAnchorType>> convertedAnchor =
convert<PropertyValue<LightAnchorType>>(*anchor, error);

if (convertedAnchor) {
light.get<LightAnchor>().value = *convertedAnchor;
} else {
return {};
}
}

const auto anchorTransition = objectMember(value, "anchor-transition");
if (anchorTransition) {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*anchorTransition, error);
if (transition) {
light.get<LightAnchor>().transition = *transition;
} else {
return {};
}
}

const auto color = objectMember(value, "color");
if (color) {
optional<PropertyValue<Color>> convertedColor =
convert<PropertyValue<Color>>(*color, error);

if (convertedColor) {
light.get<LightColor>().value = *convertedColor;
} else {
return {};
}
}

const auto colorTransition = objectMember(value, "color-transition");
if (colorTransition) {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*colorTransition, error);
if (transition) {
light.get<LightColor>().transition = *transition;
} else {
return {};
}
}

const auto position = objectMember(value, "position");
if (position) {
optional<PropertyValue<Position>> convertedPosition =
convert<PropertyValue<Position>>(*position, error);

if (convertedPosition) {
light.get<LightPosition>().value = *convertedPosition;
} else {
return {};
}
}

const auto positionTransition = objectMember(value, "position-transition");
if (positionTransition) {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*positionTransition, error);
if (transition) {
light.get<LightPosition>().transition = *transition;
} else {
return {};
}
}

const auto intensity = objectMember(value, "intensity");
if (intensity) {
optional<PropertyValue<float>> convertedIntensity =
convert<PropertyValue<float>>(*intensity, error);

if (convertedIntensity) {
light.get<LightIntensity>().value = *convertedIntensity;
} else {
return {};
}
}

const auto intensityTransition = objectMember(value, "intensity-transition");
if (intensityTransition) {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*intensityTransition, error);
if (transition) {
light.get<LightIntensity>().transition = *transition;
} else {
return {};
}
}
return { light };
};
};

} // namespace conversion
} // namespace style
} // namespace mbgl
29 changes: 29 additions & 0 deletions include/mbgl/style/conversion/position.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/position.hpp>
#include <mbgl/util/optional.hpp>

#include <array>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<Position> {
template <class V>
optional<Position> operator()(const V& value, Error& error) const {
optional<std::array<float, 3>> spherical = convert<std::array<float, 3>>(value, error);

if (!spherical) {
return {};
}

return Position(*spherical);
}
};

} // namespace conversion
} // namespace style
} // namespace mbgl
2 changes: 1 addition & 1 deletion include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Layer : public mbgl::util::noncopyable {

// Convenience method for dynamic dispatch on the concrete layer type. Using
// method overloading, this allows consolidation of logic common to vector-based
// layers (Fill, Line, Circle, or Symbol). For example:
// layers (Fill, FillExtrusion, Line, Circle, or Symbol). For example:
//
// struct Visitor {
// void operator()(CustomLayer&) { ... }
Expand Down
Loading

1 comment on commit f6e79d7

@kkaefer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Please sign in to comment.