BsRenderTarget.h 6.1 KB

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