BsRenderTargets.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsPixelUtil.h"
  6. #include "BsRendererCamera.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup RenderBeast
  10. * @{
  11. */
  12. /**
  13. * Allocates and handles all the required render targets for rendering a scene from a specific view.
  14. *
  15. * @note Core thread only.
  16. */
  17. class BS_BSRND_EXPORT RenderTargets
  18. {
  19. public:
  20. /**
  21. * Creates a new set of render targets. This will not actually allocate the internal render targets - this happens
  22. * the first time you call bind().
  23. *
  24. * @param[in] view Information about the view that the render targets will be used for. Determines size
  25. * of the render targets, and the output color render target.
  26. * @param[in] hdr Should the render targets support high dynamic range rendering.
  27. */
  28. static SPtr<RenderTargets> create(const RENDERER_VIEW_TARGET_DESC& view, bool hdr);
  29. /**
  30. * Allocates the textures required for rendering. Allocations are pooled so this is generally a fast operation
  31. * unless the size or other render target options changed. This must be called before binding render targets.
  32. */
  33. void allocate();
  34. /**
  35. * Deallocates textures by returning them to the pool. This should be done when the caller is done using the render
  36. * targets, so that other systems might re-use them. This will not release any memory unless all render targets
  37. * pointing to those textures go out of scope.
  38. */
  39. void release();
  40. /** Binds the GBuffer render target for rendering. */
  41. void bindGBuffer();
  42. /** Binds the scene color render target for rendering. */
  43. void bindSceneColor(bool readOnlyDepthStencil);
  44. /** Returns the scene color render target. */
  45. SPtr<RenderTexture> getSceneColorRT() const { return mSceneColorRT; }
  46. /** Returns the first color texture of the gbuffer as a bindable texture. */
  47. SPtr<Texture> getTextureA() const;
  48. /** Returns the second color texture of the gbuffer as a bindable texture. */
  49. SPtr<Texture> getTextureB() const;
  50. /** Returns the depth texture of the gbuffer as a bindable texture. */
  51. SPtr<Texture> getTextureDepth() const;
  52. /** Checks if the targets support HDR rendering. */
  53. bool getHDR() const { return mHDR; }
  54. /** Returns the number of samples per pixel supported by the targets. */
  55. UINT32 getNumSamples() const { return mViewTarget.numSamples; }
  56. private:
  57. RenderTargets(const RENDERER_VIEW_TARGET_DESC& view, bool hdr);
  58. RENDERER_VIEW_TARGET_DESC mViewTarget;
  59. SPtr<PooledRenderTexture> mSceneColorTex;
  60. SPtr<PooledRenderTexture> mAlbedoTex;
  61. SPtr<PooledRenderTexture> mNormalTex;
  62. SPtr<PooledRenderTexture> mDepthTex;
  63. SPtr<RenderTexture> mGBufferRT;
  64. SPtr<RenderTexture> mSceneColorRT;
  65. PixelFormat mSceneColorFormat;
  66. PixelFormat mAlbedoFormat;
  67. PixelFormat mNormalFormat;
  68. bool mHDR;
  69. };
  70. /** @} */
  71. }}