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

◆ create_2d_array()

std::shared_ptr< Core::VKImage > MayaFlux::Portal::Graphics::TextureLoom::create_2d_array ( uint32_t  width,
uint32_t  height,
uint32_t  layers,
ImageFormat  format = ImageFormat::RGBA8,
const void *  data = nullptr 
)

Create a 2D texture array.

All layers share the same width, height, and format. The image view type is VK_IMAGE_VIEW_TYPE_2D_ARRAY, making it bindable as sampler2DArray in GLSL.

Parameters
widthWidth in pixels per layer.
heightHeight in pixels per layer.
layersNumber of array layers. Must be > 0.
formatImage format (default RGBA8).
dataOptional pixel data for all layers concatenated in order (layer 0 first). Must be exactly width * height * bpp(format) * layers bytes when non-null. Pass nullptr to allocate without uploading; the image is transitioned to eShaderReadOnlyOptimal.
Returns
Initialised VKImage with array_layers == layers, or nullptr on failure.

Definition at line 213 of file TextureLoom.cpp.

216{
217 if (!is_initialized()) {
219 "TextureLoom not initialized");
220 return nullptr;
221 }
222
223 if (layers == 0) {
225 "create_2d_array: layers must be > 0");
226 return nullptr;
227 }
228
229 auto vk_format = to_vulkan_format(format);
230 auto image = std::make_shared<Core::VKImage>(
231 width, height, 1, vk_format,
234 1, layers,
236
238
239 if (!image->is_initialized()) {
241 "create_2d_array: failed to initialize VKImage ({}x{} layers={})",
242 width, height, layers);
243 return nullptr;
244 }
245
246 if (data) {
247 const size_t total = calculate_image_size(width, height, 1, format) * layers;
248 upload_data(image, data, total);
249 } else {
251 image->get_image(),
252 vk::ImageLayout::eUndefined,
253 vk::ImageLayout::eShaderReadOnlyOptimal,
254 1, layers, vk::ImageAspectFlagBits::eColor);
255 image->set_current_layout(vk::ImageLayout::eShaderReadOnlyOptimal);
256 }
257
258 m_textures.push_back(image);
260 "Created 2D array texture: {}x{} layers={} format={}",
261 width, height, layers, vk::to_string(vk_format));
262 return image;
263}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:64
uint32_t width
Definition Decoder.cpp:66
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(), 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.

+ Here is the call graph for this function: