BsRenderTarget.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsPixelUtil.h"
  4. #include "BsViewport.h"
  5. #include "BsCoreObject.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Structure that contains information about
  11. * what part of the texture represents the render surface.
  12. */
  13. struct BS_CORE_EXPORT RENDER_SURFACE_DESC
  14. {
  15. TexturePtr texture;
  16. UINT32 face;
  17. UINT32 mipLevel;
  18. };
  19. /**
  20. * @brief Contains various properties that describe a render target.
  21. */
  22. class BS_CORE_EXPORT RenderTargetProperties
  23. {
  24. public:
  25. virtual ~RenderTargetProperties() { }
  26. /**
  27. * @brief Returns width of the render target, in pixels.
  28. *
  29. * @note Sim thread only.
  30. */
  31. UINT32 getWidth() const { return mWidth; }
  32. /**
  33. * @brief Returns height of the render target, in pixels.
  34. *
  35. * @note Sim thread only.
  36. */
  37. UINT32 getHeight() const { return mHeight; }
  38. /**
  39. * @brief Gets the number of samples used for multisampling.
  40. * (0 if multisampling is not used).
  41. */
  42. UINT32 getMultisampleCount() const { return mMultisampleCount; }
  43. /**
  44. * @brief Returns true if the render target will wait for vertical sync
  45. * before swapping buffers. This will eliminate tearing but may increase
  46. * input latency.
  47. */
  48. bool getVSync() const { return mVSync; }
  49. /**
  50. * @brief Returns how often should the frame be presented in respect to
  51. * display device refresh rate. Normal value is 1 where it will
  52. * match the refresh rate. Higher values will decrease the frame
  53. * rate (e.g. present interval of 2 on 60Hz refresh rate will display
  54. * at most 30 frames per second).
  55. */
  56. UINT32 getVSyncInterval() const { return mVSyncInterval; }
  57. /**
  58. * @brief Returns true if pixels written to the render target will be gamma corrected.
  59. */
  60. bool isHwGammaEnabled() const { return mHwGamma; }
  61. /**
  62. * @brief Returns true if the render target can be used for rendering.
  63. *
  64. * @note Core thread only.
  65. */
  66. bool isActive() const { return mActive; }
  67. /**
  68. * @brief Returns render target priority. Targets with higher priority will be
  69. * rendered before ones with lower priority.
  70. */
  71. INT32 getPriority() const { return mPriority; }
  72. /**
  73. * @brief Returns true if the render target is a render window.
  74. */
  75. bool isWindow() const { return mIsWindow; }
  76. /**
  77. * @brief Does the texture need to be vertically flipped because of different screen space coordinate systems.
  78. * (i.e. is origin top left or bottom left. Engine default is top left.)
  79. */
  80. bool requiresTextureFlipping() const { return mRequiresTextureFlipping; }
  81. protected:
  82. friend class RenderTargetCore;
  83. friend class RenderTarget;
  84. UINT32 mWidth = 0;
  85. UINT32 mHeight = 0;
  86. UINT32 mColorDepth = 32;
  87. INT32 mPriority = 0;
  88. UINT32 mVSyncInterval = 1;
  89. bool mActive = true;
  90. bool mHwGamma = false;
  91. bool mVSync = false;
  92. bool mRequiresTextureFlipping = false;
  93. bool mIsWindow = false;
  94. UINT32 mMultisampleCount = 0;
  95. };
  96. /**
  97. * @brief Provides access to internal render target implementation usable only from the core thread.
  98. *
  99. * @note Core thread only.
  100. */
  101. class BS_CORE_EXPORT RenderTargetCore : public CoreObjectCore
  102. {
  103. public:
  104. /**
  105. * @brief Frame buffer type when double-buffering is used.
  106. */
  107. enum FrameBuffer
  108. {
  109. FB_FRONT,
  110. FB_BACK,
  111. FB_AUTO
  112. };
  113. RenderTargetCore();
  114. virtual ~RenderTargetCore() { }
  115. /**
  116. * @brief Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window).
  117. */
  118. virtual void setActive(bool state);
  119. /**
  120. * @brief Sets a priority that determines in which orders the render targets the processed.
  121. *
  122. * @param priority The priority. Higher value means the target will be rendered sooner.
  123. */
  124. void setPriority(INT32 priority);
  125. /**
  126. * @brief Swaps the frame buffers to display the next frame.
  127. */
  128. virtual void swapBuffers() {};
  129. /**
  130. * @brief Queries the render target for a custom attribute. This may be anything and is
  131. * implementation specific.
  132. */
  133. virtual void getCustomAttribute(const String& name, void* pData) const;
  134. /**
  135. * @brief Returns properties that describe the render target.
  136. */
  137. const RenderTargetProperties& getProperties() const;
  138. protected:
  139. friend class RenderTarget;
  140. /**
  141. * @brief Returns properties that describe the render target.
  142. */
  143. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  144. };
  145. /**
  146. * @brief Render target is a frame buffer or a texture that the render
  147. * system renders to.
  148. *
  149. * @note Sim thread unless noted otherwise. Retrieve core implementation from getCore()
  150. * for core thread only functionality.
  151. */
  152. class BS_CORE_EXPORT RenderTarget : public CoreObject
  153. {
  154. public:
  155. virtual ~RenderTarget() { }
  156. /**
  157. * @brief Queries the render target for a custom attribute. This may be anything and is
  158. * implementation specific.
  159. */
  160. virtual void getCustomAttribute(const String& name, void* pData) const;
  161. /**
  162. * @copydoc RenderTargetCore::setPriority
  163. */
  164. void setPriority(CoreAccessor& accessor, UINT32 priority);
  165. /**
  166. * @brief Returns properties that describe the render target.
  167. *
  168. * @note Sim thread only.
  169. */
  170. const RenderTargetProperties& getProperties() const;
  171. /**
  172. * @brief Retrieves a core implementation of a render target usable only from the
  173. * core thread.
  174. */
  175. SPtr<RenderTargetCore> getCore() const;
  176. /**
  177. * @brief Event that gets triggered whenever the render target is resized.
  178. *
  179. * @note Sim thread only.
  180. */
  181. mutable Event<void()> onResized;
  182. protected:
  183. friend class RenderTargetCore;
  184. /**
  185. * @brief Returns properties that describe the render target.
  186. */
  187. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  188. };
  189. }