BsRenderTarget.h 5.8 KB

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