59{
60 display_service->submit_and_present = [this](
61 const std::shared_ptr<void>& window_ptr,
62 uint64_t primary_cmd_bits) {
63 auto window = std::static_pointer_cast<Window>(window_ptr);
64 vk::CommandBuffer primary_cmd = *reinterpret_cast<vk::CommandBuffer*>(&primary_cmd_bits);
65
67 };
68
69 display_service->wait_idle = [this]() {
71 };
72
73 display_service->resize_surface = [this](const std::shared_ptr<void>& window_ptr, uint32_t width, uint32_t height) {
74 auto window = std::static_pointer_cast<Window>(window_ptr);
75 window->set_size(width, height);
77 if (ctx.window == window) {
78 ctx.needs_recreation = true;
79 break;
80 }
81 }
82 };
83
84 display_service->get_swapchain_image_count = [this](const std::shared_ptr<void>& window_ptr) -> uint32_t {
85 auto window = std::static_pointer_cast<Window>(window_ptr);
87 if (ctx.window == window) {
88 return static_cast<uint32_t>(ctx.swapchain->get_image_count());
89 }
90 }
91 return 0;
92 };
93
94 display_service->get_swapchain_format = [this](const std::shared_ptr<void>& window_ptr) -> uint32_t {
95 auto window = std::static_pointer_cast<Window>(window_ptr);
97 if (ctx.window == window) {
98 return static_cast<int>(ctx.swapchain->get_image_format());
99 }
100 }
101 return 0;
102 };
103
104 display_service->get_swapchain_extent = [this](
105 const std::shared_ptr<void>& window_ptr,
106 uint32_t& out_width,
107 uint32_t& out_height) {
108 auto window = std::static_pointer_cast<Window>(window_ptr);
110
111 if (context && context->swapchain) {
112 auto extent = context->swapchain->get_extent();
113 out_width = extent.width;
114 out_height = extent.height;
115 } else {
116 out_width = 0;
117 out_height = 0;
118 }
119 };
120
121 display_service->acquire_next_swapchain_image = [this](const std::shared_ptr<void>& window_ptr) -> uint64_t {
122 auto window = std::static_pointer_cast<Window>(window_ptr);
124 if (!ctx) {
126 "Window '{}' not registered for swapchain acquisition",
127 window->get_create_info().title);
128 return 0;
129 }
130
132 size_t frame_index = ctx->current_frame;
133 auto& in_flight = ctx->in_flight[frame_index];
134 auto& image_available = ctx->image_available[frame_index];
135
136 if (device.waitForFences(1, &in_flight, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout) {
138 "Fence timeout during swapchain acquisition for window '{}'",
139 window->get_create_info().title);
140 return 0;
141 }
142
143 auto image_index_opt = ctx->swapchain->acquire_next_image(image_available);
144 if (!image_index_opt.has_value()) {
145 ctx->needs_recreation = true;
146 return 0;
147 }
148
149 ctx->current_image_index = image_index_opt.value();
150
151 if (device.resetFences(1, &in_flight) != vk::Result::eSuccess) {
153 "Failed to reset fence for window '{}'",
154 window->get_create_info().title);
155 return 0;
156 }
157
158 const auto& images = ctx->swapchain->get_images();
159 VkImage raw = images[ctx->current_image_index];
160 return reinterpret_cast<uint64_t>(raw);
161 };
162
163 display_service->get_current_image_view = [this](const std::shared_ptr<void>& window_ptr) -> void* {
164 auto window = std::static_pointer_cast<Window>(window_ptr);
166
167 if (!context || !context->swapchain) {
168 return nullptr;
169 }
170
171 const auto& image_views = context->swapchain->get_image_views();
172 if (context->current_image_index >= image_views.size()) {
174 "Invalid current_image_index {} for window '{}' (swapchain has {} images)",
175 context->current_image_index,
176 window->get_create_info().title,
177 image_views.size());
178 return nullptr;
179 }
180
181 static thread_local vk::ImageView view;
182 view = image_views[context->current_image_index];
183 return static_cast<void*>(&view);
184 };
185}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::vector< WindowRenderContext > m_window_contexts
void submit_and_present(const std::shared_ptr< Window > &window, const vk::CommandBuffer &command_buffer)
WindowRenderContext * find_window_context(const std::shared_ptr< Window > &window)
vk::Device get_device() const
Get logical device.
@ GraphicsCallback
Graphics/visual rendering callback - frame-rate real-time.
@ Core
Core engine, backend, subsystems.