DI-Guy SDK Documentation  13.1
diguyOsgGraphicsLink.h
Go to the documentation of this file.
1 #ifndef diguyOsgGraphicsLink_h__
2 #define diguyOsgGraphicsLink_h__
3 
4 
5 /*********************************************************************
6  **
7  *2 diguyOsgGraphicsLink
8  **
9  */
10 
11 #include <diguyGraphicsLink.h>
12 
13 #include <osg/Group>
14 #include <osg/MatrixTransform>
15 #include <osgViewer/Viewer>
16 
17 class diguyGraphicsState;
23 
24 
25 /**********************************************************************
26  **
27  ** diguyRootNode acts as an OSG fast culler and lod picker, avoids
28  ** many wasteful traversals of the internal diguy hierarchy. Can save 90% over naive
29  ** osg culling calculations and traversal.
30  */
31 class diguyOsgRootNode : public osg::MatrixTransform
32 {
33 public :
35  void traverse(osg::NodeVisitor& nv);
36 
38  void add_geode_for_fast_draw(diguyOsgGraphicsShape * shape, osg::Geode* geode, int lod)
39  {
40  if(lod >= m_lod_drawables.size()){
41  m_lod_drawables.resize(lod+1);
42  }
43  m_lod_drawables[lod].push_back(diguyOsgGraphicsShapeGeodeMap(shape, geode));
44  }
45  void add_switch_for_fast_draw(diguyOsgGraphicsShape * shape, osg::Switch* switch_node)
46  {
47  m_switch_nodes.push_back(diguyOsgGraphicsShapeSwitchMap(shape, switch_node));
48  }
49 
50 private:
51  // two pairs for tracking shape geode and shape switch connections
53  {
54  diguyOsgGraphicsShapeGeodeMap(diguyOsgGraphicsShape * shape, osg::Geode* geode) :
55  m_shape(shape), m_geode(geode) {}
56 
58  osg::Geode* m_geode;
59  };
61  {
62  diguyOsgGraphicsShapeSwitchMap(diguyOsgGraphicsShape * shape, osg::Switch* switch_node) :
63  m_shape(shape), m_switch(switch_node){}
64 
66  osg::Switch* m_switch;
67  };
68 
69  std::vector<diguyOsgGraphicsShapeSwitchMap> m_switch_nodes;
70  std::vector<std::vector<diguyOsgGraphicsShapeGeodeMap> > m_lod_drawables;
71 
73 };
74 
75 /**********************************************************************
76  **
77  ** Class declaration. diguyOsgGraphicsLink publicly inherits
78  ** diguyGraphicsLink. Virtual functions are declared for some of the
79  ** virtual functions in the base class.
80  */
82 {
83 
84 public:
85 
86  diguyOsgGraphicsLink(void* internal_data);
87 
88  virtual void build();
89 
90 
91  virtual void unbuild();
92  virtual void update();
93  virtual void attach_to_scene();
94  virtual void detach_from_scene();
95  virtual void instancing_state_changed(int is_instanced);
96  virtual void set_shader_instance(diguyGraphicsShaderInstance* shader_instance);
97 
98  virtual void post_build();
99 
100  osg::MatrixTransform* get_dof_node() {return m_dof_node.get();}
101  osg::StateSet* get_top_level_state_set();
102 
103  static osg::Group* get_instancing_attach_node() { return s_diguy_instancing_attach_pt; }
104 
105  static void set_diguy_attach_ptr(osg::Group* diguy_attach_pt);
107  static osgViewer::Viewer* get_viewer() {return s_viewer; }
108  static void set_viewer(osgViewer::Viewer* viewer) {s_viewer = viewer;}
111  osg::Geode * get_bounding_sphere_visual(){return m_bounding_sphere_visual.get();}
113 protected:
114  friend class diguyOsgGraphicsShape;
115  friend class diguyOsgRootNode;
116 
117  osg::Geode* make_bounding_sphere_visual(osg::Vec3& center, float radius);
118 
119  osg::ref_ptr<osg::Texture2D> get_default_variation_texture();
120 
121 // diguyGraphicsState* get_top_level_graphics_state();
122 // void recursive_post_build(diguyGraphicsState* first_state);
123 
124 
125  osg::ref_ptr<osg::Uniform> m_ufrm_link_matrix;
127  // vars that are probably only relevant to the base link
128  osg::ref_ptr<osg::MatrixTransform> m_dof_node;
129  osg::ref_ptr<osg::Uniform> m_ufrm_inverse_transform_matrix;
130  osg::ref_ptr<osg::Uniform> m_ufrm_eye_point_os;
131  osg::ref_ptr<osg::Uniform> m_ufrm_light_dir_os;
132  osg::ref_ptr<osg::Uniform> m_ufrm_emission_color;
134  osg::ref_ptr<osg::Geode> m_bounding_sphere_visual;
135 
139  static osg::Group* s_diguy_attach_pt;
140  static osg::Group* s_diguy_instancing_attach_pt;
141  static osgViewer::Viewer* s_viewer;
142  static osg::ref_ptr<osg::Texture2D> sm_degenerate_texture;
143  int m_instanced;
144 };
145 
146 
152 #endif // diguyOsgGraphicsLink_h__
153 
154 
Definition: diguyOsgGraphicsShaderProgram.h:22
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:55
void add_geode_for_fast_draw(diguyOsgGraphicsShape *shape, osg::Geode *geode, int lod)
Definition: diguyOsgGraphicsLink.h:37
Definition: diguyOsgGraphicsState.h:21
std::vector< diguyOsgGraphicsShapeSwitchMap > m_switch_nodes
Definition: diguyOsgGraphicsLink.h:68
diguyOsgRootNode(diguyOsgGraphicsLink *link)
Definition: diguyOsgGraphicsLink.cpp:84
Definition: diguyOsgGraphicsShaderInstance.h:21
osg::Geode * m_geode
Definition: diguyOsgGraphicsLink.h:57
Definition: diguyOsgGraphicsLink.h:30
osg::Switch * m_switch
Definition: diguyOsgGraphicsLink.h:65
A class that represents a shared material/textures combination.
Definition: diguyGraphicsState.h:37
Definition: diguyOsgGraphicsLink.h:59
void traverse(osg::NodeVisitor &nv)
Definition: diguyOsgGraphicsLink.cpp:94
diguyOsgGraphicsShape * m_shape
Definition: diguyOsgGraphicsLink.h:64
Definition: diguyOsgGraphicsLink.h:51
Definition: diguyOsgGraphicsShape.h:23
std::vector< std::vector< diguyOsgGraphicsShapeGeodeMap > > m_lod_drawables
Definition: diguyOsgGraphicsLink.h:69
diguyOsgGraphicsShapeSwitchMap(diguyOsgGraphicsShape *shape, osg::Switch *switch_node)
Definition: diguyOsgGraphicsLink.h:61
diguyOsgGraphicsShape * m_shape
Definition: diguyOsgGraphicsLink.h:56
osg::ref_ptr< osgViewer::Viewer > viewer
4 Header files and forward declarations
Definition: simple_playback_osg_2.cpp:43
void remove_shape(diguyOsgGraphicsShape *shape)
Definition: diguyOsgGraphicsLink.cpp:175
void add_switch_for_fast_draw(diguyOsgGraphicsShape *shape, osg::Switch *switch_node)
Definition: diguyOsgGraphicsLink.h:44
diguyOsgGraphicsLink * m_link
Definition: diguyOsgGraphicsLink.h:71
diguyOsgGraphicsShapeGeodeMap(diguyOsgGraphicsShape *shape, osg::Geode *geode)
Definition: diguyOsgGraphicsLink.h:53