BsViewport.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. const Color& getClearColor() const { return mClearColor; }
  72. void setClearColor(const Color& clearColor) { mClearColor = clearColor; }
  73. float getClearDepthValue() const { return mDepthClearValue; }
  74. void getClearDepthValue(float value) { mDepthClearValue = value; }
  75. UINT16 getClearStencilValue() const { return mStencilClearValue; }
  76. void setStencilClearValue(UINT16 value) { mStencilClearValue = value; }
  77. bool getRequiresColorClear() const { return mRequiresColorClear; }
  78. void setRequiresColorClear(bool requiresClear) { mRequiresColorClear = requiresClear; }
  79. bool getRequiresDepthClear() const { return mRequiresDepthClear; }
  80. void setRequiresDepthClear(bool requiresClear) { mRequiresDepthClear = requiresClear; }
  81. bool getRequiresStencilClear() const { return mRequiresStencilClear; }
  82. void setRequiresStencilClear(bool requiresClear) { mRequiresStencilClear = requiresClear; }
  83. /**
  84. * @brief Makes an exact copy of this viewport.
  85. */
  86. Viewport clone();
  87. protected:
  88. RenderTargetPtr mTarget;
  89. RectF mNormArea;
  90. RectI mArea;
  91. bool mRequiresColorClear;
  92. bool mRequiresDepthClear;
  93. bool mRequiresStencilClear;
  94. Color mClearColor;
  95. float mDepthClearValue;
  96. UINT16 mStencilClearValue;
  97. static const Color DEFAULT_CLEAR_COLOR;
  98. void updateArea();
  99. void targetResized();
  100. };
  101. }