summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/gl/attribute.cpp227
-rw-r--r--src/mbgl/gl/attribute.hpp185
-rw-r--r--src/mbgl/gl/context.cpp87
-rw-r--r--src/mbgl/gl/context.hpp35
-rw-r--r--src/mbgl/gl/draw_mode.hpp19
-rw-r--r--src/mbgl/gl/normalization.hpp35
-rw-r--r--src/mbgl/gl/program.hpp42
-rw-r--r--src/mbgl/gl/segment.cpp7
-rw-r--r--src/mbgl/gl/segment.hpp33
-rw-r--r--src/mbgl/gl/types.hpp10
-rw-r--r--src/mbgl/gl/uniform.hpp33
-rw-r--r--src/mbgl/layout/symbol_feature.hpp3
-rw-r--r--src/mbgl/layout/symbol_layout.cpp88
-rw-r--r--src/mbgl/layout/symbol_layout.hpp21
-rw-r--r--src/mbgl/programs/attributes.hpp160
-rw-r--r--src/mbgl/programs/circle_program.cpp2
-rw-r--r--src/mbgl/programs/circle_program.hpp32
-rw-r--r--src/mbgl/programs/collision_box_program.cpp2
-rw-r--r--src/mbgl/programs/collision_box_program.hpp21
-rw-r--r--src/mbgl/programs/debug_program.hpp12
-rw-r--r--src/mbgl/programs/fill_program.cpp4
-rw-r--r--src/mbgl/programs/fill_program.hpp58
-rw-r--r--src/mbgl/programs/line_program.cpp10
-rw-r--r--src/mbgl/programs/line_program.hpp76
-rw-r--r--src/mbgl/programs/program.hpp54
-rw-r--r--src/mbgl/programs/raster_program.cpp2
-rw-r--r--src/mbgl/programs/raster_program.hpp27
-rw-r--r--src/mbgl/programs/symbol_program.cpp2
-rw-r--r--src/mbgl/programs/symbol_program.hpp36
-rw-r--r--src/mbgl/renderer/bucket.hpp7
-rw-r--r--src/mbgl/renderer/circle_bucket.cpp27
-rw-r--r--src/mbgl/renderer/circle_bucket.hpp20
-rw-r--r--src/mbgl/renderer/debug_bucket.cpp4
-rw-r--r--src/mbgl/renderer/debug_bucket.hpp2
-rw-r--r--src/mbgl/renderer/fill_bucket.cpp30
-rw-r--r--src/mbgl/renderer/fill_bucket.hpp20
-rw-r--r--src/mbgl/renderer/line_bucket.cpp39
-rw-r--r--src/mbgl/renderer/line_bucket.hpp25
-rw-r--r--src/mbgl/renderer/painter.cpp24
-rw-r--r--src/mbgl/renderer/painter.hpp4
-rw-r--r--src/mbgl/renderer/painter_background.cpp31
-rw-r--r--src/mbgl/renderer/painter_circle.cpp12
-rw-r--r--src/mbgl/renderer/painter_clipping.cpp10
-rw-r--r--src/mbgl/renderer/painter_debug.cpp10
-rw-r--r--src/mbgl/renderer/painter_fill.cpp36
-rw-r--r--src/mbgl/renderer/painter_line.cpp5
-rw-r--r--src/mbgl/renderer/painter_raster.cpp6
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp13
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp18
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp16
-rw-r--r--src/mbgl/style/bucket_parameters.cpp14
-rw-r--r--src/mbgl/style/bucket_parameters.hpp21
-rw-r--r--src/mbgl/style/conversion/stringify.hpp148
-rw-r--r--src/mbgl/style/cross_faded_property_evaluator.cpp19
-rw-r--r--src/mbgl/style/cross_faded_property_evaluator.hpp2
-rw-r--r--src/mbgl/style/data_driven_property_evaluator.hpp42
-rw-r--r--src/mbgl/style/function.cpp81
-rw-r--r--src/mbgl/style/function/categorical_stops.cpp35
-rw-r--r--src/mbgl/style/function/identity_stops.cpp43
-rw-r--r--src/mbgl/style/layer_impl.hpp2
-rw-r--r--src/mbgl/style/layer_observer.hpp1
-rw-r--r--src/mbgl/style/layers/background_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/background_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/background_layer_properties.hpp1
-rw-r--r--src/mbgl/style/layers/circle_layer.cpp84
-rw-r--r--src/mbgl/style/layers/circle_layer_impl.cpp22
-rw-r--r--src/mbgl/style/layers/circle_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/circle_layer_properties.hpp15
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer.cpp36
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer_impl.cpp2
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer_properties.hpp7
-rw-r--r--src/mbgl/style/layers/fill_layer.cpp36
-rw-r--r--src/mbgl/style/layers/fill_layer_impl.cpp17
-rw-r--r--src/mbgl/style/layers/fill_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/fill_layer_properties.hpp7
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs20
-rw-r--r--src/mbgl/style/layers/layer_properties.hpp.ejs11
-rw-r--r--src/mbgl/style/layers/line_layer.cpp60
-rw-r--r--src/mbgl/style/layers/line_layer_impl.cpp35
-rw-r--r--src/mbgl/style/layers/line_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/line_layer_properties.hpp11
-rw-r--r--src/mbgl/style/layers/raster_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/raster_layer_impl.hpp2
-rw-r--r--src/mbgl/style/layers/raster_layer_properties.hpp1
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp12
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.cpp49
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.hpp6
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp5
-rw-r--r--src/mbgl/style/layout_property.hpp13
-rw-r--r--src/mbgl/style/paint_property.hpp86
-rw-r--r--src/mbgl/style/paint_property_binder.hpp283
-rw-r--r--src/mbgl/style/parser.cpp12
-rw-r--r--src/mbgl/style/possibly_evaluated_property_value.hpp74
-rw-r--r--src/mbgl/style/property_evaluator.hpp2
-rw-r--r--src/mbgl/style/style.cpp5
-rw-r--r--src/mbgl/style/style.hpp1
-rw-r--r--src/mbgl/text/quads.cpp2
-rw-r--r--src/mbgl/text/shaping.cpp13
-rw-r--r--src/mbgl/text/shaping.hpp41
-rw-r--r--src/mbgl/tile/geometry_tile_worker.cpp27
-rw-r--r--src/mbgl/util/ignore.hpp3
-rw-r--r--src/mbgl/util/indexed_tuple.hpp13
-rw-r--r--src/mbgl/util/interpolate.cpp19
-rw-r--r--src/mbgl/util/interpolate.hpp9
-rw-r--r--src/mbgl/util/type_list.hpp40
108 files changed, 2269 insertions, 924 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index 7432fff590..2c16dac3fc 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -1,29 +1,238 @@
#include <mbgl/gl/attribute.hpp>
+#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/normalization.hpp>
namespace mbgl {
namespace gl {
+static_assert(offsetof(Normalized<uint8_t>, value) == 0, "unexpected normalized offset");
+
AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
return location;
}
-void bindAttribute(AttributeLocation location,
- std::size_t count,
- DataType type,
- std::size_t vertexSize,
- std::size_t vertexOffset,
- std::size_t attributeOffset) {
+template <class T> DataType DataTypeOf = static_cast<DataType>(0);
+template <> DataType DataTypeOf< int8_t> = DataType::Byte;
+template <> DataType DataTypeOf<uint8_t> = DataType::UnsignedByte;
+template <> DataType DataTypeOf< int16_t> = DataType::Short;
+template <> DataType DataTypeOf<uint16_t> = DataType::UnsignedShort;
+template <> DataType DataTypeOf< int32_t> = DataType::Integer;
+template <> DataType DataTypeOf<uint32_t> = DataType::UnsignedInteger;
+template <> DataType DataTypeOf<float> = DataType::Float;
+
+template <class T> bool IsNormalized = false;
+template <class T> bool IsNormalized<Normalized<T>> = true;
+template <class T> DataType DataTypeOf<Normalized<T>> = DataTypeOf<T>;
+
+template <class T, std::size_t N>
+void VariableAttributeBinding<T, N>::bind(Context& context,
+ AttributeLocation location,
+ optional<VariableAttributeBinding<T, N>>& oldBinding,
+ std::size_t vertexOffset) const {
+ if (oldBinding == *this) {
+ return;
+ }
+ context.vertexBuffer = vertexBuffer;
MBGL_CHECK_ERROR(glEnableVertexAttribArray(location));
MBGL_CHECK_ERROR(glVertexAttribPointer(
location,
- static_cast<GLint>(count),
- static_cast<GLenum>(type),
- GL_FALSE,
+ static_cast<GLint>(N),
+ static_cast<GLenum>(DataTypeOf<T>),
+ static_cast<GLboolean>(IsNormalized<T>),
static_cast<GLsizei>(vertexSize),
reinterpret_cast<GLvoid*>(attributeOffset + (vertexSize * vertexOffset))));
}
+template class VariableAttributeBinding<uint8_t, 1>;
+template class VariableAttributeBinding<uint8_t, 2>;
+template class VariableAttributeBinding<uint8_t, 3>;
+template class VariableAttributeBinding<uint8_t, 4>;
+
+template class VariableAttributeBinding<Normalized<uint8_t>, 1>;
+template class VariableAttributeBinding<Normalized<uint8_t>, 2>;
+template class VariableAttributeBinding<Normalized<uint8_t>, 3>;
+template class VariableAttributeBinding<Normalized<uint8_t>, 4>;
+
+template class VariableAttributeBinding<uint16_t, 1>;
+template class VariableAttributeBinding<uint16_t, 2>;
+template class VariableAttributeBinding<uint16_t, 3>;
+template class VariableAttributeBinding<uint16_t, 4>;
+
+template class VariableAttributeBinding<int16_t, 1>;
+template class VariableAttributeBinding<int16_t, 2>;
+template class VariableAttributeBinding<int16_t, 3>;
+template class VariableAttributeBinding<int16_t, 4>;
+
+template class VariableAttributeBinding<float, 1>;
+template class VariableAttributeBinding<float, 2>;
+template class VariableAttributeBinding<float, 3>;
+template class VariableAttributeBinding<float, 4>;
+
+template <>
+void ConstantAttributeBinding<uint8_t, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint8_t, 1>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0]));
+}
+
+template <>
+void ConstantAttributeBinding<uint8_t, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint8_t, 2>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1]));
+}
+
+template <>
+void ConstantAttributeBinding<uint8_t, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint8_t, 3>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2]));
+}
+
+template <>
+void ConstantAttributeBinding<uint8_t, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint8_t, 4>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3]));
+}
+
+
+template <>
+void ConstantAttributeBinding<Normalized<uint8_t>, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 1>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0].denormalized()));
+}
+
+template <>
+void ConstantAttributeBinding<Normalized<uint8_t>, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 2>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0].denormalized(), value[1].denormalized()));
+}
+
+template <>
+void ConstantAttributeBinding<Normalized<uint8_t>, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 3>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0].denormalized(), value[1].denormalized(), value[2].denormalized()));
+}
+
+template <>
+void ConstantAttributeBinding<Normalized<uint8_t>, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 4>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0].denormalized(), value[1].denormalized(), value[2].denormalized(), value[3].denormalized()));
+}
+
+
+template <>
+void ConstantAttributeBinding<uint16_t, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint16_t, 1>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0]));
+}
+
+template <>
+void ConstantAttributeBinding<uint16_t, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint16_t, 2>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1]));
+}
+
+template <>
+void ConstantAttributeBinding<uint16_t, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint16_t, 3>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2]));
+}
+
+template <>
+void ConstantAttributeBinding<uint16_t, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint16_t, 4>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3]));
+}
+
+
+template <>
+void ConstantAttributeBinding<int16_t, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<int16_t, 1>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0]));
+}
+
+template <>
+void ConstantAttributeBinding<int16_t, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<int16_t, 2>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1]));
+}
+
+template <>
+void ConstantAttributeBinding<int16_t, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<int16_t, 3>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2]));
+}
+
+template <>
+void ConstantAttributeBinding<int16_t, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<int16_t, 4>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3]));
+}
+
+
+template <>
+void ConstantAttributeBinding<float, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<float, 1>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0]));
+}
+
+template <>
+void ConstantAttributeBinding<float, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<float, 2>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0], value[1]));
+}
+
+template <>
+void ConstantAttributeBinding<float, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<float, 3>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0], value[1], value[2]));
+}
+
+template <>
+void ConstantAttributeBinding<float, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<float, 4>>& oldBinding, std::size_t) const {
+ assert(location != 0);
+ oldBinding = {};
+ MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
+ MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0], value[1], value[2], value[3]));
+}
+
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index e45014127b..6300ebb56b 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -1,8 +1,10 @@
#pragma once
#include <mbgl/gl/types.hpp>
+#include <mbgl/gl/segment.hpp>
#include <mbgl/util/ignore.hpp>
#include <mbgl/util/indexed_tuple.hpp>
+#include <mbgl/util/variant.hpp>
#include <cstddef>
#include <functional>
@@ -10,24 +12,79 @@
namespace mbgl {
namespace gl {
-template <class Tag, class T, std::size_t N>
+template <class T, std::size_t N>
+class VariableAttributeBinding {
+public:
+ VariableAttributeBinding(BufferID vertexBuffer_,
+ std::size_t vertexSize_,
+ std::size_t attributeOffset_)
+ : vertexBuffer(vertexBuffer_),
+ vertexSize(vertexSize_),
+ attributeOffset(attributeOffset_)
+ {}
+
+ void bind(Context&, AttributeLocation, optional<VariableAttributeBinding<T, N>>&, std::size_t vertexOffset) const;
+
+ friend bool operator==(const VariableAttributeBinding& lhs,
+ const VariableAttributeBinding& rhs) {
+ return lhs.vertexBuffer == rhs.vertexBuffer
+ && lhs.vertexSize == rhs.vertexSize
+ && lhs.attributeOffset == rhs.attributeOffset;
+ }
+
+private:
+ BufferID vertexBuffer;
+ std::size_t vertexSize;
+ std::size_t attributeOffset;
+};
+
+template <class T, std::size_t N>
+class ConstantAttributeBinding {
+public:
+ ConstantAttributeBinding() { value.fill(T()); }
+
+ explicit ConstantAttributeBinding(std::array<T, N> value_)
+ : value(std::move(value_))
+ {}
+
+ void bind(Context&, AttributeLocation, optional<VariableAttributeBinding<T, N>>&, std::size_t) const;
+
+ friend bool operator==(const ConstantAttributeBinding& lhs,
+ const ConstantAttributeBinding& rhs) {
+ return lhs.value == rhs.value;
+ }
+
+private:
+ std::array<T, N> value;
+};
+
+template <class T, std::size_t N>
class Attribute {
public:
- using Type = T[N];
+ using Value = std::array<T, N>;
+
+ using VariableBinding = VariableAttributeBinding<T, N>;
+ using ConstantBinding = ConstantAttributeBinding<T, N>;
- class State {
- public:
- explicit State(AttributeLocation location_)
- : location(location_) {}
+ using Location = AttributeLocation;
- AttributeLocation location;
- static constexpr std::size_t count = N;
- static constexpr DataType type = DataTypeOf<T>::value;
- };
+ using Binding = variant<
+ ConstantBinding,
+ VariableBinding>;
+
+ static void bind(Context& context,
+ const Location& location,
+ optional<VariableBinding>& oldBinding,
+ const Binding& newBinding,
+ std::size_t vertexOffset) {
+ Binding::visit(newBinding, [&] (const auto& binding) {
+ binding.bind(context, location, oldBinding, vertexOffset);
+ });
+ }
};
#define MBGL_DEFINE_ATTRIBUTE(type_, n_, name_) \
- struct name_ : ::mbgl::gl::Attribute<name_, type_, n_> { static constexpr auto name = #name_; }
+ struct name_ : ::mbgl::gl::Attribute<type_, n_> { static auto name() { return #name_; } }
namespace detail {
@@ -41,10 +98,16 @@ namespace detail {
template <class... As>
class Vertex;
+template <>
+class Vertex<> {
+public:
+ using VertexType = Vertex<>;
+};
+
template <class A1>
class Vertex<A1> {
public:
- typename A1::Type a1;
+ typename A1::Value a1;
using VertexType = Vertex<A1>;
static const std::size_t attributeOffsets[1];
@@ -53,8 +116,8 @@ public:
template <class A1, class A2>
class Vertex<A1, A2> {
public:
- typename A1::Type a1;
- typename A2::Type a2;
+ typename A1::Value a1;
+ typename A2::Value a2;
using VertexType = Vertex<A1, A2>;
static const std::size_t attributeOffsets[2];
@@ -63,9 +126,9 @@ public:
template <class A1, class A2, class A3>
class Vertex<A1, A2, A3> {
public:
- typename A1::Type a1;
- typename A2::Type a2;
- typename A3::Type a3;
+ typename A1::Value a1;
+ typename A2::Value a2;
+ typename A3::Value a3;
using VertexType = Vertex<A1, A2, A3>;
static const std::size_t attributeOffsets[3];
@@ -74,10 +137,10 @@ public:
template <class A1, class A2, class A3, class A4>
class Vertex<A1, A2, A3, A4> {
public:
- typename A1::Type a1;
- typename A2::Type a2;
- typename A3::Type a3;
- typename A4::Type a4;
+ typename A1::Value a1;
+ typename A2::Value a2;
+ typename A3::Value a3;
+ typename A4::Value a4;
using VertexType = Vertex<A1, A2, A3, A4>;
static const std::size_t attributeOffsets[4];
@@ -86,11 +149,11 @@ public:
template <class A1, class A2, class A3, class A4, class A5>
class Vertex<A1, A2, A3, A4, A5> {
public:
- typename A1::Type a1;
- typename A2::Type a2;
- typename A3::Type a3;
- typename A4::Type a4;
- typename A5::Type a5;
+ typename A1::Value a1;
+ typename A2::Value a2;
+ typename A3::Value a3;
+ typename A4::Value a4;
+ typename A5::Value a5;
using VertexType = Vertex<A1, A2, A3, A4, A5>;
static const std::size_t attributeOffsets[5];
@@ -135,37 +198,71 @@ const std::size_t Vertex<A1, A2, A3, A4, A5>::attributeOffsets[5] = {
AttributeLocation bindAttributeLocation(ProgramID, AttributeLocation, const char * name);
-void bindAttribute(AttributeLocation location,
- std::size_t count,
- DataType type,
- std::size_t vertexSize,
- std::size_t vertexOffset,
- std::size_t attributeOffset);
-
template <class... As>
class Attributes {
public:
- using State = IndexedTuple<TypeList<As...>, TypeList<typename As::State...>>;
+ using Types = TypeList<As...>;
+ using Locations = IndexedTuple<
+ TypeList<As...>,
+ TypeList<typename As::Location...>>;
+ using Bindings = IndexedTuple<
+ TypeList<As...>,
+ TypeList<typename As::Binding...>>;
+ using VariableBindings = IndexedTuple<
+ TypeList<As...>,
+ TypeList<optional<typename As::VariableBinding>...>>;
+
using Vertex = detail::Vertex<As...>;
template <class A>
static constexpr std::size_t Index = TypeIndex<A, As...>::value;
- static State state(const ProgramID& id) {
- return State { typename As::State(bindAttributeLocation(id, Index<As>, As::name))... };
+ static Locations locations(const ProgramID& id) {
+ return Locations { bindAttributeLocation(id, Index<As>, As::name())... };
}
- static std::function<void (std::size_t)> binder(const State& state) {
- return [&state] (std::size_t vertexOffset) {
- util::ignore({ (bindAttribute(state.template get<As>().location,
- state.template get<As>().count,
- state.template get<As>().type,
- sizeof(Vertex),
- vertexOffset,
- Vertex::attributeOffsets[Index<As>]), 0)... });
+ template <class DrawMode>
+ static Bindings allVariableBindings(const VertexBuffer<Vertex, DrawMode>& buffer) {
+ static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout");
+
+ return Bindings {
+ typename As::VariableBinding {
+ buffer.buffer,
+ sizeof(Vertex),
+ Vertex::attributeOffsets[Index<As>]
+ }...
};
}
+
+ static void bind(Context& context,
+ const Locations& locations,
+ VariableBindings& oldBindings,
+ const Bindings& newBindings,
+ std::size_t vertexOffset) {
+ util::ignore({ (As::bind(context,
+ locations.template get<As>(),
+ oldBindings.template get<As>(),
+ newBindings.template get<As>(),
+ vertexOffset), 0)... });
+ }
};
+namespace detail {
+
+template <class...>
+struct ConcatenateAttributes;
+
+template <class... As, class... Bs>
+struct ConcatenateAttributes<TypeList<As...>, TypeList<Bs...>> {
+ using Type = Attributes<As..., Bs...>;
+};
+
+} // namespace detail
+
+template <class A, class B>
+using ConcatenateAttributes = typename detail::ConcatenateAttributes<
+ typename A::Types,
+ typename B::Types>::Type;
+
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 5048ffcd66..a74e941bc6 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -122,6 +122,16 @@ UniqueTexture Context::createTexture() {
return UniqueTexture{ std::move(id), { this } };
}
+UniqueVertexArray Context::createVertexArray() {
+ if (!gl::GenVertexArrays) {
+ throw std::runtime_error("GL_ARB_vertex_array_object extension is required");
+ }
+
+ VertexArrayID id = 0;
+ MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
+ return UniqueVertexArray(std::move(id), { this });
+}
+
UniqueFramebuffer Context::createFramebuffer() {
FramebufferID id = 0;
MBGL_CHECK_ERROR(glGenFramebuffers(1, &id));
@@ -407,32 +417,26 @@ void Context::clear(optional<mbgl::Color> color,
}
#if not MBGL_USE_GLES2
-PrimitiveType Context::operator()(const Points& points) {
+void Context::setDrawMode(const Points& points) {
pointSize = points.pointSize;
- return PrimitiveType::Points;
}
#else
-PrimitiveType Context::operator()(const Points&) {
- return PrimitiveType::Points;
+void Context::setDrawMode(const Points&) {
}
#endif // MBGL_USE_GLES2
-PrimitiveType Context::operator()(const Lines& lines) {
+void Context::setDrawMode(const Lines& lines) {
lineWidth = lines.lineWidth;
- return PrimitiveType::Lines;
}
-PrimitiveType Context::operator()(const LineStrip& lineStrip) {
+void Context::setDrawMode(const LineStrip& lineStrip) {
lineWidth = lineStrip.lineWidth;
- return PrimitiveType::LineStrip;
}
-PrimitiveType Context::operator()(const Triangles&) {
- return PrimitiveType::Triangles;
+void Context::setDrawMode(const Triangles&) {
}
-PrimitiveType Context::operator()(const TriangleStrip&) {
- return PrimitiveType::TriangleStrip;
+void Context::setDrawMode(const TriangleStrip&) {
}
void Context::setDepthMode(const DepthMode& depth) {
@@ -474,57 +478,14 @@ void Context::setColorMode(const ColorMode& color) {
colorMask = color.mask;
}
-void Context::draw(const Drawable& drawable) {
- if (drawable.segments.empty()) {
- return;
- }
-
- PrimitiveType primitiveType = apply_visitor([&] (auto m) { return (*this)(m); }, drawable.drawMode);
-
- setDepthMode(drawable.depthMode);
- setStencilMode(drawable.stencilMode);
- setColorMode(drawable.colorMode);
-
- program = drawable.program;
-
- drawable.bindUniforms();
-
- for (const auto& segment : drawable.segments) {
- auto needAttributeBindings = [&] () {
- if (!gl::GenVertexArrays || !gl::BindVertexArray) {
- return true;
- }
-
- if (segment.vao) {
- vertexArrayObject = *segment.vao;
- return false;
- }
-
- VertexArrayID id = 0;
- MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
- vertexArrayObject = id;
- segment.vao = UniqueVertexArray(std::move(id), { this });
-
- // If we are initializing a new VAO, we need to force the buffers
- // to be rebound. VAOs don't inherit the existing buffer bindings.
- vertexBuffer.setDirty();
- elementBuffer.setDirty();
-
- return true;
- };
-
- if (needAttributeBindings()) {
- vertexBuffer = drawable.vertexBuffer;
- elementBuffer = drawable.indexBuffer;
- drawable.bindAttributes(segment.vertexOffset);
- }
-
- MBGL_CHECK_ERROR(glDrawElements(
- static_cast<GLenum>(primitiveType),
- static_cast<GLsizei>(segment.indexLength),
- GL_UNSIGNED_SHORT,
- reinterpret_cast<GLvoid*>(sizeof(uint16_t) * segment.indexOffset)));
- }
+void Context::draw(PrimitiveType primitiveType,
+ std::size_t indexOffset,
+ std::size_t indexLength) {
+ MBGL_CHECK_ERROR(glDrawElements(
+ static_cast<GLenum>(primitiveType),
+ static_cast<GLsizei>(indexLength),
+ GL_UNSIGNED_SHORT,
+ reinterpret_cast<GLvoid*>(sizeof(uint16_t) * indexOffset)));
}
void Context::performCleanup() {
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 093afa20ed..636dfc9eac 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -13,7 +13,6 @@
#include <mbgl/gl/depth_mode.hpp>
#include <mbgl/gl/stencil_mode.hpp>
#include <mbgl/gl/color_mode.hpp>
-#include <mbgl/gl/segment.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -40,6 +39,7 @@ public:
UniqueProgram createProgram(ShaderID vertexShader, ShaderID fragmentShader);
void linkProgram(ProgramID);
UniqueTexture createTexture();
+ UniqueVertexArray createVertexArray();
template <class Vertex, class DrawMode>
VertexBuffer<Vertex, DrawMode> createVertexBuffer(VertexVector<Vertex, DrawMode>&& v) {
@@ -119,25 +119,20 @@ public:
optional<float> depth,
optional<int32_t> stencil);
- struct Drawable {
- DrawMode drawMode;
- DepthMode depthMode;
- StencilMode stencilMode;
- ColorMode colorMode;
- gl::ProgramID program;
- gl::BufferID vertexBuffer;
- gl::BufferID indexBuffer;
- const std::vector<Segment>& segments;
- std::function<void ()> bindUniforms;
- std::function<void (std::size_t)> bindAttributes;
- };
-
- void draw(const Drawable&);
+ void setDrawMode(const Points&);
+ void setDrawMode(const Lines&);
+ void setDrawMode(const LineStrip&);
+ void setDrawMode(const Triangles&);
+ void setDrawMode(const TriangleStrip&);
void setDepthMode(const DepthMode&);
void setStencilMode(const StencilMode&);
void setColorMode(const ColorMode&);
+ void draw(PrimitiveType,
+ std::size_t indexOffset,
+ std::size_t indexLength);
+
// Actually remove the objects we marked as abandoned with the above methods.
// Only call this while the OpenGL context is exclusive to this thread.
void performCleanup();
@@ -164,6 +159,8 @@ public:
std::array<State<value::BindTexture>, 2> texture;
State<value::BindVertexArray> vertexArrayObject;
State<value::Program> program;
+ State<value::BindVertexBuffer> vertexBuffer;
+ State<value::BindElementBuffer> elementBuffer;
#if not MBGL_USE_GLES2
State<value::PixelZoom> pixelZoom;
@@ -196,8 +193,6 @@ private:
#if not MBGL_USE_GLES2
State<value::PointSize> pointSize;
#endif // MBGL_USE_GLES2
- State<value::BindVertexBuffer> vertexBuffer;
- State<value::BindElementBuffer> elementBuffer;
UniqueBuffer createVertexBuffer(const void* data, std::size_t size);
UniqueBuffer createIndexBuffer(const void* data, std::size_t size);
@@ -210,12 +205,6 @@ private:
void drawPixels(Size size, const void* data, TextureFormat);
#endif // MBGL_USE_GLES2
- PrimitiveType operator()(const Points&);
- PrimitiveType operator()(const Lines&);
- PrimitiveType operator()(const LineStrip&);
- PrimitiveType operator()(const Triangles&);
- PrimitiveType operator()(const TriangleStrip&);
-
friend detail::ProgramDeleter;
friend detail::ShaderDeleter;
friend detail::BufferDeleter;
diff --git a/src/mbgl/gl/draw_mode.hpp b/src/mbgl/gl/draw_mode.hpp
index ab86d5e469..275eb25b89 100644
--- a/src/mbgl/gl/draw_mode.hpp
+++ b/src/mbgl/gl/draw_mode.hpp
@@ -1,7 +1,7 @@
#pragma once
+#include <mbgl/gl/types.hpp>
#include <mbgl/gl/primitives.hpp>
-#include <mbgl/util/variant.hpp>
#include <cassert>
@@ -11,7 +11,9 @@ namespace gl {
class Points {
public:
using Primitive = Point;
+
static constexpr std::size_t bufferGroupSize = 1;
+ static constexpr PrimitiveType primitiveType = PrimitiveType::Points;
explicit Points(float pointSize_) : pointSize(pointSize_) {}
@@ -21,7 +23,9 @@ public:
class Lines {
public:
using Primitive = Line;
+
static constexpr std::size_t bufferGroupSize = 2;
+ static constexpr PrimitiveType primitiveType = PrimitiveType::Lines;
explicit Lines(float lineWidth_) : lineWidth(lineWidth_) {
assert(lineWidth > 0);
@@ -35,7 +39,9 @@ public:
// LineStrip is a form of "Line" rendering, but the element buffer
// cannot be grouped into logical elements beyond a single Point.
using Primitive = Line;
+
static constexpr std::size_t bufferGroupSize = 1;
+ static constexpr PrimitiveType primitiveType = PrimitiveType::LineStrip;
explicit LineStrip(float lineWidth_) : lineWidth(lineWidth_) {
assert(lineWidth > 0);
@@ -47,7 +53,9 @@ public:
class Triangles {
public:
using Primitive = Triangle;
+
static constexpr std::size_t bufferGroupSize = 3;
+ static constexpr PrimitiveType primitiveType = PrimitiveType::Triangles;
};
class TriangleStrip {
@@ -55,7 +63,9 @@ public:
// TriangleStrip is a form of "Triangle" rendering, but the element buffer
// cannot be grouped into logical elements beyond a single Point.
using Primitive = Triangle;
+
static constexpr std::size_t bufferGroupSize = 1;
+ static constexpr PrimitiveType primitiveType = PrimitiveType::TriangleStrip;
};
// Special draw mode for use with VertexVector<Indexed, Vertex>, in which
@@ -65,12 +75,5 @@ public:
static constexpr std::size_t bufferGroupSize = 1;
};
-using DrawMode = variant<
- Points,
- Lines,
- LineStrip,
- Triangles,
- TriangleStrip>;
-
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/normalization.hpp b/src/mbgl/gl/normalization.hpp
new file mode 100644
index 0000000000..83fa67a3ec
--- /dev/null
+++ b/src/mbgl/gl/normalization.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <mbgl/math/clamp.hpp>
+
+#include <cassert>
+#include <limits>
+
+namespace mbgl {
+namespace gl {
+
+template <class T>
+class Normalized {
+public:
+ T value;
+
+ Normalized() : value(0) {}
+
+ explicit Normalized(float f)
+ : value(static_cast<T>(std::numeric_limits<T>::max() * util::clamp(f, 0.0f, 1.0f))) {
+ assert(f >= 0.0f);
+ assert(f <= 1.0f);
+ }
+
+ float denormalized() const {
+ return float(value) / std::numeric_limits<T>::max();
+ }
+};
+
+template <class T>
+bool operator==(const Normalized<T>& lhs, const Normalized<T>& rhs) {
+ return lhs.value == rhs.value;
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 33387e9d4e..fa0470796e 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -20,16 +20,14 @@ public:
using Attributes = As;
using Uniforms = Us;
- using Vertex = typename Attributes::Vertex;
using UniformValues = typename Uniforms::Values;
-
- static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout");
+ using AttributeBindings = typename Attributes::Bindings;
Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource)
: vertexShader(context.createShader(ShaderType::Vertex, vertexSource)),
fragmentShader(context.createShader(ShaderType::Fragment, fragmentSource)),
program(context.createProgram(vertexShader, fragmentShader)),
- attributesState(Attributes::state(program)),
+ attributeLocations(Attributes::locations(program)),
uniformsState((context.linkProgram(program), Uniforms::state(program))) {}
template <class DrawMode>
@@ -39,22 +37,30 @@ public:
StencilMode stencilMode,
ColorMode colorMode,
UniformValues&& uniformValues,
- const VertexBuffer<Vertex>& vertexBuffer,
+ AttributeBindings&& attributeBindings,
const IndexBuffer<DrawMode>& indexBuffer,
const SegmentVector<Attributes>& segments) {
static_assert(std::is_same<Primitive, typename DrawMode::Primitive>::value, "incompatible draw mode");
- context.draw({
- std::move(drawMode),
- std::move(depthMode),
- std::move(stencilMode),
- std::move(colorMode),
- program,
- vertexBuffer.buffer,
- indexBuffer.buffer,
- segments,
- Uniforms::binder(uniformsState, std::move(uniformValues)),
- Attributes::binder(attributesState)
- });
+
+ context.setDrawMode(drawMode);
+ context.setDepthMode(depthMode);
+ context.setStencilMode(stencilMode);
+ context.setColorMode(colorMode);
+
+ context.program = program;
+
+ Uniforms::bind(uniformsState, std::move(uniformValues));
+
+ for (const auto& segment : segments) {
+ segment.bind(context,
+ indexBuffer.buffer,
+ attributeLocations,
+ attributeBindings);
+
+ context.draw(drawMode.primitiveType,
+ segment.indexOffset,
+ segment.indexLength);
+ }
}
private:
@@ -62,7 +68,7 @@ private:
UniqueShader fragmentShader;
UniqueProgram program;
- typename Attributes::State attributesState;
+ typename Attributes::Locations attributeLocations;
typename Uniforms::State uniformsState;
};
diff --git a/src/mbgl/gl/segment.cpp b/src/mbgl/gl/segment.cpp
new file mode 100644
index 0000000000..aabdc83cd4
--- /dev/null
+++ b/src/mbgl/gl/segment.cpp
@@ -0,0 +1,7 @@
+#include <mbgl/gl/segment.hpp>
+
+namespace mbgl {
+namespace gl {
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp
index 8f74afd237..bb9f2f1ee8 100644
--- a/src/mbgl/gl/segment.hpp
+++ b/src/mbgl/gl/segment.hpp
@@ -1,12 +1,16 @@
#pragma once
+#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/util/optional.hpp>
#include <cstddef>
+#include <vector>
namespace mbgl {
namespace gl {
+template <class Attributes>
class Segment {
public:
Segment(std::size_t vertexOffset_,
@@ -24,13 +28,38 @@ public:
std::size_t vertexLength;
std::size_t indexLength;
+ void bind(Context& context,
+ BufferID indexBuffer_,
+ const typename Attributes::Locations& attributeLocations,
+ const typename Attributes::Bindings& attributeBindings_) const {
+ if (!vao) {
+ vao = context.createVertexArray();
+ context.vertexBuffer.setDirty();
+ }
+
+ context.vertexArrayObject = *vao;
+
+ if (indexBuffer != indexBuffer_) {
+ indexBuffer = indexBuffer_;
+ context.elementBuffer.setDirty();
+ context.elementBuffer = indexBuffer_;
+ }
+
+ Attributes::bind(context,
+ attributeLocations,
+ variableBindings,
+ attributeBindings_,
+ vertexOffset);
+ }
+
private:
- friend class Context;
mutable optional<UniqueVertexArray> vao;
+ mutable optional<BufferID> indexBuffer;
+ mutable typename Attributes::VariableBindings variableBindings;
};
template <class Attributes>
-class SegmentVector : public std::vector<Segment> {
+class SegmentVector : public std::vector<Segment<Attributes>> {
public:
SegmentVector() = default;
};
diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp
index 577629d5d3..565ca5754f 100644
--- a/src/mbgl/gl/types.hpp
+++ b/src/mbgl/gl/types.hpp
@@ -34,16 +34,6 @@ enum class DataType : uint32_t {
Float = 0x1406
};
-template <typename T> struct DataTypeOf;
-
-template <> struct DataTypeOf<int8_t> : std::integral_constant<DataType, DataType::Byte> {};
-template <> struct DataTypeOf<uint8_t> : std::integral_constant<DataType, DataType::UnsignedByte> {};
-template <> struct DataTypeOf<int16_t> : std::integral_constant<DataType, DataType::Short> {};
-template <> struct DataTypeOf<uint16_t> : std::integral_constant<DataType, DataType::UnsignedShort> {};
-template <> struct DataTypeOf<int32_t> : std::integral_constant<DataType, DataType::Integer> {};
-template <> struct DataTypeOf<uint32_t> : std::integral_constant<DataType, DataType::UnsignedInteger> {};
-template <> struct DataTypeOf<float> : std::integral_constant<DataType, DataType::Float> {};
-
enum class RenderbufferType : uint32_t {
RGBA = 0x8058,
DepthStencil = 0x88F0,
diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp
index 726cd4fe10..92136b61c2 100644
--- a/src/mbgl/gl/uniform.hpp
+++ b/src/mbgl/gl/uniform.hpp
@@ -50,32 +50,49 @@ template <class Tag, class T, size_t N>
using UniformMatrix = Uniform<Tag, std::array<T, N*N>>;
#define MBGL_DEFINE_UNIFORM_SCALAR(type_, name_) \
- struct name_ : ::mbgl::gl::UniformScalar<name_, type_> { static constexpr auto name = #name_; }
+ struct name_ : ::mbgl::gl::UniformScalar<name_, type_> { static auto name() { return #name_; } }
#define MBGL_DEFINE_UNIFORM_VECTOR(type_, n_, name_) \
- struct name_ : ::mbgl::gl::UniformVector<name_, type_, n_> { static constexpr auto name = #name_; }
+ struct name_ : ::mbgl::gl::UniformVector<name_, type_, n_> { static auto name() { return #name_; } }
#define MBGL_DEFINE_UNIFORM_MATRIX(type_, n_, name_) \
- struct name_ : ::mbgl::gl::UniformMatrix<name_, type_, n_> { static constexpr auto name = #name_; }
+ struct name_ : ::mbgl::gl::UniformMatrix<name_, type_, n_> { static auto name() { return #name_; } }
UniformLocation uniformLocation(ProgramID, const char * name);
template <class... Us>
class Uniforms {
public:
+ using Types = TypeList<Us...>;
using State = IndexedTuple<TypeList<Us...>, TypeList<typename Us::State...>>;
using Values = IndexedTuple<TypeList<Us...>, TypeList<typename Us::Value...>>;
static State state(const ProgramID& id) {
- return State { { uniformLocation(id, Us::name) }... };
+ return State { { uniformLocation(id, Us::name()) }... };
}
- static std::function<void ()> binder(State& state, Values&& values_) {
- return [&state, values = std::move(values_)] () mutable {
- util::ignore({ (state.template get<Us>() = values.template get<Us>(), 0)... });
- };
+ static void bind(State& state, Values&& values) {
+ util::ignore({ (state.template get<Us>() = values.template get<Us>(), 0)... });
}
};
+
+namespace detail {
+
+template <class...>
+struct ConcatenateUniforms;
+
+template <class... As, class... Bs>
+struct ConcatenateUniforms<TypeList<As...>, TypeList<Bs...>> {
+ using Type = Uniforms<As..., Bs...>;
+};
+
+} // namespace detail
+
+template <class A, class B>
+using ConcatenateUniforms = typename detail::ConcatenateUniforms<
+ typename A::Types,
+ typename B::Types>::Type;
+
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp
index 5dd61d9156..e55995f952 100644
--- a/src/mbgl/layout/symbol_feature.hpp
+++ b/src/mbgl/layout/symbol_feature.hpp
@@ -3,6 +3,7 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/util/optional.hpp>
+#include <array>
#include <string>
namespace mbgl {
@@ -13,6 +14,8 @@ public:
GeometryCollection geometry;
optional<std::u16string> text;
optional<std::string> icon;
+ std::array<float, 2> iconOffset;
+ float iconRotation;
std::size_t index;
};
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index eaa0332995..5dd36c41bd 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -3,7 +3,9 @@
#include <mbgl/layout/clip_lines.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/style/filter_evaluator.hpp>
-#include <mbgl/style/layer.hpp>
+#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/style/layers/symbol_layer.hpp>
+#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/text/glyph_atlas.hpp>
#include <mbgl/text/get_anchors.hpp>
@@ -27,27 +29,49 @@ namespace mbgl {
using namespace style;
-SymbolLayout::SymbolLayout(std::vector<std::string> layerIDs_,
- std::string sourceLayerName_,
- uint32_t overscaling_,
- float zoom_,
- const MapMode mode_,
- const GeometryTileLayer& layer,
- const style::Filter& filter,
- style::SymbolLayoutProperties::Evaluated layout_,
- float textMaxSize_,
+SymbolLayout::SymbolLayout(const BucketParameters& parameters,
+ const std::vector<const Layer*>& layers,
+ const GeometryTileLayer& sourceLayer,
SpriteAtlas& spriteAtlas_)
- : layerIDs(std::move(layerIDs_)),
- sourceLayerName(std::move(sourceLayerName_)),
- overscaling(overscaling_),
- zoom(zoom_),
- mode(mode_),
- layout(std::move(layout_)),
- textMaxSize(textMaxSize_),
+ : sourceLayerName(sourceLayer.getName()),
+ bucketName(layers.at(0)->getID()),
+ overscaling(parameters.tileID.overscaleFactor()),
+ zoom(parameters.tileID.overscaledZ),
+ mode(parameters.mode),
spriteAtlas(spriteAtlas_),
- tileSize(util::tileSize * overscaling_),
+ tileSize(util::tileSize * overscaling),
tilePixelRatio(float(util::EXTENT) / tileSize) {
+ const SymbolLayer::Impl& leader = *layers.at(0)->as<SymbolLayer>()->impl;
+
+ layout = leader.layout.evaluate(PropertyEvaluationParameters(zoom));
+
+ if (layout.get<IconRotationAlignment>() == AlignmentType::Auto) {
+ if (layout.get<SymbolPlacement>() == SymbolPlacementType::Line) {
+ layout.get<IconRotationAlignment>() = AlignmentType::Map;
+ } else {
+ layout.get<IconRotationAlignment>() = AlignmentType::Viewport;
+ }
+ }
+
+ if (layout.get<TextRotationAlignment>() == AlignmentType::Auto) {
+ if (layout.get<SymbolPlacement>() == SymbolPlacementType::Line) {
+ layout.get<TextRotationAlignment>() = AlignmentType::Map;
+ } else {
+ layout.get<TextRotationAlignment>() = AlignmentType::Viewport;
+ }
+ }
+
+ // If unspecified `text-pitch-alignment` inherits `text-rotation-alignment`
+ if (layout.get<TextPitchAlignment>() == AlignmentType::Auto) {
+ layout.get<TextPitchAlignment>() = layout.get<TextRotationAlignment>();
+ }
+
+ textMaxSize = leader.layout.evaluate<TextSize>(PropertyEvaluationParameters(18));
+
+ layout.get<IconSize>() = leader.layout.evaluate<IconSize>(PropertyEvaluationParameters(zoom + 1));
+ layout.get<TextSize>() = leader.layout.evaluate<TextSize>(PropertyEvaluationParameters(zoom + 1));
+
const bool hasText = !layout.get<TextField>().empty() && !layout.get<TextFont>().empty();
const bool hasIcon = !layout.get<IconImage>().empty();
@@ -55,13 +79,15 @@ SymbolLayout::SymbolLayout(std::vector<std::string> layerIDs_,
return;
}
- auto layerName = layer.getName();
+ for (const auto& layer : layers) {
+ layerPaintProperties.emplace(layer->getID(), layer->as<SymbolLayer>()->impl->paint.evaluated);
+ }
// Determine and load glyph ranges
- const size_t featureCount = layer.featureCount();
+ const size_t featureCount = sourceLayer.featureCount();
for (size_t i = 0; i < featureCount; ++i) {
- auto feature = layer.getFeature(i);
- if (!filter(feature->getType(), feature->getID(), [&] (const auto& key) { return feature->getValue(key); }))
+ auto feature = sourceLayer.getFeature(i);
+ if (!leader.filter(feature->getType(), feature->getID(), [&] (const auto& key) { return feature->getValue(key); }))
continue;
SymbolFeature ft;
@@ -103,6 +129,8 @@ SymbolLayout::SymbolLayout(std::vector<std::string> layerIDs_,
if (hasIcon) {
ft.icon = util::replaceTokens(layout.get<IconImage>(), getValue);
+ ft.iconOffset = layout.get<IconOffset>().evaluate(zoom, *feature);
+ ft.iconRotation = layout.get<IconRotate>().evaluate(zoom, *feature) * util::DEG2RAD;
}
if (ft.text || ft.icon) {
@@ -209,14 +237,14 @@ void SymbolLayout::prepare(uintptr_t tileUID,
if (feature.icon) {
auto image = spriteAtlas.getImage(*feature.icon, SpritePatternMode::Single);
if (image) {
- shapedIcon = shapeIcon(*image, layout);
+ shapedIcon = shapeIcon(*image, feature);
assert((*image).spriteImage);
if ((*image).spriteImage->sdf) {
sdfIcons = true;
}
if ((*image).relativePixelRatio != 1.0f) {
iconsNeedLinear = true;
- } else if (layout.get<IconRotate>() != 0) {
+ } else if (layout.get<IconRotate>().constantOr(1) != 0) {
iconsNeedLinear = true;
}
}
@@ -254,7 +282,7 @@ void SymbolLayout::addFeature(const SymbolFeature& feature,
? SymbolPlacementType::Point
: layout.get<SymbolPlacement>();
const float textRepeatDistance = symbolSpacing / 2;
- IndexedSubfeature indexedFeature = {feature.index, sourceLayerName, layerIDs.at(0), symbolInstances.size()};
+ IndexedSubfeature indexedFeature = {feature.index, sourceLayerName, bucketName, symbolInstances.size()};
auto addSymbolInstance = [&] (const GeometryCoordinates& line, Anchor& anchor) {
// https://github.com/mapbox/vector-tile-spec/tree/master/2.1#41-layers
@@ -350,7 +378,7 @@ bool SymbolLayout::anchorIsTooClose(const std::u16string& text, const float repe
}
std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile) {
- auto bucket = std::make_unique<SymbolBucket>(mode, layout, sdfIcons, iconsNeedLinear);
+ auto bucket = std::make_unique<SymbolBucket>(layout, layerPaintProperties, zoom, sdfIcons, iconsNeedLinear);
// Calculate which labels can be shown and when they can be shown and
// create the bufers used for rendering.
@@ -487,13 +515,13 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);
// coordinates (2 triangles)
- buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, tl, tex.x, tex.y,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tl, tex.x, tex.y,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, tr, tex.x + tex.w, tex.y,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tr, tex.x + tex.w, tex.y,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, bl, tex.x, tex.y + tex.h,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, bl, tex.x, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolAttributes::vertex(anchorPoint, br, tex.x + tex.w, tex.y + tex.h,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, br, tex.x + tex.w, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle));
// add the two triangles, referencing the four coordinates we just inserted.
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
index 3430b937e9..cb31bb3b29 100644
--- a/src/mbgl/layout/symbol_layout.hpp
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -20,6 +20,7 @@ class GlyphAtlas;
class SymbolBucket;
namespace style {
+class BucketParameters;
class Filter;
class Layer;
} // namespace style
@@ -28,15 +29,9 @@ struct Anchor;
class SymbolLayout {
public:
- SymbolLayout(std::vector<std::string> layerIDs_,
- std::string sourceLayerName_,
- uint32_t overscaling,
- float zoom,
- const MapMode,
+ SymbolLayout(const style::BucketParameters&,
+ const std::vector<const style::Layer*>&,
const GeometryTileLayer&,
- const style::Filter&,
- style::SymbolLayoutProperties::Evaluated,
- float textMaxSize,
SpriteAtlas&);
bool canPrepare(GlyphAtlas&);
@@ -56,8 +51,7 @@ public:
State state = Pending;
- const std::vector<std::string> layerIDs;
- const std::string sourceLayerName;
+ std::unordered_map<std::string, style::SymbolPaintProperties::Evaluated> layerPaintProperties;
private:
void addFeature(const SymbolFeature&,
@@ -75,11 +69,14 @@ private:
void addSymbols(Buffer&, const SymbolQuads&, float scale,
const bool keepUpright, const style::SymbolPlacementType, const float placementAngle);
+ const std::string sourceLayerName;
+ const std::string bucketName;
const float overscaling;
const float zoom;
const MapMode mode;
- const style::SymbolLayoutProperties::Evaluated layout;
- const float textMaxSize;
+
+ style::SymbolLayoutProperties::Evaluated layout;
+ float textMaxSize;
SpriteAtlas& spriteAtlas;
diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp
index 38bbe89377..c4cc5dea8b 100644
--- a/src/mbgl/programs/attributes.hpp
+++ b/src/mbgl/programs/attributes.hpp
@@ -1,22 +1,174 @@
#pragma once
#include <mbgl/gl/attribute.hpp>
+#include <mbgl/gl/uniform.hpp>
+#include <mbgl/gl/normalization.hpp>
#include <cstdint>
namespace mbgl {
namespace attributes {
-// Attributes common to several shaders.
+// Layout attributes
MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos);
-MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_offset);
MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude);
MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);
template <std::size_t N>
-struct a_data : gl::Attribute<a_data<N>, uint8_t, N> {
- static constexpr auto name = "a_data";
+struct a_data : gl::Attribute<uint8_t, N> {
+ static auto name() { return "a_data"; }
+};
+
+template <std::size_t N>
+struct a_offset : gl::Attribute<int16_t, N> {
+ static auto name() { return "a_offset"; }
+};
+
+// Paint attributes
+
+template <class Attr>
+struct Min : Attr {
+ static auto name() {
+ static const std::string name = Attr::name() + std::string("_min");
+ return name.c_str();
+ }
+};
+
+template <class Attr>
+struct Max : Attr {
+ static auto name() {
+ static const std::string name = Attr::name() + std::string("_max");
+ return name.c_str();
+ }
+};
+
+template <class Attr>
+struct InterpolationUniform : gl::UniformScalar<InterpolationUniform<Attr>, float> {
+ static auto name() {
+ static const std::string name = Attr::name() + std::string("_t");
+ return name.c_str();
+ }
+};
+
+struct a_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
+ static auto name() { return "a_color"; }
+
+ static Value value(const Color& color) {
+ return {{
+ gl::Normalized<uint8_t>(color.r),
+ gl::Normalized<uint8_t>(color.g),
+ gl::Normalized<uint8_t>(color.b),
+ gl::Normalized<uint8_t>(color.a)
+ }};
+ }
+};
+
+struct a_stroke_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
+ static auto name() { return "a_stroke_color"; }
+
+ static Value value(const Color& color) {
+ return {{
+ gl::Normalized<uint8_t>(color.r),
+ gl::Normalized<uint8_t>(color.g),
+ gl::Normalized<uint8_t>(color.b),
+ gl::Normalized<uint8_t>(color.a)
+ }};
+ }
+};
+
+struct a_outline_color : gl::Attribute<gl::Normalized<uint8_t>, 4> {
+ static auto name() { return "a_outline_color"; }
+
+ static Value value(const Color& color) {
+ return {{
+ gl::Normalized<uint8_t>(color.r),
+ gl::Normalized<uint8_t>(color.g),
+ gl::Normalized<uint8_t>(color.b),
+ gl::Normalized<uint8_t>(color.a)
+ }};
+ }
+};
+
+struct a_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> {
+ static auto name() { return "a_opacity"; }
+
+ static Value value(float opacity) {
+ return {{ gl::Normalized<uint8_t>(opacity) }};
+ }
+};
+
+struct a_stroke_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> {
+ static auto name() { return "a_stroke_opacity"; }
+
+ static Value value(float opacity) {
+ return {{ gl::Normalized<uint8_t>(opacity) }};
+ }
+};
+
+struct a_blur : gl::Attribute<float, 1> {
+ static auto name() { return "a_blur"; }
+
+ static Value value(float blur) {
+ return {{ blur }};
+ }
+};
+
+struct a_radius : gl::Attribute<float, 1> {
+ static auto name() { return "a_radius"; }
+
+ static Value value(float radius) {
+ return {{ radius }};
+ }
+};
+
+struct a_width : gl::Attribute<float, 1> {
+ static auto name() { return "a_width"; }
+
+ static Value value(float width) {
+ return {{ width }};
+ }
+};
+
+struct a_height : gl::Attribute<float, 1> {
+ static auto name() { return "a_height"; }
+
+ static Value value(float width) {
+ return {{ width }};
+ }
+};
+
+struct a_base : gl::Attribute<float, 1> {
+ static auto name() { return "a_base"; }
+
+ static Value value(float width) {
+ return {{ width }};
+ }
+};
+
+struct a_gap_width : gl::Attribute<float, 1> {
+ static auto name() { return "a_gapwidth"; }
+
+ static Value value(float width) {
+ return {{ width }};
+ }
+};
+
+struct a_stroke_width : gl::Attribute<float, 1> {
+ static auto name() { return "a_stroke_width"; }
+
+ static Value value(float width) {
+ return {{ width }};
+ }
+};
+
+template <>
+struct a_offset<1> : gl::Attribute<float, 1> {
+ static auto name() { return "a_offset"; }
+
+ static Value value(float offset) {
+ return {{ offset }};
+ }
};
} // namespace attributes
diff --git a/src/mbgl/programs/circle_program.cpp b/src/mbgl/programs/circle_program.cpp
index d6bc439feb..99b47dd5c0 100644
--- a/src/mbgl/programs/circle_program.cpp
+++ b/src/mbgl/programs/circle_program.cpp
@@ -2,6 +2,6 @@
namespace mbgl {
-static_assert(sizeof(CircleProgram::Vertex) == 4, "expected CircleVertex size");
+static_assert(sizeof(CircleLayoutVertex) == 4, "expected CircleLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/circle_program.hpp b/src/mbgl/programs/circle_program.hpp
index c9aea1d137..60a5faf649 100644
--- a/src/mbgl/programs/circle_program.hpp
+++ b/src/mbgl/programs/circle_program.hpp
@@ -5,35 +5,24 @@
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shader/circle.hpp>
#include <mbgl/util/geometry.hpp>
+#include <mbgl/style/layers/circle_layer_properties.hpp>
namespace mbgl {
namespace uniforms {
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_radius);
-MBGL_DEFINE_UNIFORM_SCALAR(Color, u_stroke_color);
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_width);
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_stroke_opacity);
MBGL_DEFINE_UNIFORM_SCALAR(bool, u_scale_with_map);
} // namespace uniforms
-using CircleAttributes = gl::Attributes<
- attributes::a_pos>;
-
class CircleProgram : public Program<
shaders::circle,
gl::Triangle,
- CircleAttributes,
+ gl::Attributes<
+ attributes::a_pos>,
gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_opacity,
- uniforms::u_color,
- uniforms::u_radius,
- uniforms::u_blur,
- uniforms::u_stroke_color,
- uniforms::u_stroke_width,
- uniforms::u_stroke_opacity,
uniforms::u_scale_with_map,
- uniforms::u_extrude_scale>>
+ uniforms::u_extrude_scale>,
+ style::CirclePaintProperties>
{
public:
using Program::Program;
@@ -44,16 +33,17 @@ public:
* @param {number} ex extrude normal
* @param {number} ey extrude normal
*/
- static Vertex vertex(Point<int16_t> p, float ex, float ey) {
- return Vertex {
- {
+ static LayoutVertex vertex(Point<int16_t> p, float ex, float ey) {
+ return LayoutVertex {
+ {{
static_cast<int16_t>((p.x * 2) + ((ex + 1) / 2)),
static_cast<int16_t>((p.y * 2) + ((ey + 1) / 2))
- }
+ }}
};
}
};
-using CircleVertex = CircleProgram::Vertex;
+using CircleLayoutVertex = CircleProgram::LayoutVertex;
+using CircleAttributes = CircleProgram::Attributes;
} // namespace mbgl
diff --git a/src/mbgl/programs/collision_box_program.cpp b/src/mbgl/programs/collision_box_program.cpp
index d6a36e54a1..a3dc01ebe4 100644
--- a/src/mbgl/programs/collision_box_program.cpp
+++ b/src/mbgl/programs/collision_box_program.cpp
@@ -2,6 +2,6 @@
namespace mbgl {
-static_assert(sizeof(CollisionBoxProgram::Vertex) == 10, "expected CollisionBoxVertex size");
+static_assert(sizeof(CollisionBoxProgram::LayoutVertex) == 10, "expected CollisionBoxVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp
index 26e38419a4..e59aa5ac8b 100644
--- a/src/mbgl/programs/collision_box_program.hpp
+++ b/src/mbgl/programs/collision_box_program.hpp
@@ -28,29 +28,30 @@ class CollisionBoxProgram : public Program<
uniforms::u_matrix,
uniforms::u_scale,
uniforms::u_zoom,
- uniforms::u_maxzoom>>
+ uniforms::u_maxzoom>,
+ style::PaintProperties<>>
{
public:
using Program::Program;
- static Vertex vertex(Point<float> a, Point<float> o, float maxzoom, float placementZoom) {
- return Vertex {
- {
+ static LayoutVertex vertex(Point<float> a, Point<float> o, float maxzoom, float placementZoom) {
+ return LayoutVertex {
+ {{
static_cast<int16_t>(a.x),
static_cast<int16_t>(a.y)
- },
- {
+ }},
+ {{
static_cast<int16_t>(::round(o.x)),
static_cast<int16_t>(::round(o.y))
- },
- {
+ }},
+ {{
static_cast<uint8_t>(maxzoom * 10),
static_cast<uint8_t>(placementZoom * 10)
- }
+ }}
};
}
};
-using CollisionBoxVertex = CollisionBoxProgram::Vertex;
+using CollisionBoxVertex = CollisionBoxProgram::LayoutVertex;
} // namespace mbgl
diff --git a/src/mbgl/programs/debug_program.hpp b/src/mbgl/programs/debug_program.hpp
index cd4e08b1bc..6b3b479d24 100644
--- a/src/mbgl/programs/debug_program.hpp
+++ b/src/mbgl/programs/debug_program.hpp
@@ -7,21 +7,21 @@
namespace mbgl {
-using DebugAttributes = gl::Attributes<
- attributes::a_pos>;
-
class DebugProgram : public Program<
shaders::debug,
gl::Line,
- DebugAttributes,
+ gl::Attributes<
+ attributes::a_pos>,
gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_color>>
+ uniforms::u_color>,
+ style::PaintProperties<>>
{
public:
using Program::Program;
};
-using DebugVertex = DebugProgram::Vertex;
+using DebugLayoutVertex = DebugProgram::LayoutVertex;
+using DebugAttributes = DebugProgram::Attributes;
} // namespace mbgl
diff --git a/src/mbgl/programs/fill_program.cpp b/src/mbgl/programs/fill_program.cpp
index a8154d08f9..6998d56232 100644
--- a/src/mbgl/programs/fill_program.cpp
+++ b/src/mbgl/programs/fill_program.cpp
@@ -8,11 +8,10 @@ namespace mbgl {
using namespace style;
-static_assert(sizeof(FillAttributes::Vertex) == 4, "expected FillVertex size");
+static_assert(sizeof(FillLayoutVertex) == 4, "expected FillLayoutVertex size");
FillPatternUniforms::Values
FillPatternUniforms::values(mat4 matrix,
- float opacity,
Size framebufferSize,
const SpriteAtlasPosition& a,
const SpriteAtlasPosition& b,
@@ -26,7 +25,6 @@ FillPatternUniforms::values(mat4 matrix,
return FillPatternUniforms::Values {
uniforms::u_matrix::Value{ matrix },
- uniforms::u_opacity::Value{ opacity },
uniforms::u_world::Value{ framebufferSize },
uniforms::u_pattern_tl_a::Value{ a.tl },
uniforms::u_pattern_br_a::Value{ a.br },
diff --git a/src/mbgl/programs/fill_program.hpp b/src/mbgl/programs/fill_program.hpp
index d885215c59..600e25bb46 100644
--- a/src/mbgl/programs/fill_program.hpp
+++ b/src/mbgl/programs/fill_program.hpp
@@ -10,6 +10,7 @@
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/mat4.hpp>
#include <mbgl/util/size.hpp>
+#include <mbgl/style/layers/fill_layer_properties.hpp>
#include <string>
@@ -25,7 +26,6 @@ template <class> class Faded;
namespace uniforms {
MBGL_DEFINE_UNIFORM_SCALAR(Size, u_world);
-MBGL_DEFINE_UNIFORM_SCALAR(Color, u_outline_color);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_scale_a);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_scale_b);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tile_units_to_pixels);
@@ -33,32 +33,17 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_pixel_coord_upper);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_pixel_coord_lower);
} // namespace uniforms
-struct FillAttributes : gl::Attributes<
+struct FillLayoutAttributes : gl::Attributes<
attributes::a_pos>
-{
- static Vertex vertex(Point<int16_t> p) {
- return Vertex {
- {
- p.x,
- p.y
- }
- };
- }
-};
-
-using FillVertex = FillAttributes::Vertex;
+{};
struct FillUniforms : gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_opacity,
- uniforms::u_color,
- uniforms::u_outline_color,
uniforms::u_world>
{};
struct FillPatternUniforms : gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_opacity,
uniforms::u_world,
uniforms::u_pattern_tl_a,
uniforms::u_pattern_br_a,
@@ -75,7 +60,6 @@ struct FillPatternUniforms : gl::Uniforms<
uniforms::u_tile_units_to_pixels>
{
static Values values(mat4 matrix,
- float opacity,
Size framebufferSize,
const SpriteAtlasPosition&,
const SpriteAtlasPosition&,
@@ -87,37 +71,57 @@ struct FillPatternUniforms : gl::Uniforms<
class FillProgram : public Program<
shaders::fill,
gl::Triangle,
- FillAttributes,
- FillUniforms>
+ FillLayoutAttributes,
+ FillUniforms,
+ style::FillPaintProperties>
{
+public:
using Program::Program;
+
+ static LayoutVertex layoutVertex(Point<int16_t> p) {
+ return LayoutVertex {
+ {{
+ p.x,
+ p.y
+ }}
+ };
+ }
};
class FillPatternProgram : public Program<
shaders::fill_pattern,
gl::Triangle,
- FillAttributes,
- FillPatternUniforms>
+ FillLayoutAttributes,
+ FillPatternUniforms,
+ style::FillPaintProperties>
{
+public:
using Program::Program;
};
class FillOutlineProgram : public Program<
shaders::fill_outline,
gl::Line,
- FillAttributes,
- FillUniforms>
+ FillLayoutAttributes,
+ FillUniforms,
+ style::FillPaintProperties>
{
+public:
using Program::Program;
};
class FillOutlinePatternProgram : public Program<
shaders::fill_outline_pattern,
gl::Line,
- FillAttributes,
- FillPatternUniforms>
+ FillLayoutAttributes,
+ FillPatternUniforms,
+ style::FillPaintProperties>
{
+public:
using Program::Program;
};
+using FillLayoutVertex = FillProgram::LayoutVertex;
+using FillAttributes = FillProgram::Attributes;
+
} // namespace mbgl
diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp
index f7054d3398..8a26c88aea 100644
--- a/src/mbgl/programs/line_program.cpp
+++ b/src/mbgl/programs/line_program.cpp
@@ -10,7 +10,7 @@ namespace mbgl {
using namespace style;
-static_assert(sizeof(LineAttributes::Vertex) == 8, "expected LineVertex size");
+static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size");
template <class Values, class...Args>
Values makeValues(const LinePaintProperties::Evaluated& properties,
@@ -25,11 +25,7 @@ Values makeValues(const LinePaintProperties::Evaluated& properties,
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_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
uniforms::u_gl_units_to_pixels::Value{{{ 1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1] }}},
std::forward<Args>(args)...
@@ -45,8 +41,7 @@ LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
properties,
tile,
state,
- pixelsToGLUnits,
- uniforms::u_color::Value{ properties.get<LineColor>() }
+ pixelsToGLUnits
);
}
@@ -78,7 +73,6 @@ LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
tile,
state,
pixelsToGLUnits,
- 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 },
diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp
index 4c2f76f402..f4e3fe3d50 100644
--- a/src/mbgl/programs/line_program.hpp
+++ b/src/mbgl/programs/line_program.hpp
@@ -6,8 +6,8 @@
#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 <mbgl/style/layers/line_layer_properties.hpp>
#include <cmath>
@@ -21,8 +21,6 @@ class SpriteAtlasPosition;
namespace uniforms {
MBGL_DEFINE_UNIFORM_SCALAR(float, u_ratio);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_width);
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_gapwidth);
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_a);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_b);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_sdfgamma);
@@ -32,23 +30,38 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_patternscale_b);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_gl_units_to_pixels);
} // namespace uniforms
-struct LineAttributes : gl::Attributes<
+struct LineLayoutAttributes : gl::Attributes<
attributes::a_pos,
attributes::a_data<4>>
+{};
+
+class LineProgram : public Program<
+ shaders::line,
+ gl::Triangle,
+ LineLayoutAttributes,
+ gl::Uniforms<
+ uniforms::u_matrix,
+ uniforms::u_width,
+ uniforms::u_ratio,
+ uniforms::u_gl_units_to_pixels>,
+ style::LinePaintProperties>
{
+public:
+ using Program::Program;
+
/*
* @param p vertex position
* @param e extrude normal
* @param t texture normal
* @param dir direction of the line cap (-1/0/1)
*/
- static Vertex vertex(Point<int16_t> p, Point<double> e, Point<bool> t, int8_t dir, int32_t linesofar = 0) {
- return Vertex {
- {
+ static LayoutVertex layoutVertex(Point<int16_t> p, Point<double> e, Point<bool> t, int8_t dir, int32_t linesofar = 0) {
+ return LayoutVertex {
+ {{
static_cast<int16_t>((p.x * 2) | t.x),
static_cast<int16_t>((p.y * 2) | t.y)
- },
- {
+ }},
+ {{
// add 128 to store a byte in an unsigned byte
static_cast<uint8_t>(::round(extrudeScale * e.x) + 128),
static_cast<uint8_t>(::round(extrudeScale * e.y) + 128),
@@ -65,7 +78,7 @@ struct LineAttributes : gl::Attributes<
// so we need to shift the linesofar.
static_cast<uint8_t>(((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2)),
static_cast<uint8_t>(linesofar >> 6)
- }
+ }}
};
}
@@ -77,27 +90,6 @@ struct LineAttributes : gl::Attributes<
* the acute/bevelled line join.
*/
static const int8_t extrudeScale = 63;
-};
-
-using LineVertex = LineAttributes::Vertex;
-
-class LineProgram : public Program<
- shaders::line,
- gl::Triangle,
- LineAttributes,
- gl::Uniforms<
- uniforms::u_matrix,
- uniforms::u_opacity,
- uniforms::u_width,
- uniforms::u_gapwidth,
- uniforms::u_blur,
- uniforms::u_offset,
- uniforms::u_ratio,
- uniforms::u_gl_units_to_pixels,
- uniforms::u_color>>
-{
-public:
- using Program::Program;
static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
const RenderTile&,
@@ -108,14 +100,10 @@ public:
class LinePatternProgram : public Program<
shaders::line_pattern,
gl::Triangle,
- LineAttributes,
+ LineLayoutAttributes,
gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_opacity,
uniforms::u_width,
- uniforms::u_gapwidth,
- uniforms::u_blur,
- uniforms::u_offset,
uniforms::u_ratio,
uniforms::u_gl_units_to_pixels,
uniforms::u_pattern_tl_a,
@@ -125,7 +113,8 @@ class LinePatternProgram : public Program<
uniforms::u_pattern_size_a,
uniforms::u_pattern_size_b,
uniforms::u_fade,
- uniforms::u_image>>
+ uniforms::u_image>,
+ style::LinePaintProperties>
{
public:
using Program::Program;
@@ -141,24 +130,20 @@ public:
class LineSDFProgram : public Program<
shaders::line_sdf,
gl::Triangle,
- LineAttributes,
+ LineLayoutAttributes,
gl::Uniforms<
uniforms::u_matrix,
- uniforms::u_opacity,
uniforms::u_width,
- uniforms::u_gapwidth,
- uniforms::u_blur,
- uniforms::u_offset,
uniforms::u_ratio,
uniforms::u_gl_units_to_pixels,
- uniforms::u_color,
uniforms::u_patternscale_a,
uniforms::u_patternscale_b,
uniforms::u_tex_y_a,
uniforms::u_tex_y_b,
uniforms::u_mix,
uniforms::u_sdfgamma,
- uniforms::u_image>>
+ uniforms::u_image>,
+ style::LinePaintProperties>
{
public:
using Program::Program;
@@ -174,4 +159,7 @@ public:
float atlasWidth);
};
+using LineLayoutVertex = LineProgram::LayoutVertex;
+using LineAttributes = LineProgram::Attributes;
+
} // namespace mbgl
diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp
index 85902d3351..e75dbebf18 100644
--- a/src/mbgl/programs/program.hpp
+++ b/src/mbgl/programs/program.hpp
@@ -2,19 +2,38 @@
#include <mbgl/gl/program.hpp>
#include <mbgl/programs/program_parameters.hpp>
+#include <mbgl/programs/attributes.hpp>
+#include <mbgl/style/paint_property.hpp>
#include <sstream>
#include <cassert>
namespace mbgl {
-template <class Shaders, class Primitive, class Attributes, class Uniforms>
-class Program : public gl::Program<Primitive, Attributes, Uniforms> {
+template <class Shaders,
+ class Primitive,
+ class LayoutAttrs,
+ class Uniforms,
+ class PaintProperties>
+class Program {
public:
- using ParentType = gl::Program<Primitive, Attributes, Uniforms>;
+ using LayoutAttributes = LayoutAttrs;
+ using LayoutVertex = typename LayoutAttributes::Vertex;
+
+ using PaintPropertyBinders = typename PaintProperties::Binders;
+ using PaintAttributes = typename PaintPropertyBinders::Attributes;
+ using Attributes = gl::ConcatenateAttributes<LayoutAttributes, PaintAttributes>;
+
+ using UniformValues = typename Uniforms::Values;
+ using PaintUniforms = typename PaintPropertyBinders::Uniforms;
+ using AllUniforms = gl::ConcatenateUniforms<Uniforms, PaintUniforms>;
+
+ using ProgramType = gl::Program<Primitive, Attributes, AllUniforms>;
+
+ ProgramType program;
Program(gl::Context& context, const ProgramParameters& programParameters)
- : ParentType(context, vertexSource(programParameters), fragmentSource(programParameters))
+ : program(context, vertexSource(programParameters), fragmentSource(programParameters))
{}
static std::string pixelRatioDefine(const ProgramParameters& parameters) {
@@ -38,6 +57,33 @@ public:
return pixelRatioDefine(parameters) + Shaders::vertexSource;
}
+ template <class DrawMode>
+ void draw(gl::Context& context,
+ DrawMode drawMode,
+ gl::DepthMode depthMode,
+ gl::StencilMode stencilMode,
+ gl::ColorMode colorMode,
+ UniformValues&& uniformValues,
+ const gl::VertexBuffer<LayoutVertex>& layoutVertexBuffer,
+ const gl::IndexBuffer<DrawMode>& indexBuffer,
+ const gl::SegmentVector<Attributes>& segments,
+ const PaintPropertyBinders& paintPropertyBinders,
+ const typename PaintProperties::Evaluated& currentProperties,
+ float currentZoom) {
+ program.draw(
+ context,
+ std::move(drawMode),
+ std::move(depthMode),
+ std::move(stencilMode),
+ std::move(colorMode),
+ uniformValues
+ .concat(paintPropertyBinders.uniformValues(currentZoom)),
+ LayoutAttributes::allVariableBindings(layoutVertexBuffer)
+ .concat(paintPropertyBinders.attributeBindings(currentProperties)),
+ indexBuffer,
+ segments
+ );
+ }
};
} // namespace mbgl
diff --git a/src/mbgl/programs/raster_program.cpp b/src/mbgl/programs/raster_program.cpp
index ebec4c68cc..6906903e6b 100644
--- a/src/mbgl/programs/raster_program.cpp
+++ b/src/mbgl/programs/raster_program.cpp
@@ -2,6 +2,6 @@
namespace mbgl {
-static_assert(sizeof(RasterProgram::Vertex) == 8, "expected RasterVertex size");
+static_assert(sizeof(RasterLayoutVertex) == 8, "expected RasterLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/raster_program.hpp b/src/mbgl/programs/raster_program.hpp
index 9aa25cf90c..7b4c3842be 100644
--- a/src/mbgl/programs/raster_program.hpp
+++ b/src/mbgl/programs/raster_program.hpp
@@ -5,6 +5,7 @@
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shader/raster.hpp>
#include <mbgl/util/geometry.hpp>
+#include <mbgl/style/layers/raster_layer_properties.hpp>
namespace mbgl {
@@ -22,14 +23,12 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 3, u_spin_weights);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_tl_parent);
} // namespace uniforms
-using RasterAttributes = gl::Attributes<
- attributes::a_pos,
- attributes::a_texture_pos>;
-
class RasterProgram : public Program<
shaders::raster,
gl::Triangle,
- RasterAttributes,
+ gl::Attributes<
+ attributes::a_pos,
+ attributes::a_texture_pos>,
gl::Uniforms<
uniforms::u_matrix,
uniforms::u_image0,
@@ -43,25 +42,27 @@ class RasterProgram : public Program<
uniforms::u_spin_weights,
uniforms::u_buffer_scale,
uniforms::u_scale_parent,
- uniforms::u_tl_parent>>
+ uniforms::u_tl_parent>,
+ style::RasterPaintProperties>
{
public:
using Program::Program;
- static Vertex vertex(Point<int16_t> p, Point<uint16_t> t) {
- return Vertex {
- {
+ static LayoutVertex layoutVertex(Point<int16_t> p, Point<uint16_t> t) {
+ return LayoutVertex {
+ {{
p.x,
p.y
- },
- {
+ }},
+ {{
t.x,
t.y
- }
+ }}
};
}
};
-using RasterVertex = RasterProgram::Vertex;
+using RasterLayoutVertex = RasterProgram::LayoutVertex;
+using RasterAttributes = RasterProgram::Attributes;
} // namespace mbgl
diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp
index d609dada8d..3f59000b94 100644
--- a/src/mbgl/programs/symbol_program.cpp
+++ b/src/mbgl/programs/symbol_program.cpp
@@ -7,7 +7,7 @@ namespace mbgl {
using namespace style;
-static_assert(sizeof(SymbolAttributes::Vertex) == 16, "expected SymbolVertex size");
+static_assert(sizeof(SymbolLayoutVertex) == 16, "expected SymbolLayoutVertex size");
template <class Values, class...Args>
Values makeValues(const style::SymbolPropertyValues& values,
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index be987551c0..0130255356 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -7,6 +7,7 @@
#include <mbgl/shader/symbol_sdf.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/size.hpp>
+#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <cmath>
#include <array>
@@ -31,9 +32,9 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_gamma);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_aspect_ratio);
} // namespace uniforms
-struct SymbolAttributes : gl::Attributes<
+struct SymbolLayoutAttributes : gl::Attributes<
attributes::a_pos,
- attributes::a_offset,
+ attributes::a_offset<2>,
attributes::a_texture_pos,
attributes::a_data<4>>
{
@@ -46,34 +47,32 @@ struct SymbolAttributes : gl::Attributes<
float labelminzoom,
uint8_t labelangle) {
return Vertex {
- {
+ {{
static_cast<int16_t>(a.x),
static_cast<int16_t>(a.y)
- },
- {
+ }},
+ {{
static_cast<int16_t>(::round(o.x * 64)), // use 1/64 pixels for placement
static_cast<int16_t>(::round(o.y * 64))
- },
- {
+ }},
+ {{
static_cast<uint16_t>(tx / 4),
static_cast<uint16_t>(ty / 4)
- },
- {
+ }},
+ {{
static_cast<uint8_t>(labelminzoom * 10), // 1/10 zoom levels: z16 == 160
static_cast<uint8_t>(labelangle),
static_cast<uint8_t>(minzoom * 10),
static_cast<uint8_t>(::fmin(maxzoom, 25) * 10)
- }
+ }}
};
}
};
-using SymbolVertex = SymbolAttributes::Vertex;
-
class SymbolIconProgram : public Program<
shaders::symbol_icon,
gl::Triangle,
- SymbolAttributes,
+ SymbolLayoutAttributes,
gl::Uniforms<
uniforms::u_matrix,
uniforms::u_opacity,
@@ -82,7 +81,8 @@ class SymbolIconProgram : public Program<
uniforms::u_zoom,
uniforms::u_rotate_with_map,
uniforms::u_texture,
- uniforms::u_fadetexture>>
+ uniforms::u_fadetexture>,
+ style::SymbolPaintProperties>
{
public:
using Program::Program;
@@ -97,7 +97,7 @@ public:
class SymbolSDFProgram : public Program<
shaders::symbol_sdf,
gl::Triangle,
- SymbolAttributes,
+ SymbolLayoutAttributes,
gl::Uniforms<
uniforms::u_matrix,
uniforms::u_opacity,
@@ -113,7 +113,8 @@ class SymbolSDFProgram : public Program<
uniforms::u_pitch,
uniforms::u_bearing,
uniforms::u_aspect_ratio,
- uniforms::u_pitch_with_map>>
+ uniforms::u_pitch_with_map>,
+ style::SymbolPaintProperties>
{
public:
using Program::Program;
@@ -133,4 +134,7 @@ public:
float pixelRatio);
};
+using SymbolLayoutVertex = SymbolLayoutAttributes::Vertex;
+using SymbolAttributes = SymbolIconProgram::Attributes;
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp
index 49619c14f7..294e50dd8c 100644
--- a/src/mbgl/renderer/bucket.hpp
+++ b/src/mbgl/renderer/bucket.hpp
@@ -2,6 +2,7 @@
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/tile/geometry_tile_data.hpp>
#include <atomic>
@@ -22,6 +23,10 @@ class Layer;
class Bucket : private util::noncopyable {
public:
Bucket() = default;
+ virtual ~Bucket() = default;
+
+ virtual void addFeature(const GeometryTileFeature&,
+ const GeometryCollection&) {};
// As long as this bucket has a Prepare render pass, this function is getting called. Typically,
// this only happens once when the bucket is being rendered for the first time.
@@ -31,8 +36,6 @@ public:
// once or twice (for Opaque and Transparent render passes).
virtual void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) = 0;
- virtual ~Bucket() = default;
-
virtual bool hasData() const = 0;
bool needsUpload() const {
diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp
index d3ce8405d0..6722d04497 100644
--- a/src/mbgl/renderer/circle_bucket.cpp
+++ b/src/mbgl/renderer/circle_bucket.cpp
@@ -1,21 +1,33 @@
#include <mbgl/renderer/circle_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
-#include <mbgl/gl/context.hpp>
-
#include <mbgl/programs/circle_program.hpp>
+#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
+#include <mbgl/style/layers/circle_layer_impl.hpp>
#include <mbgl/util/constants.hpp>
namespace mbgl {
using namespace style;
-CircleBucket::CircleBucket(MapMode mode_) : mode(mode_) {
+CircleBucket::CircleBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers)
+ : mode(parameters.mode) {
+ for (const auto& layer : layers) {
+ paintPropertyBinders.emplace(layer->getID(),
+ CircleProgram::PaintPropertyBinders(
+ layer->as<CircleLayer>()->impl->paint.evaluated,
+ parameters.tileID.overscaledZ));
+ }
}
void CircleBucket::upload(gl::Context& context) {
vertexBuffer = context.createVertexBuffer(std::move(vertices));
indexBuffer = context.createIndexBuffer(std::move(triangles));
+
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.upload(context);
+ }
+
uploaded = true;
}
@@ -30,10 +42,11 @@ bool CircleBucket::hasData() const {
return !segments.empty();
}
-void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
+void CircleBucket::addFeature(const GeometryTileFeature& feature,
+ const GeometryCollection& geometry) {
constexpr const uint16_t vertexLength = 4;
- for (auto& circle : geometryCollection) {
+ for (auto& circle : geometry) {
for(auto& point : circle) {
auto x = point.x;
auto y = point.y;
@@ -76,6 +89,10 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
segment.indexLength += 6;
}
}
+
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.populateVertexVectors(feature, vertices.vertexSize());
+ }
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp
index af7041a238..412db53f65 100644
--- a/src/mbgl/renderer/circle_bucket.hpp
+++ b/src/mbgl/renderer/circle_bucket.hpp
@@ -7,26 +7,34 @@
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gl/segment.hpp>
#include <mbgl/programs/circle_program.hpp>
+#include <mbgl/style/layers/circle_layer_properties.hpp>
namespace mbgl {
+namespace style {
+class BucketParameters;
+} // namespace style
+
class CircleBucket : public Bucket {
public:
- CircleBucket(const MapMode);
+ CircleBucket(const style::BucketParameters&, const std::vector<const style::Layer*>&);
+
+ void addFeature(const GeometryTileFeature&,
+ const GeometryCollection&) override;
+ bool hasData() const override;
void upload(gl::Context&) override;
void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
- bool hasData() const override;
- void addGeometry(const GeometryCollection&);
-
- gl::VertexVector<CircleVertex> vertices;
+ gl::VertexVector<CircleLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<CircleAttributes> segments;
- optional<gl::VertexBuffer<CircleVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<CircleLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
+ std::unordered_map<std::string, CircleProgram::PaintPropertyBinders> paintPropertyBinders;
+
const MapMode mode;
};
diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp
index 167df4376f..2a514989cf 100644
--- a/src/mbgl/renderer/debug_bucket.cpp
+++ b/src/mbgl/renderer/debug_bucket.cpp
@@ -23,7 +23,7 @@ DebugBucket::DebugBucket(const OverscaledTileID& id,
expires(std::move(expires_)),
debugMode(debugMode_) {
- gl::VertexVector<FillVertex> vertices;
+ gl::VertexVector<FillLayoutVertex> vertices;
gl::IndexVector<gl::Lines> indices;
auto addText = [&] (const std::string& text, double left, double baseline, double scale) {
@@ -43,7 +43,7 @@ DebugBucket::DebugBucket(const OverscaledTileID& id,
int16_t(::round(baseline - glyph.data[j + 1] * scale))
};
- vertices.emplace_back(FillAttributes::vertex(p));
+ vertices.emplace_back(FillProgram::layoutVertex(p));
if (prev) {
indices.emplace_back(vertices.vertexSize() - 2,
diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp
index 4676381789..756e58a6de 100644
--- a/src/mbgl/renderer/debug_bucket.hpp
+++ b/src/mbgl/renderer/debug_bucket.hpp
@@ -34,7 +34,7 @@ public:
const MapDebugOptions debugMode;
gl::SegmentVector<DebugAttributes> segments;
- optional<gl::VertexBuffer<DebugVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<DebugLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Lines>> indexBuffer;
};
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp
index b89e982057..64efafb108 100644
--- a/src/mbgl/renderer/fill_bucket.cpp
+++ b/src/mbgl/renderer/fill_bucket.cpp
@@ -1,8 +1,9 @@
#include <mbgl/renderer/fill_bucket.hpp>
-#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/programs/fill_program.hpp>
-#include <mbgl/util/logging.hpp>
+#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/style/layers/fill_layer.hpp>
+#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mapbox/earcut.hpp>
@@ -26,7 +27,17 @@ using namespace style;
struct GeometryTooLongException : std::exception {};
-void FillBucket::addGeometry(const GeometryCollection& geometry) {
+FillBucket::FillBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) {
+ for (const auto& layer : layers) {
+ paintPropertyBinders.emplace(layer->getID(),
+ FillProgram::PaintPropertyBinders(
+ layer->as<FillLayer>()->impl->paint.evaluated,
+ parameters.tileID.overscaledZ));
+ }
+}
+
+void FillBucket::addFeature(const GeometryTileFeature& feature,
+ const GeometryCollection& geometry) {
for (auto& polygon : classifyRings(geometry)) {
// Optimize polygons with many interior rings for earcut tesselation.
limitHoles(polygon, 500);
@@ -55,11 +66,11 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
assert(lineSegment.vertexLength <= std::numeric_limits<uint16_t>::max());
uint16_t lineIndex = lineSegment.vertexLength;
- vertices.emplace_back(FillAttributes::vertex(ring[0]));
+ vertices.emplace_back(FillProgram::layoutVertex(ring[0]));
lines.emplace_back(lineIndex + nVertices - 1, lineIndex);
for (uint32_t i = 1; i < nVertices; i++) {
- vertices.emplace_back(FillAttributes::vertex(ring[i]));
+ vertices.emplace_back(FillProgram::layoutVertex(ring[i]));
lines.emplace_back(lineIndex + i - 1, lineIndex + i);
}
@@ -89,6 +100,10 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
triangleSegment.vertexLength += totalVertices;
triangleSegment.indexLength += nIndicies;
}
+
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.populateVertexVectors(feature, vertices.vertexSize());
+ }
}
void FillBucket::upload(gl::Context& context) {
@@ -96,7 +111,10 @@ void FillBucket::upload(gl::Context& context) {
lineIndexBuffer = context.createIndexBuffer(std::move(lines));
triangleIndexBuffer = context.createIndexBuffer(std::move(triangles));
- // From now on, we're going to render during the opaque and translucent pass.
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.upload(context);
+ }
+
uploaded = true;
}
diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp
index edb1521c1d..b403e1053b 100644
--- a/src/mbgl/renderer/fill_bucket.hpp
+++ b/src/mbgl/renderer/fill_bucket.hpp
@@ -6,28 +6,38 @@
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gl/segment.hpp>
#include <mbgl/programs/fill_program.hpp>
+#include <mbgl/style/layers/fill_layer_properties.hpp>
#include <vector>
namespace mbgl {
+namespace style {
+class BucketParameters;
+} // namespace style
+
class FillBucket : public Bucket {
public:
- void upload(gl::Context&) override;
- void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
+ FillBucket(const style::BucketParameters&, const std::vector<const style::Layer*>&);
+
+ void addFeature(const GeometryTileFeature&,
+ const GeometryCollection&) override;
bool hasData() const override;
- void addGeometry(const GeometryCollection&);
+ void upload(gl::Context&) override;
+ void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
- gl::VertexVector<FillVertex> vertices;
+ gl::VertexVector<FillLayoutVertex> vertices;
gl::IndexVector<gl::Lines> lines;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<FillAttributes> lineSegments;
gl::SegmentVector<FillAttributes> triangleSegments;
- optional<gl::VertexBuffer<FillVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<FillLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Lines>> lineIndexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> triangleIndexBuffer;
+
+ std::unordered_map<std::string, FillProgram::PaintPropertyBinders> paintPropertyBinders;
};
} // namespace mbgl
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 6921b364d8..50a70c0fd4 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -1,6 +1,8 @@
#include <mbgl/renderer/line_bucket.hpp>
-#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/renderer/painter.hpp>
+#include <mbgl/style/layers/line_layer.hpp>
+#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/style/layers/line_layer_impl.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/constants.hpp>
@@ -10,19 +12,29 @@ namespace mbgl {
using namespace style;
-LineBucket::LineBucket(uint32_t overscaling_) : overscaling(overscaling_) {
-}
-
-LineBucket::~LineBucket() {
- // Do not remove. header file only contains forward definitions to unique pointers.
+LineBucket::LineBucket(const BucketParameters& parameters,
+ const std::vector<const Layer*>& layers,
+ const style::LineLayoutProperties& layout_)
+ : layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))),
+ overscaling(parameters.tileID.overscaleFactor()) {
+ for (const auto& layer : layers) {
+ paintPropertyBinders.emplace(layer->getID(),
+ LineProgram::PaintPropertyBinders(
+ layer->as<LineLayer>()->impl->paint.evaluated,
+ parameters.tileID.overscaledZ));
+ }
}
-void LineBucket::addGeometry(const GeometryCollection& geometryCollection) {
+void LineBucket::addFeature(const GeometryTileFeature& feature,
+ const GeometryCollection& geometryCollection) {
for (auto& line : geometryCollection) {
addGeometry(line);
}
-}
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.populateVertexVectors(feature, vertices.vertexSize());
+ }
+}
/*
* Sharp corners cause dashed lines to tilt because the distance along the line
@@ -383,7 +395,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
Point<double> extrude = normal;
if (endLeft)
extrude = extrude - (util::perp(normal) * endLeft);
- vertices.emplace_back(LineAttributes::vertex(currentCoordinate, extrude, { round, false }, endLeft, distance * LINE_DISTANCE_SCALE));
+ vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, false }, endLeft, distance * LINE_DISTANCE_SCALE));
e3 = vertices.vertexSize() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
@@ -394,7 +406,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate,
extrude = normal * -1.0;
if (endRight)
extrude = extrude - (util::perp(normal) * endRight);
- vertices.emplace_back(LineAttributes::vertex(currentCoordinate, extrude, { round, true }, -endRight, distance * LINE_DISTANCE_SCALE));
+ vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, true }, -endRight, distance * LINE_DISTANCE_SCALE));
e3 = vertices.vertexSize() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
@@ -419,7 +431,7 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex,
std::size_t startVertex,
std::vector<TriangleElement>& triangleStore) {
Point<double> flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0);
- vertices.emplace_back(LineAttributes::vertex(currentVertex, flippedExtrude, { false, lineTurnsLeft }, 0, distance * LINE_DISTANCE_SCALE));
+ vertices.emplace_back(LineProgram::layoutVertex(currentVertex, flippedExtrude, { false, lineTurnsLeft }, 0, distance * LINE_DISTANCE_SCALE));
e3 = vertices.vertexSize() - 1 - startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
@@ -436,7 +448,10 @@ void LineBucket::upload(gl::Context& context) {
vertexBuffer = context.createVertexBuffer(std::move(vertices));
indexBuffer = context.createIndexBuffer(std::move(triangles));
- // From now on, we're only going to render during the translucent pass.
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.upload(context);
+ }
+
uploaded = true;
}
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index d11d78ff69..78293d75f9 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -12,28 +12,37 @@
namespace mbgl {
+namespace style {
+class BucketParameters;
+} // namespace style
+
class LineBucket : public Bucket {
public:
- LineBucket(uint32_t overscaling);
- ~LineBucket() override;
+ LineBucket(const style::BucketParameters&,
+ const std::vector<const style::Layer*>&,
+ const style::LineLayoutProperties&);
- void upload(gl::Context&) override;
- void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
+ void addFeature(const GeometryTileFeature&,
+ const GeometryCollection&) override;
bool hasData() const override;
- void addGeometry(const GeometryCollection&);
- void addGeometry(const GeometryCoordinates& line);
+ void upload(gl::Context&) override;
+ void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
style::LineLayoutProperties::Evaluated layout;
- gl::VertexVector<LineVertex> vertices;
+ gl::VertexVector<LineLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<LineAttributes> segments;
- optional<gl::VertexBuffer<LineVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<LineLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
+ std::unordered_map<std::string, LineProgram::PaintPropertyBinders> paintPropertyBinders;
+
private:
+ void addGeometry(const GeometryCoordinates& line);
+
struct TriangleElement {
TriangleElement(uint16_t a_, uint16_t b_, uint16_t c_) : a(a_), b(b_), c(c_) {}
uint16_t a, b, c;
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 2e16777cdb..27d24d14a9 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -42,12 +42,12 @@ namespace mbgl {
using namespace style;
-static gl::VertexVector<FillVertex> tileVertices() {
- gl::VertexVector<FillVertex> result;
- result.emplace_back(FillAttributes::vertex({ 0, 0 }));
- result.emplace_back(FillAttributes::vertex({ util::EXTENT, 0 }));
- result.emplace_back(FillAttributes::vertex({ 0, util::EXTENT }));
- result.emplace_back(FillAttributes::vertex({ util::EXTENT, util::EXTENT }));
+static gl::VertexVector<FillLayoutVertex> tileVertices() {
+ gl::VertexVector<FillLayoutVertex> result;
+ result.emplace_back(FillProgram::layoutVertex({ 0, 0 }));
+ result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, 0 }));
+ result.emplace_back(FillProgram::layoutVertex({ 0, util::EXTENT }));
+ result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, util::EXTENT }));
return result;
}
@@ -68,12 +68,12 @@ static gl::IndexVector<gl::LineStrip> tileLineStripIndices() {
return result;
}
-static gl::VertexVector<RasterVertex> rasterVertices() {
- gl::VertexVector<RasterVertex> result;
- result.emplace_back(RasterProgram::vertex({ 0, 0 }, { 0, 0 }));
- result.emplace_back(RasterProgram::vertex({ util::EXTENT, 0 }, { 32767, 0 }));
- result.emplace_back(RasterProgram::vertex({ 0, util::EXTENT }, { 0, 32767 }));
- result.emplace_back(RasterProgram::vertex({ util::EXTENT, util::EXTENT }, { 32767, 32767 }));
+static gl::VertexVector<RasterLayoutVertex> rasterVertices() {
+ gl::VertexVector<RasterLayoutVertex> result;
+ result.emplace_back(RasterProgram::layoutVertex({ 0, 0 }, { 0, 0 }));
+ result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, 0 }, { 32767, 0 }));
+ result.emplace_back(RasterProgram::layoutVertex({ 0, util::EXTENT }, { 0, 32767 }));
+ result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, util::EXTENT }, { 32767, 32767 }));
return result;
}
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index dec7fa57fd..91f329a6eb 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -158,8 +158,8 @@ private:
std::unique_ptr<Programs> overdrawPrograms;
#endif
- gl::VertexBuffer<FillVertex> tileVertexBuffer;
- gl::VertexBuffer<RasterVertex> rasterVertexBuffer;
+ gl::VertexBuffer<FillLayoutVertex> tileVertexBuffer;
+ gl::VertexBuffer<RasterLayoutVertex> rasterVertexBuffer;
gl::IndexBuffer<gl::Triangles> tileTriangleIndexBuffer;
gl::IndexBuffer<gl::LineStrip> tileBorderIndexBuffer;
diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp
index 4a3e41701d..e8a5342f4a 100644
--- a/src/mbgl/renderer/painter_background.cpp
+++ b/src/mbgl/renderer/painter_background.cpp
@@ -14,13 +14,20 @@ using namespace style;
void Painter::renderBackground(PaintParameters& parameters, const BackgroundLayer& layer) {
// Note that for bottommost layers without a pattern, the background color is drawn with
// glClear rather than this method.
- const BackgroundPaintProperties::Evaluated& properties = layer.impl->paint.evaluated;
+ const BackgroundPaintProperties::Evaluated& background = layer.impl->paint.evaluated;
- if (!properties.get<BackgroundPattern>().to.empty()) {
+ style::FillPaintProperties::Evaluated properties;
+ properties.get<FillPattern>() = background.get<BackgroundPattern>();
+ properties.get<FillOpacity>() = { background.get<BackgroundOpacity>() };
+ properties.get<FillColor>() = { background.get<BackgroundColor>() };
+
+ const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0);
+
+ if (!background.get<BackgroundPattern>().to.empty()) {
optional<SpriteAtlasPosition> imagePosA = spriteAtlas->getPosition(
- properties.get<BackgroundPattern>().from, SpritePatternMode::Repeating);
+ background.get<BackgroundPattern>().from, SpritePatternMode::Repeating);
optional<SpriteAtlasPosition> imagePosB = spriteAtlas->getPosition(
- properties.get<BackgroundPattern>().to, SpritePatternMode::Repeating);
+ background.get<BackgroundPattern>().to, SpritePatternMode::Repeating);
if (!imagePosA || !imagePosB)
return;
@@ -36,17 +43,19 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye
colorModeForRenderPass(),
FillPatternUniforms::values(
matrixForTile(tileID),
- properties.get<BackgroundOpacity>(),
context.viewport.getCurrentValue().size,
*imagePosA,
*imagePosB,
- properties.get<BackgroundPattern>(),
+ background.get<BackgroundPattern>(),
tileID,
state
),
tileVertexBuffer,
tileTriangleIndexBuffer,
- tileTriangleSegments
+ tileTriangleSegments,
+ paintAttibuteData,
+ properties,
+ state.getZoom()
);
}
} else {
@@ -59,14 +68,14 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye
colorModeForRenderPass(),
FillProgram::UniformValues {
uniforms::u_matrix::Value{ matrixForTile(tileID) },
- uniforms::u_opacity::Value{ properties.get<BackgroundOpacity>() },
- uniforms::u_color::Value{ properties.get<BackgroundColor>() },
- uniforms::u_outline_color::Value{ properties.get<BackgroundColor>() },
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
},
tileVertexBuffer,
tileTriangleIndexBuffer,
- tileTriangleSegments
+ tileTriangleSegments,
+ paintAttibuteData,
+ properties,
+ state.getZoom()
);
}
}
diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp
index 966d58b59b..8d47e75f71 100644
--- a/src/mbgl/renderer/painter_circle.cpp
+++ b/src/mbgl/renderer/painter_circle.cpp
@@ -37,13 +37,6 @@ void Painter::renderCircle(PaintParameters& parameters,
properties.get<CircleTranslateAnchor>(),
state)
},
- uniforms::u_opacity::Value{ properties.get<CircleOpacity>() },
- uniforms::u_color::Value{ properties.get<CircleColor>() },
- uniforms::u_radius::Value{ properties.get<CircleRadius>() },
- uniforms::u_blur::Value{ properties.get<CircleBlur>() },
- uniforms::u_stroke_color::Value{ properties.get<CircleStrokeColor>() },
- uniforms::u_stroke_width::Value{ properties.get<CircleStrokeWidth>() },
- uniforms::u_stroke_opacity::Value{ properties.get<CircleStrokeOpacity>() },
uniforms::u_scale_with_map::Value{ scaleWithMap },
uniforms::u_extrude_scale::Value{ scaleWithMap
? std::array<float, 2> {{
@@ -54,7 +47,10 @@ void Painter::renderCircle(PaintParameters& parameters,
},
*bucket.vertexBuffer,
*bucket.indexBuffer,
- bucket.segments
+ bucket.segments,
+ bucket.paintPropertyBinders.at(layer.getID()),
+ properties,
+ state.getZoom()
);
}
diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp
index a2529561fe..70df9837e8 100644
--- a/src/mbgl/renderer/painter_clipping.cpp
+++ b/src/mbgl/renderer/painter_clipping.cpp
@@ -6,6 +6,8 @@
namespace mbgl {
void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& clip) {
+ static const style::FillPaintProperties::Evaluated properties {};
+ static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0);
programs->fill.draw(
context,
gl::Triangles(),
@@ -21,14 +23,14 @@ void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& cl
gl::ColorMode::disabled(),
FillProgram::UniformValues {
uniforms::u_matrix::Value{ matrixForTile(tileID) },
- uniforms::u_opacity::Value{ 0.0f },
- uniforms::u_color::Value{ Color {} },
- uniforms::u_outline_color::Value{ Color {} },
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
},
tileVertexBuffer,
tileTriangleIndexBuffer,
- tileTriangleSegments
+ tileTriangleSegments,
+ paintAttibuteData,
+ properties,
+ state.getZoom()
);
}
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index 2b838dec0e..5b347884bf 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -12,12 +12,17 @@
namespace mbgl {
+using namespace style;
+
void Painter::renderTileDebug(const RenderTile& renderTile) {
if (frame.debugOptions == MapDebugOptions::NoDebug)
return;
MBGL_DEBUG_GROUP(std::string { "debug " } + util::toString(renderTile.id));
+ static const style::PaintProperties<>::Evaluated properties {};
+ static const DebugProgram::PaintPropertyBinders paintAttibuteData(properties, 0);
+
auto draw = [&] (Color color, const auto& vertexBuffer, const auto& indexBuffer, const auto& segments, auto drawMode) {
programs->debug.draw(
context,
@@ -31,7 +36,10 @@ void Painter::renderTileDebug(const RenderTile& renderTile) {
},
vertexBuffer,
indexBuffer,
- segments
+ segments,
+ paintAttibuteData,
+ properties,
+ state.getZoom()
);
};
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index f4e73f94ac..d98cb2b57c 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -38,7 +38,6 @@ void Painter::renderFill(PaintParameters& parameters,
auto draw = [&] (uint8_t sublayer,
auto& program,
const auto& drawMode,
- const auto& vertexBuffer,
const auto& indexBuffer,
const auto& segments) {
program.draw(
@@ -51,7 +50,6 @@ void Painter::renderFill(PaintParameters& parameters,
tile.translatedMatrix(properties.get<FillTranslate>(),
properties.get<FillTranslateAnchor>(),
state),
- properties.get<FillOpacity>(),
context.viewport.getCurrentValue().size,
*imagePosA,
*imagePosB,
@@ -59,16 +57,18 @@ void Painter::renderFill(PaintParameters& parameters,
tile.id,
state
),
- vertexBuffer,
+ *bucket.vertexBuffer,
indexBuffer,
- segments
+ segments,
+ bucket.paintPropertyBinders.at(layer.getID()),
+ properties,
+ state.getZoom()
);
};
draw(0,
parameters.programs.fillPattern,
gl::Triangles(),
- *bucket.vertexBuffer,
*bucket.triangleIndexBuffer,
bucket.triangleSegments);
@@ -79,14 +79,12 @@ void Painter::renderFill(PaintParameters& parameters,
draw(2,
parameters.programs.fillOutlinePattern,
gl::Lines { 2.0f },
- *bucket.vertexBuffer,
*bucket.lineIndexBuffer,
bucket.lineSegments);
} else {
auto draw = [&] (uint8_t sublayer,
auto& program,
const auto& drawMode,
- const auto& vertexBuffer,
const auto& indexBuffer,
const auto& segments) {
program.draw(
@@ -96,17 +94,19 @@ void Painter::renderFill(PaintParameters& parameters,
stencilModeForClipping(tile.clip),
colorModeForRenderPass(),
FillProgram::UniformValues {
- uniforms::u_matrix::Value{ tile.translatedMatrix(properties.get<FillTranslate>(),
- properties.get<FillTranslateAnchor>(),
- state) },
- uniforms::u_opacity::Value{ properties.get<FillOpacity>() },
- uniforms::u_color::Value{ properties.get<FillColor>() },
- uniforms::u_outline_color::Value{ properties.get<FillOutlineColor>() },
+ uniforms::u_matrix::Value{
+ tile.translatedMatrix(properties.get<FillTranslate>(),
+ properties.get<FillTranslateAnchor>(),
+ state)
+ },
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
},
- vertexBuffer,
+ *bucket.vertexBuffer,
indexBuffer,
- segments
+ segments,
+ bucket.paintPropertyBinders.at(layer.getID()),
+ properties,
+ state.getZoom()
);
};
@@ -114,18 +114,17 @@ void Painter::renderFill(PaintParameters& parameters,
draw(2,
parameters.programs.fillOutline,
gl::Lines { 2.0f },
- *bucket.vertexBuffer,
*bucket.lineIndexBuffer,
bucket.lineSegments);
}
// Only draw the fill when it's opaque and we're drawing opaque fragments,
// or when it's translucent and we're drawing translucent fragments.
- if ((properties.get<FillColor>().a >= 1.0f && properties.get<FillOpacity>() >= 1.0f) == (pass == RenderPass::Opaque)) {
+ if ((properties.get<FillColor>().constantOr(Color()).a >= 1.0f
+ && properties.get<FillOpacity>().constantOr(0) >= 1.0f) == (pass == RenderPass::Opaque)) {
draw(1,
parameters.programs.fill,
gl::Triangles(),
- *bucket.vertexBuffer,
*bucket.triangleIndexBuffer,
bucket.triangleSegments);
}
@@ -134,7 +133,6 @@ void Painter::renderFill(PaintParameters& parameters,
draw(2,
parameters.programs.fillOutline,
gl::Lines { 2.0f },
- *bucket.vertexBuffer,
*bucket.lineIndexBuffer,
bucket.lineSegments);
}
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index 012746d2f2..0fbff94ff7 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -33,7 +33,10 @@ void Painter::renderLine(PaintParameters& parameters,
std::move(uniformValues),
*bucket.vertexBuffer,
*bucket.indexBuffer,
- bucket.segments
+ bucket.segments,
+ bucket.paintPropertyBinders.at(layer.getID()),
+ properties,
+ state.getZoom()
);
};
diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp
index dcf2644140..c216955db8 100644
--- a/src/mbgl/renderer/painter_raster.cpp
+++ b/src/mbgl/renderer/painter_raster.cpp
@@ -49,6 +49,7 @@ void Painter::renderRaster(PaintParameters& parameters,
return;
const RasterPaintProperties::Evaluated& properties = layer.impl->paint.evaluated;
+ const RasterProgram::PaintPropertyBinders paintAttributeData(properties, 0);
assert(bucket.texture);
context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
@@ -77,7 +78,10 @@ void Painter::renderRaster(PaintParameters& parameters,
},
rasterVertexBuffer,
tileTriangleIndexBuffer,
- rasterSegments
+ rasterSegments,
+ paintAttributeData,
+ properties,
+ state.getZoom()
);
}
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 39075976a0..0113c15a08 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -51,7 +51,10 @@ void Painter::renderSymbol(PaintParameters& parameters,
std::move(uniformValues),
*buffers.vertexBuffer,
*buffers.indexBuffer,
- buffers.segments
+ buffers.segments,
+ bucket.paintPropertyBinders.at(layer.getID()),
+ layer.impl->paint.evaluated,
+ state.getZoom()
);
};
@@ -110,6 +113,9 @@ void Painter::renderSymbol(PaintParameters& parameters,
}
if (bucket.hasCollisionBoxData()) {
+ static const style::PaintProperties<>::Evaluated properties {};
+ static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0);
+
programs->collisionBox.draw(
context,
gl::Lines { 1.0f },
@@ -124,7 +130,10 @@ void Painter::renderSymbol(PaintParameters& parameters,
},
*bucket.collisionBox.vertexBuffer,
*bucket.collisionBox.indexBuffer,
- bucket.collisionBox.segments
+ bucket.collisionBox.segments,
+ paintAttributeData,
+ properties,
+ state.getZoom()
);
}
}
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 0f2c89339f..9d4bde9d07 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -1,19 +1,25 @@
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
+#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
+#include <mbgl/style/layers/symbol_layer_impl.hpp>
namespace mbgl {
using namespace style;
-SymbolBucket::SymbolBucket(const MapMode mode_,
- style::SymbolLayoutProperties::Evaluated layout_,
+SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::Evaluated layout_,
+ const std::unordered_map<std::string, style::SymbolPaintProperties::Evaluated>& layerPaintProperties,
+ float zoom,
bool sdfIcons_,
bool iconsNeedLinear_)
- : mode(mode_),
- layout(std::move(layout_)),
+ : layout(std::move(layout_)),
sdfIcons(sdfIcons_),
iconsNeedLinear(iconsNeedLinear_) {
+ for (const auto& pair : layerPaintProperties) {
+ paintPropertyBinders.emplace(pair.first,
+ SymbolIconProgram::PaintPropertyBinders(pair.second, zoom));
+ }
}
void SymbolBucket::upload(gl::Context& context) {
@@ -32,6 +38,10 @@ void SymbolBucket::upload(gl::Context& context) {
collisionBox.indexBuffer = context.createIndexBuffer(std::move(collisionBox.lines));
}
+ for (auto& pair : paintPropertyBinders) {
+ pair.second.upload(context);
+ }
+
uploaded = true;
}
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index d62a61aab7..0b40bb34ae 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -16,8 +16,9 @@ namespace mbgl {
class SymbolBucket : public Bucket {
public:
- SymbolBucket(const MapMode,
- style::SymbolLayoutProperties::Evaluated,
+ SymbolBucket(style::SymbolLayoutProperties::Evaluated,
+ const std::unordered_map<std::string, style::SymbolPaintProperties::Evaluated>&,
+ float zoom,
bool sdfIcons,
bool iconsNeedLinear);
@@ -28,26 +29,27 @@ public:
bool hasIconData() const;
bool hasCollisionBoxData() const;
- const MapMode mode;
const style::SymbolLayoutProperties::Evaluated layout;
const bool sdfIcons;
const bool iconsNeedLinear;
+ std::unordered_map<std::string, SymbolIconProgram::PaintPropertyBinders> paintPropertyBinders;
+
struct TextBuffer {
- gl::VertexVector<SymbolVertex> vertices;
+ gl::VertexVector<SymbolLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<SymbolAttributes> segments;
- optional<gl::VertexBuffer<SymbolVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
} text;
struct IconBuffer {
- gl::VertexVector<SymbolVertex> vertices;
+ gl::VertexVector<SymbolLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<SymbolAttributes> segments;
- optional<gl::VertexBuffer<SymbolVertex>> vertexBuffer;
+ optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
} icon;
diff --git a/src/mbgl/style/bucket_parameters.cpp b/src/mbgl/style/bucket_parameters.cpp
index e641120c5e..2b02ac4a4a 100644
--- a/src/mbgl/style/bucket_parameters.cpp
+++ b/src/mbgl/style/bucket_parameters.cpp
@@ -1,21 +1,7 @@
#include <mbgl/style/bucket_parameters.hpp>
-#include <mbgl/style/filter_evaluator.hpp>
-#include <mbgl/tile/geometry_tile_data.hpp>
namespace mbgl {
namespace style {
-void BucketParameters::eachFilteredFeature(const Filter& filter,
- const GeometryTileLayer& layer,
- std::function<void (const GeometryTileFeature&, std::size_t index, const std::string& layerName)> function) {
- auto name = layer.getName();
- for (std::size_t i = 0; !cancelled() && i < layer.featureCount(); i++) {
- auto feature = layer.getFeature(i);
- if (!filter(feature->getType(), feature->getID(), [&] (const auto& key) { return feature->getValue(key); }))
- continue;
- function(*feature, i, name);
- }
-}
-
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/bucket_parameters.hpp b/src/mbgl/style/bucket_parameters.hpp
index d5e05c5dd2..d0edbcac30 100644
--- a/src/mbgl/style/bucket_parameters.hpp
+++ b/src/mbgl/style/bucket_parameters.hpp
@@ -2,33 +2,14 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/tile/tile_id.hpp>
-#include <mbgl/style/filter.hpp>
-
-#include <atomic>
-#include <functional>
namespace mbgl {
-
-class GeometryTileLayer;
-class GeometryTileFeature;
-class FeatureIndex;
-
namespace style {
class BucketParameters {
public:
- const OverscaledTileID& tileID;
- const std::atomic<bool>& obsolete;
- FeatureIndex& featureIndex;
+ const OverscaledTileID tileID;
const MapMode mode;
-
- bool cancelled() const {
- return obsolete;
- }
-
- void eachFilteredFeature(const Filter&,
- const GeometryTileLayer&,
- std::function<void (const GeometryTileFeature&, std::size_t index, const std::string& layerName)>);
};
} // namespace style
diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp
index d06b2f2814..71755bd9d6 100644
--- a/src/mbgl/style/conversion/stringify.hpp
+++ b/src/mbgl/style/conversion/stringify.hpp
@@ -214,20 +214,131 @@ void stringify(Writer& writer, const Undefined&) {
writer.Null();
}
-template <class Writer, class T>
-void stringify(Writer& writer, const Function<T>& f) {
- writer.StartObject();
- writer.Key("base");
- writer.Double(f.getBase());
- writer.Key("stops");
- writer.StartArray();
- for (const auto& stop : f.getStops()) {
+template <class Writer>
+void stringify(Writer& writer, const CategoricalValue& v) {
+ CategoricalValue::visit(v, [&] (const auto& v_) { stringify(writer, v_); });
+}
+
+template <class Writer>
+class StringifyStops {
+public:
+ Writer& writer;
+
+ template <class T>
+ void operator()(const ExponentialStops<T>& f) {
+ writer.Key("type");
+ writer.String("exponential");
+ writer.Key("base");
+ writer.Double(f.base);
+ writer.Key("stops");
+ stringifyStops(f.stops);
+ }
+
+ template <class T>
+ void operator()(const IntervalStops<T>& f) {
+ writer.Key("type");
+ writer.String("interval");
+ writer.Key("stops");
+ stringifyStops(f.stops);
+ }
+
+ template <class T>
+ void operator()(const CategoricalStops<T>& f) {
+ writer.Key("type");
+ writer.String("categorical");
+ writer.Key("stops");
+ stringifyStops(f.stops);
+ }
+
+ template <class T>
+ void operator()(const IdentityStops<T>&) {
+ writer.Key("type");
+ writer.String("identity");
+ }
+
+ template <class T>
+ void operator()(const std::map<float, ExponentialStops<T>>& f) {
+ writer.Key("type");
+ writer.String("exponential");
+ if (!f.empty()) {
+ writer.Key("base");
+ writer.Double(f.begin()->second.base);
+ }
+ writer.Key("stops");
+ stringifyCompositeStops(f);
+ }
+
+ template <class T>
+ void operator()(const std::map<float, IntervalStops<T>>& f) {
+ writer.Key("type");
+ writer.String("interval");
+ writer.Key("stops");
+ stringifyCompositeStops(f);
+ }
+
+ template <class T>
+ void operator()(const std::map<float, CategoricalStops<T>>& f) {
+ writer.Key("type");
+ writer.String("categorical");
+ writer.Key("stops");
+ stringifyCompositeStops(f);
+ }
+
+private:
+ template <class K, class V>
+ void stringifyStops(const std::map<K, V>& stops) {
writer.StartArray();
- writer.Double(stop.first);
- stringify(writer, stop.second);
+ for (const auto& stop : stops) {
+ writer.StartArray();
+ stringify(writer, stop.first);
+ stringify(writer, stop.second);
+ writer.EndArray();
+ }
writer.EndArray();
}
- writer.EndArray();
+
+ template <class InnerStops>
+ void stringifyCompositeStops(const std::map<float, InnerStops>& stops) {
+ writer.StartArray();
+ for (const auto& outer : stops) {
+ for (const auto& inner : outer.second.stops) {
+ writer.StartArray();
+ writer.StartObject();
+ writer.Key("zoom");
+ writer.Double(outer.first);
+ writer.Key("value");
+ stringify(writer, inner.first);
+ writer.EndObject();
+ stringify(writer, inner.second);
+ writer.EndArray();
+ }
+ }
+ writer.EndArray();
+ }
+};
+
+template <class Writer, class T>
+void stringify(Writer& writer, const CameraFunction<T>& f) {
+ writer.StartObject();
+ CameraFunction<T>::Stops::visit(f.stops, StringifyStops<Writer> { writer });
+ writer.EndObject();
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const SourceFunction<T>& f) {
+ writer.StartObject();
+ writer.Key("property");
+ writer.String(f.property);
+ SourceFunction<T>::Stops::visit(f.stops, StringifyStops<Writer> { writer });
+ writer.EndObject();
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const CompositeFunction<T>& f) {
+ writer.StartObject();
+ writer.Key("property");
+ writer.String(f.property);
+ CompositeFunction<T>::Stops::visit(f.stops, StringifyStops<Writer> { writer });
writer.EndObject();
}
@@ -238,7 +349,20 @@ void stringify(Writer& writer, const PropertyValue<T>& v) {
template <class Property, class Writer, class T>
void stringify(Writer& writer, const PropertyValue<T>& value) {
- if (value) {
+ if (!value.isUndefined()) {
+ writer.Key(Property::key);
+ stringify(writer, value);
+ }
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const DataDrivenPropertyValue<T>& v) {
+ v.evaluate([&] (const auto& v_) { stringify(writer, v_); });
+}
+
+template <class Property, class Writer, class T>
+void stringify(Writer& writer, const DataDrivenPropertyValue<T>& value) {
+ if (!value.isUndefined()) {
writer.Key(Property::key);
stringify(writer, value);
}
diff --git a/src/mbgl/style/cross_faded_property_evaluator.cpp b/src/mbgl/style/cross_faded_property_evaluator.cpp
index 4de939576e..796ca00bbf 100644
--- a/src/mbgl/style/cross_faded_property_evaluator.cpp
+++ b/src/mbgl/style/cross_faded_property_evaluator.cpp
@@ -17,21 +17,10 @@ Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const T& constant) const {
}
template <typename T>
-T getBiggestStopLessThan(const Function<T>& function, float z) {
- const auto& stops = function.getStops();
- for (uint32_t i = 0; i < stops.size(); i++) {
- if (stops[i].first > z) {
- return stops[i == 0 ? i : i - 1].second;
- }
- }
- return stops.at(stops.size() - 1).second;
-}
-
-template <typename T>
-Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const Function<T>& function) const {
- return calculate(getBiggestStopLessThan(function, parameters.z - 1.0f),
- getBiggestStopLessThan(function, parameters.z),
- getBiggestStopLessThan(function, parameters.z + 1.0f));
+Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const CameraFunction<T>& function) const {
+ return calculate(function.evaluate(parameters.z - 1.0f),
+ function.evaluate(parameters.z),
+ function.evaluate(parameters.z + 1.0f));
}
template <typename T>
diff --git a/src/mbgl/style/cross_faded_property_evaluator.hpp b/src/mbgl/style/cross_faded_property_evaluator.hpp
index 70c8c0c978..c5642f5cfb 100644
--- a/src/mbgl/style/cross_faded_property_evaluator.hpp
+++ b/src/mbgl/style/cross_faded_property_evaluator.hpp
@@ -28,7 +28,7 @@ public:
Faded<T> operator()(const Undefined&) const;
Faded<T> operator()(const T& constant) const;
- Faded<T> operator()(const Function<T>&) const;
+ Faded<T> operator()(const CameraFunction<T>&) const;
private:
Faded<T> calculate(const T& min, const T& mid, const T& max) const;
diff --git a/src/mbgl/style/data_driven_property_evaluator.hpp b/src/mbgl/style/data_driven_property_evaluator.hpp
new file mode 100644
index 0000000000..7a0ff9a094
--- /dev/null
+++ b/src/mbgl/style/data_driven_property_evaluator.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/property_evaluation_parameters.hpp>
+#include <mbgl/style/possibly_evaluated_property_value.hpp>
+
+namespace mbgl {
+namespace style {
+
+template <typename T>
+class DataDrivenPropertyEvaluator {
+public:
+ using ResultType = PossiblyEvaluatedPropertyValue<T>;
+
+ DataDrivenPropertyEvaluator(const PropertyEvaluationParameters& parameters_, T defaultValue_)
+ : parameters(parameters_),
+ defaultValue(std::move(defaultValue_)) {}
+
+ ResultType operator()(const Undefined&) const {
+ return ResultType(defaultValue);
+ }
+
+ ResultType operator()(const T& constant) const {
+ return ResultType(constant);
+ }
+
+ ResultType operator()(const CameraFunction<T>& function) const {
+ return ResultType(function.evaluate(parameters.z));
+ }
+
+ template <class Function>
+ ResultType operator()(const Function& function) const {
+ return ResultType(function);
+ }
+
+private:
+ const PropertyEvaluationParameters& parameters;
+ T defaultValue;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/function.cpp b/src/mbgl/style/function.cpp
deleted file mode 100644
index 02750c7d2e..0000000000
--- a/src/mbgl/style/function.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-#include <mbgl/style/function.hpp>
-#include <mbgl/style/types.hpp>
-#include <mbgl/util/color.hpp>
-#include <mbgl/util/interpolate.hpp>
-
-#include <cmath>
-
-namespace mbgl {
-namespace style {
-
-template <typename T>
-T Function<T>::evaluate(float z) const {
- bool smaller = false;
- float smaller_z = 0.0f;
- T smaller_val = T();
- bool larger = false;
- float larger_z = 0.0f;
- T larger_val = T();
-
- for (uint32_t i = 0; i < stops.size(); i++) {
- float stop_z = stops[i].first;
- T stop_val = stops[i].second;
- if (stop_z <= z && (!smaller || smaller_z < stop_z)) {
- smaller = true;
- smaller_z = stop_z;
- smaller_val = stop_val;
- }
- if (stop_z >= z && (!larger || larger_z > stop_z)) {
- larger = true;
- larger_z = stop_z;
- larger_val = stop_val;
- }
- }
-
- if (smaller && larger) {
- if (larger_z == smaller_z || larger_val == smaller_val) {
- return smaller_val;
- }
- const float zoomDiff = larger_z - smaller_z;
- const float zoomProgress = z - smaller_z;
- if (base == 1.0f) {
- const float t = zoomProgress / zoomDiff;
- return util::interpolate(smaller_val, larger_val, t);
- } else {
- const float t = (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
- return util::interpolate(smaller_val, larger_val, t);
- }
- } else if (larger) {
- return larger_val;
- } else if (smaller) {
- return smaller_val;
- } else {
- // No stop defined.
- assert(false);
- return T();
- }
-}
-
-template class Function<bool>;
-template class Function<float>;
-template class Function<Color>;
-template class Function<std::vector<float>>;
-template class Function<std::vector<std::string>>;
-template class Function<std::array<float, 2>>;
-template class Function<std::array<float, 4>>;
-
-template class Function<std::string>;
-template class Function<TranslateAnchorType>;
-template class Function<RotateAnchorType>;
-template class Function<CirclePitchScaleType>;
-template class Function<LineCapType>;
-template class Function<LineJoinType>;
-template class Function<SymbolPlacementType>;
-template class Function<TextAnchorType>;
-template class Function<TextJustifyType>;
-template class Function<TextTransformType>;
-template class Function<AlignmentType>;
-template class Function<IconTextFitType>;
-
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/function/categorical_stops.cpp b/src/mbgl/style/function/categorical_stops.cpp
new file mode 100644
index 0000000000..bcdf170f17
--- /dev/null
+++ b/src/mbgl/style/function/categorical_stops.cpp
@@ -0,0 +1,35 @@
+#include <mbgl/style/function/categorical_stops.hpp>
+#include <mbgl/util/color.hpp>
+
+#include <array>
+
+namespace mbgl {
+namespace style {
+
+optional<CategoricalValue> categoricalValue(const Value& value) {
+ return value.match(
+ [] (bool t) { return optional<CategoricalValue>(t); },
+ [] (uint64_t t) { return optional<CategoricalValue>(int64_t(t)); },
+ [] (int64_t t) { return optional<CategoricalValue>(t); },
+ [] (double t) { return optional<CategoricalValue>(int64_t(t)); },
+ [] (const std::string& t) { return optional<CategoricalValue>(t); },
+ [] (const auto&) { return optional<CategoricalValue>(); }
+ );
+}
+
+template <class T>
+T CategoricalStops<T>::evaluate(const Value& value) const {
+ auto v = categoricalValue(value);
+ if (!v) {
+ return defaultValue;
+ }
+ auto it = stops.find(*v);
+ return it == stops.end() ? defaultValue : it->second;
+}
+
+template class CategoricalStops<float>;
+template class CategoricalStops<Color>;
+template class CategoricalStops<std::array<float, 2>>;
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/function/identity_stops.cpp b/src/mbgl/style/function/identity_stops.cpp
new file mode 100644
index 0000000000..e210b4d773
--- /dev/null
+++ b/src/mbgl/style/function/identity_stops.cpp
@@ -0,0 +1,43 @@
+#include <mbgl/style/function/identity_stops.hpp>
+#include <mbgl/util/color.hpp>
+
+#include <array>
+
+namespace mbgl {
+namespace style {
+
+template <>
+float IdentityStops<float>::evaluate(const Value& value) const {
+ return numericValue<float>(value)
+ .value_or(0.0f);
+}
+
+template <>
+Color IdentityStops<Color>::evaluate(const Value& value) const {
+ if (!value.is<std::string>()) {
+ return Color::black();
+ }
+
+ return Color::parse(value.get<std::string>())
+ .value_or(Color::black());
+}
+
+template <>
+std::array<float, 2> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const {
+ if (!value.is<std::vector<Value>>()) {
+ return {{ 0, 0 }};
+ }
+
+ const std::vector<Value>& vector = value.get<std::vector<Value>>();
+ if (vector.size() != 2 || !numericValue<float>(vector[0]) || !numericValue<float>(vector[1])) {
+ return {{ 0, 0 }};
+ }
+
+ return {{
+ *numericValue<float>(vector[0]),
+ *numericValue<float>(vector[1])
+ }};
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp
index 0fea70c10b..9b2bfe4d2c 100644
--- a/src/mbgl/style/layer_impl.hpp
+++ b/src/mbgl/style/layer_impl.hpp
@@ -61,7 +61,7 @@ public:
// Returns true if any paint properties have active transitions.
virtual bool evaluate(const PropertyEvaluationParameters&) = 0;
- virtual std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const = 0;
+ virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const = 0;
// Checks whether this layer needs to be rendered in the given render pass.
bool hasRenderPass(RenderPass) const;
diff --git a/src/mbgl/style/layer_observer.hpp b/src/mbgl/style/layer_observer.hpp
index a3f9ca7528..2fa1c39660 100644
--- a/src/mbgl/style/layer_observer.hpp
+++ b/src/mbgl/style/layer_observer.hpp
@@ -12,6 +12,7 @@ public:
virtual void onLayerFilterChanged(Layer&) {}
virtual void onLayerVisibilityChanged(Layer&) {}
virtual void onLayerPaintPropertyChanged(Layer&) {}
+ virtual void onLayerDataDrivenPaintPropertyChanged(Layer&) {}
virtual void onLayerLayoutPropertyChanged(Layer&, const char *) {}
};
diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp
index 4a8fe39c9a..f25ba9cfb4 100644
--- a/src/mbgl/style/layers/background_layer_impl.cpp
+++ b/src/mbgl/style/layers/background_layer_impl.cpp
@@ -16,7 +16,8 @@ bool BackgroundLayer::Impl::evaluate(const PropertyEvaluationParameters& paramet
return paint.hasTransition();
}
-std::unique_ptr<Bucket> BackgroundLayer::Impl::createBucket(BucketParameters&, const GeometryTileLayer&) const {
+std::unique_ptr<Bucket> BackgroundLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const {
+ assert(false);
return nullptr;
}
diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp
index 4629217e6d..02a8c423d6 100644
--- a/src/mbgl/style/layers/background_layer_impl.hpp
+++ b/src/mbgl/style/layers/background_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
BackgroundPaintProperties paint;
};
diff --git a/src/mbgl/style/layers/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp
index 792bf3de94..fae6c26a4b 100644
--- a/src/mbgl/style/layers/background_layer_properties.hpp
+++ b/src/mbgl/style/layers/background_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp
index 389ab93403..f8d06e2644 100644
--- a/src/mbgl/style/layers/circle_layer.cpp
+++ b/src/mbgl/style/layers/circle_layer.cpp
@@ -65,64 +65,80 @@ const Filter& CircleLayer::getFilter() const {
// Paint properties
-PropertyValue<float> CircleLayer::getDefaultCircleRadius() {
+DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleRadius() {
return { 5 };
}
-PropertyValue<float> CircleLayer::getCircleRadius(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> CircleLayer::getCircleRadius(const optional<std::string>& klass) const {
return impl->paint.get<CircleRadius>(klass);
}
-void CircleLayer::setCircleRadius(PropertyValue<float> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleRadius(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleRadius(klass))
return;
impl->paint.set<CircleRadius>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<Color> CircleLayer::getDefaultCircleColor() {
+DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleColor() {
return { Color::black() };
}
-PropertyValue<Color> CircleLayer::getCircleColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> CircleLayer::getCircleColor(const optional<std::string>& klass) const {
return impl->paint.get<CircleColor>(klass);
}
-void CircleLayer::setCircleColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getCircleColor(klass))
return;
impl->paint.set<CircleColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> CircleLayer::getDefaultCircleBlur() {
+DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleBlur() {
return { 0 };
}
-PropertyValue<float> CircleLayer::getCircleBlur(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> CircleLayer::getCircleBlur(const optional<std::string>& klass) const {
return impl->paint.get<CircleBlur>(klass);
}
-void CircleLayer::setCircleBlur(PropertyValue<float> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleBlur(klass))
return;
impl->paint.set<CircleBlur>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> CircleLayer::getDefaultCircleOpacity() {
+DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleOpacity() {
return { 1 };
}
-PropertyValue<float> CircleLayer::getCircleOpacity(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> CircleLayer::getCircleOpacity(const optional<std::string>& klass) const {
return impl->paint.get<CircleOpacity>(klass);
}
-void CircleLayer::setCircleOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleOpacity(klass))
return;
impl->paint.set<CircleOpacity>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
PropertyValue<std::array<float, 2>> CircleLayer::getDefaultCircleTranslate() {
@@ -170,49 +186,61 @@ void CircleLayer::setCirclePitchScale(PropertyValue<CirclePitchScaleType> value,
impl->observer->onLayerPaintPropertyChanged(*this);
}
-PropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() {
+DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() {
return { 0 };
}
-PropertyValue<float> CircleLayer::getCircleStrokeWidth(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeWidth(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeWidth>(klass);
}
-void CircleLayer::setCircleStrokeWidth(PropertyValue<float> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleStrokeWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeWidth(klass))
return;
impl->paint.set<CircleStrokeWidth>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() {
+DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() {
return { Color::black() };
}
-PropertyValue<Color> CircleLayer::getCircleStrokeColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> CircleLayer::getCircleStrokeColor(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeColor>(klass);
}
-void CircleLayer::setCircleStrokeColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleStrokeColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getCircleStrokeColor(klass))
return;
impl->paint.set<CircleStrokeColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() {
+DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() {
return { 1 };
}
-PropertyValue<float> CircleLayer::getCircleStrokeOpacity(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeOpacity(const optional<std::string>& klass) const {
return impl->paint.get<CircleStrokeOpacity>(klass);
}
-void CircleLayer::setCircleStrokeOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
+void CircleLayer::setCircleStrokeOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeOpacity(klass))
return;
impl->paint.set<CircleStrokeOpacity>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
} // namespace style
diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp
index 136522e41c..655ad9b5b9 100644
--- a/src/mbgl/style/layers/circle_layer_impl.cpp
+++ b/src/mbgl/style/layers/circle_layer_impl.cpp
@@ -1,5 +1,4 @@
#include <mbgl/style/layers/circle_layer_impl.hpp>
-#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/renderer/circle_bucket.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/util/math.hpp>
@@ -15,27 +14,22 @@ void CircleLayer::Impl::cascade(const CascadeParameters& parameters) {
bool CircleLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) {
paint.evaluate(parameters);
- passes = (paint.evaluated.get<CircleRadius>() > 0 && paint.evaluated.get<CircleColor>().a > 0 && paint.evaluated.get<CircleOpacity>() > 0)
+ passes = (paint.evaluated.get<CircleRadius>().constantOr(1) > 0
+ && paint.evaluated.get<CircleColor>().constantOr(Color::black()).a > 0
+ && paint.evaluated.get<CircleOpacity>().constantOr(1) > 0)
? RenderPass::Translucent : RenderPass::None;
return paint.hasTransition();
}
-std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(BucketParameters& parameters, const GeometryTileLayer& layer) const {
- auto bucket = std::make_unique<CircleBucket>(parameters.mode);
-
- parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
- auto geometries = feature.getGeometries();
- bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, id);
- });
-
- return std::move(bucket);
+std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const {
+ return std::make_unique<CircleBucket>(parameters, layers);
}
float CircleLayer::Impl::getQueryRadius() const {
const std::array<float, 2>& translate = paint.evaluated.get<CircleTranslate>();
- return paint.evaluated.get<CircleRadius>() + util::length(translate[0], translate[1]);
+ return paint.evaluated.get<CircleRadius>().constantOr(CircleRadius::defaultValue())
+ + util::length(translate[0], translate[1]);
}
bool CircleLayer::Impl::queryIntersectsGeometry(
@@ -47,7 +41,7 @@ bool CircleLayer::Impl::queryIntersectsGeometry(
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry, paint.evaluated.get<CircleTranslate>(), paint.evaluated.get<CircleTranslateAnchor>(), bearing, pixelsToTileUnits);
- auto circleRadius = paint.evaluated.get<CircleRadius>() * pixelsToTileUnits;
+ auto circleRadius = paint.evaluated.get<CircleRadius>().constantOr(CircleRadius::defaultValue()) * pixelsToTileUnits;
return util::polygonIntersectsBufferedMultiPoint(
translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius);
diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp
index 744a56898c..0f9611d589 100644
--- a/src/mbgl/style/layers/circle_layer_impl.hpp
+++ b/src/mbgl/style/layers/circle_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
float getQueryRadius() const override;
bool queryIntersectsGeometry(
diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp
index ea36b31949..1cb4f5a635 100644
--- a/src/mbgl/style/layers/circle_layer_properties.hpp
+++ b/src/mbgl/style/layers/circle_layer_properties.hpp
@@ -5,23 +5,24 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
-struct CircleRadius : PaintProperty<float> {
+struct CircleRadius : DataDrivenPaintProperty<float, attributes::a_radius> {
static float defaultValue() { return 5; }
};
-struct CircleColor : PaintProperty<Color> {
+struct CircleColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};
-struct CircleBlur : PaintProperty<float> {
+struct CircleBlur : DataDrivenPaintProperty<float, attributes::a_blur> {
static float defaultValue() { return 0; }
};
-struct CircleOpacity : PaintProperty<float> {
+struct CircleOpacity : DataDrivenPaintProperty<float, attributes::a_opacity> {
static float defaultValue() { return 1; }
};
@@ -37,15 +38,15 @@ struct CirclePitchScale : PaintProperty<CirclePitchScaleType> {
static CirclePitchScaleType defaultValue() { return CirclePitchScaleType::Map; }
};
-struct CircleStrokeWidth : PaintProperty<float> {
+struct CircleStrokeWidth : DataDrivenPaintProperty<float, attributes::a_stroke_width> {
static float defaultValue() { return 0; }
};
-struct CircleStrokeColor : PaintProperty<Color> {
+struct CircleStrokeColor : DataDrivenPaintProperty<Color, attributes::a_stroke_color> {
static Color defaultValue() { return Color::black(); }
};
-struct CircleStrokeOpacity : PaintProperty<float> {
+struct CircleStrokeOpacity : DataDrivenPaintProperty<float, attributes::a_stroke_opacity> {
static float defaultValue() { return 1; }
};
diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp
index cecd60a296..379de25e8f 100644
--- a/src/mbgl/style/layers/custom_layer_impl.cpp
+++ b/src/mbgl/style/layers/custom_layer_impl.cpp
@@ -70,7 +70,8 @@ bool CustomLayer::Impl::evaluate(const PropertyEvaluationParameters&) {
return false;
}
-std::unique_ptr<Bucket> CustomLayer::Impl::createBucket(BucketParameters&, const GeometryTileLayer&) const {
+std::unique_ptr<Bucket> CustomLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const {
+ assert(false);
return nullptr;
}
diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp
index 71fb46d0d9..33eb86828c 100644
--- a/src/mbgl/style/layers/custom_layer_impl.hpp
+++ b/src/mbgl/style/layers/custom_layer_impl.hpp
@@ -32,7 +32,7 @@ private:
void cascade(const CascadeParameters&) final {}
bool evaluate(const PropertyEvaluationParameters&) final;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const final;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const final;
CustomLayerInitializeFunction initializeFn = nullptr;
CustomLayerRenderFunction renderFn = nullptr;
diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp
index 34f0267d16..0ef5c9bcbc 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer.cpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp
@@ -80,19 +80,23 @@ void FillExtrusionLayer::setFillExtrusionOpacity(PropertyValue<float> value, con
impl->observer->onLayerPaintPropertyChanged(*this);
}
-PropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor() {
+DataDrivenPropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor() {
return { Color::black() };
}
-PropertyValue<Color> FillExtrusionLayer::getFillExtrusionColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> FillExtrusionLayer::getFillExtrusionColor(const optional<std::string>& klass) const {
return impl->paint.get<FillExtrusionColor>(klass);
}
-void FillExtrusionLayer::setFillExtrusionColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void FillExtrusionLayer::setFillExtrusionColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillExtrusionColor(klass))
return;
impl->paint.set<FillExtrusionColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
PropertyValue<std::array<float, 2>> FillExtrusionLayer::getDefaultFillExtrusionTranslate() {
@@ -140,34 +144,42 @@ void FillExtrusionLayer::setFillExtrusionPattern(PropertyValue<std::string> valu
impl->observer->onLayerPaintPropertyChanged(*this);
}
-PropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight() {
+DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight() {
return { 0 };
}
-PropertyValue<float> FillExtrusionLayer::getFillExtrusionHeight(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionHeight(const optional<std::string>& klass) const {
return impl->paint.get<FillExtrusionHeight>(klass);
}
-void FillExtrusionLayer::setFillExtrusionHeight(PropertyValue<float> value, const optional<std::string>& klass) {
+void FillExtrusionLayer::setFillExtrusionHeight(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillExtrusionHeight(klass))
return;
impl->paint.set<FillExtrusionHeight>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase() {
+DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase() {
return { 0 };
}
-PropertyValue<float> FillExtrusionLayer::getFillExtrusionBase(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionBase(const optional<std::string>& klass) const {
return impl->paint.get<FillExtrusionBase>(klass);
}
-void FillExtrusionLayer::setFillExtrusionBase(PropertyValue<float> value, const optional<std::string>& klass) {
+void FillExtrusionLayer::setFillExtrusionBase(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillExtrusionBase(klass))
return;
impl->paint.set<FillExtrusionBase>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
} // namespace style
diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp
index ebe9009312..a809820644 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp
@@ -11,7 +11,7 @@ bool FillExtrusionLayer::Impl::evaluate(const PropertyEvaluationParameters&) {
return false;
}
-std::unique_ptr<Bucket> FillExtrusionLayer::Impl::createBucket(BucketParameters&, const GeometryTileLayer&) const {
+std::unique_ptr<Bucket> FillExtrusionLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const {
return nullptr;
}
diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
index 3dd8bb270a..ed7ef747fb 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
FillExtrusionPaintProperties paint;
};
diff --git a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp
index a2d01199a5..c1dd3b079d 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
@@ -13,7 +14,7 @@ struct FillExtrusionOpacity : PaintProperty<float> {
static float defaultValue() { return 1; }
};
-struct FillExtrusionColor : PaintProperty<Color> {
+struct FillExtrusionColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};
@@ -29,11 +30,11 @@ struct FillExtrusionPattern : CrossFadedPaintProperty<std::string> {
static std::string defaultValue() { return ""; }
};
-struct FillExtrusionHeight : PaintProperty<float> {
+struct FillExtrusionHeight : DataDrivenPaintProperty<float, attributes::a_height> {
static float defaultValue() { return 0; }
};
-struct FillExtrusionBase : PaintProperty<float> {
+struct FillExtrusionBase : DataDrivenPaintProperty<float, attributes::a_base> {
static float defaultValue() { return 0; }
};
diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp
index b8fa8cad8b..e1c0d4d243 100644
--- a/src/mbgl/style/layers/fill_layer.cpp
+++ b/src/mbgl/style/layers/fill_layer.cpp
@@ -80,49 +80,61 @@ void FillLayer::setFillAntialias(PropertyValue<bool> value, const optional<std::
impl->observer->onLayerPaintPropertyChanged(*this);
}
-PropertyValue<float> FillLayer::getDefaultFillOpacity() {
+DataDrivenPropertyValue<float> FillLayer::getDefaultFillOpacity() {
return { 1 };
}
-PropertyValue<float> FillLayer::getFillOpacity(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> FillLayer::getFillOpacity(const optional<std::string>& klass) const {
return impl->paint.get<FillOpacity>(klass);
}
-void FillLayer::setFillOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
+void FillLayer::setFillOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillOpacity(klass))
return;
impl->paint.set<FillOpacity>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<Color> FillLayer::getDefaultFillColor() {
+DataDrivenPropertyValue<Color> FillLayer::getDefaultFillColor() {
return { Color::black() };
}
-PropertyValue<Color> FillLayer::getFillColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> FillLayer::getFillColor(const optional<std::string>& klass) const {
return impl->paint.get<FillColor>(klass);
}
-void FillLayer::setFillColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void FillLayer::setFillColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillColor(klass))
return;
impl->paint.set<FillColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<Color> FillLayer::getDefaultFillOutlineColor() {
+DataDrivenPropertyValue<Color> FillLayer::getDefaultFillOutlineColor() {
return { {} };
}
-PropertyValue<Color> FillLayer::getFillOutlineColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> FillLayer::getFillOutlineColor(const optional<std::string>& klass) const {
return impl->paint.get<FillOutlineColor>(klass);
}
-void FillLayer::setFillOutlineColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void FillLayer::setFillOutlineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillOutlineColor(klass))
return;
impl->paint.set<FillOutlineColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
PropertyValue<std::array<float, 2>> FillLayer::getDefaultFillTranslate() {
diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp
index 1ff26aa003..c7c89f8c20 100644
--- a/src/mbgl/style/layers/fill_layer_impl.cpp
+++ b/src/mbgl/style/layers/fill_layer_impl.cpp
@@ -1,5 +1,4 @@
#include <mbgl/style/layers/fill_layer_impl.hpp>
-#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/renderer/fill_bucket.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/util/math.hpp>
@@ -25,7 +24,9 @@ bool FillLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) {
passes |= RenderPass::Translucent;
}
- if (!paint.evaluated.get<FillPattern>().from.empty() || (paint.evaluated.get<FillColor>().a * paint.evaluated.get<FillOpacity>()) < 1.0f) {
+ if (!paint.unevaluated.get<FillPattern>().isUndefined()
+ || paint.evaluated.get<FillColor>().constantOr(Color()).a < 1.0f
+ || paint.evaluated.get<FillOpacity>().constantOr(0) < 1.0f) {
passes |= RenderPass::Translucent;
} else {
passes |= RenderPass::Opaque;
@@ -34,16 +35,8 @@ bool FillLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) {
return paint.hasTransition();
}
-std::unique_ptr<Bucket> FillLayer::Impl::createBucket(BucketParameters& parameters, const GeometryTileLayer& layer) const {
- auto bucket = std::make_unique<FillBucket>();
-
- parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
- auto geometries = feature.getGeometries();
- bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, id);
- });
-
- return std::move(bucket);
+std::unique_ptr<Bucket> FillLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const {
+ return std::make_unique<FillBucket>(parameters, layers);
}
float FillLayer::Impl::getQueryRadius() const {
diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp
index 28e2fa7edc..bd25a8bebf 100644
--- a/src/mbgl/style/layers/fill_layer_impl.hpp
+++ b/src/mbgl/style/layers/fill_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
float getQueryRadius() const override;
bool queryIntersectsGeometry(
diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp
index b2d926c31e..f44a18d0e0 100644
--- a/src/mbgl/style/layers/fill_layer_properties.hpp
+++ b/src/mbgl/style/layers/fill_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
@@ -13,15 +14,15 @@ struct FillAntialias : PaintProperty<bool> {
static bool defaultValue() { return true; }
};
-struct FillOpacity : PaintProperty<float> {
+struct FillOpacity : DataDrivenPaintProperty<float, attributes::a_opacity> {
static float defaultValue() { return 1; }
};
-struct FillColor : PaintProperty<Color> {
+struct FillColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};
-struct FillOutlineColor : PaintProperty<Color> {
+struct FillOutlineColor : DataDrivenPaintProperty<Color, attributes::a_outline_color> {
static Color defaultValue() { return {}; }
};
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index e730e3a29b..4a91a5c7e3 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -86,15 +86,15 @@ const Filter& <%- camelize(type) %>Layer::getFilter() const {
// Layout properties
<% for (const property of layoutProperties) { -%>
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>() {
+<%- propertyValueType(property) %> <%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>() {
return <%- camelize(property.name) %>::defaultValue();
}
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
+<%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
return impl->layout.unevaluated.get<<%- camelize(property.name) %>>();
}
-void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) {
+void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value) {
if (value == get<%- camelize(property.name) %>())
return;
impl->layout.unevaluated.get<<%- camelize(property.name) %>>() = value;
@@ -104,19 +104,27 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue
// Paint properties
<% for (const property of paintProperties) { %>
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>() {
+<%- propertyValueType(property) %> <%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>() {
return { <%- defaultValue(property) %> };
}
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(const optional<std::string>& klass) const {
+<%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(const optional<std::string>& klass) const {
return impl->paint.get<<%- camelize(property.name) %>>(klass);
}
-void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value, const optional<std::string>& klass) {
+void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value, const optional<std::string>& klass) {
if (value == get<%- camelize(property.name) %>(klass))
return;
impl->paint.set<<%- camelize(property.name) %>>(value, klass);
+<% if (isDataDriven(property)) { -%>
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
+<% } else { -%>
impl->observer->onLayerPaintPropertyChanged(*this);
+<% } -%>
}
<% } -%>
diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs
index d18ad44efd..2a736ca388 100644
--- a/src/mbgl/style/layers/layer_properties.hpp.ejs
+++ b/src/mbgl/style/layers/layer_properties.hpp.ejs
@@ -10,22 +10,21 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
<% for (const property of layoutProperties) { -%>
-struct <%- camelize(property.name) %> : LayoutProperty<<%- propertyType(property) %>> {
+struct <%- camelize(property.name) %> : <%- layoutPropertyType(property, type) %> {
static constexpr const char * key = "<%- property.name %>";
- static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
+ static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
};
<% } -%>
<% for (const property of paintProperties) { -%>
-struct <%- camelize(property.name) %> : <%
-if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') {
-%>CrossFaded<% } -%>PaintProperty<<%- propertyType(property) %>> {
- static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
+struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> {
+ static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
};
<% } -%>
diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp
index 7f6c148cd1..fcad1eacb6 100644
--- a/src/mbgl/style/layers/line_layer.cpp
+++ b/src/mbgl/style/layers/line_layer.cpp
@@ -122,34 +122,42 @@ void LineLayer::setLineRoundLimit(PropertyValue<float> value) {
// Paint properties
-PropertyValue<float> LineLayer::getDefaultLineOpacity() {
+DataDrivenPropertyValue<float> LineLayer::getDefaultLineOpacity() {
return { 1 };
}
-PropertyValue<float> LineLayer::getLineOpacity(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> LineLayer::getLineOpacity(const optional<std::string>& klass) const {
return impl->paint.get<LineOpacity>(klass);
}
-void LineLayer::setLineOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
+void LineLayer::setLineOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineOpacity(klass))
return;
impl->paint.set<LineOpacity>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<Color> LineLayer::getDefaultLineColor() {
+DataDrivenPropertyValue<Color> LineLayer::getDefaultLineColor() {
return { Color::black() };
}
-PropertyValue<Color> LineLayer::getLineColor(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<Color> LineLayer::getLineColor(const optional<std::string>& klass) const {
return impl->paint.get<LineColor>(klass);
}
-void LineLayer::setLineColor(PropertyValue<Color> value, const optional<std::string>& klass) {
+void LineLayer::setLineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getLineColor(klass))
return;
impl->paint.set<LineColor>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
PropertyValue<std::array<float, 2>> LineLayer::getDefaultLineTranslate() {
@@ -197,49 +205,61 @@ void LineLayer::setLineWidth(PropertyValue<float> value, const optional<std::str
impl->observer->onLayerPaintPropertyChanged(*this);
}
-PropertyValue<float> LineLayer::getDefaultLineGapWidth() {
+DataDrivenPropertyValue<float> LineLayer::getDefaultLineGapWidth() {
return { 0 };
}
-PropertyValue<float> LineLayer::getLineGapWidth(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> LineLayer::getLineGapWidth(const optional<std::string>& klass) const {
return impl->paint.get<LineGapWidth>(klass);
}
-void LineLayer::setLineGapWidth(PropertyValue<float> value, const optional<std::string>& klass) {
+void LineLayer::setLineGapWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineGapWidth(klass))
return;
impl->paint.set<LineGapWidth>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> LineLayer::getDefaultLineOffset() {
+DataDrivenPropertyValue<float> LineLayer::getDefaultLineOffset() {
return { 0 };
}
-PropertyValue<float> LineLayer::getLineOffset(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> LineLayer::getLineOffset(const optional<std::string>& klass) const {
return impl->paint.get<LineOffset>(klass);
}
-void LineLayer::setLineOffset(PropertyValue<float> value, const optional<std::string>& klass) {
+void LineLayer::setLineOffset(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineOffset(klass))
return;
impl->paint.set<LineOffset>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
-PropertyValue<float> LineLayer::getDefaultLineBlur() {
+DataDrivenPropertyValue<float> LineLayer::getDefaultLineBlur() {
return { 0 };
}
-PropertyValue<float> LineLayer::getLineBlur(const optional<std::string>& klass) const {
+DataDrivenPropertyValue<float> LineLayer::getLineBlur(const optional<std::string>& klass) const {
return impl->paint.get<LineBlur>(klass);
}
-void LineLayer::setLineBlur(PropertyValue<float> value, const optional<std::string>& klass) {
+void LineLayer::setLineBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineBlur(klass))
return;
impl->paint.set<LineBlur>(value, klass);
- impl->observer->onLayerPaintPropertyChanged(*this);
+ if (value.isDataDriven()) {
+ impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
+ } else {
+ impl->observer->onLayerPaintPropertyChanged(*this);
+ }
}
PropertyValue<std::vector<float>> LineLayer::getDefaultLineDasharray() {
diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp
index 477579a43c..ef0131e3d5 100644
--- a/src/mbgl/style/layers/line_layer_impl.cpp
+++ b/src/mbgl/style/layers/line_layer_impl.cpp
@@ -1,5 +1,5 @@
#include <mbgl/style/layers/line_layer_impl.hpp>
-#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/style/property_evaluation_parameters.hpp>
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/util/math.hpp>
@@ -20,31 +20,25 @@ bool LineLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) {
paint.evaluate(parameters);
- passes = (paint.evaluated.get<LineOpacity>() > 0 && paint.evaluated.get<LineColor>().a > 0 && paint.evaluated.get<LineWidth>() > 0)
+ passes = (paint.evaluated.get<LineOpacity>().constantOr(1.0) > 0
+ && paint.evaluated.get<LineColor>().constantOr(Color::black()).a > 0
+ && paint.evaluated.get<LineWidth>() > 0)
? RenderPass::Translucent : RenderPass::None;
return paint.hasTransition();
}
-std::unique_ptr<Bucket> LineLayer::Impl::createBucket(BucketParameters& parameters, const GeometryTileLayer& layer) const {
- auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaleFactor());
-
- bucket->layout = layout.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ));
-
- parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
- auto geometries = feature.getGeometries();
- bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, id);
- });
-
- return std::move(bucket);
+std::unique_ptr<Bucket> LineLayer::Impl::createBucket(const BucketParameters& parameters, const std::vector<const Layer*>& layers) const {
+ return std::make_unique<LineBucket>(parameters, layers, layout);
}
float LineLayer::Impl::getLineWidth() const {
- if (paint.evaluated.get<LineGapWidth>() > 0) {
- return paint.evaluated.get<LineGapWidth>() + 2 * paint.evaluated.get<LineWidth>();
+ float lineWidth = paint.evaluated.get<LineWidth>();
+ float gapWidth = paint.evaluated.get<LineGapWidth>().constantOr(0);
+ if (gapWidth) {
+ return gapWidth + 2 * lineWidth;
} else {
- return paint.evaluated.get<LineWidth>();
+ return lineWidth;
}
}
@@ -80,7 +74,8 @@ optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const d
float LineLayer::Impl::getQueryRadius() const {
const std::array<float, 2>& translate = paint.evaluated.get<LineTranslate>();
- return getLineWidth() / 2.0 + std::abs(paint.evaluated.get<LineOffset>()) + util::length(translate[0], translate[1]);
+ auto offset = paint.evaluated.get<LineOffset>().constantOr(LineOffset::defaultValue());
+ return getLineWidth() / 2.0 + std::abs(offset) + util::length(translate[0], translate[1]);
}
bool LineLayer::Impl::queryIntersectsGeometry(
@@ -93,7 +88,9 @@ bool LineLayer::Impl::queryIntersectsGeometry(
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry, paint.evaluated.get<LineTranslate>(), paint.evaluated.get<LineTranslateAnchor>(), bearing, pixelsToTileUnits);
- auto offsetGeometry = offsetLine(geometry, paint.evaluated.get<LineOffset>() * pixelsToTileUnits);
+
+ auto offset = paint.evaluated.get<LineOffset>().constantOr(LineOffset::defaultValue());
+ auto offsetGeometry = offsetLine(geometry, offset * pixelsToTileUnits);
return util::polygonIntersectsBufferedMultiLine(
translatedQueryGeometry.value_or(queryGeometry),
diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp
index 1955c019af..67e793f2ea 100644
--- a/src/mbgl/style/layers/line_layer_impl.hpp
+++ b/src/mbgl/style/layers/line_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
float getQueryRadius() const override;
bool queryIntersectsGeometry(
diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp
index 2ea7f6b125..724026e3a6 100644
--- a/src/mbgl/style/layers/line_layer_properties.hpp
+++ b/src/mbgl/style/layers/line_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
@@ -29,11 +30,11 @@ struct LineRoundLimit : LayoutProperty<float> {
static float defaultValue() { return 1; }
};
-struct LineOpacity : PaintProperty<float> {
+struct LineOpacity : DataDrivenPaintProperty<float, attributes::a_opacity> {
static float defaultValue() { return 1; }
};
-struct LineColor : PaintProperty<Color> {
+struct LineColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};
@@ -49,15 +50,15 @@ struct LineWidth : PaintProperty<float> {
static float defaultValue() { return 1; }
};
-struct LineGapWidth : PaintProperty<float> {
+struct LineGapWidth : DataDrivenPaintProperty<float, attributes::a_gap_width> {
static float defaultValue() { return 0; }
};
-struct LineOffset : PaintProperty<float> {
+struct LineOffset : DataDrivenPaintProperty<float, attributes::a_offset<1>> {
static float defaultValue() { return 0; }
};
-struct LineBlur : PaintProperty<float> {
+struct LineBlur : DataDrivenPaintProperty<float, attributes::a_blur> {
static float defaultValue() { return 0; }
};
diff --git a/src/mbgl/style/layers/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp
index a78614aee9..a667ccb5a8 100644
--- a/src/mbgl/style/layers/raster_layer_impl.cpp
+++ b/src/mbgl/style/layers/raster_layer_impl.cpp
@@ -16,7 +16,8 @@ bool RasterLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters)
return paint.hasTransition();
}
-std::unique_ptr<Bucket> RasterLayer::Impl::createBucket(BucketParameters&, const GeometryTileLayer&) const {
+std::unique_ptr<Bucket> RasterLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const {
+ assert(false);
return nullptr;
}
diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp
index 8e69c21ca8..42985ce0f1 100644
--- a/src/mbgl/style/layers/raster_layer_impl.hpp
+++ b/src/mbgl/style/layers/raster_layer_impl.hpp
@@ -16,7 +16,7 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
RasterPaintProperties paint;
};
diff --git a/src/mbgl/style/layers/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp
index caa6d0c58d..219fe34d8c 100644
--- a/src/mbgl/style/layers/raster_layer_properties.hpp
+++ b/src/mbgl/style/layers/raster_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index c9014e7ee7..94c47f48b7 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -217,15 +217,15 @@ void SymbolLayer::setIconImage(PropertyValue<std::string> value) {
impl->layout.unevaluated.get<IconImage>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-image");
}
-PropertyValue<float> SymbolLayer::getDefaultIconRotate() {
+DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconRotate() {
return IconRotate::defaultValue();
}
-PropertyValue<float> SymbolLayer::getIconRotate() const {
+DataDrivenPropertyValue<float> SymbolLayer::getIconRotate() const {
return impl->layout.unevaluated.get<IconRotate>();
}
-void SymbolLayer::setIconRotate(PropertyValue<float> value) {
+void SymbolLayer::setIconRotate(DataDrivenPropertyValue<float> value) {
if (value == getIconRotate())
return;
impl->layout.unevaluated.get<IconRotate>() = value;
@@ -259,15 +259,15 @@ void SymbolLayer::setIconKeepUpright(PropertyValue<bool> value) {
impl->layout.unevaluated.get<IconKeepUpright>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright");
}
-PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconOffset() {
+DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconOffset() {
return IconOffset::defaultValue();
}
-PropertyValue<std::array<float, 2>> SymbolLayer::getIconOffset() const {
+DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getIconOffset() const {
return impl->layout.unevaluated.get<IconOffset>();
}
-void SymbolLayer::setIconOffset(PropertyValue<std::array<float, 2>> value) {
+void SymbolLayer::setIconOffset(DataDrivenPropertyValue<std::array<float, 2>> value) {
if (value == getIconOffset())
return;
impl->layout.unevaluated.get<IconOffset>() = value;
diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp
index f058598f5f..32547e465a 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.cpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.cpp
@@ -1,5 +1,5 @@
#include <mbgl/style/layers/symbol_layer_impl.hpp>
-#include <mbgl/style/bucket_parameters.hpp>
+#include <mbgl/style/property_evaluation_parameters.hpp>
#include <mbgl/layout/symbol_layout.hpp>
#include <mbgl/renderer/bucket.hpp>
@@ -24,52 +24,17 @@ bool SymbolLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters)
return paint.hasTransition();
}
-std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(BucketParameters&, const GeometryTileLayer&) const {
+std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(const BucketParameters&, const std::vector<const Layer*>&) const {
assert(false); // Should be calling createLayout() instead.
return nullptr;
}
-std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(BucketParameters& parameters,
- const GeometryTileLayer& layer,
- std::vector<std::string> group) const {
- PropertyEvaluationParameters p(parameters.tileID.overscaledZ);
- SymbolLayoutProperties::Evaluated evaluated = layout.evaluate(p);
-
- if (evaluated.get<IconRotationAlignment>() == AlignmentType::Auto) {
- if (evaluated.get<SymbolPlacement>() == SymbolPlacementType::Line) {
- evaluated.get<IconRotationAlignment>() = AlignmentType::Map;
- } else {
- evaluated.get<IconRotationAlignment>() = AlignmentType::Viewport;
- }
- }
-
- if (evaluated.get<TextRotationAlignment>() == AlignmentType::Auto) {
- if (evaluated.get<SymbolPlacement>() == SymbolPlacementType::Line) {
- evaluated.get<TextRotationAlignment>() = AlignmentType::Map;
- } else {
- evaluated.get<TextRotationAlignment>() = AlignmentType::Viewport;
- }
- }
-
- // If unspecified `text-pitch-alignment` inherits `text-rotation-alignment`
- if (evaluated.get<TextPitchAlignment>() == AlignmentType::Auto) {
- evaluated.get<TextPitchAlignment>() = evaluated.get<TextRotationAlignment>();
- }
-
- float textMaxSize = layout.evaluate<TextSize>(PropertyEvaluationParameters(18));
-
- evaluated.get<IconSize>() = layout.evaluate<IconSize>(PropertyEvaluationParameters(p.z + 1));
- evaluated.get<TextSize>() = layout.evaluate<TextSize>(PropertyEvaluationParameters(p.z + 1));
-
- return std::make_unique<SymbolLayout>(std::move(group),
- layer.getName(),
- parameters.tileID.overscaleFactor(),
- parameters.tileID.overscaledZ,
- parameters.mode,
+std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(const BucketParameters& parameters,
+ const std::vector<const Layer*>& group,
+ const GeometryTileLayer& layer) const {
+ return std::make_unique<SymbolLayout>(parameters,
+ group,
layer,
- filter,
- evaluated,
- textMaxSize,
*spriteAtlas);
}
diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp
index db18da07e2..c00c2b0bba 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.hpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.hpp
@@ -50,9 +50,9 @@ public:
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
- std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
- std::unique_ptr<SymbolLayout> createLayout(BucketParameters&, const GeometryTileLayer&,
- std::vector<std::string>) const;
+ std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override;
+ std::unique_ptr<SymbolLayout> createLayout(const BucketParameters&, const std::vector<const Layer*>&,
+ const GeometryTileLayer&) const;
SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const;
SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const;
diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp
index f5fd6ce3df..a447eb7efa 100644
--- a/src/mbgl/style/layers/symbol_layer_properties.hpp
+++ b/src/mbgl/style/layers/symbol_layer_properties.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/programs/attributes.hpp>
namespace mbgl {
namespace style {
@@ -64,7 +65,7 @@ struct IconImage : LayoutProperty<std::string> {
static std::string defaultValue() { return ""; }
};
-struct IconRotate : LayoutProperty<float> {
+struct IconRotate : DataDrivenLayoutProperty<float> {
static constexpr const char * key = "icon-rotate";
static float defaultValue() { return 0; }
};
@@ -79,7 +80,7 @@ struct IconKeepUpright : LayoutProperty<bool> {
static bool defaultValue() { return false; }
};
-struct IconOffset : LayoutProperty<std::array<float, 2>> {
+struct IconOffset : DataDrivenLayoutProperty<std::array<float, 2>> {
static constexpr const char * key = "icon-offset";
static std::array<float, 2> defaultValue() { return {{ 0, 0 }}; }
};
diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp
index 6ea06ce556..7ce2ecc7b8 100644
--- a/src/mbgl/style/layout_property.hpp
+++ b/src/mbgl/style/layout_property.hpp
@@ -1,6 +1,9 @@
#pragma once
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/style/property_evaluator.hpp>
+#include <mbgl/style/data_driven_property_evaluator.hpp>
#include <mbgl/util/indexed_tuple.hpp>
namespace mbgl {
@@ -11,11 +14,19 @@ class PropertyEvaluationParameters;
template <class T>
class LayoutProperty {
public:
- using EvaluatorType = PropertyEvaluator<T>;
using UnevaluatedType = PropertyValue<T>;
+ using EvaluatorType = PropertyEvaluator<T>;
using EvaluatedType = T;
};
+template <class T>
+class DataDrivenLayoutProperty {
+public:
+ using UnevaluatedType = DataDrivenPropertyValue<T>;
+ using EvaluatorType = DataDrivenPropertyEvaluator<T>;
+ using EvaluatedType = PossiblyEvaluatedPropertyValue<T>;
+};
+
template <class... Ps>
class LayoutProperties {
public:
diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp
index 7b56f6415d..9031d590fe 100644
--- a/src/mbgl/style/paint_property.hpp
+++ b/src/mbgl/style/paint_property.hpp
@@ -1,11 +1,15 @@
#pragma once
#include <mbgl/style/class_dictionary.hpp>
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/style/cross_faded_property_evaluator.hpp>
+#include <mbgl/style/data_driven_property_evaluator.hpp>
+#include <mbgl/style/property_evaluation_parameters.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/cascade_parameters.hpp>
-#include <mbgl/style/property_evaluation_parameters.hpp>
+#include <mbgl/style/paint_property_binder.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/indexed_tuple.hpp>
@@ -15,17 +19,18 @@
#include <utility>
namespace mbgl {
+
+class GeometryTileFeature;
+
namespace style {
-template <class T, class Evaluator>
+template <class Value>
class UnevaluatedPaintProperty {
public:
- using Result = typename Evaluator::ResultType;
-
UnevaluatedPaintProperty() = default;
- UnevaluatedPaintProperty(PropertyValue<T> value_,
- UnevaluatedPaintProperty<T, Evaluator> prior_,
+ UnevaluatedPaintProperty(Value value_,
+ UnevaluatedPaintProperty<Value> prior_,
TransitionOptions transition,
TimePoint now)
: begin(now + transition.delay.value_or(Duration::zero())),
@@ -36,22 +41,23 @@ public:
}
}
- Result evaluate(const PropertyEvaluationParameters& parameters, T defaultValue) {
- Result finalValue = value.evaluate(Evaluator(parameters, defaultValue));
+ template <class Evaluator>
+ auto evaluate(const Evaluator& evaluator, TimePoint now) {
+ auto finalValue = value.evaluate(evaluator);
if (!prior) {
// No prior value.
return finalValue;
- } else if (parameters.now >= end) {
+ } else if (now >= end) {
// Transition from prior value is now complete.
prior = {};
return finalValue;
- } else if (parameters.now < begin) {
+ } else if (now < begin) {
// Transition hasn't started yet.
- return prior->get().evaluate(parameters, defaultValue);
+ return prior->get().evaluate(evaluator, now);
} else {
// Interpolate between recursively-calculated prior value and final.
- float t = std::chrono::duration<float>(parameters.now - begin) / (end - begin);
- return util::interpolate(prior->get().evaluate(parameters, defaultValue), finalValue, util::DEFAULT_TRANSITION_EASE.solve(t, 0.001));
+ float t = std::chrono::duration<float>(now - begin) / (end - begin);
+ return util::interpolate(prior->get().evaluate(evaluator, now), finalValue, util::DEFAULT_TRANSITION_EASE.solve(t, 0.001));
}
}
@@ -63,27 +69,31 @@ public:
return value.isUndefined();
}
+ const Value& getValue() const {
+ return value;
+ }
+
private:
- optional<mapbox::util::recursive_wrapper<UnevaluatedPaintProperty<T, Evaluator>>> prior;
+ optional<mapbox::util::recursive_wrapper<UnevaluatedPaintProperty<Value>>> prior;
TimePoint begin;
TimePoint end;
- PropertyValue<T> value;
+ Value value;
};
-template <class T>
+template <class Value>
class CascadingPaintProperty {
public:
bool isUndefined() const {
return values.find(ClassID::Default) == values.end();
}
- const PropertyValue<T>& get(const optional<std::string>& klass) const {
- static const PropertyValue<T> staticValue;
+ const Value& get(const optional<std::string>& klass) const {
+ static const Value staticValue{};
const auto it = values.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default);
return it == values.end() ? staticValue : it->second;
}
- void set(const PropertyValue<T>& value_, const optional<std::string>& klass) {
+ void set(const Value& value_, const optional<std::string>& klass) {
values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_;
}
@@ -94,7 +104,7 @@ public:
template <class UnevaluatedPaintProperty>
UnevaluatedPaintProperty cascade(const CascadeParameters& params, UnevaluatedPaintProperty prior) const {
TransitionOptions transition;
- PropertyValue<T> value;
+ Value value;
for (const auto classID : params.classes) {
if (values.find(classID) != values.end()) {
@@ -117,7 +127,7 @@ public:
}
private:
- std::unordered_map<ClassID, PropertyValue<T>> values;
+ std::unordered_map<ClassID, Value> values;
std::unordered_map<ClassID, TransitionOptions> transitions;
};
@@ -125,26 +135,48 @@ template <class T>
class PaintProperty {
public:
using ValueType = PropertyValue<T>;
- using CascadingType = CascadingPaintProperty<T>;
+ using CascadingType = CascadingPaintProperty<ValueType>;
+ using UnevaluatedType = UnevaluatedPaintProperty<ValueType>;
using EvaluatorType = PropertyEvaluator<T>;
- using UnevaluatedType = UnevaluatedPaintProperty<T, EvaluatorType>;
using EvaluatedType = T;
+ static constexpr bool IsDataDriven = false;
+};
+
+template <class T, class A>
+class DataDrivenPaintProperty {
+public:
+ using ValueType = DataDrivenPropertyValue<T>;
+ using CascadingType = CascadingPaintProperty<ValueType>;
+ using UnevaluatedType = UnevaluatedPaintProperty<ValueType>;
+ using EvaluatorType = DataDrivenPropertyEvaluator<T>;
+ using EvaluatedType = PossiblyEvaluatedPropertyValue<T>;
+ static constexpr bool IsDataDriven = true;
+
+ using Type = T;
+ using Attribute = A;
};
template <class T>
class CrossFadedPaintProperty {
public:
using ValueType = PropertyValue<T>;
- using CascadingType = CascadingPaintProperty<T>;
+ using CascadingType = CascadingPaintProperty<ValueType>;
+ using UnevaluatedType = UnevaluatedPaintProperty<ValueType>;
using EvaluatorType = CrossFadedPropertyEvaluator<T>;
- using UnevaluatedType = UnevaluatedPaintProperty<T, EvaluatorType>;
using EvaluatedType = Faded<T>;
+ static constexpr bool IsDataDriven = false;
};
+template <class P>
+struct IsDataDriven : std::integral_constant<bool, P::IsDataDriven> {};
+
template <class... Ps>
class PaintProperties {
public:
using Properties = TypeList<Ps...>;
+ using DataDrivenProperties = FilteredTypeList<Properties, IsDataDriven>;
+ using Binders = PaintPropertyBinders<DataDrivenProperties>;
+
using EvaluatedTypes = TypeList<typename Ps::EvaluatedType...>;
using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
using CascadingTypes = TypeList<typename Ps::CascadingType...>;
@@ -186,7 +218,9 @@ public:
template <class P>
auto evaluate(const PropertyEvaluationParameters& parameters) {
- return unevaluated.template get<P>().evaluate(parameters, P::defaultValue());
+ using Evaluator = typename P::EvaluatorType;
+ return unevaluated.template get<P>()
+ .evaluate(Evaluator(parameters, P::defaultValue()), parameters.now);
}
void evaluate(const PropertyEvaluationParameters& parameters) {
diff --git a/src/mbgl/style/paint_property_binder.hpp b/src/mbgl/style/paint_property_binder.hpp
new file mode 100644
index 0000000000..964f33d2ec
--- /dev/null
+++ b/src/mbgl/style/paint_property_binder.hpp
@@ -0,0 +1,283 @@
+#pragma once
+
+#include <mbgl/programs/attributes.hpp>
+#include <mbgl/gl/attribute.hpp>
+#include <mbgl/gl/uniform.hpp>
+#include <mbgl/util/type_list.hpp>
+
+namespace mbgl {
+namespace style {
+
+template <class T, class A>
+class ConstantPaintPropertyBinder {
+public:
+ using Attribute = A;
+ using AttributeValue = typename Attribute::Value;
+ using AttributeBinding = typename Attribute::Binding;
+
+ ConstantPaintPropertyBinder(T constant_)
+ : constant(std::move(constant_)) {
+ }
+
+ void populateVertexVector(const GeometryTileFeature&, std::size_t) {}
+ void upload(gl::Context&) {}
+
+ AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const {
+ return typename Attribute::ConstantBinding {
+ Attribute::value(currentValue.constantOr(constant))
+ };
+ }
+
+ AttributeBinding maxAttributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const {
+ return AttributeBinding();
+ }
+
+ float interpolationFactor(float) const {
+ return 0.0f;
+ }
+
+private:
+ T constant;
+};
+
+template <class T, class A>
+class SourceFunctionPaintPropertyBinder {
+public:
+ using Attribute = A;
+ using AttributeValue = typename Attribute::Value;
+ using AttributeBinding = typename Attribute::Binding;
+
+ using Attributes = gl::Attributes<Attribute>;
+ using Vertex = typename Attributes::Vertex;
+
+ SourceFunctionPaintPropertyBinder(SourceFunction<T> function_)
+ : function(std::move(function_)) {
+ }
+
+ void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) {
+ AttributeValue value = Attribute::value(function.evaluate(feature));
+ for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) {
+ vertexVector.emplace_back(Vertex { value });
+ }
+ }
+
+ void upload(gl::Context& context) {
+ vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
+ }
+
+ AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const {
+ if (currentValue.isConstant()) {
+ return typename Attribute::ConstantBinding {
+ Attribute::value(*currentValue.constant())
+ };
+ } else {
+ return Attributes::allVariableBindings(*vertexBuffer)
+ .template get<Attribute>();
+ }
+ }
+
+ AttributeBinding maxAttributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const {
+ return AttributeBinding();
+ }
+
+ float interpolationFactor(float) const {
+ return 0.0f;
+ }
+
+private:
+ SourceFunction<T> function;
+ gl::VertexVector<Vertex> vertexVector;
+ optional<gl::VertexBuffer<Vertex>> vertexBuffer;
+};
+
+template <class T, class A>
+class CompositeFunctionPaintPropertyBinder {
+public:
+ using Attribute = A;
+ using AttributeValue = typename Attribute::Value;
+ using AttributeBinding = typename Attribute::Binding;
+
+ using MinAttribute = attributes::Min<Attribute>;
+ using MaxAttribute = attributes::Max<Attribute>;
+
+ using Attributes = gl::Attributes<MinAttribute, MaxAttribute>;
+ using Vertex = typename Attributes::Vertex;
+
+ CompositeFunctionPaintPropertyBinder(CompositeFunction<T> function_, float zoom)
+ : function(std::move(function_)),
+ coveringRanges(function.coveringRanges(zoom)) {
+ }
+
+ void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) {
+ Range<T> range = function.evaluate(std::get<1>(coveringRanges), feature);
+ AttributeValue min = Attribute::value(range.min);
+ AttributeValue max = Attribute::value(range.max);
+ for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) {
+ vertexVector.emplace_back(Vertex { min, max });
+ }
+ }
+
+ void upload(gl::Context& context) {
+ vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
+ }
+
+ AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const {
+ if (currentValue.isConstant()) {
+ return typename Attribute::ConstantBinding {
+ Attribute::value(*currentValue.constant())
+ };
+ } else {
+ return Attributes::allVariableBindings(*vertexBuffer)
+ .template get<MinAttribute>();
+ }
+ }
+
+ AttributeBinding maxAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const {
+ if (currentValue.isConstant()) {
+ return AttributeBinding();
+ } else {
+ return Attributes::allVariableBindings(*vertexBuffer)
+ .template get<MaxAttribute>();
+ }
+ }
+
+ float interpolationFactor(float currentZoom) const {
+ return util::interpolationFactor(1.0f, std::get<0>(coveringRanges), currentZoom);
+ }
+
+private:
+ using InnerStops = typename CompositeFunction<T>::InnerStops;
+ CompositeFunction<T> function;
+ std::tuple<Range<float>, Range<InnerStops>> coveringRanges;
+ gl::VertexVector<Vertex> vertexVector;
+ optional<gl::VertexBuffer<Vertex>> vertexBuffer;
+};
+
+template <class PaintProperty>
+class PaintPropertyBinder {
+public:
+ using Type = typename PaintProperty::Type;
+ using Attribute = typename PaintProperty::Attribute;
+ using PropertyValue = typename PaintProperty::EvaluatedType;
+
+ using Binder = variant<
+ ConstantPaintPropertyBinder<Type, Attribute>,
+ SourceFunctionPaintPropertyBinder<Type, Attribute>,
+ CompositeFunctionPaintPropertyBinder<Type, Attribute>>;
+
+ PaintPropertyBinder(const PropertyValue& value, float zoom)
+ : binder(value.match(
+ [&] (const Type& constant) -> Binder {
+ return ConstantPaintPropertyBinder<Type, Attribute>(constant);
+ },
+ [&] (const SourceFunction<Type>& function) {
+ return SourceFunctionPaintPropertyBinder<Type, Attribute>(function);
+ },
+ [&] (const CompositeFunction<Type>& function) {
+ return CompositeFunctionPaintPropertyBinder<Type, Attribute>(function, zoom);
+ }
+ )) {
+ }
+
+ void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) {
+ binder.match([&] (auto& b) {
+ b.populateVertexVector(feature, length);
+ });
+ }
+
+ void upload(gl::Context& context) {
+ binder.match([&] (auto& b) {
+ b.upload(context);
+ });
+ }
+
+ using MinAttribute = attributes::Min<Attribute>;
+ using MaxAttribute = attributes::Max<Attribute>;
+ using AttributeBinding = typename Attribute::Binding;
+
+ AttributeBinding minAttributeBinding(const PropertyValue& currentValue) const {
+ return binder.match([&] (const auto& b) {
+ return b.minAttributeBinding(currentValue);
+ });
+ }
+
+ AttributeBinding maxAttributeBinding(const PropertyValue& currentValue) const {
+ return binder.match([&] (const auto& b) {
+ return b.maxAttributeBinding(currentValue);
+ });
+ }
+
+ using InterpolationUniform = attributes::InterpolationUniform<Attribute>;
+ using InterpolationUniformValue = typename InterpolationUniform::Value;
+
+ InterpolationUniformValue interpolationUniformValue(float currentZoom) const {
+ return InterpolationUniformValue {
+ binder.match([&] (const auto& b) {
+ return b.interpolationFactor(currentZoom);
+ })
+ };
+ }
+
+private:
+ Binder binder;
+};
+
+template <class Ps>
+class PaintPropertyBinders;
+
+template <class... Ps>
+class PaintPropertyBinders<TypeList<Ps...>> {
+public:
+ using Binders = IndexedTuple<TypeList<Ps...>, TypeList<PaintPropertyBinder<Ps>...>>;
+
+ template <class EvaluatedProperties>
+ PaintPropertyBinders(const EvaluatedProperties& properties, float z)
+ : binders(PaintPropertyBinder<Ps>(properties.template get<Ps>(), z)...) {
+ (void)z; // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958
+ }
+
+ void populateVertexVectors(const GeometryTileFeature& feature, std::size_t length) {
+ util::ignore({
+ (binders.template get<Ps>().populateVertexVector(feature, length), 0)...
+ });
+ }
+
+ void upload(gl::Context& context) {
+ util::ignore({
+ (binders.template get<Ps>().upload(context), 0)...
+ });
+ }
+
+ using MinAttributes = gl::Attributes<typename PaintPropertyBinder<Ps>::MinAttribute...>;
+ using MaxAttributes = gl::Attributes<typename PaintPropertyBinder<Ps>::MaxAttribute...>;
+
+ using Attributes = gl::ConcatenateAttributes<MinAttributes, MaxAttributes>;
+ using AttributeBindings = typename Attributes::Bindings;
+
+ template <class EvaluatedProperties>
+ AttributeBindings attributeBindings(const EvaluatedProperties& currentProperties) const {
+ const typename MinAttributes::Bindings min {
+ binders.template get<Ps>().minAttributeBinding(currentProperties.template get<Ps>())...
+ };
+ const typename MaxAttributes::Bindings max {
+ binders.template get<Ps>().maxAttributeBinding(currentProperties.template get<Ps>())...
+ };
+ return min.concat(max);
+ }
+
+ using Uniforms = gl::Uniforms<typename PaintPropertyBinder<Ps>::InterpolationUniform...>;
+ using UniformValues = typename Uniforms::Values;
+
+ UniformValues uniformValues(float currentZoom) const {
+ (void)currentZoom; // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958
+ return UniformValues {
+ binders.template get<Ps>().interpolationUniformValue(currentZoom)...
+ };
+ }
+
+private:
+ Binders binders;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index c6c6e50dd7..926c243733 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -241,10 +241,14 @@ std::vector<FontStack> Parser::fontStacks() const {
result.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
} else if (textFont.isConstant()) {
result.insert(textFont.asConstant());
- } else if (textFont.isFunction()) {
- for (const auto& stop : textFont.asFunction().getStops()) {
- result.insert(stop.second);
- }
+ } else if (textFont.isCameraFunction()) {
+ textFont.asCameraFunction().stops.match(
+ [&] (const auto& stops) {
+ for (const auto& stop : stops.stops) {
+ result.insert(stop.second);
+ }
+ }
+ );
}
}
}
diff --git a/src/mbgl/style/possibly_evaluated_property_value.hpp b/src/mbgl/style/possibly_evaluated_property_value.hpp
new file mode 100644
index 0000000000..bb917442f6
--- /dev/null
+++ b/src/mbgl/style/possibly_evaluated_property_value.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+#include <mbgl/style/function/source_function.hpp>
+#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/util/interpolate.hpp>
+#include <mbgl/util/variant.hpp>
+
+namespace mbgl {
+
+class GeometryTileFeature;
+
+namespace style {
+
+template <class T>
+class PossiblyEvaluatedPropertyValue {
+private:
+ using Value = variant<
+ T,
+ SourceFunction<T>,
+ CompositeFunction<T>>;
+
+ Value value;
+
+public:
+ PossiblyEvaluatedPropertyValue() = default;
+ PossiblyEvaluatedPropertyValue(Value v) : value(std::move(v)) {}
+
+ bool isConstant() const {
+ return value.template is<T>();
+ }
+
+ optional<T> constant() const {
+ return value.match(
+ [&] (const T& t) { return optional<T>(t); },
+ [&] (const auto&) { return optional<T>(); });
+ }
+
+ T constantOr(const T& t) const {
+ return constant().value_or(t);
+ }
+
+ template <class... Ts>
+ auto match(Ts&&... ts) const {
+ return value.match(std::forward<Ts>(ts)...);
+ }
+
+ T evaluate(float z, const GeometryTileFeature& feature) const {
+ return value.match(
+ [&] (const T& t) { return t; },
+ [&] (const SourceFunction<T>& t) { return t.evaluate(feature); },
+ [&] (const CompositeFunction<T>& t) { return t.evaluate(z, feature); });
+ }
+};
+
+} // namespace style
+
+namespace util {
+
+template <typename T>
+struct Interpolator<style::PossiblyEvaluatedPropertyValue<T>> {
+ style::PossiblyEvaluatedPropertyValue<T> operator()(const style::PossiblyEvaluatedPropertyValue<T>& a,
+ const style::PossiblyEvaluatedPropertyValue<T>& b,
+ const double t) const {
+ if (a.isConstant() && b.isConstant()) {
+ return { interpolate(*a.constant(), *b.constant(), t) };
+ } else {
+ return { a };
+ }
+ }
+};
+
+} // namespace util
+
+} // namespace mbgl
diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp
index ca4962d948..3f629ada4f 100644
--- a/src/mbgl/style/property_evaluator.hpp
+++ b/src/mbgl/style/property_evaluator.hpp
@@ -17,7 +17,7 @@ public:
T operator()(const Undefined&) const { return defaultValue; }
T operator()(const T& constant) const { return constant; }
- T operator()(const Function<T>& fn) const { return fn.evaluate(parameters.z); }
+ T operator()(const CameraFunction<T>& fn) const { return fn.evaluate(parameters.z); }
private:
const PropertyEvaluationParameters& parameters;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index d6a525f502..61fbba67b5 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -662,6 +662,11 @@ void Style::onLayerPaintPropertyChanged(Layer&) {
observer->onUpdate(Update::RecalculateStyle | Update::Classes);
}
+void Style::onLayerDataDrivenPaintPropertyChanged(Layer& layer) {
+ layer.accept(QueueSourceReloadVisitor { updateBatch });
+ observer->onUpdate(Update::RecalculateStyle | Update::Classes | Update::Layout);
+}
+
void Style::onLayerLayoutPropertyChanged(Layer& layer, const char * property) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index d46e80e8bf..4c4bcec63a 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -146,6 +146,7 @@ private:
void onLayerFilterChanged(Layer&) override;
void onLayerVisibilityChanged(Layer&) override;
void onLayerPaintPropertyChanged(Layer&) override;
+ void onLayerDataDrivenPaintPropertyChanged(Layer&) override;
void onLayerLayoutPropertyChanged(Layer&, const char *) override;
Observer nullObserver;
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index 1a05e6f94f..10c4dfea90 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -62,7 +62,7 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
bl = {left, bottom};
}
- float angle = layout.get<IconRotate>() * util::DEG2RAD;
+ float angle = shapedIcon.angle;
if (placement == style::SymbolPlacementType::Line) {
assert(static_cast<unsigned int>(anchor.segment) < line.size());
const GeometryCoordinate &prev= line[anchor.segment];
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 062066aaf4..b43ba0220c 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -1,19 +1,18 @@
#include <mbgl/text/shaping.hpp>
-#include <mbgl/style/layers/symbol_layer_properties.hpp>
+#include <mbgl/layout/symbol_feature.hpp>
namespace mbgl {
-using namespace style;
-
-PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties::Evaluated& layout) {
- float dx = layout.get<IconOffset>()[0];
- float dy = layout.get<IconOffset>()[1];
+PositionedIcon shapeIcon(const SpriteAtlasElement& image,
+ const SymbolFeature& feature) {
+ float dx = feature.iconOffset[0];
+ float dy = feature.iconOffset[1];
float x1 = dx - image.spriteImage->getWidth() / 2.0f;
float x2 = x1 + image.spriteImage->getWidth();
float y1 = dy - image.spriteImage->getHeight() / 2.0f;
float y2 = y1 + image.spriteImage->getHeight();
- return PositionedIcon(image, y1, y2, x1, x2);
+ return PositionedIcon(image, y1, y2, x1, x2, feature.iconRotation);
}
} // namespace mbgl
diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp
index 30375179b6..b0e6ae3b1d 100644
--- a/src/mbgl/text/shaping.hpp
+++ b/src/mbgl/text/shaping.hpp
@@ -3,29 +3,40 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/sprite/sprite_image.hpp>
-#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
class SpriteAtlasElement;
+class SymbolFeature;
class PositionedIcon {
- public:
- explicit PositionedIcon() {}
- explicit PositionedIcon(const SpriteAtlasElement& _image,
- float _top, float _bottom, float _left, float _right) :
- image(_image), top(_top), bottom(_bottom), left(_left), right(_right) {}
-
- optional<SpriteAtlasElement> image;
- float top = 0;
- float bottom = 0;
- float left = 0;
- float right = 0;
-
- explicit operator bool() const { return image && (*image).pos.hasArea(); }
+public:
+ PositionedIcon() = default;
+ PositionedIcon(const SpriteAtlasElement& image_,
+ float top_,
+ float bottom_,
+ float left_,
+ float right_,
+ float angle_)
+ : image(image_),
+ top(top_),
+ bottom(bottom_),
+ left(left_),
+ right(right_),
+ angle(angle_) {}
+
+ optional<SpriteAtlasElement> image;
+ float top = 0;
+ float bottom = 0;
+ float left = 0;
+ float right = 0;
+ float angle = 0;
+
+ explicit operator bool() const { return image && (*image).pos.hasArea(); }
};
-PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties::Evaluated&);
+PositionedIcon shapeIcon(const SpriteAtlasElement&,
+ const SymbolFeature&);
} // namespace mbgl
diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp
index 2a86b7feda..b1fd7a852e 100644
--- a/src/mbgl/tile/geometry_tile_worker.cpp
+++ b/src/mbgl/tile/geometry_tile_worker.cpp
@@ -6,6 +6,8 @@
#include <mbgl/layout/symbol_layout.hpp>
#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/style/group_by_layout.hpp>
+#include <mbgl/style/filter.hpp>
+#include <mbgl/style/filter_evaluator.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
@@ -212,7 +214,7 @@ void GeometryTileWorker::redoLayout() {
std::unordered_map<std::string, std::unique_ptr<SymbolLayout>> symbolLayoutMap;
std::unordered_map<std::string, std::shared_ptr<Bucket>> buckets;
auto featureIndex = std::make_unique<FeatureIndex>();
- BucketParameters parameters { id, obsolete, *featureIndex, mode };
+ BucketParameters parameters { id, mode };
std::vector<std::vector<const Layer*>> groups = groupByLayout(*layers);
for (auto& group : groups) {
@@ -240,12 +242,27 @@ void GeometryTileWorker::redoLayout() {
if (leader.is<SymbolLayer>()) {
symbolLayoutMap.emplace(leader.getID(),
- leader.as<SymbolLayer>()->impl->createLayout(parameters, *geometryLayer, layerIDs));
+ leader.as<SymbolLayer>()->impl->createLayout(parameters, group, *geometryLayer));
} else {
- std::shared_ptr<Bucket> bucket = leader.baseImpl->createBucket(parameters, *geometryLayer);
+ const Filter& filter = leader.baseImpl->filter;
+ const std::string& sourceLayerID = leader.baseImpl->sourceLayer;
+ std::shared_ptr<Bucket> bucket = leader.baseImpl->createBucket(parameters, group);
+
+ for (std::size_t i = 0; !obsolete && i < geometryLayer->featureCount(); i++) {
+ std::unique_ptr<GeometryTileFeature> feature = geometryLayer->getFeature(i);
+
+ if (!filter(feature->getType(), feature->getID(), [&] (const auto& key) { return feature->getValue(key); }))
+ continue;
+
+ GeometryCollection geometries = feature->getGeometries();
+ bucket->addFeature(*feature, geometries);
+ featureIndex->insert(geometries, i, sourceLayerID, leader.getID());
+ }
+
if (!bucket->hasData()) {
continue;
}
+
for (const auto& layer : group) {
buckets.emplace(layer->getID(), bucket);
}
@@ -324,8 +341,8 @@ void GeometryTileWorker::attemptPlacement() {
}
std::shared_ptr<Bucket> bucket = symbolLayout->place(*collisionTile);
- for (const auto& layerID : symbolLayout->layerIDs) {
- buckets.emplace(layerID, bucket);
+ for (const auto& pair : symbolLayout->layerPaintProperties) {
+ buckets.emplace(pair.first, bucket);
}
}
diff --git a/src/mbgl/util/ignore.hpp b/src/mbgl/util/ignore.hpp
index 955b1de2fa..577bcf4d91 100644
--- a/src/mbgl/util/ignore.hpp
+++ b/src/mbgl/util/ignore.hpp
@@ -19,5 +19,8 @@ template <class... Ts> void ignore(Ts&&...) {}
//
template <class T> void ignore(const std::initializer_list<T>&) {}
+// Handle the zero-argument case.
+inline void ignore(const std::initializer_list<int>&) {}
+
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/indexed_tuple.hpp b/src/mbgl/util/indexed_tuple.hpp
index 110e7dce12..a414639530 100644
--- a/src/mbgl/util/indexed_tuple.hpp
+++ b/src/mbgl/util/indexed_tuple.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <mbgl/util/type_list.hpp>
+
#include <type_traits>
#include <tuple>
@@ -14,8 +16,6 @@ struct TypeIndex<T, T, Ts...> : std::integral_constant<std::size_t, 0> {};
template <class T, class U, class... Ts>
struct TypeIndex<T, U, Ts...> : std::integral_constant<std::size_t, 1 + TypeIndex<T, Ts...>::value> {};
-template <class...> class TypeList {};
-
template <class...> class IndexedTuple;
// A tuple of Ts, where individual members can be accessed via `t.get<I>()` for I ∈ Is.
@@ -42,6 +42,15 @@ public:
const auto& get() const {
return std::get<Index<I>>(*this);
}
+
+ template <class... Js, class... Us>
+ IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>>
+ concat(const IndexedTuple<TypeList<Js...>, TypeList<Us...>>& other) const {
+ return IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>> {
+ get<Is>()...,
+ other.template get<Js>()...
+ };
+ }
};
} // namespace mbgl
diff --git a/src/mbgl/util/interpolate.cpp b/src/mbgl/util/interpolate.cpp
new file mode 100644
index 0000000000..306a5c6630
--- /dev/null
+++ b/src/mbgl/util/interpolate.cpp
@@ -0,0 +1,19 @@
+#include <mbgl/util/interpolate.hpp>
+
+#include <cmath>
+
+namespace mbgl {
+namespace util {
+
+float interpolationFactor(float base, Range<float> range, float z) {
+ const float zoomDiff = range.max - range.min;
+ const float zoomProgress = z - range.min;
+ if (base == 1.0f) {
+ return zoomProgress / zoomDiff;
+ } else {
+ return (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
+ }
+}
+
+} // namespace util
+} // namespace mbgl
diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp
index ef066377da..d463ffc056 100644
--- a/src/mbgl/util/interpolate.hpp
+++ b/src/mbgl/util/interpolate.hpp
@@ -1,15 +1,19 @@
#pragma once
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/range.hpp>
+
#include <array>
#include <vector>
#include <string>
#include <type_traits>
#include <utility>
-#include <mbgl/util/color.hpp>
namespace mbgl {
namespace util {
+float interpolationFactor(float base, Range<float> range, float z);
+
template <class T, class Enabled = void>
struct Interpolator;
@@ -78,5 +82,8 @@ template <class T>
struct Interpolator<std::vector<T>>
: Uninterpolated {};
+template <class T>
+constexpr bool Interpolatable = !std::is_base_of<Uninterpolated, Interpolator<T>>::value;
+
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/type_list.hpp b/src/mbgl/util/type_list.hpp
new file mode 100644
index 0000000000..4a5e95c8a4
--- /dev/null
+++ b/src/mbgl/util/type_list.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <type_traits>
+#include <tuple>
+
+namespace mbgl {
+
+template <class...>
+class TypeList {};
+
+namespace detail {
+
+template <class, class>
+struct TypeCons;
+
+template <class T, class... Ts>
+struct TypeCons<T, TypeList<Ts...>> {
+ using Type = TypeList<T, Ts...>;
+};
+
+template <class, template <class> class>
+struct TypeFilter;
+
+template <template <class> class Predicate>
+struct TypeFilter<TypeList<>, Predicate> {
+ using Type = TypeList<>;
+};
+
+template <template <class> class Predicate, class T, class... Ts>
+struct TypeFilter<TypeList<T, Ts...>, Predicate> {
+ using Tail = typename TypeFilter<TypeList<Ts...>, Predicate>::Type;
+ using Type = std::conditional_t<Predicate<T>::value, typename TypeCons<T, Tail>::Type, Tail>;
+};
+
+} // namespace detail
+
+template <class TypeList, template <class> class Predicate>
+using FilteredTypeList = typename detail::TypeFilter<TypeList, Predicate>::Type;
+
+} // namespace mbgl