#include "VulkanWindow.h" VulkanWindow::VulkanWindow() { // setSurfaceType(QWindow::VulkanSurface); // if (!initVulkanInstance()) { // qCritical() << "Failed to initialize Vulkan instance!"; // exit(EXIT_FAILURE); // } // createVulkanSurface(); } VulkanWindow::~VulkanWindow() { // cleanup(); } VkSurfaceKHR VulkanWindow::createVulkanSurface(VkInstance instance, VkSurfaceKHR& surface) { #if defined(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); } #elif defined(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); } #endif _surface = surface; qDebug() << "Vulkan surface created successfully."; return _surface; } void VulkanWindow::getWindowSize(int &width, int &height) { width = this->width(); height = this->height(); } void VulkanWindow::cleanup() { if (_surface != VK_NULL_HANDLE) { vkDestroySurfaceKHR(_instance, _surface, nullptr); } }