Vulkan/Swapchain: Wrap images creation/getters

Former-commit-id: 50e5890c7aeb16408a460e6734301c6393c435e5
This commit is contained in:
Lynix 2016-05-19 09:07:31 +02:00
parent 42fba6eee4
commit 602c39e8ba
2 changed files with 63 additions and 0 deletions

View File

@ -24,6 +24,14 @@ namespace Nz
Swapchain(Swapchain&&) = default; Swapchain(Swapchain&&) = default;
~Swapchain() = default; ~Swapchain() = default;
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex);
inline bool Create(const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline VkImage GetImage(UInt32 index) const;
inline const std::vector<VkImage>& GetImages() const;
inline UInt32 GetImageCount() const;
inline bool IsSupported() const; inline bool IsSupported() const;
Swapchain& operator=(const Swapchain&) = delete; Swapchain& operator=(const Swapchain&) = delete;
@ -32,6 +40,8 @@ namespace Nz
private: private:
static VkResult CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle); static VkResult CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
static void DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator); static void DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
std::vector<VkImage> m_images;
}; };
} }
} }

View File

@ -16,6 +16,59 @@ namespace Nz
{ {
} }
inline bool Swapchain::AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex)
{
m_lastErrorCode = m_device.vkAcquireNextImageKHR(m_device, m_handle, timeout, semaphore, fence, imageIndex);
switch (m_lastErrorCode)
{
case VkResult::VK_SUBOPTIMAL_KHR:
case VkResult::VK_SUCCESS:
return true;
default:
return false;
}
}
inline bool Swapchain::Create(const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
if (!DeviceObject::Create(createInfo, allocator))
return false;
UInt32 imageCount = 0;
m_lastErrorCode = m_device.vkGetSwapchainImagesKHR(m_device, m_handle, &imageCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0)
{
NazaraError("Failed to query swapchain image count");
return false;
}
m_images.resize(imageCount);
m_lastErrorCode = m_device.vkGetSwapchainImagesKHR(m_device, m_handle, &imageCount, m_images.data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query swapchain images");
return false;
}
return true;
}
inline VkImage Swapchain::GetImage(UInt32 index) const
{
return m_images[index];
}
inline const std::vector<VkImage>& Swapchain::GetImages() const
{
return m_images;
}
inline UInt32 Swapchain::GetImageCount() const
{
return m_images.size();
}
inline bool Swapchain::IsSupported() const inline bool Swapchain::IsSupported() const
{ {
if (!m_device.IsExtensionLoaded("VK_KHR_swapchain")) if (!m_device.IsExtensionLoaded("VK_KHR_swapchain"))