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