BsRenderTexture.h 5.0 KB

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