Source code of Windows XP (NT5)
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.

562 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3ddevice3obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // d3dDeviceObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "d3d3Obj.h"
  15. #include "d3dDevice3Obj.h"
  16. #include "d3dTexture2Obj.h"
  17. #include "d3dViewport3Obj.h"
  18. #include "ddSurface4Obj.h"
  19. #include "d3dEnumPixelFormatsObj.h"
  20. //////////////////////////////////////////////////////////////////
  21. // C_dxj_Direct3dDevice3Object
  22. //////////////////////////////////////////////////////////////////
  23. C_dxj_Direct3dDevice3Object::C_dxj_Direct3dDevice3Object(){
  24. m__dxj_Direct3dDevice3=NULL;
  25. parent=NULL;
  26. parent2=NULL;
  27. pinterface=NULL;
  28. creationid = ++g_creationcount;
  29. #ifdef DEBUG
  30. char buffer[256];
  31. wsprintf(buffer,"Constructor Creation Direct3dDevice3[%d] \n",g_creationcount);
  32. OutputDebugString(buffer);
  33. #endif
  34. nextobj = g_dxj_Direct3dDevice3;
  35. g_dxj_Direct3dDevice3 = (void *)this;
  36. }
  37. //////////////////////////////////////////////////////////////////
  38. // ~C_dxj_Direct3dDevice3Object
  39. //////////////////////////////////////////////////////////////////
  40. C_dxj_Direct3dDevice3Object::~C_dxj_Direct3dDevice3Object()
  41. {
  42. C_dxj_Direct3dDevice3Object *prev=NULL;
  43. for(C_dxj_Direct3dDevice3Object *ptr=(C_dxj_Direct3dDevice3Object *)g_dxj_Direct3dDevice3; ptr; ptr=(C_dxj_Direct3dDevice3Object *)ptr->nextobj)
  44. {
  45. if(ptr == this)
  46. {
  47. if(prev)
  48. prev->nextobj = ptr->nextobj;
  49. else
  50. g_dxj_Direct3dDevice3 = (void*)ptr->nextobj;
  51. break;
  52. }
  53. prev = ptr;
  54. }
  55. if(m__dxj_Direct3dDevice3){
  56. int count = IUNK(m__dxj_Direct3dDevice3)->Release();
  57. #ifdef DEBUG
  58. char buffer[256];
  59. wsprintf(buffer, "DirectX IDirect3dDevice3 Ref count [%d] \n",count);
  60. #endif
  61. if(count==0) m__dxj_Direct3dDevice3 = NULL;
  62. }
  63. if(parent) IUNK(parent)->Release();
  64. if(parent2) IUNK(parent2)->Release();
  65. }
  66. //////////////////////////////////////////////////////////////////
  67. // InternalAddRef
  68. //////////////////////////////////////////////////////////////////
  69. DWORD C_dxj_Direct3dDevice3Object::InternalAddRef(){
  70. DWORD i;
  71. i=CComObjectRoot::InternalAddRef();
  72. #ifdef DEBUG
  73. char szBuf[MAX_PATH];
  74. wsprintf(szBuf,"Direct3dDevice3[%d] AddRef %d \n",creationid,i);
  75. OutputDebugString(szBuf);
  76. #endif
  77. return i;
  78. }
  79. //////////////////////////////////////////////////////////////////
  80. // InternalRelease
  81. //////////////////////////////////////////////////////////////////
  82. DWORD C_dxj_Direct3dDevice3Object::InternalRelease(){
  83. DWORD i;
  84. i=CComObjectRoot::InternalRelease();
  85. #ifdef DEBUG
  86. char szBuf[MAX_PATH];
  87. wsprintf(szBuf,"Direct3dDevice3 [%d] Release %d \n",creationid,i);
  88. OutputDebugString(szBuf);
  89. #endif
  90. return i;
  91. }
  92. //////////////////////////////////////////////////////////////////
  93. // InternalGetObject
  94. // InternalSetObject
  95. //////////////////////////////////////////////////////////////////
  96. GETSET_OBJECT(_dxj_Direct3dDevice3);
  97. //////////////////////////////////////////////////////////////////
  98. // addViewport
  99. // begin
  100. // beginScene
  101. // deleteViewport
  102. // endScene
  103. // setClipStatus
  104. // setLightState
  105. // setRenderState
  106. // getClipStatus
  107. // getStats
  108. // getDirect3d
  109. // getLightState
  110. // getRenderState
  111. // index
  112. //////////////////////////////////////////////////////////////////
  113. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dDevice3, addViewport, AddViewport, _dxj_Direct3dViewport3);
  114. PASS_THROUGH_CAST_3_R(_dxj_Direct3dDevice3, begin, Begin, d3dPrimitiveType, (D3DPRIMITIVETYPE),d3dVertexType, (D3DVERTEXTYPE),long,(DWORD));
  115. PASS_THROUGH_R(_dxj_Direct3dDevice3, beginScene, BeginScene);
  116. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dDevice3, deleteViewport, DeleteViewport, _dxj_Direct3dViewport3);
  117. PASS_THROUGH_R(_dxj_Direct3dDevice3, endScene, EndScene);
  118. PASS_THROUGH_CAST_1_R(_dxj_Direct3dDevice3, setClipStatus, SetClipStatus, D3dClipStatus*,(D3DCLIPSTATUS*));
  119. PASS_THROUGH_CAST_2_R(_dxj_Direct3dDevice3, setLightState, SetLightState, long ,(D3DLIGHTSTATETYPE), long ,(DWORD));
  120. PASS_THROUGH_CAST_2_R(_dxj_Direct3dDevice3, setRenderState, SetRenderState, long,(D3DRENDERSTATETYPE), long ,(DWORD));
  121. PASS_THROUGH_CAST_1_R(_dxj_Direct3dDevice3, getClipStatus, GetClipStatus, D3dClipStatus*, (D3DCLIPSTATUS *));
  122. PASS_THROUGH_CAST_2_R(_dxj_Direct3dDevice3, getLightState, GetLightState, long ,(D3DLIGHTSTATETYPE), long*,(DWORD*));
  123. PASS_THROUGH_CAST_2_R(_dxj_Direct3dDevice3, getRenderState, GetRenderState, long ,(D3DRENDERSTATETYPE), long*,(DWORD*));
  124. PASS_THROUGH_CAST_1_R(_dxj_Direct3dDevice3, index, Index, short,(WORD));
  125. //////////////////////////////////////////////////////////////////
  126. // end
  127. //////////////////////////////////////////////////////////////////
  128. STDMETHODIMP C_dxj_Direct3dDevice3Object::end(){
  129. HRESULT hr;
  130. hr=m__dxj_Direct3dDevice3->End(0);
  131. return hr;
  132. }
  133. //////////////////////////////////////////////////////////////////
  134. // getRenderTarget
  135. //////////////////////////////////////////////////////////////////
  136. STDMETHODIMP C_dxj_Direct3dDevice3Object::getRenderTarget(I_dxj_DirectDrawSurface4 **ppsurf)
  137. {
  138. #pragma message ("fix in Dx5 interface")
  139. LPDIRECTDRAWSURFACE4 lpSurf4=NULL;
  140. HRESULT hr;
  141. hr=m__dxj_Direct3dDevice3->GetRenderTarget(&lpSurf4);
  142. INTERNAL_CREATE(_dxj_DirectDrawSurface4, lpSurf4, ppsurf);
  143. return S_OK;
  144. }
  145. //////////////////////////////////////////////////////////////////
  146. // getTransform
  147. //////////////////////////////////////////////////////////////////
  148. STDMETHODIMP C_dxj_Direct3dDevice3Object::getTransform(long transtype,
  149. D3dMatrix *m){
  150. return m__dxj_Direct3dDevice3->GetTransform(
  151. (D3DTRANSFORMSTATETYPE) transtype,
  152. (LPD3DMATRIX)m);
  153. }
  154. //////////////////////////////////////////////////////////////////
  155. // multiplyTransform
  156. //////////////////////////////////////////////////////////////////
  157. STDMETHODIMP C_dxj_Direct3dDevice3Object::multiplyTransform(long transtype,
  158. D3dMatrix *m){
  159. return m__dxj_Direct3dDevice3->MultiplyTransform(
  160. (D3DTRANSFORMSTATETYPE) transtype,
  161. (LPD3DMATRIX) m);
  162. }
  163. //////////////////////////////////////////////////////////////////
  164. // setTransform
  165. //////////////////////////////////////////////////////////////////
  166. STDMETHODIMP C_dxj_Direct3dDevice3Object::setTransform(long transtype,
  167. D3dMatrix *m){
  168. return m__dxj_Direct3dDevice3->SetTransform(
  169. (D3DTRANSFORMSTATETYPE) transtype,
  170. (LPD3DMATRIX) m);
  171. }
  172. //////////////////////////////////////////////////////////////////
  173. // nextViewport
  174. //////////////////////////////////////////////////////////////////
  175. STDMETHODIMP C_dxj_Direct3dDevice3Object::nextViewport(I_dxj_Direct3dViewport3 *ref, long flags, I_dxj_Direct3dViewport3 **vp)
  176. {
  177. if (!ref) return E_INVALIDARG;
  178. LPDIRECT3DVIEWPORT3 lpvp;
  179. DO_GETOBJECT_NOTNULL(LPDIRECT3DVIEWPORT3, lpref, ref);
  180. HRESULT hr=m__dxj_Direct3dDevice3->NextViewport(lpref, &lpvp, flags);
  181. if (hr != DD_OK ) return hr;
  182. INTERNAL_CREATE(_dxj_Direct3dViewport3, lpvp, vp);
  183. return S_OK;
  184. }
  185. //////////////////////////////////////////////////////////////////
  186. // setCurrentViewport
  187. //////////////////////////////////////////////////////////////////
  188. STDMETHODIMP C_dxj_Direct3dDevice3Object::setCurrentViewport(I_dxj_Direct3dViewport3 *viewport)
  189. {
  190. if (!viewport) return E_INVALIDARG;
  191. DO_GETOBJECT_NOTNULL(LPDIRECT3DVIEWPORT3, lpref, viewport);
  192. return m__dxj_Direct3dDevice3->SetCurrentViewport(lpref);
  193. }
  194. //////////////////////////////////////////////////////////////////
  195. // setRenderTarget
  196. //////////////////////////////////////////////////////////////////
  197. STDMETHODIMP C_dxj_Direct3dDevice3Object::setRenderTarget(I_dxj_DirectDrawSurface4 *surf)
  198. {
  199. HRESULT hr;
  200. if (!surf) return E_INVALIDARG;
  201. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE4, lpref, surf);
  202. hr= m__dxj_Direct3dDevice3->SetRenderTarget(lpref,0);
  203. return hr;
  204. }
  205. //////////////////////////////////////////////////////////////////
  206. // getCurrentViewport
  207. //////////////////////////////////////////////////////////////////
  208. STDMETHODIMP C_dxj_Direct3dDevice3Object::getCurrentViewport(I_dxj_Direct3dViewport3 **ppvp)
  209. {
  210. LPDIRECT3DVIEWPORT3 lpvp=NULL;
  211. HRESULT hr=m__dxj_Direct3dDevice3->GetCurrentViewport(&lpvp);
  212. if (hr!= DD_OK ) return hr;
  213. INTERNAL_CREATE(_dxj_Direct3dViewport3, lpvp, ppvp);
  214. return S_OK;
  215. }
  216. //////////////////////////////////////////////////////////////////
  217. // beginIndexed
  218. //////////////////////////////////////////////////////////////////
  219. STDMETHODIMP C_dxj_Direct3dDevice3Object::beginIndexed(
  220. d3dPrimitiveType d3dpt,
  221. long d3dvt,
  222. void *verts,
  223. long vertexCount,
  224. long flags){
  225. HRESULT hr;
  226. __try {
  227. hr= m__dxj_Direct3dDevice3->BeginIndexed(
  228. (D3DPRIMITIVETYPE) d3dpt,
  229. (DWORD) d3dvt,
  230. (void*) verts,
  231. (DWORD) vertexCount,
  232. (DWORD) flags);
  233. }
  234. __except(1, 1){
  235. return DDERR_EXCEPTION;
  236. }
  237. return hr;
  238. }
  239. //////////////////////////////////////////////////////////////////
  240. // drawIndexedPrimitive
  241. //////////////////////////////////////////////////////////////////
  242. STDMETHODIMP C_dxj_Direct3dDevice3Object::drawIndexedPrimitive(
  243. d3dPrimitiveType d3dpt,
  244. long d3dvt,
  245. void *Verts,
  246. long vertexCount,
  247. SAFEARRAY **ppsaIndex,
  248. long indexArraySize,
  249. long flags){
  250. HRESULT hr;
  251. __try {
  252. hr=m__dxj_Direct3dDevice3->DrawIndexedPrimitive(
  253. (D3DPRIMITIVETYPE) d3dpt,
  254. (DWORD) d3dvt,
  255. (void*) Verts,
  256. (DWORD)vertexCount,
  257. (unsigned short*) ((SAFEARRAY*)*ppsaIndex)->pvData,
  258. (DWORD)indexArraySize,
  259. (DWORD) flags);
  260. }
  261. __except(1, 1){
  262. return DDERR_EXCEPTION;
  263. }
  264. return hr;
  265. }
  266. //////////////////////////////////////////////////////////////////
  267. // drawPrimitive
  268. //////////////////////////////////////////////////////////////////
  269. STDMETHODIMP C_dxj_Direct3dDevice3Object::drawPrimitive(
  270. d3dPrimitiveType d3dpt,
  271. long d3dvt,
  272. void* Verts,
  273. long vertexCount,
  274. long flags){
  275. HRESULT hr;
  276. __try {
  277. hr= m__dxj_Direct3dDevice3->DrawPrimitive(
  278. (D3DPRIMITIVETYPE) d3dpt,
  279. (DWORD) d3dvt,
  280. (void*) Verts,
  281. (DWORD)vertexCount,
  282. (DWORD) flags);
  283. }
  284. __except(1, 1){
  285. return DDERR_EXCEPTION;
  286. }
  287. return hr;
  288. }
  289. //////////////////////////////////////////////////////////////////
  290. // vertex
  291. //////////////////////////////////////////////////////////////////
  292. STDMETHODIMP C_dxj_Direct3dDevice3Object::vertex(void *vert){
  293. HRESULT hr;
  294. __try {
  295. hr=m__dxj_Direct3dDevice3->Vertex((void*)vert);
  296. }
  297. __except(1,1){
  298. return DDERR_EXCEPTION;
  299. }
  300. return hr;
  301. };
  302. //////////////////////////////////////////////////////////////////
  303. // getTextureFormatsEnum
  304. //////////////////////////////////////////////////////////////////
  305. STDMETHODIMP C_dxj_Direct3dDevice3Object::getTextureFormatsEnum(I_dxj_D3DEnumPixelFormats **ppRet)
  306. {
  307. HRESULT hr;
  308. hr=C_dxj_D3DEnumPixelFormatsObject::create(m__dxj_Direct3dDevice3,ppRet);
  309. return hr;
  310. }
  311. //////////////////////////////////////////////////////////////////
  312. // computeSphereVisibility
  313. //////////////////////////////////////////////////////////////////
  314. STDMETHODIMP C_dxj_Direct3dDevice3Object::computeSphereVisibility(
  315. D3dVector __RPC_FAR *center,
  316. float __RPC_FAR *radi,
  317. /* [retval][out] */ long __RPC_FAR *returnVal)
  318. {
  319. HRESULT hr=m__dxj_Direct3dDevice3->ComputeSphereVisibility((LPD3DVECTOR)center,radi,1,0,(DWORD*)returnVal);
  320. return hr;
  321. }
  322. //////////////////////////////////////////////////////////////////
  323. // drawIndexedPrimitiveVB
  324. //////////////////////////////////////////////////////////////////
  325. STDMETHODIMP C_dxj_Direct3dDevice3Object::drawIndexedPrimitiveVB(
  326. /* [in] */ d3dPrimitiveType d3dpt,
  327. /* [in] */ I_dxj_Direct3dVertexBuffer __RPC_FAR *vertexBuffer,
  328. /* [in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *indexArray,
  329. /* [in] */ long indexcount,
  330. /* [in] */ long flags)
  331. {
  332. HRESULT hr;
  333. if (!indexArray) return E_FAIL;
  334. DO_GETOBJECT_NOTNULL( LPDIRECT3DVERTEXBUFFER , lpVB, vertexBuffer);
  335. __try{
  336. hr=m__dxj_Direct3dDevice3->DrawIndexedPrimitiveVB
  337. ((D3DPRIMITIVETYPE)d3dpt,
  338. lpVB,
  339. (WORD*) ((SAFEARRAY*)*indexArray)->pvData,
  340. (DWORD)indexcount,
  341. (DWORD)flags);
  342. }
  343. __except(1,1){
  344. return DDERR_EXCEPTION;
  345. }
  346. return hr;
  347. }
  348. //////////////////////////////////////////////////////////////////
  349. // drawPrimitiveVB
  350. //////////////////////////////////////////////////////////////////
  351. STDMETHODIMP C_dxj_Direct3dDevice3Object::drawPrimitiveVB(
  352. /* [in] */ d3dPrimitiveType d3dpt,
  353. /* [in] */ I_dxj_Direct3dVertexBuffer __RPC_FAR *vertexBuffer,
  354. /* [in] */ long startVertex,
  355. /* [in] */ long numVertices,
  356. /* [in] */ long flags)
  357. {
  358. HRESULT hr;
  359. DO_GETOBJECT_NOTNULL( LPDIRECT3DVERTEXBUFFER , lpVB, vertexBuffer);
  360. __try{
  361. hr=m__dxj_Direct3dDevice3->DrawPrimitiveVB
  362. ((D3DPRIMITIVETYPE)d3dpt,
  363. lpVB,
  364. (DWORD) startVertex,
  365. (DWORD) numVertices,
  366. (DWORD)flags);
  367. }
  368. __except(1,1){
  369. return DDERR_EXCEPTION;
  370. }
  371. return hr;
  372. }
  373. //////////////////////////////////////////////////////////////////
  374. // validateDevice
  375. //////////////////////////////////////////////////////////////////
  376. STDMETHODIMP C_dxj_Direct3dDevice3Object::validateDevice(
  377. /* [retval][out] */ long __RPC_FAR *passes)
  378. {
  379. HRESULT hr=m__dxj_Direct3dDevice3->ValidateDevice((DWORD*)passes);
  380. return hr;
  381. }
  382. //////////////////////////////////////////////////////////////////
  383. // getTexture
  384. //////////////////////////////////////////////////////////////////
  385. STDMETHODIMP C_dxj_Direct3dDevice3Object::getTexture(
  386. /* [in] */ long stage,
  387. /* [retval][out] */ I_dxj_Direct3dTexture2 __RPC_FAR *__RPC_FAR *retv)
  388. {
  389. LPDIRECT3DTEXTURE2 lpNew=NULL;
  390. HRESULT hr;
  391. *retv=NULL;
  392. hr=m__dxj_Direct3dDevice3->GetTexture((DWORD)stage,&lpNew);
  393. //null is valid
  394. if (lpNew==NULL) return S_OK;
  395. INTERNAL_CREATE(_dxj_Direct3dTexture2, lpNew, retv);
  396. if (*retv==NULL) return E_OUTOFMEMORY;
  397. return hr;
  398. }
  399. //////////////////////////////////////////////////////////////////
  400. // getTextureStageState
  401. //////////////////////////////////////////////////////////////////
  402. STDMETHODIMP C_dxj_Direct3dDevice3Object::getTextureStageState(
  403. /* [in] */ long stage,
  404. /* [in] */ long state,
  405. /* [retval][out] */ long __RPC_FAR *retv)
  406. {
  407. HRESULT hr;
  408. hr=m__dxj_Direct3dDevice3->GetTextureStageState((DWORD)stage,(D3DTEXTURESTAGESTATETYPE) state, (DWORD*)retv);
  409. return hr;
  410. }
  411. //////////////////////////////////////////////////////////////////
  412. // setTexture
  413. //////////////////////////////////////////////////////////////////
  414. STDMETHODIMP C_dxj_Direct3dDevice3Object::setTexture(
  415. long stage,
  416. I_dxj_Direct3dTexture2 *tex)
  417. {
  418. HRESULT hr;
  419. if (tex==NULL)
  420. {
  421. hr=m__dxj_Direct3dDevice3->SetTexture((DWORD)stage,NULL);
  422. }
  423. else
  424. {
  425. DO_GETOBJECT_NOTNULL(LPDIRECT3DTEXTURE2, lpTex, tex);
  426. hr=m__dxj_Direct3dDevice3->SetTexture((DWORD)stage,lpTex);
  427. }
  428. return hr;
  429. }
  430. //////////////////////////////////////////////////////////////////
  431. // setTextureStageState
  432. //////////////////////////////////////////////////////////////////
  433. STDMETHODIMP C_dxj_Direct3dDevice3Object::setTextureStageState(
  434. /* [in] */ long stage,
  435. /* [in] */ long state,
  436. /* [in] */ long val)
  437. {
  438. HRESULT hr;
  439. hr=m__dxj_Direct3dDevice3->SetTextureStageState((DWORD)stage,(D3DTEXTURESTAGESTATETYPE) state, (DWORD)val);
  440. return hr;
  441. }
  442. //////////////////////////////////////////////////////////////////
  443. // getCaps
  444. //////////////////////////////////////////////////////////////////
  445. STDMETHODIMP C_dxj_Direct3dDevice3Object::getCaps(
  446. D3dDeviceDesc *a,D3dDeviceDesc *b)
  447. {
  448. if (a) a->lSize=sizeof(D3DDEVICEDESC);
  449. if (b) b->lSize=sizeof(D3DDEVICEDESC);
  450. HRESULT hr;
  451. hr=m__dxj_Direct3dDevice3->GetCaps((D3DDEVICEDESC*)a,(D3DDEVICEDESC*)b);
  452. return hr;
  453. }
  454. //////////////////////////////////////////////////////////////////
  455. // getDirect3D
  456. //////////////////////////////////////////////////////////////////
  457. STDMETHODIMP C_dxj_Direct3dDevice3Object::getDirect3D( I_dxj_Direct3d3 **ret)
  458. {
  459. HRESULT hr;
  460. LPDIRECT3D3 lpD3D=NULL;
  461. hr=m__dxj_Direct3dDevice3->GetDirect3D(&lpD3D);
  462. if FAILED(hr) return hr;
  463. if (!lpD3D) return E_FAIL;
  464. INTERNAL_CREATE(_dxj_Direct3d3,lpD3D,ret);
  465. return hr;
  466. }
  467. //////////////////////////////////////////////////////////////////
  468. // getStats
  469. //////////////////////////////////////////////////////////////////
  470. STDMETHODIMP C_dxj_Direct3dDevice3Object::getStats( D3dStats *stats)
  471. {
  472. HRESULT hr;
  473. if (!stats) return E_INVALIDARG;
  474. D3DSTATS *lpStats=(D3DSTATS*)stats;
  475. lpStats->dwSize=sizeof(D3DSTATS);
  476. hr=m__dxj_Direct3dDevice3->GetStats(lpStats);
  477. return hr;
  478. }