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.

266 lines
7.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3d7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // d3dObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "d3d7Obj.h"
  15. #include "d3dDevice7Obj.h"
  16. #include "d3dEnumDevices7Obj.h"
  17. #include "ddSurface7Obj.h"
  18. #include "D3DEnumPixelFormats7Obj.h"
  19. #include "d3dVertexBuffer7Obj.h"
  20. #include "dDraw7Obj.h"
  21. typedef HRESULT (__stdcall *DDRAWCREATE)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
  22. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  23. extern BSTR GUIDtoBSTR(LPGUID);
  24. extern HRESULT D3DBSTRtoGUID(LPGUID,BSTR);
  25. extern BSTR D3DGUIDtoBSTR(LPGUID);
  26. C_dxj_Direct3d7Object::C_dxj_Direct3d7Object(){
  27. m__dxj_Direct3d7=NULL;
  28. parent=NULL;
  29. pinterface=NULL;
  30. creationid = ++g_creationcount;
  31. DPF1(1,"Constructor Creation Direct3d3[%d] \n ",g_creationcount);
  32. nextobj = g_dxj_Direct3d7;
  33. g_dxj_Direct3d7 = (void *)this;
  34. }
  35. C_dxj_Direct3d7Object::~C_dxj_Direct3d7Object()
  36. {
  37. C_dxj_Direct3d7Object *prev=NULL;
  38. for(C_dxj_Direct3d7Object *ptr=(C_dxj_Direct3d7Object *)g_dxj_Direct3d7; ptr; ptr=(C_dxj_Direct3d7Object *)ptr->nextobj)
  39. {
  40. if(ptr == this)
  41. {
  42. if(prev)
  43. prev->nextobj = ptr->nextobj;
  44. else
  45. g_dxj_Direct3d7 = (void*)ptr->nextobj;
  46. break;
  47. }
  48. prev = ptr;
  49. }
  50. if(m__dxj_Direct3d7){
  51. int count = IUNK(m__dxj_Direct3d7)->Release();
  52. DPF1(1,"DirectX IDirect3d7 Ref count [%d] \n",count);
  53. if(count==0) m__dxj_Direct3d7 = NULL;
  54. }
  55. if(parent) IUNK(parent)->Release();
  56. }
  57. DWORD C_dxj_Direct3d7Object::InternalAddRef(){
  58. DWORD i;
  59. i=CComObjectRoot::InternalAddRef();
  60. DPF2(1,"Direct3d3[%d] AddRef %d \n",creationid,i);
  61. return i;
  62. }
  63. DWORD C_dxj_Direct3d7Object::InternalRelease(){
  64. DWORD i;
  65. i=CComObjectRoot::InternalRelease();
  66. DPF2(1,"Direct3d7 [%d] Release %d \n",creationid,i);
  67. return i;
  68. }
  69. GETSET_OBJECT(_dxj_Direct3d7);
  70. #if 0
  71. /////////////////////////////////////////////////////////////////////////////
  72. STDMETHODIMP C_dxj_Direct3d7Object::findDevice(D3dFindDeviceSearch *ds, D3dFindDeviceResult7 *dr )
  73. {
  74. HRESULT hr;
  75. //Fixup FindDeviceSearch
  76. ds->lSize = sizeof(D3DFINDDEVICESEARCH);
  77. ds->dpcPrimCaps.lSize =sizeof(D3DPRIMCAPS);
  78. ZeroMemory((LPGUID)&(ds->guidStruct),sizeof(GUID));
  79. hr=BSTRtoGUID((LPGUID)&(ds->guidStruct), ds->strGuid);
  80. //if FAILED(hr) return E_INVALIDARG;
  81. //Fixup FindDeviceResult
  82. memset(dr,0,sizeof(D3DFINDDEVICERESULT7));
  83. dr->lSize = sizeof(D3DFINDDEVICERESULT7);
  84. dr->ddHwDesc.lSize=sizeof(D3DDEVICEDESC7);
  85. dr->ddSwDesc.lSize=sizeof(D3DDEVICEDESC7);
  86. // NOTE THE TOP PORTIONS OF D3dFindDeviceSearch and D3dFindDeviceResult
  87. // are the same As D3DFINDEVICSEARCH and D3DFINDRESULT
  88. //
  89. hr = m__dxj_Direct3d7->FindDevice((D3DFINDDEVICESEARCH*)ds, (D3DFINDDEVICERESULT7*)dr);
  90. dr->strGuid=D3DGUIDtoBSTR((LPGUID) &(dr->guidStruct));
  91. return hr;
  92. }
  93. #endif
  94. /////////////////////////////////////////////////////////////////////////////
  95. STDMETHODIMP C_dxj_Direct3d7Object::getDevicesEnum(I_dxj_Direct3DEnumDevices **ppRet)
  96. {
  97. HRESULT hr=E_FAIL;
  98. hr=C_dxj_Direct3DEnumDevices7Object::create(m__dxj_Direct3d7,ppRet);
  99. return hr;
  100. }
  101. //TODO tighter code produced if made into an inline function
  102. //and use a for loop to compare byte by byte
  103. #define GUIDISEQUAL(a,b) \
  104. ((((DxGuid *)a)->data1==((DxGuid *)b)->data1) && \
  105. (((DxGuid *)a)->data2==((DxGuid *)b)->data2) && \
  106. (((DxGuid *)a)->data3==((DxGuid *)b)->data3) && \
  107. (((DxGuid *)a)->data4[0]==((DxGuid *)b)->data4[0]) && \
  108. (((DxGuid *)a)->data4[1]==((DxGuid *)b)->data4[1]) && \
  109. (((DxGuid *)a)->data4[2]==((DxGuid *)b)->data4[2]) && \
  110. (((DxGuid *)a)->data4[3]==((DxGuid *)b)->data4[3]) && \
  111. (((DxGuid *)a)->data4[4]==((DxGuid *)b)->data4[4]) && \
  112. (((DxGuid *)a)->data4[5]==((DxGuid *)b)->data4[5]) && \
  113. (((DxGuid *)a)->data4[6]==((DxGuid *)b)->data4[6]) && \
  114. (((DxGuid *)a)->data4[7]==((DxGuid *)b)->data4[7]))
  115. /////////////////////////////////////////////////////////////////////////////
  116. STDMETHODIMP C_dxj_Direct3d7Object::createDevice(BSTR strClsid, I_dxj_DirectDrawSurface7 *surf,I_dxj_Direct3dDevice7 **retv)
  117. {
  118. LPDIRECT3DDEVICE7 lpNew=NULL;
  119. HRESULT hr;
  120. GUID clsid;
  121. hr=D3DBSTRtoGUID(&clsid,strClsid);
  122. if FAILED(hr) return E_INVALIDARG;
  123. //CreateDevice wants a DirectDrawSurface as opposed to
  124. //a DirectDrawSurface3 . we implement as cast
  125. //cause DX allows us to.
  126. //Consider - Is the cost of a QI call really to much?
  127. //AK
  128. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE7, lpSurf, surf);
  129. hr=m__dxj_Direct3d7->CreateDevice(clsid, lpSurf, &lpNew);
  130. if FAILED(hr) return hr;
  131. //INTERNAL_CREATE(_dxj_Direct3dDevice3, lpNew, retv);
  132. INTERNAL_CREATE_2REFS(_dxj_Direct3dDevice7,_dxj_DirectDrawSurface7,surf, lpNew,retv)
  133. return S_OK;
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. STDMETHODIMP C_dxj_Direct3d7Object::getDirectDraw(I_dxj_DirectDraw7 **retv)
  137. {
  138. IDirectDraw7 *pdd7;
  139. HRESULT hr;
  140. hr=m__dxj_Direct3d7->QueryInterface(IID_IDirectDraw7,(void**)&pdd7);
  141. if FAILED(hr) return hr;
  142. INTERNAL_CREATE(_dxj_DirectDraw7, pdd7, retv);
  143. return hr;
  144. }
  145. STDMETHODIMP C_dxj_Direct3d7Object::createVertexBuffer(
  146. /* [in] */ D3dVertexBufferDesc *desc,
  147. /* [in] */ long flags,
  148. /* [retval][out] */ I_dxj_Direct3dVertexBuffer7 __RPC_FAR *__RPC_FAR *f)
  149. {
  150. LPDIRECT3DVERTEXBUFFER7 pBuff=NULL;
  151. HRESULT hr;
  152. if (!desc) return E_INVALIDARG;
  153. desc->lSize=sizeof(D3DVERTEXBUFFERDESC);
  154. hr=m__dxj_Direct3d7->CreateVertexBuffer((LPD3DVERTEXBUFFERDESC) desc,
  155. &pBuff,
  156. (DWORD)flags
  157. );
  158. if FAILED(hr) return hr;
  159. INTERNAL_CREATE(_dxj_Direct3dVertexBuffer7, pBuff, f);
  160. DWORD fvf=(DWORD)desc->lFVF;
  161. long n=0;
  162. if (fvf == D3DFVF_VERTEX) n=sizeof(D3DVERTEX);
  163. else if (fvf == D3DFVF_LVERTEX) n=sizeof(D3DLVERTEX);
  164. else if (fvf == D3DFVF_TLVERTEX) n=sizeof(D3DLVERTEX);
  165. else
  166. {
  167. if (fvf & D3DFVF_DIFFUSE ) n=n+sizeof(DWORD);
  168. if (fvf & D3DFVF_SPECULAR ) n=n+sizeof(DWORD);
  169. if (fvf & D3DFVF_NORMAL ) n=n+sizeof(float)*3;
  170. if (fvf & D3DFVF_XYZ ) n=n+sizeof(float)*3;
  171. if (fvf & D3DFVF_XYZRHW ) n=n+sizeof(float)*4;
  172. if (fvf & D3DFVF_TEX0 ) n=n+sizeof(float)*2;
  173. if (fvf & D3DFVF_TEX1 ) n=n+sizeof(float)*2;
  174. if (fvf & D3DFVF_TEX2 ) n=n+sizeof(float)*2;
  175. if (fvf & D3DFVF_TEX3 ) n=n+sizeof(float)*2;
  176. if (fvf & D3DFVF_TEX4 ) n=n+sizeof(float)*2;
  177. if (fvf & D3DFVF_TEX5 ) n=n+sizeof(float)*2;
  178. if (fvf & D3DFVF_TEX6 ) n=n+sizeof(float)*2;
  179. if (fvf & D3DFVF_TEX7 ) n=n+sizeof(float)*2;
  180. if (fvf & D3DFVF_TEX8 ) n=n+sizeof(float)*2;
  181. }
  182. (*f)->setVertexSize(n);
  183. return S_OK;
  184. }
  185. STDMETHODIMP C_dxj_Direct3d7Object::getEnumZBufferFormats(
  186. /* [in] */ BSTR guid,
  187. /* [retval][out] */ I_dxj_Direct3DEnumPixelFormats __RPC_FAR *__RPC_FAR *retval)
  188. {
  189. HRESULT hr=C_dxj_Direct3DEnumPixelFormats7Object::create2(m__dxj_Direct3d7, guid, retval);
  190. return hr;
  191. }
  192. STDMETHODIMP C_dxj_Direct3d7Object::evictManagedTextures( void)
  193. {
  194. HRESULT hr;
  195. hr=m__dxj_Direct3d7->EvictManagedTextures();
  196. return hr;
  197. }