g4tools  5.4.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::sg::GL_action Class Reference
Inheritance diagram for tools::sg::GL_action:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::GL_action:
Collaboration graph
[legend]

Public Types

typedef tools::sg::bufpos bufpos
 
- Public Types inherited from tools::sg::render_action
typedef unsigned int gstoid
 

Public Member Functions

virtual void draw_vertex_array (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs)
 
virtual void draw_vertex_array_xy (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xys)
 
virtual void draw_vertex_color_array (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_rgbas)
 
virtual void draw_vertex_normal_array (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_nms)
 
virtual void draw_vertex_color_normal_array (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_rgbas, const float *a_nms)
 
virtual void draw_vertex_array_texture (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, gstoid a_tex, const float *a_tex_coords)
 texture ///////////////////////////////////////////////////// More...
 
virtual void draw_vertex_normal_array_texture (tools::gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_nms, gstoid a_tex, const float *a_tex_coords)
 
virtual void begin_gsto (gstoid a_id)
 VBO /////////////////////////////////////////////////////////. More...
 
virtual void end_gsto ()
 
virtual void draw_gsto_v (tools::gl::mode_t a_mode, size_t a_elems, bufpos a_pos_xyzs)
 
virtual void draw_gsto_vc (tools::gl::mode_t a_mode, size_t a_elems, bufpos a_pos_xyzs, bufpos a_pos_rgbas)
 
virtual void draw_gsto_vn (tools::gl::mode_t a_mode, size_t a_elems, bufpos a_pos_xyzs, bufpos a_pos_nms)
 
virtual void draw_gsto_vcn (tools::gl::mode_t a_mode, size_t a_elems, bufpos a_pos_xyzs, bufpos a_pos_rgbas, bufpos a_pos_nms)
 
virtual void clear_color (float a_r, float a_g, float a_b, float a_a)
 
virtual void color4f (float a_r, float a_g, float a_b, float a_a)
 
virtual void line_width (float a_v)
 
virtual void point_size (float a_v)
 
virtual void set_polygon_offset (bool a_v)
 
virtual void normal (float a_x, float a_y, float a_z)
 
virtual void set_winding (tools::sg::winding_type a_v)
 
virtual void set_shade_model (tools::sg::shade_type a_v)
 
virtual void set_cull_face (bool a_on)
 
virtual void set_point_smooth (bool a_on)
 
virtual void set_line_smooth (bool a_on)
 
virtual void set_depth_test (bool a_on)
 
virtual void load_proj_matrix (const tools::mat4f &a_mtx)
 
virtual void load_model_matrix (const tools::mat4f &a_mtx)
 
virtual unsigned int max_lights ()
 
virtual void enable_light (unsigned int a_light, float a_dx, float a_dy, float a_dz, float a_r, float a_g, float a_b, float a_a)
 
virtual void set_lighting (bool a_on)
 
virtual void set_blend (bool a_on)
 
virtual void restore_state (unsigned int a_ret_num_light)
 
virtual tools::sg::render_managerrender_manager ()
 
 GL_action (GL_manager &a_mgr, std::ostream &a_out, unsigned int a_ww, unsigned int a_wh)
 
virtual ~GL_action ()
 
 GL_action (const GL_action &a_from)
 
GL_actionoperator= (const GL_action &a_from)
 
- Public Member Functions inherited from tools::sg::render_action
 render_action (std::ostream &a_out, unsigned int a_ww, unsigned int a_wh)
 
virtual ~render_action ()
 
 render_action (const render_action &a_from)
 
render_actionoperator= (const render_action &a_from)
 
void load_matrices_to_identity ()
 
void load_matrices_from_state ()
 
void clear_color (const colorf &a_color)
 
void color4f (const colorf &a_color)
 
void enable_light (unsigned int a_light, const vec3f &a_dir, const colorf &a_col)
 
void draw_vertex_array (gl::mode_t a_mode, const std::vector< float > &a_xyzs)
 
void draw_vertex_array_xy (gl::mode_t a_mode, const std::vector< float > &a_xys)
 
void draw_vertex_color_array (gl::mode_t a_mode, const std::vector< float > &a_xyzs, const std::vector< float > &a_rgbas)
 
void draw_vertex_normal_array (gl::mode_t a_mode, const std::vector< float > &a_xyzs, const std::vector< float > &a_nms)
 
void draw_vertex_color_normal_array (gl::mode_t a_mode, const std::vector< float > &a_xyzs, const std::vector< float > &a_rgbas, const std::vector< float > &a_nms)
 
void normal (const vec3f &a_vec)
 
bool add_triangles_normal (size_t a_floatn, const float *a_xyzs, const float *a_nms)
 
bool add_triangle_fan_normal (size_t a_floatn, const float *a_xyzs, const float *a_nms)
 
bool add_triangle_fan_normal_rgba (size_t a_floatn, const float *a_xyzs, float *a_nms, const float *a_rgbas)
 
bool add_triangle_strip_normal (size_t a_floatn, const float *a_xyzs, const float *a_nms)
 
bool add_triangle_strip_normal_rgba (size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas)
 
bool add_lines (size_t a_floatn, const float *a_xyzs)
 
bool add_line_loop (size_t a_floatn, const float *a_xyzs)
 
bool add_line_strip (size_t a_floatn, const float *a_xyzs)
 
bool add_points (size_t a_floatn, const float *a_xyzs)
 
bool add_triangle_fan_texture_normal (size_t a_floatn, const float *a_xyzs, const float *a_nms, gstoid a_tex, const float *a_texs)
 
bool add_triangle_strip_texture_normal (size_t a_floatn, const float *a_xyzs, const float *a_nms, gstoid a_tex, const float *a_texs)
 
bool add_line_loop (const std::vector< float > &a_xyzs)
 
bool add_line_strip (const std::vector< float > &a_xyzs)
 
bool add_triangle_strip_as_triangles (size_t a_floatn, const float *a_xyzs, const float *a_nms)
 
void dump_vertex_array_xy (std::ostream &a_out, gl::mode_t, size_t a_floatn, const float *a_xys)
 
- Public Member Functions inherited from tools::sg::matrix_action
 matrix_action (std::ostream &a_out, unsigned int a_ww, unsigned int a_wh)
 
virtual ~matrix_action ()
 
 matrix_action (const matrix_action &a_from)
 
matrix_actionoperator= (const matrix_action &a_from)
 
void push_matrices ()
 
void pop_matrices ()
 
mat4fprojection_matrix ()
 
mat4fmodel_matrix ()
 
bool end () const
 
int cur () const
 
bool project_point (float &a_x, float &a_y, float &a_z, float &a_w)
 
void model_point (float &a_x, float &a_y, float &a_z, float &a_w)
 
void projected_origin (float &a_x, float &a_y, float &a_z)
 
- Public Member Functions inherited from tools::sg::win_action
 win_action (std::ostream &a_out, unsigned int a_ww, unsigned int a_wh)
 
virtual ~win_action ()
 
unsigned int ww () const
 
unsigned int wh () const
 
- Public Member Functions inherited from tools::sg::action
virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const =0
 
 action (std::ostream &a_out)
 
virtual ~action ()
 
std::ostream & out () const
 
- Public Member Functions inherited from tools::sg::states
 states (unsigned int a_ww, unsigned int a_wh)
 
virtual ~states ()
 
const sg::statestate () const
 
sg::statestate ()
 
void pop_state ()
 
void push_state ()
 
void save_state (const sg::state &a_state)
 
const sg::statesaved_state () const
 
sg::statesaved_state ()
 

Protected Member Functions

void _draw_v (tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs)
 
void _draw_vc (tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_rgbas)
 
void _draw_vn (tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_nms)
 
void _draw_vcn (tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_rgbas, const void *a_pos_nms)
 
- Protected Member Functions inherited from tools::sg::matrix_action
void reset ()
 
- Protected Member Functions inherited from tools::sg::win_action
 win_action (const win_action &a_from)
 
win_actionoperator= (const win_action &a_from)
 
- Protected Member Functions inherited from tools::sg::action
 action (const action &a_from)
 
actionoperator= (const action &)
 
- Protected Member Functions inherited from tools::sg::states
 states (const states &a_from)
 
statesoperator= (const states &a_from)
 

Protected Attributes

GL_managerm_mgr
 
gstoid m_gsto
 
- Protected Attributes inherited from tools::sg::matrix_action
std::vector< mat4fm_projs
 
std::vector< mat4fm_models
 
int m_cur
 
mat4f m_identity
 
- Protected Attributes inherited from tools::sg::win_action
unsigned int m_ww
 
unsigned int m_wh
 
- Protected Attributes inherited from tools::sg::action
std::ostream & m_out
 
- Protected Attributes inherited from tools::sg::states
std::vector< sg::statem_states
 
sg::state m_state
 
sg::state m_saved_state
 

Detailed Description

Definition at line 17 of file GL_action.

Member Typedef Documentation

◆ bufpos

Definition at line 199 of file GL_action.

Constructor & Destructor Documentation

◆ GL_action() [1/2]

tools::sg::GL_action::GL_action ( GL_manager a_mgr,
std::ostream &  a_out,
unsigned int  a_ww,
unsigned int  a_wh 
)
inline

Definition at line 569 of file GL_action.

570  :parent(a_out,a_ww,a_wh)
571  ,m_mgr(a_mgr)
572  ,m_gsto(0)
573 #ifdef TOOLS_HAS_GL_LIST
574  ,m_created(false)
575  ,m_gl_id(0)
576 #endif
577  {}

◆ ~GL_action()

virtual tools::sg::GL_action::~GL_action ( )
inlinevirtual

Definition at line 578 of file GL_action.

578 {}

◆ GL_action() [2/2]

tools::sg::GL_action::GL_action ( const GL_action a_from)
inline

Definition at line 580 of file GL_action.

581  :parent(a_from)
582  ,m_mgr(a_from.m_mgr)
583  ,m_gsto(0)
584 #ifdef TOOLS_HAS_GL_LIST
585  ,m_created(false)
586  ,m_gl_id(0)
587 #endif
588  {}

Member Function Documentation

◆ _draw_v()

void tools::sg::GL_action::_draw_v ( tools::gl::mode_t  a_mode,
size_t  a_elems,
const void *  a_pos_xyzs 
)
inlineprotected

Definition at line 599 of file GL_action.

599  {
600  ::glEnableClientState(GL_VERTEX_ARRAY);
601  ::glVertexPointer(3,GL_FLOAT,0,a_pos_xyzs);
602  ::glDrawArrays(a_mode,0,(GLsizei)a_elems);
603  ::glDisableClientState(GL_VERTEX_ARRAY);
604  }

◆ _draw_vc()

void tools::sg::GL_action::_draw_vc ( tools::gl::mode_t  a_mode,
size_t  a_elems,
const void *  a_pos_xyzs,
const void *  a_pos_rgbas 
)
inlineprotected

Definition at line 606 of file GL_action.

606  {
607 
608  ::glEnableClientState(GL_VERTEX_ARRAY);
609  ::glEnableClientState(GL_COLOR_ARRAY);
610 
611  ::glVertexPointer(3,GL_FLOAT,0,a_pos_xyzs);
612  ::glColorPointer(4,GL_FLOAT,0,a_pos_rgbas);
613 
614  ::glDrawArrays(a_mode,0,(GLsizei)a_elems);
615 
616  ::glDisableClientState(GL_COLOR_ARRAY);
617  ::glDisableClientState(GL_VERTEX_ARRAY);
618  }

◆ _draw_vcn()

void tools::sg::GL_action::_draw_vcn ( tools::gl::mode_t  a_mode,
size_t  a_elems,
const void *  a_pos_xyzs,
const void *  a_pos_rgbas,
const void *  a_pos_nms 
)
inlineprotected

Definition at line 633 of file GL_action.

633  {
634  ::glEnableClientState(GL_VERTEX_ARRAY);
635  ::glEnableClientState(GL_COLOR_ARRAY);
636  ::glEnableClientState(GL_NORMAL_ARRAY);
637 
638  ::glVertexPointer(3,GL_FLOAT,0,a_pos_xyzs);
639  ::glColorPointer(4,GL_FLOAT,0,a_pos_rgbas);
640  ::glNormalPointer(GL_FLOAT,0,a_pos_nms);
641 
642  ::glDrawArrays(a_mode,0,(GLsizei)a_elems);
643 
644  ::glDisableClientState(GL_COLOR_ARRAY);
645  ::glDisableClientState(GL_NORMAL_ARRAY);
646  ::glDisableClientState(GL_VERTEX_ARRAY);
647  }

◆ _draw_vn()

void tools::sg::GL_action::_draw_vn ( tools::gl::mode_t  a_mode,
size_t  a_elems,
const void *  a_pos_xyzs,
const void *  a_pos_nms 
)
inlineprotected

Definition at line 620 of file GL_action.

620  {
621  ::glEnableClientState(GL_VERTEX_ARRAY);
622  ::glEnableClientState(GL_NORMAL_ARRAY);
623 
624  ::glVertexPointer(3,GL_FLOAT,0,a_pos_xyzs);
625  ::glNormalPointer(GL_FLOAT,0,a_pos_nms);
626 
627  ::glDrawArrays(a_mode,0,(GLsizei)a_elems);
628 
629  ::glDisableClientState(GL_NORMAL_ARRAY);
630  ::glDisableClientState(GL_VERTEX_ARRAY);
631  }

◆ begin_gsto()

virtual void tools::sg::GL_action::begin_gsto ( gstoid  a_id)
inlinevirtual

VBO /////////////////////////////////////////////////////////.

Implements tools::sg::render_action.

Definition at line 146 of file GL_action.

146  {
147  switch(m_mgr.get_gsto_mode()){
148 
150 #ifdef TOOLS_HAS_GL_VBO
151  m_mgr.bind_gsto(a_id);
152 #endif
153  }break;
154 
156 #ifdef TOOLS_HAS_GL_LIST
157  m_gsto = a_id;
158  m_created = false;
159  m_gl_id = m_mgr.gsto_gl_list_id(a_id,m_created);
160  if(m_gl_id && m_created) {
161  ::glNewList(m_gl_id,GL_COMPILE);
162  }
163 #endif
164  }break;
165 
167  m_gsto = a_id;
168  }break;
169  }
170  }

◆ clear_color()

virtual void tools::sg::GL_action::clear_color ( float  a_r,
float  a_g,
float  a_b,
float  a_a 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 359 of file GL_action.

359  {
360  ::glClearColor(a_r,a_g,a_b,a_a);
361  ::glClear(GL_COLOR_BUFFER_BIT);
362  }

◆ color4f()

virtual void tools::sg::GL_action::color4f ( float  a_r,
float  a_g,
float  a_b,
float  a_a 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 363 of file GL_action.

363  {
364  ::glColor4f(a_r,a_g,a_b,a_a);
365  }

◆ draw_gsto_v()

virtual void tools::sg::GL_action::draw_gsto_v ( tools::gl::mode_t  a_mode,
size_t  a_elems,
bufpos  a_pos_xyzs 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 200 of file GL_action.

200  {
201 
202  switch(m_mgr.get_gsto_mode()){
203 
205 #ifdef TOOLS_HAS_GL_VBO
206  _draw_v(a_mode,a_elems,(char*)NULL+a_pos_xyzs);
207 #endif
208  }break;
209 
211 #ifdef TOOLS_HAS_GL_LIST
212  float* buffer = m_mgr.gsto_data(m_gsto);
213  if(!buffer) return;
214  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
215  if(m_gl_id && m_created) {
216  ::glBegin(a_mode);
217  float* pos = (float*)pos_xyzs;
218  for(size_t index=0;index<a_elems;index++,pos+=3) {
219  ::glVertex3f(*(pos+0),*(pos+1),*(pos+2));
220  }
221  ::glEnd();
222  }
223 #endif
224  }break;
225 
227  float* buffer = m_mgr.gsto_data(m_gsto);
228  if(!buffer) return;
229  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
230  _draw_v(a_mode,a_elems,pos_xyzs);
231  }break;
232  }
233  }

◆ draw_gsto_vc()

virtual void tools::sg::GL_action::draw_gsto_vc ( tools::gl::mode_t  a_mode,
size_t  a_elems,
bufpos  a_pos_xyzs,
bufpos  a_pos_rgbas 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 235 of file GL_action.

235  {
236 
237  switch(m_mgr.get_gsto_mode()){
238 
240 #ifdef TOOLS_HAS_GL_VBO
241  _draw_vc(a_mode,a_elems,(char*)NULL+a_pos_xyzs,(char*)NULL+a_pos_rgbas);
242 #endif
243  }break;
244 
246 #ifdef TOOLS_HAS_GL_LIST
247  float* buffer = m_mgr.gsto_data(m_gsto);
248  if(!buffer) return;
249  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
250  void* pos_rgbas = (char*)buffer+a_pos_rgbas;
251  if(m_gl_id && m_created) {
252  ::glBegin(a_mode);
253  float* pos = (float*)pos_xyzs;
254  float* pco = (float*)pos_rgbas;
255  for(size_t index=0;index<a_elems;index++,pos+=3,pco+=4) {
256  ::glColor4f (*(pco+0),*(pco+1),*(pco+2),*(pco+3));
257  ::glVertex3f(*(pos+0),*(pos+1),*(pos+2));
258  }
259  ::glEnd();
260  }
261 #endif
262  }break;
263 
265  float* buffer = m_mgr.gsto_data(m_gsto);
266  if(!buffer) return;
267  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
268  void* pos_rgbas = (char*)buffer+a_pos_rgbas;
269  _draw_vc(a_mode,a_elems,pos_xyzs,pos_rgbas);
270  }break;
271  }
272  }

◆ draw_gsto_vcn()

virtual void tools::sg::GL_action::draw_gsto_vcn ( tools::gl::mode_t  a_mode,
size_t  a_elems,
bufpos  a_pos_xyzs,
bufpos  a_pos_rgbas,
bufpos  a_pos_nms 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 311 of file GL_action.

311  {
312 
313  switch(m_mgr.get_gsto_mode()){
314 
316 #ifdef TOOLS_HAS_GL_VBO
317  _draw_vcn(a_mode,a_elems,(char*)NULL+a_pos_xyzs,(char*)NULL+a_pos_rgbas,(char*)NULL+a_pos_nms);
318 #endif
319  }break;
320 
322 #ifdef TOOLS_HAS_GL_LIST
323  float* buffer = m_mgr.gsto_data(m_gsto);
324  if(!buffer) return;
325  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
326  void* pos_rgbas = (char*)buffer+a_pos_rgbas;
327  void* pos_nms = (char*)buffer+a_pos_nms;
328  if(m_gl_id && m_created) {
329  ::glBegin(a_mode);
330  float* pos = (float*)pos_xyzs;
331  float* pco = (float*)pos_rgbas;
332  float* pnm = (float*)pos_nms;
333  for(size_t index=0;index<a_elems;
334  index++,pos+=3,pco+=4,pnm+=3) {
335  ::glVertex3f(*(pos+0),*(pos+1),*(pos+2));
336  ::glColor4f (*(pco+0),*(pco+1),*(pco+2),*(pco+3));
337  ::glNormal3f(*(pnm+0),*(pnm+1),*(pnm+2));
338  }
339  ::glEnd();
340  }
341 #endif
342  }break;
343 
345  float* buffer = m_mgr.gsto_data(m_gsto);
346  if(!buffer) return;
347  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
348  void* pos_rgbas = (char*)buffer+a_pos_rgbas;
349  void* pos_nms = (char*)buffer+a_pos_nms;
350  _draw_vcn(a_mode,a_elems,pos_xyzs,pos_rgbas,pos_nms);
351  }break;
352  }
353  }

◆ draw_gsto_vn()

virtual void tools::sg::GL_action::draw_gsto_vn ( tools::gl::mode_t  a_mode,
size_t  a_elems,
bufpos  a_pos_xyzs,
bufpos  a_pos_nms 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 274 of file GL_action.

274  {
275 
276  switch(m_mgr.get_gsto_mode()){
277 
279 #ifdef TOOLS_HAS_GL_VBO
280  _draw_vn(a_mode,a_elems,(char*)NULL+a_pos_xyzs,(char*)NULL+a_pos_nms);
281 #endif
282  }break;
283 
285 #ifdef TOOLS_HAS_GL_LIST
286  float* buffer = m_mgr.gsto_data(m_gsto);
287  if(!buffer) return;
288  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
289  //void* pos_nms = (char*)buffer+a_pos_nms;
290  if(m_gl_id && m_created) {
291  ::glBegin(a_mode);
292  float* pos = (float*)pos_xyzs;
293  for(size_t index=0;index<a_elems;index++,pos+=3) {
294  ::glVertex3f(*(pos+0),*(pos+1),*(pos+2));
295  }
296  ::glEnd();
297  }
298 #endif
299  }break;
300 
302  float* buffer = m_mgr.gsto_data(m_gsto);
303  if(!buffer) return;
304  void* pos_xyzs = (char*)buffer+a_pos_xyzs;
305  void* pos_nms = (char*)buffer+a_pos_nms;
306  _draw_vn(a_mode,a_elems,pos_xyzs,pos_nms);
307  }break;
308  }
309  }

◆ draw_vertex_array()

virtual void tools::sg::GL_action::draw_vertex_array ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 20 of file GL_action.

20  {
21  size_t num = a_floatn/3;
22  if(!num) return;
23  _draw_v(a_mode,num,a_xyzs);
24  }

◆ draw_vertex_array_texture()

virtual void tools::sg::GL_action::draw_vertex_array_texture ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs,
gstoid  a_tex,
const float *  a_tex_coords 
)
inlinevirtual

texture /////////////////////////////////////////////////////

Implements tools::sg::render_action.

Definition at line 84 of file GL_action.

88  {
89  size_t num = a_floatn/3;
90  if(!num) return;
91 
92  //expect 2*num a_tex_coords.
93 
94  ::glEnable(GL_TEXTURE_2D);
95 
96  m_mgr.bind_gsto(a_tex);
97 
98  ::glEnableClientState(GL_VERTEX_ARRAY);
99  ::glEnableClientState(GL_TEXTURE_COORD_ARRAY);
100  ::glVertexPointer(3,GL_FLOAT,0,a_xyzs);
101  ::glTexCoordPointer(2,GL_FLOAT,0,a_tex_coords);
102  ::glDrawArrays(a_mode,0,(GLsizei)num);
103  ::glDisableClientState(GL_VERTEX_ARRAY);
104  ::glDisableClientState(GL_TEXTURE_COORD_ARRAY);
105 
106  ::glBindTexture(GL_TEXTURE_2D,0);
107 
108  ::glDisable(GL_TEXTURE_2D);
109  }

◆ draw_vertex_array_xy()

virtual void tools::sg::GL_action::draw_vertex_array_xy ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xys 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 26 of file GL_action.

26  {
27  size_t num = a_floatn/2;
28  if(!num) return;
29 #ifdef _WIN32
30  float* vp = new float[num*3];
31  if(!vp) return;
32  float* pos = vp;
33  float* pda = (float*)a_xys;
34  for(size_t index=0;index<num;index++){
35  *pos = *pda;pos++;pda++;
36  *pos = *pda;pos++;pda++;
37  *pos = 0;pos++; //Windows GL needs a z = 0.
38  }
39  ::glEnableClientState(GL_VERTEX_ARRAY);
40  ::glVertexPointer(3,GL_FLOAT,0,vp);
41  ::glDrawArrays(a_mode,0,(GLsizei)num);
42  ::glDisableClientState(GL_VERTEX_ARRAY);
43  delete [] vp;
44 #else
45  ::glEnableClientState(GL_VERTEX_ARRAY);
46  ::glVertexPointer(2,GL_FLOAT,0,a_xys);
47  ::glDrawArrays(a_mode,0,(GLsizei)num);
48  ::glDisableClientState(GL_VERTEX_ARRAY);
49 #endif
50  }

◆ draw_vertex_color_array()

virtual void tools::sg::GL_action::draw_vertex_color_array ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs,
const float *  a_rgbas 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 52 of file GL_action.

52  {
53  // Used in atb_vertices.
54  // We expect a_rgbas of size : 4*(a_floatn/3)
55  // (then one RGBA color per 3D point).
56  size_t num = a_floatn/3;
57  if(!num) return;
58  _draw_vc(a_mode,num,a_xyzs,a_rgbas);
59  }

◆ draw_vertex_color_normal_array()

virtual void tools::sg::GL_action::draw_vertex_color_normal_array ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs,
const float *  a_rgbas,
const float *  a_nms 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 69 of file GL_action.

70  {
71  // Used in atb_vertices.
72  // We expect a_nms of size : 3*(a_floatn/3)
73  // (then one normal per 3D point).
74  // We expect a_rgbas of size : 4*(a_floatn/3)
75  // (then one RGBA color per 3D point).
76  size_t num = a_floatn/3;
77  if(!num) return;
78  _draw_vcn(a_mode,num,a_xyzs,a_rgbas,a_nms);
79  }

◆ draw_vertex_normal_array()

virtual void tools::sg::GL_action::draw_vertex_normal_array ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs,
const float *  a_nms 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 61 of file GL_action.

61  {
62  // We expect a_nms of size : 3*(a_floatn/3)
63  // (then one normal per 3D point).
64  size_t num = a_floatn/3;
65  if(!num) return;
66  _draw_vn(a_mode,num,a_xyzs,a_nms);
67  }

◆ draw_vertex_normal_array_texture()

virtual void tools::sg::GL_action::draw_vertex_normal_array_texture ( tools::gl::mode_t  a_mode,
size_t  a_floatn,
const float *  a_xyzs,
const float *  a_nms,
gstoid  a_tex,
const float *  a_tex_coords 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 111 of file GL_action.

116  {
117  size_t num = a_floatn/3;
118  if(!num) return;
119 
120  //expect 2*num a_tex_coords.
121 
122  ::glEnable(GL_TEXTURE_2D);
123 
124  m_mgr.bind_gsto(a_tex);
125 
126  ::glEnableClientState(GL_VERTEX_ARRAY);
127  ::glEnableClientState(GL_NORMAL_ARRAY);
128  ::glEnableClientState(GL_TEXTURE_COORD_ARRAY);
129  ::glVertexPointer(3,GL_FLOAT,0,a_xyzs);
130  ::glNormalPointer(GL_FLOAT,0,a_nms);
131  ::glTexCoordPointer(2,GL_FLOAT,0,a_tex_coords);
132  ::glDrawArrays(a_mode,0,(GLsizei)num);
133  ::glDisableClientState(GL_NORMAL_ARRAY);
134  ::glDisableClientState(GL_VERTEX_ARRAY);
135  ::glDisableClientState(GL_TEXTURE_COORD_ARRAY);
136 
137  ::glBindTexture(GL_TEXTURE_2D,0);
138 
139  ::glDisable(GL_TEXTURE_2D);
140  }

◆ enable_light()

virtual void tools::sg::GL_action::enable_light ( unsigned int  a_light,
float  a_dx,
float  a_dy,
float  a_dz,
float  a_r,
float  a_g,
float  a_b,
float  a_a 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 442 of file GL_action.

444  {
445  ::glEnable(GL_LIGHTING);
446  GLenum light = GL_LIGHT0+a_light;
447  //::printf("debug : GL_MAX_LIGHTS %d\n",GL_MAX_LIGHTS);
448 
449  float params[4];
450  params[0] = -a_dx;
451  params[1] = -a_dy;
452  params[2] = -a_dz;
453  params[3] = 0; //0 tells that it is a directional light.
454  ::glLightfv(light,GL_POSITION,params);
455 
456  //params[0] = a_dir[0];
457  //params[1] = a_dir[1];
458  //params[2] = a_dir[2];
459  //::glLightfv(light,GL_SPOT_DIRECTION,params);
460 
461  params[0] = a_r;
462  params[1] = a_g;
463  params[2] = a_b;
464  params[3] = a_a;
465  ::glLightfv(light,GL_DIFFUSE,params);
466  ::glLightfv(light,GL_SPECULAR,params); //coin/SoDirectionalLight does that.
467 
468  params[0] = 0;
469  params[1] = 0;
470  params[2] = 0;
471  params[3] = 1;
472  ::glLightfv(light,GL_AMBIENT,params); //coin/SoDirectionalLight does that.
473 
474  // coin/SoDirectionalLight does the below :
475  ::glLightf(light, GL_SPOT_EXPONENT, 0.0);
476  ::glLightf(light, GL_SPOT_CUTOFF, 180.0);
477  ::glLightf(light, GL_CONSTANT_ATTENUATION, 1);
478  ::glLightf(light, GL_LINEAR_ATTENUATION, 0);
479  ::glLightf(light, GL_QUADRATIC_ATTENUATION, 0);
480 
481  //::printf("debug : GL_MAX_LIGHTS %d\n",GL_MAX_LIGHTS);
482 
483  ::glEnable(light);
484  }

◆ end_gsto()

virtual void tools::sg::GL_action::end_gsto ( )
inlinevirtual

Implements tools::sg::render_action.

Definition at line 172 of file GL_action.

172  {
173  switch(m_mgr.get_gsto_mode()){
174 
176 #ifdef TOOLS_HAS_GL_VBO
177  ::glBindBuffer(GL_ARRAY_BUFFER,0);
178 #endif
179  }break;
180 
182 #ifdef TOOLS_HAS_GL_LIST
183  if(m_gl_id && m_created) {
184  ::glEndList();
185  }
186  if(m_gl_id) ::glCallList(m_gl_id);
187  m_created = false;
188  m_gl_id = 0;
189  m_gsto = 0;
190 #endif
191  }break;
192 
194  m_gsto = 0;
195  }break;
196  }
197  }

◆ line_width()

virtual void tools::sg::GL_action::line_width ( float  a_v)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 366 of file GL_action.

366 {::glLineWidth(a_v);}

◆ load_model_matrix()

virtual void tools::sg::GL_action::load_model_matrix ( const tools::mat4f a_mtx)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 416 of file GL_action.

416  {
417  ::glMatrixMode(GL_MODELVIEW);
418  ::glLoadMatrixf(a_mtx.data());
419 /*
420  tools::mat4f tmp(a_mtx);
421  tmp.no_translate();
422  tools::mat4f normal_matrix;
423  if(!tmp.invert(normal_matrix)) {
424  m_out << "tools::WebGL::render::load_model_matrix :"
425  << " can't invert model matrix."
426  << std::endl;
427  }
428  normal_matrix.transpose();
429 
430  tools::mat4f to_check(a_mtx);
431  to_check.no_translate();
432  float fepsilon = 1e-10;
433  if(!normal_matrix.equal_prec(to_check,fepsilon,tools::ffabs)) {
434  mat_dump(m_out,"problem with normal_matrix ",normal_matrix);
435  mat_dump(m_out,"expected",to_check);
436  }
437 */
438  }

◆ load_proj_matrix()

virtual void tools::sg::GL_action::load_proj_matrix ( const tools::mat4f a_mtx)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 411 of file GL_action.

411  {
412  ::glMatrixMode(GL_PROJECTION);
413  ::glLoadMatrixf(a_mtx.data());
414  }

◆ max_lights()

virtual unsigned int tools::sg::GL_action::max_lights ( )
inlinevirtual

Implements tools::sg::render_action.

Definition at line 440 of file GL_action.

440 {return GL_MAX_LIGHTS;}

◆ normal()

virtual void tools::sg::GL_action::normal ( float  a_x,
float  a_y,
float  a_z 
)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 373 of file GL_action.

373  {
374  ::glNormal3f(a_x,a_y,a_z);
375  }

◆ operator=()

GL_action& tools::sg::GL_action::operator= ( const GL_action a_from)
inline

Definition at line 589 of file GL_action.

589  {
590  render_action::operator=(a_from);
591  m_gsto = 0;
592 #ifdef TOOLS_HAS_GL_LIST
593  m_created = false;
594  m_gl_id = 0;
595 #endif
596  return *this;
597  }

◆ point_size()

virtual void tools::sg::GL_action::point_size ( float  a_v)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 367 of file GL_action.

367 {::glPointSize(a_v);}

◆ render_manager()

virtual tools::sg::render_manager& tools::sg::GL_action::render_manager ( )
inlinevirtual

Implements tools::sg::render_action.

Definition at line 567 of file GL_action.

567 {return m_mgr;}

◆ restore_state()

virtual void tools::sg::GL_action::restore_state ( unsigned int  a_ret_num_light)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 495 of file GL_action.

495  {
496  const tools::sg::state& _state = state();
497  ::glMatrixMode(GL_PROJECTION);
498  ::glLoadMatrixf(_state.m_proj.data());
499 
500  ::glMatrixMode(GL_MODELVIEW);
501  ::glLoadMatrixf(_state.m_model.data());
502 
503  if(_state.m_GL_LIGHTING) ::glEnable(GL_LIGHTING);
504  else ::glDisable(GL_LIGHTING);
505 
506  if(_state.m_GL_DEPTH_TEST) ::glEnable(GL_DEPTH_TEST);
507  else ::glDisable(GL_DEPTH_TEST);
508 
509  if(_state.m_GL_CULL_FACE) ::glEnable(GL_CULL_FACE);
510  else ::glDisable(GL_CULL_FACE);
511 
512  if(_state.m_GL_POINT_SMOOTH) ::glEnable(GL_POINT_SMOOTH);
513  else ::glDisable(GL_POINT_SMOOTH);
514 
515  if(_state.m_GL_LINE_SMOOTH) ::glEnable(GL_LINE_SMOOTH);
516  else ::glDisable(GL_LINE_SMOOTH);
517 
518  if(_state.m_GL_POLYGON_OFFSET_FILL) ::glEnable(GL_POLYGON_OFFSET_FILL);
519  else ::glDisable(GL_POLYGON_OFFSET_FILL);
520 
521  if(_state.m_GL_TEXTURE_2D) ::glEnable(GL_TEXTURE_2D);
522  else ::glDisable(GL_TEXTURE_2D);
523 
524  if(_state.m_GL_BLEND) ::glEnable(GL_BLEND);
525  else ::glDisable(GL_BLEND);
526 
527  if(_state.m_winding==tools::sg::winding_ccw) {
528  ::glFrontFace(GL_CCW);
529  } else {
530  ::glFrontFace(GL_CW);
531  }
532 
534  ::glShadeModel(GL_SMOOTH);
535  else
536  ::glShadeModel(GL_FLAT);
537 
538  ::glColor4f(_state.m_color.r(),
539  _state.m_color.g(),
540  _state.m_color.b(),
541  _state.m_color.a());
542 
543  ::glNormal3f(_state.m_normal.x(),
544  _state.m_normal.y(),
545  _state.m_normal.z());
546 
547  // The "return of separator" state had ret_num_light.
548  // The restored state has m_light.
549  // We have to glDisable lights with index in [m_light,ret_num_light-1]
550  for(unsigned int index=_state.m_light;index<a_ret_num_light;index++) {
551  ::glDisable(GL_LIGHT0+index);
552  }
553 
554  ::glLineWidth(_state.m_line_width);
555 
556  ::glPointSize(_state.m_point_size);
557 
558 #if TARGET_OS_IPHONE
559 // GL-ES
560 #elif defined(ANDROID)
561 // GL-ES
562 #else
563  ::glDisable(GL_POLYGON_STIPPLE); //CoinGL : reading a .wrl having Material::transparency may enable GL_POLYGON_STIPPLE.
564 #endif
565  }

◆ set_blend()

virtual void tools::sg::GL_action::set_blend ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 490 of file GL_action.

490  {
491  if(a_on) ::glEnable(GL_BLEND);
492  else ::glDisable(GL_BLEND);
493  }

◆ set_cull_face()

virtual void tools::sg::GL_action::set_cull_face ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 391 of file GL_action.

391  {
392  if(a_on) ::glEnable(GL_CULL_FACE);
393  else ::glDisable(GL_CULL_FACE);
394  }

◆ set_depth_test()

virtual void tools::sg::GL_action::set_depth_test ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 406 of file GL_action.

406  {
407  if(a_on) ::glEnable(GL_DEPTH_TEST);
408  else ::glDisable(GL_DEPTH_TEST);
409  }

◆ set_lighting()

virtual void tools::sg::GL_action::set_lighting ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 486 of file GL_action.

486  {
487  if(a_on) ::glEnable(GL_LIGHTING);
488  else ::glDisable(GL_LIGHTING);
489  }

◆ set_line_smooth()

virtual void tools::sg::GL_action::set_line_smooth ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 401 of file GL_action.

401  {
402  if(a_on) ::glEnable(GL_LINE_SMOOTH);
403  else ::glDisable(GL_LINE_SMOOTH);
404  }

◆ set_point_smooth()

virtual void tools::sg::GL_action::set_point_smooth ( bool  a_on)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 396 of file GL_action.

396  {
397  if(a_on) ::glEnable(GL_POINT_SMOOTH);
398  else ::glDisable(GL_POINT_SMOOTH);
399  }

◆ set_polygon_offset()

virtual void tools::sg::GL_action::set_polygon_offset ( bool  a_v)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 368 of file GL_action.

368  {
369  if(a_v) ::glEnable(GL_POLYGON_OFFSET_FILL);
370  else ::glDisable(GL_POLYGON_OFFSET_FILL);
371  ::glPolygonOffset(1.,1.);
372  }

◆ set_shade_model()

virtual void tools::sg::GL_action::set_shade_model ( tools::sg::shade_type  a_v)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 384 of file GL_action.

384  {
385  if(a_v==tools::sg::shade_smooth)
386  ::glShadeModel(GL_SMOOTH);
387  else
388  ::glShadeModel(GL_FLAT);
389  }

◆ set_winding()

virtual void tools::sg::GL_action::set_winding ( tools::sg::winding_type  a_v)
inlinevirtual

Implements tools::sg::render_action.

Definition at line 377 of file GL_action.

377  {
378  if(a_v==tools::sg::winding_ccw)
379  ::glFrontFace(GL_CCW);
380  else
381  ::glFrontFace(GL_CW);
382  }

Member Data Documentation

◆ m_gsto

gstoid tools::sg::GL_action::m_gsto
protected

Definition at line 651 of file GL_action.

◆ m_mgr

GL_manager& tools::sg::GL_action::m_mgr
protected

Definition at line 650 of file GL_action.


The documentation for this class was generated from the following file:
tools::sg::state
Definition: state:25
tools::sg::state::m_GL_LIGHTING
bool m_GL_LIGHTING
Definition: state:248
tools::sg::state::m_GL_DEPTH_TEST
bool m_GL_DEPTH_TEST
Definition: state:247
tools::sg::winding_ccw
@ winding_ccw
Definition: enums:105
tools::sg::state::m_point_size
float m_point_size
Definition: state:269
tools::sg::GL_action::_draw_vc
void _draw_vc(tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_rgbas)
Definition: GL_action:606
tools::sg::GL_action::_draw_vn
void _draw_vn(tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_nms)
Definition: GL_action:620
tools::sg::state::m_GL_POLYGON_OFFSET_FILL
bool m_GL_POLYGON_OFFSET_FILL
Definition: state:250
tools::sg::GL_manager::gsto_gl_list_id
unsigned int gsto_gl_list_id(unsigned int a_id, bool &a_created) const
Definition: GL_manager:368
tools::sg::state::m_GL_CULL_FACE
bool m_GL_CULL_FACE
Definition: state:249
tools::sg::state::m_normal
vec3f m_normal
Definition: state:260
tools::sg::state::m_winding
winding_type m_winding
Definition: state:258
tools::sg::GL_action::m_gsto
gstoid m_gsto
Definition: GL_action:651
tools::sg::gsto_gl_vbo
@ gsto_gl_vbo
Definition: enums:174
tools::sg::state::m_GL_TEXTURE_2D
bool m_GL_TEXTURE_2D
Definition: state:251
tools::sg::state::m_GL_POINT_SMOOTH
bool m_GL_POINT_SMOOTH
Definition: state:252
tools::vec3::y
const T & y() const
Definition: vec3:85
tools::sg::render_action::operator=
render_action & operator=(const render_action &a_from)
Definition: render_action:86
tools::colorf::g
float g() const
Definition: colorf:33
tools::sg::GL_action::m_mgr
GL_manager & m_mgr
Definition: GL_action:650
tools::sg::state::m_light
unsigned int m_light
Definition: state:262
tools::vec3::x
const T & x() const
Definition: vec3:84
tools::sg::GL_manager::gsto_data
float * gsto_data(unsigned int a_id) const
Definition: GL_manager:362
tools::sg::GL_action::_draw_vcn
void _draw_vcn(tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs, const void *a_pos_rgbas, const void *a_pos_nms)
Definition: GL_action:633
tools::sg::state::m_GL_LINE_SMOOTH
bool m_GL_LINE_SMOOTH
Definition: state:253
tools::colorf::a
float a() const
Definition: colorf:35
tools::sg::GL_action::_draw_v
void _draw_v(tools::gl::mode_t a_mode, size_t a_elems, const void *a_pos_xyzs)
Definition: GL_action:599
tools::sg::GL_manager::get_gsto_mode
virtual tools::sg::gsto_mode get_gsto_mode() const
Definition: GL_manager:395
tools::sg::GL_manager::bind_gsto
void bind_gsto(unsigned int a_id)
Definition: GL_manager:492
tools::sg::state::m_shade_model
shade_type m_shade_model
Definition: state:265
tools::sg::state::m_proj
mat4f m_proj
Definition: state:244
tools::sg::gsto_memory
@ gsto_memory
Definition: enums:173
tools::sg::state::m_model
mat4f m_model
Definition: state:245
tools::sg::gsto_gl_list
@ gsto_gl_list
Definition: enums:175
tools::colorf::r
float r() const
Definition: colorf:32
tools::vec3::z
const T & z() const
Definition: vec3:86
tools::sg::state::m_line_width
float m_line_width
Definition: state:267
tools::sg::state::m_color
colorf m_color
Definition: state:259
tools::sg::state::m_GL_BLEND
bool m_GL_BLEND
Definition: state:254
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::shade_smooth
@ shade_smooth
Definition: enums:199
tools::colorf::b
float b() const
Definition: colorf:34