BsVulkanSwapChain.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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);
  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. private:
  51. SPtr<VulkanDevice> mDevice;
  52. VkSwapchainKHR mSwapChain = VK_NULL_HANDLE;
  53. UINT32 mWidth = 0;
  54. UINT32 mHeight = 0;
  55. Vector<SwapChainSurface> mSurfaces;
  56. UINT32 mCurrentSemaphoreIdx = 0;
  57. UINT32 mCurrentBackBufferIdx = 0;
  58. };
  59. /** @} */
  60. }