BsMultiRenderTexture.h 5.4 KB

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