BsMultiRenderTexture.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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::syncToCore
  62. */
  63. virtual void syncToCore(const CoreSyncData& data);
  64. private:
  65. /**
  66. * @brief Checks that all render surfaces and depth/stencil surface match. If they do not match
  67. * an exception is thrown.
  68. */
  69. void throwIfBuffersDontMatch() const;
  70. // TODO - Not implemented
  71. virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);
  72. protected:
  73. Vector<TextureViewPtr> mColorSurfaces;
  74. TextureViewPtr mDepthStencilSurface;
  75. MULTI_RENDER_TEXTURE_CORE_DESC mDesc;
  76. };
  77. /**
  78. * @brief Object representing multiple render textures. You may bind this to the pipeline
  79. * in order to render to all or some of the textures at once.
  80. *
  81. * @note Sim thread only.
  82. */
  83. class BS_CORE_EXPORT MultiRenderTexture : public RenderTarget
  84. {
  85. public:
  86. virtual ~MultiRenderTexture() { }
  87. /**
  88. * @brief Returns a color surface texture you may bind as an input to an GPU program.
  89. *
  90. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  91. */
  92. const HTexture& getBindableColorTexture(UINT32 idx) const { return mBindableColorTex[idx]; }
  93. /**
  94. * @brief Returns a depth/stencil 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& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  99. /**
  100. * @brief Retrieves a core implementation of a render texture usable only from the
  101. * core thread.
  102. */
  103. SPtr<MultiRenderTextureCore> getCore() const;
  104. /**
  105. * @copydoc TextureManager::createMultiRenderTexture
  106. */
  107. static MultiRenderTexturePtr create(const MULTI_RENDER_TEXTURE_DESC& desc);
  108. /**
  109. * @brief Returns properties that describe the render texture.
  110. */
  111. const MultiRenderTextureProperties& getProperties() const;
  112. /**
  113. * @brief Returns the number of color surfaces used by the render texture.
  114. */
  115. UINT32 getColorSurfaceCount() const;
  116. protected:
  117. MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
  118. /**
  119. * @copydoc RenderTarget::createCore
  120. */
  121. SPtr<CoreObjectCore> createCore() const;
  122. /**
  123. * @copydoc CoreObjectCore::syncToCore
  124. */
  125. virtual CoreSyncData syncToCore(FrameAlloc* allocator);
  126. MULTI_RENDER_TEXTURE_DESC mDesc;
  127. Vector<HTexture> mBindableColorTex;
  128. HTexture mBindableDepthStencilTex;
  129. };
  130. }