View3D.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../UI/Window.h"
  5. namespace Urho3D
  6. {
  7. class Camera;
  8. class Node;
  9. class Scene;
  10. class Texture2D;
  11. class Viewport;
  12. /// %UI element which renders a 3D scene.
  13. class URHO3D_API View3D : public Window
  14. {
  15. URHO3D_OBJECT(View3D, Window);
  16. public:
  17. /// Construct.
  18. explicit View3D(Context* context);
  19. /// Destruct.
  20. ~View3D() override;
  21. /// Register object factory.
  22. /// @nobind
  23. static void RegisterObject(Context* context);
  24. /// React to resize.
  25. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  26. /// Define the scene and camera to use in rendering. When ownScene is true the View3D will take ownership of them with shared pointers.
  27. void SetView(Scene* scene, Camera* camera, bool ownScene = true);
  28. /// Set render texture pixel format. Default is RGB.
  29. /// @property
  30. void SetFormat(unsigned format);
  31. /// Set render target auto update mode. Default is true.
  32. /// @property
  33. void SetAutoUpdate(bool enable);
  34. /// Queue manual update on the render texture.
  35. void QueueUpdate();
  36. /// Return render texture pixel format.
  37. /// @property
  38. unsigned GetFormat() const { return rttFormat_; }
  39. /// Return whether render target updates automatically.
  40. /// @property
  41. bool GetAutoUpdate() const { return autoUpdate_; }
  42. /// Return scene.
  43. /// @property
  44. Scene* GetScene() const;
  45. /// Return camera scene node.
  46. /// @property
  47. Node* GetCameraNode() const;
  48. /// Return render texture.
  49. /// @property
  50. Texture2D* GetRenderTexture() const;
  51. /// Return depth stencil texture.
  52. /// @property
  53. Texture2D* GetDepthTexture() const;
  54. /// Return viewport.
  55. /// @property
  56. Viewport* GetViewport() const;
  57. private:
  58. /// Reset scene.
  59. void ResetScene();
  60. /// Handle render surface update event. Queue the texture for update in case the View3D is visible and automatic update is enabled.
  61. void HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& eventData);
  62. /// Renderable texture.
  63. SharedPtr<Texture2D> renderTexture_;
  64. /// Depth stencil texture.
  65. SharedPtr<Texture2D> depthTexture_;
  66. /// Viewport.
  67. SharedPtr<Viewport> viewport_;
  68. /// Scene.
  69. SharedPtr<Scene> scene_;
  70. /// Camera scene node.
  71. SharedPtr<Node> cameraNode_;
  72. /// Own scene.
  73. bool ownScene_;
  74. /// Render texture format.
  75. unsigned rttFormat_;
  76. /// Render texture auto update mode.
  77. bool autoUpdate_;
  78. };
  79. }