BsRenderTargets.h 3.5 KB

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