MayaFlux 0.5.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 786 of file BackendWindowHandler.cpp.

787{
788 auto window = ctx.window;
789
790 if (!window || !window->get_state().is_visible || !window->get_rendering_buffers().empty()) {
791 return;
792 }
793
794 try {
795 auto device = m_context.get_device();
796
797 size_t frame_index = ctx.current_frame;
798 auto& in_flight = ctx.in_flight[frame_index];
799 auto& image_available = ctx.image_available[frame_index];
800 auto& render_finished = ctx.render_finished[frame_index];
801
802 auto cmd_buffer = ctx.clear_command_buffers[frame_index];
803 if (!cmd_buffer) {
805 "Clear command buffer not allocated for window '{}'",
806 window->get_create_info().title);
807 return;
808 }
809 cmd_buffer.reset({});
810
811 if (device.waitForFences(1, &in_flight, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout) {
812 return;
813 }
814
815 auto image_index_opt = ctx.swapchain->acquire_next_image(image_available);
816 if (!image_index_opt.has_value()) {
817 ctx.needs_recreation = true;
818 return;
819 }
820 ctx.current_image_index = image_index_opt.value();
821
822 if (device.resetFences(1, &in_flight) != vk::Result::eSuccess) {
823 return;
824 }
825
826 vk::CommandBufferBeginInfo begin_info {};
827 begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
828 cmd_buffer.begin(begin_info);
829
830 const auto& image_views = ctx.swapchain->get_image_views();
831 auto extent = ctx.swapchain->get_extent();
832
833 vk::RenderingAttachmentInfo color_attachment {};
834 color_attachment.imageView = image_views[ctx.current_image_index];
835 color_attachment.imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
836 color_attachment.loadOp = vk::AttachmentLoadOp::eClear;
837 color_attachment.storeOp = vk::AttachmentStoreOp::eStore;
838 color_attachment.clearValue.color = vk::ClearColorValue(
839 window->get_create_info().clear_color);
840
841 vk::RenderingInfo rendering_info {};
842 rendering_info.renderArea = vk::Rect2D { { 0, 0 }, extent };
843 rendering_info.layerCount = 1;
844 rendering_info.colorAttachmentCount = 1;
845 rendering_info.pColorAttachments = &color_attachment;
846
847 vk::ImageMemoryBarrier barrier {};
848 barrier.oldLayout = vk::ImageLayout::eUndefined;
849 barrier.newLayout = vk::ImageLayout::eColorAttachmentOptimal;
850 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
851 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
852 barrier.image = ctx.swapchain->get_images()[ctx.current_image_index];
853 barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
854 barrier.subresourceRange.levelCount = 1;
855 barrier.subresourceRange.layerCount = 1;
856 barrier.srcAccessMask = {};
857 barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
858
859 cmd_buffer.pipelineBarrier(
860 vk::PipelineStageFlagBits::eTopOfPipe,
861 vk::PipelineStageFlagBits::eColorAttachmentOutput,
862 {}, {}, {}, barrier);
863
864 cmd_buffer.beginRendering(rendering_info);
865 cmd_buffer.endRendering();
866
867 barrier.oldLayout = vk::ImageLayout::eColorAttachmentOptimal;
868 barrier.newLayout = vk::ImageLayout::ePresentSrcKHR;
869 barrier.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
870 barrier.dstAccessMask = {};
871
872 cmd_buffer.pipelineBarrier(
873 vk::PipelineStageFlagBits::eColorAttachmentOutput,
874 vk::PipelineStageFlagBits::eBottomOfPipe,
875 {}, {}, {}, barrier);
876
877 cmd_buffer.end();
878
879 submit_and_present(window, cmd_buffer);
880
881 ctx.current_frame = (ctx.current_frame + 1) % ctx.in_flight.size();
882
883 } catch (const std::exception& e) {
885 "Failed to render empty window '{}': {}",
886 window->get_create_info().title, e.what());
887 }
888}
#define MF_RT_ERROR(comp, ctx,...)
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, 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, and MayaFlux::Core::WindowRenderContext::window.