Support loading sRGB textures
This commit is contained in:
parent
e0acd31259
commit
f0c63bac7a
2 changed files with 44 additions and 0 deletions
|
|
@ -33,6 +33,9 @@ namespace psemek::gfx
|
|||
template <typename T>
|
||||
struct integer;
|
||||
|
||||
template <typename T>
|
||||
struct srgb;
|
||||
|
||||
template <typename Pixel>
|
||||
struct pixel_traits;
|
||||
|
||||
|
|
@ -70,6 +73,24 @@ namespace psemek::gfx
|
|||
static constexpr GLenum type = gl::UNSIGNED_BYTE;
|
||||
};
|
||||
|
||||
// Normalized 8-bit sRGB
|
||||
|
||||
template <>
|
||||
struct pixel_traits<srgb<geom::vector<std::uint8_t, 3>>>
|
||||
{
|
||||
static constexpr GLenum internal_format = gl::SRGB8;
|
||||
static constexpr GLenum format = gl::RGB;
|
||||
static constexpr GLenum type = gl::UNSIGNED_BYTE;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pixel_traits<srgb<geom::vector<std::uint8_t, 4>>>
|
||||
{
|
||||
static constexpr GLenum internal_format = gl::SRGB8_ALPHA8;
|
||||
static constexpr GLenum format = gl::RGBA;
|
||||
static constexpr GLenum type = gl::UNSIGNED_BYTE;
|
||||
};
|
||||
|
||||
// Normalized 10-bit
|
||||
|
||||
template <>
|
||||
|
|
|
|||
|
|
@ -47,9 +47,15 @@ namespace psemek::gfx
|
|||
template <typename Pixel>
|
||||
void load(geom::vector<std::size_t, D> const & size, Pixel const * data = nullptr);
|
||||
|
||||
template <typename Pixel>
|
||||
void load_srgb(geom::vector<std::size_t, D> const & size, Pixel const * data = nullptr);
|
||||
|
||||
template <typename Pixel>
|
||||
void load(util::array<Pixel, D> const & p);
|
||||
|
||||
template <typename Pixel>
|
||||
void load_srgb(util::array<Pixel, D> const & p);
|
||||
|
||||
void pixels(GLenum format, GLenum type, void * data, int layer = 0) const;
|
||||
|
||||
template <typename Pixmap>
|
||||
|
|
@ -278,6 +284,14 @@ namespace psemek::gfx
|
|||
load(traits::internal_format, size, traits::format, traits::type, data);
|
||||
}
|
||||
|
||||
template <std::size_t D, GLenum Target>
|
||||
template <typename Pixel>
|
||||
void basic_texture<D, Target>::load_srgb(geom::vector<std::size_t, D> const & size, Pixel const * data)
|
||||
{
|
||||
using traits = pixel_traits<srgb<Pixel>>;
|
||||
load(traits::internal_format, size, traits::format, traits::type, data);
|
||||
}
|
||||
|
||||
template <std::size_t D, GLenum Target>
|
||||
template <typename Pixel>
|
||||
void basic_texture<D, Target>::load(util::array<Pixel, D> const & p)
|
||||
|
|
@ -287,6 +301,15 @@ namespace psemek::gfx
|
|||
load(size, p.data());
|
||||
}
|
||||
|
||||
template <std::size_t D, GLenum Target>
|
||||
template <typename Pixel>
|
||||
void basic_texture<D, Target>::load_srgb(util::array<Pixel, D> const & p)
|
||||
{
|
||||
geom::vector<std::size_t, D> size;
|
||||
for (std::size_t i = 0; i < D; ++i) size[i] = p.dim(i);
|
||||
load_srgb(size, p.data());
|
||||
}
|
||||
|
||||
template <std::size_t D, GLenum Target>
|
||||
void basic_texture<D, Target>::pixels(GLenum format, GLenum type, void * data, int layer) const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue