Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 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 19 protected: //gstos 20 virtual unsigned int create_gsto(std::ostrea 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_da 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_ed 50 51 if(state.m_use_gsto) { 52 unsigned int _id = get_gsto_id(a_action. 53 if(_id) { 54 bufpos pxyzs = 0; 55 bufpos plines = pxyzs+m_gstos_points_s 56 bufpos ptris = plines+m_gstos_lines_sz 57 bufpos pnms = ptris+m_gstos_tris_sz*s 58 59 a_action.begin_gsto(_id); 60 if(draw_edges) { 61 //a_action.set_lighting(false); //NO 62 a_action.color4f(0,0,0,1); //if ligh 63 a_action.line_width(1); 64 65 a_action.draw_gsto_v(gl::lines(),m_g 66 67 //pushes back the filled polygons to 68 a_action.set_polygon_offset(true); 69 70 a_action.color4f(state.m_color); 71 a_action.line_width(state.m_line_wid 72 //a_action.set_lighting(state.m_GL_L 73 } 74 if(state.m_draw_type==draw_points) { 75 a_action.draw_gsto_v(gl::points(),m_ 76 } else if(state.m_draw_type==draw_line 77 a_action.draw_gsto_v(gl::lines(),m_g 78 } else { 79 a_action.draw_gsto_vn(gl::triangles( 80 } 81 if(draw_edges) a_action.set_polygon_of 82 a_action.end_gsto(); 83 return true; 84 85 } else { //!_id 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_ 95 const state& state = a_action.state(); 96 if(state.m_use_gsto) { 97 unsigned int _id = get_gsto_id(a_action. 98 if(_id) { 99 bufpos pxyzs = 0; 100 bufpos plines = pxyzs+m_gstos_points_s 101 bufpos ptris = plines+m_gstos_lines_sz 102 bufpos pnms = ptris+m_gstos_tris_sz*s 103 104 a_action.begin_gsto(_id); 105 a_action.draw_gsto_v(gl::points(),m_gs 106 a_action.draw_gsto_v(gl::lines(),m_gst 107 a_action.draw_gsto_vn(gl::triangles(), 108 a_action.end_gsto(); 109 return true; 110 111 } else { //!_id 112 // use immediate rendering. 113 } 114 115 } else { 116 clean_gstos(&a_action.render_manager()); 117 } 118 return false; 119 } 120 public: 121 render_gstos():parent(),m_gstos_points_sz(0) 122 virtual ~render_gstos() {} 123 public: 124 render_gstos(const render_gstos& a_from):par 125 render_gstos& operator=(const render_gstos& 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: 134 size_t m_gstos_points_sz; 135 size_t m_gstos_lines_sz; 136 size_t m_gstos_tris_sz; 137 size_t m_gstos_nms_sz; 138 }; 139 140 }} 141 142 #endif