2
0

BsRenderTargets.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 bindGBuffer();
  42. /**
  43. * @brief Binds the scene color render target for rendering.
  44. */
  45. void bindSceneColor(bool readOnlyDepthStencil);
  46. /**
  47. * @brief Resolves the GBuffer scene color into the output scene color buffer.
  48. */
  49. void resolve();
  50. /**
  51. * @brief Returns the first color texture of the gbuffer as a bindable texture.
  52. */
  53. SPtr<TextureCore> getTextureA() const;
  54. /**
  55. * @brief Returns the second color texture of the gbuffer as a bindable texture.
  56. */
  57. SPtr<TextureCore> getTextureB() const;
  58. /**
  59. * @brief Returns the depth texture of the gbuffer as a bindable texture.
  60. */
  61. SPtr<TextureCore> getTextureDepth() const;
  62. /**
  63. * @brief Checks if the targets support HDR rendering.
  64. */
  65. bool getHDR() const { return mHDR; }
  66. /**
  67. * @brief Returns the number of samples per pixel supported by the targets.
  68. */
  69. UINT32 getNumSamples() const { return mNumSamples; }
  70. private:
  71. RenderTargets(const SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  72. /**
  73. * @brief Returns the width of gbuffer textures, in pixels.
  74. */
  75. UINT32 getWidth() const;
  76. /**
  77. * @brief Returns the height of gbuffer textures, in pixels.
  78. */
  79. UINT32 getHeight() const;
  80. SPtr<ViewportCore> mViewport;
  81. SPtr<PooledRenderTexture> mSceneColorTex;
  82. SPtr<PooledRenderTexture> mAlbedoTex;
  83. SPtr<PooledRenderTexture> mNormalTex;
  84. SPtr<PooledRenderTexture> mDepthTex;
  85. SPtr<MultiRenderTextureCore> mGBufferRT;
  86. SPtr<RenderTextureCore> mSceneColorRT;
  87. PixelFormat mDiffuseFormat;
  88. PixelFormat mNormalFormat;
  89. UINT32 mNumSamples;
  90. bool mHDR;
  91. };
  92. }