BsRenderTargets.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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, and the output color render target.
  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 SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  26. /**
  27. * @brief Allocates the textures required for rendering. Allocations are pooled so this is generally a fast
  28. * operation unless the size or other render target options changed. This must be called before binding
  29. * render targets.
  30. */
  31. void allocate();
  32. /**
  33. * @brief Deallocates textures by returning them to the pool. This should be done when the caller is done using
  34. * the render targets, so that other systems might re-use them. This will not release any memory unless
  35. * all render targets pointing to those textures go out of scope.
  36. */
  37. void release();
  38. /**
  39. * @brief Binds the GBuffer render target for rendering.
  40. */
  41. void bind();
  42. /**
  43. * @brief Returns the first color texture of the gbuffer as a bindable texture.
  44. */
  45. SPtr<TextureCore> getTextureA() const;
  46. /**
  47. * @brief Returns the second color texture of the gbuffer as a bindable texture.
  48. */
  49. SPtr<TextureCore> getTextureB() const;
  50. /**
  51. * @brief Returns the depth texture of the gbuffer as a bindable texture.
  52. */
  53. SPtr<TextureCore> getTextureDepth() const;
  54. /**
  55. * @brief Checks if the targets support HDR rendering.
  56. */
  57. bool getHDR() const { return mHDR; }
  58. /**
  59. * @brief Returns the number of samples per pixel supported by the targets.
  60. */
  61. UINT32 getNumSamples() const { return mNumSamples; }
  62. private:
  63. RenderTargets(const SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  64. /**
  65. * @brief Returns the width of gbuffer textures, in pixels.
  66. */
  67. UINT32 getWidth() const;
  68. /**
  69. * @brief Returns the height of gbuffer textures, in pixels.
  70. */
  71. UINT32 getHeight() const;
  72. SPtr<ViewportCore> mViewport;
  73. SPtr<PooledRenderTexture> mSceneColorTex;
  74. SPtr<PooledRenderTexture> mAlbedoTex;
  75. SPtr<PooledRenderTexture> mNormalTex;
  76. SPtr<PooledRenderTexture> mDepthTex;
  77. SPtr<MultiRenderTextureCore> mGBufferRT;
  78. PixelFormat mDiffuseFormat;
  79. PixelFormat mNormalFormat;
  80. UINT32 mNumSamples;
  81. bool mHDR;
  82. };
  83. }