Vulkan: Add support for surfaces
Former-commit-id: c4599c430add1bc54e9665d5bb0e0ca5071bcf41
This commit is contained in:
166
include/Nazara/Vulkan/VkSurface.inl
Normal file
166
include/Nazara/Vulkan/VkSurface.inl
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
||||
#include <Nazara/Vulkan/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Surface::Surface(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_surface(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline Surface::~Surface()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkAndroidSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
inline bool Surface::Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMirSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXcbSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXlibSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWaylandSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
instance,
|
||||
handle
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void Surface::Destroy()
|
||||
{
|
||||
if (m_surface)
|
||||
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
}
|
||||
|
||||
inline bool Surface::IsSupported() const
|
||||
{
|
||||
if (!m_instance.IsExtensionLoaded("VK_KHR_surface"))
|
||||
return false;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_android_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_mir_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xcb_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xlib_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_wayland_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_win32_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Vulkan/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user