BsMultiRenderTexture.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderTarget.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Descriptor class used for initializing a MultiRenderTexture.
  8. * Contains descriptors for each individual color render surface and
  9. * their common depth/stencil surface.
  10. */
  11. struct BS_CORE_EXPORT MULTI_RENDER_TEXTURE_DESC
  12. {
  13. Vector<RENDER_SURFACE_DESC> colorSurfaces;
  14. RENDER_SURFACE_DESC depthStencilSurface;
  15. };
  16. /**
  17. * @see MULTI_RENDER_TEXTURE_DESC
  18. *
  19. * @note References core textures instead of texture handles.
  20. */
  21. struct BS_CORE_EXPORT MULTI_RENDER_TEXTURE_CORE_DESC
  22. {
  23. Vector<RENDER_SURFACE_CORE_DESC> colorSurfaces;
  24. RENDER_SURFACE_CORE_DESC depthStencilSurface;
  25. };
  26. /**
  27. * @brief Contains various properties that describe a render texture.
  28. */
  29. class BS_CORE_EXPORT MultiRenderTextureProperties : public RenderTargetProperties
  30. {
  31. public:
  32. MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc);
  33. MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
  34. virtual ~MultiRenderTextureProperties() { }
  35. protected:
  36. friend class MultiRenderTextureCore;
  37. friend class MultiRenderTexture;
  38. void construct(const TextureProperties* props);
  39. };
  40. /**
  41. * @brief Object representing multiple render textures. You may bind this to the pipeline
  42. * in order to render to all or some of the textures at once.
  43. *
  44. * @note Core thread only.
  45. */
  46. class BS_CORE_EXPORT MultiRenderTextureCore : public RenderTargetCore
  47. {
  48. public:
  49. virtual ~MultiRenderTextureCore();
  50. /**
  51. * @copydoc CoreObjectCore::initialize
  52. */
  53. virtual void initialize();
  54. /**
  55. * @brief Returns properties that describe the render texture.
  56. */
  57. const MultiRenderTextureProperties& getProperties() const;
  58. protected:
  59. MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
  60. /**
  61. * @copydoc CoreObjectCore::syncFromCore
  62. */
  63. virtual CoreSyncData syncFromCore(FrameAlloc* allocator);
  64. /**
  65. * @copydoc CoreObjectCore::syncToCore
  66. */
  67. virtual void syncToCore(const CoreSyncData& data);
  68. private:
  69. /**
  70. * @brief Checks that all render surfaces and depth/stencil surface match. If they do not match
  71. * an exception is thrown.
  72. */
  73. void throwIfBuffersDontMatch() const;
  74. // TODO - Not implemented
  75. virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);
  76. protected:
  77. Vector<TextureViewPtr> mColorSurfaces;
  78. TextureViewPtr mDepthStencilSurface;
  79. MULTI_RENDER_TEXTURE_CORE_DESC mDesc;
  80. };
  81. /**
  82. * @brief Object representing multiple render textures. You may bind this to the pipeline
  83. * in order to render to all or some of the textures at once.
  84. *
  85. * @note Sim thread only.
  86. */
  87. class BS_CORE_EXPORT MultiRenderTexture : public RenderTarget
  88. {
  89. public:
  90. virtual ~MultiRenderTexture() { }
  91. /**
  92. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  93. *
  94. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  95. */
  96. const HTexture& getBindableColorTexture(UINT32 idx) const { return mBindableColorTex[idx]; }
  97. /**
  98. * @brief Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  99. *
  100. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  101. */
  102. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  103. /**
  104. * @brief Retrieves a core implementation of a render texture usable only from the
  105. * core thread.
  106. */
  107. SPtr<MultiRenderTextureCore> getCore() const;
  108. /**
  109. * @copydoc TextureManager::createMultiRenderTexture
  110. */
  111. static MultiRenderTexturePtr create(const MULTI_RENDER_TEXTURE_DESC& desc);
  112. /**
  113. * @brief Returns properties that describe the render texture.
  114. */
  115. const MultiRenderTextureProperties& getProperties() const;
  116. /**
  117. * @brief Returns the number of color surfaces used by the render texture.
  118. */
  119. UINT32 getColorSurfaceCount() const;
  120. protected:
  121. MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
  122. /**
  123. * @copydoc RenderTarget::createCore
  124. */
  125. SPtr<CoreObjectCore> createCore() const;
  126. /**
  127. * @copydoc CoreObjectCore::syncToCore
  128. */
  129. virtual CoreSyncData syncToCore(FrameAlloc* allocator);
  130. /**
  131. * @copydoc CoreObjectCore::syncFromCore
  132. */
  133. virtual void syncFromCore(const CoreSyncData& data);
  134. MULTI_RENDER_TEXTURE_DESC mDesc;
  135. Vector<HTexture> mBindableColorTex;
  136. HTexture mBindableDepthStencilTex;
  137. };
  138. }