2#ifndef LIBSBX_GRAPHICS_IMAGES_IMAGE2D_HPP_
3#define LIBSBX_GRAPHICS_IMAGES_IMAGE2D_HPP_
7#include <libsbx/utility/crc32.hpp>
8#include <libsbx/utility/enum.hpp>
10#include <libsbx/memory/observer_ptr.hpp>
12#include <libsbx/reflection/description.hpp>
14#include <libsbx/math/vector2.hpp>
16#include <libsbx/graphics/resource_storage.hpp>
18#include <libsbx/graphics/images/image.hpp>
20namespace sbx::graphics {
22enum class format : std::int32_t {
23 undefined = VK_FORMAT_UNDEFINED,
24 r8_unorm = VK_FORMAT_R8_UNORM,
25 r16_sfloat = VK_FORMAT_R16_SFLOAT,
26 r32_sfloat = VK_FORMAT_R32_SFLOAT,
27 r32_uint = VK_FORMAT_R32_UINT,
28 r64_uint = VK_FORMAT_R64_UINT,
29 r16g16_sfloat = VK_FORMAT_R16G16_SFLOAT,
30 r32g32_sfloat = VK_FORMAT_R32G32_SFLOAT,
31 r32g32_uint = VK_FORMAT_R32G32_UINT,
32 r8g8b8a8_unorm = VK_FORMAT_R8G8B8A8_UNORM,
33 r8g8b8a8_srgb = VK_FORMAT_R8G8B8A8_SRGB,
34 b8g8r8a8_srgb = VK_FORMAT_B8G8R8A8_SRGB,
35 a2b10g10r10_unorm_pack32 = VK_FORMAT_A2B10G10R10_UNORM_PACK32,
36 r16g16b16a16_sfloat = VK_FORMAT_R16G16B16A16_SFLOAT,
37 r32g32b32a32_sfloat = VK_FORMAT_R32G32B32A32_SFLOAT
40enum class address_mode : std::int32_t {
41 repeat = VK_SAMPLER_ADDRESS_MODE_REPEAT,
42 mirror = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
43 clamp_to_edge = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
44 clamp_to_border = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
47enum class filter : std::int32_t {
48 nearest = VK_SAMPLER_MIPMAP_MODE_NEAREST,
49 linear = VK_SAMPLER_MIPMAP_MODE_LINEAR
56 image2d(
const math::vector2u& extent, graphics::format format = graphics::format::r8g8b8a8_unorm, graphics::filter filter = graphics::filter::linear, graphics::address_mode address_mode = graphics::address_mode::repeat, VkImageUsageFlags usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT,
bool anisotropic =
false,
bool mipmap =
false, std::uint32_t array_layers = 1u);
58 image2d(
const std::filesystem::path& path, graphics::format format = graphics::format::r8g8b8a8_srgb, graphics::filter filter = graphics::filter::linear, graphics::address_mode address_mode = graphics::address_mode::repeat,
bool anisotropic =
false,
bool mipmap =
false);
66 auto name()
const noexcept -> std::string
override {
72 enum class file_flags : std::uint16_t {
74 compressed = utility::bit_v<0>
79 std::uint16_t version;
83 std::uint32_t channels;
84 std::uint32_t uncompressed_size;
85 std::uint32_t compressed_size;
88 static_assert(
sizeof(file_header) == 32u,
"file_header layout changed");
90 static constexpr auto file_magic = utility::make_magic<std::uint64_t>(
"SBXTEXTR");
91 static constexpr auto file_version = std::uint16_t{1u};
92 static constexpr auto binary_file_extension = std::string_view{
".sbxtex"};
94 auto _upload_pixels(
const std::uint8_t* pixels, std::size_t size) -> void;
96 auto _load(
const std::filesystem::path& path = {}) ->
void;
98 auto _load_binary(
const std::filesystem::path& path) -> void;
100 static auto _process(
const std::filesystem::path& path, std::uint32_t width, std::uint32_t height, std::uint32_t channels,
const std::uint8_t* pixels) -> void;
104 std::uint8_t _channels;
115 static constexpr auto name() -> std::string_view {
119 static constexpr auto enumerators() {
120 return std::make_tuple(
121 enumerator{
"undefined", sbx::graphics::format::undefined},
122 enumerator{
"r8_unorm", sbx::graphics::format::r8_unorm},
123 enumerator{
"r16_sfloat", sbx::graphics::format::r16_sfloat},
124 enumerator{
"r32_sfloat", sbx::graphics::format::r32_sfloat},
125 enumerator{
"r32_uint", sbx::graphics::format::r32_uint},
126 enumerator{
"r64_uint", sbx::graphics::format::r64_uint},
127 enumerator{
"r16g16_sfloat", sbx::graphics::format::r16g16_sfloat},
128 enumerator{
"r32g32_sfloat", sbx::graphics::format::r32g32_sfloat},
129 enumerator{
"r32g32_uint", sbx::graphics::format::r32g32_uint},
130 enumerator{
"r8g8b8a8_unorm", sbx::graphics::format::r8g8b8a8_unorm},
131 enumerator{
"r8g8b8a8_srgb", sbx::graphics::format::r8g8b8a8_srgb},
132 enumerator{
"b8g8r8a8_srgb", sbx::graphics::format::b8g8r8a8_srgb},
133 enumerator{
"a2b10g10r10_unorm_pack32", sbx::graphics::format::a2b10g10r10_unorm_pack32},
134 enumerator{
"r16g16b16a16_sfloat", sbx::graphics::format::r16g16b16a16_sfloat},
135 enumerator{
"r32g32b32a32_sfloat", sbx::graphics::format::r32g32b32a32_sfloat}
Definition: image2d.hpp:52
Definition: resource_storage.hpp:18
A vector in two-dimensional space.
Definition: vector2.hpp:28
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:29
Definition: description.hpp:16
Definition: enumerator.hpp:10