BsViewport.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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)
  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)
  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. }
  28. RectI Viewport::getArea() const
  29. {
  30. float width = (float)mTarget->getWidth();
  31. float height = (float)mTarget->getHeight();
  32. RectI area;
  33. area.x = (int)(mNormArea.x * width);
  34. area.y = (int)(mNormArea.y * height);
  35. area.width = (int)(mNormArea.width * width);
  36. area.height = (int)(mNormArea.height * height);
  37. return area;
  38. }
  39. void Viewport::setRequiresClear(bool colorClear, bool depthClear, bool stencilClear)
  40. {
  41. mRequiresColorClear = colorClear;
  42. mRequiresDepthClear = depthClear;
  43. mRequiresStencilClear = stencilClear;
  44. }
  45. void Viewport::setClearValues(const Color& clearColor, float clearDepth, UINT16 clearStencil)
  46. {
  47. mClearColor = clearColor;
  48. mDepthClearValue = clearDepth;
  49. mStencilClearValue = clearStencil;
  50. }
  51. INT32 Viewport::getX() const
  52. {
  53. return (INT32)(mNormArea.x * mTarget->getWidth());
  54. }
  55. INT32 Viewport::getY() const
  56. {
  57. return (INT32)(mNormArea.y * mTarget->getHeight());
  58. }
  59. INT32 Viewport::getWidth() const
  60. {
  61. return (INT32)(mNormArea.width * mTarget->getWidth());
  62. }
  63. INT32 Viewport::getHeight() const
  64. {
  65. return (INT32)(mNormArea.height * mTarget->getHeight());
  66. }
  67. Viewport Viewport::clone()
  68. {
  69. return *this;
  70. }
  71. }