[Mesa-dev] [PATCH 20/84] st/nine: Refactor LightEnable

Axel Davy axel.davy at ens.fr
Wed Dec 7 22:54:53 UTC 2016


Call a helper function.

Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
 src/gallium/state_trackers/nine/device9.c    | 25 +-------------------
 src/gallium/state_trackers/nine/nine_state.c | 35 ++++++++++++++++++++++++++++
 src/gallium/state_trackers/nine/nine_state.h |  4 ++++
 3 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
index 6ece0e0..4a16e09 100644
--- a/src/gallium/state_trackers/nine/device9.c
+++ b/src/gallium/state_trackers/nine/device9.c
@@ -2123,7 +2123,6 @@ NineDevice9_LightEnable( struct NineDevice9 *This,
                          BOOL Enable )
 {
     struct nine_state *state = This->update;
-    unsigned i;
 
     DBG("This=%p Index=%u Enable=%i\n", This, Index, Enable);
 
@@ -2139,30 +2138,8 @@ NineDevice9_LightEnable( struct NineDevice9 *This,
         light.Direction.z = 1.0f;
         NineDevice9_SetLight(This, Index, &light);
     }
-    user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
-
-    for (i = 0; i < state->ff.num_lights_active; ++i) {
-        if (state->ff.active_light[i] == Index)
-            break;
-    }
 
-    if (Enable) {
-        if (i < state->ff.num_lights_active)
-            return D3D_OK;
-        /* XXX wine thinks this should still succeed:
-         */
-        user_assert(i < NINE_MAX_LIGHTS_ACTIVE, D3DERR_INVALIDCALL);
-
-        state->ff.active_light[i] = Index;
-        state->ff.num_lights_active++;
-    } else {
-        if (i == state->ff.num_lights_active)
-            return D3D_OK;
-        --state->ff.num_lights_active;
-        for (; i < state->ff.num_lights_active; ++i)
-            state->ff.active_light[i] = state->ff.active_light[i + 1];
-    }
-    state->changed.group |= NINE_STATE_FF_LIGHTING;
+    nine_state_light_enable(&state->ff, &state->changed.group, Index, Enable);
 
     return D3D_OK;
 }
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index 071c12c..f95a66c 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -2859,6 +2859,41 @@ nine_state_set_light(struct nine_ff_state *ff_state, DWORD Index,
     return D3D_OK;
 }
 
+HRESULT
+nine_state_light_enable(struct nine_ff_state *ff_state, uint32_t *change_group,
+                        DWORD Index, BOOL Enable)
+{
+    unsigned i;
+
+    user_assert(Index < ff_state->num_lights, D3DERR_INVALIDCALL);
+
+    for (i = 0; i < ff_state->num_lights_active; ++i) {
+        if (ff_state->active_light[i] == Index)
+            break;
+    }
+
+    if (Enable) {
+        if (i < ff_state->num_lights_active)
+            return D3D_OK;
+        /* XXX wine thinks this should still succeed:
+         */
+        user_assert(i < NINE_MAX_LIGHTS_ACTIVE, D3DERR_INVALIDCALL);
+
+        ff_state->active_light[i] = Index;
+        ff_state->num_lights_active++;
+    } else {
+        if (i == ff_state->num_lights_active)
+            return D3D_OK;
+        --ff_state->num_lights_active;
+        for (; i < ff_state->num_lights_active; ++i)
+            ff_state->active_light[i] = ff_state->active_light[i + 1];
+    }
+
+    *change_group |= NINE_STATE_FF_LIGHTING;
+
+    return D3D_OK;
+}
+
 #define D3DRS_TO_STRING_CASE(n) case D3DRS_##n: return "D3DRS_"#n
 const char *nine_d3drs_to_string(DWORD State)
 {
diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
index 314dd7c..4d1e8a4 100644
--- a/src/gallium/state_trackers/nine/nine_state.h
+++ b/src/gallium/state_trackers/nine/nine_state.h
@@ -465,6 +465,10 @@ nine_state_access_transform(struct nine_ff_state *, D3DTRANSFORMSTATETYPE,
 HRESULT
 nine_state_set_light(struct nine_ff_state *, DWORD, const D3DLIGHT9 *);
 
+HRESULT
+nine_state_light_enable(struct nine_ff_state *, uint32_t *,
+                        DWORD, BOOL);
+
 const char *nine_d3drs_to_string(DWORD State);
 
 #endif /* _NINE_STATE_H_ */
-- 
2.10.2



More information about the mesa-dev mailing list