]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resourcemanager.h
Use DSA for binding textures if available
[libs/gl.git] / source / resourcemanager.h
index 9378d920c9671743daafddfec70def0acee39e68..9dcd9b997a56a25214ea691d27f2f616197ae55f 100644 (file)
@@ -11,7 +11,7 @@
 namespace Msp {
 namespace GL {
 
-class ResourceWatcher;
+class ResourceObserver;
 
 class resource_load_error: public std::runtime_error
 {
@@ -62,7 +62,7 @@ private:
                State state;
                unsigned last_used;
                UInt64 data_size;
-               std::vector<ResourceWatcher *> watchers;
+               std::vector<ResourceObserver *> observers;
 
                ManagedResource(Resource &);
 
@@ -72,8 +72,8 @@ private:
                void finish_loading();
                void unload();
 
-               void add_watcher(ResourceWatcher &);
-               void remove_watcher(ResourceWatcher &);
+               void add_observer(ResourceObserver &);
+               void remove_observer(ResourceObserver &);
        };
 
        typedef std::list<ManagedResource *> LoadQueue;
@@ -88,6 +88,8 @@ private:
                unsigned capacity;
                unsigned size;
                std::list<resource_load_error> error_queue;
+               Mutex data_size_mutex;
+               UInt64 loaded_data_size;
                volatile bool done;
 
        public:
@@ -106,6 +108,7 @@ private:
        public:
                bool sync();
                bool needs_work() const { return size<capacity; }
+               UInt64 get_and_reset_loaded_data_size();
 
                void terminate();
        };
@@ -117,6 +120,7 @@ private:
        mutable Mutex map_mutex;
        ResourceMap resources;
        LoadQueue queue;
+       UInt64 total_data_size;
        UInt64 size_limit;
        unsigned frame;
        unsigned min_retain_frames;
@@ -148,17 +152,20 @@ public:
        void resource_used(const Resource &);
        void remove_resource(Resource &);
 
-       void watch_resource(const Resource &, ResourceWatcher &);
-       void unwatch_resource(const Resource &, ResourceWatcher &);
+       void observe_resource(const Resource &, ResourceObserver &);
+       void unobserve_resource(const Resource &, ResourceObserver &);
+
+       // Deprecated names
+       void watch_resource(const Resource &r, ResourceObserver &o) { observe_resource(r, o); }
+       void unwatch_resource(const Resource &r, ResourceObserver &o) { unobserve_resource(r, o); }
 
        void tick();
 private:
        void dispatch_work();
        void unload_by_age();
        void unload_by_size();
-       UInt64 get_total_data_size_() const;
 public:
-       UInt64 get_total_data_size() const;
+       UInt64 get_total_data_size() const { return total_data_size; }
 
 private:
        static bool age_order(ManagedResource *, ManagedResource *);