st/nine: Refactor SetLight
authorAxel Davy <axel.davy@ens.fr>
Wed, 19 Oct 2016 21:29:58 +0000 (23:29 +0200)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:22 +0000 (23:44 +0100)
Call a helper function to set the light.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/nine_state.c
src/gallium/state_trackers/nine/nine_state.h

index 2587ad1d7aeadb654520402da82eefba8266233b..74c1bea785796b2c2ca155d736fd373e129b6360 100644 (file)
@@ -2073,6 +2073,7 @@ NineDevice9_SetLight( struct NineDevice9 *This,
                       const D3DLIGHT9 *pLight )
 {
     struct nine_state *state = This->update;
+    HRESULT hr;
 
     DBG("This=%p Index=%u pLight=%p\n", This, Index, pLight);
     if (pLight)
@@ -2083,27 +2084,10 @@ NineDevice9_SetLight( struct NineDevice9 *This,
 
     user_assert(Index < NINE_MAX_LIGHTS, D3DERR_INVALIDCALL); /* sanity */
 
-    if (Index >= state->ff.num_lights) {
-        unsigned n = state->ff.num_lights;
-        unsigned N = Index + 1;
-
-        state->ff.light = REALLOC(state->ff.light, n * sizeof(D3DLIGHT9),
-                                                   N * sizeof(D3DLIGHT9));
-        if (!state->ff.light)
-            return E_OUTOFMEMORY;
-        state->ff.num_lights = N;
-
-        for (; n < Index; ++n) {
-            memset(&state->ff.light[n], 0, sizeof(D3DLIGHT9));
-            state->ff.light[n].Type = (D3DLIGHTTYPE)NINED3DLIGHT_INVALID;
-        }
-    }
-    state->ff.light[Index] = *pLight;
+    hr = nine_state_set_light(&state->ff, Index, pLight);
+    if (hr != D3D_OK)
+        return hr;
 
-    if (pLight->Type == D3DLIGHT_SPOT && pLight->Theta >= pLight->Phi) {
-        DBG("Warning: clamping D3DLIGHT9.Theta\n");
-        state->ff.light[Index].Theta = state->ff.light[Index].Phi;
-    }
     if (pLight->Type != D3DLIGHT_DIRECTIONAL &&
         pLight->Attenuation0 == 0.0f &&
         pLight->Attenuation1 == 0.0f &&
index 47fe31d391c4c07d0ef9f3c28569114a1aa8048e..0767126db3c771e253b81023c09a3ff43eac4ef1 100644 (file)
@@ -2826,6 +2826,34 @@ nine_state_access_transform(struct nine_ff_state *ff_state, D3DTRANSFORMSTATETYP
     return &ff_state->transform[index];
 }
 
+HRESULT
+nine_state_set_light(struct nine_ff_state *ff_state, DWORD Index,
+                     const D3DLIGHT9 *pLight)
+{
+    if (Index >= ff_state->num_lights) {
+        unsigned n = ff_state->num_lights;
+        unsigned N = Index + 1;
+
+        ff_state->light = REALLOC(ff_state->light, n * sizeof(D3DLIGHT9),
+                                                   N * sizeof(D3DLIGHT9));
+        if (!ff_state->light)
+            return E_OUTOFMEMORY;
+        ff_state->num_lights = N;
+
+        for (; n < Index; ++n) {
+            memset(&ff_state->light[n], 0, sizeof(D3DLIGHT9));
+            ff_state->light[n].Type = (D3DLIGHTTYPE)NINED3DLIGHT_INVALID;
+        }
+    }
+    ff_state->light[Index] = *pLight;
+
+    if (pLight->Type == D3DLIGHT_SPOT && pLight->Theta >= pLight->Phi) {
+        DBG("Warning: clamping D3DLIGHT9.Theta\n");
+        ff_state->light[Index].Theta = ff_state->light[Index].Phi;
+    }
+    return D3D_OK;
+}
+
 #define D3DRS_TO_STRING_CASE(n) case D3DRS_##n: return "D3DRS_"#n
 const char *nine_d3drs_to_string(DWORD State)
 {
index d73c40681f85046c724d636e9735d06535fc4311..314dd7c06e45bd62002f80a1e9d72fe72d13f6b5 100644 (file)
@@ -462,6 +462,9 @@ D3DMATRIX *
 nine_state_access_transform(struct nine_ff_state *, D3DTRANSFORMSTATETYPE,
                             boolean alloc);
 
+HRESULT
+nine_state_set_light(struct nine_ff_state *, DWORD, const D3DLIGHT9 *);
+
 const char *nine_d3drs_to_string(DWORD State);
 
 #endif /* _NINE_STATE_H_ */