BsRenderTargets.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /** Returns the scene color render target. */
  46. SPtr<RenderTextureCore> getSceneColorRT() const { return mSceneColorRT; }
  47. /** Returns the first color texture of the gbuffer as a bindable texture. */
  48. SPtr<TextureCore> getTextureA() const;
  49. /** Returns the second color texture of the gbuffer as a bindable texture. */
  50. SPtr<TextureCore> getTextureB() const;
  51. /** Returns the depth texture of the gbuffer as a bindable texture. */
  52. SPtr<TextureCore> getTextureDepth() const;
  53. /** Checks if the targets support HDR rendering. */
  54. bool getHDR() const { return mHDR; }
  55. /** Returns the number of samples per pixel supported by the targets. */
  56. UINT32 getNumSamples() const { return mNumSamples; }
  57. private:
  58. RenderTargets(const SPtr<ViewportCore>& viewport, bool hdr, UINT32 numSamples);
  59. /** Returns the width of gbuffer textures, in pixels. */
  60. UINT32 getWidth() const;
  61. /** Returns the height of gbuffer textures, in pixels. */
  62. UINT32 getHeight() const;
  63. SPtr<ViewportCore> mViewport;
  64. SPtr<PooledRenderTexture> mSceneColorTex;
  65. SPtr<PooledRenderTexture> mAlbedoTex;
  66. SPtr<PooledRenderTexture> mNormalTex;
  67. SPtr<PooledRenderTexture> mDepthTex;
  68. SPtr<MultiRenderTextureCore> mGBufferRT;
  69. SPtr<RenderTextureCore> mSceneColorRT;
  70. PixelFormat mSceneColorFormat;
  71. PixelFormat mAlbedoFormat;
  72. PixelFormat mNormalFormat;
  73. UINT32 mNumSamples;
  74. bool mHDR;
  75. };
  76. /** @} */
  77. }