UIView3D.h 2.7 KB

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