BsMultiRenderTexture.h 4.0 KB

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