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

◆ render_empty_window()

void MayaFlux::Core::BackendWindowHandler::render_empty_window ( WindowRenderContext &  ctx)
private

Render empty windows with clear color.

Parameters
ctxWindow render context

For windows that are registered for processing but have no buffers attached, this performs a minimal clear pass so the window is visible and responsive to input events.

Definition at line 807 of file BackendWindowHandler.cpp.

808{
809 auto window = ctx.window;
810
811 if (!window || !window->get_state().is_visible || !window->get_rendering_buffers().empty()) {
812 return;
813 }
814
815 try {
816 auto device = m_context.get_device();
817
818 size_t frame_index = ctx.current_frame;
819 auto& in_flight = ctx.in_flight[frame_index];
820 auto& image_available = ctx.image_available[frame_index];
821 auto& render_finished = ctx.render_finished[frame_index];
822
823 auto cmd_buffer = ctx.clear_command_buffers[frame_index];
824 if (!cmd_buffer) {
826 "Clear command buffer not allocated for window '{}'",
827 window->get_create_info().title);
828 return;
829 }
830
831 if (device.waitForFences(1, &in_flight, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout) {
832 return;
833 }
834 cmd_buffer.reset({});
835
836 auto image_index_opt = ctx.swapchain->acquire_next_image(image_available);
837 if (!image_index_opt.has_value()) {
838 ctx.needs_recreation = true;
839 return;
840 }
841 ctx.current_image_index = image_index_opt.value();
842
843 if (device.resetFences(1, &in_flight) != vk::Result::eSuccess) {
844 return;
845 }
846
847 vk::CommandBufferBeginInfo begin_info {};
848 begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
849 cmd_buffer.begin(begin_info);
850
851 const auto& image_views = ctx.swapchain->get_image_views();
852 auto extent = ctx.swapchain->get_extent();
853
854 vk::RenderingAttachmentInfo color_attachment {};
855 color_attachment.imageView = image_views[ctx.current_image_index];
856 color_attachment.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
857 color_attachment.loadOp = vk::AttachmentLoadOp::eClear;
858 color_attachment.storeOp = vk::AttachmentStoreOp::eStore;
859 color_attachment.clearValue.color = vk::ClearColorValue(
860 window->get_create_info().clear_color);
861
862 vk::RenderingInfo rendering_info {};
863 rendering_info.renderArea = vk::Rect2D { { 0, 0 }, extent };
864 rendering_info.layerCount = 1;
865 rendering_info.colorAttachmentCount = 1;
866 rendering_info.pColorAttachments = &color_attachment;
867
868 vk::ImageMemoryBarrier barrier {};
869 barrier.oldLayout = vk::ImageLayout::eUndefined;
870 barrier.newLayout = vk::ImageLayout::eColorAttachmentOptimal;
871 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
872 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
873 barrier.image = ctx.swapchain->get_images()[ctx.current_image_index];
874 barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
875 barrier.subresourceRange.levelCount = 1;
876 barrier.subresourceRange.layerCount = 1;
877 barrier.srcAccessMask = {};
878 barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
879
880 cmd_buffer.pipelineBarrier(
881 vk::PipelineStageFlagBits::eTopOfPipe,
882 vk::PipelineStageFlagBits::eColorAttachmentOutput,
883 {}, {}, {}, barrier);
884
885 cmd_buffer.beginRendering(rendering_info);
886 cmd_buffer.endRendering();
887
888 barrier.oldLayout = vk::ImageLayout::eColorAttachmentOptimal;
889 barrier.newLayout = vk::ImageLayout::ePresentSrcKHR;
890 barrier.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
891 barrier.dstAccessMask = {};
892
893 cmd_buffer.pipelineBarrier(
894 vk::PipelineStageFlagBits::eColorAttachmentOutput,
895 vk::PipelineStageFlagBits::eBottomOfPipe,
896 {}, {}, {}, barrier);
897
898 cmd_buffer.end();
899
900 submit_and_present(window, cmd_buffer);
901
902 ctx.current_frame = (ctx.current_frame + 1) % ctx.in_flight.size();
903
904 } catch (const std::exception& e) {
906 "Failed to render empty window '{}': {}",
907 window->get_create_info().title, e.what());
908 }
909}
#define MF_RT_ERROR(comp, ctx,...)
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
vk::PhysicalDevice device
Definition VKDevice.cpp:121
void submit_and_present(const std::shared_ptr< Window > &window, const vk::CommandBuffer &command_buffer)
vk::Device get_device() const
Get logical device.
Definition VKContext.hpp:49
@ GraphicsCallback
Graphics/visual rendering callback - frame-rate real-time.
@ Core
Core engine, backend, subsystems.

References MayaFlux::Core::WindowRenderContext::clear_command_buffers, MayaFlux::Journal::Core, MayaFlux::Core::WindowRenderContext::current_frame, MayaFlux::Core::WindowRenderContext::current_image_index, device, MayaFlux::Journal::GraphicsCallback, MayaFlux::Core::WindowRenderContext::image_available, MayaFlux::Core::WindowRenderContext::in_flight, MF_RT_ERROR, MayaFlux::Core::WindowRenderContext::needs_recreation, MayaFlux::Core::WindowRenderContext::render_finished, MayaFlux::Core::WindowRenderContext::swapchain, MayaFlux::Core::WindowRenderContext::window, and window.