28 enum texture_type: std::uint8_t
31 texture_type_1d_array,
33 texture_type_2d_array,
36 texture_type_cube_array
42 std::uint32_t format_identifier{0};
43 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&format_identifier), 1);
46 if (format_identifier != 0xbc969ff0)
52 std::uint32_t format_version{0};
53 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&format_version), 1);
56 if (format_version != 1)
62 std::uint32_t image_path_length{0};
63 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&image_path_length), 1);
64 std::string image_path(image_path_length,
'\0');
65 ctx.
read8(
reinterpret_cast<std::byte*
>(image_path.data()), image_path_length);
68 std::shared_ptr<gl::image> image;
72 case texture_type_1d_array:
77 case texture_type_2d_array:
85 case texture_type_cube:
86 case texture_type_cube_array:
96 std::uint32_t first_mip_level;
97 std::uint32_t mip_level_count;
98 std::uint32_t first_array_layer;
99 std::uint32_t array_layer_count;
101 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&first_mip_level), 1);
102 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&mip_level_count), 1);
103 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&first_array_layer), 1);
104 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&array_layer_count), 1);
107 if (!mip_level_count)
109 mip_level_count = image->get_mip_levels();
113 if (!array_layer_count)
115 array_layer_count = image->get_array_layers();
126 float max_anisotropy;
127 std::uint8_t compare_enabled;
131 std::array<float, 4> border_color;
132 ctx.
read8(
reinterpret_cast<std::byte*
>(&mag_filter), 1);
133 ctx.
read8(
reinterpret_cast<std::byte*
>(&min_filter), 1);
134 ctx.
read8(
reinterpret_cast<std::byte*
>(&mipmap_mode), 1);
135 ctx.
read8(
reinterpret_cast<std::byte*
>(&address_mode_u), 1);
136 ctx.
read8(
reinterpret_cast<std::byte*
>(&address_mode_v), 1);
137 ctx.
read8(
reinterpret_cast<std::byte*
>(&address_mode_w), 1);
138 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&mip_lod_bias), 1);
139 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&max_anisotropy), 1);
140 ctx.
read8(
reinterpret_cast<std::byte*
>(&compare_enabled), 1);
142 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&min_lod), 1);
143 ctx.
read32_le(
reinterpret_cast<std::byte*
>(&max_lod), 1);
144 ctx.
read32_le(
reinterpret_cast<std::byte*
>(border_color.data()), 4);
147 std::shared_ptr<gl::sampler> sampler = std::make_shared<gl::sampler>
165 switch (texture_type)
167 case texture_type_1d:
169 auto image_view = std::make_shared<gl::image_view_1d>(image,
format, first_mip_level, mip_level_count, first_array_layer);
170 return std::make_unique<gl::texture_1d>(std::move(image_view), std::move(sampler));
173 case texture_type_1d_array:
175 auto image_view = std::make_shared<gl::image_view_1d_array>(image,
format, first_mip_level, mip_level_count, first_array_layer, array_layer_count);
176 return std::make_unique<gl::texture_1d_array>(std::move(image_view), std::move(sampler));
179 case texture_type_2d:
181 auto image_view = std::make_shared<gl::image_view_2d>(image,
format, first_mip_level, mip_level_count, first_array_layer);
182 return std::make_unique<gl::texture_2d>(std::move(image_view), std::move(sampler));
185 case texture_type_2d_array:
187 auto image_view = std::make_shared<gl::image_view_2d_array>(image,
format, first_mip_level, mip_level_count, first_array_layer, array_layer_count);
188 return std::make_unique<gl::texture_2d_array>(std::move(image_view), std::move(sampler));
191 case texture_type_3d:
193 auto image_view = std::make_shared<gl::image_view_3d>(image,
format, first_mip_level, mip_level_count);
194 return std::make_unique<gl::texture_3d>(std::move(image_view), std::move(sampler));
197 case texture_type_cube:
199 auto image_view = std::make_shared<gl::image_view_cube>(image,
format, first_mip_level, mip_level_count, first_array_layer);
200 return std::make_unique<gl::texture_cube>(std::move(image_view), std::move(sampler));
203 case texture_type_cube_array:
205 auto image_view = std::make_shared<gl::image_view_cube_array>(image,
format, first_mip_level, mip_level_count, first_array_layer, array_layer_count);
206 return std::make_unique<gl::texture_cube_array>(std::move(image_view), std::move(sampler));
An exception of this type is thrown when an error occurs during deserialization.
Cube-compatible 2D image.
static std::unique_ptr< T > load(::resource_manager &resource_manager, deserialize_context &ctx)
Loads a resource.
Manages the loading, caching, and saving of resources.
std::shared_ptr< T > load(const std::filesystem::path &path)
Loads and caches a resource.
format
Image and vertex formats.
sampler_address_mode
Behaviors of sampling with texture coordinates outside an image.
sampler_mipmap_mode
Mipmap modes used for texture lookups.
sampler_filter
Filters used for texture lookups.
compare_op
Comparison operators.
Provides access to a deserialization state.
virtual std::size_t read32_le(std::byte *data, std::size_t count) noexcept(false)=0
Reads 32-bit (double word) little-endian data.
virtual std::size_t read8(std::byte *data, std::size_t count) noexcept(false)=0
Reads 8-bit (byte) data.