25 MANDRILL_API
Swapchain(ptr<Device> pDevice, uint32_t framesInFlight = 2);
48 MANDRILL_API
void present(VkCommandBuffer cmd, ptr<Image> pImage);
78 return mImages[mImageIndex];
85 MANDRILL_API
const std::vector<VkImage>&
getImages()
const
96 return mImageViews[mImageIndex];
115 return mDescriptorSets[mImageIndex];
151 return mInFlightIndex;
161 return mPreviousInFlightIndex;
170 return static_cast<uint32_t
>(mInFlightFences.size());
184 void createSwapchain();
185 void destroySwapchain();
186 void createSyncObjects(uint32_t framesInFlight);
187 void destroySyncObjects();
188 void createDescriptor();
189 void destroyDescriptor();
191 ptr<Device> mpDevice;
193 VkSwapchainKHR mSwapchain;
194 VkFormat mImageFormat;
197 std::vector<VkImage> mImages;
198 std::vector<VkImageView> mImageViews;
201 VkSurfaceCapabilitiesKHR capabilities{};
202 std::vector<VkSurfaceFormatKHR> formats;
203 std::vector<VkPresentModeKHR> presentModes;
206 std::vector<VkCommandBuffer> mCommandBuffers;
208 std::vector<VkSemaphore> mRenderFinishedSemaphores;
209 std::vector<VkSemaphore> mPresentFinishedSemaphores;
210 std::vector<VkFence> mInFlightFences;
212 uint32_t mInFlightIndex = 0;
213 uint32_t mPreviousInFlightIndex = 0;
214 uint32_t mImageIndex = 0;
216 VkDescriptorSetLayout mDescriptorSetLayout;
217 VkDescriptorPool mDescriptorPool;
218 std::vector<VkDescriptorSet> mDescriptorSets;
220 bool mRecreated =
false;
222 enum class ScreenshotState {
230 ScreenshotState mScreenshotState = ScreenshotState::Idle;
231 ptr<Image> mScreenshotStageImage;
232 std::mutex mScreenshotMutex;
233 std::condition_variable mScreenshotAvailableCV;
234 uint32_t mScreenshotInFlightIndex;
Swapchain class for managing the swapchain and its images.
Definition Swapchain.h:16
MANDRILL_API VkImageView getImageView() const
Get the current swapchain image view.
Definition Swapchain.h:94
MANDRILL_API VkDescriptorSet getImageDescriptorSet() const
Get the descriptor set of the current swapchain image. Useful if using the swapchain image as a stora...
Definition Swapchain.h:113
MANDRILL_API void present(VkCommandBuffer cmd, ptr< Image > pImage)
Present a rendered image to the swapchain image.
Definition Swapchain.cpp:163
MANDRILL_API void requestScreenshot()
Request a screenshot from the next rendered frame. This call must be paired with a call to waitForScr...
Definition Swapchain.cpp:263
MANDRILL_API VkExtent2D getExtent() const
Get the extent (resolution) of the swapchain.
Definition Swapchain.h:131
MANDRILL_API void recreate()
Recreate the swapchain, for instance if window size changed.
Definition Swapchain.cpp:92
MANDRILL_API VkSwapchainKHR getSwapchain() const
Get the swapchain handle.
Definition Swapchain.h:67
MANDRILL_API std::vector< uint8_t > waitForScreenshot()
Wait for screenshot to be available and acquire it. Only call this after a call to requestScreenshot(...
Definition Swapchain.cpp:270
MANDRILL_API bool recreated() const
Check if the swapchain was recreated during the last frame. This is reset in present().
Definition Swapchain.h:177
MANDRILL_API ~Swapchain()
Destructor for swapchain.
Definition Swapchain.cpp:85
MANDRILL_API const std::vector< VkImageView > & getImageViews() const
Get all the swapchain image views.
Definition Swapchain.h:103
MANDRILL_API const std::vector< VkImage > & getImages() const
Get all the swapchain images.
Definition Swapchain.h:85
MANDRILL_API uint32_t getPreviousInFlightIndex() const
Get the index of the previous frame that was in flight. This is useful when indexing after calling pr...
Definition Swapchain.h:159
MANDRILL_API VkImage getImage() const
Get the current swapchain image.
Definition Swapchain.h:76
MANDRILL_API uint32_t getInFlightIndex() const
Get the current frame in flight index.
Definition Swapchain.h:149
MANDRILL_API VkFormat getImageFormat() const
Get the image format of the swapchain.
Definition Swapchain.h:122
MANDRILL_API VkCommandBuffer acquireNextImage()
Acquire the next image in the swapchain to render to.
Definition Swapchain.cpp:116
MANDRILL_API uint32_t getImageIndex() const
Get the current image index.
Definition Swapchain.h:140
MANDRILL_API uint32_t getFramesInFlightCount() const
Get the count of the total number of frames in flight.
Definition Swapchain.h:168