diff options
Diffstat (limited to 'src/mbgl/gl/attribute.hpp')
-rw-r--r-- | src/mbgl/gl/attribute.hpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index c4fe8b993f..c7f9ba3fd4 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -3,6 +3,7 @@ #include <mbgl/gfx/attribute.hpp> #include <mbgl/gl/types.hpp> #include <mbgl/util/ignore.hpp> +#include <mbgl/util/literal.hpp> #include <mbgl/util/indexed_tuple.hpp> #include <mbgl/util/optional.hpp> @@ -50,13 +51,15 @@ public: } }; - return Locations{ maybeBindLocation(As::name())... }; + return Locations{ maybeBindLocation( + concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... }; }()) { } template <class BinaryProgram> AttributeLocations(const BinaryProgram& program) - : locations{ program.attributeLocation(As::name())... } { + : locations{ program.attributeLocation( + concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... } { } NamedAttributeLocations getNamedLocations() const { @@ -68,7 +71,9 @@ public: } }; - util::ignore({ (maybeAddLocation(As::name(), locations.template get<As>()), 0)... }); + util::ignore({ (maybeAddLocation(concat_literals<&string_literal<'a', '_'>::value, &As::name>::value(), + locations.template get<As>()), + 0)... }); return result; } @@ -90,5 +95,36 @@ public: } }; +template <class> +class AttributeKey; + +constexpr auto attributeDefinePrefix() { + return "#define HAS_UNIFORM_u_"; +} + +template <class... As> +class AttributeKey<TypeList<As...>> final { +public: + static_assert(sizeof...(As) <= 32, "attribute count exceeds 32"); + + static uint32_t compute(const gfx::AttributeBindings<TypeList<As...>>& bindings) { + uint32_t value = 0; + util::ignore( + { (bindings.template get<As>() ? (void)(value |= 1 << TypeIndex<As, As...>::value) + : (void)0, + 0)... }); + return value; + } + + static std::string defines(const gfx::AttributeBindings<TypeList<As...>>& bindings) { + std::string result; + util::ignore({ (!bindings.template get<As>() + ? (void)(result += concat_literals<&attributeDefinePrefix, &As::name, &string_literal<'\n'>::value>::value()) + : (void)0, + 0)... }); + return result; + } +}; + } // namespace gl } // namespace mbgl |