Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cDXBase.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cDXBase_H
8 #define _INC_cDXBase_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "UseDX.h"
14 
15 namespace Gray3D
16 {
17  class cDXDevice;
18 
20  {
26 
27  public:
29 
31  cIUnkPtr<ID3DDevice> m_pD3DDev; // fast pointer into m_pDXDev above to indicate Active device. ! Lost = nullptr
32 
33  public:
34  cDXBase(cDXDevice* pDXDev = nullptr) noexcept;
35  virtual ~cDXBase();
36 
37  ID3DDevice* get_D3DDev() const noexcept
38  {
40  DEBUG_CHECK(m_pD3DDev.isValidPtr());
41  return m_pD3DDev;
42  }
43  bool isInitDevice() const noexcept
44  {
46  return m_pDXDev != nullptr;
47  }
48  bool isLostDevice() const noexcept
49  {
51  return m_pD3DDev == nullptr;
52  }
53 
54  virtual HRESULT InitDeviceObjects(cDXDevice* pDXDev);
55  virtual HRESULT OnResetDeviceX();
56  virtual HRESULT OnLostDeviceX();
57  virtual HRESULT DeleteDeviceObjects();
58 
60  };
61 
62 #ifdef USE_DXX
63  template <class _TYPE>
64  class GRAY3D_LINK cDXBaseT : public cDXBase
65  {
69 
70  typedef cDXBase SUPER_t;
71 
72  protected:
73  cIUnkPtr<_TYPE> m_pDXObj;
74 
75  public:
76  cDXBaseT(_TYPE* pDXObj = nullptr)
77  : m_pDXObj(pDXObj)
78  {
79  }
80  cDXBaseT(const cDXBaseT<_TYPE>& Obj)
81  : m_pDXObj(Obj.m_pDXObj)
82  {
84  }
85 
86  virtual HRESULT OnLostDeviceX() override
87  {
90  if (m_pDXObj != nullptr)
91  {
92  m_pDXObj->OnLostDevice();
93  }
94  return SUPER_t::OnLostDeviceX();
95  }
96  virtual HRESULT OnResetDeviceX() override
97  {
99  if (!isInitDevice())
100  {
101  // ASSERT(0);
102  return E_FAIL;
103  }
104  if (m_pDXObj != nullptr)
105  {
106  m_pDXObj->OnResetDevice();
107  }
108  return SUPER_t::OnResetDeviceX();
109  }
110  virtual HRESULT DeleteDeviceObjects() override
111  {
113  m_pDXObj.ReleasePtr();
114  return SUPER_t::DeleteDeviceObjects();
115  }
116 
117  _TYPE* get_DXObj() const noexcept
118  {
119  return m_pDXObj;
120  }
121  operator _TYPE* () const noexcept
122  {
123  return m_pDXObj;
124  }
125  };
126 #endif
127 
128 }
129 
130 #endif // _INC_cDXBase_H
#define GRAY3D_LINK
Definition: Gray3D.h:15
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
Definition: cDXBase.h:20
bool isLostDevice() const noexcept
Definition: cDXBase.h:48
cDXDevice * m_pDXDev
What device is this attached to (or should be)? InitDeviceObjects() was called and DeleteDeviceObject...
Definition: cDXBase.h:28
UNITTEST_FRIEND(cDXBase)
bool isInitDevice() const noexcept
Definition: cDXBase.h:43
cIUnkPtr< ID3DDevice > m_pD3DDev
Definition: cDXBase.h:31
Definition: cDXDevice.h:20
Definition: cIUnkPtr.h:32
int ReleasePtr()
Definition: cIUnkPtr.h:207
bool isValidPtr() const noexcept
Definition: cPtrFacade.h:41
Definition: IUnknown.h:68
Definition: Gray3D.cpp:12