D3DDevice.inl
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:10k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1999 DXGuide.  All Rights Reserved.
  2. // File: D3DDevice.inl
  3. // Inlines for CD3DDevice
  4. #include "DirectX.h" // for REPORTDXERROR
  5. #include "D3DVertexBuffer.h" // for CD3DVertexBuffer
  6. inline LPDIRECT3D7 CD3DDevice::GetDirect3D(void) const
  7. {
  8. return  m_lpD3D;
  9. }
  10. inline CD3DMaterial* CD3DDevice::GetD3DMaterial(void) const
  11. {
  12. return  m_pD3DMaterial;
  13. }
  14. inline HRESULT CD3DDevice::GetInfo(DWORD  dwDevInfoID,
  15. LPVOID  pDevInfoStruct, DWORD  dwSize)
  16. {
  17. HRESULT hr = m_lpD3DDevice->GetInfo(dwDevInfoID,
  18. pDevInfoStruct, dwSize);
  19. REPORTDXERROR(hr);
  20. return  hr;
  21. }
  22. inline D3DDEVICEDESC7 const* CD3DDevice::GetD3DDeviceDesc(void) const
  23. {
  24. return  m_pD3DDeviceDesc;
  25. }
  26. inline D3DPRIMCAPS const* CD3DDevice::GetTriCaps(void) const
  27. {
  28. return  &(m_pD3DDeviceDesc->dpcTriCaps);
  29. }
  30. inline D3DPRIMCAPS const* CD3DDevice::GetLineCaps(void) const
  31. {
  32. return  &(m_pD3DDeviceDesc->dpcLineCaps);
  33. }
  34. inline bool CD3DDevice::IsSupportMipmaps(void) const
  35. {
  36. return  ((GetTriCaps()->dwTextureFilterCaps & (D3DPTFILTERCAPS_MIPNEAREST | D3DPTFILTERCAPS_MIPLINEAR)) != 0);
  37. }
  38. // Get triangle caps and check for w-buffering
  39. inline bool CD3DDevice::IsSupportWBuffer(void) const
  40. {
  41. return  ((GetTriCaps()->dwRasterCaps & D3DPRASTERCAPS_WBUFFER) != 0);
  42. }
  43. inline bool CD3DDevice::IsSupportDirectionalLights(void) const
  44. {
  45. return  ((m_pD3DDeviceDesc->dwVertexProcessingCaps & D3DVTXPCAPS_DIRECTIONALLIGHTS) != 0);
  46. }
  47. inline bool CD3DDevice::IsSupportPositionalLights(void) const
  48. {
  49. return  ((m_pD3DDeviceDesc->dwVertexProcessingCaps & D3DVTXPCAPS_POSITIONALLIGHTS) != 0);
  50. }
  51. inline D3DDEVICETYPE CD3DDevice::GetDeviceType(void) const
  52. {
  53. return  GetSelectedD3DDeviceInfoObject()->GetD3DDeviceType();
  54. }
  55. // -- Device states --
  56. inline HRESULT CD3DDevice::ApplyStateBlock(DWORD  dwBlockHandle)
  57. {
  58. HRESULT hr = m_lpD3DDevice->ApplyStateBlock(dwBlockHandle);
  59. REPORTDXERROR(hr);
  60. return  hr;
  61. }
  62. inline HRESULT CD3DDevice::BeginStateBlock(void)
  63. {
  64. HRESULT hr = m_lpD3DDevice->BeginStateBlock();
  65. REPORTDXERROR(hr);
  66. return  hr;
  67. }
  68. inline HRESULT CD3DDevice::EndStateBlock(LPDWORD  lpdwBlockHandle)
  69. {
  70. HRESULT hr = m_lpD3DDevice->EndStateBlock(lpdwBlockHandle);
  71. REPORTDXERROR(hr);
  72. return  hr;
  73. }
  74. inline HRESULT CD3DDevice::CaptureStateBlock(DWORD  dwBlockHandle)
  75. {
  76. HRESULT hr = m_lpD3DDevice->CaptureStateBlock(dwBlockHandle);
  77. REPORTDXERROR(hr);
  78. return  hr;
  79. }
  80. inline HRESULT CD3DDevice::CreateStateBlock(
  81. D3DSTATEBLOCKTYPE  d3dsbType, LPDWORD  lpdwBlockHandle)
  82. {
  83. HRESULT hr =  m_lpD3DDevice->CreateStateBlock(
  84. d3dsbType, lpdwBlockHandle);
  85. REPORTDXERROR(hr);
  86. return  hr;
  87. }
  88. inline HRESULT CD3DDevice::DeleteStateBlock(DWORD  dwBlockHandle)
  89. {
  90. HRESULT hr = m_lpD3DDevice->DeleteStateBlock(dwBlockHandle);
  91. REPORTDXERROR(hr);
  92. return  hr;
  93. }
  94. inline HRESULT CD3DDevice::GetClipStatus(LPD3DCLIPSTATUS  lpD3DClipStatus)
  95. {
  96. HRESULT hr = m_lpD3DDevice->GetClipStatus(lpD3DClipStatus);
  97. REPORTDXERROR(hr);
  98. return  hr;
  99. }
  100. inline HRESULT CD3DDevice::SetClipStatus(LPD3DCLIPSTATUS  lpD3DClipStatus)
  101. {
  102. HRESULT hr = m_lpD3DDevice->SetClipStatus(lpD3DClipStatus);
  103. REPORTDXERROR(hr);
  104. return  hr;
  105. }
  106. inline HRESULT CD3DDevice::GetRenderState(D3DRENDERSTATETYPE  dwRenderStateType,
  107. LPDWORD  lpdwRenderState)
  108. {
  109. HRESULT hr = m_lpD3DDevice->GetRenderState(dwRenderStateType,
  110. lpdwRenderState);
  111. REPORTDXERROR(hr);
  112. return  hr;
  113. }
  114. inline HRESULT CD3DDevice::SetRenderState(
  115. D3DRENDERSTATETYPE  dwRenderStateType,
  116. DWORD  dwRenderState)
  117. {
  118. HRESULT hr = m_lpD3DDevice->SetRenderState(
  119. dwRenderStateType, dwRenderState);
  120. REPORTDXERROR(hr);
  121. return  hr;
  122. }
  123. inline HRESULT CD3DDevice::GetRenderTarget(
  124. LPDIRECTDRAWSURFACE7*  lplpRenderTarget)
  125. {
  126. HRESULT hr = m_lpD3DDevice->GetRenderTarget(lplpRenderTarget);
  127. REPORTDXERROR(hr);
  128. return  hr;
  129. }
  130. inline HRESULT CD3DDevice::GetTransform(
  131. D3DTRANSFORMSTATETYPE  dtstTransformStateType,
  132. LPD3DMATRIX  lpD3DMatrix)
  133. {
  134. HRESULT hr = m_lpD3DDevice->GetTransform(
  135. dtstTransformStateType,
  136. lpD3DMatrix);
  137. REPORTDXERROR(hr);
  138. return  hr;
  139. }
  140. inline HRESULT CD3DDevice::SetTransform(
  141. D3DTRANSFORMSTATETYPE  dtstTransformStateType,
  142. LPD3DMATRIX  lpD3DMatrix)
  143. {
  144. HRESULT hr = m_lpD3DDevice->SetTransform(
  145. dtstTransformStateType,
  146. lpD3DMatrix);
  147. REPORTDXERROR(hr);
  148. return  hr;
  149. }
  150. inline HRESULT CD3DDevice::BeginScene(void)
  151. {
  152. HRESULT hr = m_lpD3DDevice->BeginScene();
  153. REPORTDXERROR(hr);
  154. return  hr;
  155. }
  156. inline HRESULT CD3DDevice::EndScene(void)
  157. {
  158. HRESULT hr = m_lpD3DDevice->EndScene();
  159. REPORTDXERROR(hr);
  160. return  hr;
  161. }
  162. inline HRESULT CD3DDevice::DrawPrimitive(
  163. D3DPRIMITIVETYPE  dptPrimitiveType,
  164. DWORD  dwVertexTypeDesc, LPVOID  lpvVertices,
  165. DWORD  dwVertexCount, DWORD  dwFlags)
  166. {
  167. HRESULT hr = m_lpD3DDevice->DrawPrimitive(
  168. dptPrimitiveType, dwVertexTypeDesc,
  169. lpvVertices, dwVertexCount, dwFlags);
  170. REPORTDXERROR(hr);
  171. return  hr;
  172. }
  173. inline HRESULT CD3DDevice::DrawIndexedPrimitive(
  174. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  175. DWORD  dwVertexTypeDesc, LPVOID  lpvVertices,
  176. DWORD  dwVertexCount, LPWORD  lpwIndices,
  177. DWORD  dwIndexCount, DWORD  dwFlags)
  178. {
  179. HRESULT hr = m_lpD3DDevice->DrawIndexedPrimitive(
  180. d3dptPrimitiveType, dwVertexTypeDesc,
  181. lpvVertices, dwVertexCount, lpwIndices,
  182. dwIndexCount, dwFlags);
  183. REPORTDXERROR(hr);
  184. return  hr;
  185. }
  186. inline HRESULT CD3DDevice::DrawPrimitiveStrided(
  187. D3DPRIMITIVETYPE  dptPrimitiveType,
  188. DWORD  dwVertexTypeDesc,
  189. LPD3DDRAWPRIMITIVESTRIDEDDATA  lpVertexArray,
  190. DWORD  dwVertexCount,
  191. DWORD  dwFlags)
  192. {
  193. HRESULT hr = m_lpD3DDevice->DrawPrimitiveStrided(
  194. dptPrimitiveType, dwVertexTypeDesc,
  195. lpVertexArray, dwVertexCount, dwFlags);
  196. REPORTDXERROR(hr);
  197. return  hr;
  198. }
  199. inline HRESULT CD3DDevice::DrawIndexedPrimitiveStrided(
  200. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  201. DWORD  dwVertexTypeDesc,
  202. LPD3DDRAWPRIMITIVESTRIDEDDATA  lpVertexArray,
  203. DWORD  dwVertexCount,
  204. LPWORD  lpwIndices,
  205. DWORD  dwIndexCount,
  206. DWORD  dwFlags)
  207. {
  208. HRESULT hr = m_lpD3DDevice->DrawIndexedPrimitiveStrided(
  209. d3dptPrimitiveType, dwVertexTypeDesc,
  210. lpVertexArray, dwVertexCount,
  211. lpwIndices, dwIndexCount, dwFlags);
  212. REPORTDXERROR(hr);
  213. return  hr;
  214. }
  215. inline HRESULT CD3DDevice::DrawPrimitiveVB(
  216. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  217. CD3DVertexBuffer*  pD3DVertexBuffer,
  218. DWORD  dwStartVertex,
  219. DWORD  dwNumVertices,
  220. DWORD  dwFlags)
  221. {
  222. HRESULT hr = m_lpD3DDevice->DrawPrimitiveVB(
  223. d3dptPrimitiveType, pD3DVertexBuffer->m_lpD3DVertexBuffer,
  224. dwStartVertex, dwNumVertices, dwFlags);
  225. REPORTDXERROR(hr);
  226. return  hr;
  227. }
  228. inline HRESULT CD3DDevice::DrawIndexedPrimitiveVB(
  229. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  230. CD3DVertexBuffer*  pD3DVertexBuffer,
  231. DWORD  dwStartVertex,
  232. DWORD  dwNumVertices,
  233. LPWORD  lpwIndices,
  234. DWORD  dwIndexCount,
  235. DWORD  dwFlags)
  236. {
  237. HRESULT hr = m_lpD3DDevice->DrawIndexedPrimitiveVB(
  238. d3dptPrimitiveType,
  239. pD3DVertexBuffer->m_lpD3DVertexBuffer,
  240. dwStartVertex, dwNumVertices, lpwIndices,
  241. dwIndexCount, dwFlags);
  242. REPORTDXERROR(hr);
  243. return  hr;
  244. }
  245. inline void CD3DDevice::SetTextureColorStage(DWORD  dwStage, D3DTEXTUREOP  op, DWORD  dwArg1, DWORD  dwArg2)
  246. {
  247. SetTextureStageState(dwStage, D3DTSS_COLOROP, op);
  248. SetTextureStageState(dwStage, D3DTSS_COLORARG1, dwArg1);
  249. SetTextureStageState(dwStage, D3DTSS_COLORARG2, dwArg2);
  250. }
  251. inline void CD3DDevice::SetTextureAlphaStage(DWORD  dwStage, D3DTEXTUREOP  op, DWORD  dwArg1, DWORD  dwArg2)
  252. {
  253. SetTextureStageState(dwStage, D3DTSS_ALPHAOP, op);
  254. SetTextureStageState(dwStage, D3DTSS_ALPHAARG1, dwArg1);
  255. SetTextureStageState(dwStage, D3DTSS_ALPHAARG2, dwArg2);
  256. }
  257. inline HRESULT CD3DDevice::SetMaterial(LPD3DMATERIAL7  lpMaterial)
  258. {
  259. HRESULT hr = m_lpD3DDevice->SetMaterial(lpMaterial);
  260. REPORTDXERROR(hr);
  261. return  hr;
  262. }
  263. inline HRESULT CD3DDevice::GetMaterial(LPD3DMATERIAL7  lpMaterial)
  264. {
  265. HRESULT hr = m_lpD3DDevice->GetMaterial(lpMaterial);
  266. REPORTDXERROR(hr);
  267. return  hr;
  268. }
  269. inline HRESULT CD3DDevice::SetLight(DWORD  dwLightIndex, LPD3DLIGHT7  lpLight)
  270. {
  271. HRESULT hr = m_lpD3DDevice->SetLight(dwLightIndex, lpLight);
  272. REPORTDXERROR(hr);
  273. return  hr;
  274. }
  275. inline HRESULT CD3DDevice::GetLight(DWORD  dwLightIndex, LPD3DLIGHT7  lpLight)
  276. {
  277. HRESULT hr = m_lpD3DDevice->GetLight(dwLightIndex, lpLight);
  278. REPORTDXERROR(hr);
  279. return  hr;
  280. }
  281. inline HRESULT CD3DDevice::LightEnable(DWORD  dwLightIndex, BOOL  bEnable)
  282. {
  283. HRESULT hr = m_lpD3DDevice->LightEnable(dwLightIndex, bEnable);
  284. REPORTDXERROR(hr);
  285. return  hr;
  286. }
  287. inline HRESULT CD3DDevice::GetLightEnable(DWORD  dwLightIndex, BOOL*  pbEnable) const
  288. {
  289. HRESULT hr = m_lpD3DDevice->GetLightEnable(dwLightIndex, pbEnable);
  290. REPORTDXERROR(hr);
  291. return  hr;
  292. }
  293. inline DWORD CD3DDevice::GetMaxActiveLights(void) const
  294. {
  295. return  m_pD3DDeviceDesc->dwMaxActiveLights;
  296. }
  297. inline HRESULT CD3DDevice::Load(LPDIRECTDRAWSURFACE7  lpDestTex,
  298. LPPOINT  lpDestPoint, LPDIRECTDRAWSURFACE7  lpSrcTex,
  299. LPRECT  lprcSrcRect, DWORD  dwFlags)
  300. {
  301. HRESULT hr = m_lpD3DDevice->Load(lpDestTex,
  302. lpDestPoint, lpSrcTex, lprcSrcRect, dwFlags);
  303. REPORTDXERROR(hr);
  304. return  hr;
  305. }
  306. inline HRESULT CD3DDevice::PreLoad(LPDIRECTDRAWSURFACE7  lpddsTexture)
  307. {
  308. HRESULT hr = m_lpD3DDevice->PreLoad(lpddsTexture);
  309. REPORTDXERROR(hr);
  310. return  hr;
  311. }
  312. inline HRESULT CD3DDevice::GetClipPlane(DWORD  dwIndex, D3DVALUE*  pPlaneEquation)
  313. {
  314. HRESULT hr = m_lpD3DDevice->GetClipPlane(dwIndex, pPlaneEquation);
  315. REPORTDXERROR(hr);
  316. return  hr;
  317. }
  318. inline HRESULT CD3DDevice::SetClipPlane(DWORD  dwIndex, D3DVALUE*  pPlaneEquation)
  319. {
  320. HRESULT hr = m_lpD3DDevice->SetClipPlane(dwIndex, pPlaneEquation);
  321. REPORTDXERROR(hr);
  322. return  hr;
  323. }
  324. inline HRESULT CD3DDevice::GetViewport(LPD3DVIEWPORT7  lpViewport)
  325. {
  326. HRESULT hr = m_lpD3DDevice->GetViewport(lpViewport);
  327. REPORTDXERROR(hr);
  328. return  hr;
  329. }
  330. inline HRESULT CD3DDevice::SetViewport(LPD3DVIEWPORT7  lpViewport)
  331. {
  332. HRESULT hr = m_lpD3DDevice->SetViewport(lpViewport);
  333. REPORTDXERROR(hr);
  334. return  hr;
  335. }