summaryrefslogtreecommitdiff
path: root/src/mbgl/programs
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-16 17:00:43 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-17 08:27:53 -0700
commitff413f6b99d7cb7b7482d56479f10e0a8fe83046 (patch)
treea0a7aab5a9eb785565b6d8c90632d864aa1101a5 /src/mbgl/programs
parent0dca6cd9bfdb1fb77f7755d639f92a6a1ba06dc1 (diff)
downloadqtlocation-mapboxgl-ff413f6b99d7cb7b7482d56479f10e0a8fe83046.tar.gz
[core] Fix overspecialization of PaintPropertyBinder template
PaintPropertyBinder and subclass templates were being instantiated for every unique attribute type (e.g. a_color, a_fill_color, a_halo_color) even though they behave identically for a given property value type (e.g. Color). To fix this, a unique type such as a_color no longer derives from gl::Attribute<...> -- instead it has an inner Type typedef, which should be used wherever neither a unique type nor attribute name is required. This reduces binary size substantially: VM SIZE FILE SIZE ++++++++++++++ GROWING ++++++++++++++ -------------- SHRINKING -------------- -2.0% -49.3Ki __TEXT,__text -49.3Ki -2.0% -3.1% -5.21Ki [None] -2.79Ki -1.6% -2.1% -4.12Ki __TEXT,__const -4.12Ki -2.1% -1.4% -4.04Ki __TEXT,__gcc_except_tab -4.04Ki -1.4% -19.3% -3.62Ki __DATA,__data -3.62Ki -19.3% -2.5% -1.65Ki __TEXT,__unwind_info -1.65Ki -2.5% -4.2% -8 __DATA,__mod_init_func 0 [ = ] -1.9% -68.0Ki TOTAL -65.6Ki -1.9%
Diffstat (limited to 'src/mbgl/programs')
-rw-r--r--src/mbgl/programs/attributes.hpp181
1 files changed, 38 insertions, 143 deletions
diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp
index b015c06366..7d39c04395 100644
--- a/src/mbgl/programs/attributes.hpp
+++ b/src/mbgl/programs/attributes.hpp
@@ -16,209 +16,104 @@ MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_offset);
MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);
template <std::size_t N>
-struct a_data : gl::Attribute<uint8_t, N> {
+struct a_data {
static auto name() { return "a_data"; }
+ using Type = gl::Attribute<uint8_t, N>;
};
template <std::size_t N>
-struct a_offset : gl::Attribute<int16_t, N> {
+struct a_offset {
static auto name() { return "a_offset"; }
+ using Type = gl::Attribute<int16_t, N>;
};
// Paint attributes
-/*
- ZoomInterpolatedAttribute<Attr> is a 'compound' attribute, representing two values of the
- the base attribute Attr. These two values are provided to the shader to allow interpolation
- between zoom levels, without the need to repopulate vertex buffers each frame as the map is
- being zoomed.
-*/
-template <class Attr>
-struct ZoomInterpolatedAttribute : gl::Attribute<typename Attr::ValueType, Attr::Dimensions * 2> {
- using Value = typename gl::Attribute<typename Attr::ValueType, Attr::Dimensions * 2>::Value;
-
- static auto name() {
- return Attr::name();
- }
-
- template <class InputType>
- static Value value(const InputType& min, const InputType& max){
- auto minValue = Attr::value(min);
- auto maxValue = Attr::value(max);
- Value result = {{}};
- for (size_t i = 0; i < Attr::Dimensions; i++) {
- result[i] = minValue[i];
- result[Attr::Dimensions+i] = maxValue[i];
- }
- return result;
- }
-};
-
-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();
- }
-};
-
-/*
- 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.
-
- Also note:
- - Colors come in as floats 0..1, so we scale by 255.
- - Casting the scaled values to ints is important: without doing this, e.g., the
- fractional part of the `r` component would corrupt the lower-8 bits of the encoded
- value, which must be reserved for the `g` component.
-*/
-static std::array<float, 2> encodeColor (const Color& color) {
- const auto v1 = static_cast<uint16_t>( static_cast<uint16_t>(color.r*255)*256 + color.g*255);
- const auto v2 = static_cast<uint16_t>( static_cast<uint16_t>(color.b*255)*256 + color.a*255);
- return {{ static_cast<float>(v1), static_cast<float>(v2) }};
-}
-
-struct a_color : gl::Attribute<float, 2> {
+struct a_color {
static auto name() { return "a_color"; }
-
- static Value value(const Color& color) {
- return encodeColor(color);
- }
+ using Type = gl::Attribute<float, 2>;
};
-// used in the symbol sdf shader
-struct a_fill_color : gl::Attribute<float, 2> {
+struct a_fill_color {
static auto name() { return "a_fill_color"; }
-
- static Value value(const Color& color) {
- return encodeColor(color);
- }
+ using Type = gl::Attribute<float, 2>;
};
-// used in the symbol sdf shader
-struct a_halo_color : gl::Attribute<float, 2> {
+struct a_halo_color {
static auto name() { return "a_halo_color"; }
-
- static Value value(const Color& color) {
- return encodeColor(color);
- }
+ using Type = gl::Attribute<float, 2>;
};
-struct a_stroke_color : gl::Attribute<float, 2> {
+struct a_stroke_color {
static auto name() { return "a_stroke_color"; }
-
- static Value value(const Color& color) {
- return encodeColor(color);
- }
+ using Type = gl::Attribute<float, 2>;
};
-struct a_outline_color : gl::Attribute<float, 2> {
+struct a_outline_color {
static auto name() { return "a_outline_color"; }
-
- static Value value(const Color& color) {
- return encodeColor(color);
- }
+ using Type = gl::Attribute<float, 2>;
};
-struct a_opacity : gl::Attribute<float, 1> {
+struct a_opacity {
static auto name() { return "a_opacity"; }
-
- static Value value(float opacity) {
- return {{ opacity }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_stroke_opacity : gl::Attribute<float, 1> {
+struct a_stroke_opacity {
static auto name() { return "a_stroke_opacity"; }
-
- static Value value(float opacity) {
- return {{ opacity }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_blur : gl::Attribute<float, 1> {
+struct a_blur {
static auto name() { return "a_blur"; }
-
- static Value value(float blur) {
- return {{ blur }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_radius : gl::Attribute<float, 1> {
+struct a_radius {
static auto name() { return "a_radius"; }
-
- static Value value(float radius) {
- return {{ radius }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_width : gl::Attribute<float, 1> {
+struct a_width {
static auto name() { return "a_width"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_height : gl::Attribute<float, 1> {
+struct a_height {
static auto name() { return "a_height"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_base : gl::Attribute<float, 1> {
+struct a_base {
static auto name() { return "a_base"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_gap_width : gl::Attribute<float, 1> {
+struct a_gap_width {
static auto name() { return "a_gapwidth"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_stroke_width : gl::Attribute<float, 1> {
+struct a_stroke_width {
static auto name() { return "a_stroke_width"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
template <>
-struct a_offset<1> : gl::Attribute<float, 1> {
+struct a_offset<1> {
static auto name() { return "a_offset"; }
-
- static Value value(float offset) {
- return {{ offset }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_halo_width : gl::Attribute<float, 1> {
+struct a_halo_width {
static auto name() { return "a_halo_width"; }
-
- static Value value(float width) {
- return {{ width }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-struct a_halo_blur : gl::Attribute<float, 1> {
+struct a_halo_blur {
static auto name() { return "a_halo_blur"; }
-
- static Value value(float blur) {
- return {{ blur }};
- }
+ using Type = gl::Attribute<float, 1>;
};
-
-
} // namespace attributes
} // namespace mbgl