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;
|
DWORD shader_handle;
|
||||||
} IDirect3DVertexDeclaration8Impl;
|
} IDirect3DVertexDeclaration8Impl;
|
||||||
|
|
||||||
|
HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
|
||||||
|
IDirect3DDevice8Impl *device, const DWORD *elements) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* IDirect3DVertexShader8 interface
|
* 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) {
|
static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
|
||||||
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
|
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
|
||||||
IDirect3DVertexDeclaration8Impl *object;
|
IDirect3DVertexDeclaration8Impl *object;
|
||||||
WINED3DVERTEXELEMENT *wined3d_elements;
|
HRESULT hr;
|
||||||
UINT wined3d_element_count;
|
|
||||||
HRESULT hr = D3D_OK;
|
|
||||||
|
|
||||||
TRACE("(%p) : declaration %p\n", This, declaration);
|
TRACE("(%p) : declaration %p\n", This, declaration);
|
||||||
|
|
||||||
|
@ -1732,38 +1730,18 @@ static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *if
|
||||||
return D3DERR_OUTOFVIDEOMEMORY;
|
return D3DERR_OUTOFVIDEOMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
object->ref_count = 1;
|
hr = vertexdeclaration_init(object, This, declaration);
|
||||||
object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
|
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
|
||||||
object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
|
|
||||||
if (!object->elements) {
|
|
||||||
ERR("Memory allocation failed\n");
|
|
||||||
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
|
||||||
HeapFree(GetProcessHeap(), 0, object);
|
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;
|
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) {
|
static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
|
||||||
|
|
|
@ -358,3 +358,39 @@ const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
|
||||||
IDirect3DVertexDeclaration8Impl_AddRef,
|
IDirect3DVertexDeclaration8Impl_AddRef,
|
||||||
IDirect3DVertexDeclaration8Impl_Release
|
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