Commit d010dac8 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

ddraw: Rename d3d_vertex_buffer_init() and have it allocate the object too.

parent b02457a1
......@@ -4952,32 +4952,16 @@ static HRESULT WINAPI d3d7_CreateVertexBuffer(IDirect3D7 *iface, D3DVERTEXBUFFER
if (!vertex_buffer || !desc) return DDERR_INVALIDPARAMS;
TRACE("Vertex buffer description:\n");
TRACE(" dwSize %u\n", desc->dwSize);
TRACE(" dwCaps %#x\n", desc->dwCaps);
TRACE(" FVF %#x\n", desc->dwFVF);
TRACE(" dwNumVertices %u\n", desc->dwNumVertices);
/* Now create the vertex buffer */
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
ERR("Failed to allocate vertex buffer memory.\n");
return DDERR_OUTOFMEMORY;
}
hr = d3d_vertex_buffer_init(object, This, desc);
if (FAILED(hr))
hr = d3d_vertex_buffer_create(&object, This, desc);
if (hr == D3D_OK)
{
WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
TRACE("Created vertex buffer %p.\n", object);
*vertex_buffer = (IDirect3DVertexBuffer7 *)object;
}
else
WARN("Failed to create vertex buffer, hr %#x.\n", hr);
TRACE("Created vertex buffer %p.\n", object);
*vertex_buffer = (IDirect3DVertexBuffer7 *)object;
return D3D_OK;
return hr;
}
static HRESULT WINAPI d3d3_CreateVertexBuffer(IDirect3D3 *iface, D3DVERTEXBUFFERDESC *desc,
......
......@@ -534,8 +534,8 @@ struct IDirect3DVertexBufferImpl
DWORD fvf;
};
HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN;
HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirectDrawImpl *ddraw,
D3DVERTEXBUFFERDESC *desc) DECLSPEC_HIDDEN;
static inline IDirect3DVertexBufferImpl *vb_from_vb1(IDirect3DVertexBuffer *iface)
{
......
......@@ -526,11 +526,22 @@ static const struct IDirect3DVertexBufferVtbl d3d_vertex_buffer1_vtbl =
IDirect3DVertexBufferImpl_1_Optimize
};
HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
IDirectDrawImpl *ddraw, D3DVERTEXBUFFERDESC *desc)
HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirectDrawImpl *ddraw,
D3DVERTEXBUFFERDESC *desc)
{
IDirect3DVertexBufferImpl *buffer;
DWORD usage;
HRESULT hr;
HRESULT hr = D3D_OK;
TRACE("Vertex buffer description:\n");
TRACE(" dwSize %u\n", desc->dwSize);
TRACE(" dwCaps %#x\n", desc->dwCaps);
TRACE(" FVF %#x\n", desc->dwFVF);
TRACE(" dwNumVertices %u\n", desc->dwNumVertices);
buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*buffer));
if (!buffer)
return DDERR_OUTOFMEMORY;
buffer->lpVtbl = &d3d_vertex_buffer7_vtbl;
buffer->IDirect3DVertexBuffer_vtbl = &d3d_vertex_buffer1_vtbl;
......@@ -552,12 +563,9 @@ HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
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;
hr = DDERR_INVALIDPARAMS;
goto end;
}
buffer->wineD3DVertexDeclaration = ddraw_find_decl(ddraw, desc->dwFVF);
......@@ -565,13 +573,17 @@ HRESULT d3d_vertex_buffer_init(IDirect3DVertexBufferImpl *buffer,
{
ERR("Failed to find vertex declaration for fvf %#x.\n", desc->dwFVF);
wined3d_buffer_decref(buffer->wineD3DVertexBuffer);
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
hr = DDERR_INVALIDPARAMS;
goto end;
}
wined3d_vertex_declaration_incref(buffer->wineD3DVertexDeclaration);
end:
LeaveCriticalSection(&ddraw_cs);
if (hr == D3D_OK)
*vertex_buf = buffer;
else
HeapFree(GetProcessHeap(), 0, buffer);
return D3D_OK;
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