Viewport.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Camera.h"
  24. #include "Graphics.h"
  25. #include "Log.h"
  26. #include "Renderer.h"
  27. #include "RenderPath.h"
  28. #include "ResourceCache.h"
  29. #include "Scene.h"
  30. #include "StringUtils.h"
  31. #include "Viewport.h"
  32. #include "XMLFile.h"
  33. #include "DebugNew.h"
  34. namespace Urho3D
  35. {
  36. OBJECTTYPESTATIC(Viewport);
  37. Viewport::Viewport(Context* context) :
  38. Object(context),
  39. rect_(IntRect::ZERO)
  40. {
  41. SetRenderPath((RenderPath*)0);
  42. }
  43. Viewport::Viewport(Context* context, Scene* scene, Camera* camera, RenderPath* renderPath) :
  44. Object(context),
  45. scene_(scene),
  46. camera_(camera),
  47. rect_(IntRect::ZERO)
  48. {
  49. SetRenderPath(renderPath);
  50. }
  51. Viewport::Viewport(Context* context, Scene* scene, Camera* camera, const IntRect& rect, RenderPath* renderPath) :
  52. Object(context),
  53. scene_(scene),
  54. camera_(camera),
  55. rect_(rect)
  56. {
  57. SetRenderPath(renderPath);
  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::SetRenderPath(RenderPath* renderPath)
  75. {
  76. if (renderPath)
  77. renderPath_ = renderPath;
  78. else
  79. {
  80. Renderer* renderer = GetSubsystem<Renderer>();
  81. if (renderer)
  82. renderPath_ = renderer->GetDefaultRenderPath();
  83. }
  84. }
  85. void Viewport::SetRenderPath(XMLFile* file)
  86. {
  87. SharedPtr<RenderPath> newRenderPath(new RenderPath());
  88. if (newRenderPath->Load(file))
  89. renderPath_ = newRenderPath;
  90. }
  91. Scene* Viewport::GetScene() const
  92. {
  93. return scene_;
  94. }
  95. Camera* Viewport::GetCamera() const
  96. {
  97. return camera_;
  98. }
  99. RenderPath* Viewport::GetRenderPath() const
  100. {
  101. return renderPath_;
  102. }
  103. }