Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
drawable.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_DRAWABLE_HPP__
4 #define SCENEVIEW_DRAWABLE_HPP__
5 
6 #include <memory>
7 
8 #include <sceneview/geometry_resource.hpp>
9 #include <sceneview/material_resource.hpp>
10 
11 namespace sv {
12 
13 class DrawContext;
14 
15 class DrawNode;
16 
20 class Drawable {
21  public:
22  typedef std::shared_ptr<Drawable> Ptr;
23 
24  public:
25  virtual ~Drawable();
26 
27  static Ptr Create(const GeometryResource::Ptr& geometry,
28  const MaterialResource::Ptr& material) {
29  return Ptr(new Drawable(geometry, material));
30  }
31 
32  const GeometryResource::Ptr& Geometry() { return geometry_; }
33 
34  const MaterialResource::Ptr& Material() { return material_; }
35 
36  virtual void SetMaterial(const MaterialResource::Ptr& material);
37 
58  virtual bool PreDraw() { return true; }
59 
64  virtual void PostDraw() {}
65 
70  virtual const AxisAlignedBox& BoundingBox() {
71  return geometry_->BoundingBox();
72  }
73 
74  protected:
75  Drawable(const GeometryResource::Ptr& geometry,
76  const MaterialResource::Ptr& material);
77 
81  void BoundingBoxChanged();
82 
83  private:
84  friend class DrawNode;
85 
86  friend class GeometryResource;
87 
88  void AddListener(DrawNode* listener);
89 
90  void RemoveListener(DrawNode* listener);
91 
92  std::vector<DrawNode*> listeners_;
93 
94  GeometryResource::Ptr geometry_;
95  MaterialResource::Ptr material_;
96 };
97 
98 } // namespace sv
99 
100 #endif // SCENEVIEW_DRAWABLE_HPP__
void BoundingBoxChanged()
Call this when the bounding box changes.
Fundamental drawable unit.
Definition: drawable.hpp:20
Geometry that can be rendered with glDrawArrays() or glDrawElements().
Definition: geometry_resource.hpp:91
An axis-aligned box typically used for bounding box and intersection calculations.
Definition: axis_aligned_box.hpp:17
virtual void PostDraw()
Called by the render engine just after rendering the geometry referenced by this object.
Definition: drawable.hpp:64
Scene node that contains a list of drawable objects.
Definition: draw_node.hpp:26
virtual const AxisAlignedBox & BoundingBox()
Called by the render engine to determine the axis-aligned bounding box of the Drawable, in the Drawable's own coordinate frame.
Definition: drawable.hpp:70
virtual bool PreDraw()
Called by the render engine just before rendering the geometry referenced by this object...
Definition: drawable.hpp:58