BsViewport.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "BsViewport.h"
  2. #include "BsViewportRTTI.h"
  3. #include "BsException.h"
  4. #include "BsRenderTarget.h"
  5. #include "BsMath.h"
  6. #include "BsRenderSystem.h"
  7. namespace BansheeEngine
  8. {
  9. const Color Viewport::DEFAULT_CLEAR_COLOR = Color(143.0f / 255.0f, 111.0f / 255.0f, 0);
  10. Viewport::Viewport()
  11. :mTarget(nullptr), mClearColor(DEFAULT_CLEAR_COLOR), mRequiresColorClear(true), mRequiresDepthClear(true),
  12. mRequiresStencilClear(false), mStencilClearValue(0), mDepthClearValue(1.0f), mCoreDirtyFlags(0xFFFFFFFF)
  13. {
  14. }
  15. Viewport::Viewport(const RenderTargetPtr& target, float x, float y, float width, float height)
  16. :mTarget(target), mNormArea(x, y, width, height), mClearColor(DEFAULT_CLEAR_COLOR), mRequiresColorClear(true),
  17. mRequiresDepthClear(true), mRequiresStencilClear(false), mStencilClearValue(0), mDepthClearValue(1.0f), mCoreDirtyFlags(0xFFFFFFFF)
  18. {
  19. }
  20. Viewport::~Viewport()
  21. { }
  22. void Viewport::setArea(float x, float y, float width, float height)
  23. {
  24. mNormArea.x = x;
  25. mNormArea.y = y;
  26. mNormArea.width = width;
  27. mNormArea.height = height;
  28. markCoreDirty();
  29. }
  30. Rect2I Viewport::getArea() const
  31. {
  32. float width = (float)mTarget->getProperties().getWidth();
  33. float height = (float)mTarget->getProperties().getHeight();
  34. Rect2I area;
  35. area.x = (int)(mNormArea.x * width);
  36. area.y = (int)(mNormArea.y * height);
  37. area.width = (int)(mNormArea.width * width);
  38. area.height = (int)(mNormArea.height * height);
  39. return area;
  40. }
  41. void Viewport::setRequiresClear(bool colorClear, bool depthClear, bool stencilClear)
  42. {
  43. mRequiresColorClear = colorClear;
  44. mRequiresDepthClear = depthClear;
  45. mRequiresStencilClear = stencilClear;
  46. markCoreDirty();
  47. }
  48. void Viewport::setClearValues(const Color& clearColor, float clearDepth, UINT16 clearStencil)
  49. {
  50. mClearColor = clearColor;
  51. mDepthClearValue = clearDepth;
  52. mStencilClearValue = clearStencil;
  53. markCoreDirty();
  54. }
  55. INT32 Viewport::getX() const
  56. {
  57. return (INT32)(mNormArea.x * mTarget->getProperties().getWidth());
  58. }
  59. INT32 Viewport::getY() const
  60. {
  61. return (INT32)(mNormArea.y * mTarget->getProperties().getHeight());
  62. }
  63. INT32 Viewport::getWidth() const
  64. {
  65. return (INT32)(mNormArea.width * mTarget->getProperties().getWidth());
  66. }
  67. INT32 Viewport::getHeight() const
  68. {
  69. return (INT32)(mNormArea.height * mTarget->getProperties().getHeight());
  70. }
  71. Viewport Viewport::clone()
  72. {
  73. return *this;
  74. }
  75. RTTITypeBase* Viewport::getRTTIStatic()
  76. {
  77. return ViewportRTTI::instance();
  78. }
  79. RTTITypeBase* Viewport::getRTTI() const
  80. {
  81. return Viewport::getRTTIStatic();
  82. }
  83. }