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.

792 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3drm3obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // d3drmObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "d3drm3Obj.h"
  15. #include "d3drmDeviceArrayObj.h"
  16. #include "d3drmLightObj.h"
  17. #include "d3drmMeshObj.h"
  18. #include "d3drmWrapObj.h"
  19. #include "d3drmVisualObj.h"
  20. #include "d3drmUserVisualObj.h"
  21. #include "d3drmClippedVisualObj.h"
  22. #include "d3drmDevice3Obj.h"
  23. #include "d3drmFrame3Obj.h"
  24. #include "d3drmMeshBuilder3Obj.h"
  25. #include "d3drmMaterial2Obj.h"
  26. #include "d3drmTexture3Obj.h"
  27. #include "d3drmViewport2Obj.h"
  28. #include "d3drmAnimationSet2Obj.h"
  29. #include "d3drmFace2Obj.h"
  30. #include "d3drmAnimation2Obj.h"
  31. #include "d3drmShadow2Obj.h"
  32. #include "d3drmProgressiveMeshObj.h"
  33. #include "d3drmFrameInterObj.h"
  34. #include "d3drmLightInterObj.h"
  35. #include "d3drmViewportInterObj.h"
  36. #include "d3drmTextureInterObj.h"
  37. #include "d3drmMaterialInterObj.h"
  38. #include "d3drmMeshInterObj.h"
  39. #include "ddSurface7Obj.h"
  40. extern void *g_dxj_Direct3dRMMeshInterpolator;
  41. extern void *g_dxj_Direct3dRMViewportInterpolator;
  42. extern void *g_dxj_Direct3dRMLightInterpolator;
  43. extern void *g_dxj_Direct3dRMFrameInterpolator;
  44. extern void *g_dxj_Direct3dRMMaterialInterpolator;
  45. extern void *g_dxj_Direct3dRMTextureInterpolator;
  46. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  47. #define DO_GETOBJECT_NOTNULL_VISUAL_ADDREF(v,i) LPDIRECT3DRMVISUAL v=NULL; \
  48. { IUnknown *pIUnk=NULL; \
  49. if(i) i->InternalGetObject((IUnknown **)&pIUnk); \
  50. if (pIUnk) pIUnk->QueryInterface(IID_IDirect3DRMVisual,(void**)&v); \
  51. }
  52. extern BOOL is4Bit;
  53. extern HRESULT BSTRtoPPGUID(LPGUID*,BSTR);
  54. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  55. extern HRESULT D3DBSTRtoGUID(LPGUID,BSTR);
  56. C_dxj_Direct3dRM3Object::C_dxj_Direct3dRM3Object(){
  57. m__dxj_Direct3dRM3=NULL;
  58. parent=NULL;
  59. pinterface=NULL;
  60. creationid = ++g_creationcount;
  61. DPF1(1,"Constructor Creation Direct3dRM2[%d] \n ",g_creationcount);
  62. nextobj = g_dxj_Direct3dRM3;
  63. g_dxj_Direct3dRM3 = (void *)this;
  64. }
  65. C_dxj_Direct3dRM3Object::~C_dxj_Direct3dRM3Object(){
  66. DPF1(1,"Destructor Direct3dRM2 [%d] \n",creationid);
  67. C_dxj_Direct3dRM3Object *prev=NULL;
  68. for(C_dxj_Direct3dRM3Object *ptr=(C_dxj_Direct3dRM3Object *)g_dxj_Direct3dRM3;
  69. ptr;
  70. ptr=(C_dxj_Direct3dRM3Object *)ptr->nextobj)
  71. {
  72. if(ptr == this)
  73. {
  74. if(prev)
  75. prev->nextobj = ptr->nextobj;
  76. else
  77. g_dxj_Direct3dRM3 = (void*)ptr->nextobj;
  78. break;
  79. }
  80. prev = ptr;
  81. }
  82. if(m__dxj_Direct3dRM3){
  83. int count = IUNK(m__dxj_Direct3dRM3)->Release();
  84. DPF1(1,"DirectX real IDirect3dRM2 Ref count [%d] \n",count);
  85. if(count==0){
  86. m__dxj_Direct3dRM3 = NULL;
  87. }
  88. }
  89. if (parent)
  90. IUNK(parent)->Release();
  91. }
  92. #if 0
  93. DWORD C_dxj_Direct3dRM3Object::InternalAddRef(){
  94. DWORD i;
  95. i=CComObjectRoot::InternalAddRef();
  96. DPF1(1,"D3DRM3 [%d] AddRef %d \n",creationid,i);
  97. return i;
  98. }
  99. DWORD C_dxj_Direct3dRM3Object::InternalRelease(){
  100. DWORD i;
  101. i=CComObjectRoot::InternalRelease();
  102. DPF1(1,"D3DRM2 [%d] Release %d \n",creationid,i);
  103. return i;
  104. }
  105. #endif
  106. GETSET_OBJECT(_dxj_Direct3dRM3);
  107. PASS_THROUGH1_R(_dxj_Direct3dRM3, setDefaultTextureColors, SetDefaultTextureColors, long)
  108. PASS_THROUGH1_R(_dxj_Direct3dRM3, setDefaultTextureShades, SetDefaultTextureShades, long)
  109. PASS_THROUGH1_R(_dxj_Direct3dRM3, tick, Tick, d3dvalue);
  110. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, createAnimationSet, CreateAnimationSet, _dxj_Direct3dRMAnimationSet2) ;
  111. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, createMesh, CreateMesh, _dxj_Direct3dRMMesh);
  112. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, createFace, CreateFace, _dxj_Direct3dRMFace2);
  113. //TODO - do we need a new type of device array
  114. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, createAnimation, CreateAnimation, _dxj_Direct3dRMAnimation2);
  115. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, createMeshBuilder, CreateMeshBuilder, _dxj_Direct3dRMMeshBuilder3);
  116. RETURN_NEW_ITEM1_R(_dxj_Direct3dRM3,createMaterial,CreateMaterial,_dxj_Direct3dRMMaterial2,d3dvalue);
  117. RETURN_NEW_ITEM_CAST_2_R(_dxj_Direct3dRM3, createLight,CreateLight,_dxj_Direct3dRMLight, d3drmLightType, (enum _D3DRMLIGHTTYPE), d3dcolor, (d3dcolor));
  118. //TOEXPAND
  119. RETURN_NEW_ITEM_R(_dxj_Direct3dRM3, getDevices, GetDevices, _dxj_Direct3dRMDeviceArray);
  120. STDMETHODIMP C_dxj_Direct3dRM3Object::createTextureFromSurface(I_dxj_DirectDrawSurface4 *dds, I_dxj_Direct3dRMTexture3 **retval)
  121. {
  122. HRESULT hretval;
  123. LPDIRECT3DRMTEXTURE3 lpTex;
  124. LPDIRECTDRAWSURFACE lpDDS=NULL;
  125. if ( is4Bit )
  126. return E_FAIL;
  127. if ( dds == NULL )
  128. return E_FAIL;
  129. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE4, lpDDS4, dds);
  130. hretval= lpDDS4->QueryInterface(IID_IDirectDrawSurface,(void**)&lpDDS);
  131. if FAILED(hretval) return hretval;
  132. hretval = m__dxj_Direct3dRM3->CreateTextureFromSurface(lpDDS, &lpTex);
  133. if (lpDDS) lpDDS->Release();
  134. if FAILED(hretval) return hretval;
  135. INTERNAL_CREATE(_dxj_Direct3dRMTexture3, lpTex, retval);
  136. return S_OK;
  137. }
  138. #if 0
  139. /////////////////////////////////////////////////////////////////////////////
  140. STDMETHODIMP C_dxj_Direct3dRM3Object::createDeviceFromD3D(I_dxj_Direct3d3 *d3d, I_dxj_Direct3dDevice3* d3dDev, I_dxj_Direct3dRMDevice3 **retval)
  141. {
  142. HRESULT hretval;
  143. LPDIRECT3DRMDEVICE3 lpDev;
  144. LPDIRECT3D2 lpD3D2;
  145. LPDIRECT3DDEVICE2 lpD3DDev2;
  146. if ( is4Bit )
  147. return E_FAIL;
  148. if ( d3d == NULL || d3dDev == NULL )
  149. return E_FAIL;
  150. DO_GETOBJECT_NOTNULL(LPDIRECT3D3, lpD3D3, d3d);
  151. DO_GETOBJECT_NOTNULL(LPDIRECT3DDEVICE3, lpD3DDev3, d3dDev);
  152. hretval=lpD3D3->QueryInterface(IID_IDirect3D2,(void**)&lpD3D2);
  153. if FAILED(hretval) return hretval;
  154. hretval=lpD3DDev3->QueryInterface(IID_IDirect3DDevice2,(void**)&lpD3DDev2);
  155. if FAILED(hretval) return hretval;
  156. hretval = m__dxj_Direct3dRM3->CreateDeviceFromD3D(lpD3D2, lpD3DDev2, &lpDev);
  157. lpD3DDev2->Release();
  158. lpD3D2->Release();
  159. if FAILED(hretval) return hretval;
  160. //we need to parent the dev to the d3ddevice object.
  161. //INTERNAL_CREATE(_dxj_Direct3dRMDevice3, lpDev, retval);
  162. INTERNAL_CREATE_1REFS(_dxj_Direct3dRMDevice3, _dxj_Direct3dDevice3, d3dDev,lpDev, retval);
  163. return S_OK;
  164. }
  165. #endif
  166. /////////////////////////////////////////////////////////////////////////////
  167. STDMETHODIMP C_dxj_Direct3dRM3Object::createDeviceFromSurface(BSTR guid, I_dxj_DirectDraw4 *dd, I_dxj_DirectDrawSurface4 *dds,long flags,I_dxj_Direct3dRMDevice3 **retval)
  168. {
  169. HRESULT hretval;
  170. LPDIRECT3DRMDEVICE3 lpDev=NULL;
  171. LPDIRECTDRAW lpDD=NULL;
  172. LPDIRECTDRAWSURFACE lpDDS=NULL;
  173. GUID g;
  174. LPGUID pg=&g;
  175. #pragma message ("need new device to be parented to the surface?")
  176. ZeroMemory(&g,sizeof(GUID));
  177. if ((!guid)||(guid[0]==0)){
  178. pg=NULL;
  179. }
  180. else {
  181. hretval=D3DBSTRtoGUID(&g,guid);
  182. if FAILED(hretval) return E_INVALIDARG;
  183. }
  184. if ( dd == NULL || dds == NULL )
  185. return E_FAIL;
  186. DO_GETOBJECT_NOTNULL(LPDIRECTDRAW4, lpDD4, dd);
  187. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE4, lpDDS4, dds);
  188. if (!lpDD4) return E_INVALIDARG;
  189. if (!lpDDS4) return E_INVALIDARG;
  190. hretval = lpDD4->QueryInterface(IID_IDirectDraw,(void**)&lpDD);
  191. if FAILED(hretval) return hretval;
  192. hretval = lpDDS4->QueryInterface(IID_IDirectDrawSurface,(void**)&lpDDS);
  193. if FAILED(hretval) return hretval;
  194. hretval = m__dxj_Direct3dRM3->CreateDeviceFromSurface( pg, lpDD, lpDDS, (DWORD) flags, &lpDev);
  195. lpDD->Release();
  196. lpDDS->Release();
  197. if FAILED(hretval) return hretval;
  198. INTERNAL_CREATE(_dxj_Direct3dRMDevice3, lpDev, retval);
  199. return S_OK;
  200. }
  201. //////////////////////////////////////////////////////////////////////////
  202. // A call to EnumerateObjects envokes the user's callback for each
  203. // d3drmObject object in the list. In addition all enumerate calls will
  204. // generate their full complement of enumerations. Hence there are 2
  205. // lists: a) the list of objects, b) the list of enumeration calls.
  206. STDMETHODIMP C_dxj_Direct3dRM3Object::enumerateObjects(
  207. I_dxj_Direct3dRMEnumerateObjectsCallback *enumC, IUnknown *args)
  208. {
  209. EnumerateObjectsCallback *enumcb;
  210. if ( is4Bit )
  211. return E_FAIL;
  212. enumcb = (EnumerateObjectsCallback*)AddCallbackLink((void**)&EnumCallbacks,
  213. (I_dxj_Direct3dRMCallback*)enumC, (void*) args);
  214. if( !enumcb ) {
  215. DPF(1,"Callback EnumerateObjects creation failed!\r\n");
  216. return E_FAIL;
  217. }
  218. m__dxj_Direct3dRM3->EnumerateObjects(myEnumerateObjectsCallback, enumcb);
  219. // Remove ourselves in a thread-safe manner.
  220. UndoCallbackLink((GeneralCallback*)enumcb,
  221. (GeneralCallback**)&EnumCallbacks);
  222. return S_OK;
  223. }
  224. //////////////////////////////////////////////////////////////////////////////
  225. STDMETHODIMP C_dxj_Direct3dRM3Object::loadFromFile(BSTR filename, VARIANT id,
  226. SAFEARRAY **psa, long cnt, d3drmLoadFlags options, I_dxj_Direct3dRMLoadCallback *fn1,
  227. IUnknown *arg1, I_dxj_Direct3dRMLoadTextureCallback3 *fn2, IUnknown *arg2, I_dxj_Direct3dRMFrame3 *f)
  228. {
  229. HRESULT hr;
  230. GUID aGuids[100];
  231. int i=0;
  232. ZeroMemory(&(aGuids[0]),sizeof(GUID)*100);
  233. //check args
  234. if (cnt>100) return E_INVALIDARG;
  235. if (cnt<0) return E_INVALIDARG;
  236. if (!ISSAFEARRAY1D(psa,(DWORD)cnt)) return E_FAIL;
  237. for (i =0;i<cnt;i++)
  238. {
  239. hr=BSTRtoGUID(&(aGuids[i]),((BSTR*)((SAFEARRAY *)*psa)->pvData)[i]);
  240. if FAILED(hr) return hr;
  241. }
  242. TextureCallback3 *tcb = NULL;
  243. LoadCallback *lcb = NULL;
  244. if ( is4Bit )
  245. return E_FAIL;
  246. D3DRMLOADTEXTURE3CALLBACK d3dtcb = NULL;
  247. D3DRMLOADCALLBACK d3dlcb = NULL;
  248. LPVOID pArgs1 = NULL;
  249. LPVOID pArgs2 = NULL;
  250. if (arg1) arg1->AddRef();
  251. if (arg2) arg2->AddRef();
  252. if( fn2 ) {
  253. if ((tcb = (TextureCallback3*)AddCallbackLink((void**)&TextureCallbacks3,
  254. (I_dxj_Direct3dRMCallback*)fn2, (void*) arg2)) == NULL) {
  255. DPF(1,"Callback object creation failed!\r\n");
  256. if (arg1) arg1->Release();
  257. if (arg2) arg2->Release();
  258. return E_FAIL;
  259. }
  260. d3dtcb = myLoadTextureCallback3;
  261. pArgs1 = (void *)tcb;
  262. }
  263. if( fn1 ) {
  264. if ((lcb = (LoadCallback*)AddCallbackLink((void**)&LoadCallbacks,
  265. (I_dxj_Direct3dRMCallback*)fn1, (void*) arg1)) == NULL) {
  266. DPF(1,"Callback object creation failed!\r\n");
  267. if (arg1) arg1->Release();
  268. if (arg2) arg2->Release();
  269. return E_FAIL;
  270. }
  271. d3dlcb = myd3drmLoadCallback;
  272. pArgs2 = (void *)lcb;
  273. }
  274. USES_CONVERSION;
  275. LPSTR pszNam = W2T(filename); // Now convert to ANSI
  276. LPDIRECT3DRMFRAME3 lpff = NULL;
  277. if(f)
  278. {
  279. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, lpF, f);
  280. lpff = lpF;
  281. }
  282. void *args=NULL;
  283. DWORD pos=0;
  284. GUID loadGuid;
  285. VARIANT var;
  286. VariantInit(&var);
  287. if ((options & D3DRMLOAD_BYNAME)||(D3DRMLOAD_FROMURL & options)) {
  288. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  289. if FAILED(hr) return E_INVALIDARG;
  290. args=(void*)W2T(V_BSTR(&id));
  291. }
  292. else if(options & D3DRMLOAD_BYPOSITION){
  293. hr=VariantChangeType(&var,&id,0,VT_I4);
  294. if FAILED(hr) return E_INVALIDARG;
  295. pos=V_I4(&id);
  296. args=&pos;
  297. }
  298. else if(options & D3DRMLOAD_BYGUID){
  299. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  300. if FAILED(hr) return E_INVALIDARG;
  301. hr=BSTRtoGUID(&loadGuid,V_BSTR(&id));
  302. if FAILED(hr) return E_INVALIDARG;
  303. args=&loadGuid;
  304. }
  305. VariantClear(&var);
  306. if (options &D3DRMLOAD_FROMRESOURCE){
  307. D3DRMLOADRESOURCE res;
  308. ZeroMemory(&res,sizeof(D3DRMLOADRESOURCE));
  309. res.lpName=pszNam;
  310. res.lpType="XFILE";
  311. hr = m__dxj_Direct3dRM3->Load(&res,(void*) args, (LPGUID*)aGuids, (DWORD)cnt, (DWORD)options,
  312. d3dlcb, pArgs2, d3dtcb, pArgs1, lpff);
  313. }
  314. else {
  315. hr = m__dxj_Direct3dRM3->Load(pszNam,(void*) args, (LPGUID*)aGuids, (DWORD)cnt, (DWORD)options,
  316. d3dlcb, pArgs2, d3dtcb, pArgs1, lpff);
  317. }
  318. // Remove ourselves in a thread-safe manner.
  319. if (tcb) UndoCallbackLink((GeneralCallback*)tcb, (GeneralCallback**)&TextureCallbacks3);
  320. if (lcb) UndoCallbackLink((GeneralCallback*)lcb, (GeneralCallback**)&LoadCallbacks);
  321. if (arg1) arg1->Release();
  322. if (arg2) arg2->Release();
  323. return hr;
  324. }
  325. /////////////////////////////////////////////////////////////////////////////
  326. STDMETHODIMP C_dxj_Direct3dRM3Object::getSearchPath(BSTR *Name)
  327. {
  328. DWORD cnt = 0;
  329. if ( is4Bit )
  330. return E_FAIL;
  331. if((m__dxj_Direct3dRM3->GetSearchPath(&cnt,(char*)NULL)) != D3DRM_OK) // size
  332. return E_FAIL;
  333. LPSTR str = (LPSTR)alloca(cnt); // ANSI buffer on stack;
  334. if((m__dxj_Direct3dRM3->GetSearchPath(&cnt, str)) != D3DRM_OK) return E_FAIL;
  335. PassBackUnicode(str, Name, cnt);
  336. return D3DRM_OK;
  337. }
  338. /////////////////////////////////////////////////////////////////////////////
  339. STDMETHODIMP C_dxj_Direct3dRM3Object::getNamedObject(BSTR Name, I_dxj_Direct3dRMObject **f)
  340. {
  341. LPDIRECT3DRMOBJECT lp; // DirectX object pointer
  342. HRESULT hr;
  343. if (!f) return E_INVALIDARG;
  344. *f=NULL;
  345. USES_CONVERSION;
  346. LPCTSTR pszName = W2T(Name); // Now convert to ANSI
  347. hr=m__dxj_Direct3dRM3->GetNamedObject(pszName,&lp);
  348. if FAILED(hr) return hr;
  349. if (lp==NULL) return S_OK;
  350. hr=CreateCoverObject(lp,f);
  351. return hr;
  352. }
  353. /////////////////////////////////////////////////////////////////////////////
  354. STDMETHODIMP C_dxj_Direct3dRM3Object::setSearchPath(BSTR Name)
  355. {
  356. USES_CONVERSION;
  357. LPCTSTR pszName = W2T(Name); // Now convert to ANSI
  358. if((m__dxj_Direct3dRM3->SetSearchPath(pszName)) != D3DRM_OK) return E_FAIL;
  359. return D3DRM_OK;
  360. }
  361. /////////////////////////////////////////////////////////////////////////////
  362. STDMETHODIMP C_dxj_Direct3dRM3Object::addSearchPath(BSTR Name)
  363. {
  364. USES_CONVERSION;
  365. LPCTSTR pszName = W2T(Name); // Now convert to ANSI
  366. if((m__dxj_Direct3dRM3->AddSearchPath(pszName)) != D3DRM_OK) return E_FAIL;
  367. return D3DRM_OK;
  368. }
  369. /////////////////////////////////////////////////////////////////////////////
  370. STDMETHODIMP C_dxj_Direct3dRM3Object::createWrap(d3drmWrapType type, I_dxj_Direct3dRMFrame3 *fr,
  371. d3dvalue ox, d3dvalue oy, d3dvalue oz,
  372. d3dvalue dx, d3dvalue dy, d3dvalue dz,
  373. d3dvalue ux, d3dvalue uy, d3dvalue uz,
  374. d3dvalue ou, d3dvalue ov,
  375. d3dvalue su, d3dvalue sv,I_dxj_Direct3dRMWrap **retv)
  376. {
  377. LPDIRECT3DRMWRAP lp;
  378. if ( is4Bit )
  379. return E_FAIL;
  380. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, lpF, fr);
  381. if ((m__dxj_Direct3dRM3->CreateWrap((enum _D3DRMWRAPTYPE)type, lpF, ox, oy, oz,
  382. dx, dy, dz, ux, uy, uz,ou, ov, su, sv, &lp)) != S_OK)
  383. {
  384. *retv = NULL;
  385. return E_FAIL;
  386. }
  387. INTERNAL_CREATE(_dxj_Direct3dRMWrap, lp, retv);
  388. return S_OK;
  389. }
  390. /////////////////////////////////////////////////////////////////////////////
  391. STDMETHODIMP C_dxj_Direct3dRM3Object::createShadow(I_dxj_Direct3dRMVisual *visual,
  392. I_dxj_Direct3dRMLight *light,
  393. d3dvalue px, d3dvalue py, d3dvalue pz,
  394. d3dvalue nx, d3dvalue ny, d3dvalue nz,
  395. I_dxj_Direct3dRMShadow2 **retv)
  396. {
  397. LPDIRECT3DRMSHADOW2 lp;
  398. HRESULT hr;
  399. DO_GETOBJECT_NOTNULL_VISUAL_ADDREF(lpV, visual);
  400. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMLIGHT, lpL, light);
  401. hr=m__dxj_Direct3dRM3->CreateShadow(lpV, lpL,
  402. px, py, pz, nx, ny, nz,&lp);
  403. if (lpV) IUNK(lpV)->Release();
  404. if (FAILED(hr))
  405. {
  406. *retv = NULL;
  407. return hr;
  408. }
  409. INTERNAL_CREATE(_dxj_Direct3dRMShadow2, lp, retv);
  410. return hr;
  411. }
  412. /////////////////////////////////////////////////////////////////////////////
  413. STDMETHODIMP C_dxj_Direct3dRM3Object::createViewport(I_dxj_Direct3dRMDevice3 *dev, I_dxj_Direct3dRMFrame3 *fr,
  414. long l,long t,long w,long h,I_dxj_Direct3dRMViewport2 **retval)
  415. {
  416. LPDIRECT3DRMVIEWPORT2 lp;
  417. HRESULT hr;
  418. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMDEVICE3, lpD, dev);
  419. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, lpF, fr);
  420. hr = m__dxj_Direct3dRM3->CreateViewport(lpD, lpF, l, t, w, h, &lp);
  421. if( hr != S_OK )
  422. return hr;
  423. //INTERNAL_CREATE(_dxj_Direct3dRMViewport2, lp, retval);
  424. C_dxj_Direct3dRMViewport2Object *c=new CComObject<C_dxj_Direct3dRMViewport2Object>;
  425. if( c == NULL )
  426. {
  427. lp->Release();
  428. return E_FAIL;
  429. }
  430. c->parent = dev;
  431. dev->AddRef();
  432. c->InternalSetObject(lp);
  433. if (FAILED(IUNK(c)->QueryInterface(IID_I_dxj_Direct3dRMViewport2, (void **)retval)))
  434. return E_FAIL;
  435. c->pinterface = *retval;
  436. return S_OK;
  437. }
  438. /////////////////////////////////////////////////////////////////////////////
  439. // real important that the return value is set correctly regardless, callbacks
  440. // use this!
  441. //
  442. STDMETHODIMP C_dxj_Direct3dRM3Object::loadTexture(BSTR name, I_dxj_Direct3dRMTexture3 **retval)
  443. {
  444. LPDIRECT3DRMTEXTURE3 lpT;
  445. USES_CONVERSION;
  446. LPCTSTR pszName = W2T(name); // Now convert to ANSI
  447. if( m__dxj_Direct3dRM3->LoadTexture(pszName, &lpT ) != S_OK )
  448. {
  449. *retval = NULL;
  450. return S_OK; // Reture ok so that we don't thro execeptionn if it fails
  451. }
  452. INTERNAL_CREATE(_dxj_Direct3dRMTexture3, lpT, retval);
  453. return S_OK;
  454. }
  455. /////////////////////////////////////////////////////////////////////////////
  456. STDMETHODIMP C_dxj_Direct3dRM3Object::createDeviceFromClipper(I_dxj_DirectDrawClipper *lpDDClipper, BSTR strGuid, int width, int height, I_dxj_Direct3dRMDevice3 **retv)
  457. {
  458. LPDIRECT3DRMDEVICE3 lpd3drmDev;
  459. GUID g;
  460. LPGUID pguid=NULL;
  461. HRESULT hr;
  462. //hr =BSTRtoPPGUID(&pguid,strGuid);
  463. if ((strGuid) && (strGuid[0]!=0)){
  464. hr=D3DBSTRtoGUID(&g,strGuid);
  465. if FAILED(hr) return hr;
  466. pguid=&g;
  467. }
  468. if ( is4Bit )
  469. return E_FAIL;
  470. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWCLIPPER, lpddc, lpDDClipper);
  471. if( m__dxj_Direct3dRM3->CreateDeviceFromClipper(lpddc, (LPGUID)pguid, width, height, &lpd3drmDev) != DD_OK)
  472. return E_FAIL;
  473. INTERNAL_CREATE_2REFS(_dxj_Direct3dRMDevice3, _dxj_DirectDrawClipper, lpDDClipper, lpd3drmDev, retv);
  474. return S_OK;
  475. }
  476. /////////////////////////////////////////////////////////////////////////////
  477. STDMETHODIMP C_dxj_Direct3dRM3Object::createFrame(I_dxj_Direct3dRMFrame3 *parent,I_dxj_Direct3dRMFrame3 **retv)
  478. {
  479. LPDIRECT3DRMFRAME3 lpFrame;
  480. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, lpFrameParent, parent)
  481. if( m__dxj_Direct3dRM3->CreateFrame(lpFrameParent, &lpFrame) != DD_OK )
  482. return E_FAIL;
  483. INTERNAL_CREATE(_dxj_Direct3dRMFrame3, lpFrame, retv);
  484. return S_OK;
  485. }
  486. /////////////////////////////////////////////////////////////////////////////
  487. STDMETHODIMP C_dxj_Direct3dRM3Object::createLightRGB(d3drmLightType lt, d3dvalue vred,
  488. d3dvalue vgreen,d3dvalue vblue,I_dxj_Direct3dRMLight **retv)
  489. {
  490. LPDIRECT3DRMLIGHT lpNew;
  491. if ( is4Bit )
  492. return E_FAIL;
  493. if( m__dxj_Direct3dRM3->CreateLightRGB((enum _D3DRMLIGHTTYPE)lt, vred, vgreen, vblue, &lpNew) != DD_OK )
  494. return E_FAIL;
  495. INTERNAL_CREATE(_dxj_Direct3dRMLight, lpNew, retv);
  496. return S_OK;
  497. }
  498. /////////////////////////////////////////////////////////////////////////////
  499. STDMETHODIMP C_dxj_Direct3dRM3Object::setOptions(long opt){
  500. return m__dxj_Direct3dRM3->SetOptions((DWORD)opt);
  501. }
  502. /////////////////////////////////////////////////////////////////////////////
  503. STDMETHODIMP C_dxj_Direct3dRM3Object::getOptions(long *opt){
  504. return m__dxj_Direct3dRM3->GetOptions((DWORD*)opt);
  505. }
  506. /////////////////////////////////////////////////////////////////////////////
  507. STDMETHODIMP C_dxj_Direct3dRM3Object::createClippedVisual(I_dxj_Direct3dRMVisual *vis, I_dxj_Direct3dRMClippedVisual**clipvis)
  508. {
  509. //LPDIRECT3DRMVISUAL lpVisual=NULL;
  510. LPDIRECT3DRMCLIPPEDVISUAL lpClippedVisual=NULL;
  511. HRESULT hr;
  512. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMVISUAL, lpVisual, vis)
  513. hr=m__dxj_Direct3dRM3->CreateClippedVisual(lpVisual,&lpClippedVisual);
  514. if FAILED(hr) return hr;
  515. INTERNAL_CREATE(_dxj_Direct3dRMClippedVisual, lpClippedVisual, clipvis);
  516. return hr;
  517. }
  518. /////////////////////////////////////////////////////////////////////////////
  519. STDMETHODIMP C_dxj_Direct3dRM3Object::createProgressiveMesh( I_dxj_Direct3dRMProgressiveMesh **retv)
  520. {
  521. LPDIRECT3DRMPROGRESSIVEMESH lpPMesh=NULL;
  522. if( m__dxj_Direct3dRM3->CreateProgressiveMesh(&lpPMesh) != DD_OK )
  523. return E_FAIL;
  524. INTERNAL_CREATE(_dxj_Direct3dRMProgressiveMesh, lpPMesh, retv);
  525. return S_OK;
  526. }
  527. /////////////////////////////////////////////////////////////////////////////
  528. //STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolator(
  529. // /* [retval][out] */ I_dxj_Direct3dRMInterpolator __RPC_FAR *__RPC_FAR *retv)
  530. //{
  531. // return E_NOTIMPL;
  532. //}
  533. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorMesh(
  534. /* [retval][out] */ I_dxj_Direct3dRMMeshInterpolator __RPC_FAR *__RPC_FAR *retv)
  535. {
  536. HRESULT hr;
  537. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  538. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMMeshInterpolator, 0, IID_IDirect3DRMInterpolator,(void**) &lpInterpolator);
  539. if FAILED(hr) return hr;
  540. INTERNAL_CREATE(_dxj_Direct3dRMMeshInterpolator, lpInterpolator, retv);
  541. return hr;
  542. }
  543. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorTexture(
  544. /* [retval][out] */ I_dxj_Direct3dRMTextureInterpolator __RPC_FAR *__RPC_FAR *retv)
  545. {
  546. HRESULT hr;
  547. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  548. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMTextureInterpolator, 0, IID_IDirect3DRMInterpolator, (void**)&lpInterpolator);
  549. if FAILED(hr) return hr;
  550. INTERNAL_CREATE(_dxj_Direct3dRMTextureInterpolator, lpInterpolator, retv);
  551. return hr;
  552. }
  553. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorMaterial(
  554. /* [retval][out] */ I_dxj_Direct3dRMMaterialInterpolator __RPC_FAR *__RPC_FAR *retv)
  555. {
  556. HRESULT hr;
  557. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  558. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMMaterialInterpolator, 0, IID_IDirect3DRMInterpolator, (void**)&lpInterpolator);
  559. if FAILED(hr) return hr;
  560. INTERNAL_CREATE(_dxj_Direct3dRMMaterialInterpolator, lpInterpolator, retv);
  561. return hr;
  562. }
  563. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorFrame(
  564. /* [retval][out] */ I_dxj_Direct3dRMFrameInterpolator __RPC_FAR *__RPC_FAR *retv)
  565. {
  566. HRESULT hr;
  567. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  568. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMFrameInterpolator, 0, IID_IDirect3DRMInterpolator, (void**)&lpInterpolator);
  569. if FAILED(hr) return hr;
  570. INTERNAL_CREATE(_dxj_Direct3dRMFrameInterpolator, lpInterpolator, retv);
  571. return hr;
  572. }
  573. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorViewport(
  574. /* [retval][out] */ I_dxj_Direct3dRMViewportInterpolator __RPC_FAR *__RPC_FAR *retv)
  575. {
  576. HRESULT hr;
  577. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  578. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMViewportInterpolator, 0, IID_IDirect3DRMInterpolator,(void**) &lpInterpolator);
  579. if FAILED(hr) return hr;
  580. INTERNAL_CREATE(_dxj_Direct3dRMViewportInterpolator, lpInterpolator, retv);
  581. return hr;
  582. }
  583. STDMETHODIMP C_dxj_Direct3dRM3Object::createInterpolatorLight(
  584. /* [retval][out] */ I_dxj_Direct3dRMLightInterpolator __RPC_FAR *__RPC_FAR *retv)
  585. {
  586. HRESULT hr;
  587. LPDIRECT3DRMINTERPOLATOR lpInterpolator=NULL;
  588. hr=m__dxj_Direct3dRM3->CreateObject(CLSID_CDirect3DRMLightInterpolator, 0, IID_IDirect3DRMInterpolator, (void**)&lpInterpolator);
  589. if FAILED(hr) return hr;
  590. INTERNAL_CREATE(_dxj_Direct3dRMLightInterpolator, lpInterpolator, retv);
  591. return hr;
  592. }
  593. /////////////////////////////////////////////////////////////////////////////