Guest User

d3d9intf.c

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×