fix GL_BACK color material bug
[mesa.git] / src / mesa / main / matrix.c
index 278584076b0c83928bef6e46971a020362cafe84..5eb5bb43f0c5daead20be807c423778bf10c4253 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: matrix.c,v 1.14 2000/02/02 19:28:27 brianp Exp $ */
+/* $Id: matrix.c,v 1.17 2000/04/08 18:57:45 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -931,6 +931,10 @@ do {                                                                       \
         mat = &ctx->TextureMatrix[ctx->Texture.CurrentTransformUnit];  \
         flags |= NEW_TEXTURE_MATRIX;                                   \
         break;                                                         \
+      case GL_COLOR:                                                   \
+        mat = &ctx->ColorMatrix;                                       \
+        flags |= NEW_COLOR_MATRIX;                                     \
+        break;                                                         \
       default:                                                         \
          gl_problem(ctx, where);                                       \
    }                                                                   \
@@ -1037,6 +1041,7 @@ _mesa_MatrixMode( GLenum mode )
       case GL_MODELVIEW:
       case GL_PROJECTION:
       case GL_TEXTURE:
+      case GL_COLOR:
          ctx->Transform.MatrixMode = mode;
          break;
       default:
@@ -1058,7 +1063,7 @@ _mesa_PushMatrix( void )
 
    switch (ctx->Transform.MatrixMode) {
       case GL_MODELVIEW:
-         if (ctx->ModelViewStackDepth>=MAX_MODELVIEW_STACK_DEPTH-1) {
+         if (ctx->ModelViewStackDepth >= MAX_MODELVIEW_STACK_DEPTH - 1) {
             gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
             return;
          }
@@ -1066,7 +1071,7 @@ _mesa_PushMatrix( void )
                         &ctx->ModelView );
          break;
       case GL_PROJECTION:
-         if (ctx->ProjectionStackDepth>=MAX_PROJECTION_STACK_DEPTH) {
+         if (ctx->ProjectionStackDepth >= MAX_PROJECTION_STACK_DEPTH - 1) {
             gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
             return;
          }
@@ -1082,7 +1087,7 @@ _mesa_PushMatrix( void )
       case GL_TEXTURE:
          {
             GLuint t = ctx->Texture.CurrentTransformUnit;
-            if (ctx->TextureStackDepth[t] >= MAX_TEXTURE_STACK_DEPTH) {
+            if (ctx->TextureStackDepth[t] >= MAX_TEXTURE_STACK_DEPTH - 1) {
                gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
                return;
             }
@@ -1090,6 +1095,14 @@ _mesa_PushMatrix( void )
                            &ctx->TextureMatrix[t] );
          }
          break;
+      case GL_COLOR:
+         if (ctx->ColorStackDepth >= MAX_COLOR_STACK_DEPTH - 1) {
+            gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
+            return;
+         }
+         gl_matrix_copy( &ctx->ColorStack[ctx->ColorStackDepth++],
+                         &ctx->ColorMatrix );
+         break;
       default:
          gl_problem(ctx, "Bad matrix mode in gl_PushMatrix");
    }
@@ -1147,6 +1160,14 @@ _mesa_PopMatrix( void )
                           &ctx->TextureStack[t][--ctx->TextureStackDepth[t]]);
          }
          break;
+      case GL_COLOR:
+         if (ctx->ColorStackDepth==0) {
+            gl_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
+            return;
+         }
+         gl_matrix_copy(&ctx->ColorMatrix,
+                        &ctx->ColorStack[--ctx->ColorStackDepth]);
+         break;
       default:
          gl_problem(ctx, "Bad matrix mode in gl_PopMatrix");
    }
@@ -1460,8 +1481,8 @@ gl_Viewport( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height )
    ctx->Viewport.WindowMap.m[MAT_TX] = ctx->Viewport.WindowMap.m[MAT_SX] + x;
    ctx->Viewport.WindowMap.m[MAT_SY] = (GLfloat) height / 2.0F;
    ctx->Viewport.WindowMap.m[MAT_TY] = ctx->Viewport.WindowMap.m[MAT_SY] + y;
-   ctx->Viewport.WindowMap.m[MAT_SZ] = 0.5 * DEPTH_SCALE;
-   ctx->Viewport.WindowMap.m[MAT_TZ] = 0.5 * DEPTH_SCALE;
+   ctx->Viewport.WindowMap.m[MAT_SZ] = 0.5 * ctx->Visual->DepthMaxF;
+   ctx->Viewport.WindowMap.m[MAT_TZ] = 0.5 * ctx->Visual->DepthMaxF;
 
    ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
    ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
@@ -1518,8 +1539,8 @@ _mesa_DepthRange( GLclampd nearval, GLclampd farval )
 
    ctx->Viewport.Near = n;
    ctx->Viewport.Far = f;
-   ctx->Viewport.WindowMap.m[MAT_SZ] = DEPTH_SCALE * ((f - n) / 2.0);
-   ctx->Viewport.WindowMap.m[MAT_TZ] = DEPTH_SCALE * ((f - n) / 2.0 + n);
+   ctx->Viewport.WindowMap.m[MAT_SZ] = ctx->Visual->DepthMaxF * ((f - n) / 2.0);
+   ctx->Viewport.WindowMap.m[MAT_TZ] = ctx->Visual->DepthMaxF * ((f - n) / 2.0 + n);
 
    ctx->ModelProjectWinMatrixUptodate = GL_FALSE;