From: Henri Verbeet Date: Wed, 23 Sep 2009 08:05:50 +0000 (+0200) Subject: d3d8: Add a separate function for vertex declaration initialization. X-Git-Tag: wine-1.1.30~125 X-Git-Url: http://git.etersoft.ru/projects/?a=commitdiff_plain;h=f394dfc0f88efb9482210cc572d00e2724aa4443;p=wine%2Feterwine.git d3d8: Add a separate function for vertex declaration initialization. --- diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index 86b936a0a1..46cea98102 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -544,6 +544,8 @@ typedef struct { DWORD shader_handle; } IDirect3DVertexDeclaration8Impl; +HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration, + IDirect3DDevice8Impl *device, const DWORD *elements) DECLSPEC_HIDDEN; /***************************************************************************** * IDirect3DVertexShader8 interface diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 688ea0d6b4..80dc2491ed 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -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,38 +1730,18 @@ 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; + return hr; } - CopyMemory(object->elements, declaration, object->elements_size); + TRACE("Created vertex declaration %p.\n", object); + *decl_ptr = (IDirect3DVertexDeclaration8 *)object; - 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; + return D3D_OK; } static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) { diff --git a/dlls/d3d8/vertexdeclaration.c b/dlls/d3d8/vertexdeclaration.c index 2eea098a4e..2291daabe7 100644 --- a/dlls/d3d8/vertexdeclaration.c +++ b/dlls/d3d8/vertexdeclaration.c @@ -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; +}