MayaFlux 1.0.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 723 of file BackendWindowHandler.cpp.

724{
725 if (!ctx.swapchain) {
726 return;
727 }
728
729 auto extent = ctx.swapchain->get_extent();
730
731 if (ctx.depth_image && ctx.depth_image->is_initialized()
732 && ctx.depth_image->get_width() == extent.width
733 && ctx.depth_image->get_height() == extent.height) {
734 return;
735 }
736
737 auto device = m_context.get_device();
738
739 if (ctx.depth_image && ctx.depth_image->is_initialized()) {
740 device.waitIdle();
741 const auto& res = ctx.depth_image->get_image_resources();
742 if (res.image_view) {
743 device.destroyImageView(res.image_view);
744 }
745 if (res.memory) {
746 device.freeMemory(res.memory);
747 }
748 if (res.image) {
749 device.destroyImage(res.image);
750 }
751 ctx.depth_image.reset();
752 }
753
754 ctx.depth_image = std::make_shared<VKImage>(
755 extent.width, extent.height, 1,
756 vk::Format::eD32Sfloat,
759 1, 1,
761
762 m_resource_manager->initialize_image(ctx.depth_image);
763
764 if (!ctx.depth_image->is_initialized()) {
766 "Failed to create depth image for window '{}'",
767 ctx.window->get_create_info().title);
768 ctx.depth_image.reset();
769 return;
770 }
771
773 ctx.depth_image->get_image(),
774 vk::ImageLayout::eUndefined,
775 vk::ImageLayout::eDepthStencilAttachmentOptimal,
776 1, 1,
777 vk::ImageAspectFlagBits::eDepth);
778 ctx.depth_image->set_current_layout(vk::ImageLayout::eDepthStencilAttachmentOptimal);
779
781 "Created depth image for window '{}': {}x{}, D32_SFLOAT",
782 ctx.window->get_create_info().title,
783 extent.width, extent.height);
784}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
vk::PhysicalDevice device
Definition VKDevice.cpp:121
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, device, 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: