Commit 584cb331 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Add a separate function for execute buffer initialization.

parent a60c4939
...@@ -614,8 +614,8 @@ struct IDirect3DExecuteBufferImpl ...@@ -614,8 +614,8 @@ struct IDirect3DExecuteBufferImpl
BOOL need_free; BOOL need_free;
}; };
/* The VTable */ HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
extern const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl DECLSPEC_HIDDEN; IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc) DECLSPEC_HIDDEN;
/* The execute function */ /* The execute function */
void IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This, void IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
......
...@@ -712,6 +712,8 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface, ...@@ -712,6 +712,8 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
{ {
IDirect3DDeviceImpl *This = device_from_device1(iface); IDirect3DDeviceImpl *This = device_from_device1(iface);
IDirect3DExecuteBufferImpl* object; IDirect3DExecuteBufferImpl* object;
HRESULT hr;
TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter); TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
if(UnkOuter) if(UnkOuter)
...@@ -725,46 +727,14 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface, ...@@ -725,46 +727,14 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
return DDERR_OUTOFMEMORY; return DDERR_OUTOFMEMORY;
} }
object->lpVtbl = &IDirect3DExecuteBuffer_Vtbl; hr = d3d_execute_buffer_init(object, This, Desc);
object->ref = 1; if (FAILED(hr))
object->d3ddev = This;
/* Initializes memory */
memcpy(&object->desc, Desc, Desc->dwSize);
/* No buffer given */
if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
object->desc.lpData = NULL;
/* No buffer size given */
if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
object->desc.dwBufferSize = 0;
/* Create buffer if asked */
if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
{
object->need_free = TRUE;
object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
if(!object->desc.lpData)
{
ERR("Out of memory when allocating the execute buffer data\n");
HeapFree(GetProcessHeap(), 0, object);
return DDERR_OUTOFMEMORY;
}
}
else
{ {
object->need_free = FALSE; WARN("Failed to initialize execute buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
} }
/* No vertices for the moment */
object->vertex_data = NULL;
object->desc.dwFlags |= D3DDEB_LPDATA;
object->indices = NULL;
object->nb_indices = 0;
*ExecuteBuffer = (IDirect3DExecuteBuffer *)object; *ExecuteBuffer = (IDirect3DExecuteBuffer *)object;
TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object); TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
......
...@@ -825,7 +825,7 @@ IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface, ...@@ -825,7 +825,7 @@ IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface,
return DDERR_UNSUPPORTED; /* Unchecked */ return DDERR_UNSUPPORTED; /* Unchecked */
} }
const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl = static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
{ {
IDirect3DExecuteBufferImpl_QueryInterface, IDirect3DExecuteBufferImpl_QueryInterface,
IDirect3DExecuteBufferImpl_AddRef, IDirect3DExecuteBufferImpl_AddRef,
...@@ -838,3 +838,38 @@ const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl = ...@@ -838,3 +838,38 @@ const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl =
IDirect3DExecuteBufferImpl_Validate, IDirect3DExecuteBufferImpl_Validate,
IDirect3DExecuteBufferImpl_Optimize, IDirect3DExecuteBufferImpl_Optimize,
}; };
HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
{
execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl;
execute_buffer->ref = 1;
execute_buffer->d3ddev = device;
/* Initializes memory */
memcpy(&execute_buffer->desc, desc, desc->dwSize);
/* No buffer given */
if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
execute_buffer->desc.lpData = NULL;
/* No buffer size given */
if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
execute_buffer->desc.dwBufferSize = 0;
/* Create buffer if asked */
if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
{
execute_buffer->need_free = TRUE;
execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
if (!execute_buffer->desc.lpData)
{
ERR("Failed to allocate execute buffer data.\n");
return DDERR_OUTOFMEMORY;
}
}
execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
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