Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Ktx2Loader.h
1#pragma once
2#include <cstdint>
3#include <filesystem>
4#include <memory>
5#include <string>
6#include <vector>
7#include <vulkan/vulkan_core.h>
8
9namespace Engine::Assets {
10
11 namespace Textures
12 {
17 uint32_t baseWidth = 0;
18 uint32_t baseHeight = 0;
19 uint32_t sourceWidth = 0;
20 uint32_t sourceHeight = 0;
21 VkFormat vkFormat = VK_FORMAT_UNDEFINED;
22 uint32_t mipLevels = 0;
23 uint32_t sourceMipLevels = 0;
24 uint32_t sourceBaseMip = 0;
25 bool isCompressed = false;
26 std::vector<uint8_t> allData;
27 std::shared_ptr<void> externalDataOwner;
28 const uint8_t* externalData = nullptr;
29 std::vector<VkDeviceSize> mipOffsets;
30 std::vector<VkDeviceSize> mipSizes;
31 std::vector<uint32_t> mipWidths;
32 std::vector<uint32_t> mipHeights;
33 std::string uri;
34
38 [[nodiscard]] const uint8_t* bytes() const
39 {
40 return externalData != nullptr ? externalData : allData.data();
41 }
42
46 [[nodiscard]] bool hasBytes() const
47 {
48 return externalData != nullptr || !allData.empty();
49 }
50
55 {
56 std::vector<uint8_t>().swap(allData);
57 externalDataOwner.reset();
58 externalData = nullptr;
59 }
60 };
61
69 Ktx2TextureData extractMipRange(const Ktx2TextureData& source, uint32_t firstMip, uint32_t mipCount);
70 }
71
72 namespace Loaders
73 {
77 enum class Ktx2TextureType : uint32_t
78 {
79 BC6H_Unsigned = 0x8E8F,
80 BC6H_Signed = 0x8E8E,
81 BC7_RGBA = 0x8E8C,
82 BC7_SRGB = 0x8E8D,
83 BC4_Unsigned = 0x8DBB,
84 BC4_Signed = 0x8DBC,
85 BC5_Unsigned = 0x8DBD,
86 BC5_Signed = 0x8DBE,
87 };
88
96 class Ktx2Loader {
97 public:
101 Ktx2Loader() = default;
102
106 ~Ktx2Loader() = default;
107
113 Textures::Ktx2TextureData load(const std::filesystem::path& filename);
114 };
115 }
116
117} // namespace EngineCore
Ktx2Loader()=default
Creates a stateless KTX loader.
~Ktx2Loader()=default
Destroys the loader.
Textures::Ktx2TextureData load(const std::filesystem::path &filename)
Loads image data and mip metadata from a KTX or KTX2 file.
Ktx2TextureType
OpenGL internal format constants for KTX1 texture compression types.
Definition Ktx2Loader.h:78
@ BC5_Signed
GL_COMPRESSED_SIGNED_RG_RGTC2.
Definition Ktx2Loader.h:86
@ BC7_SRGB
GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM.
Definition Ktx2Loader.h:82
@ BC6H_Unsigned
GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT.
Definition Ktx2Loader.h:79
@ BC5_Unsigned
GL_COMPRESSED_RG_RGTC2.
Definition Ktx2Loader.h:85
@ BC6H_Signed
GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT.
Definition Ktx2Loader.h:80
@ BC4_Unsigned
GL_COMPRESSED_RED_RGTC1.
Definition Ktx2Loader.h:83
@ BC4_Signed
GL_COMPRESSED_SIGNED_RED_RGTC1.
Definition Ktx2Loader.h:84
@ BC7_RGBA
GL_COMPRESSED_RGBA_BPTC_UNORM.
Definition Ktx2Loader.h:81
Ktx2TextureData extractMipRange(const Ktx2TextureData &source, uint32_t firstMip, uint32_t mipCount)
Copies a contiguous mip range into a new KTX data object.
Stores all data loaded from a KTX2 file including mip chain.
Definition Ktx2Loader.h:16
const uint8_t * externalData
Borrowed image bytes from an external owner.
Definition Ktx2Loader.h:28
std::vector< uint32_t > mipWidths
Width for each local mip level.
Definition Ktx2Loader.h:31
std::vector< VkDeviceSize > mipSizes
Byte size for each local mip level.
Definition Ktx2Loader.h:30
uint32_t baseWidth
Width of mip level 0 in this data object.
Definition Ktx2Loader.h:17
std::vector< uint8_t > allData
Owned contiguous image bytes.
Definition Ktx2Loader.h:26
void releaseBytes()
Releases owned and externally held image bytes.
Definition Ktx2Loader.h:54
VkFormat vkFormat
Vulkan format used for upload.
Definition Ktx2Loader.h:21
bool isCompressed
True when the format uses block compression.
Definition Ktx2Loader.h:25
uint32_t mipLevels
Number of mip levels stored in this data object.
Definition Ktx2Loader.h:22
const uint8_t * bytes() const
Returns the contiguous image bytes, whether owned or externally held.
Definition Ktx2Loader.h:38
uint32_t sourceMipLevels
Number of mip levels in the original source texture.
Definition Ktx2Loader.h:23
uint32_t sourceHeight
Height of the original source texture before mip extraction.
Definition Ktx2Loader.h:20
uint32_t sourceWidth
Width of the original source texture before mip extraction.
Definition Ktx2Loader.h:19
std::shared_ptr< void > externalDataOwner
Owner that keeps externalData alive.
Definition Ktx2Loader.h:27
uint32_t baseHeight
Height of mip level 0 in this data object.
Definition Ktx2Loader.h:18
uint32_t sourceBaseMip
Source mip index represented by local mip level 0.
Definition Ktx2Loader.h:24
std::vector< uint32_t > mipHeights
Height for each local mip level.
Definition Ktx2Loader.h:32
std::vector< VkDeviceSize > mipOffsets
Byte offset for each local mip level.
Definition Ktx2Loader.h:29
std::string uri
Source URI or filename used for diagnostics.
Definition Ktx2Loader.h:33
bool hasBytes() const
Returns true when image bytes are available.
Definition Ktx2Loader.h:46