Commit 717419da authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d8: Add a separate function for pixel shader initialization.

parent 7f1c802b
......@@ -603,17 +603,6 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im
#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
/* ------------------------ */
/* IDirect3DPixelShaderImpl */
/* ------------------------ */
/*****************************************************************************
* Predeclare the interface implementation structures
*/
extern const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl DECLSPEC_HIDDEN;
/*****************************************************************************
* IDirect3DPixelShader implementation structure
*/
......@@ -625,6 +614,9 @@ typedef struct IDirect3DPixelShader8Impl {
IWineD3DPixelShader *wineD3DPixelShader;
} IDirect3DPixelShader8Impl;
HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
/**
* Internals functions
*
......
......@@ -2094,15 +2094,20 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, I
return rc;
}
static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
const DWORD *byte_code, DWORD *shader)
{
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
IDirect3DPixelShader8Impl *object;
DWORD shader_handle;
DWORD handle;
HRESULT hr;
TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
if (NULL == ppShader) {
if (!shader)
{
TRACE("(%p) Invalid call\n", This);
return D3DERR_INVALIDCALL;
}
......@@ -2110,39 +2115,38 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 i
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
ERR("Failed to allocate memmory.\n");
ERR("Failed to allocate pixel shader memmory.\n");
return E_OUTOFMEMORY;
}
object->ref = 1;
object->lpVtbl = &Direct3DPixelShader8_Vtbl;
wined3d_mutex_lock();
hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
NULL, &object->wineD3DPixelShader, (IUnknown *)object);
if (FAILED(hr))
{
wined3d_mutex_unlock();
FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
HeapFree(GetProcessHeap(), 0 , object);
*ppShader = 0;
return hr;
}
handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
wined3d_mutex_unlock();
if (handle == D3D8_INVALID_HANDLE)
{
ERR("Failed to allocate shader handle\n");
IDirect3DVertexShader8_Release((IUnknown *)object);
ERR("Failed to allocate pixel shader handle.\n");
HeapFree(GetProcessHeap(), 0, object);
return E_OUTOFMEMORY;
}
*ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
return hr;
hr = pixelshader_init(object, This, byte_code, shader_handle);
if (FAILED(hr))
{
WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
wined3d_mutex_lock();
d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, object);
*shader = 0;
return hr;
}
TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
*shader = shader_handle;
return D3D_OK;
}
static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
......
......@@ -65,10 +65,32 @@ static ULONG WINAPI IDirect3DPixelShader8Impl_Release(IDirect3DPixelShader8 * if
return ref;
}
const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
static const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
{
/* IUnknown */
IDirect3DPixelShader8Impl_QueryInterface,
IDirect3DPixelShader8Impl_AddRef,
IDirect3DPixelShader8Impl_Release,
};
HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
const DWORD *byte_code, DWORD shader_handle)
{
HRESULT hr;
shader->ref = 1;
shader->lpVtbl = &Direct3DPixelShader8_Vtbl;
shader->handle = shader_handle;
wined3d_mutex_lock();
hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
NULL, &shader->wineD3DPixelShader, (IUnknown *)shader);
wined3d_mutex_unlock();
if (FAILED(hr))
{
WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
return hr;
}
return D3D_OK;
}
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