slang: Use _mesa_snprintf() wrapper.
[mesa.git] / src / mesa / shader / prog_statevars.c
index 971eb25a4918dcfe09891556cc3947d95a8a0f1f..f51d9e265129b7b230100bd588896aa27e1e406d 100644 (file)
@@ -206,28 +206,28 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
          /* state[2] is the texgen attribute */
          switch (state[2]) {
          case STATE_TEXGEN_EYE_S:
-            COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneS);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenS.EyePlane);
             return;
          case STATE_TEXGEN_EYE_T:
-            COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneT);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenT.EyePlane);
             return;
          case STATE_TEXGEN_EYE_R:
-            COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneR);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenR.EyePlane);
             return;
          case STATE_TEXGEN_EYE_Q:
-            COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneQ);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenQ.EyePlane);
             return;
          case STATE_TEXGEN_OBJECT_S:
-            COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneS);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenS.ObjectPlane);
             return;
          case STATE_TEXGEN_OBJECT_T:
-            COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneT);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenT.ObjectPlane);
             return;
          case STATE_TEXGEN_OBJECT_R:
-            COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneR);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenR.ObjectPlane);
             return;
          case STATE_TEXGEN_OBJECT_Q:
-            COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneQ);
+            COPY_4V(value, ctx->Texture.Unit[unit].GenQ.ObjectPlane);
             return;
          default:
             _mesa_problem(ctx, "Invalid texgen state in fetch_state");
@@ -395,6 +395,12 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
 
    case STATE_INTERNAL:
       switch (state[1]) {
+      case STATE_CURRENT_ATTRIB: {
+         const GLuint idx = (GLuint) state[2];
+         COPY_4V(value, ctx->Current.Attrib[idx]);
+         return;
+      }                                                  
+
       case STATE_NORMAL_SCALE:
          ASSIGN_4V(value, 
                    ctx->_ModelViewInvScale, 
@@ -493,14 +499,37 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
             const struct gl_texture_object *texObj
                = ctx->Texture.Unit[unit]._Current;
             if (texObj) {
-               value[0] = texObj->ShadowAmbient;
-               value[1] = texObj->ShadowAmbient;
-               value[2] = texObj->ShadowAmbient;
-               value[3] = texObj->ShadowAmbient;
+               value[0] =
+               value[1] =
+               value[2] =
+               value[3] = texObj->CompareFailValue;
             }
          }
          return;
+      case STATE_ROT_MATRIX_0:
+         {
+            const int unit = (int) state[2];
+            GLfloat *rotMat22 = ctx->Texture.Unit[unit].RotMatrix;
+            value[0] = rotMat22[0]; 
+            value[1] = rotMat22[2];
+            value[2] = 0.0;
+            value[3] = 0.0;
+         }
+         break;
+      case STATE_ROT_MATRIX_1:
+         {
+            const int unit = (int) state[2];
+            GLfloat *rotMat22 = ctx->Texture.Unit[unit].RotMatrix;
+            value[0] = rotMat22[1];
+            value[1] = rotMat22[3];
+            value[2] = 0.0;
+            value[3] = 0.0;
+         }
+         break;
 
+         /* XXX: make sure new tokens added here are also handled in the 
+          * _mesa_program_state_flags() switch, below.
+          */
       default:
          /* unknown state indexes are silently ignored
           *  should be handled by the driver.
@@ -574,11 +603,31 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
 
    case STATE_INTERNAL:
       switch (state[1]) {
+      case STATE_CURRENT_ATTRIB:
+         return _NEW_CURRENT_ATTRIB;
+
+      case STATE_NORMAL_SCALE:
+         return _NEW_MODELVIEW;
+
       case STATE_TEXRECT_SCALE:
       case STATE_SHADOW_AMBIENT:
+      case STATE_ROT_MATRIX_0:
+      case STATE_ROT_MATRIX_1:
         return _NEW_TEXTURE;
       case STATE_FOG_PARAMS_OPTIMIZED:
         return _NEW_FOG;
+      case STATE_LIGHT_SPOT_DIR_NORMALIZED:
+      case STATE_LIGHT_POSITION:
+      case STATE_LIGHT_POSITION_NORMALIZED:
+      case STATE_LIGHT_HALF_VECTOR:
+         return _NEW_LIGHT;
+
+      case STATE_PT_SCALE:
+      case STATE_PT_BIAS:
+      case STATE_PCM_SCALE:
+      case STATE_PCM_BIAS:
+         return _NEW_PIXEL;
+
       default:
          /* unknown state indexes are silently ignored and
          *  no flag set, since it is handled by the driver.
@@ -604,6 +653,9 @@ append(char *dst, const char *src)
 }
 
 
+/**
+ * Convert token 'k' to a string, append it onto 'dst' string.
+ */
 static void
 append_token(char *dst, gl_state_index k)
 {
@@ -736,11 +788,30 @@ append_token(char *dst, gl_state_index k)
    case STATE_LOCAL:
       append(dst, "local");
       break;
+   /* BEGIN internal state vars */
+   case STATE_INTERNAL:
+      append(dst, "(internal)");
+      break;
    case STATE_NORMAL_SCALE:
       append(dst, "normalScale");
       break;
-   case STATE_INTERNAL:
-      append(dst, "(internal)");
+   case STATE_TEXRECT_SCALE:
+      append(dst, "texrectScale");
+      break;
+   case STATE_FOG_PARAMS_OPTIMIZED:
+      append(dst, "fogParamsOptimized");
+      break;
+   case STATE_LIGHT_SPOT_DIR_NORMALIZED:
+      append(dst, "lightSpotDirNormalized");
+      break;
+   case STATE_LIGHT_POSITION:
+      append(dst, "lightPosition");
+      break;
+   case STATE_LIGHT_POSITION_NORMALIZED:
+      append(dst, "light.position.normalized");
+      break;
+   case STATE_LIGHT_HALF_VECTOR:
+      append(dst, "lightHalfVector");
       break;
    case STATE_PT_SCALE:
       append(dst, "PTscale");
@@ -755,10 +826,17 @@ append_token(char *dst, gl_state_index k)
       append(dst, "PCMbias");
       break;
    case STATE_SHADOW_AMBIENT:
-      append(dst, "ShadowAmbient");
+      append(dst, "CompareFailValue");
+      break;
+   case STATE_ROT_MATRIX_0:
+      append(dst, "rotMatrixRow0");
+      break;
+   case STATE_ROT_MATRIX_1:
+      append(dst, "rotMatrixRow1");
       break;
    default:
-      ;
+      /* probably STATE_INTERNAL_DRIVER+i (driver private state) */
+      append(dst, "driverState");
    }
 }
 
