From 2c79f46df26e5dbeaa8361e7d838c9ffb7a7915b Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Tue, 29 May 2018 22:19:09 -0700 Subject: blerp :skull: --- src/mbgl/gl/attribute.hpp | 1 + src/mbgl/renderer/paint_property_binder.hpp | 128 +++++++++++++++++++--------- src/mbgl/style/paint_property.hpp | 17 +++- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index 329b761df..9bd5e7b9f 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -227,6 +227,7 @@ public: using Bindings = IndexedTuple< TypeList, TypeList...>>; + using NamedLocations = std::vector>; using Vertex = detail::Vertex; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 3a49882f1..0406cd55d 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -21,10 +21,51 @@ namespace mbgl { template using ZoomInterpolatedAttributeType = gl::Attribute; +template +struct ZoomInterpolatedAttribute { + static auto name() { return Attr::name(); } + using Type = ZoomInterpolatedAttributeType; +}; + +template +struct InterpolationUniform : gl::UniformScalar, float> { + static auto name() { + static const std::string name = Attr::name() + std::string("_t"); + return name.c_str(); + } +}; + +namespace detail { + +template +struct ZoomInterpolatedAttributes; + +template +struct ZoomInterpolatedAttributes> { + using Attributes = gl::Attributes...>; +}; + +template +struct InterpolationUniforms; + +template +struct InterpolationUniforms> { + using Uniforms = gl::Uniforms...>; +}; + +} //namespace detail + +template +using ZoomInterpolatedAttributes = typename detail::ZoomInterpolatedAttributes::Attributes; + +template +using InterpolationUniforms = typename detail::InterpolationUniforms::Uniforms; + + + inline std::array attributeValue(float v) { return {{ v }}; } - /* Encode a four-component color value into a pair of floats. Since csscolorparser uses 8-bit precision for each color component, for each float we use the upper 8 @@ -72,17 +113,18 @@ std::array zoomInterpolatedAttributeValue(const std::array Note that the shader source varies depending on whether we're using a uniform or attribute. Like GL JS, we dynamically compile shaders at runtime to accomodate this. */ -template +template class PaintPropertyBinder { public: - using Attribute = ZoomInterpolatedAttributeType; - using AttributeBinding = typename Attribute::Binding; + // takes gl::Attribute + using Attributes = ZoomInterpolatedAttributes; + using AttributeBindings = typename Attributes::Bindings; virtual ~PaintPropertyBinder() = default; virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) = 0; virtual void upload(gl::Context& context) = 0; - virtual optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; + virtual optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; virtual float interpolationFactor(float currentZoom) const = 0; virtual T uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const = 0; @@ -94,8 +136,8 @@ public: template class ConstantPaintPropertyBinder : public PaintPropertyBinder { public: - using Attribute = ZoomInterpolatedAttributeType; - using AttributeBinding = typename Attribute::Binding; + using Attributes = ZoomInterpolatedAttributes; + using AttributeBindings = typename Attributes::Bindings; ConstantPaintPropertyBinder(T constant_) : constant(std::move(constant_)) { @@ -104,7 +146,7 @@ public: void populateVertexVector(const GeometryTileFeature&, std::size_t) override {} void upload(gl::Context&) override {} - optional attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { + optional attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { return {}; } @@ -120,15 +162,17 @@ private: T constant; }; + + template -class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder { +class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder> { public: - using BaseAttribute = A; - using BaseAttributeValue = typename BaseAttribute::Value; + using BaseAttribute = typename A::Type; using BaseVertex = gl::detail::Vertex; - using Attribute = ZoomInterpolatedAttributeType; - using AttributeBinding = typename Attribute::Binding; + using Attribute = ZoomInterpolatedAttributeType; + using Attributes = ZoomInterpolatedAttributes>; + using AttributeBindings = typename Attributes::Bindings; SourceFunctionPaintPropertyBinder(style::SourceFunction function_, T defaultValue_) : function(std::move(function_)), @@ -148,11 +192,11 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { return {}; } else { - return Attribute::binding(*vertexBuffer, 0, BaseAttribute::Dimensions); + return {Attribute::binding(*vertexBuffer, 0, BaseAttribute::Dimensions)}; } } @@ -177,15 +221,14 @@ private: }; template -class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder { +class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder> { public: - using BaseAttribute = A; - using BaseAttributeValue = typename BaseAttribute::Value; - - using Attribute = ZoomInterpolatedAttributeType; - using AttributeValue = typename Attribute::Value; - using AttributeBinding = typename Attribute::Binding; + + using Attribute = ZoomInterpolatedAttributeType; + using Attributes = ZoomInterpolatedAttributes>; + using AttributeBindings = typename Attributes::Bindings; using Vertex = gl::detail::Vertex; + using AttributeValue = typename Attribute::Value; CompositeFunctionPaintPropertyBinder(style::CompositeFunction function_, float zoom, T defaultValue_) : function(std::move(function_)), @@ -209,11 +252,11 @@ public: vertexBuffer = context.createVertexBuffer(std::move(vertexVector)); } - optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + optional attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { return {}; } else { - return Attribute::binding(*vertexBuffer, 0); + return {Attribute::binding(*vertexBuffer, 0)}; } } @@ -242,6 +285,21 @@ private: optional> vertexBuffer; }; +// create new class for Binder creation (instead of the function below) templated on the kind of property +// (DataDrivenPaintProperty or CrossFadedDataDrivenPaintProperty), so that we can have access to the original property +// template parameters of Attributes type alias (i.e. A for gl::Attributes or A1, A2 for gl::Attributes) +// through partial specialization of the CreateBinder class?? + +//template +//class CreateBinder {}; +//class CreateBinder> { +// +//}; +// +//class CreateBinder { +// +//}; + template std::unique_ptr> PaintPropertyBinder::create(const PossiblyEvaluatedPropertyValue& value, float zoom, T defaultValue) { @@ -258,19 +316,6 @@ PaintPropertyBinder::create(const PossiblyEvaluatedPropertyValue& value ); } -template -struct ZoomInterpolatedAttribute { - static auto name() { return Attr::name(); } - using Type = ZoomInterpolatedAttributeType; -}; - -template -struct InterpolationUniform : gl::UniformScalar, float> { - static auto name() { - static const std::string name = Attr::name() + std::string("_t"); - return name.c_str(); - } -}; template class PaintPropertyBinders; @@ -279,7 +324,7 @@ template class PaintPropertyBinders> { public: template - using Binder = PaintPropertyBinder; + using Binder = PaintPropertyBinder; using Binders = IndexedTuple< TypeList, @@ -307,9 +352,9 @@ public: } template - using Attribute = ZoomInterpolatedAttribute; + using Attribute = ZoomInterpolatedAttributes; - using Attributes = gl::Attributes...>; + using Attributes = gl::ConcatenateAttributes...>; using AttributeBindings = typename Attributes::Bindings; template @@ -319,7 +364,7 @@ public: }; } - using Uniforms = gl::Uniforms..., typename Ps::Uniform...>; + using Uniforms = gl::Uniforms..., typename Ps::Uniform...>; using UniformValues = typename Uniforms::Values; template @@ -367,5 +412,4 @@ public: private: Binders binders; }; - } // namespace mbgl diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 195eb645a..eeda482b2 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -34,7 +34,22 @@ public: using Type = T; static constexpr bool IsDataDriven = true; - using Attribute = A; + using Attributes = gl::Attributes; + using Uniform = U; +}; + +template +class CrossFadedDataDrivenPaintProperty { +public: + using TransitionableType = Transitionable>; + using UnevaluatedType = Transitioning>; + // need CrossFadedDataDrivenPropertyEvaluator here or maybe can extend the existing CrossFadedPropertyEvaluator? + using EvaluatorType = DataDrivenPropertyEvaluator; + using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue>; + using Type = T; + static constexpr bool IsDataDriven = true; + + using Attributes = gl::Attributes; using Uniform = U; }; -- cgit v1.2.3