mesa/formats: add more MESA_FORMAT_LAYOUTs
[mesa.git] / src / mesa / program / prog_statevars.c
index f6fd53576c1f609a034e01209947c52ab4ee8138..bdb335e4ba3ab1c62b4f7c2581e406bb364f6d4a 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 
+#include <stdio.h>
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/blend.h"
@@ -41,6 +42,9 @@
 #include "main/samplerobj.h"
 
 
+#define ONE_DIV_SQRT_LN2 (1.201122408786449815)
+
+
 /**
  * Use the list of tokens in the state[] array to find global GL state
  * and return it in <value>.  Usually, four values are returned in <value>
@@ -58,9 +62,9 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          /* state[1] is either 0=front or 1=back side */
          const GLuint face = (GLuint) state[1];
          const struct gl_material *mat = &ctx->Light.Material;
-         ASSERT(face == 0 || face == 1);
+         assert(face == 0 || face == 1);
          /* we rely on tokens numbered so that _BACK_ == _FRONT_+ 1 */
-         ASSERT(MAT_ATTRIB_FRONT_AMBIENT + 1 == MAT_ATTRIB_BACK_AMBIENT);
+         assert(MAT_ATTRIB_FRONT_AMBIENT + 1 == MAT_ATTRIB_BACK_AMBIENT);
          /* XXX we could get rid of this switch entirely with a little
           * work in arbprogparse.c's parse_state_single_item().
           */
@@ -170,7 +174,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          const GLuint ln = (GLuint) state[1];
          const GLuint face = (GLuint) state[2];
          GLint i;
-         ASSERT(face == 0 || face == 1);
+         assert(face == 0 || face == 1);
          switch (state[3]) {
             case STATE_AMBIENT:
                for (i = 0; i < 3; i++) {
@@ -240,14 +244,14 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
       {
          /* state[1] is the texture unit */
          const GLuint unit = (GLuint) state[1];
-         if (_mesa_get_clamp_fragment_color(ctx))
+         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
             COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
          else
             COPY_4V(value, ctx->Texture.Unit[unit].EnvColorUnclamped);
       }
       return;
    case STATE_FOG_COLOR:
-      if (_mesa_get_clamp_fragment_color(ctx))
+      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
          COPY_4V(value, ctx->Fog.Color);
       else
          COPY_4V(value, ctx->Fog.ColorUnclamped);
@@ -295,10 +299,8 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          const gl_state_index modifier = state[4];
          const GLfloat *m;
          GLuint row, i;
-         ASSERT(firstRow >= 0);
-         ASSERT(firstRow < 4);
-         ASSERT(lastRow >= 0);
-         ASSERT(lastRow < 4);
+         assert(firstRow < 4);
+         assert(lastRow < 4);
          if (mat == STATE_MODELVIEW_MATRIX) {
             matrix = ctx->ModelviewMatrixStack.Top;
          }
@@ -309,11 +311,11 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
             matrix = &ctx->_ModelProjectMatrix;
          }
          else if (mat == STATE_TEXTURE_MATRIX) {
-            ASSERT(index < Elements(ctx->TextureMatrixStack));
+            assert(index < ARRAY_SIZE(ctx->TextureMatrixStack));
             matrix = ctx->TextureMatrixStack[index].Top;
          }
          else if (mat == STATE_PROGRAM_MATRIX) {
-            ASSERT(index < Elements(ctx->ProgramMatrixStack));
+            assert(index < ARRAY_SIZE(ctx->ProgramMatrixStack));
             matrix = ctx->ProgramMatrixStack[index].Top;
          }
          else {
@@ -353,9 +355,9 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
       ((int *)value)[0] = ctx->DrawBuffer->Visual.samples;
       return;
    case STATE_DEPTH_RANGE:
-      value[0] = ctx->Viewport.Near;                     /* near       */
-      value[1] = ctx->Viewport.Far;                      /* far        */
-      value[2] = ctx->Viewport.Far - ctx->Viewport.Near; /* far - near */
+      value[0] = ctx->ViewportArray[0].Near;                /* near       */
+      value[1] = ctx->ViewportArray[0].Far;                 /* far        */
+      value[2] = ctx->ViewportArray[0].Far - ctx->ViewportArray[0].Near; /* far - near */
       value[3] = 1.0;
       return;
    case STATE_FRAGMENT_PROGRAM:
@@ -368,6 +370,13 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
                COPY_4V(value, ctx->FragmentProgram.Parameters[idx]);
                return;
             case STATE_LOCAL:
+               if (!ctx->FragmentProgram.Current->Base.LocalParams) {
+                  ctx->FragmentProgram.Current->Base.LocalParams =
+                     calloc(MAX_PROGRAM_LOCAL_PARAMS, sizeof(float[4]));
+                  if (!ctx->FragmentProgram.Current->Base.LocalParams)
+                     return;
+               }
+
                COPY_4V(value, ctx->FragmentProgram.Current->Base.LocalParams[idx]);
                return;
             default:
@@ -387,6 +396,13 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
                COPY_4V(value, ctx->VertexProgram.Parameters[idx]);
                return;
             case STATE_LOCAL:
+               if (!ctx->VertexProgram.Current->Base.LocalParams) {
+                  ctx->VertexProgram.Current->Base.LocalParams =
+                     calloc(MAX_PROGRAM_LOCAL_PARAMS, sizeof(float[4]));
+                  if (!ctx->VertexProgram.Current->Base.LocalParams)
+                     return;
+               }
+
                COPY_4V(value, ctx->VertexProgram.Current->Base.LocalParams[idx]);
                return;
             default:
@@ -579,28 +595,6 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          }
          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;
-         }
-         return;
-
-      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;
-         }
-         return;
-
       /* XXX: make sure new tokens added here are also handled in the 
        * _mesa_program_state_flags() switch, below.
        */
@@ -692,8 +686,6 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
          return _NEW_MODELVIEW;
 
       case STATE_TEXRECT_SCALE:
-      case STATE_ROT_MATRIX_0:
-      case STATE_ROT_MATRIX_1:
         return _NEW_TEXTURE;
       case STATE_FOG_PARAMS_OPTIMIZED:
         return _NEW_FOG;
@@ -919,12 +911,6 @@ append_token(char *dst, gl_state_index k)
    case STATE_FB_WPOS_Y_TRANSFORM:
       append(dst, "FbWposYTransform");
       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");
@@ -1059,7 +1045,7 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
       break;
    }
 
-   return _mesa_strdup(str);
+   return strdup(str);
 }