Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/draw_style 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_draw_style
0005 #define tools_sg_draw_style
0006 
0007 #include "node"
0008 
0009 #include "lpat"
0010 #include "sf_enum"
0011 #include "render_action"
0012 #include "pick_action"
0013 #include "bbox_action"
0014 
0015 namespace tools {
0016 namespace sg {
0017 
0018 class draw_style : public node {
0019   TOOLS_NODE(draw_style,tools::sg::draw_style,node)
0020 public:
0021   sf_enum<draw_type> style;
0022   sf<float> line_width;
0023   sf<lpat> line_pattern;
0024   sf<float> point_size;
0025   sf<bool> cull_face;
0026   sf<bool> winding_ccw;
0027 public:
0028   virtual const desc_fields& node_desc_fields() const {
0029     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::draw_style)
0030     static const desc_fields s_v(parent::node_desc_fields(),6, //WARNING : take care of count.
0031       TOOLS_ARG_FIELD_DESC(style),
0032       TOOLS_ARG_FIELD_DESC(line_width),
0033       TOOLS_ARG_FIELD_DESC(line_pattern),
0034       TOOLS_ARG_FIELD_DESC(point_size),
0035       TOOLS_ARG_FIELD_DESC(cull_face),
0036       TOOLS_ARG_FIELD_DESC(winding_ccw)
0037     );
0038     return s_v;
0039   }
0040 private:
0041   void add_fields(){
0042     add_field(&style);
0043     add_field(&line_width);
0044     add_field(&line_pattern);
0045     add_field(&point_size);
0046     add_field(&cull_face);
0047     add_field(&winding_ccw);
0048   }
0049 public:
0050   virtual void render(render_action& a_action) {
0051     state& state = a_action.state();
0052     _set_state(state);
0053 
0054     if(style.value()==draw_lines) {
0055       //no LINE_STIPPLE in GLES.
0056       //::glEnable(GL_LINE_STIPPLE); //done in viewer::render()
0057       //::glLineStipple(1,line_pattern.value());
0058       a_action.line_width(state.m_line_width);
0059     } else if(style.value()==draw_points) {
0060       a_action.point_size(state.m_point_size);
0061     } else if(style.value()==draw_filled) {
0062       a_action.set_cull_face(state.m_GL_CULL_FACE);
0063       a_action.set_winding(state.m_winding);
0064     }
0065   }
0066   virtual void pick(pick_action& a_action) {_set_state(a_action.state());}
0067   virtual void bbox(bbox_action& a_action) {_set_state(a_action.state());}
0068 public:
0069   draw_style()
0070   :parent()
0071   ,style(draw_filled)
0072   ,line_width(1) //NOTE : 0 induces a 501 gl error.
0073   ,line_pattern(line_solid)
0074   ,point_size(1)
0075   ,cull_face(true)
0076   ,winding_ccw(true)
0077   {
0078     add_fields();
0079   }
0080   virtual ~draw_style(){}
0081 public:
0082   draw_style(const draw_style& a_from)
0083   :parent(a_from)
0084   ,style(a_from.style)
0085   ,line_width(a_from.line_width)
0086   ,line_pattern(a_from.line_pattern)
0087   ,point_size(a_from.point_size)
0088   ,cull_face(a_from.cull_face)
0089   ,winding_ccw(a_from.winding_ccw)
0090   {
0091     add_fields();
0092   }
0093   draw_style& operator=(const draw_style& a_from){
0094     parent::operator=(a_from);
0095 
0096     style = a_from.style;
0097     line_width = a_from.line_width;
0098     line_pattern = a_from.line_pattern;
0099     point_size = a_from.point_size;
0100     cull_face = a_from.cull_face;
0101     winding_ccw = a_from.winding_ccw;
0102 
0103     return *this;
0104   }
0105 protected:
0106   void _set_state(state& a_state) {
0107     a_state.m_draw_type = style;
0108     a_state.m_line_width = line_width;
0109     a_state.m_line_pattern = line_pattern;
0110     a_state.m_point_size = point_size;
0111     a_state.m_GL_CULL_FACE = cull_face;
0112     a_state.m_winding = winding_ccw.value()?sg::winding_ccw:sg::winding_cw;
0113   }
0114 };
0115 
0116 }}
0117 
0118 #endif