UISceneView.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "UIWidget.h"
  3. #include <Atomic/Graphics/Texture2D.h>
  4. #include <Atomic/Graphics/Viewport.h>
  5. #include <Atomic/Scene/Scene.h>
  6. #include <TurboBadger/tb_widgets.h>
  7. using namespace tb;
  8. namespace Atomic
  9. {
  10. class UISceneView;
  11. class UIRenderer;
  12. class SceneViewWidget : public tb::TBWidget
  13. {
  14. friend class UISceneView;
  15. public:
  16. // For safe typecasting
  17. TBOBJECT_SUBCLASS(SceneViewWidget, tb::TBWidget);
  18. SceneViewWidget();
  19. virtual void OnPaint(const PaintProps &paint_props);
  20. private:
  21. WeakPtr<UISceneView> sceneView_;
  22. PODVector<float> vertexData_;
  23. };
  24. class UISceneView : public UIWidget
  25. {
  26. friend class SceneViewWidget;
  27. OBJECT(UISceneView)
  28. public:
  29. UISceneView(Context* context, bool createWidget = true);
  30. virtual ~UISceneView();
  31. /// React to resize.
  32. void OnResize(const IntVector2& newSize);
  33. /// Define the scene and camera to use in rendering. When ownScene is true the View3D will take ownership of them with shared pointers.
  34. void SetView(Scene* scene, Camera* camera);
  35. /// Set render texture pixel format. Default is RGB.
  36. void SetFormat(unsigned format);
  37. /// Set render target auto update mode. Default is true.
  38. void SetAutoUpdate(bool enable);
  39. /// Queue manual update on the render texture.
  40. void QueueUpdate();
  41. /// Return render texture pixel format.
  42. unsigned GetFormat() const { return rttFormat_; }
  43. /// Return whether render target updates automatically.
  44. bool GetAutoUpdate() const { return autoUpdate_; }
  45. /// Return scene.
  46. Scene* GetScene() const;
  47. /// Return camera scene node.
  48. Node* GetCameraNode() const;
  49. /// Return render texture.
  50. Texture2D* GetRenderTexture() const;
  51. /// Return depth stencil texture.
  52. Texture2D* GetDepthTexture() const;
  53. /// Return viewport.
  54. Viewport* GetViewport() const;
  55. void SetResizeRequired() {resizeRequired_ = true;}
  56. const IntVector2& GetSize() const { return size_; }
  57. protected:
  58. void HandleEndFrame(StringHash eventType, VariantMap& eventData);
  59. /// Renderable texture.
  60. SharedPtr<Texture2D> renderTexture_;
  61. /// Depth stencil texture.
  62. SharedPtr<Texture2D> depthTexture_;
  63. /// Viewport.
  64. SharedPtr<Viewport> viewport_;
  65. /// Scene.
  66. SharedPtr<Scene> scene_;
  67. /// Camera scene node.
  68. SharedPtr<Node> cameraNode_;
  69. /// Render texture format.
  70. unsigned rttFormat_;
  71. /// Render texture auto update mode.
  72. bool autoUpdate_;
  73. bool resizeRequired_;
  74. IntVector2 size_;
  75. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  76. private:
  77. UIRenderer* renderer_;
  78. };
  79. }