d3dx9: Use the ID3DXInclude object to open the initial file in D3DX[Assemble|Compile|Preprocess]ShaderFromFile.

This commit is contained in:
Matteo Bruni 2013-09-03 16:29:43 +02:00 committed by Alexandre Julliard
parent 1f6173a69f
commit 613d27ebeb
1 changed files with 44 additions and 20 deletions

View File

@ -306,27 +306,38 @@ HRESULT WINAPI D3DXAssembleShaderFromFileA(const char *filename, const D3DXMACRO
HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
{
void *buffer;
const void *buffer;
DWORD len;
HRESULT hr;
struct D3DXIncludeImpl includefromfile;
char *filename_a;
TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
debugstr_w(filename), defines, include, flags, shader, error_messages);
if(FAILED(map_view_of_file(filename, &buffer, &len)))
return D3DXERR_INVALIDDATA;
if(!include)
{
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
include = &includefromfile.ID3DXInclude_iface;
}
hr = D3DXAssembleShader(buffer, len, defines, include, flags,
shader, error_messages);
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
if (!filename_a)
return E_OUTOFMEMORY;
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
UnmapViewOfFile(buffer);
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
if (FAILED(hr))
{
HeapFree(GetProcessHeap(), 0, filename_a);
return D3DXERR_INVALIDDATA;
}
hr = D3DXAssembleShader(buffer, len, defines, include, flags, shader, error_messages);
ID3DXInclude_Close(include, buffer);
HeapFree(GetProcessHeap(), 0, filename_a);
return hr;
}
@ -425,7 +436,7 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
{
void *buffer;
const void *buffer;
DWORD len, filename_len;
HRESULT hr;
struct D3DXIncludeImpl includefromfile;
@ -436,9 +447,6 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
debugstr_w(filename), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
flags, shader, error_messages, constant_table);
if (FAILED(map_view_of_file(filename, &buffer, &len)))
return D3DXERR_INVALIDDATA;
if (!include)
{
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
@ -448,12 +456,16 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
filename_len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
filename_a = HeapAlloc(GetProcessHeap(), 0, filename_len * sizeof(char));
if (!filename_a)
{
UnmapViewOfFile(buffer);
return E_OUTOFMEMORY;
}
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, filename_len, NULL, NULL);
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
if (FAILED(hr))
{
HeapFree(GetProcessHeap(), 0, filename_a);
return D3DXERR_INVALIDDATA;
}
hr = D3DCompile(buffer, len, filename_a, (const D3D_SHADER_MACRO *)defines,
(ID3DInclude *)include, entrypoint, profile, flags, 0,
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
@ -462,8 +474,8 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
hr = D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader),
constant_table);
ID3DXInclude_Close(include, buffer);
HeapFree(GetProcessHeap(), 0, filename_a);
UnmapViewOfFile(buffer);
return hr;
}
@ -546,29 +558,41 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileA(const char *filename, const D3DXMAC
HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
{
void *buffer;
const void *buffer;
DWORD len;
HRESULT hr;
struct D3DXIncludeImpl includefromfile;
char *filename_a;
TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
debugstr_w(filename), defines, include, shader, error_messages);
if (FAILED(map_view_of_file(filename, &buffer, &len)))
return D3DXERR_INVALIDDATA;
if (!include)
{
includefromfile.ID3DXInclude_iface.lpVtbl = &D3DXInclude_Vtbl;
include = &includefromfile.ID3DXInclude_iface;
}
len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
if (!filename_a)
return E_OUTOFMEMORY;
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
if (FAILED(hr))
{
HeapFree(GetProcessHeap(), 0, filename_a);
return D3DXERR_INVALIDDATA;
}
hr = D3DPreprocess(buffer, len, NULL,
(const D3D_SHADER_MACRO *)defines,
(ID3DInclude *) include,
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
UnmapViewOfFile(buffer);
ID3DXInclude_Close(include, buffer);
HeapFree(GetProcessHeap(), 0, filename_a);
return hr;
}