[PATCH v2 2/4] wined3d: Introduce a separate structure for light state.
Zebediah Figura
z.figura12 at gmail.com
Tue Feb 12 10:45:05 CST 2019
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
v2: Rename to wined3d_light_state_*.
dlls/wined3d/cs.c | 8 ++++----
dlls/wined3d/device.c | 14 +++++++-------
dlls/wined3d/glsl_shader.c | 8 ++++----
dlls/wined3d/state.c | 4 ++--
dlls/wined3d/stateblock.c | 31 ++++++++++++++++---------------
dlls/wined3d/utils.c | 6 +++---
dlls/wined3d/wined3d_private.h | 23 +++++++++++++++--------
7 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 7471d24e7e..7e1c4ef0ec 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -1818,7 +1818,7 @@ static void wined3d_cs_exec_set_light(struct wined3d_cs *cs, const void *data)
light_idx = op->light.OriginalIndex;
- if (!(light_info = wined3d_state_get_light(&cs->state, light_idx)))
+ if (!(light_info = wined3d_light_state_get_light(&cs->state.light_state, light_idx)))
{
TRACE("Adding new light.\n");
if (!(light_info = heap_alloc_zero(sizeof(*light_info))))
@@ -1828,7 +1828,7 @@ static void wined3d_cs_exec_set_light(struct wined3d_cs *cs, const void *data)
}
hash_idx = LIGHTMAP_HASHFUNC(light_idx);
- list_add_head(&cs->state.light_map[hash_idx], &light_info->entry);
+ list_add_head(&cs->state.light_state.light_map[hash_idx], &light_info->entry);
light_info->glIndex = -1;
light_info->OriginalIndex = light_idx;
}
@@ -1865,14 +1865,14 @@ static void wined3d_cs_exec_set_light_enable(struct wined3d_cs *cs, const void *
struct wined3d_light_info *light_info;
int prev_idx;
- if (!(light_info = wined3d_state_get_light(&cs->state, op->idx)))
+ if (!(light_info = wined3d_light_state_get_light(&cs->state.light_state, op->idx)))
{
ERR("Light doesn't exist.\n");
return;
}
prev_idx = light_info->glIndex;
- wined3d_state_enable_light(&cs->state, &device->adapter->d3d_info, light_info, op->enable);
+ wined3d_light_state_enable_light(&cs->state.light_state, &device->adapter->d3d_info, light_info, op->enable);
if (light_info->glIndex != prev_idx)
{
device_invalidate_state(device, STATE_LIGHT_TYPE);
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 1b2f7e0931..0f10588172 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1608,13 +1608,13 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device,
return WINED3DERR_INVALIDCALL;
}
- if (!(object = wined3d_state_get_light(device->update_state, light_idx)))
+ if (!(object = wined3d_light_state_get_light(&device->update_state->light_state, light_idx)))
{
TRACE("Adding new light\n");
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
- list_add_head(&device->update_state->light_map[hash_idx], &object->entry);
+ list_add_head(&device->update_state->light_state.light_map[hash_idx], &object->entry);
object->glIndex = -1;
object->OriginalIndex = light_idx;
}
@@ -1721,7 +1721,7 @@ HRESULT CDECL wined3d_device_get_light(const struct wined3d_device *device,
TRACE("device %p, light_idx %u, light %p.\n", device, light_idx, light);
- if (!(light_info = wined3d_state_get_light(&device->state, light_idx)))
+ if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
{
TRACE("Light information requested but light not defined\n");
return WINED3DERR_INVALIDCALL;
@@ -1738,19 +1738,19 @@ HRESULT CDECL wined3d_device_set_light_enable(struct wined3d_device *device, UIN
TRACE("device %p, light_idx %u, enable %#x.\n", device, light_idx, enable);
/* Special case - enabling an undefined light creates one with a strict set of parameters. */
- if (!(light_info = wined3d_state_get_light(device->update_state, light_idx)))
+ if (!(light_info = wined3d_light_state_get_light(&device->update_state->light_state, light_idx)))
{
TRACE("Light enabled requested but light not defined, so defining one!\n");
wined3d_device_set_light(device, light_idx, &WINED3D_default_light);
- if (!(light_info = wined3d_state_get_light(device->update_state, light_idx)))
+ if (!(light_info = wined3d_light_state_get_light(&device->update_state->light_state, light_idx)))
{
FIXME("Adding default lights has failed dismally\n");
return WINED3DERR_INVALIDCALL;
}
}
- wined3d_state_enable_light(device->update_state, &device->adapter->d3d_info, light_info, enable);
+ wined3d_light_state_enable_light(&device->update_state->light_state, &device->adapter->d3d_info, light_info, enable);
if (!device->recording)
wined3d_cs_emit_set_light_enable(device->cs, light_idx, enable);
@@ -1763,7 +1763,7 @@ HRESULT CDECL wined3d_device_get_light_enable(const struct wined3d_device *devic
TRACE("device %p, light_idx %u, enable %p.\n", device, light_idx, enable);
- if (!(light_info = wined3d_state_get_light(&device->state, light_idx)))
+ if (!(light_info = wined3d_light_state_get_light(&device->state.light_state, light_idx)))
{
TRACE("Light enabled state requested but light not defined.\n");
return WINED3DERR_INVALIDCALL;
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index ba2c62165b..5387628a90 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -1891,10 +1891,10 @@ static void shader_glsl_load_constants(void *shader_priv, struct wined3d_context
for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
{
- if (!state->lights[i])
+ if (!state->light_state.lights[i])
continue;
- switch (state->lights[i]->OriginalParms.type)
+ switch (state->light_state.lights[i]->OriginalParms.type)
{
case WINED3D_LIGHT_POINT:
++point_count;
@@ -1909,7 +1909,7 @@ static void shader_glsl_load_constants(void *shader_priv, struct wined3d_context
++parallel_point_count;
break;
default:
- FIXME("Unhandled light type %#x.\n", state->lights[i]->OriginalParms.type);
+ FIXME("Unhandled light type %#x.\n", state->light_state.lights[i]->OriginalParms.type);
break;
}
}
@@ -1921,7 +1921,7 @@ static void shader_glsl_load_constants(void *shader_priv, struct wined3d_context
shader_glsl_ffp_vertex_lightambient_uniform(context, state, prog);
for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
{
- const struct wined3d_light_info *light_info = state->lights[i];
+ const struct wined3d_light_info *light_info = state->light_state.lights[i];
unsigned int idx;
if (!light_info)
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 1b5eacdf21..0f7b030b0c 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3811,7 +3811,7 @@ static void transform_view(struct wined3d_context *context, const struct wined3d
/* Reset lights. TODO: Call light apply func */
for (k = 0; k < gl_info->limits.lights; ++k)
{
- if (!(light = state->lights[k]))
+ if (!(light = state->light_state.lights[k]))
continue;
if (light->OriginalParms.type == WINED3D_LIGHT_DIRECTIONAL)
gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->direction.x);
@@ -4142,7 +4142,7 @@ static void light(struct wined3d_context *context, const struct wined3d_state *s
{
const struct wined3d_gl_info *gl_info = context->gl_info;
UINT Index = state_id - STATE_ACTIVELIGHT(0);
- const struct wined3d_light_info *lightInfo = state->lights[Index];
+ const struct wined3d_light_info *lightInfo = state->light_state.lights[Index];
if (!lightInfo)
{
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 5b9ddd0c40..afddd11b75 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -395,7 +395,7 @@ void stateblock_init_contained_states(struct wined3d_stateblock *stateblock)
}
}
-static void stateblock_init_lights(struct wined3d_stateblock *stateblock, struct list *light_map)
+static void stateblock_init_lights(struct list *dst_map, struct list *src_map)
{
unsigned int i;
@@ -403,12 +403,12 @@ static void stateblock_init_lights(struct wined3d_stateblock *stateblock, struct
{
const struct wined3d_light_info *src_light;
- LIST_FOR_EACH_ENTRY(src_light, &light_map[i], struct wined3d_light_info, entry)
+ LIST_FOR_EACH_ENTRY(src_light, &src_map[i], struct wined3d_light_info, entry)
{
struct wined3d_light_info *dst_light = heap_alloc(sizeof(*dst_light));
*dst_light = *src_light;
- list_add_tail(&stateblock->state.light_map[i], &dst_light->entry);
+ list_add_tail(&dst_map[i], &dst_light->entry);
}
}
}
@@ -581,13 +581,13 @@ void state_cleanup(struct wined3d_state *state)
for (counter = 0; counter < MAX_ACTIVE_LIGHTS; ++counter)
{
- state->lights[counter] = NULL;
+ state->light_state.lights[counter] = NULL;
}
for (counter = 0; counter < LIGHTMAP_SIZE; ++counter)
{
struct list *e1, *e2;
- LIST_FOR_EACH_SAFE(e1, e2, &state->light_map[counter])
+ LIST_FOR_EACH_SAFE(e1, e2, &state->light_state.light_map[counter])
{
struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry);
list_remove(&light->entry);
@@ -612,7 +612,7 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
return refcount;
}
-struct wined3d_light_info *wined3d_state_get_light(const struct wined3d_state *state, unsigned int idx)
+struct wined3d_light_info *wined3d_light_state_get_light(const struct wined3d_light_state *state, unsigned int idx)
{
struct wined3d_light_info *light_info;
unsigned int hash_idx;
@@ -627,7 +627,7 @@ struct wined3d_light_info *wined3d_state_get_light(const struct wined3d_state *s
return NULL;
}
-void wined3d_state_enable_light(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info,
+void wined3d_light_state_enable_light(struct wined3d_light_state *state, const struct wined3d_d3d_info *d3d_info,
struct wined3d_light_info *light_info, BOOL enable)
{
unsigned int light_count, i;
@@ -672,7 +672,8 @@ void wined3d_state_enable_light(struct wined3d_state *state, const struct wined3
WARN("Too many concurrently active lights.\n");
}
-static void wined3d_state_record_lights(struct wined3d_state *dst_state, const struct wined3d_state *src_state)
+static void wined3d_state_record_lights(struct wined3d_light_state *dst_state,
+ const struct wined3d_light_state *src_state)
{
const struct wined3d_light_info *src;
struct wined3d_light_info *dst;
@@ -685,7 +686,7 @@ static void wined3d_state_record_lights(struct wined3d_state *dst_state, const s
{
LIST_FOR_EACH_ENTRY(dst, &dst_state->light_map[i], struct wined3d_light_info, entry)
{
- if ((src = wined3d_state_get_light(src_state, dst->OriginalIndex)))
+ if ((src = wined3d_light_state_get_light(src_state, dst->OriginalIndex)))
{
dst->OriginalParms = src->OriginalParms;
@@ -985,7 +986,7 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
stateblock->stateblock_state.ps = state->ps;
}
- wined3d_state_record_lights(&stateblock->state, src_state);
+ wined3d_state_record_lights(&stateblock->state.light_state, &src_state->light_state);
TRACE("Capture done.\n");
}
@@ -1029,11 +1030,11 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock)
1, &stateblock->stateblock_state.vs_consts_b[stateblock->contained_vs_consts_b[i]]);
}
- for (i = 0; i < ARRAY_SIZE(stateblock->state.light_map); ++i)
+ for (i = 0; i < ARRAY_SIZE(stateblock->state.light_state.light_map); ++i)
{
const struct wined3d_light_info *light;
- LIST_FOR_EACH_ENTRY(light, &stateblock->state.light_map[i], struct wined3d_light_info, entry)
+ LIST_FOR_EACH_ENTRY(light, &stateblock->state.light_state.light_map[i], struct wined3d_light_info, entry)
{
wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms);
wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1);
@@ -1454,7 +1455,7 @@ void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
for (i = 0; i < LIGHTMAP_SIZE; i++)
{
- list_init(&state->light_map[i]);
+ list_init(&state->light_state.light_map[i]);
}
if (flags & WINED3D_STATE_INIT_DEFAULT)
@@ -1520,7 +1521,7 @@ static HRESULT stateblock_init(struct wined3d_stateblock *stateblock,
switch (type)
{
case WINED3D_SBT_ALL:
- stateblock_init_lights(stateblock, device->state.light_map);
+ stateblock_init_lights(stateblock->state.light_state.light_map, device->state.light_state.light_map);
stateblock_savedstates_set_all(&stateblock->changed,
d3d_info->limits.vs_uniform_count, d3d_info->limits.ps_uniform_count);
break;
@@ -1531,7 +1532,7 @@ static HRESULT stateblock_init(struct wined3d_stateblock *stateblock,
break;
case WINED3D_SBT_VERTEX_STATE:
- stateblock_init_lights(stateblock, device->state.light_map);
+ stateblock_init_lights(stateblock->state.light_state.light_map, device->state.light_state.light_map);
stateblock_savedstates_set_vertex(&stateblock->changed,
d3d_info->limits.vs_uniform_count);
break;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 7b42202213..54e3b1031a 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -6281,10 +6281,10 @@ void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
{
- if (!state->lights[i])
+ if (!state->light_state.lights[i])
continue;
- switch (state->lights[i]->OriginalParms.type)
+ switch (state->light_state.lights[i]->OriginalParms.type)
{
case WINED3D_LIGHT_POINT:
++settings->point_light_count;
@@ -6299,7 +6299,7 @@ void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
++settings->parallel_point_light_count;
break;
default:
- FIXME("Unhandled light type %#x.\n", state->lights[i]->OriginalParms.type);
+ FIXME("Unhandled light type %#x.\n", state->light_state.lights[i]->OriginalParms.type);
break;
}
}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 07d77011f1..3544bfa512 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2888,6 +2888,16 @@ struct wined3d_stream_state
UINT flags;
};
+#define LIGHTMAP_SIZE 43
+#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE)
+
+struct wined3d_light_state
+{
+ /* Light hashmap. Collisions are handled using linked lists. */
+ struct list light_map[LIGHTMAP_SIZE];
+ const struct wined3d_light_info *lights[MAX_ACTIVE_LIGHTS];
+};
+
#define WINED3D_STATE_NO_REF 0x00000001
#define WINED3D_STATE_INIT_DEFAULT 0x00000002
@@ -2935,11 +2945,7 @@ struct wined3d_state
RECT scissor_rects[WINED3D_MAX_VIEWPORTS];
unsigned int scissor_rect_count;
- /* Light hashmap. Collisions are handled using linked lists. */
-#define LIGHTMAP_SIZE 43
-#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE)
- struct list light_map[LIGHTMAP_SIZE];
- const struct wined3d_light_info *lights[MAX_ACTIVE_LIGHTS];
+ struct wined3d_light_state light_state;
DWORD render_states[WINEHIGHEST_RENDER_STATE + 1];
struct wined3d_blend_state *blend_state;
@@ -3626,11 +3632,12 @@ void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state,
const struct wined3d_device *device, DWORD flags) DECLSPEC_HIDDEN;
void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) DECLSPEC_HIDDEN;
-void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
-void wined3d_state_enable_light(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info,
+void wined3d_light_state_enable_light(struct wined3d_light_state *state, const struct wined3d_d3d_info *d3d_info,
struct wined3d_light_info *light_info, BOOL enable) DECLSPEC_HIDDEN;
-struct wined3d_light_info *wined3d_state_get_light(const struct wined3d_state *state,
+struct wined3d_light_info *wined3d_light_state_get_light(const struct wined3d_light_state *state,
unsigned int idx) DECLSPEC_HIDDEN;
+
+void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
const struct wined3d_d3d_info *d3d_info, DWORD flags) DECLSPEC_HIDDEN;
void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN;
--
2.20.1
More information about the wine-devel
mailing list