BsViewport.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsColor.h"
  4. #include "BsRectI.h"
  5. #include "BsRectF.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Viewport provides you with a way to render to only a part of a
  11. * RenderTarget. It also allows you to set up color/depth/stencil
  12. * clear values for that specific region.
  13. */
  14. class BS_CORE_EXPORT Viewport
  15. {
  16. public:
  17. Viewport();
  18. /**
  19. * @brief Constructs a new viewport.
  20. *
  21. * @note Viewport coordinates are normalized in [0, 1] range.
  22. */
  23. Viewport(const RenderTargetPtr& target, float x = 0.0f, float y = 0.0f, float width = 1.0f, float height = 1.0f);
  24. virtual ~Viewport();
  25. /**
  26. * @brief Returns the render target the viewport is associated with.
  27. */
  28. RenderTargetPtr getTarget() const { return mTarget; }
  29. /**
  30. * @brief Gets the normalized x coordinate of the viewport, in [0, 1] range.
  31. */
  32. float getNormalizedX() const { return mNormArea.x; }
  33. /**
  34. * @brief Gets the normalized y coordinate of the viewport, in [0, 1] range.
  35. */
  36. float getNormalizedY() const { return mNormArea.y; }
  37. /**
  38. * @brief Gets the normalized width of the viewport, in [0, 1] range.
  39. */
  40. float getNormalizedWidth() const { return mNormArea.width; }
  41. /**
  42. * @brief Gets the normalized height of the viewport, in [0, 1] range.
  43. */
  44. float getNormalizedHeight() const { return mNormArea.height; }
  45. /**
  46. * @brief Gets the actual x coordinate of the viewport in pixels, in [0, RenderTargetWidth] range.
  47. */
  48. INT32 getX() const { return mArea.x; }
  49. /**
  50. * @brief Gets the actual y coordinate of the viewport in pixels, in [0, RenderTargetHeight] range.
  51. */
  52. INT32 getY() const { return mArea.y; }
  53. /**
  54. * @brief Gets the actual width coordinate of the viewport in pixels, in [0, RenderTargetWidth] range.
  55. */
  56. INT32 getWidth() const { return mArea.width; }
  57. /**
  58. * @brief Gets the actual height coordinate of the viewport in pixels, in [0, RenderTargetHeight] range.
  59. */
  60. INT32 getHeight() const { return mArea.height; }
  61. /**
  62. * @brief Changes the area that the viewport covers.
  63. *
  64. * @note Viewport coordinates are normalized in [0, 1] range.
  65. */
  66. void setArea(float x, float y, float width, float height);
  67. /**
  68. * @brief Returns actual area of the viewport, in pixels.
  69. */
  70. const RectI& getArea() const { return mArea; }
  71. /**
  72. * @brief Returns the color to clear the viewport color buffers to.
  73. */
  74. const Color& getClearColor() const { return mClearColor; }
  75. /**
  76. * @brief Sets the color to clear the viewport color buffers to.
  77. */
  78. void setClearColor(const Color& clearColor) { mClearColor = clearColor; }
  79. /**
  80. * @brief Returns the value to clear the viewport depth buffers to.
  81. */
  82. float getClearDepthValue() const { return mDepthClearValue; }
  83. /**
  84. * @brief Sets the value to clear the viewport depth buffer to.
  85. */
  86. void setClearDepthValue(float value) { mDepthClearValue = value; }
  87. /**
  88. * @brief Returns the value to clear the viewport stencil buffer to.
  89. */
  90. UINT16 getClearStencilValue() const { return mStencilClearValue; }
  91. /**
  92. * @brief Sets the value to clear the viewport stencil buffer to.
  93. */
  94. void setStencilClearValue(UINT16 value) { mStencilClearValue = value; }
  95. /**
  96. * @brief Returns true if viewport requires color clear before rendering.
  97. */
  98. bool getRequiresColorClear() const { return mRequiresColorClear; }
  99. /**
  100. * @brief Determines should viewport color buffer be cleared before rendering.
  101. */
  102. void setRequiresColorClear(bool requiresClear) { mRequiresColorClear = requiresClear; }
  103. /**
  104. * @brief Returns true if viewport requires depth clear before rendering.
  105. */
  106. bool getRequiresDepthClear() const { return mRequiresDepthClear; }
  107. /**
  108. * @brief Determines should viewport depth buffer be cleared before rendering.
  109. */
  110. void setRequiresDepthClear(bool requiresClear) { mRequiresDepthClear = requiresClear; }
  111. /**
  112. * @brief Returns true if viewport requires stencil clear before rendering.
  113. */
  114. bool getRequiresStencilClear() const { return mRequiresStencilClear; }
  115. /**
  116. * @brief Determines should viewport stencil buffer be cleared before rendering.
  117. */
  118. void setRequiresStencilClear(bool requiresClear) { mRequiresStencilClear = requiresClear; }
  119. /**
  120. * @brief Makes an exact copy of this viewport.
  121. */
  122. Viewport clone();
  123. protected:
  124. RenderTargetPtr mTarget;
  125. RectF mNormArea;
  126. RectI mArea;
  127. bool mRequiresColorClear;
  128. bool mRequiresDepthClear;
  129. bool mRequiresStencilClear;
  130. Color mClearColor;
  131. float mDepthClearValue;
  132. UINT16 mStencilClearValue;
  133. static const Color DEFAULT_CLEAR_COLOR;
  134. void updateArea();
  135. void targetResized();
  136. };
  137. }