Commit 9c1af318 authored by Philip Trettner's avatar Philip Trettner

fixed array_view and setUniform a bit for array types

parent 07f89ff3
......@@ -17,18 +17,18 @@ auto make_array_view(Range&& r);
namespace detail
{
template <class Range, class T>
auto convertible_to_array_view_test(int) -> decltype(static_cast<T*>(std::declval<Range>().data()), static_cast<size_t>(std::declval<Range>().size()), 0)
template <class Range, class T, class = void>
struct convertible_to_array_view_t : std::false_type
{
}
template <class Range, class T>
char convertible_to_array_view_test(...);
};
template <class Range, class T>
struct convertible_to_array_view_t
struct convertible_to_array_view_t<Range,
T,
std::void_t<decltype(static_cast<T*>(std::declval<Range>().data()), static_cast<size_t>(std::declval<Range>().size()))>>
: std::true_type
{
static constexpr inline bool value = sizeof(convertible_to_array_view_test<Range, T>(0)) > 1;
};
template <class Range, class T>
static constexpr inline bool convertible_to_array_view = convertible_to_array_view_t<Range, T>::value;
}
......@@ -92,18 +92,13 @@ private:
template <class Range>
auto make_array_view(Range&& r)
{
using std::begin;
using T = std::decay_t<decltype(*begin(r))>;
using T = std::remove_reference_t<decltype(r.data()[0])>;
return array_view<T>(std::forward<Range>(r));
}
namespace detail
{
using glow::make_array_view;
template <class Range>
char make_array_view(...);
template <class Range>
constexpr bool can_make_array_view = sizeof(make_array_view<Range>(std::declval<Range>())) > 1;
constexpr bool can_make_array_view = convertible_to_array_view<Range, void>;
}
}
......@@ -72,10 +72,15 @@ public: // gl functions with use
{
if constexpr (detail::uniform<T>::is_supported)
uniform<T>(name) = value;
else if constexpr (std::is_array_v<T>)
{
using E = std::decay_t<decltype(value[0])>;
uniform<E[]>(name) = value;
}
else if constexpr (detail::can_make_array_view<T>)
{
auto view = glow::make_array_view(value);
using E = typename decltype(view)::element_type;
using E = std::remove_const_t<typename decltype(view)::element_type>;
uniform<E[]>(name) = view;
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment