Vulkan: Use a generic class helper for all device objects

This greatly reduce the amount of code required for wrappers around
Vulkan Objects


Former-commit-id: 885d0b39197ba41fd856c45571dbf06d8ae27d8c
This commit is contained in:
Lynix
2016-05-14 14:46:15 +02:00
parent ef66c09719
commit a8fa5e1d12
6 changed files with 133 additions and 112 deletions

View File

@@ -12,55 +12,15 @@ namespace Nz
namespace Vk
{
inline Swapchain::Swapchain(Device& device) :
m_device(device),
m_swapchain(VK_NULL_HANDLE)
DeviceObject(device)
{
}
inline Swapchain::~Swapchain()
{
Destroy();
}
inline bool Swapchain::Create(const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_device.vkCreateSwapchainKHR(m_device, &createInfo, allocator, &m_swapchain);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan swapchain");
return false;
}
// Store the allocator to access them when needed
if (allocator)
m_allocator = *allocator;
else
m_allocator.pfnAllocation = nullptr;
return true;
}
inline void Swapchain::Destroy()
{
if (m_swapchain != VK_NULL_HANDLE)
m_device.vkDestroySwapchainKHR(m_device, m_swapchain, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
}
inline VkResult Swapchain::GetLastErrorCode() const
{
return m_lastErrorCode;
}
inline bool Swapchain::IsSupported() const
{
if (!m_device.IsExtensionLoaded("VK_KHR_swapchain"))
return false;
}
inline Swapchain::operator VkSwapchainKHR()
{
return m_swapchain;
}
}
}