BsRenderTexture.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 Contains various properties that describe a render texture.
  17. */
  18. class BS_CORE_EXPORT RenderTextureProperties : public RenderTargetProperties
  19. {
  20. public:
  21. virtual ~RenderTextureProperties() { }
  22. private:
  23. friend class RenderTextureCore;
  24. friend class RenderTexture;
  25. };
  26. /**
  27. * @brief Provides access to internal render texture implementation usable only from the core thread.
  28. *
  29. * @note Core thread only.
  30. */
  31. class BS_CORE_EXPORT RenderTextureCore : public RenderTargetCore
  32. {
  33. public:
  34. RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  35. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
  36. virtual ~RenderTextureCore();
  37. /**
  38. * @brief Returns properties that describe the render texture.
  39. */
  40. const RenderTextureProperties& getProperties() const { return *static_cast<RenderTextureProperties*>(mProperties); }
  41. /**
  42. * @copydoc RenderTargetCore::getNonCore
  43. */
  44. RenderTexture* getNonCore() const;
  45. private:
  46. /**
  47. * @brief Throws an exception of the color and depth/stencil buffers aren't compatible.
  48. */
  49. void throwIfBuffersDontMatch() const;
  50. protected:
  51. friend class RenderTexture;
  52. TextureViewPtr mColorSurface;
  53. TextureViewPtr mDepthStencilSurface;
  54. };
  55. /**
  56. * @brief Render target specialization that allows you to render into a texture you may
  57. * later bind in further render operations.
  58. *
  59. * @note Sim thread only. Retrieve core implementation from getCore()
  60. * for core thread only functionality.
  61. */
  62. class BS_CORE_EXPORT RenderTexture : public RenderTarget
  63. {
  64. public:
  65. virtual ~RenderTexture() { }
  66. /**
  67. * @brief Creates a new render texture with color and optionally depth/stencil surfaces.
  68. *
  69. * @param textureType Type of texture to render to.
  70. * @param width Width of the render texture, in pixels.
  71. * @param height Height of the render texture, in pixels.
  72. * @param format Pixel format used by the texture color surface.
  73. * @param hwGamma Should the written pixels be gamma corrected.
  74. * @param multisampleCount If higher than 1, texture containing multiple samples per pixel is created.
  75. * @param multisampleHint Hint about what kind of multisampling to use. Render system specific.
  76. * @param createDepth Should a depth/stencil surface be created along with the color surface.
  77. * @param depthStencilFormat Format used by the depth stencil surface, if one is created.
  78. */
  79. static RenderTexturePtr create(TextureType textureType, UINT32 width, UINT32 height,
  80. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  81. const String& multisampleHint = "", bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  82. /**
  83. * @copydoc TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
  84. */
  85. static RenderTexturePtr create(const RENDER_TEXTURE_DESC& desc);
  86. /**
  87. * @copydoc RenderTexture::requiresTextureFlipping
  88. */
  89. virtual bool requiresTextureFlipping() const { return false; }
  90. /**
  91. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  92. *
  93. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  94. */
  95. const HTexture& getBindableColorTexture() const { return mBindableColorTex; }
  96. /**
  97. * @brief Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  98. *
  99. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  100. */
  101. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  102. /**
  103. * @brief Returns properties that describe the render texture.
  104. */
  105. const RenderTextureProperties& getProperties() const;
  106. /**
  107. * @brief Retrieves a core implementation of a render texture usable only from the
  108. * core thread.
  109. *
  110. * @note Core thread only.
  111. */
  112. RenderTextureCore* getCore() const;
  113. protected:
  114. friend class TextureManager;
  115. RenderTexture() { }
  116. /**
  117. * @copydoc RenderTarget::initialize
  118. */
  119. virtual void initialize(const RENDER_TEXTURE_DESC& desc);
  120. /**
  121. * @copydoc RenderTexture::createCore
  122. */
  123. virtual RenderTargetCore* createCore();
  124. /**
  125. * @brief Creates a core implementation of a render texture. This implementation
  126. * is to be used on the core thread only.
  127. */
  128. virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  129. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc) = 0;
  130. protected:
  131. HTexture mBindableColorTex;
  132. HTexture mBindableDepthStencilTex;
  133. RENDER_SURFACE_DESC mColorSurfaceDesc;
  134. RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
  135. };
  136. }