summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-20 21:16:56 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-20 21:16:56 +0000
commitd3bba829acfb2eabce748220eff045ef0c6f7880 (patch)
tree323a58d0f97437bebd293dd6e73e18ee61f33f2e /Common/interface
parentUpdated readme (diff)
downloadDiligentCore-d3bba829acfb2eabce748220eff045ef0c6f7880.tar.gz
DiligentCore-d3bba829acfb2eabce748220eff045ef0c6f7880.zip
Multiple improvements to shader resource binding in D3D11 and D3D12
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/RefCntAutoPtr.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/Common/interface/RefCntAutoPtr.h b/Common/interface/RefCntAutoPtr.h
index 6a826c27..b76fd048 100644
--- a/Common/interface/RefCntAutoPtr.h
+++ b/Common/interface/RefCntAutoPtr.h
@@ -85,6 +85,7 @@ public:
pObj->QueryInterface( IID, reinterpret_cast<IObject**>(&m_pObject) );
}
+ // Copy constructor must not be template!
RefCntAutoPtr(const RefCntAutoPtr& AutoPtr) :
m_pObject(AutoPtr.m_pObject)
{
@@ -92,6 +93,13 @@ public:
m_pObject->AddRef();
}
+ template<typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
+ RefCntAutoPtr(const RefCntAutoPtr<DerivedType>& AutoPtr) :
+ RefCntAutoPtr<T>(AutoPtr.m_pObject)
+ {
+ }
+
+ // Non-template move constructor
RefCntAutoPtr(RefCntAutoPtr&& AutoPtr) :
m_pObject(std::move(AutoPtr.m_pObject))
{
@@ -99,6 +107,14 @@ public:
AutoPtr.m_pObject = nullptr;
}
+ template<typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
+ RefCntAutoPtr(RefCntAutoPtr<DerivedType>&& AutoPtr) :
+ m_pObject(std::move(AutoPtr.m_pObject))
+ {
+ //Make sure original pointer has no references to the object
+ AutoPtr.m_pObject = nullptr;
+ }
+
~RefCntAutoPtr()
{
Release();
@@ -149,16 +165,26 @@ public:
return *this = AutoPtr.m_pObject;
}
+ template<typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
+ RefCntAutoPtr& operator = (const RefCntAutoPtr<DerivedType>& AutoPtr)
+ {
+ return *this = static_cast<T*>(AutoPtr.m_pObject);
+ }
+
RefCntAutoPtr& operator = (RefCntAutoPtr&& AutoPtr)
{
if (m_pObject != AutoPtr.m_pObject)
- {
- if (m_pObject)
- m_pObject->Release();
- m_pObject = std::move(AutoPtr.m_pObject);
- //Make sure original pointer has no references to the object
- AutoPtr.m_pObject = nullptr;
- }
+ Attach(AutoPtr.Detach());
+
+ return *this;
+ }
+
+ template<typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
+ RefCntAutoPtr& operator = (RefCntAutoPtr<DerivedType>&& AutoPtr)
+ {
+ if (m_pObject != AutoPtr.m_pObject)
+ Attach(AutoPtr.Detach());
+
return *this;
}
@@ -245,6 +271,9 @@ public:
const T** GetRawDblPtr()const{return &m_pObject;}
private:
+ template<typename OtherType>
+ friend class RefCntAutoPtr;
+
T* m_pObject;
};