DepthDownscale.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// @addtogroup renderer
  11. /// @{
  12. /// Downscales the depth buffer a few times.
  13. class DepthDownscale : public RendererObject
  14. {
  15. public:
  16. DepthDownscale(Renderer* r)
  17. : RendererObject(r)
  18. {
  19. }
  20. ~DepthDownscale();
  21. ANKI_USE_RESULT Error init(const ConfigSet& cfg);
  22. /// Import render targets
  23. void importRenderTargets(RenderingContext& ctx);
  24. /// Populate the rendergraph.
  25. void populateRenderGraph(RenderingContext& ctx);
  26. /// Return a FP color render target with hierarchical Z (min Z) in it's mips.
  27. RenderTargetHandle getHiZRt() const
  28. {
  29. return m_runCtx.m_hizRt;
  30. }
  31. U32 getMipmapCount() const
  32. {
  33. return m_mipCount;
  34. }
  35. void getClientDepthMapInfo(F32*& depthValues, U32& width, U32& height) const
  36. {
  37. width = m_lastMipSize.x();
  38. height = m_lastMipSize.y();
  39. ANKI_ASSERT(m_clientBuffer);
  40. m_clientBuffer->invalidate(0, MAX_PTR_SIZE);
  41. depthValues = static_cast<F32*>(m_clientBufferAddr);
  42. }
  43. private:
  44. TexturePtr m_hizTex;
  45. Bool m_hizTexImportedOnce = false;
  46. ShaderProgramResourcePtr m_prog;
  47. ShaderProgramPtr m_grProg;
  48. BufferPtr m_counterBuffer;
  49. Bool m_counterBufferZeroed = false;
  50. SamplerPtr m_reductionSampler;
  51. BufferPtr m_clientBuffer;
  52. void* m_clientBufferAddr = nullptr;
  53. UVec2 m_lastMipSize;
  54. U32 m_mipCount = 0;
  55. class
  56. {
  57. public:
  58. RenderTargetHandle m_hizRt;
  59. } m_runCtx; ///< Run context.
  60. ANKI_USE_RESULT Error initInternal(const ConfigSet& cfg);
  61. Bool doesSamplerReduction() const
  62. {
  63. return m_reductionSampler.isCreated();
  64. }
  65. };
  66. /// @}
  67. } // end namespace anki