fixed pointer arithmetic error in glCopyPixels
[mesa.git] / src / mesa / main / mtypes.h
index 32820178d4184911d1528888c24f56ce540f6714..efa26afe8b1d81861c208571dbeb03c3f23a8916 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: mtypes.h,v 1.55 2001/12/14 02:50:02 brianp Exp $ */
+/* $Id: mtypes.h,v 1.66 2002/03/13 04:33:16 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  4.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/**
+ * \file mtypes.h
+ * \brief Main Mesa data structures.
+ */
 
 #ifndef TYPES_H
 #define TYPES_H
@@ -67,7 +71,7 @@
 #endif
 
 
-/*
+/**
  * Accumulation buffer data type:
  */
 #if ACCUM_BITS==8
@@ -81,7 +85,7 @@
 #endif
 
 
-/*
+/**
  * Stencil buffer data type:
  */
 #if STENCIL_BITS==8
 #endif
 
 
-/*
+/**
  * Depth buffer data type:
  */
 typedef GLuint GLdepth;  /* Must be 32-bits! */
 
 
-/*
+/**
  * Fixed point data type:
  */
 typedef int GLfixed;
 
 
 
-/*
+/**
  * Some forward type declarations
  */
 struct _mesa_HashTable;
@@ -120,7 +124,52 @@ typedef struct gl_frame_buffer GLframebuffer;
 
 
 
-/* Maximum number of temporary vertices required for clipping.  (Used
+/* These define the aliases between numbered vertex attributes and
+ * conventional OpenGL vertex attributes.  We use these values in
+ * quite a few places.  New in Mesa 4.1.
+ */
+#define VERT_ATTRIB_POS      0
+#define VERT_ATTRIB_WEIGHT   1
+#define VERT_ATTRIB_NORMAL   2
+#define VERT_ATTRIB_COLOR0   3
+#define VERT_ATTRIB_COLOR1   4
+#define VERT_ATTRIB_FOG      5
+#define VERT_ATTRIB_SIX      6
+#define VERT_ATTRIB_SEVEN    7
+#define VERT_ATTRIB_TEX0     8
+#define VERT_ATTRIB_TEX1     9
+#define VERT_ATTRIB_TEX2     10
+#define VERT_ATTRIB_TEX3     11
+#define VERT_ATTRIB_TEX4     12
+#define VERT_ATTRIB_TEX5     13
+#define VERT_ATTRIB_TEX6     14
+#define VERT_ATTRIB_TEX7     15
+#define VERT_ATTRIB_MAX      16
+
+/* These are used in bitfields in many places */
+#define VERT_BIT_POS     (1 << VERT_ATTRIB_POS)
+#define VERT_BIT_WEIGHT  (1 << VERT_ATTRIB_WEIGHT)
+#define VERT_BIT_NORMAL  (1 << VERT_ATTRIB_NORMAL)
+#define VERT_BIT_COLOR0  (1 << VERT_ATTRIB_COLOR0)
+#define VERT_BIT_COLOR1  (1 << VERT_ATTRIB_COLOR1)
+#define VERT_BIT_FOG     (1 << VERT_ATTRIB_FOG)
+#define VERT_BIT_SIX     (1 << VERT_ATTRIB_SIX)
+#define VERT_BIT_SEVEN   (1 << VERT_ATTRIB_SEVEN)
+#define VERT_BIT_TEX0    (1 << VERT_ATTRIB_TEX0)
+#define VERT_BIT_TEX1    (1 << VERT_ATTRIB_TEX1)
+#define VERT_BIT_TEX2    (1 << VERT_ATTRIB_TEX2)
+#define VERT_BIT_TEX3    (1 << VERT_ATTRIB_TEX3)
+#define VERT_BIT_TEX4    (1 << VERT_ATTRIB_TEX4)
+#define VERT_BIT_TEX5    (1 << VERT_ATTRIB_TEX5)
+#define VERT_BIT_TEX6    (1 << VERT_ATTRIB_TEX6)
+#define VERT_BIT_TEX7    (1 << VERT_ATTRIB_TEX7)
+
+#define VERT_BIT_TEX(u)  (1 << (VERT_ATTRIB_TEX0 + (u)))
+
+
+
+/**
+ * Maximum number of temporary vertices required for clipping.  (Used
  * in array_cache and tnl modules).
  */
 #define MAX_CLIPPED_VERTICES ((2 * (6 + MAX_CLIP_PLANES))+1)
