Framebuffer.h 2.2 KB

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