zdray/thirdparty/ZVulkan/include/zvulkan/vulkanswapchain.h

62 lines
1.9 KiB
C
Raw Permalink Normal View History

2022-11-07 20:36:27 +00:00
#pragma once
#include "vulkandevice.h"
#include "vulkanobjects.h"
2022-11-07 20:36:27 +00:00
class VulkanSemaphore;
class VulkanFence;
class VulkanSurfaceCapabilities
{
public:
VkSurfaceCapabilitiesKHR Capabilites = { };
#ifdef WIN32
VkSurfaceCapabilitiesFullScreenExclusiveEXT FullScreenExclusive = { VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_FULL_SCREEN_EXCLUSIVE_EXT };
#else
struct { void* pNext = nullptr; VkBool32 fullScreenExclusiveSupported = 0; } FullScreenExclusive;
#endif
std::vector<VkPresentModeKHR> PresentModes;
std::vector<VkSurfaceFormatKHR> Formats;
};
2022-11-07 20:36:27 +00:00
class VulkanSwapChain
{
public:
VulkanSwapChain(VulkanDevice* device);
2022-11-07 20:36:27 +00:00
~VulkanSwapChain();
void Create(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen);
bool Lost() const { return lost; }
2022-11-07 20:36:27 +00:00
int Width() const { return actualExtent.width; }
int Height() const { return actualExtent.height; }
VkSurfaceFormatKHR Format() const { return format; }
2022-11-07 20:36:27 +00:00
int ImageCount() const { return (int)images.size(); }
VulkanImage* GetImage(int index) { return images[index].get(); }
VulkanImageView* GetImageView(int index) { return views[index].get(); }
2022-11-07 20:36:27 +00:00
int AcquireImage(VulkanSemaphore* semaphore = nullptr, VulkanFence* fence = nullptr);
void QueuePresent(int imageIndex, VulkanSemaphore* semaphore = nullptr);
2022-11-07 20:36:27 +00:00
private:
void SelectFormat(const VulkanSurfaceCapabilities& caps, bool hdr);
bool CreateSwapchain(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen);
VulkanSurfaceCapabilities GetSurfaceCapabilities(bool exclusivefullscreen);
VulkanDevice* device = nullptr;
bool lost = true;
VkExtent2D actualExtent = {};
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
VkSurfaceFormatKHR format = {};
VkPresentModeKHR presentMode;
std::vector<std::unique_ptr<VulkanImage>> images;
std::vector<std::unique_ptr<VulkanImageView>> views;
VulkanSwapChain(const VulkanSwapChain&) = delete;
VulkanSwapChain& operator=(const VulkanSwapChain&) = delete;
2022-11-07 20:36:27 +00:00
};