BsRenderTexture.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsTexture.h"
  4. #include "BsRenderTarget.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Structure that describes a render texture color and depth/stencil surfaces.
  9. */
  10. struct BS_CORE_EXPORT RENDER_TEXTURE_DESC
  11. {
  12. RENDER_SURFACE_DESC colorSurface;
  13. RENDER_SURFACE_DESC depthStencilSurface;
  14. };
  15. /**
  16. * @brief Render target specialization that allows you to render into a texture you may
  17. * later bind in further render operations.
  18. *
  19. * @note Thread safe, except where noted otherwise.
  20. */
  21. class BS_CORE_EXPORT RenderTexture : public RenderTarget
  22. {
  23. public:
  24. virtual ~RenderTexture();
  25. /**
  26. * @brief Creates a new render texture with color and optionally depth/stencil surfaces.
  27. *
  28. * @param textureType Type of texture to render to.
  29. * @param width Width of the render texture, in pixels.
  30. * @param height Height of the render texture, in pixels.
  31. * @param format Pixel format used by the texture color surface.
  32. * @param hwGamma Should the written pixels be gamma corrected.
  33. * @param multisampleCount If higher than 1, texture containing multiple samples per pixel is created.
  34. * @param multisampleHint Hint about what kind of multisampling to use. Render system specific.
  35. * @param createDepth Should a depth/stencil surface be created along with the color surface.
  36. * @param depthStencilFormat Format used by the depth stencil surface, if one is created.
  37. */
  38. static RenderTexturePtr create(TextureType textureType, UINT32 width, UINT32 height,
  39. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  40. const String& multisampleHint = "", bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  41. /**
  42. * @copydoc RenderTarget::isWindow.
  43. */
  44. bool isWindow() const { return false; }
  45. /**
  46. * @copydoc RenderTarget::requiresTextureFlipping.
  47. */
  48. bool requiresTextureFlipping() const { return false; }
  49. /**
  50. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  51. *
  52. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  53. */
  54. const HTexture& getBindableColorTexture() const { return mBindableColorTex; }
  55. /**
  56. * @brief Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  57. *
  58. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  59. */
  60. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  61. protected:
  62. friend class TextureManager;
  63. RenderTexture();
  64. /**
  65. * @copydoc RenderTarget::initialize
  66. */
  67. void initialize(const RENDER_TEXTURE_DESC& desc);
  68. /**
  69. * @copydoc RenderTarget::destroy_internal()
  70. */
  71. virtual void destroy_internal();
  72. private:
  73. /**
  74. * @brief Throws an exception of the color and depth/stencil buffers aren't compatible.
  75. */
  76. void throwIfBuffersDontMatch() const;
  77. /**
  78. * @copydoc RenderTarget::copyToMemory
  79. */
  80. virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO);
  81. protected:
  82. TextureViewPtr mColorSurface;
  83. TextureViewPtr mDepthStencilSurface;
  84. HTexture mBindableColorTex;
  85. HTexture mBindableDepthStencilTex;
  86. };
  87. }