=?UTF-8?Q?Rico=20Sch=C3=BCller=20?=: d3dx9: Merge get/is_valid_constant().

Alexandre Julliard julliard at winehq.org
Mon Jul 22 14:22:46 CDT 2013


Module: wine
Branch: master
Commit: 918abfef6a7a7e0d14fec9000205146af804b9e5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=918abfef6a7a7e0d14fec9000205146af804b9e5

Author: Rico Schüller <kgbricola at web.de>
Date:   Mon Jul 22 14:35:34 2013 +0200

d3dx9: Merge get/is_valid_constant().

---

 dlls/d3dx9_36/shader.c |   47 ++++++++++++++++-------------------------------
 1 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c
index 8b089d2..6ad5f92 100644
--- a/dlls/d3dx9_36/shader.c
+++ b/dlls/d3dx9_36/shader.c
@@ -610,11 +610,6 @@ static inline BOOL is_vertex_shader(DWORD version)
     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)
 {
     return (D3DXHANDLE)constant;
@@ -708,54 +703,44 @@ static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl
     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;
 
-    /* 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->desc.Elements > 1) count = parent->desc.Elements;
-    else count = parent->desc.StructMembers;
-
+    count = parent->desc.Elements > 1 ? parent->desc.Elements : parent->desc.StructMembers;
     for (i = 0; i < count; ++i)
     {
-        if (&parent->constants[i] == constant)
-            return constant;
+        if (handle_from_constant(&parent->constants[i]) == handle)
+            return &parent->constants[i];
 
-        if (is_valid_sub_constant(&parent->constants[i], constant))
-            return constant;
+        c = is_valid_sub_constant(&parent->constants[i], handle);
+        if (c) return c;
     }
 
     return NULL;
 }
 
-static inline struct ctab_constant *is_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
+static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
 {
-    struct ctab_constant *c = constant_from_handle(handle);
+    struct ctab_constant *c;
     UINT i;
 
-    if (!c) return NULL;
+    if (!handle) return NULL;
 
     for (i = 0; i < table->desc.Constants; ++i)
     {
-        if (&table->constants[i] == c)
-            return c;
+        if (handle_from_constant(&table->constants[i]) == handle)
+            return &table->constants[i];
 
-        if (is_valid_sub_constant(&table->constants[i], c))
-            return c;
+        c = is_valid_sub_constant(&table->constants[i], handle);
+        if (c) return c;
     }
 
-    return NULL;
-}
-
-static inline struct ctab_constant *get_valid_constant(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
-{
-    struct ctab_constant *constant = is_valid_constant(table, handle);
-
-    if (!constant) constant = get_constant_by_name(table, NULL, handle);
-
-    return constant;
+    return get_constant_by_name(table, NULL, handle);
 }
 
 static inline void set_float_shader_constant(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,




More information about the wine-cvs mailing list