You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
#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<unsigned int>(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<ANativeWindow*>(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);
|
|
}
|
|
}
|
|
|