@@ -185,7 +234,7 @@ struct gl_shine_tab {
 
 
 struct gl_light {
-   struct gl_light *next;              /* double linked list with sentinel */
+   struct gl_light *next;      /* double linked list with sentinel */
    struct gl_light *prev;
 
    GLfloat Ambient[4];         /* ambient color */
@@ -295,30 +344,10 @@ struct gl_colorbuffer_attrib {
 };
 
 
-/* These define the aliases between numbered vertex attributes and
- * conventional OpenGL vertex attributes.
- */
-#define VERT_ATTRIB_POS      0
-#define VERT_ATTRIB_WEIGHT   1
-#define VERT_ATTRIB_NORMAL   2
-#define VERT_ATTRIB_COLOR0   3
-#define VERT_ATTRIB_COLOR1   4
-#define VERT_ATTRIB_FOG      5
-#define VERT_ATTRIB_SIX      6
-#define VERT_ATTRIB_SEVEN    7
-#define VERT_ATTRIB_TEX0     8
-#define VERT_ATTRIB_TEX1     9
-#define VERT_ATTRIB_TEX2     10
-#define VERT_ATTRIB_TEX3     11
-#define VERT_ATTRIB_TEX4     12
-#define VERT_ATTRIB_TEX5     13
-#define VERT_ATTRIB_TEX6     14
-#define VERT_ATTRIB_TEX7     15
-
 struct gl_current_attrib {
    /* These values valid only when FLUSH_VERTICES has been called.
     */
-   GLfloat Attrib[8 + MAX_TEXTURE_UNITS][4];   /* Current vertex attributes */
+   GLfloat Attrib[VERT_ATTRIB_MAX][4];         /* Current vertex attributes */
                                                /* indexed by VERT_ATTRIB_* */
    GLuint Index;                               /* Current color index */
    GLboolean EdgeFlag;                         /* Current edge flag */
@@ -333,7 +362,6 @@ struct gl_current_attrib {
    GLuint RasterIndex;                         /* Current raster index */
    GLfloat *RasterTexCoord;                    /* Current raster texcoord */
    GLfloat RasterMultiTexCoord[MAX_TEXTURE_UNITS][4];
-   GLfloat RasterFogCoord;
    GLboolean RasterPosValid;                   /* Raster pos valid flag */
 };
 
@@ -376,6 +404,7 @@ struct gl_enable_attrib {
    GLboolean Map1TextureCoord4;
    GLboolean Map1Vertex3;
    GLboolean Map1Vertex4;
+   GLboolean Map1Attrib[16];  /* GL_NV_vertex_program */
    GLboolean Map2Color4;
    GLboolean Map2Index;
    GLboolean Map2Normal;
@@ -385,6 +414,7 @@ struct gl_enable_attrib {
    GLboolean Map2TextureCoord4;
    GLboolean Map2Vertex3;
    GLboolean Map2Vertex4;
+   GLboolean Map2Attrib[16];  /* GL_NV_vertex_program */
    GLboolean MinMax;
    GLboolean Normalize;
    GLboolean PixelTexture;
@@ -423,6 +453,7 @@ struct gl_eval_attrib {
    GLboolean Map1TextureCoord4;
    GLboolean Map1Vertex3;
    GLboolean Map1Vertex4;
+   GLboolean Map1Attrib[16];  /* GL_NV_vertex_program */
    GLboolean Map2Color4;
    GLboolean Map2Index;
    GLboolean Map2Normal;
@@ -432,6 +463,7 @@ struct gl_eval_attrib {
    GLboolean Map2TextureCoord4;
    GLboolean Map2Vertex3;
    GLboolean Map2Vertex4;
+   GLboolean Map2Attrib[16];  /* GL_NV_vertex_program */
    GLboolean AutoNormal;
    /* Map Grid endpoints and divisions and calculated du values */
    GLint MapGrid1un;
@@ -867,7 +899,7 @@ struct gl_texture_object {
    GLchan ShadowAmbient;       /* GL_SGIX/ARB_shadow_ambient */
    GLenum CompareMode;         /* GL_ARB_shadow */
    GLenum CompareFunc;         /* GL_ARB_shadow */
-   GLenum CompareResult;       /* GL_ARB_shadow */
+   GLenum DepthMode;           /* GL_ARB_depth_texture */
    GLint _MaxLevel;            /* actual max mipmap level (q in the spec) */
    GLfloat _MaxLambda;         /* = _MaxLevel - BaseLevel (q - b in spec) */
    GLboolean GenerateMipmap;    /* GL_SGIS_generate_mipmap */
@@ -1029,7 +1061,7 @@ struct gl_client_array {
    GLsizei StrideB;            /* actual stride in bytes */
    void *Ptr;
    GLuint Flags;
-   GLboolean Enabled;
+   GLuint Enabled;             /* one of the _NEW_ARRAY_ bits */
 };
 
 
@@ -1112,6 +1144,7 @@ struct gl_evaluators {
    struct gl_1d_map Map1Texture2;
    struct gl_1d_map Map1Texture3;
    struct gl_1d_map Map1Texture4;
+   struct gl_1d_map Map1Attrib[16];  /* GL_NV_vertex_program */
 
    /* 2-D maps */
    struct gl_2d_map Map2Vertex3;
@@ -1123,6 +1156,7 @@ struct gl_evaluators {
    struct gl_2d_map Map2Texture2;
    struct gl_2d_map Map2Texture3;
    struct gl_2d_map Map2Texture4;
+   struct gl_2d_map Map2Attrib[16];  /* GL_NV_vertex_program */
 };
 
 
@@ -1131,10 +1165,8 @@ struct gl_evaluators {
  */
 
 #define VP_MAX_INSTRUCTIONS 128
-#define VP_MAX_MATRICES 8
-#define VP_MAX_MATRIX_DEPTH 4
 
-#define VP_NUM_INPUT_REGS 16
+#define VP_NUM_INPUT_REGS VERT_ATTRIB_MAX
 #define VP_NUM_OUTPUT_REGS 15
 #define VP_NUM_TEMP_REGS 12
 #define VP_NUM_PROG_REGS 96
@@ -1151,40 +1183,6 @@ struct gl_evaluators {
 #define VP_PROG_REG_START   (VP_TEMP_REG_END + 1)
 #define VP_PROG_REG_END     (VP_PROG_REG_START + VP_NUM_PROG_REGS - 1)
 
-/* Input register names */
-#define VP_IN_OPOS (VP_INPUT_REG_START + 0)
-#define VP_IN_WGHT (VP_INPUT_REG_START + 1)
-#define VP_IN_NRML (VP_INPUT_REG_START + 2)
-#define VP_IN_COL0 (VP_INPUT_REG_START + 3)
-#define VP_IN_COL1 (VP_INPUT_REG_START + 4)
-#define VP_IN_FOGC (VP_INPUT_REG_START + 5)
-#define VP_IN_TEX0 (VP_INPUT_REG_START + 8)
-#define VP_IN_TEX1 (VP_INPUT_REG_START + 9)
-#define VP_IN_TEX2 (VP_INPUT_REG_START + 10)
-#define VP_IN_TEX3 (VP_INPUT_REG_START + 11)
-#define VP_IN_TEX4 (VP_INPUT_REG_START + 12)
-#define VP_IN_TEX5 (VP_INPUT_REG_START + 13)
-#define VP_IN_TEX6 (VP_INPUT_REG_START + 14)
-#define VP_IN_TEX7 (VP_INPUT_REG_START + 15)
-
-/* Output register names */
-#define VP_OUT_HPOS (VP_OUTPUT_REG_START + 0)
-#define VP_OUT_COL0 (VP_OUTPUT_REG_START + 1)
-#define VP_OUT_COL1 (VP_OUTPUT_REG_START + 2)
-#define VP_OUT_BFC0 (VP_OUTPUT_REG_START + 3)
-#define VP_OUT_BFC1 (VP_OUTPUT_REG_START + 4)
-#define VP_OUT_FOGC (VP_OUTPUT_REG_START + 5)
-#define VP_OUT_PSIZ (VP_OUTPUT_REG_START + 6)
-#define VP_OUT_TEX0 (VP_OUTPUT_REG_START + 7)
-#define VP_OUT_TEX1 (VP_OUTPUT_REG_START + 8)
-#define VP_OUT_TEX2 (VP_OUTPUT_REG_START + 9)
-#define VP_OUT_TEX3 (VP_OUTPUT_REG_START + 10)
-#define VP_OUT_TEX4 (VP_OUTPUT_REG_START + 11)
-#define VP_OUT_TEX5 (VP_OUTPUT_REG_START + 12)
-#define VP_OUT_TEX6 (VP_OUTPUT_REG_START + 13)
-#define VP_OUT_TEX7 (VP_OUTPUT_REG_START + 14)
-
-
 
 /* Machine state (i.e. the register file) */
 struct vp_machine
@@ -1214,6 +1212,10 @@ enum vp_opcode
    SGE,
    MAD,
    ARL,
+   DPH,
+   RCC,
+   SUB,
+   ABS,
    END
 };
 
@@ -1251,29 +1253,29 @@ struct vp_program
    GLubyte *String;                      /* Original user code */
    struct vp_instruction *Instructions;  /* Compiled instructions */
    GLenum Target;      /* GL_VERTEX_PROGRAM_NV or GL_VERTEX_STATE_PROGRAM_NV */
-   GLint ErrorPos;
+   GLint ErrorPos;            /* Position in string where error was detected */
+   GLint RefCount;            /* Since programs can be shared among contexts */
+   GLboolean IsPositionInvariant;  /* GL_NV_vertex_program1_1 */
    GLboolean Resident;
+   GLuint InputsRead;     /* Bitmask of which input regs are read */
+   GLuint OutputsWritten; /* Bitmask of which output regs are written to */
 };
 
 
 /*
  * State vars for GL_NV_vertex_program
  */
-struct gl_vertex_program
+struct vertex_program_state
 {
    GLboolean Enabled;                    /* GL_VERTEX_PROGRAM_NV */
    GLboolean PointSizeEnabled;           /* GL_VERTEX_PROGRAM_POINT_SIZE_NV */
-   GLboolean TwoSideEnabled;            /* GL_VERTEX_PROGRAM_TWO_SIDE_NV */
-   GLuint Binding;                       /* currently bound program */
-   struct _mesa_HashTable *HashTable;    /* all programs */
+   GLboolean TwoSideEnabled;             /* GL_VERTEX_PROGRAM_TWO_SIDE_NV */
+   GLuint CurrentID;                     /* currently bound program's ID */
+   struct vp_program *Current;           /* ptr to currently bound program */
    struct vp_machine Machine;            /* machine state */
-   GLmatrix Matrix[VP_MAX_MATRICES];          /* Tracking matrices */
-   GLmatrix MatrixStack[VP_MAX_MATRICES][VP_MAX_MATRIX_DEPTH-1];  /* stacks */
-   GLuint MatrixStackDepth[VP_MAX_MATRICES];
 
    GLenum TrackMatrix[VP_NUM_PROG_REGS / 4];
    GLenum TrackMatrixTransform[VP_NUM_PROG_REGS / 4];
-
 };
 
 
@@ -1294,6 +1296,9 @@ struct gl_shared_state {
    struct gl_texture_object *Default3D;
    struct gl_texture_object *DefaultCubeMap;
 
+   /* GL_NV_vertex_program */
+   struct _mesa_HashTable *VertexPrograms;
+
    void *DriverData;  /* Device driver shared state */
 };
 
@@ -1376,6 +1381,7 @@ struct gl_extensions {
    /* Flags to quickly test if certain extensions are available.
     * Not every extension needs to have such a flag, but it's encouraged.
     */
+   GLboolean ARB_depth_texture;
    GLboolean ARB_imaging;
    GLboolean ARB_multisample;
    GLboolean ARB_multitexture;
@@ -1423,12 +1429,13 @@ struct gl_extensions {
    GLboolean NV_blend_square;
    GLboolean NV_texgen_reflection;
    GLboolean NV_vertex_program;
+   GLboolean NV_vertex_program1_1;
    GLboolean SGI_color_matrix;
    GLboolean SGI_color_table;
    GLboolean SGIS_generate_mipmap;
    GLboolean SGIS_pixel_texture;
    GLboolean SGIS_texture_edge_clamp;
-   GLboolean SGIX_depth_texture;  /* or GL_ARB_depth_texture */
+   GLboolean SGIX_depth_texture;
    GLboolean SGIX_pixel_texture;
    GLboolean SGIX_shadow;
    GLboolean SGIX_shadow_ambient; /* or GL_ARB_shadow_ambient */
@@ -1439,10 +1446,10 @@ struct gl_extensions {
 /* XXX just an idea */
 struct matrix_stack
 {
-   GLmatrix Top;
-   GLmatrix *Stack;
-   GLuint Depth;
-   GLuint MaxDepth;
+   GLmatrix *Top;      /* points into Stack */
+   GLmatrix *Stack;    /* array [MaxDepth] of GLmatrix */
+   GLuint Depth;       /* 0 <= Depth < MaxDepth */
+   GLuint MaxDepth;    /* size of Stack[] array */
    GLuint DirtyFlag;   /* _NEW_MODELVIEW or _NEW_PROJECTION, for example */
 };
 
@@ -1507,28 +1514,29 @@ struct matrix_stack
 #define _NEW_BUFFERS            0x1000000  /* ctx->Visual, ctx->DrawBuffer, */
 #define _NEW_MULTISAMPLE        0x2000000  /* ctx->Multisample */
 #define _NEW_TRACK_MATRIX       0x4000000  /* ctx->VertexProgram */
+#define _NEW_PROGRAM            0x8000000  /* ctx->VertexProgram */
 #define _NEW_ALL ~0
 
 
 
 /* Bits to track array state changes (also used to summarize array enabled)
  */
-#define _NEW_ARRAY_VERTEX           (1 << VERT_ATTRIB_POS)
-#define _NEW_ARRAY_WEIGHT           (1 << VERT_ATTRIB_WEIGHT)
-#define _NEW_ARRAY_NORMAL           (1 << VERT_ATTRIB_NORMAL)
-#define _NEW_ARRAY_COLOR0           (1 << VERT_ATTRIB_COLOR0)
-#define _NEW_ARRAY_COLOR1           (1 << VERT_ATTRIB_COLOR1)
-#define _NEW_ARRAY_FOGCOORD         (1 << VERT_ATTRIB_FOG)
-#define _NEW_ARRAY_INDEX            (1 << VERT_ATTRIB_SIX)
-#define _NEW_ARRAY_EDGEFLAG         (1 << VERT_ATTRIB_SEVEN)
-#define _NEW_ARRAY_TEXCOORD_0       (1 << VERT_ATTRIB_TEX0)
-#define _NEW_ARRAY_TEXCOORD_1       (1 << VERT_ATTRIB_TEX1)
-#define _NEW_ARRAY_TEXCOORD_2       (1 << VERT_ATTRIB_TEX2)
-#define _NEW_ARRAY_TEXCOORD_3       (1 << VERT_ATTRIB_TEX3)
-#define _NEW_ARRAY_TEXCOORD_4       (1 << VERT_ATTRIB_TEX4)
-#define _NEW_ARRAY_TEXCOORD_5       (1 << VERT_ATTRIB_TEX5)
-#define _NEW_ARRAY_TEXCOORD_6       (1 << VERT_ATTRIB_TEX6)
-#define _NEW_ARRAY_TEXCOORD_7       (1 << VERT_ATTRIB_TEX7)
+#define _NEW_ARRAY_VERTEX           VERT_BIT_POS
+#define _NEW_ARRAY_WEIGHT           VERT_BIT_WEIGHT
+#define _NEW_ARRAY_NORMAL           VERT_BIT_NORMAL
+#define _NEW_ARRAY_COLOR0           VERT_BIT_COLOR0
+#define _NEW_ARRAY_COLOR1           VERT_BIT_COLOR1
+#define _NEW_ARRAY_FOGCOORD         VERT_BIT_FOG
+#define _NEW_ARRAY_INDEX            VERT_BIT_SIX
+#define _NEW_ARRAY_EDGEFLAG         VERT_BIT_SEVEN
+#define _NEW_ARRAY_TEXCOORD_0       VERT_BIT_TEX0
+#define _NEW_ARRAY_TEXCOORD_1       VERT_BIT_TEX1
+#define _NEW_ARRAY_TEXCOORD_2       VERT_BIT_TEX2
+#define _NEW_ARRAY_TEXCOORD_3       VERT_BIT_TEX3
+#define _NEW_ARRAY_TEXCOORD_4       VERT_BIT_TEX4
+#define _NEW_ARRAY_TEXCOORD_5       VERT_BIT_TEX5
+#define _NEW_ARRAY_TEXCOORD_6       VERT_BIT_TEX6
+#define _NEW_ARRAY_TEXCOORD_7       VERT_BIT_TEX7
 #define _NEW_ARRAY_ALL              0xffff
 #define _NEW_ARRAY_VERT_ATTRIB0     0x10000
 
@@ -1580,13 +1588,16 @@ struct matrix_stack
 #define _IMAGE_NEW_TRANSFER_STATE         (_NEW_PIXEL | _NEW_COLOR_MATRIX)
 
 
+/* Bits for ctx->_NeedNormals */
 #define NEED_NORMALS_TEXGEN      0x1
 #define NEED_NORMALS_LIGHT       0x2
 
+/* Bits for ctx->_NeedEyeCoords */
 #define NEED_EYE_TEXGEN          0x1
 #define NEED_EYE_LIGHT           0x2
 #define NEED_EYE_LIGHT_MODELVIEW 0x4
 #define NEED_EYE_POINT_ATTEN     0x8
+#define NEED_EYE_DRIVER          0x10
 
 
 /*
@@ -1618,15 +1629,16 @@ struct gl_tnl_module {
 };
 
 
-/*
- * The library context:
+/**
+ * This is the central context data structure for Mesa.  Almost all
+ * OpenGL state is contained in this structure.
  */
 struct __GLcontextRec {
-   /*
-   ** Os related interfaces; these *must* be the first members of this
-   ** structure, because they are exposed to the outside world (i.e. GLX
-   ** extension).
-   */
+   /**
+    * OS related interfaces; these *must* be the first members of this
+    * structure, because they are exposed to the outside world (i.e. GLX
+    * extension).
+    */
    __GLimports imports;
    __GLexports exports;
 
@@ -1634,52 +1646,39 @@ struct __GLcontextRec {
    struct gl_shared_state *Shared;
 
    /* API function pointer tables */
-   struct _glapi_table *Save;  /* Display list save funcs */
-   struct _glapi_table *Exec;  /* Execute funcs */
-   struct _glapi_table *CurrentDispatch;  /* == Save or Exec !! */
+   struct _glapi_table *Save;  /**< Display list save funcs */
+   struct _glapi_table *Exec;  /**< Execute funcs */
+   struct _glapi_table *CurrentDispatch;  /**< == Save or Exec !! */
 
-   GLboolean ExecPrefersFloat; /* What preference for color conversion? */
+   GLboolean ExecPrefersFloat; /**< What preference for color conversion? */
    GLboolean SavePrefersFloat;
 
    GLvisual Visual;
-   GLframebuffer *DrawBuffer;  /* buffer for writing */
-   GLframebuffer *ReadBuffer;  /* buffer for reading */
+   GLframebuffer *DrawBuffer;  /**< buffer for writing */
+   GLframebuffer *ReadBuffer;  /**< buffer for reading */
 
-   /* Driver function pointer table */
+   /**
+    * Device driver function pointer table
+    */
    struct dd_function_table Driver;
 
-   void *DriverCtx;    /* Points to device driver context/state */
-   void *DriverMgrCtx; /* Points to device driver manager (optional)*/
+   void *DriverCtx;    /**< Points to device driver context/state */
+   void *DriverMgrCtx; /**< Points to device driver manager (optional)*/
 
    /* Core/Driver constants */
    struct gl_constants Const;
 
-   /* Modelview matrix and stack */
-   GLmatrix ModelView;           /* current matrix, not stored on stack */
-   GLuint ModelViewStackDepth;
-   GLmatrix ModelViewStack[MAX_MODELVIEW_STACK_DEPTH - 1];
-#if 1
-   struct matrix_stack ModelviewStack;
-#endif
-
-   /* Projection matrix and stack */
-   GLmatrix ProjectionMatrix;    /* current matrix, not stored on stack */
-   GLuint ProjectionStackDepth;
-   GLmatrix ProjectionStack[MAX_PROJECTION_STACK_DEPTH - 1];
+   /* The various 4x4 matrix stacks */
+   struct matrix_stack ModelviewMatrixStack;
+   struct matrix_stack ProjectionMatrixStack;
+   struct matrix_stack ColorMatrixStack;
+   struct matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
+   struct matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
+   struct matrix_stack *CurrentStack; /* Points to one of the above stacks */
 
    /* Combined modelview and projection matrix */
    GLmatrix _ModelProjectMatrix;
 
-   /* Texture matrix and stack */
-   GLmatrix TextureMatrix[MAX_TEXTURE_UNITS];
-   GLuint TextureStackDepth[MAX_TEXTURE_UNITS];
-   GLmatrix TextureStack[MAX_TEXTURE_UNITS][MAX_TEXTURE_STACK_DEPTH - 1];
-
-   /* Color matrix and stack */
-   GLmatrix ColorMatrix;
-   GLuint ColorStackDepth;
-   GLmatrix ColorStack[MAX_COLOR_STACK_DEPTH - 1];
-
    /* Display lists */
    GLuint CallDepth;           /* Current recursion calling depth */
    GLboolean ExecuteFlag;      /* Execute GL commands? */
@@ -1745,7 +1744,7 @@ struct __GLcontextRec {
    struct gl_color_table PostColorMatrixColorTable;
    struct gl_color_table ProxyPostColorMatrixColorTable;
 
-   struct gl_vertex_program VertexProgram;  /* GL_NV_vertex_program */
+   struct vertex_program_state VertexProgram;  /* GL_NV_vertex_program */
 
    GLenum ErrorValue;        /* Last error code */
    GLenum RenderMode;        /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */
@@ -1759,28 +1758,28 @@ struct __GLcontextRec {
    GLuint _NeedEyeCoords;
    GLuint _NeedNormals;    /* Are vertex normal vectors needed? */
 
-   struct gl_shine_tab *_ShineTable[2];  /* Active shine tables */
-   struct gl_shine_tab *_ShineTabList;   /* Mru list of inactive shine tables */
+   struct gl_shine_tab *_ShineTable[2]; /* Active shine tables */
+   struct gl_shine_tab *_ShineTabList;  /* Mru list of inactive shine tables */
 
    struct gl_list_extensions listext; /* driver dlist extensions */
 
 
-   GLboolean OcclusionResult;  /* GL_HP_occlusion_test */
-   GLboolean OcclusionResultSaved;  /* GL_HP_occlusion_test */
+   GLboolean OcclusionResult;       /**< for GL_HP_occlusion_test */
+   GLboolean OcclusionResultSaved;  /**< for GL_HP_occlusion_test */
 
    /* Z buffer stuff */
-   GLuint DepthMax;            /* Max depth buffer value */
-   GLfloat DepthMaxF;          /* Float max depth buffer value */
-   GLfloat MRD;                        /* minimum resolvable difference in Z values */
+   GLuint DepthMax;    /**< Max depth buffer value */
+   GLfloat DepthMaxF;  /**< Float max depth buffer value */
+   GLfloat MRD;                /**< minimum resolvable difference in Z values */
 
-   /* Should 3Dfx Glide driver catch signals? */
+   /** Should 3Dfx Glide driver catch signals? */
    GLboolean CatchSignals;
 
-   /* For debugging/development only */
+   /** For debugging/development only */
    GLboolean NoRaster;
    GLboolean FirstTimeCurrent;
 
-   /* Dither disable via MESA_NO_DITHER env var */
+   /** Dither disable via MESA_NO_DITHER env var */
    GLboolean NoDither;
 
    GLboolean Rendering;