mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #6 from lioncash/view
View: Add load() overload for arbitrary containers
This commit is contained in:
commit
953e1a0270
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <boo/BooObject.hpp>
|
||||
|
@ -111,20 +113,19 @@ public:
|
|||
|
||||
void load(const VertStruct* data, size_t count) {
|
||||
if (m_vertsBuf) {
|
||||
VertStruct* out = m_vertsBuf.access();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
out[i] = data[i];
|
||||
VertStruct* const out = m_vertsBuf.access();
|
||||
std::copy(data, data + count, out);
|
||||
}
|
||||
}
|
||||
template <typename VertArray>
|
||||
void load(const VertArray data) {
|
||||
static_assert(std::is_same<std::remove_all_extents_t<VertArray>, VertStruct>::value, "mismatched type");
|
||||
if (m_vertsBuf) {
|
||||
constexpr size_t count = sizeof(VertArray) / sizeof(VertStruct);
|
||||
VertStruct* out = m_vertsBuf.access();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
out[i] = data[i];
|
||||
}
|
||||
template <typename ContiguousContainer>
|
||||
void load(const ContiguousContainer& container) {
|
||||
// All contiguous containers (even those that aren't containers like C arrays) are usable
|
||||
// with std::begin(). Because of that, we can use it to deduce the contained type.
|
||||
static_assert(std::is_same_v<std::remove_reference_t<decltype(*std::begin(std::declval<ContiguousContainer&>()))>,
|
||||
VertStruct>,
|
||||
"Supplied container doesn't contain same type of vertex struct");
|
||||
|
||||
load(std::data(container), std::size(container));
|
||||
}
|
||||
|
||||
operator const boo::ObjToken<boo::IShaderDataBinding>&() { return m_shaderBinding; }
|
||||
|
|
Loading…
Reference in New Issue