Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_zb_manager 5 #define tools_sg_zb_manager 6 7 #include "render_manager" 8 9 #ifdef TOOLS_MEM 10 #include "../mem" 11 #endif 12 13 #include <map> 14 15 namespace tools { 16 namespace sg { 17 18 class zb_manager : public virtual render_manager { 19 typedef render_manager parent; 20 public: 21 TOOLS_SCLASS(tools::sg::zb_manager) 22 virtual void* cast(const std::string& a_class) const { 23 if(void* p = cmp_cast<zb_manager>(this,a_class)) {return p;} 24 else return 0; 25 } 26 public: 27 virtual bool begin_render(int,int,unsigned int,unsigned int,float,float,float,float,bool = true) {return true;} 28 virtual void end_render() {} 29 30 virtual unsigned int create_texture(const img_byte& a_img,bool /*a_NEAREST*/) { 31 m_gen_id++; //never return 0. 32 m_gstos[m_gen_id] = a_img; 33 return m_gen_id; 34 } 35 36 virtual unsigned int create_gsto_from_data(size_t,const float*) {return 0;} 37 38 virtual bool is_gsto_id_valid(unsigned int a_id) const { 39 gstos_t::const_iterator it = m_gstos.find(a_id); 40 if(it==m_gstos.end()) return false; 41 return true; 42 } 43 virtual void delete_gsto(unsigned int a_id) { 44 gstos_t::iterator it = m_gstos.find(a_id); 45 if(it!=m_gstos.end()) m_gstos.erase(it); 46 } 47 48 // 49 virtual gsto_mode get_gsto_mode() const {return gsto_memory;} 50 virtual void set_gsto_mode(gsto_mode) {} 51 virtual void available_gsto_modes(std::vector<std::string>& a_v) {a_v.clear();} 52 virtual void available_not_memory_gsto_mode(std::string& a_s) const {a_s.clear();} 53 virtual size_t used_texture_memory() const {return 0;} 54 virtual size_t gstos_size() const {return 0;} 55 public: 56 zb_manager():m_gen_id(0){ 57 #ifdef TOOLS_MEM 58 mem::increment(s_class().c_str()); 59 #endif 60 } 61 virtual ~zb_manager(){ 62 m_gstos.clear(); 63 #ifdef TOOLS_MEM 64 mem::decrement(s_class().c_str()); 65 #endif 66 } 67 public: 68 zb_manager(const zb_manager& a_from) 69 :parent(a_from) 70 ,m_gen_id(0) 71 ,m_gstos() 72 { 73 #ifdef TOOLS_MEM 74 mem::increment(s_class().c_str()); 75 #endif 76 } 77 zb_manager& operator=(const zb_manager& a_from){ 78 if(&a_from==this) return *this; 79 m_gen_id = 0; 80 m_gstos.clear(); 81 return *this; 82 } 83 public: 84 bool find(unsigned int a_id,img_byte& a_img) { 85 gstos_t::iterator it = m_gstos.find(a_id); 86 if(it==m_gstos.end()) return false; 87 a_img = (*it).second; 88 return true; 89 } 90 //void cleanup() {} 91 void delete_gstos() {m_gstos.clear();} 92 protected: 93 unsigned int m_gen_id; 94 typedef std::map<unsigned int,img_byte> gstos_t; 95 gstos_t m_gstos; //only textures for the moment. 96 }; 97 98 }} 99 100 #endif