Viewport.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Camera.h"
  25. #include "PostProcess.h"
  26. #include "Scene.h"
  27. #include "Viewport.h"
  28. #include "DebugNew.h"
  29. namespace Urho3D
  30. {
  31. Viewport::Viewport() :
  32. rect_(IntRect::ZERO)
  33. {
  34. }
  35. Viewport::Viewport(Scene* scene, Camera* camera) :
  36. scene_(scene),
  37. camera_(camera),
  38. rect_(IntRect::ZERO)
  39. {
  40. }
  41. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect) :
  42. scene_(scene),
  43. camera_(camera),
  44. rect_(rect)
  45. {
  46. }
  47. Viewport::Viewport(Scene* scene, Camera* camera, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  48. scene_(scene),
  49. camera_(camera),
  50. rect_(IntRect::ZERO),
  51. postProcesses_(postProcesses)
  52. {
  53. }
  54. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  55. scene_(scene),
  56. camera_(camera),
  57. rect_(rect),
  58. postProcesses_(postProcesses)
  59. {
  60. }
  61. Viewport::~Viewport()
  62. {
  63. }
  64. void Viewport::SetScene(Scene* scene)
  65. {
  66. scene_ = scene;
  67. }
  68. void Viewport::SetCamera(Camera* camera)
  69. {
  70. camera_ = camera;
  71. }
  72. void Viewport::SetRect(const IntRect& rect)
  73. {
  74. rect_ = rect;
  75. }
  76. void Viewport::AddPostProcess(PostProcess* effect)
  77. {
  78. if (!effect)
  79. return;
  80. SharedPtr<PostProcess> effectPtr(effect);
  81. if (!postProcesses_.Contains(effectPtr))
  82. postProcesses_.Push(effectPtr);
  83. }
  84. void Viewport::InsertPostProcess(unsigned index, PostProcess* effect)
  85. {
  86. if (!effect)
  87. return;
  88. SharedPtr<PostProcess> effectPtr(effect);
  89. if (postProcesses_.Contains(effectPtr))
  90. return;
  91. if (index >= postProcesses_.Size())
  92. postProcesses_.Push(effectPtr);
  93. else
  94. postProcesses_.Insert(postProcesses_.Begin() + index, effectPtr);
  95. }
  96. void Viewport::RemovePostProcess(PostProcess* effect)
  97. {
  98. for (Vector<SharedPtr<PostProcess> >::Iterator i = postProcesses_.Begin(); i != postProcesses_.End(); ++i)
  99. {
  100. if (i->Get() == effect)
  101. {
  102. postProcesses_.Erase(i);
  103. return;
  104. }
  105. }
  106. }
  107. void Viewport::RemovePostProcess(unsigned index)
  108. {
  109. postProcesses_.Erase(index);
  110. }
  111. void Viewport::RemoveAllPostProcesses()
  112. {
  113. postProcesses_.Clear();
  114. }
  115. Scene* Viewport::GetScene() const
  116. {
  117. return scene_;
  118. }
  119. Camera* Viewport::GetCamera() const
  120. {
  121. return camera_;
  122. }
  123. PostProcess* Viewport::GetPostProcess(unsigned index) const
  124. {
  125. return index < postProcesses_.Size() ? postProcesses_[index] : (PostProcess*)0;
  126. }
  127. }