Framebuffer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/GrObject.h>
  7. #include <AnKi/Gr/TextureView.h>
  8. namespace anki {
  9. /// @addtogroup graphics
  10. /// @{
  11. /// Framebuffer attachment info.
  12. class FramebufferAttachmentInfo
  13. {
  14. public:
  15. TextureViewPtr m_textureView;
  16. AttachmentLoadOperation m_loadOperation = AttachmentLoadOperation::kClear;
  17. AttachmentStoreOperation m_storeOperation = AttachmentStoreOperation::kStore;
  18. AttachmentLoadOperation m_stencilLoadOperation = AttachmentLoadOperation::kClear;
  19. AttachmentStoreOperation m_stencilStoreOperation = AttachmentStoreOperation::kStore;
  20. ClearValue m_clearValue;
  21. };
  22. /// Framebuffer initializer.
  23. class FramebufferInitInfo : public GrBaseInitInfo
  24. {
  25. public:
  26. Array<FramebufferAttachmentInfo, kMaxColorRenderTargets> m_colorAttachments;
  27. U32 m_colorAttachmentCount = 0;
  28. FramebufferAttachmentInfo m_depthStencilAttachment;
  29. class
  30. {
  31. public:
  32. TextureViewPtr m_textureView;
  33. U32 m_texelWidth = 0;
  34. U32 m_texelHeight = 0;
  35. } m_shadingRateImage;
  36. FramebufferInitInfo()
  37. : GrBaseInitInfo()
  38. {
  39. }
  40. FramebufferInitInfo(CString name)
  41. : GrBaseInitInfo(name)
  42. {
  43. }
  44. FramebufferInitInfo(const FramebufferInitInfo& b)
  45. : GrBaseInitInfo(b)
  46. {
  47. operator=(b);
  48. }
  49. ~FramebufferInitInfo() = default;
  50. FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
  51. {
  52. GrBaseInitInfo::operator=(b);
  53. for(U i = 0; i < b.m_colorAttachmentCount; i++)
  54. {
  55. m_colorAttachments[i] = b.m_colorAttachments[i];
  56. }
  57. m_colorAttachmentCount = b.m_colorAttachmentCount;
  58. m_depthStencilAttachment = b.m_depthStencilAttachment;
  59. m_shadingRateImage = b.m_shadingRateImage;
  60. return *this;
  61. }
  62. Bool isValid() const
  63. {
  64. for(U i = 0; i < m_colorAttachmentCount; ++i)
  65. {
  66. if(!m_colorAttachments[i].m_textureView.isCreated())
  67. {
  68. return false;
  69. }
  70. }
  71. if(m_colorAttachmentCount == 0 && !m_depthStencilAttachment.m_textureView.isCreated())
  72. {
  73. return false;
  74. }
  75. if(m_shadingRateImage.m_textureView)
  76. {
  77. if(m_shadingRateImage.m_texelHeight == 0 || m_shadingRateImage.m_texelWidth == 0)
  78. {
  79. return false;
  80. }
  81. if(!isPowerOfTwo(m_shadingRateImage.m_texelHeight) || !isPowerOfTwo(m_shadingRateImage.m_texelWidth))
  82. {
  83. return false;
  84. }
  85. }
  86. return true;
  87. }
  88. };
  89. /// GPU framebuffer.
  90. class Framebuffer : public GrObject
  91. {
  92. ANKI_GR_OBJECT
  93. public:
  94. static constexpr GrObjectType kClassType = GrObjectType::kFramebuffer;
  95. protected:
  96. /// Construct.
  97. Framebuffer(GrManager* manager, CString name)
  98. : GrObject(manager, kClassType, name)
  99. {
  100. }
  101. /// Destroy.
  102. ~Framebuffer()
  103. {
  104. }
  105. private:
  106. [[nodiscard]] static Framebuffer* newInstance(GrManager* manager, const FramebufferInitInfo& init);
  107. };
  108. /// @}
  109. } // end namespace anki