2
0

BsViewport.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. updateArea();
  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)
  18. {
  19. updateArea();
  20. }
  21. Viewport::~Viewport()
  22. { }
  23. void Viewport::targetResized()
  24. {
  25. updateArea();
  26. }
  27. void Viewport::updateArea()
  28. {
  29. if(mTarget != nullptr)
  30. {
  31. float height = (float) mTarget->getHeight();
  32. float width = (float) mTarget->getWidth();
  33. mArea.x = (int) (mNormArea.x * width);
  34. mArea.y = (int) (mNormArea.y * height);
  35. mArea.width = (int) (mNormArea.width * width);
  36. mArea.height = (int) (mNormArea.height * height);
  37. }
  38. }
  39. void Viewport::setArea(float x, float y, float width, float height)
  40. {
  41. mNormArea.x = x;
  42. mNormArea.y = y;
  43. mNormArea.width = width;
  44. mNormArea.height = height;
  45. updateArea();
  46. }
  47. Viewport Viewport::clone()
  48. {
  49. return *this;
  50. }
  51. }