Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

374 lines
13 KiB

  1. #ifndef __VBUFFER_HPP__
  2. #define __VBUFFER_HPP__
  3. /*==========================================================================;
  4. *
  5. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * File: vbuffer.hpp
  8. * Content: Class header the vertex buffer class
  9. *
  10. ***************************************************************************/
  11. // Includes
  12. #include "buffer.hpp"
  13. // The base-class implementation of the vertex buffer assumes
  14. // that it is resides system-memory. It may be managed.
  15. class CVertexBuffer : public IDirect3DVertexBuffer8, public CBuffer
  16. {
  17. public:
  18. // Creation function for Vertex Buffers
  19. static HRESULT Create(CBaseDevice *pDevice,
  20. DWORD cbLength,
  21. DWORD dwUsage,
  22. DWORD dwFVF,
  23. D3DPOOL Pool,
  24. REF_TYPE refType,
  25. IDirect3DVertexBuffer8 **ppVertexBuffer);
  26. static HRESULT CreateSysmemVertexBuffer(CBaseDevice *pDevice,
  27. DWORD cbLength,
  28. DWORD dwFVF,
  29. DWORD dwUsage,
  30. DWORD dwActualUsage,
  31. D3DPOOL Pool,
  32. D3DPOOL ActualPool,
  33. REF_TYPE refType,
  34. CVertexBuffer **pVB);
  35. static HRESULT CreateDriverVertexBuffer(CBaseDevice *pDevice,
  36. DWORD cbLength,
  37. DWORD dwFVF,
  38. DWORD dwUsage,
  39. DWORD dwActualUsage,
  40. D3DPOOL Pool,
  41. D3DPOOL ActualPool,
  42. REF_TYPE refType,
  43. CVertexBuffer **pVB);
  44. static HRESULT CreateDriverManagedVertexBuffer(CBaseDevice *pDevice,
  45. DWORD cbLength,
  46. DWORD dwFVF,
  47. DWORD dwUsage,
  48. DWORD dwActualUsage,
  49. D3DPOOL Pool,
  50. D3DPOOL ActualPool,
  51. REF_TYPE refType,
  52. CVertexBuffer **pVB);
  53. // Methods for Resource Management
  54. // Create duplicate of current object in new pool;
  55. // LOD is ignored for our type
  56. virtual HRESULT Clone(D3DPOOL Pool,
  57. CResource **ppResource) const;
  58. virtual const D3DBUFFER_DESC* GetBufferDesc() const;
  59. virtual HRESULT LockI(DWORD dwFlags) {return D3D_OK;}
  60. virtual HRESULT UnlockI() {return D3D_OK;}
  61. virtual void SetCachedDataPointer(BYTE *pData) {}
  62. HRESULT UpdateDirtyPortion(CResource *pResourceTarget);
  63. DWORD GetFVF() const { return m_desc.FVF; }
  64. // IUnknown methods
  65. STDMETHOD(QueryInterface) (REFIID riid,
  66. LPVOID FAR * ppvObj);
  67. STDMETHOD_(ULONG,AddRef) ();
  68. STDMETHOD_(ULONG,Release) ();
  69. // Some Methods for IDirect3DBuffer
  70. STDMETHOD(SetPrivateData)(REFGUID riid,
  71. CONST VOID *pvData,
  72. DWORD cbData,
  73. DWORD dwFlags);
  74. STDMETHOD(GetPrivateData)(REFGUID riid,
  75. LPVOID pvData,
  76. LPDWORD pcbData);
  77. STDMETHOD(FreePrivateData)(REFGUID riid);
  78. STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  79. STDMETHOD_(DWORD, GetPriority)();
  80. STDMETHOD_(DWORD, SetPriority)(DWORD dwPriority);
  81. STDMETHOD_(void, PreLoad)();
  82. STDMETHOD_(D3DRESOURCETYPE, GetType)();
  83. // Methods for IDirect3DVertexBuffer8
  84. STDMETHOD(Lock)(UINT cbOffsetToLock,
  85. UINT cbSizeToLock,
  86. BYTE **ppbData,
  87. DWORD dwFlags);
  88. STDMETHOD(Unlock)();
  89. STDMETHOD(GetDesc)(D3DVERTEXBUFFER_DESC *pDesc);
  90. DWORD GetVertexSize() const { return m_vertsize; }
  91. DWORD GetNumVertices() const { return m_numverts; }
  92. WORD* GetClipCodes() const { return m_pClipCodes; }
  93. void AllocateClipCodes();
  94. BYTE* Data() const
  95. {
  96. DXGASSERT(m_desc.Usage & D3DUSAGE_SOFTWAREPROCESSING);
  97. DXGASSERT(m_desc.Pool == D3DPOOL_SYSTEMMEM || m_desc.Pool == D3DPOOL_MANAGED);
  98. DXGASSERT(m_LockCount == 0);
  99. return GetPrivateDataPointer();
  100. }
  101. protected:
  102. CVertexBuffer(CBaseDevice *pDevice,
  103. DWORD cbLength,
  104. DWORD dwFVF,
  105. DWORD dwUsage,
  106. DWORD dwActualUsage,
  107. D3DPOOL Pool,
  108. D3DPOOL ActualPool,
  109. REF_TYPE refType,
  110. HRESULT *phr);
  111. virtual ~CVertexBuffer()
  112. {
  113. delete[] m_pClipCodes;
  114. }
  115. #if DBG
  116. HRESULT ValidateLockParams(UINT cbOffsetToLock,
  117. UINT SizeToLock,
  118. BYTE **ppbData,
  119. DWORD dwFlags) const;
  120. #endif // DBG
  121. D3DVERTEXBUFFER_DESC m_desc;
  122. DWORD m_usageUser;
  123. DWORD m_numverts;
  124. DWORD m_vertsize;
  125. WORD* m_pClipCodes;
  126. }; // class CVertexBuffer
  127. class CVertexBufferMT : public CVertexBuffer
  128. {
  129. public:
  130. STDMETHOD(Lock)(UINT cbOffsetToLock,
  131. UINT cbSizeToLock,
  132. BYTE **ppbData,
  133. DWORD dwFlags)
  134. {
  135. API_ENTER(Device());
  136. return CVertexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  137. }
  138. STDMETHOD(Unlock)()
  139. {
  140. API_ENTER(Device());
  141. return CVertexBuffer::Unlock();
  142. }
  143. friend CVertexBuffer;
  144. protected:
  145. CVertexBufferMT(CBaseDevice *pDevice,
  146. DWORD cbLength,
  147. DWORD dwFVF,
  148. DWORD Usage,
  149. DWORD ActualUsage,
  150. D3DPOOL Pool,
  151. D3DPOOL ActualPool,
  152. REF_TYPE refType,
  153. HRESULT *phr) :
  154. CVertexBuffer(pDevice,
  155. cbLength,
  156. dwFVF,
  157. Usage,
  158. ActualUsage,
  159. Pool,
  160. ActualPool,
  161. refType,
  162. phr)
  163. {
  164. }
  165. }; // class CVertexBufferMT
  166. // This derived version of the vertex buffer class
  167. // overrides lock/unlock to call the driver instead
  168. class CDriverVertexBuffer : public CVertexBuffer
  169. {
  170. public:
  171. STDMETHOD(Lock)(UINT cbOffsetToLock,
  172. UINT cbSizeToLock,
  173. BYTE **ppbData,
  174. DWORD dwFlags);
  175. STDMETHOD(Unlock)();
  176. // Alloc CVertexBuffer to construct this object
  177. friend CVertexBuffer;
  178. HRESULT LockI(DWORD dwFlags);
  179. HRESULT UnlockI();
  180. BYTE* GetCachedDataPointer() const { return m_pbData; }
  181. void SetCachedDataPointer(BYTE *pData) { m_pbData = pData; }
  182. BYTE* Data() const
  183. {
  184. DXGASSERT(FALSE); // Direct pointer access not supported
  185. return 0;
  186. }
  187. protected:
  188. CDriverVertexBuffer(CBaseDevice *pDevice,
  189. DWORD cbLength,
  190. DWORD dwFVF,
  191. DWORD Usage,
  192. DWORD ActualUsage,
  193. D3DPOOL Pool,
  194. D3DPOOL ActualPool,
  195. REF_TYPE refType,
  196. HRESULT *phr);
  197. ~CDriverVertexBuffer();
  198. BYTE* m_pbData; // stores cached pointer
  199. }; // class CDriverVertexBuffer
  200. class CDriverVertexBufferMT : public CDriverVertexBuffer
  201. {
  202. public:
  203. STDMETHOD(Lock)(UINT cbOffsetToLock,
  204. UINT cbSizeToLock,
  205. BYTE **ppbData,
  206. DWORD dwFlags)
  207. {
  208. API_ENTER(Device());
  209. return CDriverVertexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  210. }
  211. STDMETHOD(Unlock)()
  212. {
  213. API_ENTER(Device());
  214. return CDriverVertexBuffer::Unlock();
  215. }
  216. friend CVertexBuffer;
  217. protected:
  218. CDriverVertexBufferMT(CBaseDevice *pDevice,
  219. DWORD cbLength,
  220. DWORD dwFVF,
  221. DWORD Usage,
  222. DWORD ActualUsage,
  223. D3DPOOL Pool,
  224. D3DPOOL ActualPool,
  225. REF_TYPE refType,
  226. HRESULT *phr) :
  227. CDriverVertexBuffer(pDevice,
  228. cbLength,
  229. dwFVF,
  230. Usage,
  231. ActualUsage,
  232. Pool,
  233. ActualPool,
  234. refType,
  235. phr)
  236. {
  237. }
  238. }; // class CVertexBufferMT
  239. // This derived version of the vertex buffer class
  240. // overrides lock/unlock to call the driver instead
  241. class CDriverManagedVertexBuffer : public CVertexBuffer
  242. {
  243. public:
  244. STDMETHOD(Lock)(UINT cbOffsetToLock,
  245. UINT cbSizeToLock,
  246. BYTE **ppbData,
  247. DWORD dwFlags);
  248. STDMETHOD(Unlock)();
  249. HRESULT LockI(DWORD dwFlags) {return D3D_OK;}
  250. HRESULT UnlockI() {return D3D_OK;}
  251. BYTE* Data() const
  252. {
  253. DXGASSERT(m_desc.Usage & D3DUSAGE_SOFTWAREPROCESSING);
  254. DXGASSERT((m_desc.Usage & D3DUSAGE_WRITEONLY) == 0);
  255. DXGASSERT(m_LockCount == 0);
  256. DXGASSERT(m_pbData != 0);
  257. return m_pbData;
  258. }
  259. // Alloc CVertexBuffer to construct this object
  260. friend CVertexBuffer;
  261. protected:
  262. CDriverManagedVertexBuffer(CBaseDevice *pDevice,
  263. DWORD cbLength,
  264. DWORD dwFVF,
  265. DWORD Usage,
  266. DWORD ActualUsage,
  267. D3DPOOL Pool,
  268. D3DPOOL ActualPool,
  269. REF_TYPE refType,
  270. HRESULT *phr);
  271. HRESULT UpdateCachedPointer(CBaseDevice*);
  272. friend HRESULT CResource::RestoreDriverManagementState(CBaseDevice*);
  273. BYTE* m_pbData; // stores cached pointer
  274. BOOL m_bDriverCalled;
  275. }; // class CDriverVertexBuffer
  276. class CDriverManagedVertexBufferMT : public CDriverManagedVertexBuffer
  277. {
  278. public:
  279. STDMETHOD(Lock)(UINT cbOffsetToLock,
  280. UINT cbSizeToLock,
  281. BYTE **ppbData,
  282. DWORD dwFlags)
  283. {
  284. API_ENTER(Device());
  285. return CDriverManagedVertexBuffer::Lock(cbOffsetToLock, cbSizeToLock, ppbData, dwFlags);
  286. }
  287. STDMETHOD(Unlock)()
  288. {
  289. API_ENTER(Device());
  290. return CDriverManagedVertexBuffer::Unlock();
  291. }
  292. // Alloc CVertexBuffer to construct this object
  293. friend CVertexBuffer;
  294. protected:
  295. CDriverManagedVertexBufferMT(CBaseDevice *pDevice,
  296. DWORD cbLength,
  297. DWORD dwFVF,
  298. DWORD Usage,
  299. DWORD ActualUsage,
  300. D3DPOOL Pool,
  301. D3DPOOL ActualPool,
  302. REF_TYPE refType,
  303. HRESULT *phr) :
  304. CDriverManagedVertexBuffer(pDevice,
  305. cbLength,
  306. dwFVF,
  307. Usage,
  308. ActualUsage,
  309. Pool,
  310. ActualPool,
  311. refType,
  312. phr)
  313. {
  314. }
  315. }; // class CDriverVertexBufferMT
  316. #endif // __VBUFFER_HPP__