Guest User

d3d9intf.c - Koopah's D3D Patch/Vicosku .162 Edit

a guest
Jun 18th, 2015
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // license:BSD-3-Clause
  2. // copyright-holders:Aaron Giles
  3. //============================================================
  4. //
  5. // d3d9intf.c - Direct3D 9 abstraction layer
  6. //
  7. //============================================================
  8.  
  9. // standard windows headers
  10. #define WIN32_LEAN_AND_MEAN
  11. #include <windows.h>
  12. #include <d3d9.h>
  13. #include <d3dx9.h>
  14. #undef interface
  15.  
  16. // MAME headers
  17. #include "emu.h"
  18.  
  19. // MAMEOS headers
  20. #include "d3dintf.h"
  21. #include "winmain.h"
  22.  
  23.  
  24.  
  25. //============================================================
  26. // TYPE DEFINITIONS
  27. //============================================================
  28.  
  29. typedef HRESULT (WINAPI *direct3dcreate9ex_ptr)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
  30.  
  31. namespace d3d
  32. {
  33. //============================================================
  34. // PROTOTYPES
  35. //============================================================
  36.  
  37. static void set_interfaces(base *d3dptr);
  38.  
  39. //============================================================
  40. // INLINES
  41. //============================================================
  42.  
  43. INLINE void convert_present_params(const present_parameters *params, D3DPRESENT_PARAMETERS *d3d9params)
  44. {
  45. memset(d3d9params, 0, sizeof(*d3d9params));
  46. d3d9params->BackBufferWidth = params->BackBufferWidth;
  47. d3d9params->BackBufferHeight = params->BackBufferHeight;
  48. d3d9params->BackBufferFormat = params->BackBufferFormat;
  49. d3d9params->BackBufferCount = params->BackBufferCount;
  50. d3d9params->MultiSampleType = params->MultiSampleType;
  51. d3d9params->MultiSampleQuality = params->MultiSampleQuality;
  52. d3d9params->SwapEffect = params->SwapEffect;
  53. d3d9params->hDeviceWindow = params->hDeviceWindow;
  54. d3d9params->Windowed = params->Windowed;
  55. d3d9params->EnableAutoDepthStencil = params->EnableAutoDepthStencil;
  56. d3d9params->AutoDepthStencilFormat = params->AutoDepthStencilFormat;
  57. d3d9params->Flags = params->Flags;
  58. d3d9params->FullScreen_RefreshRateInHz = params->FullScreen_RefreshRateInHz;
  59. d3d9params->PresentationInterval = params->PresentationInterval;
  60. }
  61.  
  62. INLINE void convert_display_mode_d3d9params(const D3DPRESENT_PARAMETERS *d3d9params, D3DDISPLAYMODEEX *displaymode)
  63. {
  64. memset(displaymode, 0, sizeof(D3DDISPLAYMODEEX));
  65. displaymode->Size = sizeof(D3DDISPLAYMODEEX);
  66. displaymode->Width = d3d9params->BackBufferWidth;
  67. displaymode->Height = d3d9params->BackBufferHeight;
  68. displaymode->RefreshRate = d3d9params->FullScreen_RefreshRateInHz;
  69. displaymode->Format = d3d9params->BackBufferFormat;
  70. displaymode->ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE;
  71. }
  72.  
  73. //============================================================
  74. // drawd3d9_init
  75. //============================================================
  76.  
  77. base *drawd3d9_init(void)
  78. {
  79. bool post_available = true;
  80.  
  81. // dynamically grab the create function from d3d9.dll
  82. HINSTANCE dllhandle = LoadLibrary(TEXT("d3d9.dll"));
  83. if (dllhandle == NULL)
  84. {
  85. osd_printf_verbose("Direct3D: Unable to access d3d9.dll\n");
  86. return NULL;
  87. }
  88.  
  89. // import the create function
  90. direct3dcreate9ex_ptr direct3dcreate9ex = (direct3dcreate9ex_ptr)GetProcAddress(dllhandle, "Direct3DCreate9Ex");
  91. if (direct3dcreate9ex == NULL)
  92. {
  93. osd_printf_verbose("Direct3D: Unable to find Direct3DCreate9Ex\n");
  94. FreeLibrary(dllhandle);
  95. dllhandle = NULL;
  96. return NULL;
  97. }
  98.  
  99. // create our core direct 3d object
  100. IDirect3D9Ex *d3d9 = NULL;
  101. (*direct3dcreate9ex)(D3D_SDK_VERSION, &d3d9);
  102. if (d3d9 == NULL)
  103. {
  104. osd_printf_verbose("Direct3D: Error attempting to initialize Direct3D9Ex\n");
  105. FreeLibrary(dllhandle);
  106. dllhandle = NULL;
  107. return NULL;
  108. }
  109.  
  110. // dynamically grab the shader load function from d3dx9.dll
  111. HINSTANCE fxhandle = NULL;
  112. for (int idx = 99; idx >= 0; idx--) // a shameful moogle
  113. {
  114. #ifdef UNICODE
  115. wchar_t dllbuf[13];
  116. wsprintf(dllbuf, TEXT("d3dx9_%d.dll"), idx);
  117. fxhandle = LoadLibrary(dllbuf);
  118. #else
  119. char dllbuf[13];
  120. sprintf(dllbuf, "d3dx9_%d.dll", idx);
  121. fxhandle = LoadLibraryA(dllbuf);
  122. #endif
  123. if (fxhandle != NULL)
  124. {
  125. break;
  126. }
  127. }
  128. if (fxhandle == NULL)
  129. {
  130. osd_printf_verbose("Direct3D: Warning - Unable find any D3D9 DLLs; disabling post-effect rendering\n");
  131. post_available = false;
  132. }
  133.  
  134. // allocate an object to hold our data
  135. base *d3dptr = global_alloc(base);
  136. d3dptr->version = 9;
  137. d3dptr->d3dobj = d3d9;
  138. d3dptr->dllhandle = dllhandle;
  139. d3dptr->post_fx_available = post_available;
  140. d3dptr->libhandle = fxhandle;
  141. set_interfaces(d3dptr);
  142.  
  143. osd_printf_verbose("Direct3D: Using Direct3D 9\n");
  144. return d3dptr;
  145. }
  146.  
  147.  
  148.  
  149. //============================================================
  150. // Direct3D interfaces
  151. //============================================================
  152.  
  153. static HRESULT check_device_format(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT adapterformat, DWORD usage, D3DRESOURCETYPE restype, D3DFORMAT format)
  154. {
  155. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  156. return IDirect3D9_CheckDeviceFormat(d3d9, adapter, devtype, adapterformat, usage, restype, format);
  157. }
  158.  
  159.  
  160. static HRESULT check_device_type(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, D3DFORMAT format, D3DFORMAT backformat, BOOL windowed)
  161. {
  162. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  163. return IDirect3D9_CheckDeviceType(d3d9, adapter, devtype, format, backformat, windowed);
  164. }
  165.  
  166. static HRESULT create_device(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, HWND focus, DWORD behavior, present_parameters *params, device **dev)
  167. {
  168. HRESULT result;
  169. IDirect3D9Ex *d3d9ex = (IDirect3D9Ex *) d3dptr->d3dobj;
  170. D3DPRESENT_PARAMETERS d3d9params;
  171. convert_present_params(params, &d3d9params);
  172.  
  173. if (params->Windowed)
  174. {
  175. result = d3d9ex->CreateDeviceEx(adapter, devtype, focus, behavior, &d3d9params, NULL, (IDirect3DDevice9Ex **) dev);
  176. }
  177. else
  178. {
  179. D3DDISPLAYMODEEX displaymode;
  180. convert_display_mode_d3d9params(&d3d9params, &displaymode);
  181. result = d3d9ex->CreateDeviceEx(adapter, devtype, focus, behavior, &d3d9params, &displaymode, (IDirect3DDevice9Ex **) dev);
  182. }
  183.  
  184. if (result == D3D_OK)
  185. {
  186. HRESULT latency_ok = IDirect3DDevice9Ex_SetMaximumFrameLatency((IDirect3DDevice9Ex *) *dev, 1);
  187. if (latency_ok != D3D_OK)
  188. {
  189. osd_printf_error("Unable to set Direct3D device maximum frame latency\n");
  190. }
  191. }
  192. return result;
  193. }
  194.  
  195. static HRESULT enum_adapter_modes(base *d3dptr, UINT adapter, D3DFORMAT format, UINT index, D3DDISPLAYMODE *mode)
  196. {
  197. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  198. return IDirect3D9_EnumAdapterModes(d3d9, adapter, format, index, mode);
  199. }
  200.  
  201.  
  202. static UINT get_adapter_count(base *d3dptr)
  203. {
  204. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  205. return IDirect3D9_GetAdapterCount(d3d9);
  206. }
  207.  
  208.  
  209. static HRESULT get_adapter_display_mode(base *d3dptr, UINT adapter, D3DDISPLAYMODE *mode)
  210. {
  211. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  212. return IDirect3D9_GetAdapterDisplayMode(d3d9, adapter, mode);
  213. }
  214.  
  215.  
  216. static HRESULT get_adapter_identifier(base *d3dptr, UINT adapter, DWORD flags, adapter_identifier *identifier)
  217. {
  218. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  219. D3DADAPTER_IDENTIFIER9 id;
  220. HRESULT result = IDirect3D9_GetAdapterIdentifier(d3d9, adapter, flags, &id);
  221. memcpy(identifier->Driver, id.Driver, sizeof(identifier->Driver));
  222. memcpy(identifier->Description, id.Description, sizeof(identifier->Description));
  223. identifier->DriverVersion = id.DriverVersion;
  224. identifier->VendorId = id.VendorId;
  225. identifier->DeviceId = id.DeviceId;
  226. identifier->SubSysId = id.SubSysId;
  227. identifier->Revision = id.Revision;
  228. identifier->DeviceIdentifier = id.DeviceIdentifier;
  229. identifier->WHQLLevel = id.WHQLLevel;
  230. return result;
  231. }
  232.  
  233.  
  234. static UINT get_adapter_mode_count(base *d3dptr, UINT adapter, D3DFORMAT format)
  235. {
  236. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  237. return IDirect3D9_GetAdapterModeCount(d3d9, adapter, format);
  238. }
  239.  
  240.  
  241. static HMONITOR get_adapter_monitor(base *d3dptr, UINT adapter)
  242. {
  243. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  244. return IDirect3D9_GetAdapterMonitor(d3d9, adapter);
  245. }
  246.  
  247.  
  248. static HRESULT get_caps_dword(base *d3dptr, UINT adapter, D3DDEVTYPE devtype, caps_index which, DWORD *value)
  249. {
  250. IDirect3D9 *d3d9 = (IDirect3D9 *)d3dptr->d3dobj;
  251. D3DCAPS9 caps;
  252. HRESULT result = IDirect3D9_GetDeviceCaps(d3d9, adapter, devtype, &caps);
  253. switch (which)
  254. {
  255. case CAPS_PRESENTATION_INTERVALS: *value = caps.PresentationIntervals; break;
  256. case CAPS_CAPS2: *value = caps.Caps2; break;
  257. case CAPS_DEV_CAPS: *value = caps.DevCaps; break;
  258. case CAPS_SRCBLEND_CAPS: *value = caps.SrcBlendCaps; break;
  259. case CAPS_DSTBLEND_CAPS: *value = caps.DestBlendCaps; break;
  260. case CAPS_TEXTURE_CAPS: *value = caps.TextureCaps; break;
  261. case CAPS_TEXTURE_FILTER_CAPS: *value = caps.TextureFilterCaps; break;
  262. case CAPS_TEXTURE_ADDRESS_CAPS: *value = caps.TextureAddressCaps; break;
  263. case CAPS_TEXTURE_OP_CAPS: *value = caps.TextureOpCaps; break;
  264. case CAPS_MAX_TEXTURE_ASPECT: *value = caps.MaxTextureAspectRatio; break;
  265. case CAPS_MAX_TEXTURE_WIDTH: *value = caps.MaxTextureWidth; break;
  266. case CAPS_MAX_TEXTURE_HEIGHT: *value = caps.MaxTextureHeight; break;
  267. case CAPS_STRETCH_RECT_FILTER: *value = caps.StretchRectFilterCaps; break;
  268. case CAPS_MAX_PS30_INSN_SLOTS: *value = caps.MaxPixelShader30InstructionSlots; break;
  269. }
  270. return result;
  271. }
  272.  
  273.  
  274. static ULONG release(base *d3dptr)
  275. {
  276. IDirect3D9Ex *d3d9 = (IDirect3D9Ex *)d3dptr->d3dobj;
  277. ULONG result = IDirect3D9Ex_Release(d3d9);
  278. FreeLibrary(d3dptr->dllhandle);
  279. global_free(d3dptr);
  280. return result;
  281. }
  282.  
  283.  
  284. static const interface d3d9_interface =
  285. {
  286. check_device_format,
  287. check_device_type,
  288. create_device,
  289. enum_adapter_modes,
  290. get_adapter_count,
  291. get_adapter_display_mode,
  292. get_adapter_identifier,
  293. get_adapter_mode_count,
  294. get_adapter_monitor,
  295. get_caps_dword,
  296. release
  297. };
  298.  
  299.  
  300.  
  301. //============================================================
  302. // Direct3DDevice interfaces
  303. //============================================================
  304.  
  305. static HRESULT device_begin_scene(device *dev)
  306. {
  307. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  308. return IDirect3DDevice9_BeginScene(device);
  309. }
  310.  
  311. static HRESULT device_clear(device *dev, DWORD count, const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
  312. {
  313. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  314. return IDirect3DDevice9_Clear(device, count, rects, flags, color, z, stencil);
  315. }
  316.  
  317.  
  318. static HRESULT device_create_offscreen_plain_surface(device *dev, UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, surface **surface)
  319. {
  320. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  321. return IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, pool, (IDirect3DSurface9 **)surface, NULL);
  322. }
  323.  
  324. static HRESULT device_create_texture(device *dev, UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, texture **texture)
  325. {
  326. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  327. return IDirect3DDevice9_CreateTexture(device, width, height, levels, usage, format, pool, (IDirect3DTexture9 **)texture, NULL);
  328. }
  329.  
  330.  
  331. static HRESULT device_create_vertex_buffer(device *dev, UINT length, DWORD usage, DWORD fvf, D3DPOOL pool, vertex_buffer **buf)
  332. {
  333. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  334. return IDirect3DDevice9_CreateVertexBuffer(device, length, usage, fvf, pool, (IDirect3DVertexBuffer9 **)buf, NULL);
  335. }
  336.  
  337.  
  338. static HRESULT device_draw_primitive(device *dev, D3DPRIMITIVETYPE type, UINT start, UINT count)
  339. {
  340. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  341. return IDirect3DDevice9_DrawPrimitive(device, type, start, count);
  342. }
  343.  
  344.  
  345. static HRESULT device_end_scene(device *dev)
  346. {
  347. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  348. return IDirect3DDevice9_EndScene(device);
  349. }
  350.  
  351.  
  352. static HRESULT device_get_raster_status(device *dev, D3DRASTER_STATUS *status)
  353. {
  354. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  355. return IDirect3DDevice9_GetRasterStatus(device, 0, status);
  356. }
  357.  
  358.  
  359. static HRESULT device_get_render_target(device *dev, DWORD index, surface **surface)
  360. {
  361. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  362. return IDirect3DDevice9_GetRenderTarget(device, index, (IDirect3DSurface9 **)surface);
  363. }
  364.  
  365.  
  366. static HRESULT device_get_render_target_data(device *dev, surface *rendertarget, surface *destsurface)
  367. {
  368. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  369. return IDirect3DDevice9_GetRenderTargetData(device, (IDirect3DSurface9 *)rendertarget, (IDirect3DSurface9 *)destsurface);
  370. }
  371.  
  372.  
  373. static HRESULT device_present(device *dev, const RECT *source, const RECT *dest, HWND override, RGNDATA *dirty, DWORD flags)
  374. {
  375. IDirect3DDevice9Ex *device = (IDirect3DDevice9Ex *)dev;
  376. if (flags != 0)
  377. {
  378. IDirect3DSwapChain9 *chain;
  379. HRESULT result = IDirect3DDevice9Ex_GetSwapChain(device, 0, &chain);
  380. if (result == D3D_OK)
  381. {
  382. result = IDirect3DSwapChain9Ex_Present(chain, source, dest, override, dirty, flags);
  383. IDirect3DSwapChain9Ex_Release(chain);
  384. return result;
  385. }
  386. }
  387. return IDirect3DDevice9Ex_Present(device, source, dest, override, dirty);
  388. }
  389.  
  390.  
  391. static ULONG device_release(device *dev)
  392. {
  393. IDirect3DDevice9Ex *device = (IDirect3DDevice9Ex *)dev;
  394. return IDirect3DDevice9Ex_Release(device);
  395. }
  396.  
  397.  
  398. static HRESULT device_reset(device *dev, present_parameters *params)
  399. {
  400. HRESULT result;
  401. IDirect3DDevice9Ex *device = (IDirect3DDevice9Ex *)dev;
  402. D3DPRESENT_PARAMETERS d3d9params;
  403. convert_present_params(params, &d3d9params);
  404.  
  405. if (params->Windowed)
  406. {
  407. result = IDirect3DDevice9Ex_ResetEx(device, &d3d9params, NULL);
  408. }
  409. else
  410. {
  411. D3DDISPLAYMODEEX displaymode;
  412. convert_display_mode_d3d9params(&d3d9params, &displaymode);
  413. result = IDirect3DDevice9Ex_ResetEx(device, &d3d9params, &displaymode);
  414. }
  415.  
  416. return result;
  417. }
  418.  
  419.  
  420. static void device_set_gamma_ramp(device *dev, DWORD flags, const D3DGAMMARAMP *ramp)
  421. {
  422. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  423. IDirect3DDevice9_SetGammaRamp(device, 0, flags, ramp);
  424. }
  425.  
  426.  
  427. static HRESULT device_set_render_state(device *dev, D3DRENDERSTATETYPE state, DWORD value)
  428. {
  429. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  430. return IDirect3DDevice9_SetRenderState(device, state, value);
  431. }
  432.  
  433.  
  434. static HRESULT device_set_render_target(device *dev, DWORD index, surface *surf)
  435. {
  436. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  437. IDirect3DSurface9 *surface = (IDirect3DSurface9 *)surf;
  438. return IDirect3DDevice9_SetRenderTarget(device, index, surface);
  439. }
  440.  
  441.  
  442. static HRESULT device_create_render_target(device *dev, UINT width, UINT height, D3DFORMAT format, surface **surface)
  443. {
  444. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  445. return IDirect3DDevice9_CreateRenderTarget(device, width, height, format, D3DMULTISAMPLE_NONE, 0, false, (IDirect3DSurface9 **)surface, NULL);
  446. }
  447.  
  448.  
  449. static HRESULT device_set_stream_source(device *dev, UINT number, vertex_buffer *vbuf, UINT stride)
  450. {
  451. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  452. IDirect3DVertexBuffer9 *vertexbuf = (IDirect3DVertexBuffer9 *)vbuf;
  453. return IDirect3DDevice9_SetStreamSource(device, number, vertexbuf, 0, stride);
  454. }
  455.  
  456.  
  457. static HRESULT device_set_texture(device *dev, DWORD stage, texture *tex)
  458. {
  459. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  460. IDirect3DBaseTexture9 *texture = (IDirect3DBaseTexture9 *)tex;
  461. return IDirect3DDevice9_SetTexture(device, stage, texture);
  462. }
  463.  
  464.  
  465. static HRESULT device_set_texture_stage_state(device *dev, DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
  466. {
  467. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  468.  
  469. // some state which was here got pushed into sampler state in D3D9
  470. switch ((DWORD)state)
  471. {
  472. case D3DTSS_ADDRESSU:
  473. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_ADDRESSU, value);
  474. case D3DTSS_ADDRESSV:
  475. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_ADDRESSV, value);
  476. case D3DTSS_BORDERCOLOR:
  477. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_BORDERCOLOR, value);
  478. case D3DTSS_MAGFILTER:
  479. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MAGFILTER, value);
  480. case D3DTSS_MINFILTER:
  481. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MINFILTER, value);
  482. case D3DTSS_MIPFILTER:
  483. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MIPFILTER, value);
  484. case D3DTSS_MIPMAPLODBIAS:
  485. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MIPMAPLODBIAS, value);
  486. case D3DTSS_MAXMIPLEVEL:
  487. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MAXMIPLEVEL, value);
  488. case D3DTSS_MAXANISOTROPY:
  489. return IDirect3DDevice9_SetSamplerState(device, stage, D3DSAMP_MAXANISOTROPY, value);
  490. default:
  491. return IDirect3DDevice9_SetTextureStageState(device, stage, state, value);
  492. }
  493. }
  494.  
  495.  
  496. static HRESULT device_set_vertex_format(device *dev, D3DFORMAT format)
  497. {
  498. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  499. return IDirect3DDevice9_SetFVF(device, format);
  500. }
  501.  
  502.  
  503. static HRESULT device_stretch_rect(device *dev, surface *source, const RECT *srcrect, surface *dest, const RECT *dstrect, D3DTEXTUREFILTERTYPE filter)
  504. {
  505. IDirect3DDevice9 *device = (IDirect3DDevice9 *)dev;
  506. IDirect3DSurface9 *ssurface = (IDirect3DSurface9 *)source;
  507. IDirect3DSurface9 *dsurface = (IDirect3DSurface9 *)dest;
  508. return IDirect3DDevice9_StretchRect(device, ssurface, srcrect, dsurface, dstrect, filter);
  509. }
  510.  
  511.  
  512. static HRESULT device_test_cooperative_level(device *dev)
  513. {
  514. IDirect3DDevice9Ex *device = (IDirect3DDevice9Ex *) dev;
  515. return IDirect3DDevice9Ex_CheckDeviceState(device, NULL);
  516. }
  517.  
  518.  
  519. static const device_interface d3d9_device_interface =
  520. {
  521. device_begin_scene,
  522. device_clear,
  523. device_create_offscreen_plain_surface,
  524. device_create_texture,
  525. device_create_vertex_buffer,
  526. device_create_render_target,
  527. device_draw_primitive,
  528. device_end_scene,
  529. device_get_raster_status,
  530. device_get_render_target,
  531. device_get_render_target_data,
  532. device_present,
  533. device_release,
  534. device_reset,
  535. device_set_gamma_ramp,
  536. device_set_render_state,
  537. device_set_render_target,
  538. device_set_stream_source,
  539. device_set_texture,
  540. device_set_texture_stage_state,
  541. device_set_vertex_format,
  542. device_stretch_rect,
  543. device_test_cooperative_level
  544. };
  545.  
  546.  
  547.  
  548. //============================================================
  549. // Direct3DSurface interfaces
  550. //============================================================
  551.  
  552. static HRESULT surface_lock_rect(surface *surf, D3DLOCKED_RECT *locked, const RECT *rect, DWORD flags)
  553. {
  554. IDirect3DSurface9 *surface = (IDirect3DSurface9 *)surf;
  555. return IDirect3DSurface9_LockRect(surface, locked, rect, flags);
  556. }
  557.  
  558.  
  559. static ULONG surface_release(surface *surf)
  560. {
  561. IDirect3DSurface9 *surface = (IDirect3DSurface9 *)surf;
  562. return IDirect3DSurface9_Release(surface);
  563. }
  564.  
  565.  
  566. static HRESULT surface_unlock_rect(surface *surf)
  567. {
  568. IDirect3DSurface9 *surface = (IDirect3DSurface9 *)surf;
  569. return IDirect3DSurface9_UnlockRect(surface);
  570. }
  571.  
  572.  
  573. static const surface_interface d3d9_surface_interface =
  574. {
  575. surface_lock_rect,
  576. surface_release,
  577. surface_unlock_rect
  578. };
  579.  
  580.  
  581.  
  582. //============================================================
  583. // Direct3DTexture interfaces
  584. //============================================================
  585.  
  586. static HRESULT texture_get_surface_level(texture *tex, UINT level, surface **surface)
  587. {
  588. IDirect3DTexture9 *texture = (IDirect3DTexture9 *)tex;
  589. return IDirect3DTexture9_GetSurfaceLevel(texture, level, (IDirect3DSurface9 **)surface);
  590. }
  591.  
  592.  
  593. static HRESULT texture_lock_rect(texture *tex, UINT level, D3DLOCKED_RECT *locked, const RECT *rect, DWORD flags)
  594. {
  595. IDirect3DTexture9 *texture = (IDirect3DTexture9 *)tex;
  596. return IDirect3DTexture9_LockRect(texture, level, locked, rect, flags);
  597. }
  598.  
  599.  
  600. static ULONG texture_release(texture *tex)
  601. {
  602. IDirect3DTexture9 *texture = (IDirect3DTexture9 *)tex;
  603. return IDirect3DTexture9_Release(texture);
  604. }
  605.  
  606.  
  607. static HRESULT texture_unlock_rect(texture *tex, UINT level)
  608. {
  609. IDirect3DTexture9 *texture = (IDirect3DTexture9 *)tex;
  610. return IDirect3DTexture9_UnlockRect(texture, level);
  611. }
  612.  
  613.  
  614. static const texture_interface d3d9_texture_interface =
  615. {
  616. texture_get_surface_level,
  617. texture_lock_rect,
  618. texture_release,
  619. texture_unlock_rect
  620. };
  621.  
  622.  
  623.  
  624. //============================================================
  625. // Direct3DVertexBuffer interfaces
  626. //============================================================
  627.  
  628. static HRESULT vertex_buffer_lock(vertex_buffer *vbuf, UINT offset, UINT size, VOID **data, DWORD flags)
  629. {
  630. IDirect3DVertexBuffer9 *vertexbuf = (IDirect3DVertexBuffer9 *)vbuf;
  631. return IDirect3DVertexBuffer9_Lock(vertexbuf, offset, size, data, flags);
  632. }
  633.  
  634.  
  635. static ULONG vertex_buffer_release(vertex_buffer *vbuf)
  636. {
  637. IDirect3DVertexBuffer9 *vertexbuf = (IDirect3DVertexBuffer9 *)vbuf;
  638. return IDirect3DVertexBuffer9_Release(vertexbuf);
  639. }
  640.  
  641.  
  642. static HRESULT vertex_buffer_unlock(vertex_buffer *vbuf)
  643. {
  644. IDirect3DVertexBuffer9 *vertexbuf = (IDirect3DVertexBuffer9 *)vbuf;
  645. return IDirect3DVertexBuffer9_Unlock(vertexbuf);
  646. }
  647.  
  648.  
  649. static const vertex_buffer_interface d3d9_vertex_buffer_interface =
  650. {
  651. vertex_buffer_lock,
  652. vertex_buffer_release,
  653. vertex_buffer_unlock
  654. };
  655.  
  656.  
  657. //============================================================
  658. // set_interfaces
  659. //============================================================
  660.  
  661. static void set_interfaces(base *d3dptr)
  662. {
  663. d3dptr->d3d = d3d9_interface;
  664. d3dptr->device = d3d9_device_interface;
  665. d3dptr->surface = d3d9_surface_interface;
  666. d3dptr->texture = d3d9_texture_interface;
  667. d3dptr->vertexbuf = d3d9_vertex_buffer_interface;
  668. }
  669.  
  670. };
RAW Paste Data