ir_to_mesa: make some global variable static
[mesa.git] / src / mesa / program / prog_statevars.c
index baac29ff0dd5dc3d6daea105bae86c9ffb9977c1..f9c6677b19bbc6a6882117ccf3c585e48d979861 100644 (file)
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
+#include "main/fbobject.h"
 #include "prog_statevars.h"
 #include "prog_parameter.h"
+#include "main/samplerobj.h"
 
 
 /**
@@ -237,11 +239,17 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
       {
          /* state[1] is the texture unit */
          const GLuint unit = (GLuint) state[1];
-         COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
+         if(ctx->Color._ClampFragmentColor)
+            COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
+         else
+            COPY_4V(value, ctx->Texture.Unit[unit].EnvColorUnclamped);
       }
       return;
    case STATE_FOG_COLOR:
-      COPY_4V(value, ctx->Fog.Color);
+      if(ctx->Color._ClampFragmentColor)
+         COPY_4V(value, ctx->Fog.Color);
+      else
+         COPY_4V(value, ctx->Fog.ColorUnclamped);
       return;
    case STATE_FOG_PARAMS:
       value[0] = ctx->Fog.Density;
@@ -316,7 +324,6 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
              modifier == STATE_MATRIX_INVTRANS) {
             /* Be sure inverse is up to date:
             */
-            _math_matrix_alloc_inv( (GLmatrix *) matrix );
            _math_matrix_analyse( (GLmatrix*) matrix );
             m = matrix->inv;
          }
@@ -399,6 +406,22 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          }
          return;
 
+      case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED:
+         {
+            const GLuint idx = (GLuint) state[2];
+            if(ctx->Light._ClampVertexColor &&
+               (idx == VERT_ATTRIB_COLOR0 ||
+                idx == VERT_ATTRIB_COLOR1)) {
+               value[0] = CLAMP(ctx->Current.Attrib[idx][0], 0.0f, 1.0f);
+               value[1] = CLAMP(ctx->Current.Attrib[idx][1], 0.0f, 1.0f);
+               value[2] = CLAMP(ctx->Current.Attrib[idx][2], 0.0f, 1.0f);
+               value[3] = CLAMP(ctx->Current.Attrib[idx][3], 0.0f, 1.0f);
+            }
+            else
+               COPY_4V(value, ctx->Current.Attrib[idx]);
+         }
+         return;
+
       case STATE_NORMAL_SCALE:
          ASSIGN_4V(value, 
                    ctx->_ModelViewInvScale, 
@@ -437,7 +460,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          value[0] = (ctx->Fog.End == ctx->Fog.Start)
             ? 1.0f : (GLfloat)(-1.0F / (ctx->Fog.End - ctx->Fog.Start));
          value[1] = ctx->Fog.End * -value[0];
-         value[2] = (GLfloat)(ctx->Fog.Density * ONE_DIV_LN2);
+         value[2] = (GLfloat)(ctx->Fog.Density * M_LOG2E); /* M_LOG2E == 1/ln(2) */
          value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2);
          return;
 
@@ -473,29 +496,6 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
             value[3] = ctx->Point.Threshold;
          }
          return;
-      case STATE_POINT_SIZE_IMPL_CLAMP:
-         {
-           /* for implementation clamp only in vs */
-            GLfloat minImplSize;
-            GLfloat maxImplSize;
-            if (ctx->Point.PointSprite) {
-               minImplSize = ctx->Const.MinPointSizeAA;
-               maxImplSize = ctx->Const.MaxPointSize;
-            }
-            else if (ctx->Point.SmoothFlag || ctx->Multisample._Enabled) {
-               minImplSize = ctx->Const.MinPointSizeAA;
-               maxImplSize = ctx->Const.MaxPointSizeAA;
-            }
-            else {
-               minImplSize = ctx->Const.MinPointSize;
-               maxImplSize = ctx->Const.MaxPointSize;
-            }
-            value[0] = ctx->Point.Size;
-            value[1] = minImplSize;
-            value[2] = maxImplSize;
-            value[3] = ctx->Point.Threshold;
-         }
-         return;
       case STATE_LIGHT_SPOT_DIR_NORMALIZED:
          {
             /* here, state[2] is the light number */
@@ -551,20 +551,6 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          value[3] = ctx->Pixel.AlphaBias;
          return;
 
-      case STATE_SHADOW_AMBIENT:
-         {
-            const int unit = (int) state[2];
-            const struct gl_texture_object *texObj
-               = ctx->Texture.Unit[unit]._Current;
-            if (texObj) {
-               value[0] =
-               value[1] =
-               value[2] =
-               value[3] = texObj->CompareFailValue;
-            }
-         }
-         return;
-
       case STATE_FB_SIZE:
          value[0] = (GLfloat) (ctx->DrawBuffer->Width - 1);
          value[1] = (GLfloat) (ctx->DrawBuffer->Height - 1);
@@ -572,6 +558,24 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          value[3] = 0.0F;
          return;
 
+      case STATE_FB_WPOS_Y_TRANSFORM:
+         /* A driver may negate this conditional by using ZW swizzle
+          * instead of XY (based on e.g. some other state). */
+         if (_mesa_is_user_fbo(ctx->DrawBuffer)) {
+            /* Identity (XY) followed by flipping Y upside down (ZW). */
+            value[0] = 1.0F;
+            value[1] = 0.0F;
+            value[2] = -1.0F;
+            value[3] = (GLfloat) ctx->DrawBuffer->Height;
+         } else {
+            /* Flipping Y upside down (XY) followed by identity (ZW). */
+            value[0] = -1.0F;
+            value[1] = (GLfloat) ctx->DrawBuffer->Height;
+            value[2] = 1.0F;
+            value[3] = 0.0F;
+         }
+         return;
+
       case STATE_ROT_MATRIX_0:
          {
             const int unit = (int) state[2];
@@ -624,17 +628,22 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
 {
    switch (state[0]) {
    case STATE_MATERIAL:
+   case STATE_LIGHTPROD:
+   case STATE_LIGHTMODEL_SCENECOLOR:
+      /* these can be effected by glColor when colormaterial mode is used */
+      return _NEW_LIGHT | _NEW_CURRENT_ATTRIB;
+
    case STATE_LIGHT:
    case STATE_LIGHTMODEL_AMBIENT:
-   case STATE_LIGHTMODEL_SCENECOLOR:
-   case STATE_LIGHTPROD:
       return _NEW_LIGHT;
 
    case STATE_TEXGEN:
-   case STATE_TEXENV_COLOR:
       return _NEW_TEXTURE;
+   case STATE_TEXENV_COLOR:
+      return _NEW_TEXTURE | _NEW_BUFFERS | _NEW_FRAG_CLAMP;
 
    case STATE_FOG_COLOR:
+      return _NEW_FOG | _NEW_BUFFERS | _NEW_FRAG_CLAMP;
    case STATE_FOG_PARAMS:
       return _NEW_FOG;
 
@@ -670,19 +679,19 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
       switch (state[1]) {
       case STATE_CURRENT_ATTRIB:
          return _NEW_CURRENT_ATTRIB;
+      case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED:
+         return _NEW_CURRENT_ATTRIB | _NEW_LIGHT | _NEW_BUFFERS;
 
       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_POINT_SIZE_CLAMPED:
-      case STATE_POINT_SIZE_IMPL_CLAMP:
          return _NEW_POINT | _NEW_MULTISAMPLE;
       case STATE_LIGHT_SPOT_DIR_NORMALIZED:
       case STATE_LIGHT_POSITION:
@@ -695,6 +704,7 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
          return _NEW_PIXEL;
 
       case STATE_FB_SIZE:
+      case STATE_FB_WPOS_Y_TRANSFORM:
          return _NEW_BUFFERS;
 
       default:
@@ -873,9 +883,6 @@ append_token(char *dst, gl_state_index k)
    case STATE_POINT_SIZE_CLAMPED:
       append(dst, "pointSizeClamped");
       break;
-   case STATE_POINT_SIZE_IMPL_CLAMP:
-      append(dst, "pointSizeImplClamp");
-      break;
    case STATE_LIGHT_SPOT_DIR_NORMALIZED:
       append(dst, "lightSpotDirNormalized");
       break;
@@ -894,12 +901,12 @@ append_token(char *dst, gl_state_index k)
    case STATE_PT_BIAS:
       append(dst, "PTbias");
       break;
-   case STATE_SHADOW_AMBIENT:
-      append(dst, "CompareFailValue");
-      break;
    case STATE_FB_SIZE:
       append(dst, "FbSize");
       break;
+   case STATE_FB_WPOS_Y_TRANSFORM:
+      append(dst, "FbWposYTransform");
+      break;
    case STATE_ROT_MATRIX_0:
       append(dst, "rotMatrixRow0");
       break;
@@ -1046,7 +1053,9 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
  * Loop over all the parameters in a parameter list.  If the parameter
  * is a GL state reference, look up the current value of that state
  * variable and put it into the parameter's Value[4] array.
- * This would be called at glBegin time when using a fragment program.
+ * Other parameter types never change or are explicitly set by the user
+ * with glUniform() or glProgramParameter(), etc.
+ * This would be called at glBegin time.
  */
 void
 _mesa_load_state_parameters(struct gl_context *ctx,
@@ -1057,13 +1066,11 @@ _mesa_load_state_parameters(struct gl_context *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,
-                          (gl_state_index *) paramList->Parameters[i].StateIndexes,
-                           paramList->ParameterValues[i]);
+                          paramList->Parameters[i].StateIndexes,
+                           &paramList->ParameterValues[i][0].f);
       }
    }
 }