here's a patch which fixes all remaining lighting problems (well those I could see at a glance) with NWN on r200 (likely also fixes the same bugs on radeon, untested). (I mentioned these problems earlier, the almost black target indicator, the almost black (instead of blue) portals, the main character didn't shine.)
I think the patch is pretty self-explanatory (basically if a color material is enabled the light model changes, but it will never change back when the material is disabled again), except I've also removed the unnecessary calls to update_light_colors (and friends) (I believe they were necessary before the recent other lighting fixes, don't worry they still get called a bazillion of times, since r200/radeonColorMaterial is only called when r200/radeonUpdateMaterial is called right after that it should be really safe to remove these calls.)
nwn is still a bit slow though, I'm working on that ;-).
Roland
P.S: Hoping this message appears on the list sometime before April 2005 or so, this <censored> mailserver is such a POS.
P.P.S: Is someone going to apply the texstate fixes (required for texrect), I can't keep track of all those changes here...
Index: radeon_state.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/radeon/radeon_state.c,v retrieving revision 1.13 diff -u -r1.13 radeon_state.c --- radeon_state.c 28 Jan 2004 17:35:49 -0000 1.13 +++ radeon_state.c 30 Jan 2004 22:52:16 -0000 @@ -859,18 +859,19 @@ static void radeonColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) { + radeonContextPtr rmesa = RADEON_CONTEXT(ctx); + GLuint light_model_ctl1 = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]; + + /* Default to PREMULT: + */ + light_model_ctl1 &= ~((3 << RADEON_EMISSIVE_SOURCE_SHIFT) | + (3 << RADEON_AMBIENT_SOURCE_SHIFT) | + (3 << RADEON_DIFFUSE_SOURCE_SHIFT) | + (3 << RADEON_SPECULAR_SOURCE_SHIFT)); + if (ctx->Light.ColorMaterialEnabled) { - radeonContextPtr rmesa = RADEON_CONTEXT(ctx); - GLuint light_model_ctl1 = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]; GLuint mask = ctx->Light.ColorMaterialBitmask; - /* Default to PREMULT: - */ - light_model_ctl1 &= ~((3 << RADEON_EMISSIVE_SOURCE_SHIFT) | - (3 << RADEON_AMBIENT_SOURCE_SHIFT) | - (3 << RADEON_DIFFUSE_SOURCE_SHIFT) | - (3 << RADEON_SPECULAR_SOURCE_SHIFT)); - if (mask & MAT_BIT_FRONT_EMISSION) { light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << RADEON_EMISSIVE_SOURCE_SHIFT); @@ -890,20 +891,12 @@ light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE << RADEON_SPECULAR_SOURCE_SHIFT); } - - if (light_model_ctl1 != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]) { - GLuint p; - - RADEON_STATECHANGE( rmesa, tcl ); - rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] = light_model_ctl1; + } - for (p = 0 ; p < MAX_LIGHTS; p++) - update_light_colors( ctx, p ); - update_global_ambient( ctx ); - } + if (light_model_ctl1 != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL]) { + RADEON_STATECHANGE( rmesa, tcl ); + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] = light_model_ctl1; } - - check_twoside_fallback( ctx ); } void radeonUpdateMaterial( GLcontext *ctx )
Index: r200_state.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_state.c,v retrieving revision 1.13 diff -u -r1.13 r200_state.c --- r200_state.c 27 Jan 2004 18:52:40 -0000 1.13 +++ r200_state.c 30 Jan 2004 22:53:03 -0000 @@ -872,18 +872,20 @@ static void r200ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) { + r200ContextPtr rmesa = R200_CONTEXT(ctx); + GLuint light_model_ctl1 = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1]; + + /* Default to PREMULT: + */ + light_model_ctl1 &= ~((0xf << R200_FRONT_EMISSIVE_SOURCE_SHIFT) | + (0xf << R200_FRONT_AMBIENT_SOURCE_SHIFT) | + (0xf << R200_FRONT_DIFFUSE_SOURCE_SHIFT) | + (0xf << R200_FRONT_SPECULAR_SOURCE_SHIFT)); + + if (ctx->Light.ColorMaterialEnabled) { - r200ContextPtr rmesa = R200_CONTEXT(ctx); - GLuint light_model_ctl1 = rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1]; GLuint mask = ctx->Light.ColorMaterialBitmask; - /* Default to PREMULT: - */ - light_model_ctl1 &= ~((0xf << R200_FRONT_EMISSIVE_SOURCE_SHIFT) | - (0xf << R200_FRONT_AMBIENT_SOURCE_SHIFT) | - (0xf << R200_FRONT_DIFFUSE_SOURCE_SHIFT) | - (0xf << R200_FRONT_SPECULAR_SOURCE_SHIFT)); - if (mask & MAT_BIT_FRONT_EMISSION) { light_model_ctl1 |= (R200_LM1_SOURCE_VERTEX_COLOR_0 << R200_FRONT_EMISSIVE_SOURCE_SHIFT); @@ -903,20 +905,12 @@ light_model_ctl1 |= (R200_LM1_SOURCE_VERTEX_COLOR_0 << R200_FRONT_SPECULAR_SOURCE_SHIFT); } - - if (light_model_ctl1 != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1]) { - GLuint p; - - R200_STATECHANGE( rmesa, tcl ); - rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1] = light_model_ctl1; - - for (p = 0 ; p < MAX_LIGHTS; p++) - update_light_colors( ctx, p ); - update_global_ambient( ctx ); - } } - check_twoside_fallback( ctx ); + if (light_model_ctl1 != rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1]) { + R200_STATECHANGE( rmesa, tcl ); + rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL_1] = light_model_ctl1; + } } void r200UpdateMaterial( GLcontext *ctx )