/*============================================================================= Copyright (c) 2011-2015 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP #define SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP #include #include #include #include #include #include namespace sprout { namespace darkroom { namespace lights { template struct calculate_result; namespace detail { template struct calculate_result; template struct calculate_result : public sprout::identity {}; template struct calculate_result : public sprout::darkroom::lights::calculate_result::type, Intersection, Objects> {}; } // namespace detail // // calculate_result // template struct calculate_result : public sprout::darkroom::lights::detail::calculate_result< Light, Intersection, Objects, sprout::darkroom::access::is_tuple::value > {}; template struct calculate_result : public sprout::darkroom::lights::calculate_result {}; template struct calculate_result : public sprout::darkroom::lights::calculate_result {}; template struct calculate_result : public sprout::darkroom::lights::calculate_result {}; // // calculate // template< typename Light, typename Intersection, typename Objects, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate(Light const& light, Intersection const& inter, Objects const& objs); template< typename Light, typename Intersection, typename Objects, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate(Light const& light, Intersection const& inter, Objects const& objs); namespace detail { template inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate_2(Color const& col) { return col; } template inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) { return sprout::darkroom::lights::detail::calculate_2( sprout::darkroom::colors::add(col1, col2), tail... ); } template inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate_1( Lights const& lights, Intersection const& inter, Objects const& objs, sprout::index_tuple ) { return sprout::darkroom::lights::detail::calculate_2( sprout::darkroom::lights::calculate(sprout::darkroom::access::get(lights), inter, objs)... ); } } // namespace detail // // calculate_list // template inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate_list(Lights const& lights, Intersection const& inter, Objects const& objs) { return sprout::darkroom::lights::detail::calculate_1( lights, inter, objs, sprout::tuple_indexes::make() ); } // // calculate // template< typename Light, typename Intersection, typename Objects, typename sprout::enabler_if::value>::type > inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate(Light const& light, Intersection const& inter, Objects const& objs) { return light(inter, objs); } template< typename Light, typename Intersection, typename Objects, typename sprout::enabler_if::value>::type > inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result::type calculate(Light const& light, Intersection const& inter, Objects const& objs) { return sprout::darkroom::lights::calculate_list(light, inter, objs); } } // namespace lights } // namespace darkroom } // namespace sprout #endif // #ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP