BsRenderTarget.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 "Image/BsPixelUtil.h"
  6. #include "RenderAPI/BsViewport.h"
  7. #include "CoreThread/BsCoreObject.h"
  8. #include "Utility/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. namespace ct
  30. {
  31. /**
  32. * @see bs::RENDER_SURFACE_DESC
  33. *
  34. * @note References core textures instead of texture handles.
  35. */
  36. struct BS_CORE_EXPORT RENDER_SURFACE_DESC
  37. {
  38. RENDER_SURFACE_DESC() { }
  39. SPtr<Texture> texture;
  40. /** First face of the texture to bind (array index in texture arrays, or Z slice in 3D textures). */
  41. UINT32 face = 0;
  42. /**
  43. * Number of faces to bind (entries in a texture array, or Z slices in 3D textures). When zero the entire resource
  44. * will be bound.
  45. */
  46. UINT32 numFaces = 0;
  47. /** If the texture has multiple mips, which one to bind (only one can be bound for rendering). */
  48. UINT32 mipLevel = 0;
  49. };
  50. }
  51. /** Contains various properties that describe a render target. */
  52. class BS_CORE_EXPORT RenderTargetProperties
  53. {
  54. public:
  55. RenderTargetProperties() { }
  56. virtual ~RenderTargetProperties() { }
  57. /** Width of the render target, in pixels. */
  58. UINT32 width = 0;
  59. /** Height of the render target, in pixels. */
  60. UINT32 height = 0;
  61. /**
  62. * Number of three dimensional slices of the render target. This will be number of layers for array
  63. * textures or number of faces cube textures.
  64. */
  65. UINT32 numSlices = 0;
  66. /**
  67. * Controls in what order is the render target rendered to compared to other render targets. Targets with higher
  68. * priority will be rendered before ones with lower priority.
  69. */
  70. INT32 priority = 0;
  71. /**
  72. * True if the render target will wait for vertical sync before swapping buffers. This will eliminate
  73. * tearing but may increase input latency.
  74. */
  75. bool vsync = false;
  76. /**
  77. * Controls how often should the frame be presented in respect to display device refresh rate. Normal value is 1
  78. * where it will match the refresh rate. Higher values will decrease the frame rate (for example present interval of
  79. * 2 on 60Hz refresh rate will display at most 30 frames per second).
  80. */
  81. UINT32 vsyncInterval = 1;
  82. /** True if pixels written to the render target will be gamma corrected. */
  83. bool hwGamma = false;
  84. /**
  85. * Does the texture need to be vertically flipped because of different screen space coordinate systems. (Determines
  86. * is origin top left or bottom left. Engine default is top left.)
  87. */
  88. bool requiresTextureFlipping = false;
  89. /** True if the target is a window, false if an offscreen target. */
  90. bool isWindow = false;
  91. /** Controls how many samples are used for multisampling. (0 or 1 if multisampling is not used). */
  92. UINT32 multisampleCount = 0;
  93. };
  94. /**
  95. * Render target is a frame buffer or a texture that the render system renders the scene to.
  96. *
  97. * @note
  98. * Sim thread unless noted otherwise. Retrieve core implementation from getCore() for core thread only functionality.
  99. */
  100. class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) RenderTarget : public CoreObject
  101. {
  102. public:
  103. RenderTarget();
  104. virtual ~RenderTarget() { }
  105. /** Queries the render target for a custom attribute. This may be anything and is implementation specific. */
  106. virtual void getCustomAttribute(const String& name, void* pData) const;
  107. /**
  108. * @copydoc ct::RenderTarget::setPriority
  109. *
  110. * @note This is an @ref asyncMethod "asynchronous method".
  111. */
  112. void setPriority(INT32 priority);
  113. /**
  114. * Returns properties that describe the render target.
  115. *
  116. * @note Sim thread only.
  117. */
  118. const RenderTargetProperties& getProperties() const;
  119. /** Retrieves a core implementation of a render target usable only from the core thread. */
  120. SPtr<ct::RenderTarget> getCore() const;
  121. /**
  122. * Event that gets triggered whenever the render target is resized.
  123. *
  124. * @note Sim thread only.
  125. */
  126. mutable Event<void()> onResized;
  127. protected:
  128. friend class ct::RenderTarget;
  129. /** Returns properties that describe the render target. */
  130. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  131. };
  132. /** @} */
  133. namespace ct
  134. {
  135. /** @addtogroup RenderAPI-Internal
  136. * @{
  137. */
  138. /**
  139. * Provides access to internal render target implementation usable only from the core thread.
  140. *
  141. * @note Core thread only.
  142. */
  143. class BS_CORE_EXPORT RenderTarget : public CoreObject
  144. {
  145. public:
  146. /** Frame buffer type when double-buffering is used. */
  147. enum FrameBuffer
  148. {
  149. FB_FRONT,
  150. FB_BACK,
  151. FB_AUTO
  152. };
  153. RenderTarget();
  154. virtual ~RenderTarget() { }
  155. /**
  156. * Sets a priority that determines in which orders the render targets the processed.
  157. *
  158. * @param[in] priority The priority. Higher value means the target will be rendered sooner.
  159. */
  160. void setPriority(INT32 priority);
  161. /**
  162. * Swaps the frame buffers to display the next frame.
  163. *
  164. * @param[in] syncMask Optional synchronization mask that determines for which queues should the system wait
  165. * before performing the swap buffer operation. By default the system waits for all queues.
  166. * However if certain queues are performing non-rendering operations, or operations not
  167. * related to this render target, you can exclude them from the sync mask for potentially
  168. * better performance. You can use CommandSyncMask to generate a valid sync mask.
  169. */
  170. virtual void swapBuffers(UINT32 syncMask = 0xFFFFFFFF) {}
  171. /** Queries the render target for a custom attribute. This may be anything and is implementation specific. */
  172. virtual void getCustomAttribute(const String& name, void* pData) const;
  173. /** Returns properties that describe the render target. */
  174. const RenderTargetProperties& getProperties() const;
  175. protected:
  176. friend class bs::RenderTarget;
  177. /** Returns properties that describe the render target. */
  178. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  179. };
  180. /** @} */
  181. }
  182. }