BsRenderTexture.h 5.2 KB

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