Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resourcebase.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_RESOURCEBASE_H_
19 #define ION_GFX_RESOURCEBASE_H_
20 
21 #include <stddef.h>
22 #include <cstdint>
23 
24 namespace ion {
25 namespace gfx {
26 
28 
31 typedef intptr_t ResourceKey;
32 
36 class ResourceBase {
37  public:
41  explicit ResourceBase(const ResourceHolder* holder, ResourceKey key)
42  : holder_(holder),
43  key_(key) {}
44  virtual ~ResourceBase() {}
45 
47  const ResourceHolder* GetHolder() const { return holder_; }
48 
51  ResourceKey GetKey() const { return key_; }
52 
55 
60  virtual void OnDestroyed() = 0;
61 
64  virtual void OnChanged(const int bit) = 0;
65 
71  virtual size_t GetGpuMemoryUsed() const = 0;
72 
73  private:
74  const ResourceHolder* holder_;
75  const ResourceKey key_;
76 
77  friend class ResourceHolder;
78 };
79 
80 } // namespace gfx
81 } // namespace ion
82 
83 #endif // ION_GFX_RESOURCEBASE_H_
const ResourceHolder * GetHolder() const
Retrieve the holder for which this resource was created.
Definition: resourcebase.h:47
virtual size_t GetGpuMemoryUsed() const =0
Returns the amount of GPU memory in bytes that this resource uses.
ResourceKey GetKey() const
Retrieve a key that disambiguates between multiple resources created for the same holder by the same ...
Definition: resourcebase.h:51
virtual void OnDestroyed()=0
Each derived class must define these to acquire and release its resource.
intptr_t ResourceKey
Type of identifiers used to disambiguate between multiple resources created for the same Ion object b...
Definition: resourcebase.h:27
ResourceBase is an internal abstract base class for managed resources.
Definition: resourcebase.h:36
virtual void OnChanged(const int bit)=0
Informs the resource that something has changed and that it needs to update itself.
ResourceBase(const ResourceHolder *holder, ResourceKey key)
The constructor accepts a holder parameter to simplify control flow during construction.
Definition: resourcebase.h:41
ResourceHolder is an internal base class for objects that hold resources managed by an outside entity...