Sprout/sprout/darkroom/pixels/generate.hpp

141 lines
5.1 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2014-01-08 07:48:12 +00:00
Copyright (c) 2011-2014 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
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)
=============================================================================*/
2011-11-26 06:20:35 +00:00
#ifndef SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#define SPROUT_DARKROOM_PIXELS_GENERATE_HPP
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
2013-04-06 04:06:51 +00:00
#include <sprout/index_tuple/metafunction.hpp>
#include <sprout/array.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
2013-03-31 06:14:10 +00:00
#include <sprout/container/indexes.hpp>
2011-11-26 06:20:35 +00:00
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/renderers/calculate.hpp>
#include <sprout/darkroom/tracers/calculate.hpp>
2011-11-26 06:20:35 +00:00
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>(
sprout::darkroom::tracers::calculate(
raytracer,
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,
2013-03-31 06:14:10 +00:00
sprout::container_indexes<typename sprout::container_traits<Pixels>::value_type>::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,
std::size_t depth_max = sprout::darkroom::renderers::default_depth
2011-11-26 06:20:35 +00:00
)
{
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,
2013-03-31 06:14:10 +00:00
sprout::container_indexes<Pixels>::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