BsRenderTexture.h 6.0 KB

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