BsViewport.cpp 2.5 KB

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