From 1226e72bf719c664b5fd14c666af609ee3f54cb6 Mon Sep 17 00:00:00 2001 From: Raphael Junqueira Date: Fri, 28 Jan 2005 14:03:32 +0000 Subject: [PATCH] - add vertex Declaration support (using wined3d) - minimal impl for SetRenderTarget and CreateQuery (needed to get some samples working) - remove no longer needed #undef GL_VERSION_1_4 --- dlls/d3d9/d3d9_private.h | 10 +---- dlls/d3d9/device.c | 40 +++++++++++++++----- dlls/d3d9/directx.c | 9 ++++- dlls/d3d9/query.c | 35 ++++++++++++++++-- dlls/d3d9/texture.c | 2 +- dlls/d3d9/vertexdeclaration.c | 70 +++++++++++++++++++++++++++++------ 6 files changed, 131 insertions(+), 35 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 99d45ae184f..1d71bcbeca4 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -1000,15 +1000,7 @@ struct IDirect3DVertexDeclaration9Impl { DWORD ref; /* IDirect3DVertexDeclaration9 fields */ - IDirect3DDevice9Impl* Device; - - /** precomputed fvf if simple declaration */ - DWORD fvf[MAX_STREAMS]; - DWORD allFVF; - - /** dx8 compatible Declaration fields */ - DWORD* pDeclaration8; - DWORD declaration8Length; + IWineD3DVertexDeclaration *wineD3DVertexDeclaration; }; /* IUnknown: */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index f7a58f9d589..aed23e3f6e8 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1,7 +1,7 @@ /* * IDirect3DDevice9 implementation * - * Copyright 2002-2003 Jason Edmeades + * Copyright 2002-2005 Jason Edmeades * Raphael Junqueira * * This library is free software; you can redistribute it and/or @@ -22,9 +22,6 @@ #include "config.h" #include "d3d9_private.h" -/** currently desactiving 1_4 support as mesa doesn't implement all 1_4 support while defining it */ -#undef GL_VERSION_1_4 - WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DECLARE_DEBUG_CHANNEL(d3d_shader); @@ -319,25 +316,50 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVI HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; + HRESULT hr = S_OK; + + /* If pRenderTarget == NULL, it seems to default to back buffer */ + if (pRenderTarget == NULL) pRenderTarget = (IDirect3DSurface9*) This->backBuffer; + + /* If we are trying to set what we already have, don't bother */ + if ((IDirect3DSurface9Impl*) pRenderTarget == This->renderTarget) { + TRACE("Trying to do a NOP SetRenderTarget operation\n"); + } else { + /* Otherwise, set the render target up */ + TRACE("(%p) : newRender@%p (default is backbuffer=(%p))\n", This, pRenderTarget, This->backBuffer); + hr = E_FAIL; /* not supported yet */ + } + + return hr; } HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); + TRACE("(%p)->returning (%p) default is backbuffer=(%p)\n", This, This->renderTarget, This->backBuffer); + *ppRenderTarget = (LPDIRECT3DSURFACE9) This->renderTarget; + IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) *ppRenderTarget); return D3D_OK; } HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pZStencilSurface) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); + HRESULT hr = S_OK; + /* If we are trying to set what we already have, don't bother */ + if ((IDirect3DSurface9Impl*) pZStencilSurface == This->stencilBufferTarget) { + TRACE("Trying to do a NOP SetDepthStencilSurface operation\n"); + } else { + /* Otherwise, set the target up */ + TRACE("(%p) : newDepthStencil@%p (default is stencilbuffer=(%p))\n", This, pZStencilSurface, This->depthStencilBuffer); + hr = E_FAIL; /* not supported yet */ + } return D3D_OK; } HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9** ppZStencilSurface) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); + TRACE("(%p)->returning (%p) default is stencilbuffer=(%p)\n", This, This->stencilBufferTarget, This->depthStencilBuffer); + *ppZStencilSurface = (LPDIRECT3DSURFACE9) This->stencilBufferTarget; + IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) *ppZStencilSurface); return D3D_OK; } diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c index cc2aad87738..2548d541b3b 100644 --- a/dlls/d3d9/directx.c +++ b/dlls/d3d9/directx.c @@ -164,12 +164,19 @@ HRESULT WINAPI D3D9CB_CreateRenderTarget(IUnknown *device, UINT Width, UINT Heig IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) { HRESULT res = D3D_OK; IDirect3DSurface9Impl *d3dSurface = NULL; + IDirect3DDevice9Impl* pDeviceImpl = (IDirect3DDevice9Impl*) device; res = IDirect3DDevice9_CreateRenderTarget((IDirect3DDevice9 *)device, Width, Height, Format, MultiSample, MultisampleQuality, Lockable, (IDirect3DSurface9 **)&d3dSurface, pSharedHandle); - if (res == D3D_OK) { + + if (SUCCEEDED(res)) { *ppSurface = d3dSurface->wineD3DSurface; + if (NULL == pDeviceImpl->backBuffer) { + pDeviceImpl->backBuffer = d3dSurface; + pDeviceImpl->renderTarget = d3dSurface; + IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) pDeviceImpl->renderTarget); + } } else { *ppSurface = NULL; } diff --git a/dlls/d3d9/query.c b/dlls/d3d9/query.c index 3ef67c8500a..8b8f12d9058 100644 --- a/dlls/d3d9/query.c +++ b/dlls/d3d9/query.c @@ -109,7 +109,36 @@ IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl = /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */ HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9 iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; +#if 0 + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; +#endif + IDirect3DQuery9Impl *object = NULL; + HRESULT hr = D3D_OK; + + if (NULL == ppQuery) { + return D3DERR_INVALIDCALL; + } + /* Allocate the storage for the device */ + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl)); + if (NULL == object) { + FIXME("Allocation of memory failed\n"); + *ppQuery = NULL; + return D3DERR_OUTOFVIDEOMEMORY; + } + + object->lpVtbl = &Direct3DQuery9_Vtbl; + object->ref = 1; +#if 0 + hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, 9, pVertexElements, &(object->wineD3DQuery)); + + if (FAILED(hr)) { + /* free up object */ + FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This); + HeapFree(GetProcessHeap(), 0, object); + *ppQuery = NULL; + } else { + *ppQuery = (LPDIRECT3DQUERY9) object; + } +#endif + return hr; } diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c index 87f18ff24c4..a605d9d47b2 100644 --- a/dlls/d3d9/texture.c +++ b/dlls/d3d9/texture.c @@ -232,7 +232,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9 iface, UIN hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage, Format, Pool, &(object->wineD3DTexture), pSharedHandle, (IUnknown *)object, D3D9CB_CreateSurface); - if (hrc != D3D_OK) { + if (FAILED(hrc)) { /* free up object */ FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This); HeapFree(GetProcessHeap(), 0, object); diff --git a/dlls/d3d9/vertexdeclaration.c b/dlls/d3d9/vertexdeclaration.c index 0cab3cb5934..e5b253fe786 100644 --- a/dlls/d3d9/vertexdeclaration.c +++ b/dlls/d3d9/vertexdeclaration.c @@ -55,6 +55,7 @@ ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECLARATION TRACE("(%p) : ReleaseRef to %ld\n", This, ref); if (ref == 0) { + IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration); HeapFree(GetProcessHeap(), 0, This); } return ref; @@ -63,16 +64,16 @@ ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECLARATION /* IDirect3DVertexDeclaration9 Interface follow: */ HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDevice(LPDIRECT3DVERTEXDECLARATION9 iface, IDirect3DDevice9** ppDevice) { IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface; - TRACE("(%p) : returning %p\n", This, This->Device); - *ppDevice = (LPDIRECT3DDEVICE9) This->Device; - IDirect3DDevice9Impl_AddRef(*ppDevice); + IWineD3DDevice *myDevice = NULL; + IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice); + IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice); + IWineD3DDevice_Release(myDevice); return D3D_OK; } HRESULT WINAPI IDirect3DVertexDeclaration9Impl_GetDeclaration(LPDIRECT3DVERTEXDECLARATION9 iface, D3DVERTEXELEMENT9* pDecl, UINT* pNumElements) { IDirect3DVertexDeclaration9Impl *This = (IDirect3DVertexDeclaration9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; + return IWineD3DVertexDeclaration_GetDeclaration(This->wineD3DVertexDeclaration, 9, pDecl, (DWORD*) pNumElements); } @@ -89,18 +90,63 @@ IDirect3DVertexDeclaration9Vtbl Direct3DVertexDeclaration9_Vtbl = /* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9 iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; + IDirect3DVertexDeclaration9Impl *object = NULL; + HRESULT hr = D3D_OK; + + if (NULL == ppDecl) { + return D3DERR_INVALIDCALL; + } + /* Allocate the storage for the device */ + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl)); + if (NULL == object) { + FIXME("Allocation of memory failed\n"); + *ppDecl = NULL; + return D3DERR_OUTOFVIDEOMEMORY; + } + + object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl; + object->ref = 1; + hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, 9, pVertexElements, &(object->wineD3DVertexDeclaration)); + + if (FAILED(hr)) { + /* free up object */ + FIXME("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This); + HeapFree(GetProcessHeap(), 0, object); + *ppDecl = NULL; + } else { + *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object; + } + return hr; } HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9* pDecl) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; + IDirect3DVertexDeclaration9Impl *pDeclImpl = (IDirect3DVertexDeclaration9Impl *)pDecl; + HRESULT hr = S_OK; + + This->UpdateStateBlock->vertexDecl = NULL; + if (NULL != pDecl) { + hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl->wineD3DVertexDeclaration); + if (SUCCEEDED(hr)) { + This->UpdateStateBlock->vertexDecl = (IDirect3DVertexDeclaration9Impl*) pDecl; + } + } + return hr; } HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9 iface, IDirect3DVertexDeclaration9** ppDecl) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - FIXME("(%p) : stub\n", This); - return D3D_OK; + IDirect3DDevice9Impl* This = (IDirect3DDevice9Impl*) iface; + IWineD3DVertexDeclaration* pTest = NULL; + HRESULT hr = S_OK; + IDirect3DVertexDeclaration9Impl* pCur = This->StateBlock->vertexDecl; + + if (NULL == ppDecl) { + return D3DERR_INVALIDCALL; + } + *ppDecl = NULL; + hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest); + if (SUCCEEDED(hr) && (NULL == pCur || pCur->wineD3DVertexDeclaration == pTest)) { + *ppDecl = (IDirect3DVertexDeclaration9*) pCur; + } + return hr; }