View3D.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // Copyright (c) 2008-2020 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 "../UI/Window.h"
  24. namespace Urho3D
  25. {
  26. class Camera;
  27. class Node;
  28. class Scene;
  29. class Texture2D;
  30. class Viewport;
  31. /// %UI element which renders a 3D scene.
  32. class URHO3D_API View3D : public Window
  33. {
  34. URHO3D_OBJECT(View3D, Window);
  35. public:
  36. /// Construct.
  37. explicit View3D(Context* context);
  38. /// Destruct.
  39. ~View3D() override;
  40. /// Register object factory.
  41. static void RegisterObject(Context* context);
  42. /// React to resize.
  43. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  44. /// Define the scene and camera to use in rendering. When ownScene is true the View3D will take ownership of them with shared pointers.
  45. void SetView(Scene* scene, Camera* camera, bool ownScene = true);
  46. /// Set render texture pixel format. Default is RGB.
  47. /// @property
  48. void SetFormat(unsigned format);
  49. /// Set render target auto update mode. Default is true.
  50. /// @property
  51. void SetAutoUpdate(bool enable);
  52. /// Queue manual update on the render texture.
  53. void QueueUpdate();
  54. /// Return render texture pixel format.
  55. /// @property
  56. unsigned GetFormat() const { return rttFormat_; }
  57. /// Return whether render target updates automatically.
  58. /// @property
  59. bool GetAutoUpdate() const { return autoUpdate_; }
  60. /// Return scene.
  61. /// @property
  62. Scene* GetScene() const;
  63. /// Return camera scene node.
  64. /// @property
  65. Node* GetCameraNode() const;
  66. /// Return render texture.
  67. /// @property
  68. Texture2D* GetRenderTexture() const;
  69. /// Return depth stencil texture.
  70. /// @property
  71. Texture2D* GetDepthTexture() const;
  72. /// Return viewport.
  73. /// @property
  74. Viewport* GetViewport() const;
  75. private:
  76. /// Reset scene.
  77. void ResetScene();
  78. /// Handle render surface update event. Queue the texture for update in case the View3D is visible and automatic update is enabled.
  79. void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
  80. /// Renderable texture.
  81. SharedPtr<Texture2D> renderTexture_;
  82. /// Depth stencil texture.
  83. SharedPtr<Texture2D> depthTexture_;
  84. /// Viewport.
  85. SharedPtr<Viewport> viewport_;
  86. /// Scene.
  87. SharedPtr<Scene> scene_;
  88. /// Camera scene node.
  89. SharedPtr<Node> cameraNode_;
  90. /// Own scene.
  91. bool ownScene_;
  92. /// Render texture format.
  93. unsigned rttFormat_;
  94. /// Render texture auto update mode.
  95. bool autoUpdate_;
  96. };
  97. }