#include "VulkanWindow.h" VulkanWindow::VulkanWindow() { // setSurfaceType(QWindow::VulkanSurface); // if (!initVulkanInstance()) { // qCritical() << "Failed to initialize Vulkan instance!"; // exit(EXIT_FAILURE); // } createVulkanSurface(); } VulkanWindow::~VulkanWindow() { // cleanup(); } void VulkanWindow::createVulkanSurface() { VkSurfaceKHR surface; #ifdef Q_OS_LINUX VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; surfaceCreateInfo.connection = QX11Info::connection(); surfaceCreateInfo.window = static_cast(winId()); if (vkCreateXcbSurfaceKHR(_instance, &surfaceCreateInfo, nullptr, &surface) != VK_SUCCESS) { qCritical() << "Failed to create Vulkan surface on Linux."; exit(EXIT_FAILURE); } #elif Q_OS_ANDROID VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; surfaceCreateInfo.window = reinterpret_cast(winId()); if (vkCreateAndroidSurfaceKHR(_instance, &surfaceCreateInfo, nullptr, &surface) != VK_SUCCESS) { qCritical() << "Failed to create Vulkan surface on Android."; exit(EXIT_FAILURE); } #endif _surface = surface; qDebug() << "Vulkan surface created successfully."; } void VulkanWindow::cleanup() { if (_surface != VK_NULL_HANDLE) { vkDestroySurfaceKHR(_instance, _surface, nullptr); } }