16 "TextureLoom already initialized (static flag)");
22 "Cannot initialize TextureLoom with null backend");
28 "TextureLoom already initialized");
37 "TextureLoom initialized");
52 "Shutting down TextureLoom...");
55 if (texture && texture->is_initialized()) {
67 "TextureLoom shutdown complete");
75 uint32_t width, uint32_t height,
76 ImageFormat format,
const void* data, uint32_t mip_levels)
80 "TextureLoom not initialized");
85 auto image = std::make_shared<Core::VKImage>(
86 width, height, 1, vk_format,
94 if (!image->is_initialized()) {
96 "Failed to initialize VKImage");
106 vk::ImageLayout::eUndefined,
107 vk::ImageLayout::eShaderReadOnlyOptimal,
108 mip_levels, 1, vk::ImageAspectFlagBits::eColor);
109 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
114 "Created 2D texture: {}x{}, format: {}, mips: {}",
115 width, height, vk::to_string(vk_format), mip_levels);
120 uint32_t width, uint32_t height, uint32_t depth,
125 "TextureLoom not initialized");
130 auto image = std::make_shared<Core::VKImage>(
131 width, height, depth, vk_format,
138 if (!image->is_initialized()) {
140 "Failed to initialize 3D VKImage");
150 vk::ImageLayout::eUndefined,
151 vk::ImageLayout::eShaderReadOnlyOptimal,
152 1, 1, vk::ImageAspectFlagBits::eColor);
153 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
158 "Created 3D texture: {}x{}x{}, format: {}",
159 width, height, depth, vk::to_string(vk_format));
164 uint32_t size,
ImageFormat format,
const void* data)
168 "TextureLoom not initialized");
173 auto image = std::make_shared<Core::VKImage>(
174 size, size, 1, vk_format,
181 if (!image->is_initialized()) {
183 "Failed to initialize cubemap VKImage");
189 size_t total_size = face_size * 6;
194 vk::ImageLayout::eUndefined,
195 vk::ImageLayout::eShaderReadOnlyOptimal,
196 1, 6, vk::ImageAspectFlagBits::eColor);
197 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
202 "Created cubemap: {}x{}, format: {}", size, size, vk::to_string(vk_format));
207 uint32_t width, uint32_t height,
ImageFormat format)
211 "TextureLoom not initialized");
216 auto image = std::make_shared<Core::VKImage>(
217 width, height, 1, vk_format,
224 if (!image->is_initialized()) {
226 "Failed to initialize render target VKImage");
232 vk::ImageLayout::eUndefined,
233 vk::ImageLayout::eColorAttachmentOptimal,
234 1, 1, vk::ImageAspectFlagBits::eColor);
235 image->set_current_layout(vk::ImageLayout::eColorAttachmentOptimal);
239 "Created render target: {}x{}, format: {}",
240 width, height, vk::to_string(vk_format));
245 uint32_t width, uint32_t height,
bool with_stencil)
249 "TextureLoom not initialized");
253 vk::Format vk_format = with_stencil
254 ? vk::Format::eD24UnormS8Uint
255 : vk::Format::eD32Sfloat;
257 auto image = std::make_shared<Core::VKImage>(
258 width, height, 1, vk_format,
265 if (!image->is_initialized()) {
267 "Failed to initialize depth buffer VKImage");
271 vk::ImageAspectFlags aspect = with_stencil
272 ? (vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil)
273 : vk::ImageAspectFlagBits::eDepth;
277 vk::ImageLayout::eUndefined,
278 vk::ImageLayout::eDepthStencilAttachmentOptimal,
280 image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
284 "Created depth buffer: {}x{}, format: {}, stencil: {}",
285 width, height, vk::to_string(vk_format), with_stencil);
290 uint32_t width, uint32_t height,
ImageFormat format)
294 "TextureLoom not initialized");
299 auto image = std::make_shared<Core::VKImage>(
300 width, height, 1, vk_format,
307 if (!image->is_initialized()) {
309 "Failed to initialize storage image VKImage");
315 vk::ImageLayout::eUndefined,
316 vk::ImageLayout::eGeneral,
317 1, 1, vk::ImageAspectFlagBits::eColor);
318 image->set_current_layout(vk::ImageLayout::eGeneral);
322 "Created storage image: {}x{}, format: {}",
323 width, height, vk::to_string(vk_format));
332 const std::shared_ptr<Core::VKImage>& image,
const void* data,
size_t size)
336 "Invalid parameters for upload_data");
344 const std::shared_ptr<Core::VKImage>& image,
void* data,
size_t size)
348 "Invalid parameters for download_data");
363 "TextureLoom not initialized");
405 hash ^= std::hash<int> {}(
static_cast<int>(config.
mag_filter)) << 0;
406 hash ^= std::hash<int> {}(
static_cast<int>(config.
min_filter)) << 4;
407 hash ^= std::hash<int> {}(
static_cast<int>(config.
address_mode_u)) << 8;
408 hash ^= std::hash<int> {}(
static_cast<int>(config.
address_mode_v)) << 12;
409 hash ^= std::hash<int> {}(
static_cast<int>(config.
address_mode_w)) << 16;
423 return vk::Format::eR8Unorm;
425 return vk::Format::eR8G8Unorm;
427 return vk::Format::eR8G8B8Unorm;
429 return vk::Format::eR8G8B8A8Unorm;
431 return vk::Format::eR8G8B8A8Srgb;
433 return vk::Format::eR16Sfloat;
435 return vk::Format::eR16G16Sfloat;
437 return vk::Format::eR16G16B16A16Sfloat;
439 return vk::Format::eR32Sfloat;
441 return vk::Format::eR32G32Sfloat;
443 return vk::Format::eR32G32B32A32Sfloat;
445 return vk::Format::eD16Unorm;
447 return vk::Format::eX8D24UnormPack32;
449 return vk::Format::eD32Sfloat;
451 return vk::Format::eD24UnormS8Uint;
453 return vk::Format::eR8G8B8A8Unorm;
492 uint32_t width, uint32_t height, uint32_t depth,
ImageFormat format)
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
void download_image_data(std::shared_ptr< VKImage > image, void *data, size_t size)
Download data from an image (creates staging buffer internally)
void cleanup_image(const std::shared_ptr< VKImage > &image)
Cleanup a VKImage (destroy view, image, and free memory)
void initialize_image(const std::shared_ptr< VKImage > &image)
Initialize a VKImage (allocate VkImage, memory, and create image view)
vk::Sampler create_sampler(vk::Filter filter=vk::Filter::eLinear, vk::SamplerAddressMode address_mode=vk::SamplerAddressMode::eRepeat, float max_anisotropy=0.0F)
Create sampler.
void transition_image_layout(vk::Image image, vk::ImageLayout old_layout, vk::ImageLayout new_layout, uint32_t mip_levels=1, uint32_t array_layers=1, vk::ImageAspectFlags aspect_flags=vk::ImageAspectFlagBits::eColor)
Transition image layout using a pipeline barrier.
void upload_image_data(std::shared_ptr< VKImage > image, const void *data, size_t size)
Upload data to an image (creates staging buffer internally)
@ RENDER_TARGET
Color attachment for rendering.
@ STORAGE
Storage image (compute shader read/write)
@ TEXTURE_2D
Sampled texture (shader read)
@ DEPTH_STENCIL
Depth/stencil attachment.
std::shared_ptr< Core::VKImage > create_render_target(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8)
Create a render target (color attachment)
std::shared_ptr< Core::VKImage > create_depth_buffer(uint32_t width, uint32_t height, bool with_stencil=false)
Create a depth buffer.
static size_t get_bytes_per_pixel(ImageFormat format)
Get bytes per pixel for a format.
vk::Sampler get_nearest_sampler()
Get a default nearest sampler (for pixel-perfect sampling)
static size_t calculate_image_size(uint32_t width, uint32_t height, uint32_t depth, ImageFormat format)
Calculate image data size.
static vk::Format to_vulkan_format(ImageFormat format)
Convert Portal ImageFormat to Vulkan format.
std::shared_ptr< Core::VKImage > create_storage_image(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8)
Create a storage image (compute shader read/write)
void upload_data(const std::shared_ptr< Core::VKImage > &image, const void *data, size_t size)
Upload pixel data to an existing texture.
bool initialize(const std::shared_ptr< Core::VulkanBackend > &backend)
Initialize texture manager.
vk::Sampler get_or_create_sampler(const SamplerConfig &config)
Get or create a sampler with the given configuration.
void download_data(const std::shared_ptr< Core::VKImage > &image, void *data, size_t size)
Download pixel data from a texture.
std::shared_ptr< Core::VulkanBackend > m_backend
std::shared_ptr< Core::VKImage > create_3d(uint32_t width, uint32_t height, uint32_t depth, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr)
Create a 3D texture (volumetric)
vk::Sampler create_sampler(const SamplerConfig &config)
void shutdown()
Shutdown and cleanup all textures.
Core::BackendResourceManager * m_resource_manager
std::shared_ptr< Core::VKImage > create_2d(uint32_t width, uint32_t height, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr, uint32_t mip_levels=1)
Create a 2D texture.
static size_t hash_sampler_config(const SamplerConfig &config)
std::vector< std::shared_ptr< Core::VKImage > > m_textures
static bool s_initialized
std::shared_ptr< Core::VKImage > create_cubemap(uint32_t size, ImageFormat format=ImageFormat::RGBA8, const void *data=nullptr)
Create a cubemap texture.
vk::Sampler get_default_sampler()
Get a default linear sampler (for convenience)
std::unordered_map< size_t, vk::Sampler > m_sampler_cache
bool is_initialized() const
Check if manager is initialized.
@ ImageProcessing
Image processing tasks (filters, transformations)
@ Portal
High-level user-facing API layer.
@ VOLUMETRIC_3D
3D volumetric data
@ IMAGE_COLOR
2D RGB/RGBA image
@ IMAGE_2D
2D image (grayscale or single channel)
@ CLAMP_TO_EDGE
Clamp to edge color.
@ NEAREST
Nearest neighbor (pixelated)
ImageFormat
User-friendly image format enum.
@ DEPTH24_STENCIL8
24-bit depth + 8-bit stencil
@ RGB8
Three channel 8-bit.
@ DEPTH32F
32-bit float depth
@ RGBA32F
Four channel 32-bit float.
@ R16F
Single channel 16-bit float.
@ RGBA16F
Four channel 16-bit float.
@ RGBA8
Four channel 8-bit.
@ RG32F
Two channel 32-bit float.
@ R32F
Single channel 32-bit float.
@ R8
Single channel 8-bit.
@ RG16F
Two channel 16-bit float.
@ RGBA8_SRGB
Four channel 8-bit sRGB.
AddressMode address_mode_v
AddressMode address_mode_w
AddressMode address_mode_u