Framebuffer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  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/Texture.h>
  8. #include <cstring>
  9. namespace anki
  10. {
  11. /// @addtogroup graphics
  12. /// @{
  13. /// Framebuffer attachment info.
  14. class Attachment
  15. {
  16. public:
  17. TexturePtr m_texture;
  18. U32 m_arrayIndex = 0; ///< For array textures
  19. U32 m_depth = 0; ///< For 3D textures
  20. U32 m_faceIndex = 0; ///< For cubemap textures
  21. U32 m_mipmap = 0;
  22. PixelFormat m_format;
  23. AttachmentLoadOperation m_loadOperation = AttachmentLoadOperation::CLEAR;
  24. AttachmentStoreOperation m_storeOperation = AttachmentStoreOperation::STORE;
  25. union
  26. {
  27. Array<F32, 4> m_colorf = {{0.0, 0.0, 0.0, 0.0}};
  28. Array<I32, 4> m_colori;
  29. Array<U32, 4> m_coloru;
  30. struct
  31. {
  32. F32 m_depth;
  33. I32 m_stencil;
  34. } m_depthStencil;
  35. } m_clearValue;
  36. Attachment() = default;
  37. Attachment(const Attachment& b)
  38. {
  39. operator=(b);
  40. }
  41. ~Attachment() = default;
  42. Attachment& operator=(const Attachment& b)
  43. {
  44. m_texture = b.m_texture;
  45. m_arrayIndex = b.m_arrayIndex;
  46. m_depth = b.m_depth;
  47. m_faceIndex = b.m_faceIndex;
  48. m_mipmap = b.m_mipmap;
  49. m_format = b.m_format;
  50. m_loadOperation = b.m_loadOperation;
  51. m_storeOperation = b.m_storeOperation;
  52. memcpy(&m_clearValue, &b.m_clearValue, sizeof(m_clearValue));
  53. return *this;
  54. }
  55. };
  56. /// Framebuffer initializer.
  57. class FramebufferInitInfo
  58. {
  59. public:
  60. Array<Attachment, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
  61. U32 m_colorAttachmentsCount = 0;
  62. Attachment m_depthStencilAttachment;
  63. FramebufferInitInfo() = default;
  64. FramebufferInitInfo(const FramebufferInitInfo& b)
  65. {
  66. operator=(b);
  67. }
  68. ~FramebufferInitInfo() = default;
  69. FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
  70. {
  71. for(U i = 0; i < b.m_colorAttachmentsCount; i++)
  72. {
  73. m_colorAttachments[i] = b.m_colorAttachments[i];
  74. }
  75. m_colorAttachmentsCount = b.m_colorAttachmentsCount;
  76. m_depthStencilAttachment = b.m_depthStencilAttachment;
  77. return *this;
  78. }
  79. };
  80. /// GPU framebuffer.
  81. class Framebuffer : public GrObject
  82. {
  83. public:
  84. /// Construct.
  85. Framebuffer(GrManager* manager);
  86. /// Destroy.
  87. ~Framebuffer();
  88. /// Access the implementation.
  89. FramebufferImpl& getImplementation()
  90. {
  91. return *m_impl;
  92. }
  93. /// Create.
  94. void create(const FramebufferInitInfo& init);
  95. private:
  96. UniquePtr<FramebufferImpl> m_impl;
  97. };
  98. /// @}
  99. } // end namespace anki