UISceneView.h 2.5 KB

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