BsVulkanFramebuffer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 BansheeEngine
  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. /** Gets internal Vulkan render pass object. */
  53. VkRenderPass getRenderPass() const { return mRenderPass; }
  54. /** Gets internal Vulkan framebuffer object. */
  55. VkFramebuffer getFramebuffer() const { return mFramebuffer; }
  56. /**
  57. * Gets the number of layers in each framebuffer surface. A layer is an element in a texture array, or a depth
  58. * slice in a 3D texture).
  59. */
  60. UINT32 getNumLayers() const { return mNumLayers; }
  61. /** Returns the initial layer of the color texture surface in which to start rendering. */
  62. UINT32 getColorBaseLayer(UINT32 colorIdx) const { return mColorBaseLayers[colorIdx]; }
  63. /** Returns the initial layer of the depth-stencil texture surface in which to start rendering. */
  64. UINT32 getDepthStencilBaseLayer() const { return mDepthBaseLayer; }
  65. /** Gets the total number of frame-buffer attachments, including both color and depth. */
  66. UINT32 getNumAttachments() const { return mNumAttachments; }
  67. /** Gets the number of color frame-buffer attachments. */
  68. UINT32 getNumColorAttachments() const { return mNumColorAttachments; }
  69. /** Returns true if the framebuffer has a depth attachment. */
  70. bool hasDepthAttachment() const { return mHasDepth; }
  71. /** Returns sample flags that determine if the framebuffer supports multi-sampling, and for how many samples. */
  72. VkSampleCountFlagBits getSampleFlags() const { return mSampleFlags; }
  73. private:
  74. UINT32 mId;
  75. VkRenderPass mRenderPass;
  76. VkFramebuffer mFramebuffer;
  77. UINT32 mNumAttachments;
  78. UINT32 mNumColorAttachments;
  79. UINT32 mNumLayers;
  80. UINT32 mColorBaseLayers[BS_MAX_MULTIPLE_RENDER_TARGETS];
  81. UINT32 mDepthBaseLayer;
  82. bool mHasDepth;
  83. VkSampleCountFlagBits mSampleFlags;
  84. static UINT32 sNextValidId;
  85. };
  86. /** @} */
  87. }