d3d8: Add a separate function for vertex declaration initialization.
This commit is contained in:
parent
0241fefa94
commit
f394dfc0f8
|
@ -544,6 +544,8 @@ typedef struct {
|
|||
DWORD shader_handle;
|
||||
} IDirect3DVertexDeclaration8Impl;
|
||||
|
||||
HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
|
||||
IDirect3DDevice8Impl *device, const DWORD *elements) DECLSPEC_HIDDEN;
|
||||
|
||||
/*****************************************************************************
|
||||
* IDirect3DVertexShader8 interface
|
||||
|
|
|
@ -1719,9 +1719,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 ifa
|
|||
static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
|
||||
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
|
||||
IDirect3DVertexDeclaration8Impl *object;
|
||||
WINED3DVERTEXELEMENT *wined3d_elements;
|
||||
UINT wined3d_element_count;
|
||||
HRESULT hr = D3D_OK;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("(%p) : declaration %p\n", This, declaration);
|
||||
|
||||
|
@ -1732,40 +1730,20 @@ static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *if
|
|||
return D3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
object->ref_count = 1;
|
||||
object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
|
||||
|
||||
wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
|
||||
object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
|
||||
if (!object->elements) {
|
||||
ERR("Memory allocation failed\n");
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
||||
hr = vertexdeclaration_init(object, This, declaration);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
|
||||
HeapFree(GetProcessHeap(), 0, object);
|
||||
*decl_ptr = NULL;
|
||||
return D3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
CopyMemory(object->elements, declaration, object->elements_size);
|
||||
|
||||
wined3d_mutex_lock();
|
||||
hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
|
||||
(IUnknown *)object, wined3d_elements, wined3d_element_count);
|
||||
wined3d_mutex_unlock();
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
|
||||
HeapFree(GetProcessHeap(), 0, object->elements);
|
||||
HeapFree(GetProcessHeap(), 0, object);
|
||||
} else {
|
||||
*decl_ptr = (IDirect3DVertexDeclaration8 *)object;
|
||||
TRACE("(%p) : Created vertex declaration %p\n", This, object);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
TRACE("Created vertex declaration %p.\n", object);
|
||||
*decl_ptr = (IDirect3DVertexDeclaration8 *)object;
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
|
||||
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
|
||||
HRESULT hrc = D3D_OK;
|
||||
|
|
|
@ -358,3 +358,39 @@ const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
|
|||
IDirect3DVertexDeclaration8Impl_AddRef,
|
||||
IDirect3DVertexDeclaration8Impl_Release
|
||||
};
|
||||
|
||||
HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
|
||||
IDirect3DDevice8Impl *device, const DWORD *elements)
|
||||
{
|
||||
WINED3DVERTEXELEMENT *wined3d_elements;
|
||||
UINT wined3d_element_count;
|
||||
HRESULT hr;
|
||||
|
||||
declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
|
||||
declaration->ref_count = 1;
|
||||
|
||||
wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
|
||||
declaration->elements = HeapAlloc(GetProcessHeap(), 0, declaration->elements_size);
|
||||
if (!declaration->elements)
|
||||
{
|
||||
ERR("Failed to allocate vertex declaration elements memory.\n");
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
memcpy(declaration->elements, elements, declaration->elements_size);
|
||||
|
||||
wined3d_mutex_lock();
|
||||
hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wined3d_vertex_declaration,
|
||||
(IUnknown *)declaration, wined3d_elements, wined3d_element_count);
|
||||
wined3d_mutex_unlock();
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
||||
HeapFree(GetProcessHeap(), 0, declaration->elements);
|
||||
return hr;
|
||||
}
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue