// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Vulkan Renderer" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include namespace Nz { VulkanSurface::VulkanSurface() : m_surface(Vulkan::GetInstance()) { } bool VulkanSurface::Create(WindowHandle handle) { bool success = false; #if defined(NAZARA_PLATFORM_WINDOWS) { NazaraAssert(handle.type == WindowManager::Windows, "expected Windows window"); HWND winHandle = reinterpret_cast(handle.windows.window); HINSTANCE instance = reinterpret_cast(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE)); success = m_surface.Create(instance, winHandle); } #elif defined(NAZARA_PLATFORM_LINUX) { switch (handle.type) { #ifdef VK_USE_PLATFORM_WAYLAND_KHR case WindowManager::Wayland: { wl_display* display = static_cast(handle.wayland.display); wl_surface* surface = static_cast(handle.wayland.surface); success = m_surface.Create(display, surface); break; } #endif #ifdef VK_USE_PLATFORM_XLIB_KHR case WindowManager::X11: { Display* display = static_cast(handle.x11.display); ::Window window = static_cast<::Window>(handle.x11.window); success = m_surface.Create(display, window); break; } #endif default: { NazaraError("unhandled window type"); return false; } } } #else #error This OS is not supported by Vulkan #endif if (!success) { NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_surface.GetLastErrorCode())); return false; } return true; } void VulkanSurface::Destroy() { m_surface.Destroy(); } }