Warning, /include/Geant4/tools/sg/render_gstos is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_render_gstos
0005 #define tools_sg_render_gstos
0006
0007 #include "gstos"
0008 #include "render_action"
0009
0010 #include "gstos_add"
0011
0012 namespace tools {
0013 namespace sg {
0014
0015 class render_gstos : public gstos {
0016 typedef gstos parent;
0017 public:
0018 virtual void visit(gstos_add& a_visitor,draw_type a_style) = 0;
0019 protected: //gstos
0020 virtual unsigned int create_gsto(std::ostream&,sg::render_manager& a_mgr) {
0021 std::vector<float> gsto_data;
0022
0023 gstos_add _add;
0024 visit(_add,draw_points);
0025 append(gsto_data,_add.m_xyzs);
0026 m_gstos_points_sz = _add.m_xyzs.size();
0027
0028 _add.clear();
0029 visit(_add,draw_lines);
0030 append(gsto_data,_add.m_xyzs);
0031 m_gstos_lines_sz = _add.m_xyzs.size();
0032
0033 _add.clear();
0034 visit(_add,draw_filled);
0035 append(gsto_data,_add.m_xyzs);
0036 m_gstos_tris_sz = _add.m_xyzs.size();
0037 append(gsto_data,_add.m_nms);
0038 m_gstos_nms_sz = _add.m_nms.size();
0039
0040 if(gsto_data.empty()) return 0;
0041
0042 return a_mgr.create_gsto_from_data(gsto_data);
0043 }
0044 public: //node
0045 bool gstos_render(render_action& a_action) {
0046 const state& state = a_action.state();
0047
0048 bool draw_edges = false;
0049 if(state.m_draw_type==draw_filled) draw_edges = state.m_GL_LIGHTING?false:true;
0050
0051 if(state.m_use_gsto) {
0052 unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
0053 if(_id) {
0054 bufpos pxyzs = 0;
0055 bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
0056 bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
0057 bufpos pnms = ptris+m_gstos_tris_sz*sizeof(float);
0058
0059 a_action.begin_gsto(_id);
0060 if(draw_edges) {
0061 //a_action.set_lighting(false); //NOTE : we should do that if style==draw_fill !
0062 a_action.color4f(0,0,0,1); //if lighten, then rendered grey.
0063 a_action.line_width(1);
0064
0065 a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0066
0067 //pushes back the filled polygons to avoid z-fighting with lines
0068 a_action.set_polygon_offset(true);
0069
0070 a_action.color4f(state.m_color);
0071 a_action.line_width(state.m_line_width);
0072 //a_action.set_lighting(state.m_GL_LIGHTING);
0073 }
0074 if(state.m_draw_type==draw_points) {
0075 a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
0076 } else if(state.m_draw_type==draw_lines) {
0077 a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0078 } else {
0079 a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
0080 }
0081 if(draw_edges) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
0082 a_action.end_gsto();
0083 return true;
0084
0085 } else { //!_id
0086 // use immediate rendering.
0087 }
0088
0089 } else {
0090 clean_gstos(&a_action.render_manager());
0091 }
0092 return false;
0093 }
0094 bool gstos_render_no_style(render_action& a_action) { //for sg::markers.
0095 const state& state = a_action.state();
0096 if(state.m_use_gsto) {
0097 unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
0098 if(_id) {
0099 bufpos pxyzs = 0;
0100 bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
0101 bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
0102 bufpos pnms = ptris+m_gstos_tris_sz*sizeof(float);
0103
0104 a_action.begin_gsto(_id);
0105 a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
0106 a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0107 a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
0108 a_action.end_gsto();
0109 return true;
0110
0111 } else { //!_id
0112 // use immediate rendering.
0113 }
0114
0115 } else {
0116 clean_gstos(&a_action.render_manager());
0117 }
0118 return false;
0119 }
0120 public:
0121 render_gstos():parent(),m_gstos_points_sz(0),m_gstos_lines_sz(0),m_gstos_tris_sz(0),m_gstos_nms_sz(0) {}
0122 virtual ~render_gstos() {}
0123 public:
0124 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) {}
0125 render_gstos& operator=(const render_gstos& a_from){
0126 parent::operator=(a_from);
0127 m_gstos_points_sz = 0;
0128 m_gstos_lines_sz = 0;
0129 m_gstos_tris_sz = 0;
0130 m_gstos_nms_sz = 0;
0131 return *this;
0132 }
0133 protected:
0134 size_t m_gstos_points_sz;
0135 size_t m_gstos_lines_sz;
0136 size_t m_gstos_tris_sz;
0137 size_t m_gstos_nms_sz;
0138 };
0139
0140 }}
0141
0142 #endif