Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_draw_style 5 #define tools_sg_draw_style 6 7 #include "node" 8 9 #include "lpat" 10 #include "sf_enum" 11 #include "render_action" 12 #include "pick_action" 13 #include "bbox_action" 14 15 namespace tools { 16 namespace sg { 17 18 class draw_style : public node { 19 TOOLS_NODE(draw_style,tools::sg::draw_style,node) 20 public: 21 sf_enum<draw_type> style; 22 sf<float> line_width; 23 sf<lpat> line_pattern; 24 sf<float> point_size; 25 sf<bool> cull_face; 26 sf<bool> winding_ccw; 27 public: 28 virtual const desc_fields& node_desc_fields() const { 29 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::draw_style) 30 static const desc_fields s_v(parent::node_desc_fields(),6, //WARNING : take care of count. 31 TOOLS_ARG_FIELD_DESC(style), 32 TOOLS_ARG_FIELD_DESC(line_width), 33 TOOLS_ARG_FIELD_DESC(line_pattern), 34 TOOLS_ARG_FIELD_DESC(point_size), 35 TOOLS_ARG_FIELD_DESC(cull_face), 36 TOOLS_ARG_FIELD_DESC(winding_ccw) 37 ); 38 return s_v; 39 } 40 private: 41 void add_fields(){ 42 add_field(&style); 43 add_field(&line_width); 44 add_field(&line_pattern); 45 add_field(&point_size); 46 add_field(&cull_face); 47 add_field(&winding_ccw); 48 } 49 public: 50 virtual void render(render_action& a_action) { 51 state& state = a_action.state(); 52 _set_state(state); 53 54 if(style.value()==draw_lines) { 55 //no LINE_STIPPLE in GLES. 56 //::glEnable(GL_LINE_STIPPLE); //done in viewer::render() 57 //::glLineStipple(1,line_pattern.value()); 58 a_action.line_width(state.m_line_width); 59 } else if(style.value()==draw_points) { 60 a_action.point_size(state.m_point_size); 61 } else if(style.value()==draw_filled) { 62 a_action.set_cull_face(state.m_GL_CULL_FACE); 63 a_action.set_winding(state.m_winding); 64 } 65 } 66 virtual void pick(pick_action& a_action) {_set_state(a_action.state());} 67 virtual void bbox(bbox_action& a_action) {_set_state(a_action.state());} 68 public: 69 draw_style() 70 :parent() 71 ,style(draw_filled) 72 ,line_width(1) //NOTE : 0 induces a 501 gl error. 73 ,line_pattern(line_solid) 74 ,point_size(1) 75 ,cull_face(true) 76 ,winding_ccw(true) 77 { 78 add_fields(); 79 } 80 virtual ~draw_style(){} 81 public: 82 draw_style(const draw_style& a_from) 83 :parent(a_from) 84 ,style(a_from.style) 85 ,line_width(a_from.line_width) 86 ,line_pattern(a_from.line_pattern) 87 ,point_size(a_from.point_size) 88 ,cull_face(a_from.cull_face) 89 ,winding_ccw(a_from.winding_ccw) 90 { 91 add_fields(); 92 } 93 draw_style& operator=(const draw_style& a_from){ 94 parent::operator=(a_from); 95 96 style = a_from.style; 97 line_width = a_from.line_width; 98 line_pattern = a_from.line_pattern; 99 point_size = a_from.point_size; 100 cull_face = a_from.cull_face; 101 winding_ccw = a_from.winding_ccw; 102 103 return *this; 104 } 105 protected: 106 void _set_state(state& a_state) { 107 a_state.m_draw_type = style; 108 a_state.m_line_width = line_width; 109 a_state.m_line_pattern = line_pattern; 110 a_state.m_point_size = point_size; 111 a_state.m_GL_CULL_FACE = cull_face; 112 a_state.m_winding = winding_ccw.value()?sg::winding_ccw:sg::winding_cw; 113 } 114 }; 115 116 }} 117 118 #endif