BsRenderTarget.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsString.h"
  4. #include "BsPixelUtil.h"
  5. #include "BsViewport.h"
  6. #include "BsCoreObject.h"
  7. #include "BsEvent.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Structure that contains information about
  12. * what part of the texture represents the render surface.
  13. */
  14. struct BS_CORE_EXPORT RENDER_SURFACE_DESC
  15. {
  16. TexturePtr texture;
  17. UINT32 face;
  18. UINT32 numFaces;
  19. UINT32 mipLevel;
  20. };
  21. /**
  22. * @brief Render target is a frame buffer or a texture that the render
  23. * system renders to.
  24. *
  25. * @note Thread safe, except where noted otherwise.
  26. */
  27. class BS_CORE_EXPORT RenderTarget : public CoreObject
  28. {
  29. public:
  30. /**
  31. * @brief Frame buffer type when double-buffering is used.
  32. */
  33. enum FrameBuffer
  34. {
  35. FB_FRONT,
  36. FB_BACK,
  37. FB_AUTO
  38. };
  39. virtual ~RenderTarget();
  40. /**
  41. * @brief Returns a name of the render target, used for easier identification.
  42. */
  43. const String& getName() const { return mName; }
  44. /**
  45. * @brief Returns width of the render target, in pixels.
  46. */
  47. UINT32 getWidth() const { return mWidth; }
  48. /**
  49. * @brief Returns height of the render target, in pixels.
  50. */
  51. UINT32 getHeight() const { return mHeight; }
  52. /**
  53. * @brief Gets the number of samples used for multisampling.
  54. * (0 if multisampling is not used).
  55. */
  56. UINT32 getMultisampleCount() const { return mMultisampleCount; }
  57. /**
  58. * @brief Get a render-system specific hint used for determining
  59. * multisampling type.
  60. */
  61. const String& getMultisampleHint() const { return mMultisampleHint; }
  62. /**
  63. * @brief Returns true if the render target will wait for vertical sync
  64. * before swapping buffers. This will eliminate tearing but may increase
  65. * input latency.
  66. */
  67. bool getVSync() const { return mVSync; }
  68. /**
  69. * @brief Queries the render target for a custom attribute. This may be anything and is
  70. * implementation specific.
  71. *
  72. * @note Core thread only.
  73. */
  74. virtual void getCustomAttribute(const String& name, void* pData) const;
  75. /**
  76. * @brief Returns true if the render target is a render window.
  77. */
  78. virtual bool isWindow() const = 0;
  79. /**
  80. * @brief Returns true if the render target can be used for rendering.
  81. *
  82. * @note Core thread only.
  83. */
  84. bool isActive() const { return mActive; }
  85. /**
  86. * @brief Returns true if pixels written to the render target will be gamma corrected.
  87. */
  88. bool isHwGammaEnabled() const { return mHwGamma; }
  89. /**
  90. * @brief Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window).
  91. *
  92. * @note Core thread only.
  93. */
  94. virtual void setActive(bool state) { mActive = state; }
  95. /**
  96. * @brief Returns render target priority. Targets with higher priority will be
  97. * rendered before ones with lower priority.
  98. */
  99. INT32 getPriority() const { return mPriority; }
  100. /**
  101. * @brief Sets a priority that determines in which orders the render targets the processed.
  102. *
  103. * @param priority The priority. Higher value means the target will be rendered sooner.
  104. */
  105. void setPriority(INT32 priority) { mPriority = priority; }
  106. /**
  107. * @brief Swaps the frame buffers to display the next frame.
  108. *
  109. * @note Core thread only.
  110. */
  111. virtual void swapBuffers() {};
  112. /**
  113. * @brief Copy data from the render target into the provided pixel buffer.
  114. *
  115. * @param dst Destination buffer to copy the data to. Caller must ensure the buffer is of adequate size.
  116. * @param buffer Which buffer is data taken from. This is irrelevant for single buffer render targets.
  117. *
  118. * @note Core thread only.
  119. */
  120. virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;
  121. /**
  122. * @brief Does the texture need to be vertically flipped because of different screen space coordinate systems.
  123. * (i.e. is origin top left or bottom left. Engine default is top left.)
  124. */
  125. virtual bool requiresTextureFlipping() const = 0;
  126. /**
  127. * @brief Event that gets triggered whenever the render target is resized.
  128. *
  129. * @note Sim thread only.
  130. */
  131. mutable Event<void()> onResized;
  132. protected:
  133. RenderTarget();
  134. String mName;
  135. UINT32 mWidth;
  136. UINT32 mHeight;
  137. UINT32 mColorDepth;
  138. INT32 mPriority;
  139. bool mActive;
  140. bool mHwGamma;
  141. bool mVSync;
  142. UINT32 mMultisampleCount;
  143. String mMultisampleHint;
  144. };
  145. }