BsRenderTarget.h 7.1 KB

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