Sprout/sprout/darkroom/pixels/generate.hpp

138 lines
4.6 KiB
C++
Raw Normal View History

2011-11-26 06:20:35 +00:00
#ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#define SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
2013-02-07 14:12:57 +00:00
#include <sprout/array/array.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
2011-11-26 06:20:35 +00:00
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace pixels {
//
// generate
//
namespace detail {
template<
typename Pixels,
2012-10-05 15:58:56 +00:00
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights,
2012-02-28 01:46:39 +00:00
sprout::index_t... XIndexes
2011-11-26 06:20:35 +00:00
>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Pixels>::value_type
2011-11-26 06:20:35 +00:00
generate_impl_line(
2012-10-05 15:58:56 +00:00
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2012-10-06 04:53:07 +00:00
>::size_type x,
typename sprout::container_traits<Pixels>::size_type y,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2012-10-06 04:53:07 +00:00
>::size_type width,
typename sprout::container_traits<Pixels>::size_type height,
2011-11-26 06:20:35 +00:00
std::size_t depth_max,
sprout::index_tuple<XIndexes...>
)
{
typedef typename sprout::container_traits<Pixels>::value_type pixel_line_type;
typedef typename sprout::container_traits<pixel_line_type>::value_type pixel_type;
return sprout::make<pixel_line_type>(
2011-11-26 06:20:35 +00:00
sprout::darkroom::colors::rgb_f_to_rgb<pixel_type>(
raytracer.template operator()(
2012-10-05 15:58:56 +00:00
renderer, camera, objs, lights,
x + XIndexes, y, width, height, depth_max
2011-11-26 06:20:35 +00:00
)
)...
);
}
template<
typename Pixels,
2012-10-05 15:58:56 +00:00
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights,
2012-02-28 01:46:39 +00:00
sprout::index_t... YIndexes
2011-11-26 06:20:35 +00:00
>
inline SPROUT_CONSTEXPR Pixels
2011-11-26 06:20:35 +00:00
generate_impl(
2012-10-05 15:58:56 +00:00
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2011-11-26 06:20:35 +00:00
>::size_type x
,
typename sprout::container_traits<Pixels>::size_type y,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2011-11-26 06:20:35 +00:00
>::size_type width
,
typename sprout::container_traits<Pixels>::size_type height,
2011-11-26 06:20:35 +00:00
std::size_t depth_max,
sprout::index_tuple<YIndexes...>
)
{
return sprout::make<Pixels>(
2011-11-26 06:20:35 +00:00
sprout::darkroom::pixels::detail::generate_impl_line<Pixels>(
2012-10-05 15:58:56 +00:00
raytracer, renderer, camera, objs, lights,
x, y + YIndexes, width, height, depth_max,
2012-05-14 02:33:36 +00:00
sprout::index_range<
2011-11-26 06:20:35 +00:00
0,
sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
>::static_size
2012-05-14 02:33:36 +00:00
>::make()
2011-11-26 06:20:35 +00:00
)...
);
}
} // namespace detail
template<
typename Pixels,
2012-10-05 15:58:56 +00:00
typename RayTracer, typename Renderer, typename Camera,
typename Objects, typename Lights
2011-11-26 06:20:35 +00:00
>
inline SPROUT_CONSTEXPR Pixels generate(
2012-10-05 15:58:56 +00:00
RayTracer const& raytracer, Renderer const& renderer, Camera const& camera,
Objects const& objs, Lights const& lights,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2011-11-26 06:20:35 +00:00
>::size_type x
2012-10-06 04:53:07 +00:00
= 0,
typename sprout::container_traits<Pixels>::size_type y
2012-10-06 04:53:07 +00:00
= 0,
typename sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2011-11-26 06:20:35 +00:00
>::size_type width
= sprout::container_traits<
typename sprout::container_traits<Pixels>::value_type
2012-10-06 04:53:07 +00:00
>::static_size,
typename sprout::container_traits<Pixels>::size_type height
2012-10-06 04:53:07 +00:00
= sprout::container_traits<Pixels>::static_size,
2011-11-26 06:20:35 +00:00
std::size_t depth_max = 8
)
{
return sprout::darkroom::pixels::detail::generate_impl<Pixels>(
2012-10-05 15:58:56 +00:00
raytracer, renderer, camera, objs, lights,
x, y, width, height, depth_max,
2012-05-14 02:33:36 +00:00
sprout::index_range<
2011-11-26 06:20:35 +00:00
0,
sprout::container_traits<Pixels>::static_size
2012-05-14 02:33:36 +00:00
>::make()
2011-11-26 06:20:35 +00:00
);
}
//
// color_pixels
//
template<std::size_t Width, std::size_t Height, typename Color = sprout::darkroom::colors::rgb_t>
2011-11-26 06:20:35 +00:00
struct color_pixels {
public:
2012-10-05 15:58:56 +00:00
typedef sprout::array<sprout::array<Color, Width>, Height> type;
2011-11-26 06:20:35 +00:00
};
} // namespace pixels
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP