Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
renderer.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_RENDERER_HPP__
4 #define SCENEVIEW_RENDERER_HPP__
5 
6 #include <string>
7 
8 #include <QObject>
9 #include <QVariant>
10 
11 #include <sceneview/scene.hpp>
12 #include <sceneview/resource_manager.hpp>
13 
14 namespace sv {
15 
16 class Viewport;
17 
73 class Renderer : public QObject {
74  Q_OBJECT
75 
76  public:
80  explicit Renderer(const QString& name, QObject* parent = 0);
81 
82  Renderer(const Renderer&) = delete;
83 
84  Renderer& operator=(const Renderer&) = delete;
85 
89  const QString& Name() const { return name_; }
90 
94  Viewport* GetViewport() { return viewport_; }
95 
99  Scene::Ptr GetScene();
100 
104  ResourceManager::Ptr GetResources();
105 
115 
126  virtual void InitializeGL() {}
127 
149  virtual void RenderBegin() {}
150 
156  virtual void RenderEnd() {}
157 
164  virtual void ShutdownGL() {}
165 
169  virtual QWidget* GetWidget() { return nullptr; }
170 
179  bool Enabled() const { return enabled_; }
180 
186  virtual QVariant SaveState() { return QVariant(); }
187 
193  virtual void LoadState(const QVariant& val) {}
194 
195  signals:
196  void EnableChanged(bool enabled);
197 
198  public slots:
199  void SetEnabled(bool enabled);
200 
201  protected:
205  virtual void OnEnableChanged(bool enabled) {}
206 
207  private:
208  friend class Viewport;
209 
210  void SetViewport(Viewport* viewport);
211 
212  void SetBaseNode(GroupNode* node);
213 
214  QString name_;
215 
216  Viewport* viewport_;
217 
218  GroupNode* base_node_;
219 
220  bool enabled_;
221 };
222 
223 } // namespace sv
224 
225 #endif // SCENEVIEW_RENDERER_HPP__
A scene graph node that can have children.
Definition: group_node.hpp:26
virtual void ShutdownGL()
Override this to release any OpenGL resources acquired by the renderer.
Definition: renderer.hpp:164
const QString & Name() const
Retrieve the renderer name.
Definition: renderer.hpp:89
ResourceManager::Ptr GetResources()
Retrieve the ResourceManager for the scene.
bool Enabled() const
Definition: renderer.hpp:179
Scene::Ptr GetScene()
Retrieve the Scene graph used by the Sceneview rendering engine.
virtual void RenderEnd()
Called at the end of rendering, just after the scene has finished rendering.
Definition: renderer.hpp:156
Subclass this to add content in the scene and draw things.
Definition: renderer.hpp:73
Viewport * GetViewport()
Retrieve the viewport that manages this renderer.
Definition: renderer.hpp:94
Renderer(const QString &name, QObject *parent=0)
Construct a new renderer with the specified name.
virtual void InitializeGL()
Override to acquire OpenGL resources required by the Renderer.
Definition: renderer.hpp:126
Widget that draws a scene and manages Renderer and InputHandler objects.
Definition: viewport.hpp:27
virtual void LoadState(const QVariant &val)
Called by the viewport to restore the renderer state.
Definition: renderer.hpp:193
virtual QWidget * GetWidget()
Override this to provide a custom UI for your renderer.
Definition: renderer.hpp:169
virtual QVariant SaveState()
Called by the viewport to save the renderer state.
Definition: renderer.hpp:186
GroupNode * GetBaseNode()
Retrieve the group node assigned to this renderer.
virtual void RenderBegin()
Called at the start of rendering, just before the scene is rendered.
Definition: renderer.hpp:149