Commit 48d03555 authored by Travis Athougies's avatar Travis Athougies Committed by Alexandre Julliard

d3dx9_36: Improved constant table handle support.

parent c55caea1
......@@ -648,6 +648,33 @@ static DWORD calc_bytes(D3DXCONSTANT_DESC *desc)
return 4 * desc->Elements * desc->Rows * desc->Columns;
}
static ctab_constant *is_valid_constant(ID3DXConstantTableImpl *This, D3DXHANDLE parameter)
{
UINT i;
for (i = 0; i < This->desc.Constants; i++)
if ((ctab_constant *)parameter == &This->constants[i])
return (ctab_constant *)parameter;
return NULL;
}
static ctab_constant *lookup_constant_by_name(ID3DXConstantTableImpl *This, ctab_constant *c, LPCSTR name)
{
UINT i;
TRACE("(%p, %p, %s)\n", This, c, name);
if (c)
FIXME("Only top level constant supported\n");
for (i = 0; i < This->desc.Constants; i++)
if (!strcmp(This->constants[i].desc.Name, name))
return &This->constants[i];
return NULL;
}
/*** IUnknown methods ***/
static HRESULT WINAPI ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable* iface, REFIID riid, void** ppvObject)
{
......@@ -741,16 +768,13 @@ static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable*
return D3DERR_INVALIDCALL;
/* Applications can pass the name of the constant in place of the handle */
if (!((UINT_PTR)constant >> 16))
constant_info = &This->constants[(UINT_PTR)constant - 1];
if (is_valid_constant(This, constant))
constant_info = (ctab_constant *)constant;
else
{
D3DXHANDLE c = ID3DXConstantTable_GetConstantByName(iface, NULL, constant);
if (!c)
return D3DERR_INVALIDCALL;
constant_info = lookup_constant_by_name(This, NULL, (LPCSTR)constant);
constant_info = &This->constants[(UINT_PTR)c - 1];
}
if (!constant_info)
return D3DERR_INVALIDCALL;
if (desc)
*desc = constant_info->desc;
......@@ -785,39 +809,33 @@ static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable*
TRACE("(%p)->(%p, %d)\n", This, constant, index);
if (constant)
if (!constant)
{
FIXME("Only top level constants supported\n");
return NULL;
}
if (index >= This->desc.Constants)
return NULL;
if (index >= This->desc.Constants)
return (D3DXHANDLE)&This->constants[index];
}
else
{
FIXME("Only top level constant supported\n");
return NULL;
return (D3DXHANDLE)(DWORD_PTR)(index + 1);
}
}
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable* iface, D3DXHANDLE constant, LPCSTR name)
{
ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
UINT i;
TRACE("(%p)->(%p, %s)\n", This, constant, name);
if (!name)
return NULL;
if (constant)
{
FIXME("Only top level constants supported\n");
if (!constant || is_valid_constant(This, constant))
return (D3DXHANDLE)lookup_constant_by_name(This, (ctab_constant *)constant, name);
else
return NULL;
}
for (i = 0; i < This->desc.Constants; i++)
if (!strcmp(This->constants[i].desc.Name, name))
return (D3DXHANDLE)(DWORD_PTR)(i + 1);
return NULL;
}
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantElement(ID3DXConstantTable* iface, D3DXHANDLE constant, UINT index)
......@@ -1217,13 +1235,6 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
if (ctab_header->Target)
TRACE("Target = %s\n", object->ctab + ctab_header->Target);
if (object->desc.Constants > 65535)
{
FIXME("Too many constants (%u)\n", object->desc.Constants);
hr = E_NOTIMPL;
goto error;
}
object->constants = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(*object->constants) * object->desc.Constants);
if (!object->constants)
......@@ -1255,9 +1266,7 @@ HRESULT WINAPI D3DXGetShaderConstantTableEx(CONST DWORD* byte_code,
error:
HeapFree(GetProcessHeap(), 0, object->constants);
HeapFree(GetProcessHeap(), 0, object->ctab);
HeapFree(GetProcessHeap(), 0, object);
ID3DXConstantTableImpl_Release((ID3DXConstantTable *)object);
return hr;
}
......
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