@@ -784,23 +862,23 @@ append_index(char *dst, GLint index)
  * For example, return "state.matrix.texture[2].inverse".
  * Use _mesa_free() to deallocate the string.
  */
-const char *
+char *
 _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
 {
    char str[1000] = "";
    char tmp[30];
 
    append(str, "state.");
-   append_token(str, (gl_state_index) state[0]);
+   append_token(str, state[0]);
 
    switch (state[0]) {
    case STATE_MATERIAL:
       append_face(str, state[1]);
-      append_token(str, (gl_state_index) state[2]);
+      append_token(str, state[2]);
       break;
    case STATE_LIGHT:
       append_index(str, state[1]); /* light number [i]. */
-      append_token(str, (gl_state_index) state[2]); /* coefficients */
+      append_token(str, state[2]); /* coefficients */
       break;
    case STATE_LIGHTMODEL_AMBIENT:
       append(str, "lightmodel.ambient");
@@ -816,11 +894,11 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
    case STATE_LIGHTPROD:
       append_index(str, state[1]); /* light number [i]. */
       append_face(str, state[2]);
-      append_token(str, (gl_state_index) state[3]);
+      append_token(str, state[3]);
       break;
    case STATE_TEXGEN:
       append_index(str, state[1]); /* tex unit [i] */
-      append_token(str, (gl_state_index) state[2]); /* plane coef */
+      append_token(str, state[2]); /* plane coef */
       break;
    case STATE_TEXENV_COLOR:
       append_index(str, state[1]); /* tex unit [i] */
@@ -842,11 +920,11 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
          /* state[2] = first row to fetch */
          /* state[3] = last row to fetch */
          /* state[4] = transpose, inverse or invtrans */
-         const gl_state_index mat = (gl_state_index) state[0];
+         const gl_state_index mat = state[0];
          const GLuint index = (GLuint) state[1];
          const GLuint firstRow = (GLuint) state[2];
          const GLuint lastRow = (GLuint) state[3];
-         const gl_state_index modifier = (gl_state_index) state[4];
+         const gl_state_index modifier = state[4];
          if (index ||
              mat == STATE_TEXTURE_MATRIX ||
              mat == STATE_PROGRAM_MATRIX)
@@ -874,10 +952,11 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
    case STATE_VERTEX_PROGRAM:
       /* state[1] = {STATE_ENV, STATE_LOCAL} */
       /* state[2] = parameter index          */
-      append_token(str, (gl_state_index) state[1]);
+      append_token(str, state[1]);
       append_index(str, state[2]);
       break;
    case STATE_INTERNAL:
+      append_token(str, state[1]);
       break;
    default:
       _mesa_problem(NULL, "Invalid state in _mesa_program_state_string");