BsRenderTargets.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. namespace BansheeEngine
  7. {
  8. /** @addtogroup RenderBeast
  9. * @{
  10. */
  11. /**
  12. * Allocates and handles all the required render targets for rendering a scene from a specific viewport.
  13. *
  14. * @note Core thread only.
  15. */
  16. class BS_BSRND_EXPORT RenderTargets
  17. {
  18. public:
  19. /**
  20. * Creates a new set of render targets. This will not actually allocate the internal render targets - this happens
  21. * the first time you call bind().
  22. *
  23. * @param[in] viewport Viewport that the render targets will be used for. Determines size of the render
  24. * targets, and the output color render target.
  25. * @param[in] hdr Should the render targets support high dynamic range rendering.
  26. * @param[in] numSamples Number of samples to use if multisampling is active. Provide 0 or 1 if multisampled
  27. * targets are not needed.
  28. */
  29. static SPtr<RenderTargets> create(const SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  30. /**
  31. * Allocates the textures required for rendering. Allocations are pooled so this is generally a fast operation
  32. * unless the size or other render target options changed. This must be called before binding render targets.
  33. */
  34. void allocate();
  35. /**
  36. * Deallocates textures by returning them to the pool. This should be done when the caller is done using the render
  37. * targets, so that other systems might re-use them. This will not release any memory unless all render targets
  38. * pointing to those textures go out of scope.
  39. */
  40. void release();
  41. /** Binds the GBuffer render target for rendering. */
  42. void bindGBuffer();
  43. /** Binds the scene color render target for rendering. */
  44. void bindSceneColor(bool readOnlyDepthStencil);
  45. /** Resolves the GBuffer scene color into the output scene color buffer. */
  46. void resolve();
  47. /** Returns the scene color render target. */
  48. SPtr<RenderTextureCore> getSceneColorRT() const { return mSceneColorRT; }
  49. /** Returns the first color texture of the gbuffer as a bindable texture. */
  50. SPtr<TextureCore> getTextureA() const;
  51. /** Returns the second color texture of the gbuffer as a bindable texture. */
  52. SPtr<TextureCore> getTextureB() const;
  53. /** Returns the depth texture of the gbuffer as a bindable texture. */
  54. SPtr<TextureCore> getTextureDepth() const;
  55. /** Checks if the targets support HDR rendering. */
  56. bool getHDR() const { return mHDR; }
  57. /** Returns the number of samples per pixel supported by the targets. */
  58. UINT32 getNumSamples() const { return mNumSamples; }
  59. private:
  60. RenderTargets(const SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  61. /** Returns the width of gbuffer textures, in pixels. */
  62. UINT32 getWidth() const;
  63. /** Returns the height of gbuffer textures, in pixels. */
  64. UINT32 getHeight() const;
  65. SPtr<ViewportCore> mViewport;
  66. SPtr<PooledRenderTexture> mSceneColorTex;
  67. SPtr<PooledRenderTexture> mAlbedoTex;
  68. SPtr<PooledRenderTexture> mNormalTex;
  69. SPtr<PooledRenderTexture> mDepthTex;
  70. SPtr<MultiRenderTextureCore> mGBufferRT;
  71. SPtr<RenderTextureCore> mSceneColorRT;
  72. PixelFormat mDiffuseFormat;
  73. PixelFormat mNormalFormat;
  74. UINT32 mNumSamples;
  75. bool mHDR;
  76. };
  77. /** @} */
  78. }