summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/paint_property_binder.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/paint_property_binder.hpp')
-rw-r--r--src/mbgl/renderer/paint_property_binder.hpp66
1 files changed, 39 insertions, 27 deletions
diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp
index 09cea12030..56f187507f 100644
--- a/src/mbgl/renderer/paint_property_binder.hpp
+++ b/src/mbgl/renderer/paint_property_binder.hpp
@@ -24,14 +24,24 @@ namespace mbgl {
between zoom levels, without the need to repopulate vertex buffers each frame as the map is
being zoomed.
*/
-template <class A>
-using ZoomInterpolatedAttributeType = gl::Attribute<typename A::ValueType, A::Dimensions * 2>;
+template <class AttributeType>
+using ZoomInterpolatedAttributeType = gfx::AttributeType<typename AttributeType::ValueType, AttributeType::Dimensions * 2>;
inline std::array<float, 1> attributeValue(float v) {
return {{ v }};
}
/*
+ * Pack a pair of values, interpreted as uint8's, into a single float.
+ * Used to conserve vertex attributes. Values are unpacked in the vertex
+ * shader using the `unpack_float()` function, defined in _prelude.vertex.glsl.
+ */
+template <typename T>
+inline uint16_t packUint8Pair(T a, T b) {
+ return static_cast<uint16_t>(a) * 256 + static_cast<uint16_t>(b);
+}
+
+/*
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
bits for one component (e.g. (color.r * 255) * 256), and the lower 8 for another.
@@ -40,8 +50,8 @@ inline std::array<float, 1> attributeValue(float v) {
*/
inline std::array<float, 2> attributeValue(const Color& color) {
return {{
- static_cast<float>(mbgl::attributes::packUint8Pair(255 * color.r, 255 * color.g)),
- static_cast<float>(mbgl::attributes::packUint8Pair(255 * color.b, 255 * color.a))
+ static_cast<float>(packUint8Pair(255 * color.r, 255 * color.g)),
+ static_cast<float>(packUint8Pair(255 * color.b, 255 * color.a))
}};
}
@@ -163,8 +173,9 @@ private:
template <class T, class A>
class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder<T, T, PossiblyEvaluatedPropertyValue<T>, A> {
public:
- using BaseAttribute = A;
- using BaseVertex = gl::detail::Vertex<BaseAttribute>;
+ using BaseAttributeType = A;
+ using BaseAttributeValue = typename A::Value;
+ using BaseVertex = gfx::Vertex<BaseAttributeValue>;
using AttributeType = ZoomInterpolatedAttributeType<A>;
@@ -190,7 +201,7 @@ public:
if (currentValue.isConstant()) {
return {};
} else {
- return std::tuple<optional<gl::AttributeBinding>> { AttributeType::binding(*vertexBuffer, 0, BaseAttribute::Dimensions) };
+ return std::tuple<optional<gl::AttributeBinding>> { gl::attributeBinding<AttributeType>(*vertexBuffer, 0, BaseAttributeType::Dimensions) };
}
}
@@ -220,7 +231,7 @@ public:
using AttributeType = ZoomInterpolatedAttributeType<A>;
using AttributeValue = typename AttributeType::Value;
- using Vertex = gl::detail::Vertex<AttributeType>;
+ using Vertex = gfx::Vertex<AttributeValue>;
CompositeFunctionPaintPropertyBinder(style::PropertyExpression<T> expression_, float zoom, T defaultValue_)
: expression(std::move(expression_)),
@@ -248,7 +259,7 @@ public:
if (currentValue.isConstant()) {
return {};
} else {
- return std::tuple<optional<gl::AttributeBinding>> { AttributeType::binding(*vertexBuffer, 0) };
+ return std::tuple<optional<gl::AttributeBinding>> { gl::attributeBinding<AttributeType>(*vertexBuffer, 0) };
}
}
@@ -283,14 +294,14 @@ public:
using AttributeType = ZoomInterpolatedAttributeType<A1>;
using AttributeType2 = ZoomInterpolatedAttributeType<A2>;
- using BaseAttribute = A1;
- using BaseAttributeValue = typename BaseAttribute::Value;
+ using BaseAttributeType = A1;
+ using BaseAttributeValue = typename BaseAttributeType::Value;
- using BaseAttribute2 = A2;
- using BaseAttributeValue2 = typename BaseAttribute2::Value;
+ using BaseAttributeType2 = A2;
+ using BaseAttributeValue2 = typename BaseAttributeType2::Value;
- using Vertex = gl::detail::Vertex<BaseAttribute>;
- using Vertex2 = gl::detail::Vertex<BaseAttribute2>;
+ using Vertex = gfx::Vertex<BaseAttributeValue>;
+ using Vertex2 = gfx::Vertex<BaseAttributeValue2>;
CompositeCrossFadedPaintPropertyBinder(style::PropertyExpression<T> expression_, float zoom, T defaultValue_)
: expression(std::move(expression_)),
@@ -344,10 +355,10 @@ public:
return {};
} else {
return std::tuple<optional<gl::AttributeBinding>, optional<gl::AttributeBinding>> {
- AttributeType::binding(*patternToVertexBuffer, 0, BaseAttribute::Dimensions),
- AttributeType2::binding(
+ gl::attributeBinding<AttributeType>(*patternToVertexBuffer, 0, BaseAttributeType::Dimensions),
+ gl::attributeBinding<AttributeType2>(
crossfade.fromScale == 2 ? *zoomInVertexBuffer : *zoomOutVertexBuffer,
- 0, BaseAttribute2::Dimensions) };
+ 0, BaseAttributeType2::Dimensions) };
}
}
@@ -420,7 +431,7 @@ struct ZoomInterpolatedAttribute {
};
template <class Attr>
-struct InterpolationUniformType {
+struct InterpolationUniform {
using Value = float;
static auto name() {
static const std::string name = Attr::name() + std::string("_t");
@@ -441,11 +452,11 @@ private:
struct Detail<T, UniformValueType, PossiblyEvaluatedType, TypeList<As...>> {
using Binder = PaintPropertyBinder<T, UniformValueType, PossiblyEvaluatedType, typename As::Type...>;
using ZoomInterpolatedAttributeList = TypeList<ZoomInterpolatedAttribute<As>...>;
- using InterpolationUniformTypeList = TypeList<InterpolationUniformType<As>...>;
+ using InterpolationUniformList = TypeList<InterpolationUniform<As>...>;
};
template <class P>
- using Property = Detail<typename P::Type, typename P::Uniform::Value, typename P::PossiblyEvaluatedType, typename P::Attributes>;
+ using Property = Detail<typename P::Type, typename P::Uniform::Value, typename P::PossiblyEvaluatedType, typename P::AttributeList>;
public:
template <class P>
@@ -485,9 +496,10 @@ public:
template <class P>
using ZoomInterpolatedAttributeList = typename Property<P>::ZoomInterpolatedAttributeList;
template <class P>
- using InterpolationUniformTypeList = typename Property<P>::InterpolationUniformTypeList;
+ using InterpolationUniformList = typename Property<P>::InterpolationUniformList;
- using Attributes = typename TypeListConcat<ZoomInterpolatedAttributeList<Ps>...>::template ExpandInto<gl::Attributes>;
+ using AttributeList = TypeListConcat<ZoomInterpolatedAttributeList<Ps>...>;
+ using Attributes = gl::Attributes<AttributeList>;
using AttributeBindings = typename Attributes::Bindings;
template <class EvaluatedProperties>
@@ -497,9 +509,9 @@ public:
) };
}
- using UniformTypeList = TypeListConcat<InterpolationUniformTypeList<Ps>..., typename Ps::Uniforms...>;
- using UniformValues = gfx::UniformValues<UniformTypeList>;
- using Uniforms = typename UniformTypeList::template ExpandInto<gl::Uniforms>;
+ using UniformList = TypeListConcat<InterpolationUniformList<Ps>..., typename Ps::UniformList...>;
+ using UniformValues = gfx::UniformValues<UniformList>;
+ using Uniforms = gl::Uniforms<UniformList>;
template <class EvaluatedProperties>
UniformValues uniformValues(float currentZoom, EvaluatedProperties& currentProperties) const {
@@ -547,7 +559,7 @@ public:
std::vector<std::string> result;
util::ignore({
(currentProperties.template get<Ps>().isConstant()
- ? UniformDefines<typename Ps::Uniforms>::appendDefines(result)
+ ? UniformDefines<typename Ps::UniformList>::appendDefines(result)
: (void) 0, 0)...
});
return result;