Viewport.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. Viewport::Viewport() :
  30. rect_(IntRect::ZERO)
  31. {
  32. }
  33. Viewport::Viewport(Scene* scene, Camera* camera) :
  34. scene_(scene),
  35. camera_(camera),
  36. rect_(IntRect::ZERO)
  37. {
  38. }
  39. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect) :
  40. scene_(scene),
  41. camera_(camera),
  42. rect_(rect)
  43. {
  44. }
  45. Viewport::Viewport(Scene* scene, Camera* camera, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  46. scene_(scene),
  47. camera_(camera),
  48. rect_(IntRect::ZERO),
  49. postProcesses_(postProcesses)
  50. {
  51. }
  52. Viewport::Viewport(Scene* scene, Camera* camera, const IntRect& rect, const Vector<SharedPtr<PostProcess> >& postProcesses) :
  53. scene_(scene),
  54. camera_(camera),
  55. rect_(rect),
  56. postProcesses_(postProcesses)
  57. {
  58. }
  59. Viewport::~Viewport()
  60. {
  61. }
  62. void Viewport::SetScene(Scene* scene)
  63. {
  64. scene_ = scene;
  65. }
  66. void Viewport::SetCamera(Camera* camera)
  67. {
  68. camera_ = camera;
  69. }
  70. void Viewport::SetRect(const IntRect& rect)
  71. {
  72. rect_ = rect;
  73. }
  74. void Viewport::AddPostProcess(PostProcess* effect)
  75. {
  76. if (!effect)
  77. return;
  78. SharedPtr<PostProcess> effectPtr(effect);
  79. if (!postProcesses_.Contains(effectPtr))
  80. postProcesses_.Push(effectPtr);
  81. }
  82. void Viewport::InsertPostProcess(unsigned index, PostProcess* effect)
  83. {
  84. if (!effect)
  85. return;
  86. SharedPtr<PostProcess> effectPtr(effect);
  87. if (postProcesses_.Contains(effectPtr))
  88. return;
  89. if (index >= postProcesses_.Size())
  90. postProcesses_.Push(effectPtr);
  91. else
  92. postProcesses_.Insert(postProcesses_.Begin() + index, effectPtr);
  93. }
  94. void Viewport::RemovePostProcess(PostProcess* effect)
  95. {
  96. for (Vector<SharedPtr<PostProcess> >::Iterator i = postProcesses_.Begin(); i != postProcesses_.End(); ++i)
  97. {
  98. if (i->Get() == effect)
  99. {
  100. postProcesses_.Erase(i);
  101. return;
  102. }
  103. }
  104. }
  105. void Viewport::RemovePostProcess(unsigned index)
  106. {
  107. postProcesses_.Erase(index);
  108. }
  109. void Viewport::RemoveAllPostProcesses()
  110. {
  111. postProcesses_.Clear();
  112. }
  113. Scene* Viewport::GetScene() const
  114. {
  115. return scene_;
  116. }
  117. Camera* Viewport::GetCamera() const
  118. {
  119. return camera_;
  120. }
  121. PostProcess* Viewport::GetPostProcess(unsigned index) const
  122. {
  123. return index < postProcesses_.Size() ? postProcesses_[index] : (PostProcess*)0;
  124. }