Framebuffer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2009-2021, 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. {
  10. /// @addtogroup graphics
  11. /// @{
  12. /// Framebuffer attachment info.
  13. class FramebufferAttachmentInfo
  14. {
  15. public:
  16. TextureViewPtr m_textureView;
  17. AttachmentLoadOperation m_loadOperation = AttachmentLoadOperation::CLEAR;
  18. AttachmentStoreOperation m_storeOperation = AttachmentStoreOperation::STORE;
  19. AttachmentLoadOperation m_stencilLoadOperation = AttachmentLoadOperation::CLEAR;
  20. AttachmentStoreOperation m_stencilStoreOperation = AttachmentStoreOperation::STORE;
  21. ClearValue m_clearValue;
  22. };
  23. /// Framebuffer initializer.
  24. class FramebufferInitInfo : public GrBaseInitInfo
  25. {
  26. public:
  27. Array<FramebufferAttachmentInfo, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
  28. U32 m_colorAttachmentCount = 0;
  29. FramebufferAttachmentInfo m_depthStencilAttachment;
  30. FramebufferInitInfo()
  31. : GrBaseInitInfo()
  32. {
  33. }
  34. FramebufferInitInfo(CString name)
  35. : GrBaseInitInfo(name)
  36. {
  37. }
  38. FramebufferInitInfo(const FramebufferInitInfo& b)
  39. : GrBaseInitInfo(b)
  40. {
  41. operator=(b);
  42. }
  43. ~FramebufferInitInfo() = default;
  44. FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
  45. {
  46. GrBaseInitInfo::operator=(b);
  47. for(U i = 0; i < b.m_colorAttachmentCount; i++)
  48. {
  49. m_colorAttachments[i] = b.m_colorAttachments[i];
  50. }
  51. m_colorAttachmentCount = b.m_colorAttachmentCount;
  52. m_depthStencilAttachment = b.m_depthStencilAttachment;
  53. return *this;
  54. }
  55. Bool isValid() const
  56. {
  57. for(U i = 0; i < m_colorAttachmentCount; ++i)
  58. {
  59. if(!m_colorAttachments[i].m_textureView.isCreated())
  60. {
  61. return false;
  62. }
  63. }
  64. if(m_colorAttachmentCount == 0 && !m_depthStencilAttachment.m_textureView.isCreated())
  65. {
  66. return false;
  67. }
  68. return true;
  69. }
  70. };
  71. /// GPU framebuffer.
  72. class Framebuffer : public GrObject
  73. {
  74. ANKI_GR_OBJECT
  75. public:
  76. static const GrObjectType CLASS_TYPE = GrObjectType::FRAMEBUFFER;
  77. protected:
  78. /// Construct.
  79. Framebuffer(GrManager* manager, CString name)
  80. : GrObject(manager, CLASS_TYPE, name)
  81. {
  82. }
  83. /// Destroy.
  84. ~Framebuffer()
  85. {
  86. }
  87. private:
  88. static ANKI_USE_RESULT Framebuffer* newInstance(GrManager* manager, const FramebufferInitInfo& init);
  89. };
  90. /// @}
  91. } // end namespace anki