BsRenderTexture.h 5.3 KB

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