From 53e37121a42f708586e843c886e1b1c88b21d235 Mon Sep 17 00:00:00 2001 From: Christian Costa Date: Fri, 14 Dec 2012 08:37:38 +0100 Subject: [PATCH] d3drm: Handle texture load proc when loading mesh data. --- dlls/d3drm/d3drm.c | 6 +++--- dlls/d3drm/d3drm_private.h | 3 ++- dlls/d3drm/meshbuilder.c | 39 ++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/dlls/d3drm/d3drm.c b/dlls/d3drm/d3drm.c index 2fe4fcebc3..7f246ce57e 100644 --- a/dlls/d3drm/d3drm.c +++ b/dlls/d3drm/d3drm.c @@ -1257,8 +1257,8 @@ static HRESULT WINAPI IDirect3DRM3Impl_EnumerateObjects(IDirect3DRM3* iface, D3D return E_NOTIMPL; } -static HRESULT load_data(IDirect3DRM3* iface, LPDIRECTXFILEDATA data_object, LPIID* GUIDs, DWORD nb_GUIDs, D3DRMLOADCALLBACK LoadProc, - LPVOID ArgLP, D3DRMLOADTEXTURECALLBACK LoadTextureProc, LPVOID ArgLTP, LPDIRECT3DRMFRAME3 parent_frame) +static HRESULT load_data(IDirect3DRM3 *iface, IDirectXFileData *data_object, IID **GUIDs, DWORD nb_GUIDs, D3DRMLOADCALLBACK LoadProc, + void *ArgLP, D3DRMLOADTEXTURECALLBACK LoadTextureProc, void *ArgLTP, IDirect3DRMFrame3 *parent_frame) { HRESULT ret = D3DRMERR_BADOBJECT; HRESULT hr; @@ -1296,7 +1296,7 @@ static HRESULT load_data(IDirect3DRM3* iface, LPDIRECTXFILEDATA data_object, LPI hr = IDirect3DRM3_CreateMeshBuilder(iface, &meshbuilder); if (SUCCEEDED(hr)) { - hr = load_mesh_data(meshbuilder, data_object); + hr = load_mesh_data(meshbuilder, data_object, LoadTextureProc, ArgLTP); if (SUCCEEDED(hr)) { /* Only top level objects are notified */ diff --git a/dlls/d3drm/d3drm_private.h b/dlls/d3drm/d3drm_private.h index 95eca5f543..941e4675ab 100644 --- a/dlls/d3drm/d3drm_private.h +++ b/dlls/d3drm/d3drm_private.h @@ -36,7 +36,8 @@ HRESULT Direct3DRMViewport_create(REFIID riid, IUnknown** ppObj) DECLSPEC_HIDDEN HRESULT Direct3DRMMaterial_create(IDirect3DRMMaterial2** ret_iface) DECLSPEC_HIDDEN; HRESULT Direct3DRMTexture_create(REFIID riid, IUnknown** ret_iface) DECLSPEC_HIDDEN; -HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData) DECLSPEC_HIDDEN; +HRESULT load_mesh_data(IDirect3DRMMeshBuilder3 *iface, IDirectXFileData *data, + D3DRMLOADTEXTURECALLBACK load_texture_proc, void *arg) DECLSPEC_HIDDEN; typedef struct { WORD major; diff --git a/dlls/d3drm/meshbuilder.c b/dlls/d3drm/meshbuilder.c index 4ef2477f1f..75f058b6dd 100644 --- a/dlls/d3drm/meshbuilder.c +++ b/dlls/d3drm/meshbuilder.c @@ -1129,7 +1129,7 @@ static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetClassName(IDirect3DRMMeshBu return D3DRM_OK; } -HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData) +HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, IDirectXFileData *pData, D3DRMLOADTEXTURECALLBACK load_texture_proc, void *arg) { IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface); LPDIRECTXFILEOBJECT pObject = NULL; @@ -1372,19 +1372,33 @@ HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData) hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&filename); if (SUCCEEDED(hr)) { - HANDLE file; - - /* If the texture file is not found, no texture is associated with the material */ - file = CreateFileA(*filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - if (file != INVALID_HANDLE_VALUE) + if (load_texture_proc) { - CloseHandle(file); + IDirect3DRMTexture *texture; - hr = Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (LPUNKNOWN*)&This->materials[i].texture); - if (FAILED(hr)) + hr = load_texture_proc(*filename, arg, &texture); + if (SUCCEEDED(hr)) { - IDirectXFileData_Release(data); - goto end; + hr = IDirect3DTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (void**)&This->materials[i].texture); + IDirect3DTexture_Release(texture); + } + } + else + { + HANDLE file; + + /* If the texture file is not found, no texture is associated with the material */ + file = CreateFileA(*filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (file != INVALID_HANDLE_VALUE) + { + CloseHandle(file); + + hr = Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown**)&This->materials[i].texture); + if (FAILED(hr)) + { + IDirectXFileData_Release(data); + goto end; + } } } } @@ -1630,7 +1644,8 @@ static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Load(IDirect3DRMMeshBuilder3* goto end; } - hr = load_mesh_data(iface, pData); + /* We don't care about the texture interface version since we rely on QueryInterface */ + hr = load_mesh_data(iface, pData, (D3DRMLOADTEXTURECALLBACK)cb, arg); if (hr == S_OK) ret = D3DRM_OK;