BsRenderTargets.h 3.4 KB

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