[core] simplify attribute/location types

This commit is contained in:
Konstantin Käfer
2018-05-31 14:41:10 +02:00
committed by Molly Lloyd
parent 0dac3bc60c
commit abc5043339
3 changed files with 13 additions and 22 deletions

View File

@@ -50,4 +50,7 @@ public:
}
};
template <class, class T>
using ExpandToType = T;
} // namespace mbgl

View File

@@ -57,18 +57,15 @@ public:
static constexpr size_t Dimensions = N;
using Value = std::array<T, N>;
using Location = AttributeLocation;
using Binding = AttributeBinding;
/*
Create a binding for this attribute. The `attributeSize` parameter may be used to
override the number of components available in the buffer for each vertex. Thus,
a buffer with only one float for each vertex can be bound to a `vec2` attribute
*/
template <class Vertex, class DrawMode>
static Binding binding(const VertexBuffer<Vertex, DrawMode>& buffer,
std::size_t attributeIndex,
std::size_t attributeSize = N) {
static AttributeBinding binding(const VertexBuffer<Vertex, DrawMode>& buffer,
std::size_t attributeIndex,
std::size_t attributeSize = N) {
static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout");
assert(attributeSize >= 1);
assert(attributeSize <= 4);
@@ -84,7 +81,7 @@ public:
};
}
static optional<Binding> offsetBinding(const optional<Binding>& binding, std::size_t vertexOffset) {
static optional<AttributeBinding> offsetBinding(const optional<AttributeBinding>& binding, std::size_t vertexOffset) {
assert(vertexOffset <= std::numeric_limits<uint32_t>::max());
if (binding) {
AttributeBinding result = *binding;
@@ -222,10 +219,10 @@ public:
using Types = TypeList<As...>;
using Locations = IndexedTuple<
TypeList<As...>,
TypeList<optional<typename As::Type::Location>...>>;
TypeList<ExpandToType<As, optional<AttributeLocation>>...>>;
using Bindings = IndexedTuple<
TypeList<As...>,
TypeList<optional<typename As::Type::Binding>...>>;
TypeList<ExpandToType<As, optional<AttributeBinding>>...>>;
using NamedLocations = std::vector<std::pair<const std::string, AttributeLocation>>;
using Vertex = detail::Vertex<typename As::Type...>;

View File

@@ -75,14 +75,12 @@ std::array<float, N*2> zoomInterpolatedAttributeValue(const std::array<float, N>
template <class T, class A>
class PaintPropertyBinder {
public:
using Attribute = ZoomInterpolatedAttributeType<A>;
using AttributeBinding = typename Attribute::Binding;
virtual ~PaintPropertyBinder() = default;
virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) = 0;
virtual void upload(gl::Context& context) = 0;
virtual optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
virtual optional<gl::AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
virtual float interpolationFactor(float currentZoom) const = 0;
virtual T uniformValue(const PossiblyEvaluatedPropertyValue<T>& currentValue) const = 0;
@@ -94,9 +92,6 @@ public:
template <class T, class A>
class ConstantPaintPropertyBinder : public PaintPropertyBinder<T, A> {
public:
using Attribute = ZoomInterpolatedAttributeType<A>;
using AttributeBinding = typename Attribute::Binding;
ConstantPaintPropertyBinder(T constant_)
: constant(std::move(constant_)) {
}
@@ -104,7 +99,7 @@ public:
void populateVertexVector(const GeometryTileFeature&, std::size_t) override {}
void upload(gl::Context&) override {}
optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const override {
optional<gl::AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const override {
return {};
}
@@ -128,7 +123,6 @@ public:
using BaseVertex = gl::detail::Vertex<BaseAttribute>;
using Attribute = ZoomInterpolatedAttributeType<A>;
using AttributeBinding = typename Attribute::Binding;
SourceFunctionPaintPropertyBinder(style::PropertyExpression<T> expression_, T defaultValue_)
: expression(std::move(expression_)),
@@ -148,7 +142,7 @@ public:
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
optional<gl::AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
if (currentValue.isConstant()) {
return {};
} else {
@@ -179,12 +173,9 @@ private:
template <class T, class A>
class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder<T, A> {
public:
using BaseAttribute = A;
using BaseAttributeValue = typename BaseAttribute::Value;
using Attribute = ZoomInterpolatedAttributeType<A>;
using AttributeValue = typename Attribute::Value;
using AttributeBinding = typename Attribute::Binding;
using Vertex = gl::detail::Vertex<Attribute>;
CompositeFunctionPaintPropertyBinder(style::PropertyExpression<T> expression_, float zoom, T defaultValue_)
@@ -209,7 +200,7 @@ public:
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
optional<AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
optional<gl::AttributeBinding> attributeBinding(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override {
if (currentValue.isConstant()) {
return {};
} else {