g4tools  5.4.0
render_gstos
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_render_gstos
5 #define tools_sg_render_gstos
6 
7 #include "gstos"
8 #include "render_action"
9 
10 #include "gstos_add"
11 
12 namespace tools {
13 namespace sg {
14 
15 class render_gstos : public gstos {
16  typedef gstos parent;
17 public:
18  virtual void visit(gstos_add& a_visitor,draw_type a_style) = 0;
19 protected: //gstos
20  virtual unsigned int create_gsto(std::ostream&,sg::render_manager& a_mgr) {
21  std::vector<float> gsto_data;
22 
23  gstos_add _add;
24  visit(_add,draw_points);
25  append(gsto_data,_add.m_xyzs);
26  m_gstos_points_sz = _add.m_xyzs.size();
27 
28  _add.clear();
29  visit(_add,draw_lines);
30  append(gsto_data,_add.m_xyzs);
31  m_gstos_lines_sz = _add.m_xyzs.size();
32 
33  _add.clear();
34  visit(_add,draw_filled);
35  append(gsto_data,_add.m_xyzs);
36  m_gstos_tris_sz = _add.m_xyzs.size();
37  append(gsto_data,_add.m_nms);
38  m_gstos_nms_sz = _add.m_nms.size();
39 
40  if(gsto_data.empty()) return 0;
41 
42  return a_mgr.create_gsto_from_data(gsto_data);
43  }
44 public: //node
45  bool gstos_render(render_action& a_action) {
46  const state& state = a_action.state();
47 
48  bool draw_edges = false;
49  if(state.m_draw_type==draw_filled) draw_edges = state.m_GL_LIGHTING?false:true;
50 
51  if(state.m_use_gsto) {
52  unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
53  if(_id) {
54  bufpos pxyzs = 0;
55  bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
56  bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
57  bufpos pnms = ptris+m_gstos_tris_sz*sizeof(float);
58 
59  a_action.begin_gsto(_id);
60  if(draw_edges) {
61  //a_action.set_lighting(false); //NOTE : we should do that if style==draw_fill !
62  a_action.color4f(0,0,0,1); //if lighten, then rendered grey.
63  a_action.line_width(1);
64 
65  a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
66 
67  //pushes back the filled polygons to avoid z-fighting with lines
68  a_action.set_polygon_offset(true);
69 
70  a_action.color4f(state.m_color);
71  a_action.line_width(state.m_line_width);
72  //a_action.set_lighting(state.m_GL_LIGHTING);
73  }
75  a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
76  } else if(state.m_draw_type==draw_lines) {
77  a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
78  } else {
79  a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
80  }
81  if(draw_edges) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
82  a_action.end_gsto();
83  return true;
84 
85  } else {
86  // use immediate rendering.
87  }
88 
89  } else {
90  clean_gstos(&a_action.render_manager());
91  }
92  return false;
93  }
94  bool gstos_render_no_style(render_action& a_action) { //for sg::markers.
95  const state& state = a_action.state();
96  if(state.m_use_gsto) {
97  unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
98  if(_id) {
99  bufpos pxyzs = 0;
100  bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
101  bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
102  bufpos pnms = ptris+m_gstos_tris_sz*sizeof(float);
103 
104  a_action.begin_gsto(_id);
105  a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
106  a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
107  a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
108  a_action.end_gsto();
109  return true;
110 
111  } else {
112  // use immediate rendering.
113  }
114 
115  } else {
116  clean_gstos(&a_action.render_manager());
117  }
118  return false;
119  }
120 public:
122  virtual ~render_gstos() {}
123 public:
126  parent::operator=(a_from);
127  m_gstos_points_sz = 0;
128  m_gstos_lines_sz = 0;
129  m_gstos_tris_sz = 0;
130  m_gstos_nms_sz = 0;
131  return *this;
132  }
133 protected:
138 };
139 
140 }}
141 
142 #endif
tools::sg::render_gstos::render_gstos
render_gstos(const render_gstos &a_from)
Definition: render_gstos:124
tools::sg::gstos
Definition: gstos:16
tools::sg::render_gstos::m_gstos_tris_sz
size_t m_gstos_tris_sz
Definition: render_gstos:136
tools::sg::render_gstos::operator=
render_gstos & operator=(const render_gstos &a_from)
Definition: render_gstos:125
tools::sg::render_gstos::m_gstos_points_sz
size_t m_gstos_points_sz
Definition: render_gstos:134
tools::sg::render_action::draw_gsto_v
virtual void draw_gsto_v(gl::mode_t, size_t, bufpos)=0
tools::sg::state
Definition: state:25
tools::sg::state::m_GL_LIGHTING
bool m_GL_LIGHTING
Definition: state:248
tools::gl::triangles
mode_t triangles()
Definition: glprims:20
gstos_add
tools::sg::render_gstos::gstos_render
bool gstos_render(render_action &a_action)
Definition: render_gstos:45
render_action
tools::sg::state::m_GL_POLYGON_OFFSET_FILL
bool m_GL_POLYGON_OFFSET_FILL
Definition: state:250
tools::sg::gstos::clean_gstos
void clean_gstos()
Definition: gstos:89
tools::gl::lines
mode_t lines()
Definition: glprims:17
tools::sg::render_gstos::~render_gstos
virtual ~render_gstos()
Definition: render_gstos:122
tools::sg::gstos_add::m_xyzs
std::vector< float > m_xyzs
Definition: gstos_add:109
tools::sg::render_gstos::visit
virtual void visit(gstos_add &a_visitor, draw_type a_style)=0
tools::sg::draw_points
@ draw_points
Definition: enums:191
tools::sg::render_action::color4f
virtual void color4f(float, float, float, float)=0
tools::sg::render_gstos
Definition: render_gstos:15
tools::sg::gstos::operator=
gstos & operator=(const gstos &a_from)
Definition: gstos:22
tools::sg::render_gstos::gstos_render_no_style
bool gstos_render_no_style(render_action &a_action)
Definition: render_gstos:94
tools::sg::render_gstos::m_gstos_lines_sz
size_t m_gstos_lines_sz
Definition: render_gstos:135
tools::sg::render_manager::create_gsto_from_data
virtual unsigned int create_gsto_from_data(size_t, const float *)=0
tools::sg::render_gstos::create_gsto
virtual unsigned int create_gsto(std::ostream &, sg::render_manager &a_mgr)
Definition: render_gstos:20
tools::sg::state::m_use_gsto
bool m_use_gsto
Definition: state:256
tools::append
void append(std::vector< T > &a_vec, const std::vector< T > &a_from)
Definition: vmanip:66
tools::sg::render_manager
Definition: render_manager:16
tools::sg::draw_filled
@ draw_filled
Definition: enums:193
tools::sg::render_gstos::m_gstos_nms_sz
size_t m_gstos_nms_sz
Definition: render_gstos:137
tools::sg::render_action::set_polygon_offset
virtual void set_polygon_offset(bool)=0
tools::sg::draw_type
draw_type
Definition: enums:190
tools::gl::points
mode_t points()
Definition: glprims:16
tools::sg::render_action::render_manager
virtual sg::render_manager & render_manager()=0
gstos
tools::sg::render_action
Definition: render_action:24
tools::sg::gstos::get_gsto_id
unsigned int get_gsto_id(std::ostream &a_out, render_manager &a_mgr)
Definition: gstos:60
tools::sg::render_gstos::render_gstos
render_gstos()
Definition: render_gstos:121
tools::sg::render_action::begin_gsto
virtual void begin_gsto(gstoid)=0
VBO /////////////////////////////////////////////////////////.
tools::sg::render_action::draw_gsto_vn
virtual void draw_gsto_vn(gl::mode_t, size_t, bufpos, bufpos)=0
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::gstos_add
Definition: gstos_add:15
tools::sg::render_action::end_gsto
virtual void end_gsto()=0
tools::sg::action::out
std::ostream & out() const
Definition: action:51
tools::sg::gstos_add::clear
void clear()
Definition: gstos_add:23
tools::sg::bufpos
size_t bufpos
Definition: render_action:22
tools::sg::gstos_add::m_nms
std::vector< float > m_nms
Definition: gstos_add:110
tools::sg::state::m_line_width
float m_line_width
Definition: state:267
tools::sg::state::m_color
colorf m_color
Definition: state:259
tools::sg::render_action::line_width
virtual void line_width(float)=0
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::state::m_draw_type
draw_type m_draw_type
Definition: state:264
tools::sg::draw_lines
@ draw_lines
Definition: enums:192