d3dx9: Merge get/is_valid_constant().

This commit is contained in:
Rico Schüller 2013-07-22 14:35:34 +02:00 committed by Alexandre Julliard
parent e6e09eb465
commit 918abfef6a
1 changed files with 21 additions and 36 deletions

View File

@ -610,11 +610,6 @@ static inline BOOL is_vertex_shader(DWORD version)
return (version & 0xffff0000) == 0xfffe0000; return (version & 0xffff0000) == 0xfffe0000;
} }
static inline struct ctab_constant *constant_from_handle(D3DXHANDLE handle)
{
return (struct ctab_constant *)handle;
}
static inline D3DXHANDLE handle_from_constant(struct ctab_constant *constant) static inline D3DXHANDLE handle_from_constant(struct ctab_constant *constant)
{ {
return (D3DXHANDLE)constant; return (D3DXHANDLE)constant;
@ -708,42 +703,22 @@ static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl
return NULL; return NULL;
} }
static struct ctab_constant *is_valid_sub_constant(struct ctab_constant *parent, struct ctab_constant *constant) static struct ctab_constant *is_valid_sub_constant(struct ctab_constant *parent, D3DXHANDLE handle)
{ {
struct ctab_constant *c;
UINT i, count; UINT i, count;
/* all variable have at least elements = 1, but no elements */ /* all variable have at least elements = 1, but not always elements */
if (!parent->constants) return NULL; if (!parent->constants) return NULL;
if (parent->desc.Elements > 1) count = parent->desc.Elements; count = parent->desc.Elements > 1 ? parent->desc.Elements : parent->desc.StructMembers;
else count = parent->desc.StructMembers;
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
if (&parent->constants[i] == constant) if (handle_from_constant(&parent->constants[i]) == handle)
return constant; return &parent->constants[i];
if (is_valid_sub_constant(&parent->constants[i], constant)) c = is_valid_sub_constant(&parent->constants[i], handle);
return constant; if (c) return c;
}
return NULL;
}
static inline struct ctab_constant *is_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
{
struct ctab_constant *c = constant_from_handle(handle);
UINT i;
if (!c) return NULL;
for (i = 0; i < table->desc.Constants; ++i)
{
if (&table->constants[i] == c)
return c;
if (is_valid_sub_constant(&table->constants[i], c))
return c;
} }
return NULL; return NULL;
@ -751,11 +726,21 @@ static inline struct ctab_constant *is_valid_constant(struct ID3DXConstantTableI
static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle) static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
{ {
struct ctab_constant *constant = is_valid_constant(table, handle); struct ctab_constant *c;
UINT i;
if (!constant) constant = get_constant_by_name(table, NULL, handle); if (!handle) return NULL;
return constant; for (i = 0; i < table->desc.Constants; ++i)
{
if (handle_from_constant(&table->constants[i]) == handle)
return &table->constants[i];
c = is_valid_sub_constant(&table->constants[i], handle);
if (c) return c;
}
return get_constant_by_name(table, NULL, handle);
} }
static inline void set_float_shader_constant(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, static inline void set_float_shader_constant(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,