Add gfx::texture_view specifying a part of existing texture
This commit is contained in:
parent
20302885b5
commit
d01008114b
1 changed files with 67 additions and 0 deletions
67
libs/gfx/include/psemek/gfx/texture_view.hpp
Normal file
67
libs/gfx/include/psemek/gfx/texture_view.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/gfx/texture.hpp>
|
||||||
|
#include <psemek/geom/box.hpp>
|
||||||
|
|
||||||
|
namespace psemek::gfx
|
||||||
|
{
|
||||||
|
|
||||||
|
template <std::size_t D, GLenum Target>
|
||||||
|
struct basic_texture_view
|
||||||
|
{
|
||||||
|
basic_texture<D, Target> const * texture = nullptr;
|
||||||
|
geom::box<std::size_t, D> part;
|
||||||
|
|
||||||
|
basic_texture_view(basic_texture<D, Target> const * texture = nullptr);
|
||||||
|
basic_texture_view(basic_texture<D, Target> const * texture, geom::box<std::size_t, D> const & part);
|
||||||
|
|
||||||
|
std::size_t size() const { return part.dimensions(); }
|
||||||
|
|
||||||
|
std::size_t width() const
|
||||||
|
{
|
||||||
|
return part[0].length();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t height() const
|
||||||
|
{
|
||||||
|
if constexpr (D >= 2)
|
||||||
|
return part[1].length();
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t depth() const
|
||||||
|
{
|
||||||
|
if constexpr (D >= 3)
|
||||||
|
return part[2].length();
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() const { return texture != nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t D, GLenum Target>
|
||||||
|
basic_texture_view<D, Target>::basic_texture_view(basic_texture<D, Target> const * texture)
|
||||||
|
: texture(texture)
|
||||||
|
{
|
||||||
|
if (texture)
|
||||||
|
{
|
||||||
|
static const auto zero = geom::point<std::size_t, D>::zero();
|
||||||
|
part = geom::span(zero, zero + texture->size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t D, GLenum Target>
|
||||||
|
basic_texture_view<D, Target>::basic_texture_view(basic_texture<D, Target> const * texture, geom::box<std::size_t, D> const & part)
|
||||||
|
: texture(texture)
|
||||||
|
, part(part)
|
||||||
|
{}
|
||||||
|
|
||||||
|
using texture_view_1d = basic_texture_view<1, gl::TEXTURE_1D>;
|
||||||
|
using texture_view_1d_array = basic_texture_view<2, gl::TEXTURE_1D_ARRAY>;
|
||||||
|
using texture_view_2d = basic_texture_view<2, gl::TEXTURE_2D>;
|
||||||
|
using texture_view_2d_array = basic_texture_view<3, gl::TEXTURE_2D_ARRAY>;
|
||||||
|
using texture_view_3d = basic_texture_view<3, gl::TEXTURE_3D>;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue