BsRenderTargets.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Returns the first color texture of the gbuffer as a bindable texture.
  39. */
  40. SPtr<TextureCore> getTextureA() const;
  41. /**
  42. * @brief Returns the second color texture of the gbuffer as a bindable texture.
  43. */
  44. SPtr<TextureCore> getTextureB() const;
  45. /**
  46. * @brief Returns the depth texture of the gbuffer as a bindable texture.
  47. */
  48. SPtr<TextureCore> getTextureDepth() const;
  49. /**
  50. * @brief Checks if the targets support HDR rendering.
  51. */
  52. bool getHDR() const { return mHDR; }
  53. /**
  54. * @brief Returns the number of samples per pixel supported by the targets.
  55. */
  56. UINT32 getNumSamples() const { return mNumSamples; }
  57. private:
  58. RenderTargets(const ViewportCore& viewport, bool hdr, UINT32 numSamples);
  59. SPtr<PooledRenderTexture> mDiffuseRT;
  60. SPtr<PooledRenderTexture> mNormalRT;
  61. SPtr<PooledRenderTexture> mDepthRT;
  62. SPtr<MultiRenderTextureCore> mGBuffer;
  63. UINT32 mWidth;
  64. UINT32 mHeight;
  65. PixelFormat mDiffuseFormat;
  66. PixelFormat mNormalFormat;
  67. UINT32 mNumSamples;
  68. bool mHDR;
  69. };
  70. }