Viewport.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // Copyright (c) 2008-2014 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. #pragma once
  23. #include "Object.h"
  24. #include "Ptr.h"
  25. #include "Ray.h"
  26. #include "Rect.h"
  27. #include "Vector2.h"
  28. namespace Urho3D
  29. {
  30. class Camera;
  31. class RenderPath;
  32. class Scene;
  33. class XMLFile;
  34. class View;
  35. /// %Viewport definition either for a render surface or the backbuffer.
  36. class URHO3D_API Viewport : public Object
  37. {
  38. OBJECT(Viewport);
  39. public:
  40. /// Construct with defaults.
  41. Viewport(Context* context);
  42. /// Construct with a full rectangle.
  43. Viewport(Context* context, Scene* scene, Camera* camera, RenderPath* renderPath = 0);
  44. /// Construct with a specified rectangle.
  45. Viewport(Context* context, Scene* scene, Camera* camera, const IntRect& rect, RenderPath* renderPath = 0);
  46. /// Destruct.
  47. ~Viewport();
  48. /// Set scene.
  49. void SetScene(Scene* scene);
  50. /// Set camera.
  51. void SetCamera(Camera* camera);
  52. /// Set rectangle.
  53. void SetRect(const IntRect& rect);
  54. /// Set rendering path.
  55. void SetRenderPath(RenderPath* path);
  56. /// Set rendering path from an XML file.
  57. void SetRenderPath(XMLFile* file);
  58. /// Set whether to render debug geometry. Default true.
  59. void SetDrawDebug(bool enable);
  60. /// Return scene.
  61. Scene* GetScene() const;
  62. /// Return camera.
  63. Camera* GetCamera() const;
  64. /// Return the internal rendering structure. May be null if the viewport has not been rendered yet.
  65. View* GetView() const;
  66. /// Return rectangle.
  67. const IntRect& GetRect() const { return rect_; }
  68. /// Return rendering path.
  69. RenderPath* GetRenderPath() const;
  70. /// Return whether to draw debug geometry.
  71. bool GetDrawDebug() const { return drawDebug_; }
  72. /// Return ray corresponding to normalized screen coordinates.
  73. Ray GetScreenRay(int x, int y) const;
  74. // Convert a world space point to normalized screen coordinates.
  75. IntVector2 WorldToScreenPoint(const Vector3& worldPos) const;
  76. // Convert screen coordinates and depth to a world space point.
  77. Vector3 ScreenToWorldPoint(int x, int y, float depth) const;
  78. /// Allocate the view structure. Called by Renderer.
  79. void AllocateView();
  80. private:
  81. /// Scene pointer.
  82. WeakPtr<Scene> scene_;
  83. /// Camera pointer.
  84. WeakPtr<Camera> camera_;
  85. /// Viewport rectangle.
  86. IntRect rect_;
  87. /// Rendering path.
  88. SharedPtr<RenderPath> renderPath_;
  89. /// Internal rendering structure.
  90. SharedPtr<View> view_;
  91. /// Debug draw flag.
  92. bool drawDebug_;
  93. };
  94. }