Create surface from window's native handles.
74{
75 if (!window) {
77 "Cannot create surface: null window");
78 return nullptr;
79 }
80
81#if defined(GLFW_BACKEND)
82 auto* glfw_window = dynamic_cast<GlfwWindow*>(window.get());
83 if (!glfw_window) {
85 "Cannot create surface: window is not a GlfwWindow");
86 return nullptr;
87 }
88
89 GLFWwindow* glfw_handle = glfw_window->get_glfw_handle();
90 if (!glfw_handle) {
92 "Cannot create surface: null GLFW handle");
93 return nullptr;
94 }
95
96 VkSurfaceKHR c_surface {};
98 return glfwCreateWindowSurface(
100 glfw_handle,
101 nullptr,
102 &c_surface);
103 });
104
105 if (result != VK_SUCCESS) {
107 "Failed to create GLFW window surface for window '{}'",
108 window->get_create_info().title);
109 return nullptr;
110 }
111
112 vk::SurfaceKHR surface(c_surface);
114
116 "Surface created for window '{}'", window->get_create_info().title);
117
118 return surface;
119
120#elif defined(WIN32_BACKEND)
122 auto hwnd = static_cast<HWND>(window->get_native_handle());
123 if (!hwnd) {
125 "Cannot create surface: null HWND");
126 return nullptr;
127 }
128
129 VkWin32SurfaceCreateInfoKHR info {};
130 info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
131 info.hinstance = GetModuleHandleW(nullptr);
132 info.hwnd = hwnd;
133
134 VkSurfaceKHR c_surface {};
135 if (vkCreateWin32SurfaceKHR(
137 &info, nullptr, &c_surface)
138 != VK_SUCCESS) {
140 "Failed to create Win32 Vulkan surface for window '{}'",
141 window->get_create_info().title);
142 return nullptr;
143 }
144
145 vk::SurfaceKHR surface(c_surface);
148 "Win32 surface created for window '{}'", window->get_create_info().title);
149 return surface;
150 }
151#elif defined(WAYLAND_BACKEND)
152 {
153 auto* wl_display = static_cast<struct wl_display*>(window->get_native_display());
154 auto* wl_surface = static_cast<struct wl_surface*>(window->get_native_handle());
155 if (!wl_display || !wl_surface) {
157 "Cannot create surface: null Wayland display or surface handle");
158 return nullptr;
159 }
160
161 VkWaylandSurfaceCreateInfoKHR info {};
162 info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
163 info.display = wl_display;
164 info.surface = wl_surface;
165
166 VkSurfaceKHR c_surface {};
167 if (vkCreateWaylandSurfaceKHR(
169 &info, nullptr, &c_surface)
170 != VK_SUCCESS) {
172 "Failed to create Wayland Vulkan surface for window '{}'",
173 window->get_create_info().title);
174 return nullptr;
175 }
176
177 vk::SurfaceKHR surface(c_surface);
180 "Wayland surface created for window '{}'", window->get_create_info().title);
181 return surface;
182 }
183#endif
184
186 "No windowing backend available for surface creation");
187 return nullptr;
188}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::vector< vk::SurfaceKHR > m_surfaces
GlobalGraphicsConfig m_graphics_config
vk::Instance get_instance() const
Get the Vulkan instance handle.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
auto dispatch_main_sync(Func &&func, Args &&... args) -> decltype(auto)
WindowingBackend windowing_backend
Selected windowing backend.