BsMultiRenderTexture.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderTarget.h"
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup RenderAPI
  7. * @{
  8. */
  9. /**
  10. * Descriptor class used for initializing a MultiRenderTexture. Contains descriptors for each individual color render
  11. * surface and their common depth/stencil surface.
  12. */
  13. struct BS_CORE_EXPORT MULTI_RENDER_TEXTURE_DESC
  14. {
  15. Vector<RENDER_SURFACE_DESC> colorSurfaces;
  16. RENDER_SURFACE_DESC depthStencilSurface;
  17. };
  18. /**
  19. * @see MULTI_RENDER_TEXTURE_DESC
  20. *
  21. * @note References core textures instead of texture handles.
  22. */
  23. struct BS_CORE_EXPORT MULTI_RENDER_TEXTURE_CORE_DESC
  24. {
  25. Vector<RENDER_SURFACE_CORE_DESC> colorSurfaces;
  26. RENDER_SURFACE_CORE_DESC depthStencilSurface;
  27. };
  28. /** Contains various properties that describe a render texture. */
  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. /** @cond INTERNAL */
  41. /**
  42. * Object representing multiple render textures. You may bind this to the pipeline in order to render to all or some
  43. * of the textures at once.
  44. *
  45. * @note Core thread only.
  46. */
  47. class BS_CORE_EXPORT MultiRenderTextureCore : public RenderTargetCore
  48. {
  49. public:
  50. virtual ~MultiRenderTextureCore();
  51. /** @copydoc CoreObjectCore::initialize */
  52. virtual void initialize() override;
  53. /** Returns properties that describe the render texture. */
  54. const MultiRenderTextureProperties& getProperties() const;
  55. protected:
  56. MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
  57. /** @copydoc CoreObjectCore::syncToCore */
  58. virtual void syncToCore(const CoreSyncData& data) override;
  59. private:
  60. /** Checks that all render surfaces and depth/stencil surface match. If they do not match an exception is thrown. */
  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_CORE_DESC mDesc;
  68. };
  69. /** @endcond */
  70. /**
  71. * Object representing multiple render textures. You may bind this to the pipeline in order to render to all or some of
  72. * the textures at once.
  73. *
  74. * @note Sim thread only.
  75. */
  76. class BS_CORE_EXPORT MultiRenderTexture : public RenderTarget
  77. {
  78. public:
  79. virtual ~MultiRenderTexture() { }
  80. /**
  81. * Returns a color surface texture you may bind as an input to an GPU program.
  82. *
  83. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  84. */
  85. const HTexture& getBindableColorTexture(UINT32 idx) const { return mBindableColorTex[idx]; }
  86. /**
  87. * Returns a depth/stencil surface texture you may bind as an input to an GPU program.
  88. *
  89. * @note Be aware that you cannot bind a render texture for reading and writing at the same time.
  90. */
  91. const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
  92. /** Retrieves a core implementation of a render texture usable only from the core thread. */
  93. SPtr<MultiRenderTextureCore> getCore() const;
  94. /** @copydoc TextureManager::createMultiRenderTexture */
  95. static MultiRenderTexturePtr create(const MULTI_RENDER_TEXTURE_DESC& desc);
  96. /** Returns properties that describe the render texture. */
  97. const MultiRenderTextureProperties& getProperties() const;
  98. /** Returns the number of color surfaces used by the render texture. */
  99. UINT32 getColorSurfaceCount() const;
  100. protected:
  101. MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
  102. /** @copydoc RenderTarget::createCore */
  103. SPtr<CoreObjectCore> createCore() const override;
  104. /** @copydoc CoreObjectCore::syncToCore */
  105. virtual CoreSyncData syncToCore(FrameAlloc* allocator) override;
  106. MULTI_RENDER_TEXTURE_DESC mDesc;
  107. Vector<HTexture> mBindableColorTex;
  108. HTexture mBindableDepthStencilTex;
  109. };
  110. /** @} */
  111. }