Commit c4368874 authored by Christian Costa's avatar Christian Costa Committed by Alexandre Julliard

d3drm: Retrieve mesh name at loading time. Implement GetName and SetName.

parent edf61623
......@@ -48,6 +48,7 @@ typedef struct {
IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
LONG ref;
char* name;
DWORD nb_vertices;
D3DVECTOR* pVertices;
DWORD nb_normals;
......@@ -344,6 +345,7 @@ static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_Release(IDirect3DRMMeshBuilder2*
if (!ref)
{
HeapFree(GetProcessHeap(), 0, This->name);
HeapFree(GetProcessHeap(), 0, This->pVertices);
HeapFree(GetProcessHeap(), 0, This->pNormals);
HeapFree(GetProcessHeap(), 0, This->pFaceData);
......@@ -408,23 +410,23 @@ static DWORD WINAPI IDirect3DRMMeshBuilder2Impl_GetAppData(IDirect3DRMMeshBuilde
}
static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetName(IDirect3DRMMeshBuilder2* iface,
LPCSTR pName)
LPCSTR name)
{
IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
FIXME("(%p)->(%s): stub\n", This, pName);
TRACE("(%p)->(%s)\n", This, debugstr_a(name));
return E_NOTIMPL;
return IDirect3DRMMeshBuilder3_SetName(&This->IDirect3DRMMeshBuilder3_iface, name);
}
static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetName(IDirect3DRMMeshBuilder2* iface,
LPDWORD lpdwSize, LPSTR lpName)
LPDWORD size, LPSTR name)
{
IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
TRACE("(%p)->(%p,%p)\n", This, size, name);
return E_NOTIMPL;
return IDirect3DRMMeshBuilder3_GetName(&This->IDirect3DRMMeshBuilder3_iface, size, name);
}
static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetClassName(IDirect3DRMMeshBuilder2* iface,
......@@ -1002,23 +1004,48 @@ static DWORD WINAPI IDirect3DRMMeshBuilder3Impl_GetAppData(IDirect3DRMMeshBuilde
}
static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetName(IDirect3DRMMeshBuilder3* iface,
LPCSTR pName)
LPCSTR name)
{
IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
char *string = NULL;
FIXME("(%p)->(%s): stub\n", This, pName);
TRACE("(%p)->(%s)\n", This, debugstr_a(name));
return E_NOTIMPL;
if (name)
{
string = HeapAlloc(GetProcessHeap(), 0, strlen(name) + 1);
if (!string) return E_OUTOFMEMORY;
strcpy(string, name);
}
HeapFree(GetProcessHeap(), 0, This->name);
This->name = string;
return D3DRM_OK;
}
static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetName(IDirect3DRMMeshBuilder3* iface,
LPDWORD lpdwSize, LPSTR lpName)
LPDWORD size, LPSTR name)
{
IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
TRACE("(%p)->(%p,%p)\n", This, size, name);
return E_NOTIMPL;
if (!size)
return E_POINTER;
if (!This->name)
{
*size = 0;
return D3DRM_OK;
}
if (*size < (strlen(This->name) + 1))
return E_INVALIDARG;
strcpy(name, This->name);
*size = strlen(This->name) + 1;
return D3DRM_OK;
}
static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetClassName(IDirect3DRMMeshBuilder3* iface,
......@@ -1052,6 +1079,29 @@ HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData)
TRACE("(%p)->(%p)\n", This, pData);
/* Remove previous name */
HeapFree(GetProcessHeap(), 0, This->name);
This->name = NULL;
hr = IDirectXFileData_GetName(pData, NULL, &size);
if (hr != DXFILE_OK)
return hr;
if (size)
{
This->name = HeapAlloc(GetProcessHeap(), 0, size);
if (!This->name)
return E_OUTOFMEMORY;
hr = IDirectXFileData_GetName(pData, This->name, &size);
if (hr != DXFILE_OK)
{
HeapFree(GetProcessHeap(), 0, This->name);
This->name = NULL;
return hr;
}
}
TRACE("Mesh name is '%s'\n", This->name ? This->name : "");
hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
if (hr != DXFILE_OK)
goto end;
......
......@@ -179,6 +179,8 @@ static void test_MeshBuilder(void)
D3DVECTOR v[3];
D3DVECTOR n[3];
DWORD f[8];
char name[10];
DWORD size;
hr = pDirect3DRMCreate(&pD3DRM);
ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
......@@ -201,6 +203,26 @@ static void test_MeshBuilder(void)
hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
size = sizeof(name);
hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
ok(!strcmp(name, "Object"), "Retreived name '%s' instead of 'Object'\n", name);
size = strlen("Object"); /* No space for null character */
hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
ok(hr == E_INVALIDARG, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, NULL);
ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
size = sizeof(name);
hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
ok(size == 0, "Size should be 0 instead of %u\n", size);
hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, "");
ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
size = sizeof(name);
hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
ok(!strcmp(name, ""), "Retreived name '%s' instead of ''\n", name);
val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
......
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