BsRenderTarget.h 6.2 KB

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