BsRenderTarget.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 bs
  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_DESC_CORE
  35. {
  36. RENDER_SURFACE_DESC_CORE() { }
  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. /** Returns width of the render target, in pixels. */
  55. UINT32 getWidth() const { return mWidth; }
  56. /** Returns height of the render target, in pixels. */
  57. UINT32 getHeight() const { return mHeight; }
  58. /**
  59. * Returns the number of three dimensional slices of the render target. This will be the depth for 3D textures,
  60. * or number of layers for array textures.
  61. */
  62. UINT32 getNumSlices() const { return mNumSlices; }
  63. /** Gets the number of samples used for multisampling. (0 or 1 if multisampling is not used). */
  64. UINT32 getMultisampleCount() const { return mMultisampleCount; }
  65. /**
  66. * Returns true if the render target will wait for vertical sync before swapping buffers. This will eliminate
  67. * tearing but may increase input latency.
  68. */
  69. bool getVSync() const { return mVSync; }
  70. /**
  71. * Returns how often should the frame be presented in respect to display device refresh rate. Normal value is 1
  72. * where it will match the refresh rate. Higher values will decrease the frame rate (for example present interval of
  73. * 2 on 60Hz refresh rate will display at most 30 frames per second).
  74. */
  75. UINT32 getVSyncInterval() const { return mVSyncInterval; }
  76. /** Returns true if pixels written to the render target will be gamma corrected. */
  77. bool isHwGammaEnabled() const { return mHwGamma; }
  78. /**
  79. * Returns true if the render target can be used for rendering.
  80. *
  81. * @note Core thread only.
  82. */
  83. bool isActive() const { return mActive; }
  84. /**
  85. * Controls in what order is the render target rendered to compared to other render targets. Targets with higher
  86. * priority will be rendered before ones with lower priority.
  87. */
  88. INT32 getPriority() const { return mPriority; }
  89. /** Returns true if the render target is a render window. */
  90. bool isWindow() const { return mIsWindow; }
  91. /**
  92. * Does the texture need to be vertically flipped because of different screen space coordinate systems. (Determines
  93. * is origin top left or bottom left. Engine default is top left.)
  94. */
  95. bool requiresTextureFlipping() const { return mRequiresTextureFlipping; }
  96. protected:
  97. friend class RenderTargetCore;
  98. friend class RenderTarget;
  99. UINT32 mWidth = 0;
  100. UINT32 mHeight = 0;
  101. UINT32 mNumSlices = 0;
  102. UINT32 mColorDepth = 32;
  103. INT32 mPriority = 0;
  104. UINT32 mVSyncInterval = 1;
  105. bool mActive = true;
  106. bool mHwGamma = false;
  107. bool mVSync = false;
  108. bool mRequiresTextureFlipping = false;
  109. bool mIsWindow = false;
  110. UINT32 mMultisampleCount = 0;
  111. };
  112. /**
  113. * Render target is a frame buffer or a texture that the render system renders the scene to.
  114. *
  115. * @note
  116. * Sim thread unless noted otherwise. Retrieve core implementation from getCore() for core thread only functionality.
  117. */
  118. class BS_CORE_EXPORT RenderTarget : public CoreObject
  119. {
  120. public:
  121. RenderTarget();
  122. virtual ~RenderTarget() { }
  123. /** Queries the render target for a custom attribute. This may be anything and is implementation specific. */
  124. virtual void getCustomAttribute(const String& name, void* pData) const;
  125. /**
  126. * @copydoc RenderTargetCore::setPriority
  127. *
  128. * @note This is an @ref asyncMethod "asynchronous method".
  129. */
  130. void setPriority(INT32 priority);
  131. /**
  132. * Returns properties that describe the render target.
  133. *
  134. * @note Sim thread only.
  135. */
  136. const RenderTargetProperties& getProperties() const;
  137. /** Retrieves a core implementation of a render target usable only from the core thread. */
  138. SPtr<RenderTargetCore> getCore() const;
  139. /**
  140. * Event that gets triggered whenever the render target is resized.
  141. *
  142. * @note Sim thread only.
  143. */
  144. mutable Event<void()> onResized;
  145. protected:
  146. friend class RenderTargetCore;
  147. /** Returns properties that describe the render target. */
  148. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  149. };
  150. /** @} */
  151. /** @addtogroup RenderAPI-Internal
  152. * @{
  153. */
  154. /**
  155. * Provides access to internal render target implementation usable only from the core thread.
  156. *
  157. * @note Core thread only.
  158. */
  159. class BS_CORE_EXPORT RenderTargetCore : public CoreObjectCore
  160. {
  161. public:
  162. /** Frame buffer type when double-buffering is used. */
  163. enum FrameBuffer
  164. {
  165. FB_FRONT,
  166. FB_BACK,
  167. FB_AUTO
  168. };
  169. RenderTargetCore();
  170. virtual ~RenderTargetCore() { }
  171. /**
  172. * Sets a priority that determines in which orders the render targets the processed.
  173. *
  174. * @param[in] priority The priority. Higher value means the target will be rendered sooner.
  175. */
  176. void setPriority(INT32 priority);
  177. /**
  178. * Swaps the frame buffers to display the next frame.
  179. *
  180. * @param[in] syncMask Optional synchronization mask that determines for which queues should the system wait
  181. * before performing the swap buffer operation. By default the system waits for all queues.
  182. * However if certain queues are performing non-rendering operations, or operations not
  183. * related to this render target, you can exclude them from the sync mask for potentially
  184. * better performance. You can use CommandSyncMask to generate a valid sync mask.
  185. */
  186. virtual void swapBuffers(UINT32 syncMask = 0xFFFFFFFF) {}
  187. /** Queries the render target for a custom attribute. This may be anything and is implementation specific. */
  188. virtual void getCustomAttribute(const String& name, void* pData) const;
  189. /** Returns properties that describe the render target. */
  190. const RenderTargetProperties& getProperties() const;
  191. protected:
  192. friend class RenderTarget;
  193. /** Returns properties that describe the render target. */
  194. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  195. };
  196. /** @} */
  197. }