DepthDownscale.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <AnKi/Resource/ImageResource.h>
  9. namespace anki
  10. {
  11. /// @addtogroup renderer
  12. /// @{
  13. /// Downscales the depth buffer a few times.
  14. class DepthDownscale : public RendererObject
  15. {
  16. public:
  17. DepthDownscale(Renderer* r)
  18. : RendererObject(r)
  19. {
  20. }
  21. ~DepthDownscale();
  22. ANKI_USE_RESULT Error init(const ConfigSet& cfg);
  23. /// Import render targets
  24. void importRenderTargets(RenderingContext& ctx);
  25. /// Populate the rendergraph.
  26. void populateRenderGraph(RenderingContext& ctx);
  27. /// Return a FP color render target with hierarchical Z (min Z) in it's mips.
  28. RenderTargetHandle getHiZRt() const
  29. {
  30. return m_runCtx.m_hizRt;
  31. }
  32. U32 getMipmapCount() const
  33. {
  34. return m_mipCount;
  35. }
  36. void getClientDepthMapInfo(F32*& depthValues, U32& width, U32& height) const
  37. {
  38. width = m_copyToBuff.m_lastMipWidth;
  39. height = m_copyToBuff.m_lastMipHeight;
  40. ANKI_ASSERT(m_copyToBuff.m_buffAddr);
  41. depthValues = static_cast<F32*>(m_copyToBuff.m_buffAddr);
  42. }
  43. private:
  44. static const U32 MIPS_WRITTEN_PER_PASS = 2;
  45. TexturePtr m_hizTex;
  46. Bool m_hizTexImportedOnce = false;
  47. ShaderProgramResourcePtr m_prog;
  48. ShaderProgramPtr m_grProg;
  49. U32 m_mipCount = 0;
  50. class
  51. {
  52. public:
  53. RenderTargetHandle m_hizRt;
  54. U32 m_mip;
  55. } m_runCtx; ///< Run context.
  56. class
  57. {
  58. public:
  59. BufferPtr m_buff;
  60. void* m_buffAddr = nullptr;
  61. U32 m_lastMipWidth = MAX_U32, m_lastMipHeight = MAX_U32;
  62. } m_copyToBuff; ///< Copy to buffer members.
  63. ANKI_USE_RESULT Error initInternal(const ConfigSet& cfg);
  64. void run(RenderPassWorkContext& rgraphCtx);
  65. };
  66. /// @}
  67. } // end namespace anki