change lighting to use MULT instead of PREMULT (i.e. move some lighting color calcula...
authorRoland Scheidegger <rscheidegger@gmx.ch>
Tue, 10 Feb 2004 23:52:18 +0000 (23:52 +0000)
committerRoland Scheidegger <rscheidegger@gmx.ch>
Tue, 10 Feb 2004 23:52:18 +0000 (23:52 +0000)
src/mesa/drivers/dri/radeon/radeon_state.c
src/mesa/drivers/dri/radeon/radeon_state_init.c

index 53537363fcf1cfeb94739902193ed8a9fa3cfdc8..c4ce6b1007d09140350369cc3bbbc3443bae1f54 100644 (file)
@@ -773,6 +773,7 @@ static void update_global_ambient( GLcontext *ctx )
    float *fcmd = (float *)RADEON_DB_STATE( glt );
 
    /* Need to do more if both emmissive & ambient are PREMULT:
+    * Hope this is not needed for MULT
     */
    if ((rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] &
        ((3 << RADEON_EMISSIVE_SOURCE_SHIFT) |
@@ -795,9 +796,6 @@ static void update_global_ambient( GLcontext *ctx )
 /* Update on change to 
  *    - light[p].colors
  *    - light[p].enabled
- *    - material,
- *    - colormaterial enabled
- *    - colormaterial bitmask
  */
 static void update_light_colors( GLcontext *ctx, GLuint p )
 {
@@ -808,25 +806,11 @@ static void update_light_colors( GLcontext *ctx, GLuint p )
    if (l->Enabled) {
       radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
       float *fcmd = (float *)RADEON_DB_STATE( lit[p] );
-      GLuint bitmask = ctx->Light.ColorMaterialBitmask;
-      GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
 
       COPY_4V( &fcmd[LIT_AMBIENT_RED], l->Ambient );    
       COPY_4V( &fcmd[LIT_DIFFUSE_RED], l->Diffuse );
       COPY_4V( &fcmd[LIT_SPECULAR_RED], l->Specular );
       
-      if (!ctx->Light.ColorMaterialEnabled)
-        bitmask = 0;
-
-      if ((bitmask & MAT_BIT_FRONT_AMBIENT) == 0) 
-        SELF_SCALE_3V( &fcmd[LIT_AMBIENT_RED], mat[MAT_ATTRIB_FRONT_AMBIENT] );
-
-      if ((bitmask & MAT_BIT_FRONT_DIFFUSE) == 0) 
-        SELF_SCALE_3V( &fcmd[LIT_DIFFUSE_RED], mat[MAT_ATTRIB_FRONT_DIFFUSE] );
-      
-      if ((bitmask & MAT_BIT_FRONT_SPECULAR) == 0) 
-        SELF_SCALE_3V( &fcmd[LIT_SPECULAR_RED], mat[MAT_ATTRIB_FRONT_SPECULAR] );
-
       RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.lit[p] );
    }
 }
@@ -860,51 +844,66 @@ static void check_twoside_fallback( GLcontext *ctx )
 
 static void radeonColorMaterial( GLcontext *ctx, GLenum face, GLenum mode )
 {
-   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 (ctx->Light.ColorMaterialEnabled) {
+      GLuint mask = ctx->Light.ColorMaterialBitmask;
+
       if (mask & MAT_BIT_FRONT_EMISSION) {
         light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE <<
                             RADEON_EMISSIVE_SOURCE_SHIFT);
       }
+      else {
+        light_model_ctl1 |= (RADEON_LM_SOURCE_STATE_MULT <<
+                            RADEON_EMISSIVE_SOURCE_SHIFT);
+      }
 
       if (mask & MAT_BIT_FRONT_AMBIENT) {
         light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE <<
                             RADEON_AMBIENT_SOURCE_SHIFT);
       }
+      else {
+        light_model_ctl1 |= (RADEON_LM_SOURCE_STATE_MULT <<
+                            RADEON_AMBIENT_SOURCE_SHIFT);
+      }
         
       if (mask & MAT_BIT_FRONT_DIFFUSE) {
         light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE <<
                             RADEON_DIFFUSE_SOURCE_SHIFT);
       }
+      else {
+        light_model_ctl1 |= (RADEON_LM_SOURCE_STATE_MULT <<
+                            RADEON_DIFFUSE_SOURCE_SHIFT);
+      }
    
       if (mask & MAT_BIT_FRONT_SPECULAR) {
         light_model_ctl1 |= (RADEON_LM_SOURCE_VERTEX_DIFFUSE <<
                             RADEON_SPECULAR_SOURCE_SHIFT);
       }
+      else {
+        light_model_ctl1 |= (RADEON_LM_SOURCE_STATE_MULT <<
+                            RADEON_SPECULAR_SOURCE_SHIFT);
+      }
+   }
+   else {
+   /* Default to MULT:
+    */
+      light_model_ctl1 |= (RADEON_LM_SOURCE_STATE_MULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
+                  (RADEON_LM_SOURCE_STATE_MULT << RADEON_AMBIENT_SOURCE_SHIFT) |
+                  (RADEON_LM_SOURCE_STATE_MULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
+                  (RADEON_LM_SOURCE_STATE_MULT << 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 );
-      }
    }
-   
-   check_twoside_fallback( ctx );
 }
 
 void radeonUpdateMaterial( GLcontext *ctx )
@@ -912,7 +911,6 @@ void radeonUpdateMaterial( GLcontext *ctx )
    radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
    GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
    GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( mtl );
-   GLuint p;
    GLuint mask = ~0;
    
    if (ctx->Light.ColorMaterialEnabled)
@@ -952,11 +950,8 @@ void radeonUpdateMaterial( GLcontext *ctx )
 
    RADEON_DB_STATECHANGE( rmesa, &rmesa->hw.mtl );
 
-   for (p = 0 ; p < MAX_LIGHTS; p++)
-      update_light_colors( ctx, p );
-
    check_twoside_fallback( ctx );
-   update_global_ambient( ctx );
+/*   update_global_ambient( ctx );*/
 }
 
 /* _NEW_LIGHT
index ceb313a7e712b7b5b4d68423958e3eaa468b9994..c84f5fd833cee1896cca0cda7b821d867c27f8cd 100644 (file)
@@ -499,10 +499,10 @@ void radeonInitState( radeonContextPtr rmesa )
       (RADEON_SPECULAR_LIGHTS |
        RADEON_DIFFUSE_SPECULAR_COMBINE |
        RADEON_LOCAL_LIGHT_VEC_GL |
-       (RADEON_LM_SOURCE_STATE_PREMULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
-       (RADEON_LM_SOURCE_STATE_PREMULT << RADEON_AMBIENT_SOURCE_SHIFT) |
-       (RADEON_LM_SOURCE_STATE_PREMULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
-       (RADEON_LM_SOURCE_STATE_PREMULT << RADEON_SPECULAR_SOURCE_SHIFT)); 
+       (RADEON_LM_SOURCE_STATE_MULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
+       (RADEON_LM_SOURCE_STATE_MULT << RADEON_AMBIENT_SOURCE_SHIFT) |
+       (RADEON_LM_SOURCE_STATE_MULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
+       (RADEON_LM_SOURCE_STATE_MULT << RADEON_SPECULAR_SOURCE_SHIFT));
 
    for (i = 0 ; i < 8; i++) {
       struct gl_light *l = &ctx->Light.Light[i];