Commit 4546a13d authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move light state to wined3d_state.

parent f4df53c4
...@@ -2546,7 +2546,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLight(IWineD3DDevice *iface, DWORD I ...@@ -2546,7 +2546,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLight(IWineD3DDevice *iface, DWORD I
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) LIST_FOR_EACH(e, &This->updateStateBlock->state.light_map[Hi])
{ {
object = LIST_ENTRY(e, struct wined3d_light_info, entry); object = LIST_ENTRY(e, struct wined3d_light_info, entry);
if(object->OriginalIndex == Index) break; if(object->OriginalIndex == Index) break;
...@@ -2560,7 +2560,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLight(IWineD3DDevice *iface, DWORD I ...@@ -2560,7 +2560,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLight(IWineD3DDevice *iface, DWORD I
ERR("Out of memory error when allocating a light\n"); ERR("Out of memory error when allocating a light\n");
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
list_add_head(&This->updateStateBlock->lightMap[Hi], &object->entry); list_add_head(&This->updateStateBlock->state.light_map[Hi], &object->entry);
object->glIndex = -1; object->glIndex = -1;
object->OriginalIndex = Index; object->OriginalIndex = Index;
} }
...@@ -2659,7 +2659,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetLight(IWineD3DDevice *iface, DWORD I ...@@ -2659,7 +2659,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetLight(IWineD3DDevice *iface, DWORD I
struct list *e; struct list *e;
TRACE("(%p) : Idx(%d), pLight(%p)\n", This, Index, pLight); TRACE("(%p) : Idx(%d), pLight(%p)\n", This, Index, pLight);
LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi]) LIST_FOR_EACH(e, &This->stateBlock->state.light_map[Hi])
{ {
lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry); lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
if(lightInfo->OriginalIndex == Index) break; if(lightInfo->OriginalIndex == Index) break;
...@@ -2688,7 +2688,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D ...@@ -2688,7 +2688,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
struct list *e; struct list *e;
TRACE("(%p) : Idx(%d), enable? %d\n", This, Index, Enable); TRACE("(%p) : Idx(%d), enable? %d\n", This, Index, Enable);
LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) LIST_FOR_EACH(e, &This->updateStateBlock->state.light_map[Hi])
{ {
lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry); lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
if(lightInfo->OriginalIndex == Index) break; if(lightInfo->OriginalIndex == Index) break;
...@@ -2703,7 +2703,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D ...@@ -2703,7 +2703,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
IWineD3DDeviceImpl_SetLight(iface, Index, &WINED3D_default_light); IWineD3DDeviceImpl_SetLight(iface, Index, &WINED3D_default_light);
/* Search for it again! Should be fairly quick as near head of list */ /* Search for it again! Should be fairly quick as near head of list */
LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) LIST_FOR_EACH(e, &This->updateStateBlock->state.light_map[Hi])
{ {
lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry); lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
if(lightInfo->OriginalIndex == Index) break; if(lightInfo->OriginalIndex == Index) break;
...@@ -2722,7 +2722,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D ...@@ -2722,7 +2722,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(lightInfo->glIndex)); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(lightInfo->glIndex));
} }
This->updateStateBlock->activeLights[lightInfo->glIndex] = NULL; This->updateStateBlock->state.lights[lightInfo->glIndex] = NULL;
lightInfo->glIndex = -1; lightInfo->glIndex = -1;
} else { } else {
TRACE("Light already disabled, nothing to do\n"); TRACE("Light already disabled, nothing to do\n");
...@@ -2738,9 +2738,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D ...@@ -2738,9 +2738,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
/* Find a free gl light */ /* Find a free gl light */
for (i = 0; i < This->maxConcurrentLights; ++i) for (i = 0; i < This->maxConcurrentLights; ++i)
{ {
if (!This->updateStateBlock->activeLights[i]) if (!This->updateStateBlock->state.lights[i])
{ {
This->updateStateBlock->activeLights[i] = lightInfo; This->updateStateBlock->state.lights[i] = lightInfo;
lightInfo->glIndex = i; lightInfo->glIndex = i;
break; break;
} }
...@@ -2775,7 +2775,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetLightEnable(IWineD3DDevice *iface, D ...@@ -2775,7 +2775,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetLightEnable(IWineD3DDevice *iface, D
UINT Hi = LIGHTMAP_HASHFUNC(Index); UINT Hi = LIGHTMAP_HASHFUNC(Index);
TRACE("(%p) : for idx(%d)\n", This, Index); TRACE("(%p) : for idx(%d)\n", This, Index);
LIST_FOR_EACH(e, &This->stateBlock->lightMap[Hi]) LIST_FOR_EACH(e, &This->stateBlock->state.light_map[Hi])
{ {
lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry); lightInfo = LIST_ENTRY(e, struct wined3d_light_info, entry);
if(lightInfo->OriginalIndex == Index) break; if(lightInfo->OriginalIndex == Index) break;
......
...@@ -3938,7 +3938,7 @@ static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, stru ...@@ -3938,7 +3938,7 @@ static void transform_view(DWORD state, IWineD3DStateBlockImpl *stateblock, stru
/* Reset lights. TODO: Call light apply func */ /* Reset lights. TODO: Call light apply func */
for (k = 0; k < stateblock->device->maxConcurrentLights; ++k) for (k = 0; k < stateblock->device->maxConcurrentLights; ++k)
{ {
light = stateblock->activeLights[k]; light = stateblock->state.lights[k];
if(!light) continue; if(!light) continue;
glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn); glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, light->lightPosn);
checkGLcall("glLightfv posn"); checkGLcall("glLightfv posn");
...@@ -4812,7 +4812,7 @@ static void viewport_vertexpart(DWORD state, IWineD3DStateBlockImpl *stateblock, ...@@ -4812,7 +4812,7 @@ static void viewport_vertexpart(DWORD state, IWineD3DStateBlockImpl *stateblock,
static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context) static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
{ {
UINT Index = state - STATE_ACTIVELIGHT(0); UINT Index = state - STATE_ACTIVELIGHT(0);
const struct wined3d_light_info *lightInfo = stateblock->activeLights[Index]; const struct wined3d_light_info *lightInfo = stateblock->state.lights[Index];
if(!lightInfo) { if(!lightInfo) {
glDisable(GL_LIGHT0 + Index); glDisable(GL_LIGHT0 + Index);
......
...@@ -452,7 +452,7 @@ static void stateblock_init_lights(IWineD3DStateBlockImpl *stateblock, struct li ...@@ -452,7 +452,7 @@ static void stateblock_init_lights(IWineD3DStateBlockImpl *stateblock, struct li
struct wined3d_light_info *dst_light = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_light)); struct wined3d_light_info *dst_light = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_light));
*dst_light = *src_light; *dst_light = *src_light;
list_add_tail(&stateblock->lightMap[i], &dst_light->entry); list_add_tail(&stateblock->state.light_map[i], &dst_light->entry);
} }
} }
} }
...@@ -518,7 +518,7 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) { ...@@ -518,7 +518,7 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
for(counter = 0; counter < LIGHTMAP_SIZE; counter++) { for(counter = 0; counter < LIGHTMAP_SIZE; counter++) {
struct list *e1, *e2; struct list *e1, *e2;
LIST_FOR_EACH_SAFE(e1, e2, &This->lightMap[counter]) LIST_FOR_EACH_SAFE(e1, e2, &This->state.light_map[counter])
{ {
struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry); struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry);
list_remove(&light->entry); list_remove(&light->entry);
...@@ -549,12 +549,14 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock ...@@ -549,12 +549,14 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock
*/ */
for(i = 0; i < LIGHTMAP_SIZE; i++) { for(i = 0; i < LIGHTMAP_SIZE; i++) {
struct list *e, *f; struct list *e, *f;
LIST_FOR_EACH(e, &This->lightMap[i]) { LIST_FOR_EACH(e, &This->state.light_map[i])
{
BOOL updated = FALSE; BOOL updated = FALSE;
struct wined3d_light_info *src = LIST_ENTRY(e, struct wined3d_light_info, entry), *realLight; struct wined3d_light_info *src = LIST_ENTRY(e, struct wined3d_light_info, entry), *realLight;
/* Look up the light in the destination */ /* Look up the light in the destination */
LIST_FOR_EACH(f, &targetStateBlock->lightMap[i]) { LIST_FOR_EACH(f, &targetStateBlock->state.light_map[i])
{
realLight = LIST_ENTRY(f, struct wined3d_light_info, entry); realLight = LIST_ENTRY(f, struct wined3d_light_info, entry);
if (realLight->OriginalIndex == src->OriginalIndex) if (realLight->OriginalIndex == src->OriginalIndex)
{ {
...@@ -563,12 +565,12 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock ...@@ -563,12 +565,12 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock
if (realLight->glIndex == -1 && src->glIndex != -1) if (realLight->glIndex == -1 && src->glIndex != -1)
{ {
/* Light disabled */ /* Light disabled */
This->activeLights[src->glIndex] = NULL; This->state.lights[src->glIndex] = NULL;
} }
else if (realLight->glIndex != -1 && src->glIndex == -1) else if (realLight->glIndex != -1 && src->glIndex == -1)
{ {
/* Light enabled */ /* Light enabled */
This->activeLights[realLight->glIndex] = src; This->state.lights[realLight->glIndex] = src;
} }
src->glIndex = realLight->glIndex; src->glIndex = realLight->glIndex;
updated = TRUE; updated = TRUE;
...@@ -586,7 +588,7 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock ...@@ -586,7 +588,7 @@ static void record_lights(IWineD3DStateBlockImpl *This, const IWineD3DStateBlock
src->OriginalParms = WINED3D_default_light; src->OriginalParms = WINED3D_default_light;
if (src->glIndex != -1) if (src->glIndex != -1)
{ {
This->activeLights[src->glIndex] = NULL; This->state.lights[src->glIndex] = NULL;
src->glIndex = -1; src->glIndex = -1;
} }
} }
...@@ -896,7 +898,7 @@ static void apply_lights(IWineD3DDevice *device, const IWineD3DStateBlockImpl *T ...@@ -896,7 +898,7 @@ static void apply_lights(IWineD3DDevice *device, const IWineD3DStateBlockImpl *T
for(i = 0; i < LIGHTMAP_SIZE; i++) { for(i = 0; i < LIGHTMAP_SIZE; i++) {
struct list *e; struct list *e;
LIST_FOR_EACH(e, &This->lightMap[i]) LIST_FOR_EACH(e, &This->state.light_map[i])
{ {
const struct wined3d_light_info *light = LIST_ENTRY(e, struct wined3d_light_info, entry); const struct wined3d_light_info *light = LIST_ENTRY(e, struct wined3d_light_info, entry);
...@@ -1371,7 +1373,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl * ...@@ -1371,7 +1373,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl *
for (i = 0; i < LIGHTMAP_SIZE; i++) for (i = 0; i < LIGHTMAP_SIZE; i++)
{ {
list_init(&stateblock->lightMap[i]); list_init(&stateblock->state.light_map[i]);
} }
hr = stateblock_allocate_shader_constants(stateblock); hr = stateblock_allocate_shader_constants(stateblock);
...@@ -1387,7 +1389,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl * ...@@ -1387,7 +1389,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl *
switch (type) switch (type)
{ {
case WINED3DSBT_ALL: case WINED3DSBT_ALL:
stateblock_init_lights(stateblock, device->stateBlock->lightMap); stateblock_init_lights(stateblock, device->stateBlock->state.light_map);
stateblock_savedstates_set_all(&stateblock->changed, device->d3d_vshader_constantF, stateblock_savedstates_set_all(&stateblock->changed, device->d3d_vshader_constantF,
device->d3d_pshader_constantF); device->d3d_pshader_constantF);
break; break;
...@@ -1397,7 +1399,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl * ...@@ -1397,7 +1399,7 @@ HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock, IWineD3DDeviceImpl *
break; break;
case WINED3DSBT_VERTEXSTATE: case WINED3DSBT_VERTEXSTATE:
stateblock_init_lights(stateblock, device->stateBlock->lightMap); stateblock_init_lights(stateblock, device->stateBlock->state.light_map);
stateblock_savedstates_set_vertex(&stateblock->changed, device->d3d_vshader_constantF); stateblock_savedstates_set_vertex(&stateblock->changed, device->d3d_vshader_constantF);
break; break;
......
...@@ -2378,6 +2378,12 @@ struct wined3d_state ...@@ -2378,6 +2378,12 @@ struct wined3d_state
WINED3DVIEWPORT viewport; WINED3DVIEWPORT viewport;
RECT scissor_rect; RECT scissor_rect;
/* Light hashmap . Collisions are handled using standard wine double linked lists */
#define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
struct list light_map[LIGHTMAP_SIZE]; /* Hash map containing the lights */
const struct wined3d_light_info *lights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
DWORD render_states[WINEHIGHEST_RENDER_STATE + 1]; DWORD render_states[WINEHIGHEST_RENDER_STATE + 1];
}; };
...@@ -2395,12 +2401,6 @@ struct IWineD3DStateBlockImpl ...@@ -2395,12 +2401,6 @@ struct IWineD3DStateBlockImpl
SAVEDSTATES changed; SAVEDSTATES changed;
struct wined3d_state state; struct wined3d_state state;
/* Light hashmap . Collisions are handled using standard wine double linked lists */
#define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
struct list lightMap[LIGHTMAP_SIZE]; /* Hash map containing the lights */
const struct wined3d_light_info *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
/* Clipping */ /* Clipping */
double clipplane[MAX_CLIPPLANES][4]; double clipplane[MAX_CLIPPLANES][4];
WINED3DCLIPSTATUS clip_status; WINED3DCLIPSTATUS clip_status;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment