BsVulkanFramebuffer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include "BsVulkanResource.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. /** Represents a single attachment in a Vulkan frame-buffer. */
  12. struct VULKAN_ATTACHMENT_DESC
  13. {
  14. /** View of the image to attach or VK_NULL_HANDLE if none. */
  15. VkImageView view;
  16. /** Format of the attached image. */
  17. VkFormat format;
  18. /** Initial layer of the surface as pointed to by the provided image view. */
  19. UINT32 baseLayer;
  20. };
  21. /** Contains parameters used for initializing VulkanFrameBuffer object. */
  22. struct VULKAN_FRAMEBUFFER_DESC
  23. {
  24. /** Images describing the color attachments. */
  25. VULKAN_ATTACHMENT_DESC color[BS_MAX_MULTIPLE_RENDER_TARGETS];
  26. /** Image describing the depth attachment. */
  27. VULKAN_ATTACHMENT_DESC depth;
  28. /** Width of the images, in pixels. All images must be the same size. */
  29. UINT32 width;
  30. /** Height of the images, in pixels. All images must be the same size. */
  31. UINT32 height;
  32. /** Number of image layers to render to. This value is used for all provided surfaces. */
  33. UINT32 layers;
  34. /** Number of samples in the attached images. All attachments must have the same number of samples. */
  35. UINT32 numSamples;
  36. /** Set to true if framebuffer represents an offscreen surface that will not be presented. */
  37. bool offscreen;
  38. };
  39. /** Vulkan frame buffer containing one or multiple color surfaces, and an optional depth surface. */
  40. class VulkanFramebuffer : public VulkanResource
  41. {
  42. public:
  43. /** Creates a new frame buffer with the specified image views attached.
  44. *
  45. * @param[in] owner Resource manager that allocated this resource.
  46. * @param[in] desc Description of the frame buffer.
  47. */
  48. VulkanFramebuffer(VulkanResourceManager* owner, const VULKAN_FRAMEBUFFER_DESC& desc);
  49. ~VulkanFramebuffer();
  50. /** Returns a unique ID of this framebuffer. */
  51. UINT32 getId() const { return mId; }
  52. /**
  53. * Gets internal Vulkan render pass object.
  54. *
  55. * @param[in] preserveContents If true, returns render pass that preserves existing framebuffer attachment
  56. * contents on load. Otherwise returns render pass that discards them (more
  57. * efficient).
  58. */
  59. VkRenderPass getRenderPass(bool preserveContents) const;
  60. /**
  61. * Gets internal Vulkan framebuffer object.
  62. *
  63. * @param[in] preserveContents If true, returns render pass that preserves existing framebuffer attachment
  64. * contents on load. Otherwise returns render pass that discards them (more
  65. * efficient).
  66. */
  67. VkFramebuffer getFramebuffer(bool preserveContents) const;
  68. /**
  69. * Gets the number of layers in each framebuffer surface. A layer is an element in a texture array, or a depth
  70. * slice in a 3D texture).
  71. */
  72. UINT32 getNumLayers() const { return mNumLayers; }
  73. /** Returns the initial layer of the color texture surface in which to start rendering. */
  74. UINT32 getColorBaseLayer(UINT32 colorIdx) const { return mColorBaseLayers[colorIdx]; }
  75. /** Returns the initial layer of the depth-stencil texture surface in which to start rendering. */
  76. UINT32 getDepthStencilBaseLayer() const { return mDepthBaseLayer; }
  77. /** Gets the total number of frame-buffer attachments, including both color and depth. */
  78. UINT32 getNumAttachments() const { return mNumAttachments; }
  79. /** Gets the number of color frame-buffer attachments. */
  80. UINT32 getNumColorAttachments() const { return mNumColorAttachments; }
  81. /** Returns true if the framebuffer has a depth attachment. */
  82. bool hasDepthAttachment() const { return mHasDepth; }
  83. /** Returns sample flags that determine if the framebuffer supports multi-sampling, and for how many samples. */
  84. VkSampleCountFlagBits getSampleFlags() const { return mSampleFlags; }
  85. private:
  86. UINT32 mId;
  87. VkRenderPass mRenderPassDiscard;
  88. VkFramebuffer mFramebufferDiscard;
  89. VkRenderPass mRenderPassPreserve;
  90. VkFramebuffer mFramebufferPreserve;
  91. UINT32 mNumAttachments;
  92. UINT32 mNumColorAttachments;
  93. UINT32 mNumLayers;
  94. UINT32 mColorBaseLayers[BS_MAX_MULTIPLE_RENDER_TARGETS];
  95. UINT32 mDepthBaseLayer;
  96. bool mHasDepth;
  97. VkSampleCountFlagBits mSampleFlags;
  98. static UINT32 sNextValidId;
  99. };
  100. /** @} */
  101. }