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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_sg_gstos
  5 #define tools_sg_gstos
  6 
  7 #include "render_manager"
  8 #include <vector>
  9 #include <ostream>
 10 
 11 //#define TOOLS_SG_GSTOS_DEBUG
 12 
 13 namespace tools {
 14 namespace sg {
 15 
 16 class gstos {
 17 protected:
 18   gstos() {}
 19   virtual ~gstos() {clean_gstos();}
 20 protected:
 21   gstos(const gstos&) {}
 22   gstos& operator=(const gstos& a_from) {
 23     if(&a_from==this) return *this;
 24     clean_gstos();
 25     return *this;
 26   }
 27 public:
 28   size_t num_gstos() const {return m_gstos.size();}
 29 protected:
 30   unsigned int get_tex_id(std::ostream& a_out,render_manager& a_mgr,const img_byte& a_img,bool a_NEAREST) {
 31     unsigned int _id = _find(&a_mgr);
 32     if(_id && !a_mgr.is_gsto_id_valid(_id)){
 33 #ifdef TOOLS_SG_GSTOS_DEBUG
 34       a_out << "debug : tools::sg::gstos::get_tex_id : " << _id << " not valid." << std::endl;
 35 #endif
 36       clean_gstos(&a_mgr);
 37       _id = 0;
 38     }
 39     if(!_id) {
 40 #ifdef TOOLS_SG_GSTOS_DEBUG
 41       a_out << "debug : tools::sg::gstos::get_tex_id : create_texture ... " << std::endl;
 42 #endif
 43       _id = a_mgr.create_texture(a_img,a_NEAREST);
 44 #ifdef TOOLS_SG_GSTOS_DEBUG
 45       a_out << "debug : tools::sg::gstos::get_tex_id : create_texture : _id " << _id << "." << std::endl;
 46 #endif
 47       if(!_id) {
 48         a_out << "tools::sg::gstos::get_tex_id :"
 49               << " render_manager.create_texture() failed."
 50               << std::endl;
 51       } else {
 52         m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
 53       }
 54     }
 55     return _id;
 56   }
 57 protected:
 58   virtual unsigned int create_gsto(std::ostream&,render_manager&) {return 0;}
 59 
 60   unsigned int get_gsto_id(std::ostream& a_out,render_manager& a_mgr){
 61     unsigned int _id = _find(&a_mgr);
 62     if(_id && !a_mgr.is_gsto_id_valid(_id)){
 63 #ifdef TOOLS_SG_GSTOS_DEBUG
 64       a_out << "debug : tools::sg::gstos::get_gsto_id : " << _id << " not valid." << std::endl;
 65 #endif
 66       clean_gstos(&a_mgr);
 67       _id = 0;
 68     }
 69     if(!_id) {
 70 #ifdef TOOLS_SG_GSTOS_DEBUG
 71       a_out << "debug : tools::sg::gstos::get_gsto_id : create_gsto ..." << std::endl;
 72 #endif
 73       _id = create_gsto(a_out,a_mgr);
 74 #ifdef TOOLS_SG_GSTOS_DEBUG
 75       a_out << "debug : tools::sg::gstos::get_gsto_id : create_gsto : _id " << _id << "." << std::endl;
 76 #endif
 77       if(!_id) {
 78         // could be ok if there is no graphical data to load.
 79         //a_out << "tools::sg::gstos::get_gsto_id :"
 80         //      << " create_gsto() failed."
 81         //      << std::endl;
 82       } else {
 83         m_gstos.push_back(std::pair<unsigned int,render_manager*>(_id,&a_mgr));
 84       }
 85     }
 86     return _id;
 87   }
 88 protected:
 89   void clean_gstos() {
 90     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
 91     for(it=m_gstos.begin();it!=m_gstos.end();){
 92       (*it).second->delete_gsto((*it).first);
 93       it = m_gstos.erase(it);
 94     }
 95   }
 96   void clean_gstos(render_manager* a_mgr) {
 97     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
 98     for(it=m_gstos.begin();it!=m_gstos.end();){
 99       if((*it).second==a_mgr) {
100         (*it).second->delete_gsto((*it).first);
101         it = m_gstos.erase(it);
102       } else {
103         it++;
104       }
105     }
106   }
107 protected:
108   unsigned int _find(render_manager* a_mgr) {
109     std::vector< std::pair<unsigned int,render_manager*> >::iterator it;
110     for(it=m_gstos.begin();it!=m_gstos.end();++it){
111       if((*it).second==a_mgr) return (*it).first;
112     }
113     return 0;
114   }
115 
116 protected:
117   std::vector< std::pair<unsigned int,render_manager*> > m_gstos;
118 };
119 
120 }}
121 
122 #endif