Vulkan/Swapchain: Make swapchain create imageview
Former-commit-id: aba6fa6ca74eb1566d5203e12978c9be4731331e [formerly cb900a59afe3b8d9778a82b3302dc483b500083d] Former-commit-id: 5283d835a1560cbc6c5034563af262d8f33e6bfc
This commit is contained in:
parent
0702511108
commit
8bc7998b46
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
||||||
|
#include <Nazara/Vulkan/VkImageView.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +20,8 @@ namespace Nz
|
||||||
friend DeviceObject;
|
friend DeviceObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct Buffer;
|
||||||
|
|
||||||
Swapchain() = default;
|
Swapchain() = default;
|
||||||
Swapchain(const Swapchain&) = delete;
|
Swapchain(const Swapchain&) = delete;
|
||||||
Swapchain(Swapchain&&) = default;
|
Swapchain(Swapchain&&) = default;
|
||||||
|
|
@ -28,20 +31,26 @@ namespace Nz
|
||||||
|
|
||||||
inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||||
|
|
||||||
inline VkImage GetImage(UInt32 index) const;
|
inline const Buffer& GetBuffer(UInt32 index) const;
|
||||||
inline const std::vector<VkImage>& GetImages() const;
|
inline const std::vector<Buffer>& GetBuffers() const;
|
||||||
inline UInt32 GetImageCount() const;
|
inline UInt32 GetBufferCount() const;
|
||||||
|
|
||||||
inline bool IsSupported() const;
|
inline bool IsSupported() const;
|
||||||
|
|
||||||
Swapchain& operator=(const Swapchain&) = delete;
|
Swapchain& operator=(const Swapchain&) = delete;
|
||||||
Swapchain& operator=(Swapchain&&) = delete;
|
Swapchain& operator=(Swapchain&&) = delete;
|
||||||
|
|
||||||
private:
|
struct Buffer
|
||||||
static VkResult CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
{
|
||||||
static void DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
VkImage image;
|
||||||
|
ImageView view;
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<VkImage> m_images;
|
private:
|
||||||
|
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
||||||
|
static inline void DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
||||||
|
|
||||||
|
std::vector<Buffer> m_buffers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,30 +38,64 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_images.resize(imageCount);
|
std::vector<VkImage> images(imageCount);
|
||||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, m_images.data());
|
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data());
|
||||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||||
{
|
{
|
||||||
NazaraError("Failed to query swapchain images");
|
NazaraError("Failed to query swapchain images");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_buffers.resize(imageCount);
|
||||||
|
for (UInt32 i = 0; i < imageCount; ++i)
|
||||||
|
{
|
||||||
|
m_buffers[i].image = images[i];
|
||||||
|
|
||||||
|
VkImageViewCreateInfo imageViewCreateInfo = {
|
||||||
|
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
||||||
|
nullptr, // const void* pNext;
|
||||||
|
0, // VkImageViewCreateFlags flags;
|
||||||
|
m_buffers[i].image, // VkImage image;
|
||||||
|
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
|
||||||
|
createInfo.imageFormat, // VkFormat format;
|
||||||
|
{ // VkComponentMapping components;
|
||||||
|
VK_COMPONENT_SWIZZLE_R, // VkComponentSwizzle .r;
|
||||||
|
VK_COMPONENT_SWIZZLE_G, // VkComponentSwizzle .g;
|
||||||
|
VK_COMPONENT_SWIZZLE_B, // VkComponentSwizzle .b;
|
||||||
|
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
||||||
|
},
|
||||||
|
{ // VkImageSubresourceRange subresourceRange;
|
||||||
|
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags .aspectMask;
|
||||||
|
0, // uint32_t .baseMipLevel;
|
||||||
|
1, // uint32_t .levelCount;
|
||||||
|
0, // uint32_t .baseArrayLayer;
|
||||||
|
1 // uint32_t .layerCount;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!m_buffers[i].view.Create(m_device, imageViewCreateInfo))
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create image view for image #" + String::Number(i));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VkImage Swapchain::GetImage(UInt32 index) const
|
inline const Swapchain::Buffer& Swapchain::GetBuffer(UInt32 index) const
|
||||||
{
|
{
|
||||||
return m_images[index];
|
return m_buffers[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::vector<VkImage>& Swapchain::GetImages() const
|
inline const std::vector<Swapchain::Buffer>& Swapchain::GetBuffers() const
|
||||||
{
|
{
|
||||||
return m_images;
|
return m_buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UInt32 Swapchain::GetImageCount() const
|
inline UInt32 Swapchain::GetBufferCount() const
|
||||||
{
|
{
|
||||||
return static_cast<UInt32>(m_images.size());
|
return static_cast<UInt32>(m_buffers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Swapchain::IsSupported() const
|
inline bool Swapchain::IsSupported() const
|
||||||
|
|
@ -72,12 +106,12 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
inline VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||||
{
|
{
|
||||||
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
inline void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||||
{
|
{
|
||||||
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue