MayaFlux 1.0.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 96 of file TextureLoom.cpp.

99{
100 if (!is_initialized()) {
102 "TextureLoom not initialized");
103 return nullptr;
104 }
105
106 auto vk_format = to_vulkan_format(format);
107 auto image = std::make_shared<Core::VKImage>(
108 width, height, 1, vk_format,
111 mip_levels, 1,
113
115
116 if (!image->is_initialized()) {
118 "Failed to initialize VKImage");
119 return nullptr;
120 }
121
122 if (data) {
123 size_t data_size = calculate_image_size(width, height, 1, format);
124 upload_data(image, data, data_size);
125 } else {
127 image->get_image(),
128 vk::ImageLayout::eUndefined,
129 vk::ImageLayout::eShaderReadOnlyOptimal,
130 mip_levels, 1, vk::ImageAspectFlagBits::eColor);
131 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
132 }
133
134 m_textures.push_back(image);
136 "Created 2D texture: {}x{}, format: {}, mips: {}",
137 width, height, vk::to_string(vk_format), mip_levels);
138 return image;
139}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:47
bool format
uint32_t width
uint32_t height
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(), format, height, 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 acquire_cached_image(), MayaFlux::Kakshya::TextureCollection::append(), create_2d(), MayaFlux::Yantra::VisionAnalyzer::resolve_image(), and MayaFlux::Yantra::VisionExtractor::resolve_image().

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