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