2
0

CmViewport.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCommonEnums.h"
  4. #include "CmColor.h"
  5. #include "CmRectI.h"
  6. #include "CmRectF.h"
  7. #include <boost/signals/connection.hpp>
  8. namespace CamelotFramework
  9. {
  10. /**
  11. * @brief Viewport provides you with a way to render to only a part of a
  12. * RenderTarget. It also allows you to set up color/depth/stencil
  13. * clear values for that specific region.
  14. */
  15. class CM_EXPORT Viewport
  16. {
  17. public:
  18. Viewport();
  19. /**
  20. * @brief Constructs a new viewport.
  21. *
  22. * @note Viewport coordinates are normalized in [0, 1] range.
  23. */
  24. Viewport(const RenderTargetPtr& target, float x = 0.0f, float y = 0.0f, float width = 1.0f, float height = 1.0f);
  25. virtual ~Viewport();
  26. /**
  27. * @brief Returns the render target the viewport is associated with.
  28. */
  29. RenderTargetPtr getTarget() const { return mTarget; }
  30. /**
  31. * @brief Gets the normalized x coordinate of the viewport, in [0, 1] range.
  32. */
  33. float getNormalizedX() const { return mNormArea.x; }
  34. /**
  35. * @brief Gets the normalized y coordinate of the viewport, in [0, 1] range.
  36. */
  37. float getNormalizedY() const { return mNormArea.y; }
  38. /**
  39. * @brief Gets the normalized width of the viewport, in [0, 1] range.
  40. */
  41. float getNormalizedWidth() const { return mNormArea.width; }
  42. /**
  43. * @brief Gets the normalized height of the viewport, in [0, 1] range.
  44. */
  45. float getNormalizedHeight() const { return mNormArea.height; }
  46. /**
  47. * @brief Gets the actual x coordinate of the viewport in pixels, in [0, RenderTargetWidth] range.
  48. */
  49. INT32 getX() const { return mArea.x; }
  50. /**
  51. * @brief Gets the actual y coordinate of the viewport in pixels, in [0, RenderTargetHeight] range.
  52. */
  53. INT32 getY() const { return mArea.y; }
  54. /**
  55. * @brief Gets the actual width coordinate of the viewport in pixels, in [0, RenderTargetWidth] range.
  56. */
  57. INT32 getWidth() const { return mArea.width; }
  58. /**
  59. * @brief Gets the actual height coordinate of the viewport in pixels, in [0, RenderTargetHeight] range.
  60. */
  61. INT32 getHeight() const { return mArea.height; }
  62. /**
  63. * @brief Changes the area that the viewport covers.
  64. *
  65. * @note Viewport coordinates are normalized in [0, 1] range.
  66. */
  67. void setArea(float x, float y, float width, float height);
  68. /**
  69. * @brief Returns actual area of the viewport, in pixels.
  70. */
  71. const RectI& getArea() const { return mArea; }
  72. const Color& getClearColor() const { return mClearColor; }
  73. void setClearColor(const Color& clearColor) { mClearColor = clearColor; }
  74. float getClearDepthValue() const { return mDepthClearValue; }
  75. void getClearDepthValue(float value) { mDepthClearValue = value; }
  76. UINT16 getClearStencilValue() const { return mStencilClearValue; }
  77. void setStencilClearValue(UINT16 value) { mStencilClearValue = value; }
  78. bool getRequiresColorClear() const { return mRequiresColorClear; }
  79. void setRequiresColorClear(bool requiresClear) { mRequiresColorClear = requiresClear; }
  80. bool getRequiresDepthClear() const { return mRequiresDepthClear; }
  81. void setRequiresDepthClear(bool requiresClear) { mRequiresDepthClear = requiresClear; }
  82. bool getRequiresStencilClear() const { return mRequiresStencilClear; }
  83. void setRequiresStencilClear(bool requiresClear) { mRequiresStencilClear = requiresClear; }
  84. boost::signal<void()> onResized;
  85. protected:
  86. RenderTargetPtr mTarget;
  87. RectF mNormArea;
  88. RectI mArea;
  89. bool mRequiresColorClear;
  90. bool mRequiresDepthClear;
  91. bool mRequiresStencilClear;
  92. Color mClearColor;
  93. float mDepthClearValue;
  94. UINT16 mStencilClearValue;
  95. boost::signals::connection mTargetResizedConn;
  96. static const Color DEFAULT_CLEAR_COLOR;
  97. void updateArea();
  98. void targetResized();
  99. };
  100. }