BsRenderTexture.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * @copydoc RenderTargetProperties::copyToBuffer
  27. */
  28. virtual void copyToBuffer(UINT8* buffer) const;
  29. /**
  30. * @copydoc RenderTargetProperties::copyFromBuffer
  31. */
  32. virtual void copyFromBuffer(UINT8* buffer);
  33. /**
  34. * @copydoc RenderTargetProperties::getSize
  35. */
  36. virtual UINT32 getSize() const;
  37. };
  38. /**
  39. * @brief Provides access to internal render texture implementation usable only from the core thread.
  40. *
  41. * @note Core thread only.
  42. */
  43. class BS_CORE_EXPORT RenderTextureCore : public RenderTargetCore
  44. {
  45. public:
  46. RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  47. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
  48. virtual ~RenderTextureCore();
  49. /**
  50. * @brief Returns properties that describe the render texture.
  51. */
  52. const RenderTextureProperties& getProperties() const { return *static_cast<RenderTextureProperties*>(mProperties); }
  53. /**
  54. * @copydoc RenderTargetCore::getNonCore
  55. */
  56. RenderTexture* getNonCore() const;
  57. private:
  58. /**
  59. * @brief Throws an exception of the color and depth/stencil buffers aren't compatible.
  60. */
  61. void throwIfBuffersDontMatch() const;
  62. protected:
  63. friend class RenderTexture;
  64. /**
  65. * @copydoc CoreObjectCore::initialize
  66. */
  67. virtual void initialize();
  68. /**
  69. * @copydoc CoreObjectCore::destroy
  70. */
  71. virtual void destroy();
  72. TextureViewPtr mColorSurface;
  73. TextureViewPtr mDepthStencilSurface;
  74. RENDER_SURFACE_DESC mColorSurfaceDesc;
  75. RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
  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. * @copydoc RenderTexture::requiresTextureFlipping
  109. */
  110. virtual bool requiresTextureFlipping() const { return false; }
  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 Returns properties that describe the render texture.
  125. */
  126. const RenderTextureProperties& getProperties() const;
  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. protected:
  135. friend class TextureManager;
  136. RenderTexture() { }
  137. /**
  138. * @copydoc RenderTarget::initialize
  139. */
  140. virtual void initialize(const RENDER_TEXTURE_DESC& desc);
  141. protected:
  142. HTexture mBindableColorTex;
  143. HTexture mBindableDepthStencilTex;
  144. RENDER_SURFACE_DESC mColorSurfaceDesc;
  145. RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
  146. };
  147. }