From daeba8674a57518763d4ca8258e569c71c2f0918 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 4 Oct 2020 11:18:01 +0300 Subject: [PATCH] Support vector, point & interval uniforms of unknown floating-point/integral types --- libs/gfx/include/psemek/gfx/program.hpp | 81 +++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/program.hpp b/libs/gfx/include/psemek/gfx/program.hpp index 4fe49dd2..3a63361d 100644 --- a/libs/gfx/include/psemek/gfx/program.hpp +++ b/libs/gfx/include/psemek/gfx/program.hpp @@ -53,6 +53,9 @@ namespace psemek::gfx void operator = (geom::vector const & v); void operator = (geom::vector const & v); + template + void operator = (geom::vector const & v); + void operator = (geom::point const & v); void operator = (geom::point const & v); void operator = (geom::point const & v); @@ -68,6 +71,9 @@ namespace psemek::gfx void operator = (geom::point const & v); void operator = (geom::point const & v); + template + void operator = (geom::point const & v); + void operator = (geom::matrix const & m); void operator = (geom::matrix const & m); void operator = (geom::matrix const & m); @@ -82,6 +88,9 @@ namespace psemek::gfx void operator = (geom::interval const & i); void operator = (geom::interval const & i); + template + void operator = (geom::interval const & i); + private: GLint location_; }; @@ -93,4 +102,76 @@ namespace psemek::gfx mutable std::unordered_map uniforms_; }; + template + void program::uniform_proxy::operator = (geom::vector const & v) + { + if constexpr (std::is_floating_point_v) + { + (*this) = geom::cast(v); + } + else if (std::is_integral_v) + { + if constexpr (std::is_unsigned_v) + { + (*this) = geom::cast(v); + } + else + { + (*this) = geom::cast(v); + } + } + else + { + static_assert("Unknown uniform data type"); + } + } + + template + void program::uniform_proxy::operator = (geom::point const & p) + { + if constexpr (std::is_floating_point_v) + { + (*this) = geom::cast(p); + } + else if (std::is_integral_v) + { + if constexpr (std::is_unsigned_v) + { + (*this) = geom::cast(p); + } + else + { + (*this) = geom::cast(p); + } + } + else + { + static_assert("Unknown uniform data type"); + } + } + + template + void program::uniform_proxy::operator = (geom::interval const & i) + { + if constexpr (std::is_floating_point_v) + { + (*this) = geom::cast(i); + } + else if (std::is_integral_v) + { + if constexpr (std::is_unsigned_v) + { + (*this) = geom::cast(i); + } + else + { + (*this) = geom::cast(i); + } + } + else + { + static_assert("Unknown uniform data type"); + } + } + }