2
0

BsRenderTarget.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 (e.g. present interval of 2 on
  59. * 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. (i.e. is
  79. * 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. /** @cond INTERNAL */
  98. /**
  99. * Provides access to internal render target implementation usable only from the core thread.
  100. *
  101. * @note Core thread only.
  102. */
  103. class BS_CORE_EXPORT RenderTargetCore : public CoreObjectCore
  104. {
  105. public:
  106. /** Frame buffer type when double-buffering is used. */
  107. enum FrameBuffer
  108. {
  109. FB_FRONT,
  110. FB_BACK,
  111. FB_AUTO
  112. };
  113. RenderTargetCore();
  114. virtual ~RenderTargetCore() { }
  115. /**
  116. * Sets a priority that determines in which orders the render targets the processed.
  117. *
  118. * @param[in] priority The priority. Higher value means the target will be rendered sooner.
  119. */
  120. void setPriority(INT32 priority);
  121. /** Swaps the frame buffers to display the next frame. */
  122. virtual void swapBuffers() {};
  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. /** Returns properties that describe the render target. */
  126. const RenderTargetProperties& getProperties() const;
  127. protected:
  128. friend class RenderTarget;
  129. /** Returns properties that describe the render target. */
  130. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  131. };
  132. /** @endcond */
  133. /**
  134. * Render target is a frame buffer or a texture that the render system renders the scene to.
  135. *
  136. * @note
  137. * Sim thread unless noted otherwise. Retrieve core implementation from getCore() for core thread only functionality.
  138. */
  139. class BS_CORE_EXPORT RenderTarget : public CoreObject
  140. {
  141. public:
  142. RenderTarget();
  143. virtual ~RenderTarget() { }
  144. /** Queries the render target for a custom attribute. This may be anything and is implementation specific. */
  145. virtual void getCustomAttribute(const String& name, void* pData) const;
  146. /** @copydoc RenderTargetCore::setPriority */
  147. void setPriority(CoreAccessor& accessor, INT32 priority);
  148. /**
  149. * Returns properties that describe the render target.
  150. *
  151. * @note Sim thread only.
  152. */
  153. const RenderTargetProperties& getProperties() const;
  154. /** Retrieves a core implementation of a render target usable only from the core thread. */
  155. SPtr<RenderTargetCore> getCore() const;
  156. /**
  157. * Event that gets triggered whenever the render target is resized.
  158. *
  159. * @note Sim thread only.
  160. */
  161. mutable Event<void()> onResized;
  162. protected:
  163. friend class RenderTargetCore;
  164. /** Returns properties that describe the render target. */
  165. virtual const RenderTargetProperties& getPropertiesInternal() const = 0;
  166. };
  167. /** @} */
  168. }