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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user