diff --git a/libs/gfx/include/psemek/gfx/texture_view.hpp b/libs/gfx/include/psemek/gfx/texture_view.hpp new file mode 100644 index 00000000..284cf5e3 --- /dev/null +++ b/libs/gfx/include/psemek/gfx/texture_view.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include +#include + +namespace psemek::gfx +{ + + template + struct basic_texture_view + { + basic_texture const * texture = nullptr; + geom::box part; + + basic_texture_view(basic_texture const * texture = nullptr); + basic_texture_view(basic_texture const * texture, geom::box 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 + basic_texture_view::basic_texture_view(basic_texture const * texture) + : texture(texture) + { + if (texture) + { + static const auto zero = geom::point::zero(); + part = geom::span(zero, zero + texture->size()); + } + } + + template + basic_texture_view::basic_texture_view(basic_texture const * texture, geom::box 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>; + +}