MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_2d() [2/2]

std::shared_ptr< Core::VKImage > MayaFlux::Portal::Graphics::TextureLoom::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.

Parameters
widthWidth in pixels
heightHeight in pixels
formatImage format
dataOptional initial pixel data (nullptr = empty)
mip_levelsNumber of mipmap levels (1 = no mipmaps)
Returns
Initialized VKImage ready for use

Creates device-local texture optimized for shader sampling. If data provided, uploads immediately and transitions to shader read layout.

Definition at line 81 of file TextureLoom.cpp.

84{
85 if (!is_initialized()) {
87 "TextureLoom not initialized");
88 return nullptr;
89 }
90
91 auto vk_format = to_vulkan_format(format);
92 auto image = std::make_shared<Core::VKImage>(
93 width, height, 1, vk_format,
96 mip_levels, 1,
98
100
101 if (!image->is_initialized()) {
103 "Failed to initialize VKImage");
104 return nullptr;
105 }
106
107 if (data) {
108 size_t data_size = calculate_image_size(width, height, 1, format);
109 upload_data(image, data, data_size);
110 } else {
112 image->get_image(),
113 vk::ImageLayout::eUndefined,
114 vk::ImageLayout::eShaderReadOnlyOptimal,
115 mip_levels, 1, vk::ImageAspectFlagBits::eColor);
116 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
117 }
118
119 m_textures.push_back(image);
121 "Created 2D texture: {}x{}, format: {}, mips: {}",
122 width, height, vk::to_string(vk_format), mip_levels);
123 return image;
124}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
uint32_t width
void initialize_image(const std::shared_ptr< VKImage > &image)
Initialize a VKImage (allocate VkImage, memory, and create image view)
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.
@ TEXTURE_2D
Sampled texture (shader read)
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.
void upload_data(const std::shared_ptr< Core::VKImage > &image, const void *data, size_t size)
Upload pixel data to an existing texture.
Core::BackendResourceManager * m_resource_manager
std::vector< std::shared_ptr< Core::VKImage > > m_textures
bool is_initialized() const
Check if manager is initialized.
@ ImageProcessing
Image processing tasks (filters, transformations)
@ Portal
High-level user-facing API layer.
@ IMAGE_COLOR
2D RGB/RGBA image

References calculate_image_size(), image, MayaFlux::Kakshya::IMAGE_COLOR, MayaFlux::Journal::ImageProcessing, MayaFlux::Core::BackendResourceManager::initialize_image(), is_initialized(), m_resource_manager, m_textures, MF_ERROR, MF_INFO, MayaFlux::Journal::Portal, MayaFlux::Core::VKImage::TEXTURE_2D, to_vulkan_format(), MayaFlux::Core::BackendResourceManager::transition_image_layout(), MayaFlux::Core::VKImage::TYPE_2D, upload_data(), and width.

Referenced by create_2d(), MayaFlux::Kakshya::WindowContainer::region_to_image(), and MayaFlux::Kakshya::WindowContainer::to_image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: