// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef toolx_sg_GL_action #define toolx_sg_GL_action #include "GL_manager" #include namespace toolx { namespace sg { template class GL_action_T : public tools::sg::render_action, protected GL_FUNCTIONS { using parent_gl_functions = GL_FUNCTIONS; private: TOOLS_T_ACTION(GL_FUNCTIONS,GL_action_T,toolx::sg::GL_action_T,tools::sg::render_action) public: virtual void draw_vertex_array(tools::gl::mode_t a_mode,size_t a_floatn,const float* a_xyzs){ size_t num = a_floatn/3; if(!num) return; _draw_v(a_mode,num,a_xyzs); } virtual void draw_vertex_array_xy(tools::gl::mode_t a_mode,size_t a_floatn,const float* a_xys){ size_t num = a_floatn/2; if(!num) return; #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::draw_vertex_array_xy : glGenVertexArrays failed ()." << std::endl; return; } parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::draw_vertex_array_xy : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } std::vector gsto_data; size_t ngsto = num*2; //num points * 2 coords gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_xys,ngsto*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),2,GL_FLOAT,GL_FALSE,0,NULL); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)num); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 #ifdef _WIN32 float* vp = new float[num*3]; if(!vp) return; float* pos = vp; float* pda = (float*)a_xys; for(size_t index=0;index gsto_data; gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_xyzs,a_floatn*sizeof(float)); ::memcpy(_gsto_data+nxyzs,a_tex_coords,ntcs*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0);} //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); {char* pos_xyzs = NULL; char* pos_tcs = NULL;pos_tcs += nxyzs*sizeof(float); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_tex_location(),2,GL_FLOAT,GL_FALSE,0,pos_tcs);} parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0); m_mgr.bind_gsto(a_tex); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__Uniform1i(m_mgr.g_tex_on_location(),1); parent_gl_functions::gl__Uniform1i(m_mgr.g_sampler_location(),0); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_tex_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)num); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_tex_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_tex_on_location(),0); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindTexture(GL_TEXTURE_2D,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__Enable(GL_TEXTURE_2D); m_mgr.bind_gsto(a_tex); parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__EnableClientState(GL_TEXTURE_COORD_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_xyzs); parent_gl_functions::gl__TexCoordPointer(2,GL_FLOAT,0,a_tex_coords); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)num); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__DisableClientState(GL_TEXTURE_COORD_ARRAY); parent_gl_functions::gl__BindTexture(GL_TEXTURE_2D,0); parent_gl_functions::gl__Disable(GL_TEXTURE_2D); #endif //not TOOLS_USE_GL_VERSION_3_2 } 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) { size_t num = a_floatn/3; if(!num) return; //expect 2*num a_tex_coords. #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::draw_vertex_normal_array_texture : glGenVertexArrays failed ()." << std::endl; return; } size_t nxyzs = a_floatn; size_t nnms = nxyzs; parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::draw_vertex_normal_array_texture : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } {size_t ntcs = num*2; size_t ngsto = nxyzs+nnms+ntcs; std::vector gsto_data; gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_xyzs,nxyzs*sizeof(float)); ::memcpy(_gsto_data+nxyzs,a_nms,nnms*sizeof(float)); ::memcpy(_gsto_data+nxyzs+nnms,a_tex_coords,ntcs*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0);} //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); {char* pos_xyzs = NULL; char* pos_nms = NULL;pos_nms += nxyzs*sizeof(float); char* pos_tcs = NULL;pos_tcs += (nxyzs+nnms)*sizeof(float); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_normal_location(),3,GL_FLOAT,GL_FALSE,0,pos_nms); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_tex_location(),2,GL_FLOAT,GL_FALSE,0,pos_tcs); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0);} m_mgr.bind_gsto(a_tex); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__Uniform1i(m_mgr.g_tex_on_location(),1); parent_gl_functions::gl__Uniform1i(m_mgr.g_sampler_location(),0); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_tex_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)num); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_tex_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_tex_on_location(),0); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),false); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindTexture(GL_TEXTURE_2D,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__Enable(GL_TEXTURE_2D); m_mgr.bind_gsto(a_tex); parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__EnableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__EnableClientState(GL_TEXTURE_COORD_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_xyzs); parent_gl_functions::gl__NormalPointer(GL_FLOAT,0,a_nms); parent_gl_functions::gl__TexCoordPointer(2,GL_FLOAT,0,a_tex_coords); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)num); parent_gl_functions::gl__DisableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__DisableClientState(GL_TEXTURE_COORD_ARRAY); parent_gl_functions::gl__BindTexture(GL_TEXTURE_2D,0); parent_gl_functions::gl__Disable(GL_TEXTURE_2D); #endif //not TOOLS_USE_GL_VERSION_3_2 } ///////////////////////////////////////////////////////////////// /// gsto //////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// virtual void begin_gsto(gstoid a_id) { switch(m_mgr.get_gsto_mode()){ case tools::sg::gsto_gl_vbo:{ m_mgr.bind_gsto(a_id); }break; case tools::sg::gsto_gl_list:{ #ifndef TOOLS_USE_GL_VERSION_3_2 m_gsto = a_id; m_created = false; m_gl_id = m_mgr.gsto_gl_list_id(a_id,m_created); if(m_gl_id && m_created) { parent_gl_functions::gl__NewList(m_gl_id,GL_COMPILE); } #endif }break; case tools::sg::gsto_memory:{ m_gsto = a_id; }break; } } virtual void end_gsto() { switch(m_mgr.get_gsto_mode()){ case tools::sg::gsto_gl_vbo:{ m_mgr.unbind_gsto(); }break; case tools::sg::gsto_gl_list:{ #ifndef TOOLS_USE_GL_VERSION_3_2 if(m_gl_id && m_created) { parent_gl_functions::gl__EndList(); } if(m_gl_id) parent_gl_functions::gl__CallList(m_gl_id); m_created = false; m_gl_id = 0; m_gsto = 0; #endif }break; case tools::sg::gsto_memory:{ m_gsto = 0; }break; } } typedef tools::sg::bufpos bufpos; virtual void draw_gsto_v(tools::gl::mode_t a_mode,size_t a_elems,bufpos a_pos_xyzs){ switch(m_mgr.get_gsto_mode()){ case tools::sg::gsto_gl_vbo:{ #ifdef TOOLS_USE_GL_VERSION_3_2 char* pos_xyzs = NULL;pos_xyzs += a_pos_xyzs; _draw_shader_v(a_mode,a_elems,pos_xyzs); #endif }break; case tools::sg::gsto_gl_list:{ #ifndef TOOLS_USE_GL_VERSION_3_2 float* buffer = m_mgr.gsto_data(m_gsto); if(!buffer) return; char* pos_xyzs = (char*)buffer;pos_xyzs += a_pos_xyzs; if(m_gl_id && m_created) { parent_gl_functions::gl__Begin(a_mode); float* pos = (float*)pos_xyzs; for(size_t index=0;index& a_mgr,std::ostream& a_out,unsigned int a_ww,unsigned int a_wh) :parent(a_out,a_ww,a_wh) ,m_mgr(a_mgr) ,m_gsto(0) #ifndef TOOLS_USE_GL_VERSION_3_2 ,m_created(false) ,m_gl_id(0) #endif { if (!parent_gl_functions::initialize()) { m_out << "toolx::sg::GL_action_T::GL_action_T: warning: parent_gl_functions::initialize() failed." << std::endl; } #ifdef TOOLS_USE_GL_VERSION_3_2 m_model.set_identity(); m_proj.set_identity(); #endif } virtual ~GL_action_T(){} public: GL_action_T(const GL_action_T& a_from) :parent(a_from) ,parent_gl_functions(a_from) ,m_mgr(a_from.m_mgr) ,m_gsto(0) #ifndef TOOLS_USE_GL_VERSION_3_2 ,m_created(false) ,m_gl_id(0) #endif { if (!parent_gl_functions::initialize()) { m_out << "toolx::sg::GL_action_T::GL_action_T: warning: parent_gl_functions::initialize() failed." << std::endl; } } GL_action_T& operator=(const GL_action_T& a_from){ render_action::operator=(a_from); m_gsto = 0; #ifndef TOOLS_USE_GL_VERSION_3_2 m_created = false; m_gl_id = 0; #endif return *this; } protected: #ifdef TOOLS_USE_GL_VERSION_3_2 void _draw_shader_v(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs){ if(!a_elems) return; parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_xyzs); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); } #endif void _draw_v(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs){ if(!a_elems) return; #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::_draw_v : glGenVertexArrays failed ()." << std::endl; return; } parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::_draw_v : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } std::vector gsto_data; size_t ngsto = a_elems*3; //a_elems points * 3 coords gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_pos_xyzs,ngsto*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,NULL); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_pos_xyzs); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); #endif //not TOOLS_USE_GL_VERSION_3_2 } #ifdef TOOLS_USE_GL_VERSION_3_2 void _draw_shader_vc(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs,const void* a_pos_rgbas){ if(!a_elems) return; parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_color_location(),4,GL_FLOAT,GL_FALSE,0,a_pos_rgbas); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),false); } #endif void _draw_vc(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs,const void* a_pos_rgbas){ if(!a_elems) return; #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::_draw_vc : glGenVertexArrays failed ()." << std::endl; return; } parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::_draw_vc : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } std::vector gsto_data; size_t nxyzs = a_elems*3; //a_elems points * 3 coords size_t nrgbas = a_elems*4; size_t ngsto = nxyzs+nrgbas; gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_pos_xyzs,nxyzs*sizeof(float)); ::memcpy(_gsto_data+nxyzs,a_pos_rgbas,nrgbas*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); char* pos_xyzs = NULL; char* pos_rgbas = NULL;pos_rgbas += nxyzs*sizeof(float); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_color_location(),4,GL_FLOAT,GL_FALSE,0,pos_rgbas); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),false); parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__EnableClientState(GL_COLOR_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_pos_xyzs); parent_gl_functions::gl__ColorPointer(4,GL_FLOAT,0,a_pos_rgbas); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableClientState(GL_COLOR_ARRAY); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); #endif //not TOOLS_USE_GL_VERSION_3_2 } #ifdef TOOLS_USE_GL_VERSION_3_2 void _draw_shader_vn(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs,const void* a_pos_nms){ if(!a_elems) return; parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_normal_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_nms); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),false); } #endif void _draw_vn(tools::gl::mode_t a_mode,size_t a_elems,const void* a_pos_xyzs,const void* a_pos_nms){ if(!a_elems) return; #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::_draw_vn : glGenVertexArrays failed ()." << std::endl; return; } parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::_draw_vn : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } size_t nxyzs = a_elems*3; //a_elems points * 3 coords {std::vector gsto_data; size_t nnms = nxyzs; size_t ngsto = nxyzs+nnms; gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_pos_xyzs,nxyzs*sizeof(float)); ::memcpy(_gsto_data+nxyzs,a_pos_nms,nnms*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0);} //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// {char* pos_xyzs = NULL; char* pos_nms = NULL;pos_nms += nxyzs*sizeof(float); parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_normal_location(),3,GL_FLOAT,GL_FALSE,0,pos_nms); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0);} parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),false); parent_gl_functions::gl__BindVertexArray(0); parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__EnableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_pos_xyzs); parent_gl_functions::gl__NormalPointer(GL_FLOAT,0,a_pos_nms); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); #endif //not TOOLS_USE_GL_VERSION_3_2 } #ifdef TOOLS_USE_GL_VERSION_3_2 void _draw_shader_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){ if(!a_elems) return; parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_normal_location(),3,GL_FLOAT,GL_FALSE,0,a_pos_nms); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_color_location(),4,GL_FLOAT,GL_FALSE,0,a_pos_rgbas); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),true); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),false); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),false); } #endif 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){ if(!a_elems) return; #ifdef TOOLS_USE_GL_VERSION_3_2 GLuint vao_id = 0; parent_gl_functions::gl__GenVertexArrays(1,&vao_id); if(!vao_id) { m_out << "toolx::sg::GL_action_T::_draw_vcn : glGenVertexArrays failed ()." << std::endl; return; } size_t nxyzs = a_elems*3; //a_elems points * 3 coords parent_gl_functions::gl__BindVertexArray(vao_id); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// unsigned int vbo_id = 0; parent_gl_functions::gl__GenBuffers(1,&vbo_id); if(!vbo_id) { m_out << "toolx::sg::GL_action_T::_draw_vcn : glGenBuffers failed ()." << std::endl; parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); return; } {std::vector gsto_data; size_t nnms = nxyzs; size_t nrgbas = a_elems*4; size_t ngsto = nxyzs+nnms+nrgbas; gsto_data.resize(ngsto); float* _gsto_data = gsto_data.data(); ::memcpy(_gsto_data,a_pos_xyzs,nxyzs*sizeof(float)); ::memcpy(_gsto_data+nxyzs,a_pos_nms,nnms*sizeof(float)); ::memcpy(_gsto_data+nxyzs+nnms,a_pos_rgbas,nrgbas*sizeof(float)); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); parent_gl_functions::gl__BufferData(GL_ARRAY_BUFFER,gsto_data.size()*sizeof(float),_gsto_data,GL_STATIC_DRAW); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0);} //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// {parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,vbo_id); char* pos_xyzs = NULL; char* pos_nms = NULL;pos_nms += nxyzs*sizeof(float); char* pos_rgbas = NULL;pos_rgbas += 2*nxyzs*sizeof(float); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_pos_location(),3,GL_FLOAT,GL_FALSE,0,pos_xyzs); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_normal_location(),3,GL_FLOAT,GL_FALSE,0,pos_nms); parent_gl_functions::gl__VertexAttribPointer(m_mgr.g_one_color_location(),4,GL_FLOAT,GL_FALSE,0,pos_rgbas); parent_gl_functions::gl__BindBuffer(GL_ARRAY_BUFFER,0); parent_gl_functions::gl__BindVertexArray(0);} parent_gl_functions::gl__BindVertexArray(vao_id); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),true); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),true); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__EnableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_pos_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_normal_location()); parent_gl_functions::gl__DisableVertexAttribArray(m_mgr.g_one_color_location()); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_normal_location(),false); parent_gl_functions::gl__Uniform1i(m_mgr.g_pos_color_location(),false); parent_gl_functions::gl__BindVertexArray(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// parent_gl_functions::gl__DeleteBuffers(1,&vbo_id); parent_gl_functions::gl__DeleteVertexArrays(1,&vao_id); #else //not TOOLS_USE_GL_VERSION_3_2 parent_gl_functions::gl__EnableClientState(GL_VERTEX_ARRAY); parent_gl_functions::gl__EnableClientState(GL_COLOR_ARRAY); parent_gl_functions::gl__EnableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__VertexPointer(3,GL_FLOAT,0,a_pos_xyzs); parent_gl_functions::gl__ColorPointer(4,GL_FLOAT,0,a_pos_rgbas); parent_gl_functions::gl__NormalPointer(GL_FLOAT,0,a_pos_nms); parent_gl_functions::gl__DrawArrays(a_mode,0,(GLsizei)a_elems); parent_gl_functions::gl__DisableClientState(GL_COLOR_ARRAY); parent_gl_functions::gl__DisableClientState(GL_NORMAL_ARRAY); parent_gl_functions::gl__DisableClientState(GL_VERTEX_ARRAY); #endif //not TOOLS_USE_GL_VERSION_3_2 } protected: GL_manager_T& m_mgr; gstoid m_gsto; #ifndef TOOLS_USE_GL_VERSION_3_2 bool m_created; gstoid m_gl_id; #endif #ifdef TOOLS_USE_GL_VERSION_3_2 tools::mat4f m_model; tools::mat4f m_proj; #endif }; }} #endif