diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 0bda2712d76..2a306fa8f57 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -123,3 +123,85 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA return hr; } + +static HRESULT get_resource_data(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) +{ + HGLOBAL resource; + + *length = SizeofResource(module, resinfo); + if (!*length) + return D3DX10_ERR_INVALID_DATA; + + resource = LoadResource(module, resinfo); + if (!resource) + return D3DX10_ERR_INVALID_DATA; + + *buffer = LockResource(resource); + if (!*buffer) + return D3DX10_ERR_INVALID_DATA; + + return S_OK; +} + +HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resource_name, + const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, + const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, + ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, + ID3D10Blob **errors, HRESULT *hresult) +{ + HRSRC resinfo; + void *data; + DWORD size; + HRESULT hr; + + TRACE("module %p, resource_name %s, filename %s, defines %p, include %p, profile %s, " + "shader_flags %#x, effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, " + "errors %p, hresult %p.\n", module, debugstr_a(resource_name), debugstr_a(filename), + defines, include, debugstr_a(profile), shader_flags, effect_flags, + device, effect_pool, pump, effect, errors, hresult); + + if (!(resinfo = FindResourceA(module, resource_name, (const char *)RT_RCDATA))) + return D3DX10_ERR_INVALID_DATA; + + if (FAILED(hr = get_resource_data(module, resinfo, &data, &size))) + return hr; + + return D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); +} + +HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *resource_name, + const WCHAR *filenameW, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, + const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, + ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, + ID3D10Blob **errors, HRESULT *hresult) +{ + char *filename; + HRSRC resinfo; + void *data; + DWORD size; + HRESULT hr; + int len; + + TRACE("module %p, resource_name %s, filename %s, defines %p, include %p, profile %s, " + "shader_flags %#x, effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, " + "errors %p, hresult %p.\n", module, debugstr_w(resource_name), debugstr_w(filenameW), + defines, include, debugstr_a(profile), shader_flags, effect_flags, + device, effect_pool, pump, effect, errors, hresult); + + if (!(resinfo = FindResourceW(module, resource_name, (const WCHAR *)RT_RCDATA))) + return D3DX10_ERR_INVALID_DATA; + + if (FAILED(hr = get_resource_data(module, resinfo, &data, &size))) + return hr; + + len = WideCharToMultiByte(CP_ACP, 0, filenameW, -1, NULL, 0, NULL, NULL); + if (!(filename = heap_alloc(len))) + return E_OUTOFMEMORY; + WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, len, NULL, NULL); + + hr = D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); + heap_free(filename); + return hr; +} diff --git a/dlls/d3dx10_43/d3dx10_43.spec b/dlls/d3dx10_43/d3dx10_43.spec index da6629ad1a0..8bc9451aeab 100644 --- a/dlls/d3dx10_43/d3dx10_43.spec +++ b/dlls/d3dx10_43/d3dx10_43.spec @@ -23,8 +23,8 @@ @ stdcall D3DX10CreateEffectFromFileA(str ptr ptr str long long ptr ptr ptr ptr ptr ptr) @ stdcall D3DX10CreateEffectFromFileW(wstr ptr ptr str long long ptr ptr ptr ptr ptr ptr) @ stdcall D3DX10CreateEffectFromMemory(ptr long str ptr ptr str long long ptr ptr ptr ptr ptr ptr) -@ stub D3DX10CreateEffectFromResourceA(long str str ptr ptr str long long ptr ptr ptr ptr ptr ptr) -@ stub D3DX10CreateEffectFromResourceW(long wstr wstr ptr ptr str long long ptr ptr ptr ptr ptr ptr) +@ stdcall D3DX10CreateEffectFromResourceA(long str str ptr ptr str long long ptr ptr ptr ptr ptr ptr) +@ stdcall D3DX10CreateEffectFromResourceW(long wstr wstr ptr ptr str long long ptr ptr ptr ptr ptr ptr) @ stdcall D3DX10CreateEffectPoolFromFileA(str ptr ptr str long long ptr ptr ptr ptr ptr) @ stdcall D3DX10CreateEffectPoolFromFileW(wstr ptr ptr str long long ptr ptr ptr ptr ptr) @ stdcall D3DX10CreateEffectPoolFromMemory(ptr long str ptr ptr str long long ptr ptr ptr ptr ptr) diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index bc5ca6747f5..70827056f5f 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -3153,6 +3153,27 @@ todo_wine ok(!refcount, "Unexpected refcount.\n"); } +static void test_create_effect_from_resource(void) +{ + ID3D10Device *device; + ID3D10Effect *effect; + ULONG refcount; + HRESULT hr; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + hr = D3DX10CreateEffectFromResourceA(GetModuleHandleA(NULL), "resource", NULL, NULL, NULL, + "fx_4_0", 0, 0, device, NULL, NULL, &effect, NULL, NULL); + ok(hr == D3DX10_ERR_INVALID_DATA, "Unexpected hr %#x.\n", hr); + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Unexpected refcount.\n"); +} + START_TEST(d3dx10) { test_D3DX10UnsetAllDeviceObjects(); @@ -3163,4 +3184,5 @@ START_TEST(d3dx10) test_create_texture(); test_font(); test_sprite(); + test_create_effect_from_resource(); } diff --git a/include/d3dx10async.h b/include/d3dx10async.h index c8204bc7798..0b7aca9c023 100644 --- a/include/d3dx10async.h +++ b/include/d3dx10async.h @@ -58,6 +58,18 @@ HRESULT WINAPI D3DX10PreprocessShaderFromMemory(const char *data, SIZE_T data_si const D3D10_SHADER_MACRO *defines, ID3DInclude *include, ID3DX10ThreadPump *pump, ID3D10Blob **shader_text, ID3D10Blob **errors, HRESULT *hresult); +HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resource_name, + const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, + const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, + ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, + ID3D10Blob **errors, HRESULT *hresult); + +HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *resource_name, + const WCHAR *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, + const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, + ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, + ID3D10Blob **errors, HRESULT *hresult); + HRESULT WINAPI D3DX10CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX10DataLoader **loader); HRESULT WINAPI D3DX10CreateAsyncFileLoaderA(const char *filename, ID3DX10DataLoader **loader); HRESULT WINAPI D3DX10CreateAsyncMemoryLoader(const void *data, SIZE_T datasize, ID3DX10DataLoader **loader);