BsViewport.cpp 2.4 KB

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