All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RefcountedAsyncTexture.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "IAsyncTexture.h"
6 
7 namespace Eegeo
8 {
9  namespace Rendering
10  {
11  namespace AsyncTexturing
12  {
13  template<typename TRefCounted>
15  {
16  public:
17  int GetReferenceCount() const
18  {
19  Eegeo_ASSERT(m_referenceCount >= 0, "invalid ref count -- mismatched Increment/Decrement")
20  return m_referenceCount;
21  }
22 
23  void IncrementReferenceCount()
24  {
25  m_referenceCount++;
26  Eegeo_ASSERT(m_referenceCount > 0, "invalid ref count -- mismatched Increment/Decrement");
27  }
28 
29  void DecrementReferenceCount()
30  {
31  Eegeo_ASSERT(m_referenceCount > 0, "invalid ref count -- mismatched Increment/Decrement");
32  m_referenceCount--;
33 
34  if (m_referenceCount == 0)
35  {
36  Self().DestroyTexture();
37  Eegeo_DELETE this;
38  }
39  }
40 
41  bool IsReferenced() const
42  {
43  Eegeo_ASSERT(m_referenceCount >= 0, "invalid ref count -- mismatched Increment/Decrement");
44  return m_referenceCount > 0;
45  }
46 
47  protected:
48  RefcountedAsyncTexture() : m_referenceCount(0) { }
49 
50  private:
51  TRefCounted& Self() { return *(Eegeo::CheckedCast<TRefCounted*>(this)); }
52 
53  int m_referenceCount;
54  };
55  }
56  }
57 }