Commit 70b79445 authored by Christian Costa's avatar Christian Costa Committed by Alexandre Julliard

d3dx9_36: Implement ID3DXConstantTableImpl_GetDesc + tests.

parent 104cc7c2
......@@ -281,6 +281,7 @@ typedef struct ID3DXConstantTableImpl {
LONG ref;
LPVOID ctab;
DWORD size;
D3DXCONSTANTTABLE_DESC desc;
} ID3DXConstantTableImpl;
/*** IUnknown methods ***/
......@@ -353,9 +354,14 @@ static HRESULT WINAPI ID3DXConstantTableImpl_GetDesc(ID3DXConstantTable* iface,
{
ID3DXConstantTableImpl *This = (ID3DXConstantTableImpl *)iface;
FIXME("(%p)->(%p): stub\n", This, desc);
TRACE("(%p)->(%p)\n", This, desc);
return E_NOTIMPL;
if (!desc)
return D3DERR_INVALIDCALL;
memcpy(desc, &This->desc, sizeof(This->desc));
return D3D_OK;
}
static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable* iface, D3DXHANDLE constant,
......@@ -590,10 +596,11 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
DWORD flags,
LPD3DXCONSTANTTABLE* constant_table)
{
ID3DXConstantTableImpl* object;
ID3DXConstantTableImpl* object = NULL;
HRESULT hr;
LPCVOID data;
UINT size;
D3DXSHADER_CONSTANTTABLE* ctab_header;
FIXME("(%p, %x, %p): semi-stub\n", byte_code, flags, constant_table);
......@@ -614,6 +621,9 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
object->lpVtbl = &ID3DXConstantTable_Vtbl;
object->ref = 1;
if (size < sizeof(D3DXSHADER_CONSTANTTABLE))
goto error;
object->ctab = HeapAlloc(GetProcessHeap(), 0, size);
if (!object->ctab)
{
......@@ -624,9 +634,23 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
object->size = size;
memcpy(object->ctab, data, object->size);
ctab_header = (D3DXSHADER_CONSTANTTABLE*)data;
if (ctab_header->Size != sizeof(D3DXSHADER_CONSTANTTABLE))
goto error;
object->desc.Creator = ctab_header->Creator ? (LPCSTR)object->ctab + ctab_header->Creator : NULL;
object->desc.Version = ctab_header->Version;
object->desc.Constants = ctab_header->Constants;
*constant_table = (LPD3DXCONSTANTTABLE)object;
return D3D_OK;
error:
HeapFree(GetProcessHeap(), 0, object->ctab);
HeapFree(GetProcessHeap(), 0, object);
return D3DXERR_INVALIDDATA;
}
HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code,
......
......@@ -43,7 +43,7 @@ static const DWORD simple_ps[] = {
static const DWORD shader_with_ctab[] = {
0xfffe0300, /* vs_3_0 */
0x0002fffe, FCC_TEXT, 0x00000000, /* TEXT comment */
0x0008fffe, FCC_CTAB, 0x0000001c, 0x00000000, 0xfffe0300, 0x00000000, /* CTAB comment */
0x0008fffe, FCC_CTAB, 0x0000001c, 0x00000010, 0xfffe0300, 0x00000000, /* CTAB comment */
0x00000000, 0x00000000, 0x00000000,
0x0004fffe, FCC_TEXT, 0x00000000, 0x00000000, 0x00000000, /* TEXT comment */
0x0000ffff}; /* END */
......@@ -120,6 +120,7 @@ static void test_get_shader_constant_table_ex(void)
HRESULT hr;
LPVOID data;
DWORD size;
D3DXCONSTANTTABLE_DESC desc;
hr = D3DXGetShaderConstantTableEx(NULL, 0, &constant_table);
ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
......@@ -130,7 +131,7 @@ static void test_get_shader_constant_table_ex(void)
/* With invalid CTAB data */
hr = D3DXGetShaderConstantTableEx(shader_with_invalid_ctab, 0, &constant_table);
todo_wine ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
if (constant_table) ID3DXConstantTable_Release(constant_table);
hr = D3DXGetShaderConstantTableEx(shader_with_ctab, 0, &constant_table);
......@@ -144,6 +145,15 @@ static void test_get_shader_constant_table_ex(void)
data = ID3DXConstantTable_GetBufferPointer(constant_table);
ok(!memcmp(data, shader_with_ctab + 6, size), "Retreived wrong CTAB data\n");
hr = ID3DXConstantTable_GetDesc(constant_table, NULL);
ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
ok(desc.Creator == (LPCSTR)data + 0x10, "Got result %p, expected %p\n", desc.Creator, (LPCSTR)data + 0x10);
ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
ok(desc.Constants == 0, "Got result %x, expected 0\n", desc.Constants);
ID3DXConstantTable_Release(constant_table);
}
}
......
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