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-12-17 09:00:41 +00:00
|
|
|
#ifndef SPROUT_DARKROOM_TEXTURES_TEXTURE_HPP
|
|
|
|
#define SPROUT_DARKROOM_TEXTURES_TEXTURE_HPP
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <sprout/config.hpp>
|
2013-04-22 04:04:27 +00:00
|
|
|
#include <sprout/array.hpp>
|
2011-12-17 09:00:41 +00:00
|
|
|
#include <sprout/darkroom/access/access.hpp>
|
|
|
|
#include <sprout/darkroom/colors/rgb.hpp>
|
|
|
|
|
|
|
|
//
|
|
|
|
// DARKROOM_LOAD_TEXTURE
|
|
|
|
//
|
|
|
|
#define DARKROOM_LOAD_TEXTURE <sprout/darkroom/load/texture.hpp>
|
|
|
|
|
|
|
|
//
|
|
|
|
// DARKROOM_TEX_VERSION
|
|
|
|
//
|
|
|
|
#define DARKROOM_TEX_VERSION(NUM) NUM
|
|
|
|
|
|
|
|
//
|
|
|
|
// DARKROOM_TEX_IMAGE_DEFAULT
|
|
|
|
//
|
|
|
|
#define DARKROOM_TEX_IMAGE_DEFAULT 0
|
|
|
|
|
|
|
|
//
|
|
|
|
// DARKROOM_TEX_PIXEL_INT_R8G8B8
|
|
|
|
//
|
|
|
|
#define DARKROOM_TEX_PIXEL_INT_R8G8B8 0
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace darkroom {
|
|
|
|
namespace textures {
|
|
|
|
//
|
|
|
|
// version_type
|
|
|
|
//
|
|
|
|
typedef unsigned long version_type;
|
|
|
|
//
|
|
|
|
// info_type
|
|
|
|
//
|
|
|
|
struct info_type {
|
|
|
|
public:
|
|
|
|
unsigned long image_format;
|
|
|
|
unsigned long pixel_format;
|
|
|
|
std::size_t width;
|
|
|
|
std::size_t height;
|
|
|
|
};
|
|
|
|
//
|
|
|
|
// image_type
|
|
|
|
//
|
2013-03-26 17:02:16 +00:00
|
|
|
template<std::size_t Width, std::size_t Height, typename Color = sprout::darkroom::colors::rgb_f_t>
|
2011-12-17 09:00:41 +00:00
|
|
|
struct image_type {
|
|
|
|
public:
|
|
|
|
typedef Color color_type;
|
|
|
|
typedef color_type value_type;
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
SPROUT_STATIC_CONSTEXPR size_type static_width = Width;
|
|
|
|
SPROUT_STATIC_CONSTEXPR size_type static_height = Height;
|
|
|
|
typedef sprout::array<value_type, static_width * static_height> pixels_type;
|
|
|
|
typedef typename sprout::darkroom::access::unit<color_type>::type color_component_type;
|
|
|
|
private:
|
|
|
|
pixels_type pixels_;
|
|
|
|
public:
|
|
|
|
template<typename... Elems>
|
2013-07-22 13:00:09 +00:00
|
|
|
SPROUT_CONSTEXPR image_type(info_type const&, Elems const&... elems)
|
2011-12-17 09:00:41 +00:00
|
|
|
: pixels_{{
|
|
|
|
color_type(
|
|
|
|
static_cast<color_component_type>((elems >> 16) & 0xFF) / 0xFF,
|
|
|
|
static_cast<color_component_type>((elems >> 8) & 0xFF) / 0xFF,
|
|
|
|
static_cast<color_component_type>(elems & 0xFF) / 0xFF
|
|
|
|
)...
|
|
|
|
}}
|
|
|
|
{
|
|
|
|
static_assert(sizeof...(Elems) == static_width * static_height, "image_type<>: unmatch image size");
|
|
|
|
}
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR value_type const&
|
|
|
|
operator()(size_type x, size_type y) const {
|
2011-12-17 09:00:41 +00:00
|
|
|
return pixels_[y * static_width + x];
|
|
|
|
}
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR size_type
|
|
|
|
width() const {
|
2011-12-17 09:00:41 +00:00
|
|
|
return static_width;
|
|
|
|
}
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR size_type
|
|
|
|
height() const {
|
2011-12-17 09:00:41 +00:00
|
|
|
return static_height;
|
|
|
|
}
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_CONSTEXPR pixels_type const&
|
|
|
|
pixels() const {
|
2011-12-17 09:00:41 +00:00
|
|
|
return pixels_;
|
|
|
|
}
|
|
|
|
};
|
2012-11-08 16:09:49 +00:00
|
|
|
template<std::size_t Width, std::size_t Height, typename Color>
|
|
|
|
SPROUT_CONSTEXPR_OR_CONST typename sprout::darkroom::textures::image_type<Width, Height, Color>::size_type
|
|
|
|
sprout::darkroom::textures::image_type<Width, Height, Color>::static_width;
|
|
|
|
template<std::size_t Width, std::size_t Height, typename Color>
|
|
|
|
SPROUT_CONSTEXPR_OR_CONST typename sprout::darkroom::textures::image_type<Width, Height, Color>::size_type
|
|
|
|
sprout::darkroom::textures::image_type<Width, Height, Color>::static_height;
|
2011-12-17 09:00:41 +00:00
|
|
|
} // namespace textures
|
|
|
|
} // namespace darkroom
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DARKROOM_TEXTURES_TEXTURE_HPP
|