gallium: fix update_textures() bug in pipe_texture binding logic
[mesa.git] / src / mesa / shader / prog_statevars.c
index 8b4903ea01266a41df7cacf13e318b14e215541c..6cc490bc7735d909b1772bfea41b8f6ebdd1d47c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.0
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
@@ -121,17 +121,17 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
             return;
          case STATE_HALF_VECTOR:
             {
-               GLfloat eye_z[] = {0, 0, 1};
-                                       
+               static const GLfloat eye_z[] = {0, 0, 1};
+               GLfloat p[3];
                /* Compute infinite half angle vector:
-                *   half-vector = light_position + (0, 0, 1) 
-                * and then normalize.  w = 0
-               *
+                *   halfVector = normalize(normalize(lightPos) + (0, 0, 1))
                * light.EyePosition.w should be 0 for infinite lights.
                 */
-              ADD_3V(value, eye_z, ctx->Light.Light[ln].EyePosition);
+               COPY_3V(p, ctx->Light.Light[ln].EyePosition);
+               NORMALIZE_3FV(p);
+              ADD_3V(value, p, eye_z);
               NORMALIZE_3FV(value);
-              value[3] = 0;
+              value[3] = 1.0;
             }                                            
             return;
         case STATE_POSITION_NORMALIZED:
@@ -278,14 +278,13 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
    case STATE_MVP_MATRIX:
    case STATE_TEXTURE_MATRIX:
    case STATE_PROGRAM_MATRIX:
-      /*case STATE_MATRIX:*/
+   case STATE_COLOR_MATRIX:
       {
-         /* state[1] = modelview, projection, texture, etc. */
-         /* state[2] = which texture matrix or program matrix */
-         /* state[3] = first row to fetch */
-         /* state[4] = last row to fetch */
-         /* state[5] = transpose, inverse or invtrans */
-
+         /* state[0] = modelview, projection, texture, etc. */
+         /* state[1] = which texture matrix or program matrix */
+         /* state[2] = first row to fetch */
+         /* state[3] = last row to fetch */
+         /* state[4] = transpose, inverse or invtrans */
          const GLmatrix *matrix;
          const gl_state_index mat = state[0];
          const GLuint index = (GLuint) state[1];
@@ -313,6 +312,9 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
          else if (mat == STATE_PROGRAM_MATRIX) {
             matrix = ctx->ProgramMatrixStack[index].Top;
          }
+         else if (mat == STATE_COLOR_MATRIX) {
+            matrix = ctx->ColorMatrixStack.Top;
+         }
          else {
             _mesa_problem(ctx, "Bad matrix name in _mesa_fetch_state()");
             return;
@@ -436,6 +438,18 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
          value[3] = ctx->Light.Light[ln]._CosCutoff;
          return;
       }
+      case STATE_PT_SCALE:
+         value[0] = ctx->Pixel.RedScale;
+         value[1] = ctx->Pixel.GreenScale;
+         value[2] = ctx->Pixel.BlueScale;
+         value[3] = ctx->Pixel.AlphaScale;
+         break;
+      case STATE_PT_BIAS:
+         value[0] = ctx->Pixel.RedBias;
+         value[1] = ctx->Pixel.GreenBias;
+         value[2] = ctx->Pixel.BlueBias;
+         value[3] = ctx->Pixel.AlphaBias;
+         break;
       default:
          /* unknown state indexes are silently ignored
           *  should be handled by the driver.
@@ -494,6 +508,8 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
       return _NEW_TEXTURE_MATRIX;
    case STATE_PROGRAM_MATRIX:
       return _NEW_TRACK_MATRIX;
+   case STATE_COLOR_MATRIX:
+      return _NEW_COLOR_MATRIX;
 
    case STATE_DEPTH_RANGE:
       return _NEW_VIEWPORT;
@@ -509,6 +525,8 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
       switch (state[1]) {
       case STATE_TEXRECT_SCALE:
         return _NEW_TEXTURE;
+      case STATE_FOG_PARAMS_OPTIMIZED:
+        return _NEW_FOG;
       default:
          /* unknown state indexes are silently ignored and
          *  no flag set, since it is handled by the driver.
@@ -585,6 +603,9 @@ append_token(char *dst, gl_state_index k)
    case STATE_PROGRAM_MATRIX:
       append(dst, "matrix.program");
       break;
+   case STATE_COLOR_MATRIX:
+      append(dst, "matrix.color");
+      break;
    case STATE_MATRIX_INVERSE:
       append(dst, ".inverse");
       break;
@@ -670,6 +691,12 @@ append_token(char *dst, gl_state_index k)
    case STATE_POSITION_NORMALIZED:
       append(dst, "(internal)");
       break;
+   case STATE_PT_SCALE:
+      append(dst, "PTscale");
+      break;
+   case STATE_PT_BIAS:
+      append(dst, "PTbias");
+      break;
    default:
       ;
    }
@@ -748,6 +775,7 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
    case STATE_MVP_MATRIX:
    case STATE_TEXTURE_MATRIX:
    case STATE_PROGRAM_MATRIX:
+   case STATE_COLOR_MATRIX:
       {
          /* state[0] = modelview, projection, texture, etc. */
          /* state[1] = which texture matrix or program matrix */
@@ -815,6 +843,8 @@ _mesa_load_state_parameters(GLcontext *ctx,
    if (!paramList)
       return;
 
+   /*assert(ctx->Driver.NeedFlush == 0);*/
+
    for (i = 0; i < paramList->NumParameters; i++) {
       if (paramList->Parameters[i].Type == PROGRAM_STATE_VAR) {
          _mesa_fetch_state(ctx,