BsRenderTargets.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "BsRenderBeastPrerequisites.h"
  3. #include "BsPixelUtil.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Allocates and handles all the required render targets
  8. * for rendering a scene from a specific viewport.
  9. *
  10. * @note Core thread only.
  11. */
  12. class BS_BSRND_EXPORT RenderTargets
  13. {
  14. public:
  15. /**
  16. * @brief Creates a new set of render targets. This will not actually allocate
  17. * the internal render targets - this happens the first time you call ::bind.
  18. *
  19. * @param viewport Viewport that the render targets will be used for. Determines size of the
  20. * render targets.
  21. * @param hdr Should the render targets support high dynamic range rendering.
  22. * @param numSamples Number of samples to use if multisampling is active. Provide 0 or 1 if
  23. * multisampled targets are not needed.
  24. */
  25. static SPtr<RenderTargets> create(const ViewportCore& viewport, bool hdr, UINT32 numSamples);
  26. /**
  27. * @brief Binds the render targets for rendering. This will also allocate the render
  28. * targets if they aren't already allocated.
  29. */
  30. void bind();
  31. /**
  32. * @brief Frees the render targets so they may be used by another set of render targets. This
  33. * will not release the render target memory. Memory will only released once all
  34. * RenderTarget instances pointing to the render target go out of scope.
  35. */
  36. void unbind();
  37. /**
  38. * @brief Checks if the targets support HDR rendering.
  39. */
  40. bool getHDR() const { return mHDR; }
  41. /**
  42. * @brief Returns the number of samples per pixel supported by the targets.
  43. */
  44. UINT32 getNumSamples() const { return mNumSamples; }
  45. private:
  46. RenderTargets(const ViewportCore& viewport, bool hdr, UINT32 numSamples);
  47. SPtr<PooledRenderTexture> mDiffuseRT;
  48. SPtr<PooledRenderTexture> mNormalRT;
  49. SPtr<PooledRenderTexture> mDepthRT;
  50. SPtr<MultiRenderTextureCore> mGBuffer;
  51. UINT32 mWidth;
  52. UINT32 mHeight;
  53. PixelFormat mDiffuseFormat;
  54. PixelFormat mNormalFormat;
  55. UINT32 mNumSamples;
  56. bool mHDR;
  57. };
  58. }