diff --git a/reactos/dll/directx/wine/d3d8/d3d8_private.h b/reactos/dll/directx/wine/d3d8/d3d8_private.h index c8051dcd8e3..98d5c7fcaf6 100644 --- a/reactos/dll/directx/wine/d3d8/d3d8_private.h +++ b/reactos/dll/directx/wine/d3d8/d3d8_private.h @@ -160,6 +160,7 @@ struct IDirect3D8Impl * Predeclare the interface implementation structures */ extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl; +extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl; /***************************************************************************** * IDirect3DDevice8 implementation structure @@ -170,13 +171,14 @@ typedef void * shader_handle; struct FvfToDecl { DWORD fvf; - IWineD3DVertexDeclaration *decl; + struct IDirect3DVertexDeclaration8 *decl; }; struct IDirect3DDevice8Impl { /* IUnknown fields */ const IDirect3DDevice8Vtbl *lpVtbl; + const IWineD3DDeviceParentVtbl *device_parent_vtbl; LONG ref; /* But what about baseVertexIndex in state blocks? hmm... it may be a better idea to pass this to wined3d */ IWineD3DDevice *WineD3DDevice; @@ -200,6 +202,7 @@ struct IDirect3DDevice8Impl /***************************************************************************** * IDirect3DVolume8 implementation structure */ +extern const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl; struct IDirect3DVolume8Impl { /* IUnknown fields */ @@ -531,11 +534,12 @@ typedef struct { DWORD elements_size; /* Size of elements, in bytes */ IWineD3DVertexDeclaration *wined3d_vertex_declaration; + DWORD shader_handle; } IDirect3DVertexDeclaration8Impl; /***************************************************************************** - * IDirect3DVertexShader9 interface + * IDirect3DVertexShader8 interface */ #define INTERFACE IDirect3DVertexShader8 DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown) @@ -544,9 +548,6 @@ DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown) STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IDirect3DVertexShader9 methods ***/ - STDMETHOD(GetDevice)(THIS_ struct IDirect3DDevice8** ppDevice) PURE; - STDMETHOD(GetFunction)(THIS_ void*, UINT* pSizeOfData) PURE; }; #undef INTERFACE @@ -554,16 +555,13 @@ DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown) #define IDirect3DVertexShader8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) #define IDirect3DVertexShader8_AddRef(p) (p)->lpVtbl->AddRef(p) #define IDirect3DVertexShader8_Release(p) (p)->lpVtbl->Release(p) -/*** IDirect3DVertexShader8 methods ***/ -#define IDirect3DVertexShader8_GetDevice(p,a) (p)->lpVtbl->GetDevice(p,a) -#define IDirect3DVertexShader8_GetFunction(p,a,b) (p)->lpVtbl->GetFunction(p,a,b) /* ------------------------- */ /* IDirect3DVertexShader8Impl */ /* ------------------------- */ /***************************************************************************** - * IDirect3DPixelShader9 interface + * IDirect3DPixelShader8 interface */ #define INTERFACE IDirect3DPixelShader8 DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown) @@ -572,9 +570,6 @@ DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown) STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IDirect3DPixelShader8 methods ***/ - STDMETHOD(GetDevice)(THIS_ struct IDirect3DDevice8** ppDevice) PURE; - STDMETHOD(GetFunction)(THIS_ void*, UINT* pSizeOfData) PURE; }; #undef INTERFACE @@ -582,10 +577,6 @@ DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown) #define IDirect3DPixelShader8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) #define IDirect3DPixelShader8_AddRef(p) (p)->lpVtbl->AddRef(p) #define IDirect3DPixelShader8_Release(p) (p)->lpVtbl->Release(p) -/*** IDirect3DPixelShader8 methods ***/ -#define IDirect3DPixelShader8_GetDevice(p,a) (p)->lpVtbl->GetDevice(p,a) -#define IDirect3DPixelShader8_GetFunction(p,a,b) (p)->lpVtbl->GetFunction(p,a,b) - /***************************************************************************** * Predeclare the interface implementation structures @@ -600,7 +591,6 @@ struct IDirect3DVertexShader8Impl { const IDirect3DVertexShader8Vtbl *lpVtbl; LONG ref; - DWORD handle; IDirect3DVertexDeclaration8 *vertex_declaration; IWineD3DVertexShader *wineD3DVertexShader; }; @@ -624,7 +614,6 @@ typedef struct IDirect3DPixelShader8Impl { LONG ref; DWORD handle; - /* The device, to be replaced by an IDirect3DDeviceImpl */ IWineD3DPixelShader *wineD3DPixelShader; } IDirect3DPixelShader8Impl; @@ -638,34 +627,10 @@ UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elem size_t parse_token(const DWORD* pToken); /* Callbacks */ -extern HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level, - WINED3DCUBEMAP_FACES Face, IWineD3DSurface** ppSurface, - HANDLE* pSharedHandle); - -extern HRESULT WINAPI D3D8CB_CreateVolume(IUnknown *pDevice, IUnknown *pSuperior, UINT Width, UINT Height, UINT Depth, - WINED3DFORMAT Format, WINED3DPOOL Pool, DWORD Usage, - IWineD3DVolume **ppVolume, - HANDLE * pSharedHandle); - -extern HRESULT WINAPI D3D8CB_CreateDepthStencilSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample, - DWORD MultisampleQuality, BOOL Discard, - IWineD3DSurface** ppSurface, HANDLE* pSharedHandle); - -extern HRESULT WINAPI D3D8CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample, - DWORD MultisampleQuality, BOOL Lockable, - IWineD3DSurface** ppSurface, HANDLE* pSharedHandle); - extern ULONG WINAPI D3D8CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain); - extern ULONG WINAPI D3D8CB_DestroyDepthStencilSurface (IWineD3DSurface *pSurface); - extern ULONG WINAPI D3D8CB_DestroyRenderTarget (IWineD3DSurface *pSurface); - extern ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface); - extern ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume); #endif /* __WINE_D3DX8_PRIVATE_H */ diff --git a/reactos/dll/directx/wine/d3d8/device.c b/reactos/dll/directx/wine/d3d8/device.c index f9a0150b4fa..5ef6311d6c2 100644 --- a/reactos/dll/directx/wine/d3d8/device.c +++ b/reactos/dll/directx/wine/d3d8/device.c @@ -73,6 +73,13 @@ static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 ifac return S_OK; } + if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent)) + { + IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl); + *ppobj = &This->device_parent_vtbl; + return S_OK; + } + WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj); *ppobj = NULL; return E_NOINTERFACE; @@ -104,7 +111,7 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) { This->inDestruction = TRUE; for(i = 0; i < This->numConvertedDecls; i++) { - IWineD3DVertexDeclaration_Release(This->decls[i].decl); + IDirect3DVertexDeclaration8_Release(This->decls[i].decl); } HeapFree(GetProcessHeap(), 0, This->decls); @@ -308,7 +315,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DD localParameters.AutoRestoreDisplayMode = TRUE; EnterCriticalSection(&d3d8_cs); - hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface, SURFACE_OPENGL); + hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, + &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL); LeaveCriticalSection(&d3d8_cs); pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; @@ -462,7 +470,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface object->ref = 1; EnterCriticalSection(&d3d8_cs); hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK, - (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DTexture, NULL, (IUnknown *)object, D3D8CB_CreateSurface); + Format, Pool, &object->wineD3DTexture, NULL, (IUnknown *)object); LeaveCriticalSection(&d3d8_cs); if (FAILED(hrc)) { @@ -501,9 +509,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl; object->ref = 1; EnterCriticalSection(&d3d8_cs); - hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK, - (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, NULL, - (IUnknown *)object, D3D8CB_CreateVolume); + hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, + Usage & WINED3DUSAGE_MASK, Format, Pool, &object->wineD3DVolumeTexture, NULL, (IUnknown *)object); LeaveCriticalSection(&d3d8_cs); if (hrc != D3D_OK) { @@ -543,8 +550,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 i object->ref = 1; EnterCriticalSection(&d3d8_cs); hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK, - (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, NULL, (IUnknown*)object, - D3D8CB_CreateSurface); + Format, Pool, &object->wineD3DCubeTexture, NULL, (IUnknown *)object); LeaveCriticalSection(&d3d8_cs); if (hr != D3D_OK){ @@ -761,11 +767,11 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, ID /* Copy rect by rect */ if (NULL != pSourceRects && NULL != pDestPoints) { for (i = 0; i < cRects; ++i) { - IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); + IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); } } else { for (i = 0; i < cRects; ++i) { - IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); + IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY); } } } @@ -1110,7 +1116,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface EnterCriticalSection(&d3d8_cs); hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock); if (hr != D3D_OK) { - FIXME("IWineD3DDevice_EndStateBlock returned an error\n"); + WARN("IWineD3DDevice_EndStateBlock returned an error\n"); LeaveCriticalSection(&d3d8_cs); return hr; } @@ -1263,100 +1269,70 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, D return hr; } +static const struct tss_lookup +{ + BOOL sampler_state; + DWORD state; +} +tss_lookup[] = +{ + {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */ + {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */ + {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */ + {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */ + {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */ + {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */ + {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */ + {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */ + {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */ + {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */ + {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */ + {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */ + {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */ + {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */ + {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */ + {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */ + {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */ + {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */ + {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */ + {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */ + {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */ + {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */ + {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */ + {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */ + {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */ + {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */ + {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */ + {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */ + {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */ +}; + static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) { IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface; + const struct tss_lookup *l = &tss_lookup[Type]; HRESULT hr; TRACE("(%p) Relay\n" , This); - switch(Type) { - case D3DTSS_ADDRESSU: - Type = WINED3DSAMP_ADDRESSU; - break; - case D3DTSS_ADDRESSV: - Type = WINED3DSAMP_ADDRESSV; - break; - case D3DTSS_ADDRESSW: - Type = WINED3DSAMP_ADDRESSW; - break; - case D3DTSS_BORDERCOLOR: - Type = WINED3DSAMP_BORDERCOLOR; - break; - case D3DTSS_MAGFILTER: - Type = WINED3DSAMP_MAGFILTER; - break; - case D3DTSS_MAXANISOTROPY: - Type = WINED3DSAMP_MAXANISOTROPY; - break; - case D3DTSS_MAXMIPLEVEL: - Type = WINED3DSAMP_MAXMIPLEVEL; - break; - case D3DTSS_MINFILTER: - Type = WINED3DSAMP_MINFILTER; - break; - case D3DTSS_MIPFILTER: - Type = WINED3DSAMP_MIPFILTER; - break; - case D3DTSS_MIPMAPLODBIAS: - Type = WINED3DSAMP_MIPMAPLODBIAS; - break; - default: - EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue); - LeaveCriticalSection(&d3d8_cs); - return hr; - } - EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, Type, pValue); + + if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue); + else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue); + LeaveCriticalSection(&d3d8_cs); return hr; } static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) { IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface; + const struct tss_lookup *l = &tss_lookup[Type]; HRESULT hr; TRACE("(%p) Relay\n" , This); - switch(Type) { - case D3DTSS_ADDRESSU: - Type = WINED3DSAMP_ADDRESSU; - break; - case D3DTSS_ADDRESSV: - Type = WINED3DSAMP_ADDRESSV; - break; - case D3DTSS_ADDRESSW: - Type = WINED3DSAMP_ADDRESSW; - break; - case D3DTSS_BORDERCOLOR: - Type = WINED3DSAMP_BORDERCOLOR; - break; - case D3DTSS_MAGFILTER: - Type = WINED3DSAMP_MAGFILTER; - break; - case D3DTSS_MAXANISOTROPY: - Type = WINED3DSAMP_MAXANISOTROPY; - break; - case D3DTSS_MAXMIPLEVEL: - Type = WINED3DSAMP_MAXMIPLEVEL; - break; - case D3DTSS_MINFILTER: - Type = WINED3DSAMP_MINFILTER; - break; - case D3DTSS_MIPFILTER: - Type = WINED3DSAMP_MIPFILTER; - break; - case D3DTSS_MIPMAPLODBIAS: - Type = WINED3DSAMP_MIPMAPLODBIAS; - break; - default: - EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value); - LeaveCriticalSection(&d3d8_cs); - return hr; - } - EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, Type, Value); + + if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value); + else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value); + LeaveCriticalSection(&d3d8_cs); return hr; } @@ -1537,6 +1513,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 IDirect3DVertexShader8Impl *object; IWineD3DVertexDeclaration *wined3d_vertex_declaration; const DWORD *token = pDeclaration; + shader_handle *handle; /* Test if the vertex declaration is valid */ while (D3DVSD_END() != *token) { @@ -1575,41 +1552,57 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 *ppShader = 0; return D3DERR_INVALIDCALL; } - wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration; - /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */ - hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration, pFunction, &object->wineD3DVertexShader, (IUnknown *)object); - - if (FAILED(hrc)) { - /* free up object */ - FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n"); + handle = alloc_shader_handle(This); + if (!handle) + { + ERR("Failed to allocate shader handle\n"); + LeaveCriticalSection(&d3d8_cs); + IDirect3DVertexDeclaration8_Release(object->vertex_declaration); HeapFree(GetProcessHeap(), 0, object); *ppShader = 0; - } else { - /* TODO: Store the VS declarations locally so that they can be dereferenced with a value higher than VS_HIGHESTFIXEDFXF */ - shader_handle *handle = alloc_shader_handle(This); - if (!handle) { - ERR("Failed to allocate shader handle\n"); - IDirect3DVertexShader8_Release((IUnknown *)object); - hrc = E_OUTOFMEMORY; - } else { - *handle = object; - object->handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1; - *ppShader = object->handle; + return E_OUTOFMEMORY; + } + else + { + DWORD shader_handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1; + *handle = object; + *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle; + } + wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration; + + if (pFunction) + { + /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */ + hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration, + pFunction, &object->wineD3DVertexShader, (IUnknown *)object); + + if (FAILED(hrc)) + { + /* free up object */ + FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n"); + free_shader_handle(This, handle); + IDirect3DVertexDeclaration8_Release(object->vertex_declaration); + HeapFree(GetProcessHeap(), 0, object); + *ppShader = 0; + } + else + { load_local_constants(pDeclaration, object->wineD3DVertexShader); TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader); } } + LeaveCriticalSection(&d3d8_cs); return hrc; } -static IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf) +static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf) { + IDirect3DVertexDeclaration8Impl *d3d8_declaration; HRESULT hr; - IWineD3DVertexDeclaration* pDecl = NULL; int p, low, high; /* deliberately signed */ struct FvfToDecl *convertedDecls = This->decls; @@ -1622,7 +1615,7 @@ static IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8 TRACE("%d ", p); if(convertedDecls[p].fvf == fvf) { TRACE("found %p\n", convertedDecls[p].decl); - return convertedDecls[p].decl; + return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl; } else if(convertedDecls[p].fvf < fvf) { low = p + 1; } else { @@ -1631,11 +1624,27 @@ static IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8 } TRACE("not found. Creating and inserting at position %d.\n", low); + d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration)); + if (!d3d8_declaration) + { + ERR("Memory allocation failed.\n"); + return NULL; + } + + d3d8_declaration->ref_count = 1; + d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl; + d3d8_declaration->elements = NULL; + d3d8_declaration->elements_size = 0; + d3d8_declaration->shader_handle = fvf; + hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice, - &pDecl, - (IUnknown *) This, - fvf); - if (FAILED(hr)) return NULL; + &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf); + if (FAILED(hr)) + { + ERR("Failed to create wined3d vertex declaration.\n"); + HeapFree(GetProcessHeap(), 0, d3d8_declaration); + return NULL; + } if(This->declArraySize == This->numConvertedDecls) { int grow = This->declArraySize / 2; @@ -1643,7 +1652,7 @@ static IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow)); if(!convertedDecls) { /* This will destroy it */ - IWineD3DVertexDeclaration_Release(pDecl); + IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration); return NULL; } This->decls = convertedDecls; @@ -1651,12 +1660,12 @@ static IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8 } memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low)); - convertedDecls[low].decl = pDecl; + convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration; convertedDecls[low].fvf = fvf; This->numConvertedDecls++; - TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls); - return pDecl; + TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls); + return d3d8_declaration; } static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) { @@ -1666,9 +1675,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 ifa TRACE("(%p) : Relay\n", This); EnterCriticalSection(&d3d8_cs); if (VS_HIGHESTFIXEDFXF >= pShader) { - TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF, pShader); - IWineD3DDevice_SetFVF(This->WineD3DDevice, pShader); - IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, IDirect3DDevice8Impl_FindDecl(This, pShader)); + TRACE("Setting FVF, %#x\n", pShader); + IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, + IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration); IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL); } else { TRACE("Setting shader\n"); @@ -1677,9 +1686,19 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 ifa hrc = D3DERR_INVALIDCALL; } else { IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)]; - IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, - shader ? ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration : NULL); - hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, 0 == shader ? NULL : shader->wineD3DVertexShader); + + if (shader) + { + hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, + ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration); + if (SUCCEEDED(hrc)) + hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader); + } + else + { + hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, NULL); + if (SUCCEEDED(hrc)) hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL); + } } } TRACE("(%p) : returning hr(%u)\n", This, hrc); @@ -1690,24 +1709,36 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 ifa static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) { IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface; - IWineD3DVertexShader *pShader; - HRESULT hrc = D3D_OK; + IWineD3DVertexDeclaration *wined3d_declaration; + HRESULT hrc; TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice); EnterCriticalSection(&d3d8_cs); - hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader); - if (D3D_OK == hrc) { - if(0 != pShader) { - IDirect3DVertexShader8Impl *d3d8_shader; - hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)&d3d8_shader); - IWineD3DVertexShader_Release(pShader); - *ppShader = d3d8_shader->handle; - } else { + + hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration); + if (SUCCEEDED(hrc)) + { + if (wined3d_declaration) + { + IDirect3DVertexDeclaration8 *d3d8_declaration; + hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration); + IWineD3DVertexDeclaration_Release(wined3d_declaration); + if (SUCCEEDED(hrc)) + { + *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle; + IDirect3DVertexDeclaration8_Release(d3d8_declaration); + } + } + else + { *ppShader = 0; hrc = D3D_OK; } - } else { - WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice); + } + else + { + WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n", + This, hrc, This->WineD3DDevice); } TRACE("(%p) : returning %#x\n", This, *ppShader); LeaveCriticalSection(&d3d8_cs); @@ -1750,7 +1781,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEV TRACE("(%p) : Relay\n", This); EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount); + hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount); LeaveCriticalSection(&d3d8_cs); return hr; } @@ -1761,7 +1792,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEV TRACE("(%p) : Relay\n", This); EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount); + hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount); LeaveCriticalSection(&d3d8_cs); return hr; } @@ -1819,7 +1850,16 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEV } shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)]; - hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData); + if (shader->wineD3DVertexShader) + { + hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData); + } + else + { + *pSizeOfData = 0; + hr = D3D_OK; + } + LeaveCriticalSection(&d3d8_cs); return hr; } @@ -1995,7 +2035,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDE TRACE("(%p) Relay\n", This); EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount); + hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount); LeaveCriticalSection(&d3d8_cs); return hr; } @@ -2006,7 +2046,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVI TRACE("(%p) Relay\n", This); EnterCriticalSection(&d3d8_cs); - hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount); + hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount); LeaveCriticalSection(&d3d8_cs); return hr; } @@ -2206,34 +2246,6 @@ const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl = IDirect3DDevice8Impl_DeletePatch }; -/* Internal function called back during the CreateDevice to create a render target */ -HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level, - WINED3DCUBEMAP_FACES Face, IWineD3DSurface **ppSurface, - HANDLE *pSharedHandle) { - - HRESULT res = D3D_OK; - IDirect3DSurface8Impl *d3dSurface = NULL; - BOOL Lockable = TRUE; - - if((WINED3DPOOL_DEFAULT == Pool && WINED3DUSAGE_DYNAMIC != Usage)) - Lockable = FALSE; - - TRACE("relay\n"); - res = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface8 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */); - - if (SUCCEEDED(res)) { - *ppSurface = d3dSurface->wineD3DSurface; - d3dSurface->container = pSuperior; - IUnknown_Release(d3dSurface->parentDevice); - d3dSurface->parentDevice = NULL; - d3dSurface->forwardReference = pSuperior; - } else { - FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device); - } - return res; -} - ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) { IDirect3DSurface8Impl* surfaceParent; TRACE("(%p) call back\n", pSurface); @@ -2244,3 +2256,234 @@ ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) { surfaceParent->forwardReference = NULL; return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent); } + +/* IWineD3DDeviceParent IUnknown methods */ + +static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface) +{ + return (struct IDirect3DDevice8Impl *)((char*)iface + - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl)); +} + +HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object); +} + +ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This); +} + +ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This); +} + +/* IWineD3DDeviceParent methods */ + +static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface, + IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage, + WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + IDirect3DSurface8Impl *d3d_surface; + BOOL lockable = TRUE; + HRESULT hr; + + TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n" + "\tpool %#x, level %u, face %u, surface %p\n", + iface, superior, width, height, format, usage, pool, level, face, surface); + + + if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE; + + hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height, + format, lockable, FALSE /* Discard */, level, (IDirect3DSurface8 **)&d3d_surface, + D3DRTYPE_SURFACE, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */); + if (FAILED(hr)) + { + ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr); + return hr; + } + + *surface = d3d_surface->wineD3DSurface; + d3d_surface->container = superior; + IUnknown_Release(d3d_surface->parentDevice); + d3d_surface->parentDevice = NULL; + d3d_surface->forwardReference = superior; + + return hr; +} + +static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface, + IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type, + DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + IDirect3DSurface8Impl *d3d_surface; + HRESULT hr; + + TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n" + "\tmultisample_quality %u, lockable %u, surface %p\n", + iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface); + + hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height, format, + multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface); + if (FAILED(hr)) + { + ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr); + return hr; + } + + *surface = d3d_surface->wineD3DSurface; + d3d_surface->container = (IUnknown *)This; + d3d_surface->isImplicit = TRUE; + /* Implicit surfaces are created with an refcount of 0 */ + IUnknown_Release((IUnknown *)d3d_surface); + + return hr; +} + +static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface, + IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type, + DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + IDirect3DSurface8Impl *d3d_surface; + HRESULT hr; + + TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n" + "\tmultisample_quality %u, discard %u, surface %p\n", + iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface); + + hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height, format, + multisample_type, (IDirect3DSurface8 **)&d3d_surface); + if (FAILED(hr)) + { + ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr); + return hr; + } + + *surface = d3d_surface->wineD3DSurface; + d3d_surface->container = (IUnknown *)This; + d3d_surface->isImplicit = TRUE; + /* Implicit surfaces are created with an refcount of 0 */ + IUnknown_Release((IUnknown *)d3d_surface); + + return hr; +} + +static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface, + IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format, + WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + IDirect3DVolume8Impl *object; + HRESULT hr; + + TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n", + iface, superior, width, height, depth, format, pool, usage, volume); + + /* Allocate the storage for the device */ + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + FIXME("Allocation of memory failed\n"); + *volume = NULL; + return D3DERR_OUTOFVIDEOMEMORY; + } + + object->lpVtbl = &Direct3DVolume8_Vtbl; + object->ref = 1; + hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage, + format, pool, &object->wineD3DVolume, NULL, (IUnknown *)object); + if (FAILED(hr)) + { + ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr); + HeapFree(GetProcessHeap(), 0, object); + *volume = NULL; + return hr; + } + + *volume = object->wineD3DVolume; + object->container = superior; + object->forwardReference = superior; + + TRACE("(%p) Created volume %p\n", iface, *volume); + + return hr; +} + +static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface, + WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain) +{ + struct IDirect3DDevice8Impl *This = device_from_device_parent(iface); + IDirect3DSwapChain8Impl *d3d_swapchain; + D3DPRESENT_PARAMETERS local_parameters; + HRESULT hr; + + TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain); + + /* Copy the presentation parameters */ + local_parameters.BackBufferWidth = present_parameters->BackBufferWidth; + local_parameters.BackBufferHeight = present_parameters->BackBufferHeight; + local_parameters.BackBufferFormat = present_parameters->BackBufferFormat; + local_parameters.BackBufferCount = present_parameters->BackBufferCount; + local_parameters.MultiSampleType = present_parameters->MultiSampleType; + local_parameters.SwapEffect = present_parameters->SwapEffect; + local_parameters.hDeviceWindow = present_parameters->hDeviceWindow; + local_parameters.Windowed = present_parameters->Windowed; + local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil; + local_parameters.AutoDepthStencilFormat = present_parameters->AutoDepthStencilFormat; + local_parameters.Flags = present_parameters->Flags; + local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz; + local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval; + + hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This, + &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain); + if (FAILED(hr)) + { + ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr); + *swapchain = NULL; + return hr; + } + + *swapchain = d3d_swapchain->wineD3DSwapChain; + IUnknown_Release(d3d_swapchain->parentDevice); + d3d_swapchain->parentDevice = NULL; + + /* Copy back the presentation parameters */ + present_parameters->BackBufferWidth = local_parameters.BackBufferWidth; + present_parameters->BackBufferHeight = local_parameters.BackBufferHeight; + present_parameters->BackBufferFormat = local_parameters.BackBufferFormat; + present_parameters->BackBufferCount = local_parameters.BackBufferCount; + present_parameters->MultiSampleType = local_parameters.MultiSampleType; + present_parameters->SwapEffect = local_parameters.SwapEffect; + present_parameters->hDeviceWindow = local_parameters.hDeviceWindow; + present_parameters->Windowed = local_parameters.Windowed; + present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil; + present_parameters->AutoDepthStencilFormat = local_parameters.AutoDepthStencilFormat; + present_parameters->Flags = local_parameters.Flags; + present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz; + present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval; + + return hr; +} + +const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl = +{ + /* IUnknown methods */ + device_parent_QueryInterface, + device_parent_AddRef, + device_parent_Release, + /* IWineD3DDeviceParent methods */ + device_parent_CreateSurface, + device_parent_CreateRenderTarget, + device_parent_CreateDepthStencilSurface, + device_parent_CreateVolume, + device_parent_CreateSwapChain, +}; diff --git a/reactos/dll/directx/wine/d3d8/directx.c b/reactos/dll/directx/wine/d3d8/directx.c index 3efbab09b16..72ccb3dd9d9 100644 --- a/reactos/dll/directx/wine/d3d8/directx.c +++ b/reactos/dll/directx/wine/d3d8/directx.c @@ -260,31 +260,6 @@ static HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT return ret; } -/* Internal function called back during the CreateDevice to create a render target */ -HRESULT WINAPI D3D8CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample, - DWORD MultisampleQuality, BOOL Lockable, - IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) { - HRESULT res = D3D_OK; - IDirect3DSurface8Impl *d3dSurface = NULL; - - TRACE("(%p) call back\n", device); - res = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)device, Width, Height, - (D3DFORMAT)Format, MultiSample, Lockable, - (IDirect3DSurface8 **)&d3dSurface); - - if (SUCCEEDED(res)) { - *ppSurface = d3dSurface->wineD3DSurface; - d3dSurface->container = device; - d3dSurface->isImplicit = TRUE; - /* Implicit surfaces are created with an refcount of 0 */ - IUnknown_Release((IUnknown *)d3dSurface); - } else { - *ppSurface = NULL; - } - return res; -} - ULONG WINAPI D3D8CB_DestroyRenderTarget(IWineD3DSurface *pSurface) { IDirect3DSurface8Impl* surfaceParent; TRACE("(%p) call back\n", pSurface); @@ -295,58 +270,6 @@ ULONG WINAPI D3D8CB_DestroyRenderTarget(IWineD3DSurface *pSurface) { return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent); } -/* Callback for creating the implicit swapchain when the device is created */ -static HRESULT WINAPI D3D8CB_CreateAdditionalSwapChain(IUnknown *device, - WINED3DPRESENT_PARAMETERS* pPresentationParameters, - IWineD3DSwapChain ** ppSwapChain){ - HRESULT res = D3D_OK; - IDirect3DSwapChain8Impl *d3dSwapChain = NULL; - D3DPRESENT_PARAMETERS localParameters; - TRACE("(%p) call back\n", device); - - /* Copy the presentation parameters */ - localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth; - localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight; - localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat; - localParameters.BackBufferCount = pPresentationParameters->BackBufferCount; - localParameters.MultiSampleType = pPresentationParameters->MultiSampleType; - localParameters.SwapEffect = pPresentationParameters->SwapEffect; - localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow; - localParameters.Windowed = pPresentationParameters->Windowed; - localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil; - localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat; - localParameters.Flags = pPresentationParameters->Flags; - localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz; - localParameters.FullScreen_PresentationInterval = pPresentationParameters->PresentationInterval; - - res = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)device, &localParameters, (IDirect3DSwapChain8 **)&d3dSwapChain); - - /* Copy back the presentation parameters */ - pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; - pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; - pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat; - pPresentationParameters->BackBufferCount = localParameters.BackBufferCount; - pPresentationParameters->MultiSampleType = localParameters.MultiSampleType; - pPresentationParameters->SwapEffect = localParameters.SwapEffect; - pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow; - pPresentationParameters->Windowed = localParameters.Windowed; - pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil; - pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat; - pPresentationParameters->Flags = localParameters.Flags; - pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz; - pPresentationParameters->PresentationInterval = localParameters.FullScreen_PresentationInterval; - - if (SUCCEEDED(res)) { - *ppSwapChain = d3dSwapChain->wineD3DSwapChain; - IUnknown_Release(d3dSwapChain->parentDevice); - d3dSwapChain->parentDevice = NULL; - } else { - *ppSwapChain = NULL; - } - - return res; -} - ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) { IUnknown* swapChainParent; TRACE("(%p) call back\n", pSwapChain); @@ -356,27 +279,6 @@ ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) { return IUnknown_Release(swapChainParent); } -/* Internal function called back during the CreateDevice to create a render target */ -HRESULT WINAPI D3D8CB_CreateDepthStencilSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height, - WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample, - DWORD MultisampleQuality, BOOL Discard, - IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) { - HRESULT res = D3D_OK; - IDirect3DSurface8Impl *d3dSurface = NULL; - TRACE("(%p) call back\n", device); - - res = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)device, Width, Height, - (D3DFORMAT)Format, MultiSample, (IDirect3DSurface8 **)&d3dSurface); - if (SUCCEEDED(res)) { - *ppSurface = d3dSurface->wineD3DSurface; - d3dSurface->container = device; - d3dSurface->isImplicit = TRUE; - /* Implicit surfaces are created with an refcount of 0 */ - IUnknown_Release((IUnknown *)d3dSurface); - } - return res; -} - ULONG WINAPI D3D8CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) { IDirect3DSurface8Impl* surfaceParent; TRACE("(%p) call back\n", pSurface); @@ -412,6 +314,7 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapte } object->lpVtbl = &Direct3DDevice8_Vtbl; + object->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl; object->ref = 1; object->shader_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INITIAL_SHADER_HANDLE_TABLE_SIZE * sizeof(shader_handle)); object->shader_handle_table_size = INITIAL_SHADER_HANDLE_TABLE_SIZE; @@ -419,7 +322,8 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapte /* Allocate an associated WineD3DDevice object */ EnterCriticalSection(&d3d8_cs); - hr =IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &object->WineD3DDevice, (IUnknown *)object); + hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, + (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice); if (hr != D3D_OK) { HeapFree(GetProcessHeap(), 0, object); @@ -450,7 +354,7 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapte IWineD3DDevice_SetMultithreaded(object->WineD3DDevice); } - hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters, D3D8CB_CreateAdditionalSwapChain); + hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters); LeaveCriticalSection(&d3d8_cs); pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; diff --git a/reactos/dll/directx/wine/d3d8/pixelshader.c b/reactos/dll/directx/wine/d3d8/pixelshader.c index 3ad39e6a439..5cfb0ca25a4 100644 --- a/reactos/dll/directx/wine/d3d8/pixelshader.c +++ b/reactos/dll/directx/wine/d3d8/pixelshader.c @@ -62,34 +62,10 @@ static ULONG WINAPI IDirect3DPixelShader8Impl_Release(IDirect3DPixelShader8 * if return ref; } -/* IDirect3DPixelShader8 Interface follow: */ -static HRESULT WINAPI IDirect3DPixelShader8Impl_GetDevice(IDirect3DPixelShader8 *iface, IDirect3DDevice8 **ppDevice) { - IDirect3DPixelShader8Impl *This = (IDirect3DPixelShader8Impl *)iface; - IWineD3DDevice *myDevice = NULL; - - TRACE("(%p) : Relay\n", This); - - IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice); - IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice); - IWineD3DDevice_Release(myDevice); - TRACE("(%p) returning (%p)\n", This, *ppDevice); - return D3D_OK; -} - -static HRESULT WINAPI IDirect3DPixelShader8Impl_GetFunction(IDirect3DPixelShader8 *iface, VOID *pData, UINT *pSizeOfData) { - IDirect3DPixelShader8Impl *This = (IDirect3DPixelShader8Impl *)iface; - TRACE("(%p) Relay\n", This); - return IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData); -} - - const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl = { /* IUnknown */ IDirect3DPixelShader8Impl_QueryInterface, IDirect3DPixelShader8Impl_AddRef, IDirect3DPixelShader8Impl_Release, - /* IDirect3DPixelShader8 */ - IDirect3DPixelShader8Impl_GetDevice, - IDirect3DPixelShader8Impl_GetFunction }; diff --git a/reactos/dll/directx/wine/d3d8/surface.c b/reactos/dll/directx/wine/d3d8/surface.c index 6ecd7af8c8f..0d06da26938 100644 --- a/reactos/dll/directx/wine/d3d8/surface.c +++ b/reactos/dll/directx/wine/d3d8/surface.c @@ -206,7 +206,11 @@ static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) EnterCriticalSection(&d3d8_cs); hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface); LeaveCriticalSection(&d3d8_cs); - return hr; + switch(hr) + { + case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL; + default: return hr; + } } const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl = diff --git a/reactos/dll/directx/wine/d3d8/vertexshader.c b/reactos/dll/directx/wine/d3d8/vertexshader.c index 16a809ebd17..8cd822b2744 100644 --- a/reactos/dll/directx/wine/d3d8/vertexshader.c +++ b/reactos/dll/directx/wine/d3d8/vertexshader.c @@ -57,45 +57,16 @@ static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *i if (ref == 0) { IDirect3DVertexDeclaration8_Release(This->vertex_declaration); - IWineD3DVertexShader_Release(This->wineD3DVertexShader); + if (This->wineD3DVertexShader) IWineD3DVertexShader_Release(This->wineD3DVertexShader); HeapFree(GetProcessHeap(), 0, This); } return ref; } -/* IDirect3DVertexShader8 Interface follow: */ -static HRESULT WINAPI IDirect3DVertexShader8Impl_GetDevice(IDirect3DVertexShader8 *iface, IDirect3DDevice8** ppDevice) { - IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface; - IWineD3DDevice *myDevice = NULL; - HRESULT hr; - TRACE("(%p) : Relay\n", This); - - hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice); - if (WINED3D_OK == hr && myDevice != NULL) { - hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice); - IWineD3DDevice_Release(myDevice); - } else { - *ppDevice = NULL; - } - TRACE("(%p) returning (%p)\n", This, *ppDevice); - return hr; -} - -static HRESULT WINAPI IDirect3DVertexShader8Impl_GetFunction(IDirect3DVertexShader8 *iface, VOID* pData, UINT* pSizeOfData) { - IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface; - - TRACE("(%p) : Relay\n", This); - return IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData); -} - - const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl = { /* IUnknown */ IDirect3DVertexShader8Impl_QueryInterface, IDirect3DVertexShader8Impl_AddRef, IDirect3DVertexShader8Impl_Release, - /* IDirect3DVertexShader8 */ - IDirect3DVertexShader8Impl_GetDevice, - IDirect3DVertexShader8Impl_GetFunction }; diff --git a/reactos/dll/directx/wine/d3d8/volume.c b/reactos/dll/directx/wine/d3d8/volume.c index e37817aceae..87c4172e905 100644 --- a/reactos/dll/directx/wine/d3d8/volume.c +++ b/reactos/dll/directx/wine/d3d8/volume.c @@ -192,7 +192,7 @@ static HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) { return hr; } -static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl = +const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl = { /* IUnknown */ IDirect3DVolume8Impl_QueryInterface, @@ -209,42 +209,6 @@ static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl = IDirect3DVolume8Impl_UnlockBox }; - -/* Internal function called back during the CreateVolumeTexture */ -HRESULT WINAPI D3D8CB_CreateVolume(IUnknown *pDevice, IUnknown *pSuperior, UINT Width, UINT Height, UINT Depth, - WINED3DFORMAT Format, WINED3DPOOL Pool, DWORD Usage, - IWineD3DVolume **ppVolume, - HANDLE * pSharedHandle) { - IDirect3DVolume8Impl *object; - IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)pDevice; - HRESULT hrc = D3D_OK; - - /* Allocate the storage for the device */ - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume8Impl)); - if (NULL == object) { - FIXME("Allocation of memory failed\n"); - *ppVolume = NULL; - return D3DERR_OUTOFVIDEOMEMORY; - } - - object->lpVtbl = &Direct3DVolume8_Vtbl; - object->ref = 1; - hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format, - Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object); - if (hrc != D3D_OK) { - /* free up object */ - FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This); - HeapFree(GetProcessHeap(), 0, object); - *ppVolume = NULL; - } else { - *ppVolume = object->wineD3DVolume; - object->container = pSuperior; - object->forwardReference = pSuperior; - } - TRACE("(%p) Created volume %p\n", This, *ppVolume); - return hrc; -} - ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume) { IDirect3DVolume8Impl* volumeParent;