BsVulkanSwapChain.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /** Description of a single swap chain surface. */
  11. struct SwapChainSurface
  12. {
  13. VkImage image;
  14. VkImageView view;
  15. VkSemaphore sync;
  16. bool acquired;
  17. };
  18. /** Vulkan swap chain containing two or more buffers for rendering and presenting onto the screen. */
  19. class VulkanSwapChain : INonCopyable
  20. {
  21. public:
  22. ~VulkanSwapChain();
  23. /**
  24. * Rebuilds the swap chain with the provided properties. Destroys any previously existing swap chain. Caller must
  25. * ensure the swap chain is not used at the device when this is called.
  26. */
  27. void rebuild(const SPtr<VulkanDevice>& device, VkSurfaceKHR surface, UINT32 width, UINT32 height, bool vsync,
  28. VkFormat colorFormat, VkColorSpaceKHR colorSpace, bool createDepth, VkFormat depthFormat);
  29. /**
  30. * Returns the actual width of the swap chain, in pixels. This might differ from the requested size in case it
  31. * wasn't supported.
  32. */
  33. UINT32 getWidth() const { return mWidth; }
  34. /**
  35. * Returns the actual height of the swap chain, in pixels. This might differ from the requested size in case it
  36. * wasn't supported.
  37. */
  38. UINT32 getHeight() const { return mHeight; }
  39. /**
  40. * Presents the back buffer to the output device, swapping the buffers.
  41. *
  42. * @param[in] queue Queue on which to queue the present operation. Must support present operations.
  43. * @param[in] semaphore Optional semaphore to wait on before presenting the queue.
  44. */
  45. void present(VkQueue queue, VkSemaphore semaphore);
  46. /**
  47. * Returns the current back buffer image.
  48. *
  49. * @note Must only be called once in-between present() calls, or before the first present() call.
  50. */
  51. SwapChainSurface acquireBackBuffer();
  52. /** Returns the number of available color surfaces. */
  53. UINT32 getNumColorSurfaces() const { return (UINT32)mSurfaces.size(); }
  54. /** Returns an image view representing the color surface at the specified index. */
  55. VkImageView getColorView(UINT32 index) const { return mSurfaces[index].view; }
  56. /** Returns an image view representing the depth-stencil buffer, if any. */
  57. VkImageView getDepthStencilView() const { return mDepthStencilView; }
  58. private:
  59. /** Destroys current swap chain and depth stencil image (if any). */
  60. void clear(VkSwapchainKHR swapChain);
  61. SPtr<VulkanDevice> mDevice;
  62. VkSwapchainKHR mSwapChain = VK_NULL_HANDLE;
  63. UINT32 mWidth = 0;
  64. UINT32 mHeight = 0;
  65. Vector<SwapChainSurface> mSurfaces;
  66. VkImage mDepthStencilImage = VK_NULL_HANDLE;
  67. VkImageView mDepthStencilView = VK_NULL_HANDLE;
  68. VkDeviceMemory mDepthStencilMemory = nullptr;
  69. UINT32 mCurrentSemaphoreIdx = 0;
  70. UINT32 mCurrentBackBufferIdx = 0;
  71. };
  72. /** @} */
  73. }