Changeset 229 for trunk/nv/resource.hh


Ignore:
Timestamp:
05/06/14 04:59:23 (11 years ago)
Author:
epyon
Message:
  • framebuffer extension added to gl
  • various minro changes and fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/resource.hh

    r121 r229  
    2323        {
    2424        public:
    25                 typedef std::shared_ptr< resource > ptr;
    26         public:
     25                resource() : m_size(0), m_rid(0), m_used(0), m_loaded(0), m_data(nullptr) {}
    2726                virtual bool load() = 0;
     27                virtual bool initialize() { return true; };
     28                virtual bool destroy() { return true; };
    2829                virtual bool unload() = 0;
    2930                bool is_loaded() const { return m_loaded; }
    3031                uid get_rid() const { return m_rid; }
    3132                uid get_size() const { return m_size; }
     33                const void* get() { return m_data; }
     34                void lock() { m_used++; }
     35                void unlock() { m_used--; }
    3236                virtual ~resource() {}
    3337        private:
    3438                uint32 m_size;
    3539                uint32 m_rid;
     40                uint32 m_used;
    3641                bool   m_loaded;
     42                void*  m_data;
     43        };
     44
     45        template< class DATA >
     46        class resource_type : public resource
     47        {
     48        public:
     49                explicit resource_type( DATA* data ) : m_data( data ) {}
     50                virtual bool load() { return true; };
     51                virtual bool unload() { return true; };
     52                ~resource_type() { delete data; }
     53        };
     54
     55
     56
     57        template< class DATA >
     58        class resource_handle
     59        {
     60        public:
     61                explicit resource_handle( resource_type< DATA >& m_resource )
     62                        : m_resource( &a_resource ) { m_resource.lock(); }
     63                void assign( resource_type< DATA >& a_resource )
     64                {
     65                        m_resource.unlock();
     66                        m_resource = a_resource;
     67                        m_resource.lock();
     68                }
     69                const DATA* operator->() const { return (const DATA*)m_resource.get(); }
     70                ~resource_handle() { m_resource.unlock(); }
     71        private:
     72                resource& m_resource;
    3773        };
    3874
Note: See TracChangeset for help on using the changeset viewer.