diff options
Diffstat (limited to 'src/mbgl/style/paint_property_binder.hpp')
-rw-r--r-- | src/mbgl/style/paint_property_binder.hpp | 123 |
1 files changed, 46 insertions, 77 deletions
diff --git a/src/mbgl/style/paint_property_binder.hpp b/src/mbgl/style/paint_property_binder.hpp index 79c7692b2f..17c99fe1d9 100644 --- a/src/mbgl/style/paint_property_binder.hpp +++ b/src/mbgl/style/paint_property_binder.hpp @@ -11,8 +11,11 @@ namespace style { template <class T, class A> class ConstantPaintPropertyBinder { public: - using Attribute = A; - using AttributeValue = typename Attribute::Value; + using BaseAttribute = A; + using BaseAttributeValue = typename BaseAttribute::Value; + using BaseAttributeBinding = typename BaseAttribute::Binding; + + using Attribute = attributes::ZoomInterpolatedAttribute<BaseAttribute>; using AttributeBinding = typename Attribute::Binding; ConstantPaintPropertyBinder(T constant_) @@ -22,16 +25,13 @@ public: void populateVertexVector(const GeometryTileFeature&, std::size_t) {} void upload(gl::Context&) {} - AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { + AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { + auto val = currentValue.constantOr(constant); return typename Attribute::ConstantBinding { - Attribute::value(currentValue.constantOr(constant)) + Attribute::value(val, val) }; } - AttributeBinding maxAttributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const { - return AttributeBinding(); - } - float interpolationFactor(float) const { return 0.0f; } @@ -43,12 +43,13 @@ private: template <class T, class A> class SourceFunctionPaintPropertyBinder { public: - using Attribute = A; - using AttributeValue = typename Attribute::Value; - using AttributeBinding = typename Attribute::Binding; + using BaseAttribute = A; + using BaseAttributeValue = typename BaseAttribute::Value; + using BaseAttributeBinding = typename BaseAttribute::Binding; + using BaseVertex = typename gl::Attributes<BaseAttribute>::Vertex; - using Attributes = gl::Attributes<Attribute>; - using Vertex = typename Attributes::Vertex; + using Attribute = attributes::ZoomInterpolatedAttribute<BaseAttribute>; + using AttributeBinding = typename Attribute::Binding; SourceFunctionPaintPropertyBinder(SourceFunction<T> function_, T defaultValue_) : function(std::move(function_)), @@ -56,9 +57,10 @@ public: } void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) { - AttributeValue value = Attribute::value(function.evaluate(feature, defaultValue)); + auto val = function.evaluate(feature, defaultValue); + BaseAttributeValue value = BaseAttribute::value(val); for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) { - vertexVector.emplace_back(Vertex { value }); + vertexVector.emplace_back(BaseVertex { value }); } } @@ -66,21 +68,17 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { + AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { if (currentValue.isConstant()) { + auto val = *currentValue.constant(); return typename Attribute::ConstantBinding { - Attribute::value(*currentValue.constant()) + Attribute::value(val, val) }; } else { - return Attributes::allVariableBindings(*vertexBuffer) - .template get<Attribute>(); + return Attribute::variableBinding(*vertexBuffer, 0, BaseAttribute::Dimensions); } } - AttributeBinding maxAttributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const { - return AttributeBinding(); - } - float interpolationFactor(float) const { return 0.0f; } @@ -88,22 +86,17 @@ public: private: SourceFunction<T> function; T defaultValue; - gl::VertexVector<Vertex> vertexVector; - optional<gl::VertexBuffer<Vertex>> vertexBuffer; + gl::VertexVector<BaseVertex> vertexVector; + optional<gl::VertexBuffer<BaseVertex>> vertexBuffer; }; template <class T, class A> class CompositeFunctionPaintPropertyBinder { public: - using Attribute = A; + using Attribute = attributes::ZoomInterpolatedAttribute<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; + using Vertex = typename gl::Attributes<Attribute>::Vertex; CompositeFunctionPaintPropertyBinder(CompositeFunction<T> function_, float zoom, T defaultValue_) : function(std::move(function_)), @@ -113,10 +106,9 @@ public: void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) { Range<T> range = function.evaluate(std::get<1>(coveringRanges), feature, defaultValue); - AttributeValue min = Attribute::value(range.min); - AttributeValue max = Attribute::value(range.max); + AttributeValue minMax = Attribute::value(range.min, range.max); for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) { - vertexVector.emplace_back(Vertex { min, max }); + vertexVector.emplace_back(Vertex { minMax }); } } @@ -124,23 +116,14 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - AttributeBinding minAttributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { + AttributeBinding attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const { if (currentValue.isConstant()) { + auto val = *currentValue.constant(); return typename Attribute::ConstantBinding { - Attribute::value(*currentValue.constant()) + Attribute::value(val, val) }; } 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>(); + return Attribute::variableBinding(*vertexBuffer, 0); } } @@ -161,24 +144,27 @@ template <class PaintProperty> class PaintPropertyBinder { public: using Type = typename PaintProperty::Type; - using Attribute = typename PaintProperty::Attribute; using PropertyValue = typename PaintProperty::EvaluatedType; + using BaseAttribute = typename PaintProperty::Attribute; + using Attribute = attributes::ZoomInterpolatedAttribute<BaseAttribute>; + using AttributeBinding = typename Attribute::Binding; + using Binder = variant< - ConstantPaintPropertyBinder<Type, Attribute>, - SourceFunctionPaintPropertyBinder<Type, Attribute>, - CompositeFunctionPaintPropertyBinder<Type, Attribute>>; + ConstantPaintPropertyBinder<Type, BaseAttribute>, + SourceFunctionPaintPropertyBinder<Type, BaseAttribute>, + CompositeFunctionPaintPropertyBinder<Type, BaseAttribute>>; PaintPropertyBinder(const PropertyValue& value, float zoom) : binder(value.match( [&] (const Type& constant) -> Binder { - return ConstantPaintPropertyBinder<Type, Attribute>(constant); + return ConstantPaintPropertyBinder<Type, BaseAttribute>(constant); }, [&] (const SourceFunction<Type>& function) { - return SourceFunctionPaintPropertyBinder<Type, Attribute>(function, PaintProperty::defaultValue()); + return SourceFunctionPaintPropertyBinder<Type, BaseAttribute>(function, PaintProperty::defaultValue()); }, [&] (const CompositeFunction<Type>& function) { - return CompositeFunctionPaintPropertyBinder<Type, Attribute>(function, zoom, PaintProperty::defaultValue()); + return CompositeFunctionPaintPropertyBinder<Type, BaseAttribute>(function, zoom, PaintProperty::defaultValue()); } )) { } @@ -195,19 +181,9 @@ public: }); } - 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 { + AttributeBinding attributeBinding(const PropertyValue& currentValue) const { return binder.match([&] (const auto& b) { - return b.maxAttributeBinding(currentValue); + return b.attributeBinding(currentValue); }); } @@ -252,21 +228,14 @@ public: }); } - using MinAttributes = gl::Attributes<typename PaintPropertyBinder<Ps>::MinAttribute...>; - using MaxAttributes = gl::Attributes<typename PaintPropertyBinder<Ps>::MaxAttribute...>; - - using Attributes = gl::ConcatenateAttributes<MinAttributes, MaxAttributes>; + using Attributes = gl::Attributes<typename PaintPropertyBinder<Ps>::Attribute...>; 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 typename Attributes::Bindings { + binders.template get<Ps>().attributeBinding(currentProperties.template get<Ps>())... }; - return min.concat(max); } using Uniforms = gl::Uniforms<typename PaintPropertyBinder<Ps>::InterpolationUniform...>; |