Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef toolx_sg_GL_viewer 5 #define toolx_sg_GL_viewer 6 7 #include <tools/sg/viewer> 8 9 #include "GL_manager" 10 #include "GL_action" 11 12 namespace toolx { 13 namespace sg { 14 15 class GL_viewer : public tools::sg::viewer { 16 TOOLS_HEADER(GL_viewer,toolx::sg::GL_viewer,tools::sg::viewer) 17 public: 18 void render() { 19 if(!m_ww) return; 20 if(!m_wh) return; 21 22 m_gl_mgr.begin_render(0,0,m_ww,m_wh, 23 m_clear_color.r(), 24 m_clear_color.g(), 25 m_clear_color.b(), 26 m_clear_color.a()); 27 28 GL_action action(m_gl_mgr,m_out,m_ww,m_wh); 29 action.state().m_use_gsto = m_use_gsto; 30 31 action.set_do_transparency(false); 32 action.set_have_to_do_transparency(false); 33 34 m_sg.render(action); 35 if(!action.end()) { //check that matrices stack are ok. 36 m_out << "toolx::sg::GL_viewer : bad gl_action end." << std::endl; 37 } else { 38 if(action.have_to_do_transparency()) { 39 action.set_do_transparency(true); 40 m_sg.render(action); 41 if(!action.end()) { //check that matrices stack are ok. 42 m_out << "toolx::sg::GL_viewer : bad gl_action end." << std::endl; 43 } 44 } 45 } 46 47 //after_render(); 48 49 m_gl_mgr.end_render(); 50 } 51 52 public: 53 GL_viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height) 54 :parent(a_out,a_width,a_height) 55 ,m_gl_mgr(a_out) 56 {} 57 virtual ~GL_viewer(){ 58 //WARNING : nodes may refer m_gl_mgr (to handle gstos/texs), then 59 // we have to delete them first. 60 m_sg.clear(); 61 } 62 public: 63 GL_viewer(const GL_viewer& a_from) 64 :parent(a_from) 65 ,m_gl_mgr(a_from.m_gl_mgr) 66 {} 67 GL_viewer& operator=(const GL_viewer& a_from){ 68 parent::operator=(a_from); 69 m_gl_mgr = a_from.m_gl_mgr; 70 return *this; 71 } 72 protected: 73 GL_manager m_gl_mgr; 74 }; 75 76 }} 77 78 #endif