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

◆ ensure_depth_image()

void MayaFlux::Core::BackendWindowHandler::ensure_depth_image ( WindowRenderContext ctx)
private

Ensure depth image exists at current swapchain extent.

Parameters
ctxWindow context to create depth image for

Creates or recreates a D32_SFLOAT depth image matching the swapchain extent. No-op if depth image already matches.

Definition at line 702 of file BackendWindowHandler.cpp.

703{
704 if (!ctx.swapchain) {
705 return;
706 }
707
708 auto extent = ctx.swapchain->get_extent();
709
710 if (ctx.depth_image && ctx.depth_image->is_initialized()
711 && ctx.depth_image->get_width() == extent.width
712 && ctx.depth_image->get_height() == extent.height) {
713 return;
714 }
715
716 auto device = m_context.get_device();
717
718 if (ctx.depth_image && ctx.depth_image->is_initialized()) {
719 device.waitIdle();
720 const auto& res = ctx.depth_image->get_image_resources();
721 if (res.image_view) {
722 device.destroyImageView(res.image_view);
723 }
724 if (res.memory) {
725 device.freeMemory(res.memory);
726 }
727 if (res.image) {
728 device.destroyImage(res.image);
729 }
730 ctx.depth_image.reset();
731 }
732
733 ctx.depth_image = std::make_shared<VKImage>(
734 extent.width, extent.height, 1,
735 vk::Format::eD32Sfloat,
738 1, 1,
740
741 m_resource_manager->initialize_image(ctx.depth_image);
742
743 if (!ctx.depth_image->is_initialized()) {
745 "Failed to create depth image for window '{}'",
746 ctx.window->get_create_info().title);
747 ctx.depth_image.reset();
748 return;
749 }
750
752 ctx.depth_image->get_image(),
753 vk::ImageLayout::eUndefined,
754 vk::ImageLayout::eDepthStencilAttachmentOptimal,
755 1, 1,
756 vk::ImageAspectFlagBits::eDepth);
757 ctx.depth_image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
758
760 "Created depth image for window '{}': {}x{}, D32_SFLOAT",
761 ctx.window->get_create_info().title,
762 extent.width, extent.height);
763}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
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.
vk::Device get_device() const
Get logical device.
Definition VKContext.hpp:49
@ DEPTH_STENCIL
Depth/stencil attachment.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
@ IMAGE_2D
2D image (grayscale or single channel)

References MayaFlux::Journal::Core, MayaFlux::Core::WindowRenderContext::depth_image, MayaFlux::Journal::GraphicsBackend, MayaFlux::Kakshya::IMAGE_2D, MF_ERROR, MF_INFO, MayaFlux::Core::WindowRenderContext::swapchain, and MayaFlux::Core::WindowRenderContext::window.

Referenced by setup_backend_service().

+ Here is the caller graph for this function: