Commit 0e955dae authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Add a separate function for vertex buffer initialization.

parent e2021722
......@@ -4739,9 +4739,7 @@ static HRESULT WINAPI d3d2_CreateDevice(IDirect3D2 *iface, REFCLSID riid,
static HRESULT WINAPI d3d7_CreateVertexBuffer(IDirect3D7 *iface, D3DVERTEXBUFFERDESC *desc,
IDirect3DVertexBuffer7 **vertex_buffer, DWORD flags)
{
IDirectDrawImpl *ddraw = ddraw_from_d3d7(iface);
IDirect3DVertexBufferImpl *object;
DWORD usage;
HRESULT hr;
TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
......@@ -4763,49 +4761,17 @@ static HRESULT WINAPI d3d7_CreateVertexBuffer(IDirect3D7 *iface, D3DVERTEXBUFFER
return DDERR_OUTOFMEMORY;
}
object->ref = 1;
object->lpVtbl = &IDirect3DVertexBuffer7_Vtbl;
object->IDirect3DVertexBuffer_vtbl = &IDirect3DVertexBuffer1_Vtbl;
object->ddraw = ddraw;
object->Caps = desc->dwCaps;
object->fvf = desc->dwFVF;
usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0;
usage |= WINED3DUSAGE_STATICDECL;
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DDevice_CreateVertexBuffer(ddraw->wineD3DDevice,
get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices,
usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
&object->wineD3DVertexBuffer, (IUnknown *)object, &ddraw_null_wined3d_parent_ops);
hr = d3d_vertex_buffer_init(object, ddraw_from_d3d7(iface), desc);
if (FAILED(hr))
{
WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
LeaveCriticalSection(&ddraw_cs);
if (hr == WINED3DERR_INVALIDCALL)
return DDERR_INVALIDPARAMS;
else
return hr;
}
object->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF);
if (!object->wineD3DVertexDeclaration)
{
ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
IWineD3DBuffer_Release(object->wineD3DVertexBuffer);
WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
return hr;
}
IWineD3DVertexDeclaration_AddRef(object->wineD3DVertexDeclaration);
TRACE("Created vertex buffer %p.\n", object);
*vertex_buffer = (IDirect3DVertexBuffer7 *)object;
LeaveCriticalSection(&ddraw_cs);
return D3D_OK;
}
......
......@@ -643,9 +643,8 @@ struct IDirect3DVertexBufferImpl
DWORD fvf;
};
/* The Vtables */
extern const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl DECLSPEC_HIDDEN;
extern const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl DECLSPEC_HIDDEN;
HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN;
static inline IDirect3DVertexBufferImpl *vb_from_vb1(IDirect3DVertexBuffer *iface)
{
......
......@@ -553,7 +553,7 @@ IDirect3DVertexBufferImpl_ProcessVerticesStrided(IDirect3DVertexBuffer7 *iface,
* The VTables
*****************************************************************************/
const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl =
static const struct IDirect3DVertexBuffer7Vtbl d3d_vertex_buffer7_vtbl =
{
/*** IUnknown Methods ***/
IDirect3DVertexBufferImpl_QueryInterface,
......@@ -569,7 +569,7 @@ const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl =
IDirect3DVertexBufferImpl_ProcessVerticesStrided
};
const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl =
static const struct IDirect3DVertexBufferVtbl d3d_vertex_buffer1_vtbl =
{
/*** IUnknown Methods ***/
Thunk_IDirect3DVertexBufferImpl_1_QueryInterface,
......@@ -582,3 +582,53 @@ const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl =
Thunk_IDirect3DVertexBufferImpl_1_GetVertexBufferDesc,
Thunk_IDirect3DVertexBufferImpl_1_Optimize
};
HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc)
{
DWORD usage;
HRESULT hr;
buffer->lpVtbl = &d3d_vertex_buffer7_vtbl;
buffer->IDirect3DVertexBuffer_vtbl = &d3d_vertex_buffer1_vtbl;
buffer->ref = 1;
buffer->ddraw = ddraw;
buffer->Caps = desc->dwCaps;
buffer->fvf = desc->dwFVF;
usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0;
usage |= WINED3DUSAGE_STATICDECL;
EnterCriticalSection(&ddraw_cs);
hr = IWineD3DDevice_CreateVertexBuffer(ddraw->wineD3DDevice,
get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices,
usage, desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
&buffer->wineD3DVertexBuffer, (IUnknown *)buffer, &ddraw_null_wined3d_parent_ops);
if (FAILED(hr))
{
WARN("Failed to create wined3d vertex buffer, hr %#x.\n", hr);
LeaveCriticalSection(&ddraw_cs);
if (hr == WINED3DERR_INVALIDCALL)
return DDERR_INVALIDPARAMS;
else
return hr;
}
buffer->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF);
if (!buffer->wineD3DVertexDeclaration)
{
ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
IWineD3DBuffer_Release(buffer->wineD3DVertexBuffer);
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
}
IWineD3DVertexDeclaration_AddRef(buffer->wineD3DVertexDeclaration);
LeaveCriticalSection(&ddraw_cs);
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