BsViewport.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 Activates or deactivates clears for color, depth or stencil buffers.
  73. * Buffers will be cleared before rendering to this viewport is performed.
  74. */
  75. void setRequiresClear(bool colorClear, bool depthClear, bool stencilClear);
  76. /**
  77. * @brief Sets values to clear color, depth and stencil buffers to.
  78. */
  79. void setClearValues(const Color& clearColor, float clearDepth = 0.0f, UINT16 clearStencil = 0);
  80. /**
  81. * @brief Returns the color to clear the viewport color buffers to.
  82. */
  83. const Color& getClearColor() const { return mClearColor; }
  84. /**
  85. * @brief Returns the value to clear the viewport depth buffers to.
  86. */
  87. float getClearDepthValue() const { return mDepthClearValue; }
  88. /**
  89. * @brief Returns the value to clear the viewport stencil buffer to.
  90. */
  91. UINT16 getClearStencilValue() const { return mStencilClearValue; }
  92. /**
  93. * @brief Returns true if viewport requires color clear before rendering.
  94. */
  95. bool getRequiresColorClear() const { return mRequiresColorClear; }
  96. /**
  97. * @brief Returns true if viewport requires depth clear before rendering.
  98. */
  99. bool getRequiresDepthClear() const { return mRequiresDepthClear; }
  100. /**
  101. * @brief Returns true if viewport requires stencil clear before rendering.
  102. */
  103. bool getRequiresStencilClear() const { return mRequiresStencilClear; }
  104. /**
  105. * @brief Makes an exact copy of this viewport.
  106. */
  107. Viewport clone();
  108. protected:
  109. RenderTargetPtr mTarget;
  110. RectF mNormArea;
  111. RectI mArea;
  112. bool mRequiresColorClear;
  113. bool mRequiresDepthClear;
  114. bool mRequiresStencilClear;
  115. Color mClearColor;
  116. float mDepthClearValue;
  117. UINT16 mStencilClearValue;
  118. static const Color DEFAULT_CLEAR_COLOR;
  119. void updateArea();
  120. void targetResized();
  121. };
  122. }