BsRenderTexture.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /**
  27. * @brief Provides access to internal render texture implementation usable only from the core thread.
  28. *
  29. * @note Core thread only.
  30. */
  31. class BS_CORE_EXPORT RenderTextureCore : public RenderTargetCore
  32. {
  33. public:
  34. RenderTextureCore(RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  35. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc);
  36. virtual ~RenderTextureCore();
  37. /**
  38. * @copydoc RenderTargetCore::copyToMemory
  39. */
  40. virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);
  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 multisampleHint Hint about what kind of multisampling to use. Render system specific.
  80. * @param createDepth Should a depth/stencil surface be created along with the color surface.
  81. * @param depthStencilFormat Format used by the depth stencil surface, if one is created.
  82. */
  83. static RenderTexturePtr create(TextureType textureType, UINT32 width, UINT32 height,
  84. PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0,
  85. const String& multisampleHint = "", bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
  86. /**
  87. * @copydoc RenderTexture::requiresTextureFlipping
  88. */
  89. virtual bool requiresTextureFlipping() const { return false; }
  90. /**
  91. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  92. *
  93. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  94. */
  95. const HTexture& getBindableColorTexture() const { return mBindableColorTex; }
  96. /**
  97. * @brief Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  98. *
  99. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  100. */
  101. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  102. /**
  103. * @brief Returns properties that describe the render texture.
  104. */
  105. const RenderTextureProperties& getProperties() const;
  106. /**
  107. * @brief Retrieves a core implementation of a render texture usable only from the
  108. * core thread.
  109. *
  110. * @note Core thread only.
  111. */
  112. RenderTextureCore* getCore() const;
  113. protected:
  114. friend class TextureManager;
  115. RenderTexture() { }
  116. /**
  117. * @copydoc RenderTarget::initialize
  118. */
  119. virtual void initialize(const RENDER_TEXTURE_DESC& desc);
  120. /**
  121. * @copydoc RenderTexture::createCore
  122. */
  123. virtual RenderTargetCore* createCore();
  124. /**
  125. * @brief Creates a core implementation of a render texture. This implementation
  126. * is to be used on the core thread only.
  127. */
  128. virtual RenderTextureCore* createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  129. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc) = 0;
  130. protected:
  131. HTexture mBindableColorTex;
  132. HTexture mBindableDepthStencilTex;
  133. RENDER_SURFACE_DESC mColorSurfaceDesc;
  134. RENDER_SURFACE_DESC mDepthStencilSurfaceDesc;
  135. };
  136. }