2
0

Framebuffer.h 2.3 KB

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