Commit c0cefb35 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d8: Cleanup the vertexshader handling code a bit.

parent 4131135a
......@@ -1879,75 +1879,78 @@ static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DD
static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
HRESULT hrc = D3D_OK;
IDirect3DVertexShader8Impl *shader;
HRESULT hr;
TRACE("(%p) : Relay\n", This);
EnterCriticalSection(&d3d8_cs);
if (VS_HIGHESTFIXEDFXF >= pShader) {
TRACE("Setting FVF, %#x\n", pShader);
EnterCriticalSection(&d3d8_cs);
IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
} else {
IDirect3DVertexShader8Impl *shader;
LeaveCriticalSection(&d3d8_cs);
return D3D_OK;
}
TRACE("Setting shader\n");
TRACE("Setting shader\n");
shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
if (!shader)
{
WARN("Invalid handle (%#x) passed.\n", pShader);
hrc = D3DERR_INVALIDCALL;
}
else
{
hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
if (SUCCEEDED(hrc))
hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
}
EnterCriticalSection(&d3d8_cs);
shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
if (!shader)
{
WARN("Invalid handle (%#x) passed.\n", pShader);
LeaveCriticalSection(&d3d8_cs);
return D3DERR_INVALIDCALL;
}
TRACE("(%p) : returning hr(%u)\n", This, hrc);
hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
LeaveCriticalSection(&d3d8_cs);
return hrc;
TRACE("Returning hr %#x\n", hr);
return hr;
}
static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
IWineD3DVertexDeclaration *wined3d_declaration;
IDirect3DVertexDeclaration8 *d3d8_declaration;
HRESULT hrc;
TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
EnterCriticalSection(&d3d8_cs);
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
if (FAILED(hrc))
{
LeaveCriticalSection(&d3d8_cs);
WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
This, hrc, This->WineD3DDevice);
return hrc;
}
TRACE("(%p) : returning %#x\n", This, *ppShader);
if (!wined3d_declaration)
{
LeaveCriticalSection(&d3d8_cs);
*ppShader = 0;
return D3D_OK;
}
hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
IWineD3DVertexDeclaration_Release(wined3d_declaration);
LeaveCriticalSection(&d3d8_cs);
if (SUCCEEDED(hrc))
{
*ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
IDirect3DVertexDeclaration8_Release(d3d8_declaration);
}
TRACE("(%p) : returning %#x\n", This, *ppShader);
return hrc;
}
......@@ -1955,6 +1958,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 ifa
static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
IDirect3DVertexShader8Impl *shader;
IWineD3DVertexShader *cur = NULL;
TRACE("(%p) : pShader %#x\n", This, pShader);
......@@ -1966,22 +1970,23 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE
WARN("Invalid handle (%#x) passed.\n", pShader);
LeaveCriticalSection(&d3d8_cs);
return D3DERR_INVALIDCALL;
} else {
IWineD3DVertexShader *cur = NULL;
}
IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
if(cur) {
if(cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
IWineD3DVertexShader_Release(cur);
}
IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
if (IUnknown_Release((IUnknown *)shader))
{
ERR("Shader %p has references left, this shouldn't happen.\n", shader);
}
if (cur)
{
if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
IWineD3DVertexShader_Release(cur);
}
LeaveCriticalSection(&d3d8_cs);
if (IUnknown_Release((IUnknown *)shader))
{
ERR("Shader %p has references left, this shouldn't happen.\n", shader);
}
return D3D_OK;
}
......@@ -2060,16 +2065,15 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEV
return D3DERR_INVALIDCALL;
}
if (shader->wineD3DVertexShader)
{
hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
}
else
if (!shader->wineD3DVertexShader)
{
LeaveCriticalSection(&d3d8_cs);
*pSizeOfData = 0;
hr = D3D_OK;
return D3D_OK;
}
hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
LeaveCriticalSection(&d3d8_cs);
return hr;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment