Clean-up/renaming of the per-vertex attribute bits, specifically, the
[mesa.git] / src / mesa / main / mtypes.h
index 7992b00304e048e9a141861c92d7d0149fb12913..0dec13c3aed6b5b067b31adfa795ce03c11f6440 100644 (file)
@@ -1,21 +1,21 @@
-/* $Id: mtypes.h,v 1.9 2001/01/02 22:02:51 brianp Exp $ */
+/* $Id: mtypes.h,v 1.63 2002/01/22 14:35:16 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
- * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
- * 
+ * Version:  4.1
+ *
+ * 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"),
  * to deal in the Software without restriction, including without limitation
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * 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
+
 
 #include "glheader.h"
 #include "config.h"            /* Hardwired parameters */
 #include "glthread.h"
 
 #include "math/m_matrix.h"     /* GLmatrix */
-#include "math/m_translate.h"  /* trans_XXX_func */
 
 #if defined(MESA_TRACE)
 #include "Trace/tr_context.h"
 #endif
 
 
-/* This is a macro on IRIX */
-#ifdef _P
-#undef _P
-#endif
-
-
 /* Please try to mark derived values with a leading underscore ('_').
  */
 
 #define CHAN_MAXF 1.0F
 #define CHAN_TYPE GL_FLOAT
 #else
-#error  illegal number of color channel bits
+#error "illegal number of color channel bits"
 #endif
 
 
-/*
+/**
  * Accumulation buffer data type:
  */
 #if ACCUM_BITS==8
    typedef GLbyte GLaccum;
 #elif ACCUM_BITS==16
    typedef GLshort GLaccum;
+#elif ACCUM_BITS==32
+   typedef GLfloat GLaccum;
 #else
 #  error "illegal number of accumulation bits"
 #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;
+struct gl_texture_image;
 struct gl_texture_object;
-typedef struct gl_visual GLvisual;
-typedef struct gl_frame_buffer GLframebuffer;
 typedef struct __GLcontextRec GLcontext;
+typedef struct __GLcontextModesRec GLvisual;
+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)
@@ -132,17 +177,17 @@ typedef struct __GLcontextRec GLcontext;
 
 /* Data structure for color tables */
 struct gl_color_table {
-   GLvoid *Table;
-   GLboolean FloatTable;  /* entries stored as floats? (or GLchan type) */
-   GLuint Size;           /* number of entries (rows) in table */
-   GLenum Format;
+   GLenum Format;         /* GL_ALPHA, GL_RGB, GL_RGB, etc */
    GLenum IntFormat;
-   GLint RedSize;
-   GLint GreenSize;
-   GLint BlueSize;
-   GLint AlphaSize;
-   GLint LuminanceSize;
-   GLint IntensitySize;
+   GLuint Size;           /* number of entries (rows) in table */
+   GLvoid *Table;         /* either GLfloat * or GLchan * */
+   GLboolean FloatTable;  /* are entries stored as floats? */
+   GLubyte RedSize;
+   GLubyte GreenSize;
+   GLubyte BlueSize;
+   GLubyte AlphaSize;
+   GLubyte LuminanceSize;
+   GLubyte IntensitySize;
 };
 
 
@@ -189,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 */
@@ -212,14 +257,14 @@ struct gl_light {
    GLfloat _VP_inf_norm[3];    /* Norm direction to infinite light */
    GLfloat _h_inf_norm[3];     /* Norm( _VP_inf_norm + <0,0,1> ) */
    GLfloat _NormDirection[4];  /* normalized spotlight direction */
-   GLfloat _VP_inf_spot_attenuation; 
+   GLfloat _VP_inf_spot_attenuation;
 
    GLfloat _SpotExpTable[EXP_TABLE_SIZE][2];  /* to replace a pow() call */
    GLfloat _MatAmbient[2][3];  /* material ambient * light ambient */
    GLfloat _MatDiffuse[2][3];  /* material diffuse * light diffuse */
    GLfloat _MatSpecular[2][3]; /* material spec * light specular */
-   GLfloat _dli;                       /* CI diffuse light intensity */
-   GLfloat _sli;                       /* CI specular light intensity */
+   GLfloat _dli;               /* CI diffuse light intensity */
+   GLfloat _sli;               /* CI specular light intensity */
 };
 
 
@@ -232,7 +277,7 @@ struct gl_lightmodel {
 };
 
 
-struct gl_material 
+struct gl_material
 {
    GLfloat Ambient[4];
    GLfloat Diffuse[4];
@@ -266,14 +311,14 @@ struct gl_accum_attrib {
 
 struct gl_colorbuffer_attrib {
    GLuint ClearIndex;                  /* Index to use for glClear */
-   GLfloat ClearColor[4];              /* Color to use for glClear */
+   GLchan ClearColor[4];               /* Color to use for glClear */
 
    GLuint IndexMask;                   /* Color index write mask */
    GLubyte ColorMask[4];               /* Each flag is 0xff or 0x0 */
 
    GLenum DrawBuffer;                  /* Which buffer to draw into */
    GLenum DriverDrawBuffer;            /* Current device driver dest buffer */
-   GLboolean MultiDrawBuffer;          /* Drawing to mutliple buffers? */
+   GLboolean MultiDrawBuffer;          /* Drawing to multiple buffers? */
    GLubyte DrawDestMask;               /* bitwise-OR of bitflags above */
 
    /* alpha testing */
@@ -302,23 +347,23 @@ struct gl_colorbuffer_attrib {
 struct gl_current_attrib {
    /* These values valid only when FLUSH_VERTICES has been called.
     */
-   GLfloat Normal[3];                          /* Current vertex normal */
-   GLchan Color[4];                            /* Current RGBA color */
-   GLchan SecondaryColor[4];                   /* Current secondary color */
-   GLfloat FogCoord;                           /* Current Fog coord */
+   GLfloat Attrib[VERT_ATTRIB_MAX][4];         /* Current vertex attributes */
+                                               /* indexed by VERT_ATTRIB_* */
    GLuint Index;                               /* Current color index */
    GLboolean EdgeFlag;                         /* Current edge flag */
-   GLfloat Texcoord[MAX_TEXTURE_UNITS][4];     /* Current texture coords */
-       
-   /* These values are always valid.
+
+   /* These values are always valid.  BTW, note how similar this set of
+    * attributes is to the SWvertex datatype in the software rasterizer...
     */
    GLfloat RasterPos[4];                       /* Current raster position */
    GLfloat RasterDistance;                     /* Current raster distance */
    GLfloat RasterColor[4];                     /* Current raster color */
-   GLuint  RasterIndex;                                /* Current raster index */
-   GLfloat *RasterTexCoord;                    /* Current raster texcoord*/
+   GLfloat RasterSecondaryColor[4];             /* Current rast 2ndary color */
+   GLuint RasterIndex;                         /* Current raster index */
+   GLfloat *RasterTexCoord;                    /* Current raster texcoord */
    GLfloat RasterMultiTexCoord[MAX_TEXTURE_UNITS][4];
-   GLboolean RasterPosValid;                   /* Raster po valid flag */
+   GLfloat RasterFogCoord;
+   GLboolean RasterPosValid;                   /* Raster pos valid flag */
 };
 
 
@@ -360,6 +405,7 @@ struct gl_enable_attrib {
    GLboolean Map1TextureCoord4;
    GLboolean Map1Vertex3;
    GLboolean Map1Vertex4;
+   GLboolean Map1Attrib[16];  /* GL_NV_vertex_program */
    GLboolean Map2Color4;
    GLboolean Map2Index;
    GLboolean Map2Normal;
@@ -369,6 +415,7 @@ struct gl_enable_attrib {
    GLboolean Map2TextureCoord4;
    GLboolean Map2Vertex3;
    GLboolean Map2Vertex4;
+   GLboolean Map2Attrib[16];  /* GL_NV_vertex_program */
    GLboolean MinMax;
    GLboolean Normalize;
    GLboolean PixelTexture;
@@ -381,8 +428,18 @@ struct gl_enable_attrib {
    GLboolean RescaleNormals;
    GLboolean Scissor;
    GLboolean Stencil;
+   GLboolean MultisampleEnabled;     /* GL_ARB_multisample */
+   GLboolean SampleAlphaToCoverage;  /* GL_ARB_multisample */
+   GLboolean SampleAlphaToOne;       /* GL_ARB_multisample */
+   GLboolean SampleCoverage;         /* GL_ARB_multisample */
+   GLboolean SampleCoverageInvert;   /* GL_ARB_multisample */
+   GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
    GLuint Texture[MAX_TEXTURE_UNITS];
    GLuint TexGen[MAX_TEXTURE_UNITS];
+   /* GL_NV_vertex_program */
+   GLboolean VertexProgram;
+   GLboolean VertexProgramPointSize;
+   GLboolean VertexProgramTwoSide;
 };
 
 
@@ -397,6 +454,7 @@ struct gl_eval_attrib {
    GLboolean Map1TextureCoord4;
    GLboolean Map1Vertex3;
    GLboolean Map1Vertex4;
+   GLboolean Map1Attrib[16];  /* GL_NV_vertex_program */
    GLboolean Map2Color4;
    GLboolean Map2Index;
    GLboolean Map2Normal;
@@ -406,6 +464,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;
@@ -425,7 +484,7 @@ struct gl_fog_attrib {
    GLfloat Index;              /* Fog index */
    GLenum Mode;                        /* Fog mode */
    GLboolean ColorSumEnabled;
-   GLenum FogCoordinateSource;
+   GLenum FogCoordinateSource;  /* GL_EXT_fog_coord */
 };
 
 
@@ -436,31 +495,22 @@ struct gl_hint_attrib {
    GLenum LineSmooth;
    GLenum PolygonSmooth;
    GLenum Fog;
-
-   /* GL_PGI_misc_hints */
-   GLenum AllowDrawWin;
-   GLenum AllowDrawFrg;
-   GLenum AllowDrawMem;
-   GLenum StrictLighting;
-
-   /* GL_EXT_clip_volume_hint */
-   GLenum ClipVolumeClipping;
-
-   /* GL_ARB_texture_compression */
-   GLenum TextureCompression;
+   GLenum ClipVolumeClipping;   /* GL_EXT_clip_volume_hint */
+   GLenum TextureCompression;   /* GL_ARB_texture_compression */
+   GLenum GenerateMipmap;       /* GL_SGIS_generate_mipmap */
 };
 
 
 struct gl_histogram_attrib {
-   GLuint Width;
-   GLint Format;
-   GLboolean Sink;
-   GLuint RedSize;
-   GLuint GreenSize;
-   GLuint BlueSize;
-   GLuint AlphaSize;
-   GLuint LuminanceSize;
-   GLuint Count[HISTOGRAM_TABLE_SIZE][4];
+   GLuint Width;                               /* number of table entries */
+   GLint Format;                               /* GL_ALPHA, GL_RGB, etc */
+   GLuint Count[HISTOGRAM_TABLE_SIZE][4];      /* the histogram */
+   GLboolean Sink;                             /* terminate image transfer? */
+   GLubyte RedSize;                            /* Bits per counter */
+   GLubyte GreenSize;
+   GLubyte BlueSize;
+   GLubyte AlphaSize;
+   GLubyte LuminanceSize;
 };
 
 
@@ -480,6 +530,11 @@ struct gl_convolution_attrib {
 };
 
 
+#define LIGHT_SPOT         0x1
+#define LIGHT_LOCAL_VIEWER 0x2
+#define LIGHT_POSITIONAL   0x4
+#define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
+
 struct gl_light_attrib {
    struct gl_light Light[MAX_LIGHTS];  /* Array of lights */
    struct gl_lightmodel Model;         /* Lighting model */
@@ -499,24 +554,18 @@ struct gl_light_attrib {
 
    /* Derived for optimizations: */
    GLboolean _NeedVertices;            /* Use fast shader? */
-   GLuint  _Flags;                     /* LIGHT_* flags, see below */
+   GLuint  _Flags;                     /* LIGHT_* flags, see above */
    GLfloat _BaseColor[2][3];
-   GLchan _BaseAlpha[2];
 };
 
 
-#define LIGHT_POSITIONAL   0x4
-#define LIGHT_SPOT         0x10
-#define LIGHT_LOCAL_VIEWER 0x20
-
-#define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
-
 struct gl_line_attrib {
    GLboolean SmoothFlag;       /* GL_LINE_SMOOTH enabled? */
    GLboolean StippleFlag;      /* GL_LINE_STIPPLE enabled? */
    GLushort StipplePattern;    /* Stipple pattern */
    GLint StippleFactor;                /* Stipple repeat factor */
    GLfloat Width;              /* Line width */
+   GLfloat _Width;             /* Clamped Line width */
 };
 
 
@@ -524,6 +573,7 @@ struct gl_list_attrib {
    GLuint ListBase;
 };
 
+
 struct gl_list_opcode {
    GLuint size;
    void (*execute)( GLcontext *ctx, void *data );
@@ -538,6 +588,17 @@ struct gl_list_extensions {
    GLuint nr_opcodes;
 };
 
+
+struct gl_multisample_attrib {
+   GLboolean Enabled;
+   GLboolean SampleAlphaToCoverage;
+   GLboolean SampleAlphaToOne;
+   GLboolean SampleCoverage;
+   GLfloat SampleCoverageValue;
+   GLboolean SampleCoverageInvert;
+};
+
+
 struct gl_pixel_attrib {
    GLenum ReadBuffer;          /* src buffer for glRead/CopyPixels */
    GLenum DriverReadBuffer;    /* Driver's current source buffer */
@@ -550,6 +611,7 @@ struct gl_pixel_attrib {
    GLboolean MapColorFlag;
    GLboolean MapStencilFlag;
    GLfloat ZoomX, ZoomY;
+   /* XXX move these out of gl_pixel_attrib */
    GLint MapStoSsize;          /* Size of each pixel map */
    GLint MapItoIsize;
    GLint MapItoRsize;
@@ -685,22 +747,22 @@ struct gl_stencil_attrib {
 #define TEXTURE3_3D   (TEXTURE0_3D << 12)
 #define TEXTURE3_CUBE (TEXTURE0_CUBE << 12)
 #define TEXTURE3_ANY  (TEXTURE3_1D | TEXTURE3_2D | TEXTURE3_3D | TEXTURE3_CUBE)
-#define TEXTURE4_1D   (TEXTURE0_1D << 16)    /* Texture unit 3 */
+#define TEXTURE4_1D   (TEXTURE0_1D << 16)    /* Texture unit 4 */
 #define TEXTURE4_2D   (TEXTURE0_2D << 16)
 #define TEXTURE4_3D   (TEXTURE0_3D << 16)
 #define TEXTURE4_CUBE (TEXTURE0_CUBE << 16)
 #define TEXTURE5_ANY  (TEXTURE3_1D | TEXTURE3_2D | TEXTURE3_3D | TEXTURE3_CUBE)
-#define TEXTURE5_1D   (TEXTURE0_1D << 20)    /* Texture unit 3 */
+#define TEXTURE5_1D   (TEXTURE0_1D << 20)    /* Texture unit 5 */
 #define TEXTURE5_2D   (TEXTURE0_2D << 20)
 #define TEXTURE5_3D   (TEXTURE0_3D << 20)
 #define TEXTURE5_CUBE (TEXTURE0_CUBE << 20)
 #define TEXTURE5_ANY  (TEXTURE3_1D | TEXTURE3_2D | TEXTURE3_3D | TEXTURE3_CUBE)
-#define TEXTURE6_1D   (TEXTURE0_1D << 24)    /* Texture unit 3 */
+#define TEXTURE6_1D   (TEXTURE0_1D << 24)    /* Texture unit 6 */
 #define TEXTURE6_2D   (TEXTURE0_2D << 24)
 #define TEXTURE6_3D   (TEXTURE0_3D << 24)
 #define TEXTURE6_CUBE (TEXTURE0_CUBE << 24)
 #define TEXTURE6_ANY  (TEXTURE3_1D | TEXTURE3_2D | TEXTURE3_3D | TEXTURE3_CUBE)
-#define TEXTURE7_1D   (TEXTURE0_1D << 28)    /* Texture unit 3 */
+#define TEXTURE7_1D   (TEXTURE0_1D << 28)    /* Texture unit 7 */
 #define TEXTURE7_2D   (TEXTURE0_2D << 28)
 #define TEXTURE7_3D   (TEXTURE0_3D << 28)
 #define TEXTURE7_CUBE (TEXTURE0_CUBE << 28)
@@ -714,16 +776,9 @@ struct gl_stencil_attrib {
 #define TEXGEN_REFLECTION_MAP_NV 0x8
 #define TEXGEN_NORMAL_MAP_NV     0x10
 
-#define TEXGEN_NEED_M            (TEXGEN_SPHERE_MAP)
-#define TEXGEN_NEED_F            (TEXGEN_SPHERE_MAP        | \
-                                 TEXGEN_REFLECTION_MAP_NV)
 #define TEXGEN_NEED_NORMALS      (TEXGEN_SPHERE_MAP        | \
                                  TEXGEN_REFLECTION_MAP_NV | \
                                  TEXGEN_NORMAL_MAP_NV)
-#define TEXGEN_NEED_VERTICES     (TEXGEN_OBJ_LINEAR |          \
-                                 TEXGEN_EYE_LINEAR |           \
-                                 TEXGEN_REFLECTION_MAP_NV |    \
-                                 TEXGEN_SPHERE_MAP )
 #define TEXGEN_NEED_EYE_COORD    (TEXGEN_SPHERE_MAP        | \
                                  TEXGEN_REFLECTION_MAP_NV | \
                                  TEXGEN_NORMAL_MAP_NV     | \
@@ -741,49 +796,61 @@ struct gl_stencil_attrib {
 #define ENABLE_TEXGEN5        0x20
 #define ENABLE_TEXGEN6        0x40
 #define ENABLE_TEXGEN7        0x80
-#define ENABLE_TEXMAT0        0x100    /* Ie. not the identity matrix */
-#define ENABLE_TEXMAT1        0x200
-#define ENABLE_TEXMAT2        0x400
-#define ENABLE_TEXMAT3        0x800
-#define ENABLE_TEXMAT4        0x1000   
-#define ENABLE_TEXMAT5        0x2000
-#define ENABLE_TEXMAT6        0x4000
-#define ENABLE_TEXMAT7        0x8000
-#define ENABLE_LIGHT          0x10000
-#define ENABLE_FOG            0x20000
-#define ENABLE_USERCLIP       0x40000
-#define ENABLE_NORMALIZE      0x100000
-#define ENABLE_RESCALE        0x200000
-#define ENABLE_POINT_ATTEN    0x400000
-
-
-#define ENABLE_TEXGEN_ANY (ENABLE_TEXGEN0 | ENABLE_TEXGEN1 | \
-                           ENABLE_TEXGEN2 | ENABLE_TEXGEN3 | \
-                           ENABLE_TEXGEN4 | ENABLE_TEXGEN5 | \
-                           ENABLE_TEXGEN6 | ENABLE_TEXGEN7)
-
-#define ENABLE_TEXMAT_ANY (ENABLE_TEXMAT0 | ENABLE_TEXMAT1 | \
-                           ENABLE_TEXMAT2 | ENABLE_TEXMAT3 | \
-                           ENABLE_TEXMAT4 | ENABLE_TEXMAT5 | \
-                           ENABLE_TEXMAT6 | ENABLE_TEXMAT7)
+
+#define ENABLE_TEXMAT0        0x1      /* Ie. not the identity matrix */
+#define ENABLE_TEXMAT1        0x2
+#define ENABLE_TEXMAT2        0x4
+#define ENABLE_TEXMAT3        0x8
+#define ENABLE_TEXMAT4        0x10
+#define ENABLE_TEXMAT5        0x20
+#define ENABLE_TEXMAT6        0x40
+#define ENABLE_TEXMAT7        0x80
 
 #define ENABLE_TEXGEN(i) (ENABLE_TEXGEN0 << (i))
 #define ENABLE_TEXMAT(i) (ENABLE_TEXMAT0 << (i))
 
+/*
+ * If teximage is color-index, texelOut returns GLchan[1].
+ * If teximage is depth, texelOut returns GLfloat[1].
+ * Otherwise, texelOut returns GLchan[4].
+ */
+typedef void (*FetchTexelFunc)( const struct gl_texture_image *texImage,
+                                GLint col, GLint row, GLint img,
+                                GLvoid *texelOut );
+
+/* Texture format record */
+struct gl_texture_format {
+   GLint MesaFormat;           /* One of the MESA_FORMAT_* values */
+
+   GLenum BaseFormat;          /* Either GL_ALPHA, GL_INTENSITY, GL_LUMINANCE,
+                                 * GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA,
+                                 * GL_COLOR_INDEX or GL_DEPTH_COMPONENT.
+                                 */
+   GLenum Type;                        /* Internal type as GL enum value */
+
+   GLubyte RedBits;            /* Bits per texel component */
+   GLubyte GreenBits;
+   GLubyte BlueBits;
+   GLubyte AlphaBits;
+   GLubyte LuminanceBits;
+   GLubyte IntensityBits;
+   GLubyte IndexBits;
+   GLubyte DepthBits;
+
+   GLint TexelBytes;
+
+   FetchTexelFunc FetchTexel1D;        /* Texel fetch function pointers */
+   FetchTexelFunc FetchTexel2D;
+   FetchTexelFunc FetchTexel3D;
+};
+
 /* Texture image record */
 struct gl_texture_image {
    GLenum Format;              /* GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
-                                * GL_INTENSITY, GL_RGB, GL_RGBA, or
-                                * GL_COLOR_INDEX only
+                                * GL_INTENSITY, GL_RGB, GL_RGBA,
+                                 * GL_COLOR_INDEX or GL_DEPTH_COMPONENT only.
                                 */
-   GLenum IntFormat;           /* Internal format as given by the user */
-   GLubyte RedBits;            /* Bits per texel component              */
-   GLubyte GreenBits;          /*   These are initialized by Mesa but   */
-   GLubyte BlueBits;           /*   may be reassigned by the device     */
-   GLubyte AlphaBits;          /*   driver to indicate the true texture */
-   GLubyte IntensityBits;      /*   color resolution.                   */
-   GLubyte LuminanceBits;
-   GLubyte IndexBits;
+   GLint IntFormat;            /* Internal format as given by the user */
    GLuint Border;              /* 0 or 1 */
    GLuint Width;               /* = 2^WidthLog2 + 2*Border */
    GLuint Height;              /* = 2^HeightLog2 + 2*Border */
@@ -795,7 +862,11 @@ struct gl_texture_image {
    GLuint HeightLog2;          /* = log2(Height2) */
    GLuint DepthLog2;           /* = log2(Depth2) */
    GLuint MaxLog2;             /* = MAX(WidthLog2, HeightLog2) */
-   GLchan *Data;               /* Image data as GLchan's */
+   GLvoid *Data;               /* Image data, accessed via FetchTexel() */
+
+   const struct gl_texture_format *TexFormat;
+
+   FetchTexelFunc FetchTexel;  /* Texel fetch function pointer */
 
    GLboolean IsCompressed;     /* GL_ARB_texture_compression */
    GLuint CompressedSize;      /* GL_ARB_texture_compression */
@@ -810,20 +881,30 @@ struct gl_texture_object {
    _glthread_Mutex Mutex;      /* for thread safety */
    GLint RefCount;             /* reference count */
    GLuint Name;                        /* an unsigned integer */
-   GLuint Dimensions;          /* 1 or 2 or 3 */
+   GLuint Dimensions;          /* 1 or 2 or 3 or 6 (cube map) */
    GLfloat Priority;           /* in [0,1] */
-   GLchan BorderColor[4];      /* as integers */
-   GLenum WrapS;               /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
-   GLenum WrapT;               /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
-   GLenum WrapR;               /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
+   GLfloat BorderValues[4];     /* unclamped */
+   GLchan BorderColor[4];       /* clamped, as GLchan */
+   GLenum WrapS;               /* Wrap modes are: GL_CLAMP, REPEAT */
+   GLenum WrapT;               /*   GL_CLAMP_TO_EDGE, and          */
+   GLenum WrapR;               /*   GL_CLAMP_TO_BORDER_ARB         */
    GLenum MinFilter;           /* minification filter */
    GLenum MagFilter;           /* magnification filter */
-   GLfloat MinLod;             /* OpenGL 1.2 */
-   GLfloat MaxLod;             /* OpenGL 1.2 */
-   GLint BaseLevel;            /* user-specified, OpenGL 1.2 */
-   GLint MaxLevel;             /* user-specified, OpenGL 1.2 */
+   GLfloat MinLod;             /* min lambda, OpenGL 1.2 */
+   GLfloat MaxLod;             /* max lambda, OpenGL 1.2 */
+   GLint BaseLevel;            /* min mipmap level, OpenGL 1.2 */
+   GLint MaxLevel;             /* max mipmap level, OpenGL 1.2 */
+   GLfloat MaxAnisotropy;      /* GL_EXT_texture_filter_anisotropic */
+   GLboolean CompareFlag;      /* GL_SGIX_shadow */
+   GLenum CompareOperator;     /* GL_SGIX_shadow */
+   GLchan ShadowAmbient;       /* GL_SGIX/ARB_shadow_ambient */
+   GLenum CompareMode;         /* GL_ARB_shadow */
+   GLenum CompareFunc;         /* GL_ARB_shadow */
+   GLenum CompareResult;       /* GL_ARB_shadow */
    GLint _MaxLevel;            /* actual max mipmap level (q in the spec) */
    GLfloat _MaxLambda;         /* = _MaxLevel - BaseLevel (q - b in spec) */
+   GLboolean GenerateMipmap;    /* GL_SGIS_generate_mipmap */
+
    struct gl_texture_image *Image[MAX_TEXTURE_LEVELS];
 
    /* Texture cube faces */
@@ -902,16 +983,18 @@ struct gl_texture_unit {
 struct gl_texture_attrib {
    /* multitexture */
    GLuint CurrentUnit;           /* Active texture unit */
-   GLuint CurrentTransformUnit;          /* Client active texture xform unit */
 
    GLuint _ReallyEnabled;     /* enables for all texture units: */
                              /* = (Unit[0]._ReallyEnabled << 0) | */
                              /*   (Unit[1]._ReallyEnabled << 4) | */
                             /*   (Unit[2]._ReallyEnabled << 8) | etc... */
+
    GLuint _GenFlags;  /* for texgen */
+   GLuint _TexGenEnabled;      
+   GLuint _TexMatEnabled;
 
    struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
-       
+
    struct gl_texture_object *Proxy1D;
    struct gl_texture_object *Proxy2D;
    struct gl_texture_object *Proxy3D;
@@ -931,6 +1014,7 @@ struct gl_transform_attrib {
    GLubyte   _AnyClip;                         /* How many ClipEnabled? */
    GLboolean Normalize;                                /* Normalize all normals? */
    GLboolean RescaleNormals;                   /* GL_EXT_rescale_normal */
+   GLboolean RasterPositionUnclipped;           /* GL_IBM_rasterpos_clip */
 };
 
 
@@ -950,7 +1034,6 @@ struct gl_attrib_node {
 };
 
 
-
 /*
  * Client pixel packing/unpacking attributes
  */
@@ -966,6 +1049,9 @@ struct gl_pixelstore_attrib {
 };
 
 
+#define CA_CLIENT_DATA     0x1 /* Data not alloced by mesa */
+
+
 /*
  * Client vertex array attributes
  */
@@ -975,12 +1061,11 @@ struct gl_client_array {
    GLsizei Stride;             /* user-specified stride */
    GLsizei StrideB;            /* actual stride in bytes */
    void *Ptr;
-   GLboolean Enabled;
+   GLuint Flags;
+   GLuint Enabled;             /* one of the _NEW_ARRAY_ bits */
 };
 
 
-
-
 struct gl_array_attrib {
    struct gl_client_array Vertex;           /* client data descriptors */
    struct gl_client_array Normal;
@@ -991,6 +1076,8 @@ struct gl_array_attrib {
    struct gl_client_array TexCoord[MAX_TEXTURE_UNITS];
    struct gl_client_array EdgeFlag;
 
+   struct gl_client_array VertexAttrib[16];  /* GL_NV_vertex_program */
+
    GLint TexCoordInterleaveFactor;
    GLint ActiveTexture;                /* Client Active Texture */
    GLuint LockFirst;
@@ -1001,8 +1088,6 @@ struct gl_array_attrib {
 };
 
 
-
-
 struct gl_feedback {
    GLenum Type;
    GLuint _Mask;               /* FB_* bits */
@@ -1012,7 +1097,6 @@ struct gl_feedback {
 };
 
 
-
 struct gl_selection {
    GLuint *Buffer;
    GLuint BufferSize;  /* size of SelectBuffer */
@@ -1025,7 +1109,6 @@ struct gl_selection {
 };
 
 
-
 /*
  * 1-D Evaluator control points
  */
@@ -1034,7 +1117,7 @@ struct gl_1d_map {
    GLfloat u1, u2, du; /* u1, u2, 1.0/(u2-u1) */
    GLfloat *Points;    /* Points to contiguous control points */
 };
-       
+
 
 /*
  * 2-D Evaluator control points
@@ -1062,6 +1145,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;
@@ -1073,6 +1157,121 @@ 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 */
+};
+
+
+/*
+ * Vertex program tokens and datatypes
+ */
+
+#define VP_MAX_INSTRUCTIONS 128
+
+#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
+
+#define VP_NUM_TOTAL_REGISTERS (VP_NUM_INPUT_REGS + VP_NUM_OUTPUT_REGS + VP_NUM_TEMP_REGS + VP_NUM_PROG_REGS)
+
+/* Location of register sets within the whole register file */
+#define VP_INPUT_REG_START  0
+#define VP_INPUT_REG_END    (VP_INPUT_REG_START + VP_NUM_INPUT_REGS - 1)
+#define VP_OUTPUT_REG_START (VP_INPUT_REG_END + 1)
+#define VP_OUTPUT_REG_END   (VP_OUTPUT_REG_START + VP_NUM_OUTPUT_REGS - 1)
+#define VP_TEMP_REG_START   (VP_OUTPUT_REG_END + 1)
+#define VP_TEMP_REG_END     (VP_TEMP_REG_START + VP_NUM_TEMP_REGS - 1)
+#define VP_PROG_REG_START   (VP_TEMP_REG_END + 1)
+#define VP_PROG_REG_END     (VP_PROG_REG_START + VP_NUM_PROG_REGS - 1)
+
+
+/* Machine state (i.e. the register file) */
+struct vp_machine
+{
+   GLfloat Registers[VP_NUM_TOTAL_REGISTERS][4];
+   GLint AddressReg;  /* might someday be a 4-vector */
+};
+
+
+/* Vertex program opcodes */
+enum vp_opcode
+{
+   MOV,
+   LIT,
+   RCP,
+   RSQ,
+   EXP,
+   LOG,
+   MUL,
+   ADD,
+   DP3,
+   DP4,
+   DST,
+   MIN,
+   MAX,
+   SLT,
+   SGE,
+   MAD,
+   ARL,
+   END
+};
+
+
+/* Instruction source register */
+struct vp_src_register
+{
+   GLint Register;    /* or the offset from the address register */
+   GLuint Swizzle[4];
+   GLboolean Negate;
+   GLboolean RelAddr;
+};
+
+
+/* Instruction destination register */
+struct vp_dst_register
+{
+   GLint Register;
+   GLboolean WriteMask[4];
+};
+
+
+/* Vertex program instruction */
+struct vp_instruction
+{
+   enum vp_opcode Opcode;
+   struct vp_src_register SrcReg[3];
+   struct vp_dst_register DstReg;
+};
+
+
+/* The actual vertex program, stored in the hash table */
+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;            /* Position in string where error was detected */
+   GLint RefCount;            /* Since programs can be shared among contexts */
+   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 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 CurrentID;                     /* currently bound program's ID */
+   struct vp_program *Current;           /* ptr to currently bound program */
+   struct vp_machine Machine;            /* machine state */
+
+   GLenum TrackMatrix[VP_NUM_PROG_REGS / 4];
+   GLenum TrackMatrixTransform[VP_NUM_PROG_REGS / 4];
 };
 
 
@@ -1093,43 +1292,13 @@ struct gl_shared_state {
    struct gl_texture_object *Default3D;
    struct gl_texture_object *DefaultCubeMap;
 
-   void *DriverData;  /* Device driver shared state */
-};
-
-
+   /* GL_NV_vertex_program */
+   struct _mesa_HashTable *VertexPrograms;
 
-/*
- * Describes the color, depth, stencil and accum buffer parameters.
- * In C++ terms, think of this as a base class from which device drivers
- * will make derived classes.
- */
-struct gl_visual {
-   GLboolean RGBAflag;         /* Is frame buffer in RGBA mode, not CI? */
-   GLboolean DBflag;           /* Is color buffer double buffered? */
-   GLboolean StereoFlag;       /* stereo buffer? */
-
-   GLint RedBits;              /* Bits per color component */
-   GLint GreenBits;
-   GLint BlueBits;
-   GLint AlphaBits;
-
-   GLint IndexBits;            /* Bits/pixel if in color index mode */
-
-   GLint AccumRedBits;         /* Number of bits in red accum channel */
-   GLint AccumGreenBits;       /* Number of bits in green accum channel */
-   GLint AccumBlueBits;                /* Number of bits in blue accum channel */
-   GLint AccumAlphaBits;       /* Number of bits in alpha accum channel */
-   GLint DepthBits;            /* Number of bits in depth buffer, or 0 */
-   GLint StencilBits;          /* Number of bits in stencil buffer, or 0 */
-   GLint NumSamples;            /* Samples/pixel for multisampling */
-
-   GLuint DepthMax;            /* Max depth buffer value */
-   GLfloat DepthMaxF;          /* Float max depth buffer value */
-   GLfloat MRD;                        /* minimum resolvable difference in Z values */
+   void *DriverData;  /* Device driver shared state */
 };
 
 
-
 /*
  * A "frame buffer" is a color buffer and its optional ancillary buffers:
  * depth, accum, stencil, and software-simulated alpha buffers.
@@ -1137,7 +1306,7 @@ struct gl_visual {
  * will make derived classes.
  */
 struct gl_frame_buffer {
-   GLvisual *Visual;           /* The corresponding visual */
+   GLvisual Visual;            /* The corresponding visual */
 
    GLint Width, Height;                /* size of frame buffer in pixels */
 
@@ -1169,13 +1338,16 @@ struct gl_frame_buffer {
 
 
 /*
- * Constants which may be overriden by device driver.
+ * Constants which may be overriden by device driver during context creation
+ * but are never changed after that.
  */
 struct gl_constants {
-   GLint MaxTextureSize;
-   GLint MaxCubeTextureSize;
    GLint MaxTextureLevels;
+   GLint Max3DTextureLevels;
+   GLint MaxCubeTextureLevels;
    GLuint MaxTextureUnits;
+   GLfloat MaxTextureMaxAnisotropy;    /* GL_EXT_texture_filter_anisotropic */
+   GLfloat MaxTextureLodBias;           /* GL_EXT_texture_lod_bias */
    GLuint MaxArrayLockSize;
    GLint SubPixelBits;
    GLfloat MinPointSize, MaxPointSize;         /* aliased */
@@ -1206,10 +1378,16 @@ struct gl_extensions {
     * Not every extension needs to have such a flag, but it's encouraged.
     */
    GLboolean ARB_imaging;
+   GLboolean ARB_multisample;
    GLboolean ARB_multitexture;
+   GLboolean ARB_shadow;
+   GLboolean ARB_texture_border_clamp;
    GLboolean ARB_texture_compression;
    GLboolean ARB_texture_cube_map;
-   GLboolean ARB_texture_env_add;
+   GLboolean ARB_texture_env_combine;
+   GLboolean ARB_texture_env_dot3;
+   GLboolean ARB_texture_mirrored_repeat;
+   GLboolean ARB_window_pos;
    GLboolean EXT_blend_color;
    GLboolean EXT_blend_func_separate;
    GLboolean EXT_blend_logic_op;
@@ -1232,26 +1410,43 @@ struct gl_extensions {
    GLboolean EXT_texture_compression_s3tc;
    GLboolean EXT_texture_env_add;
    GLboolean EXT_texture_env_combine;
+   GLboolean EXT_texture_env_dot3;
+   GLboolean EXT_texture_filter_anisotropic;
    GLboolean EXT_texture_object;
    GLboolean EXT_texture_lod_bias;
    GLboolean EXT_vertex_array_set;
    GLboolean HP_occlusion_test;
+   GLboolean IBM_rasterpos_clip;
    GLboolean INGR_blend_func_separate;
    GLboolean MESA_window_pos;
    GLboolean MESA_resize_buffers;
    GLboolean MESA_sprite_point;
    GLboolean NV_blend_square;
    GLboolean NV_texgen_reflection;
-   GLboolean PGI_misc_hints;
+   GLboolean NV_vertex_program;
    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_pixel_texture;
+   GLboolean SGIX_shadow;
+   GLboolean SGIX_shadow_ambient; /* or GL_ARB_shadow_ambient */
    GLboolean _3DFX_texture_compression_FXT1;
 };
 
 
+/* XXX just an idea */
+struct matrix_stack
+{
+   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 */
+};
+
 
 /*
  * Bits for image transfer operations (ctx->ImageTransferState).
@@ -1296,79 +1491,74 @@ struct gl_extensions {
 #define _NEW_EVAL              0x80       /* ctx->Eval, ctx->EvalMap */
 #define _NEW_FOG               0x100      /* ctx->Fog */
 #define _NEW_HINT              0x200      /* ctx->Hint */
-#define _NEW_400               0x400      /*  */
-#define _NEW_LIGHT             0x800      /* ctx->Light */
-#define _NEW_1000                      0x1000     /*  */
-#define _NEW_LINE              0x2000     /* ctx->Line */
-#define _NEW_4000               0x4000     /*  */
-#define _NEW_PIXEL             0x8000     /* ctx->Pixel */
-#define _NEW_POINT             0x10000    /* ctx->Point */
-#define _NEW_POLYGON           0x20000    /* ctx->Polygon */
-#define _NEW_POLYGONSTIPPLE    0x40000    /* ctx->PolygonStipple */
-#define _NEW_SCISSOR           0x80000    /* ctx->Scissor */
-#define _NEW_STENCIL           0x100000   /* ctx->Stencil */
-#define _NEW_TEXTURE           0x200000   /* ctx->Texture */
-#define _NEW_TRANSFORM         0x400000   /* ctx->Transform */
-#define _NEW_VIEWPORT          0x800000   /* ctx->Viewport */
-#define _NEW_PACKUNPACK                0x1000000  /* ctx->Pack, ctx->Unpack */
-#define _NEW_ARRAY             0x2000000  /* ctx->Array */
-#define _NEW_COLORTABLE                0x4000000  /* ctx->{*}ColorTable */
-#define _NEW_RENDERMODE                0x8000000  /* RenderMode, Feedback, Select */
-#define _NEW_BUFFERS            0x10000000 /* ctx->Visual, ctx->DrawBuffer, */
-
+#define _NEW_LIGHT             0x400      /* ctx->Light */
+#define _NEW_LINE              0x800      /* ctx->Line */
+#define _NEW_PIXEL             0x1000     /* ctx->Pixel */
+#define _NEW_POINT             0x2000     /* ctx->Point */
+#define _NEW_POLYGON           0x4000     /* ctx->Polygon */
+#define _NEW_POLYGONSTIPPLE    0x8000     /* ctx->PolygonStipple */
+#define _NEW_SCISSOR           0x10000    /* ctx->Scissor */
+#define _NEW_STENCIL           0x20000    /* ctx->Stencil */
+#define _NEW_TEXTURE           0x40000    /* ctx->Texture */
+#define _NEW_TRANSFORM         0x80000    /* ctx->Transform */
+#define _NEW_VIEWPORT          0x100000   /* ctx->Viewport */
+#define _NEW_PACKUNPACK                0x200000   /* ctx->Pack, ctx->Unpack */
+#define _NEW_ARRAY             0x400000   /* ctx->Array */
+#define _NEW_RENDERMODE                0x800000   /* RenderMode, Feedback, Select */
+#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           0x1        
-#define _NEW_ARRAY_COLOR            0x2        
-#define _NEW_ARRAY_NORMAL           0x4        
-#define _NEW_ARRAY_INDEX            0x8        
-#define _NEW_ARRAY_EDGEFLAG         0x10
-#define _NEW_ARRAY_SECONDARYCOLOR   0x20
-#define _NEW_ARRAY_FOGCOORD         0x40
-#define _NEW_ARRAY_TEXCOORD_0       0x80       
-#define _NEW_ARRAY_TEXCOORD_1       0x100
-#define _NEW_ARRAY_TEXCOORD_2       0x200
-#define _NEW_ARRAY_TEXCOORD_3       0x400
-#define _NEW_ARRAY_TEXCOORD_4       0x800      
-#define _NEW_ARRAY_TEXCOORD_5       0x1000
-#define _NEW_ARRAY_TEXCOORD_6       0x2000
-#define _NEW_ARRAY_TEXCOORD_7       0x4000
-#define _NEW_ARRAY_ALL              0x7fff
-
-#define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0<<(i))
+#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
+
+
+#define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0 << (i))
 
 /* A bunch of flags that we think might be useful to drivers.
  */
-#define DD_FEEDBACK                 0x1
-#define DD_SELECT                   0x2
-#define DD_FLATSHADE                0x4
-#define DD_SEPERATE_SPECULAR        0x10
-#define DD_TRI_LIGHT_TWOSIDE        0x20
-#define DD_TRI_UNFILLED             0x40
-#define DD_TRI_SMOOTH               0x80
-#define DD_TRI_STIPPLE              0x100
-#define DD_TRI_OFFSET               0x200
-#define DD_LINE_SMOOTH              0x800
-#define DD_LINE_STIPPLE             0x1000
-#define DD_LINE_WIDTH               0x2000
-#define DD_POINT_SMOOTH             0x4000
-#define DD_POINT_SIZE               0x8000
-#define DD_POINT_ATTEN              0x10000
-#define DD_TRI_CULL_FRONT_BACK      0x400000 /* special case on some hw */
-#define DD_Z_NEVER                  0x800000 /* special case on some hw */
-#define DD_STENCIL                  0x1000000 
+#define DD_FLATSHADE                0x1
+#define DD_SEPARATE_SPECULAR        0x2
+#define DD_TRI_CULL_FRONT_BACK      0x4 /* special case on some hw */
+#define DD_TRI_LIGHT_TWOSIDE        0x8
+#define DD_TRI_UNFILLED             0x10
+#define DD_TRI_SMOOTH               0x20
+#define DD_TRI_STIPPLE              0x40
+#define DD_TRI_OFFSET               0x80
+#define DD_LINE_SMOOTH              0x100
+#define DD_LINE_STIPPLE             0x200
+#define DD_LINE_WIDTH               0x400
+#define DD_POINT_SMOOTH             0x800
+#define DD_POINT_SIZE               0x1000
+#define DD_POINT_ATTEN              0x2000
 
 /* Define the state changes under which each of these bits might change
  */
-#define _DD_NEW_FEEDBACK                 _NEW_RENDERMODE
-#define _DD_NEW_SELECT                   _NEW_RENDERMODE
 #define _DD_NEW_FLATSHADE                _NEW_LIGHT
-#define _DD_NEW_MULTIDRAW                _NEW_COLOR
-#define _DD_NEW_SEPERATE_SPECULAR        (_NEW_LIGHT|_NEW_FOG)
+#define _DD_NEW_SEPARATE_SPECULAR        (_NEW_LIGHT | _NEW_FOG)
+#define _DD_NEW_TRI_CULL_FRONT_BACK      _NEW_POLYGON
 #define _DD_NEW_TRI_LIGHT_TWOSIDE        _NEW_LIGHT
 #define _DD_NEW_TRI_UNFILLED             _NEW_POLYGON
 #define _DD_NEW_TRI_SMOOTH               _NEW_POLYGON
@@ -1380,32 +1570,29 @@ struct gl_extensions {
 #define _DD_NEW_POINT_SMOOTH             _NEW_POINT
 #define _DD_NEW_POINT_SIZE               _NEW_POINT
 #define _DD_NEW_POINT_ATTEN              _NEW_POINT
-#define _DD_NEW_LIGHTING_CULL            _NEW_LIGHT
-#define _DD_NEW_TRI_CULL_FRONT_BACK      _NEW_POLYGON 
-#define _DD_NEW_Z_NEVER                  _NEW_DEPTH
-#define _DD_NEW_STENCIL                  _NEW_STENCIL
 
+#define _MESA_NEW_NEED_EYE_COORDS         (_NEW_LIGHT |                \
+                                           _NEW_TEXTURE |      \
+                                           _NEW_POINT |                \
+                                           _NEW_MODELVIEW)
 
-#define _MESA_NEW_NEED_EYE_COORDS         (_NEW_LIGHT|         \
-                                            _NEW_TEXTURE|              \
-                                            _NEW_POINT|                \
-                                            _NEW_MODELVIEW)    
+#define _MESA_NEW_NEED_NORMALS            (_NEW_LIGHT |                \
+                                           _NEW_TEXTURE)
 
-#define _MESA_NEW_NEED_NORMALS            (_NEW_LIGHT|         \
-                                            _NEW_TEXTURE)
-#define _IMAGE_NEW_TRANSFER_STATE        (_NEW_PIXEL|_NEW_COLOR_MATRIX)
+#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
 
 
-
 /*
  * Forward declaration of display list datatypes:
  */
@@ -1413,22 +1600,38 @@ union node;
 typedef union node Node;
 
 
-
-
-
 /* This has to be included here. */
 #include "dd.h"
 
 
 /*
- * The library context: 
+ * Core Mesa's support for tnl modules:
+ */
+#define NUM_VERTEX_FORMAT_ENTRIES (sizeof(GLvertexformat) / sizeof(void *))
+
+struct gl_tnl_module {
+   /* Vertex format to be lazily swapped into current dispatch.
+    */
+   GLvertexformat *Current;
+
+   /* Record of functions swapped out.  On restore, only need to swap
+    * these functions back in.
+    */
+   void *Swapped[NUM_VERTEX_FORMAT_ENTRIES][2];
+   GLuint SwapCount;
+};
+
+
+/**
+ * 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;
 
@@ -1436,49 +1639,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 !! */
-  
-   GLboolean ExecPrefersFloat; /* What preference for color conversion? */
+   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 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];
-
-   /* 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? */
@@ -1506,6 +1699,7 @@ struct __GLcontextRec {
    struct gl_light_attrib      Light;
    struct gl_line_attrib       Line;
    struct gl_list_attrib       List;
+   struct gl_multisample_attrib Multisample;
    struct gl_pixel_attrib      Pixel;
    struct gl_point_attrib      Point;
    struct gl_polygon_attrib    Polygon;
@@ -1543,12 +1737,13 @@ struct __GLcontextRec {
    struct gl_color_table PostColorMatrixColorTable;
    struct gl_color_table ProxyPostColorMatrixColorTable;
 
+   struct vertex_program_state VertexProgram;  /* GL_NV_vertex_program */
+
    GLenum ErrorValue;        /* Last error code */
    GLenum RenderMode;        /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */
    GLuint NewState;          /* bitwise-or of _NEW_* flags */
 
    /* Derived */
-   GLuint _Enabled;           /* bitwise-or of ENABLE_* flags */
    GLuint _TriangleCaps;      /* bitwise-or of DD_* flags */
    GLuint _ImageTransferState;/* bitwise-or of IMAGE_*_BIT flags */
    GLfloat _EyeZDir[3];
@@ -1556,34 +1751,43 @@ 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 */
 
-   /* 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;
 
-#ifdef DEBUG
    GLboolean Rendering;
-#endif
 
 #if defined(MESA_TRACE)
    struct _glapi_table *TraceDispatch;
    trace_context_t     *TraceCtx;
+#else
+   void *TraceDispatch;
+   void *TraceCtx;
 #endif
 
+   /* Core tnl module support */
+   struct gl_tnl_module TnlModule;
+
    /* Hooks for module contexts.  These will eventually live
     * in the driver or elsewhere.
     */
@@ -1598,11 +1802,10 @@ struct __GLcontextRec {
 
 /* The string names for GL_POINT, GL_LINE_LOOP, etc */
 extern const char *_mesa_prim_name[GL_POLYGON+4];
-extern GLenum gl_reduce_prim[];
 
 
 #ifdef MESA_DEBUG
-extern int MESA_VERBOSE; 
+extern int MESA_VERBOSE;
 extern int MESA_DEBUG_FLAGS;
 #else
 # define MESA_VERBOSE 0
@@ -1614,21 +1817,21 @@ extern int MESA_DEBUG_FLAGS;
 
 
 enum _verbose {
-   VERBOSE_VARRAY          = 0x1,
-   VERBOSE_TEXTURE         = 0x2,
-   VERBOSE_IMMEDIATE       = 0x4,
-   VERBOSE_PIPELINE        = 0x8,
-   VERBOSE_DRIVER          = 0x10,
-   VERBOSE_STATE           = 0x20,
-   VERBOSE_API             = 0x40,
-   VERBOSE_DISPLAY_LIST    = 0x200,
-   VERBOSE_LIGHTING        = 0x400
-}; 
+   VERBOSE_VARRAY              = 0x0001,
+   VERBOSE_TEXTURE             = 0x0002,
+   VERBOSE_IMMEDIATE           = 0x0004,
+   VERBOSE_PIPELINE            = 0x0008,
+   VERBOSE_DRIVER              = 0x0010,
+   VERBOSE_STATE               = 0x0020,
+   VERBOSE_API                 = 0x0040,
+   VERBOSE_DISPLAY_LIST                = 0x0200,
+   VERBOSE_LIGHTING            = 0x0400
+};
 
 
 enum _debug {
-   DEBUG_ALWAYS_FLUSH          = 0x1
-}; 
+   DEBUG_ALWAYS_FLUSH          = 0x1
+};
 
 
 
@@ -1638,35 +1841,40 @@ enum _debug {
 
 /* Eventually let the driver specify what statechanges require a flush:
  */
-#define FLUSH_VERTICES(ctx, newstate)                  \
-do {                                                   \
-   if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)  \
-      ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES);   \
-   ctx->NewState |= newstate;                          \
+#define FLUSH_VERTICES(ctx, newstate)                                  \
+do {                                                                   \
+   if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)                  \
+      ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES);           \
+   ctx->NewState |= newstate;                                          \
 } while (0)
 
-#define FLUSH_CURRENT(ctx, newstate)                   \
-do {                                                   \
-   if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)   \
-      ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT);    \
-   ctx->NewState |= newstate;                          \
+#define FLUSH_CURRENT(ctx, newstate)                                   \
+do {                                                                   \
+   if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)                   \
+      ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT);            \
+   ctx->NewState |= newstate;                                          \
 } while (0)
 
-#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)      \
-do {                                                           \
-   if (ctx->Driver.CurrentExecPrimitive != GL_POLYGON+1) {     \
-      gl_error( ctx, GL_INVALID_OPERATION, "begin/end" );      \
-      return retval;                                           \
-   }                                                           \
+#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)              \
+do {                                                                   \
+   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {   \
+      _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" );           \
+      return retval;                                                   \
+   }                                                                   \
 } while (0)
 
-#define ASSERT_OUTSIDE_BEGIN_END(ctx) \
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx,)
+#define ASSERT_OUTSIDE_BEGIN_END(ctx)                                  \
+do {                                                                   \
+   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {   \
+      _mesa_error( ctx, GL_INVALID_OPERATION, "begin/end" );           \
+      return;                                                          \
+   }                                                                   \
+} while (0)
 
-#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx)        \
-do {                                           \
-   ASSERT_OUTSIDE_BEGIN_END(ctx);              \
-   FLUSH_VERTICES(ctx, 0);                     \
+#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx)                                \
+do {                                                                   \
+   ASSERT_OUTSIDE_BEGIN_END(ctx);                                      \
+   FLUSH_VERTICES(ctx, 0);                                             \
 } while (0)
 
 #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)    \
@@ -1676,43 +1884,6 @@ do {                                                                     \
 } while (0)
 
 
-#ifdef DEBUG
-
-#define RENDER_START(CTX)                      \
-   do {                                                \
-      assert(!(CTX)->Rendering);               \
-      (CTX)->Rendering = GL_TRUE;              \
-      if ((CTX)->Driver.RenderStart) {         \
-         (*(CTX)->Driver.RenderStart)(CTX);    \
-      }                                                \
-   } while (0)
-
-#define RENDER_FINISH(CTX)                     \
-   do {                                                \
-      assert((CTX)->Rendering);                        \
-      (CTX)->Rendering = GL_FALSE;             \
-      if ((CTX)->Driver.RenderFinish) {                \
-         (*(CTX)->Driver.RenderFinish)(CTX);   \
-      }                                                \
-   } while (0)
-
-#else
-
-#define RENDER_START(CTX)                      \
-   do {                                                \
-      if ((CTX)->Driver.RenderStart) {         \
-         (*(CTX)->Driver.RenderStart)(CTX);    \
-      }                                                \
-   } while (0)
-
-#define RENDER_FINISH(CTX)                     \
-   do {                                                \
-      if ((CTX)->Driver.RenderFinish) {                \
-         (*(CTX)->Driver.RenderFinish)(CTX);   \
-      }                                                \
-   } while (0)
-
-#endif
 
 
 #endif /* TYPES_H */