BsRenderTarget.h 5.8 KB

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