Commit 737da3eb authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d3dx10: Partially implement D3DX10CreateEffectFromResource().

parent 3defadee
......@@ -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;
}
......@@ -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)
......
......@@ -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();
}
......@@ -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);
......
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