Framebuffer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ClearValue m_clearValue;
  26. Attachment() = default;
  27. Attachment(const Attachment& b)
  28. {
  29. operator=(b);
  30. }
  31. ~Attachment() = default;
  32. Attachment& operator=(const Attachment& b)
  33. {
  34. m_texture = b.m_texture;
  35. m_arrayIndex = b.m_arrayIndex;
  36. m_depth = b.m_depth;
  37. m_faceIndex = b.m_faceIndex;
  38. m_mipmap = b.m_mipmap;
  39. m_format = b.m_format;
  40. m_loadOperation = b.m_loadOperation;
  41. m_storeOperation = b.m_storeOperation;
  42. memcpy(&m_clearValue, &b.m_clearValue, sizeof(m_clearValue));
  43. return *this;
  44. }
  45. };
  46. /// Framebuffer initializer.
  47. class FramebufferInitInfo
  48. {
  49. public:
  50. Array<Attachment, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
  51. U32 m_colorAttachmentsCount = 0;
  52. Attachment m_depthStencilAttachment;
  53. FramebufferInitInfo() = default;
  54. FramebufferInitInfo(const FramebufferInitInfo& b)
  55. {
  56. operator=(b);
  57. }
  58. ~FramebufferInitInfo() = default;
  59. FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
  60. {
  61. for(U i = 0; i < b.m_colorAttachmentsCount; i++)
  62. {
  63. m_colorAttachments[i] = b.m_colorAttachments[i];
  64. }
  65. m_colorAttachmentsCount = b.m_colorAttachmentsCount;
  66. m_depthStencilAttachment = b.m_depthStencilAttachment;
  67. return *this;
  68. }
  69. };
  70. /// GPU framebuffer.
  71. class Framebuffer : public GrObject
  72. {
  73. public:
  74. /// Construct.
  75. Framebuffer(GrManager* manager);
  76. /// Destroy.
  77. ~Framebuffer();
  78. /// Access the implementation.
  79. FramebufferImpl& getImplementation()
  80. {
  81. return *m_impl;
  82. }
  83. /// Create.
  84. void init(const FramebufferInitInfo& init);
  85. private:
  86. UniquePtr<FramebufferImpl> m_impl;
  87. };
  88. /// @}
  89. } // end namespace anki