[core] Introduce and use IndexedTuple
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
|
||||
#include <mbgl/gl/types.hpp>
|
||||
#include <mbgl/util/ignore.hpp>
|
||||
#include <mbgl/util/indexed_tuple.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
@@ -143,27 +142,24 @@ void bindAttribute(AttributeLocation location,
|
||||
template <class... As>
|
||||
class Attributes {
|
||||
public:
|
||||
using State = std::tuple<typename As::State...>;
|
||||
using State = IndexedTuple<TypeList<As...>, TypeList<typename As::State...>>;
|
||||
using Vertex = detail::Vertex<As...>;
|
||||
|
||||
template <class A>
|
||||
static constexpr std::size_t Index = TypeIndex<A, As...>::value;
|
||||
|
||||
static State state(const ProgramID& id) {
|
||||
return State { { attributeLocation(id, As::name) }... };
|
||||
}
|
||||
|
||||
static std::function<void (std::size_t)> binder(const State& state) {
|
||||
return binder(state, std::index_sequence_for<As...>());
|
||||
}
|
||||
|
||||
private:
|
||||
template <std::size_t... Is>
|
||||
static std::function<void (std::size_t)> binder(const State& state, std::index_sequence<Is...>) {
|
||||
return [&state] (std::size_t vertexOffset) {
|
||||
ignore((bindAttribute(std::get<Is>(state).location,
|
||||
std::get<Is>(state).count,
|
||||
std::get<Is>(state).type,
|
||||
sizeof(Vertex),
|
||||
vertexOffset,
|
||||
Vertex::attributeOffsets[Is]), 0)...);
|
||||
ignore({ (bindAttribute(state.template get<As>().location,
|
||||
state.template get<As>().count,
|
||||
state.template get<As>().type,
|
||||
sizeof(Vertex),
|
||||
vertexOffset,
|
||||
Vertex::attributeOffsets[Index<As>]), 0)... });
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include <mbgl/gl/types.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/ignore.hpp>
|
||||
#include <mbgl/util/indexed_tuple.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
@@ -63,8 +63,8 @@ UniformLocation uniformLocation(ProgramID, const char * name);
|
||||
template <class... Us>
|
||||
class Uniforms {
|
||||
public:
|
||||
using State = std::tuple<typename Us::State...>;
|
||||
using Values = std::tuple<typename Us::Value...>;
|
||||
using State = IndexedTuple<TypeList<Us...>, TypeList<typename Us::State...>>;
|
||||
using Values = IndexedTuple<TypeList<Us...>, TypeList<typename Us::Value...>>;
|
||||
|
||||
static State state(const ProgramID& id) {
|
||||
return State { { uniformLocation(id, Us::name) }... };
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
static std::function<void ()> binder(State& state, Values&& values_) {
|
||||
return [&state, values = std::move(values_)] () mutable {
|
||||
ignore((std::get<typename Us::State>(state) = std::get<typename Us::Value>(values), 0)...);
|
||||
ignore({ (state.template get<Us>() = values.template get<Us>(), 0)... });
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user