BsMultiRenderTexture.h 4.4 KB

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