BsVulkanSwapChain.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Vulkan
  8. * @{
  9. */
  10. #define BS_NUM_BACK_BUFFERS 1
  11. /** Description of a single swap chain surface. */
  12. struct SwapChainSurface
  13. {
  14. VkImage image;
  15. VkImageView view;
  16. VkSemaphore sync;
  17. bool acquired;
  18. };
  19. /** Vulkan swap chain containing two or more buffers for rendering and presenting onto the screen. */
  20. class VulkanSwapChain : INonCopyable
  21. {
  22. public:
  23. ~VulkanSwapChain();
  24. /** Rebuilds the swap chain with the provided properties. Destroys any previously existing swap chain. */
  25. void rebuild(const SPtr<VulkanDevice>& device, VkSurfaceKHR surface, UINT32 width, UINT32 height, bool vsync,
  26. VkFormat colorFormat, VkColorSpaceKHR colorSpace, bool createDepth, VkFormat depthFormat);
  27. /**
  28. * Returns the actual width of the swap chain, in pixels. This might differ from the requested size in case it
  29. * wasn't supported.
  30. */
  31. UINT32 getWidth() const { return mWidth; }
  32. /**
  33. * Returns the actual height of the swap chain, in pixels. This might differ from the requested size in case it
  34. * wasn't supported.
  35. */
  36. UINT32 getHeight() const { return mHeight; }
  37. /**
  38. * Presents the back buffer to the output device, swapping the buffers.
  39. *
  40. * @param[in] queue Queue on which to queue the present operation. Must support present operations.
  41. * @param[in] semaphore Optional semaphore to wait on before presenting the queue.
  42. */
  43. void present(VkQueue queue, VkSemaphore semaphore);
  44. /**
  45. * Returns the current back buffer image.
  46. *
  47. * @note Must only be called once in-between present() calls, or before the first present() call.
  48. */
  49. SwapChainSurface acquireBackBuffer();
  50. /** Returns an image view representing the depth-stencil buffer, if any. */
  51. VkImageView getDepthStencil() const { return mDepthStencilView; }
  52. private:
  53. /** Destroys current swap chain and depth stencil image (if any). */
  54. void clear(VkSwapchainKHR swapChain);
  55. SPtr<VulkanDevice> mDevice;
  56. VkSwapchainKHR mSwapChain = VK_NULL_HANDLE;
  57. UINT32 mWidth = 0;
  58. UINT32 mHeight = 0;
  59. Vector<SwapChainSurface> mSurfaces;
  60. VkImage mDepthStencilImage = VK_NULL_HANDLE;
  61. VkImageView mDepthStencilView = VK_NULL_HANDLE;
  62. VkDeviceMemory mDepthStencilMemory = nullptr;
  63. UINT32 mCurrentSemaphoreIdx = 0;
  64. UINT32 mCurrentBackBufferIdx = 0;
  65. };
  66. /** @} */
  67. }