GBuffer.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/Renderer/RendererObject.h>
  7. #include <AnKi/Gr.h>
  8. namespace anki {
  9. /// @addtogroup renderer
  10. /// @{
  11. /// G buffer stage. It populates the G buffer
  12. class GBuffer : public RendererObject
  13. {
  14. public:
  15. GBuffer(Renderer* r)
  16. : RendererObject(r)
  17. {
  18. registerDebugRenderTarget("GBuffer_normals");
  19. registerDebugRenderTarget("GBuffer_albedo");
  20. registerDebugRenderTarget("GBuffer_velocity");
  21. }
  22. ~GBuffer();
  23. ANKI_USE_RESULT Error init(const ConfigSet& initializer);
  24. /// Populate the rendergraph.
  25. void populateRenderGraph(RenderingContext& ctx);
  26. RenderTargetHandle getColorRt(U idx) const
  27. {
  28. return m_runCtx.m_colorRts[idx];
  29. }
  30. RenderTargetHandle getDepthRt() const
  31. {
  32. return m_runCtx.m_crntFrameDepthRt;
  33. }
  34. RenderTargetHandle getPreviousFrameDepthRt() const
  35. {
  36. return m_runCtx.m_prevFrameDepthRt;
  37. }
  38. void getDebugRenderTarget(CString rtName, RenderTargetHandle& handle,
  39. ShaderProgramPtr& optionalShaderProgram) const override
  40. {
  41. if(rtName == "GBuffer_albedo")
  42. {
  43. handle = m_runCtx.m_colorRts[0];
  44. }
  45. else if(rtName == "GBuffer_normals")
  46. {
  47. handle = m_runCtx.m_colorRts[2];
  48. }
  49. else if(rtName == "GBuffer_velocity")
  50. {
  51. handle = m_runCtx.m_colorRts[3];
  52. }
  53. else
  54. {
  55. ANKI_ASSERT(!"See file");
  56. }
  57. }
  58. private:
  59. Array<RenderTargetDescription, GBUFFER_COLOR_ATTACHMENT_COUNT> m_colorRtDescrs;
  60. Array<TexturePtr, 2> m_depthRts;
  61. FramebufferDescription m_fbDescr;
  62. class
  63. {
  64. public:
  65. Array<RenderTargetHandle, GBUFFER_COLOR_ATTACHMENT_COUNT> m_colorRts;
  66. RenderTargetHandle m_crntFrameDepthRt;
  67. RenderTargetHandle m_prevFrameDepthRt;
  68. } m_runCtx;
  69. ANKI_USE_RESULT Error initInternal(const ConfigSet& initializer);
  70. void runInThread(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx) const;
  71. };
  72. /// @}
  73. } // end namespace anki