CmRenderTarget.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmString.h"
  4. #include "CmPixelUtil.h"
  5. #include "CmViewport.h"
  6. #include "CmCoreObject.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 CM_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 CM_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 Returns the number of bits a single color value of the
  54. * render target format takes.
  55. */
  56. UINT32 getColorDepth() const { return mColorDepth; }
  57. /**
  58. * @brief Returns full screen antialiasing amount. Meaning of this value
  59. * depends on anti-aliasing type used.
  60. */
  61. UINT32 getFSAA() const { return mFSAA; }
  62. /**
  63. * @brief Returns a hint used for telling render system what type of
  64. * antialiasing to use.
  65. */
  66. const String& getFSAAHint() const { return mFSAAHint; }
  67. /**
  68. * @brief Returns true if the render target will wait for vertical sync
  69. * before swapping buffers. This will eliminate tearing but may increase
  70. * input latency.
  71. */
  72. bool getVSync() const { return mVSync; }
  73. /**
  74. * @brief Queries the render target for a custom attribute. This may be anything and is
  75. * implementation specific.
  76. *
  77. * @note Core thread only.
  78. */
  79. virtual void getCustomAttribute(const String& name, void* pData) const;
  80. /**
  81. * @brief Returns true if the render target is a render window.
  82. */
  83. virtual bool isWindow() const = 0;
  84. /**
  85. * @brief Returns true if the render target can be used for rendering.
  86. *
  87. * @note Core thread only.
  88. */
  89. bool isActive() const { return mActive; }
  90. /**
  91. * @brief Returns true if pixels written to the render target will be gamma corrected.
  92. */
  93. bool isHwGammaEnabled() const { return mHwGamma; }
  94. /**
  95. * @brief Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window).
  96. *
  97. * @note Core thread only.
  98. */
  99. virtual void setActive(bool state) { mActive = state; }
  100. /**
  101. * @brief Returns render target priority. Targets with higher priority will be
  102. * rendered before ones with lower priority.
  103. */
  104. INT32 getPriority() const { return mPriority; }
  105. /**
  106. * @brief Sets a priority that determines in which orders the render targets the processed.
  107. *
  108. * @param priority The priority. Higher value means the target will be rendered sooner.
  109. */
  110. void setPriority(INT32 priority) { mPriority = priority; }
  111. /**
  112. * @brief Swaps the frame buffers to display the next frame.
  113. *
  114. * @note Core thread only.
  115. */
  116. virtual void swapBuffers() {};
  117. /**
  118. * @brief Copy data from the render target into the provided pixel buffer.
  119. *
  120. * @param dst Destination buffer to copy the data to. Caller must ensure the buffer is of adequate size.
  121. * @param buffer Which buffer is data taken from. This is irrelevant for single buffer render targets.
  122. *
  123. * @note Core thread only.
  124. */
  125. virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;
  126. /**
  127. * @brief Does the texture need to be vertically flipped because of different screen space coordinate systems.
  128. * (i.e. is origin top left or bottom left. Engine default is top left.)
  129. */
  130. virtual bool requiresTextureFlipping() const = 0;
  131. /**
  132. * @brief Event that gets triggered whenever the render target is resized.
  133. *
  134. * @note Sim thread only.
  135. */
  136. mutable Event<void()> onResized;
  137. protected:
  138. RenderTarget();
  139. String mName;
  140. UINT32 mWidth;
  141. UINT32 mHeight;
  142. UINT32 mColorDepth;
  143. INT32 mPriority;
  144. bool mActive;
  145. bool mHwGamma;
  146. bool mVSync;
  147. UINT32 mFSAA;
  148. String mFSAAHint;
  149. };
  150. }