Be more consistant with paths in #includes. Eventually, eliminate a bunch of -I...
[mesa.git] / src / mesa / main / mtypes.h
index c443411b629135e5ee1144c504ff51e7531c697e..709b88d2ef554beb58cfb46157575816afea9733 100644 (file)
@@ -7,9 +7,9 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  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"),
 
 
 #include "glheader.h"
-#include <GL/internal/glcore.h>        /* GLimports/GLexports/GLcontextModes */
+#include <GL/internal/glcore.h>        /* __GLcontextModes (GLvisual) */
 #include "config.h"            /* Hardwired parameters */
-#include "glapitable.h"
-#include "glthread.h"
+#include "glapi/glapitable.h"
+#include "glapi/glthread.h"
 #include "math/m_matrix.h"     /* GLmatrix */
 #include "bitset.h"
 
 
+/**
+ * Special, internal token
+ */
+#define GL_SHADER_PROGRAM_MESA 0x9999
+
+
 /**
  * Color channel data type.
  */
@@ -142,8 +148,8 @@ enum
    VERT_ATTRIB_COLOR0 = 3,
    VERT_ATTRIB_COLOR1 = 4,
    VERT_ATTRIB_FOG = 5,
-   VERT_ATTRIB_SIX = 6,
-   VERT_ATTRIB_SEVEN = 7,
+   VERT_ATTRIB_COLOR_INDEX = 6,
+   VERT_ATTRIB_EDGEFLAG = 7,
    VERT_ATTRIB_TEX0 = 8,
    VERT_ATTRIB_TEX1 = 9,
    VERT_ATTRIB_TEX2 = 10,
@@ -176,59 +182,43 @@ enum
  * 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_GENERIC0 (1 << VERT_ATTRIB_GENERIC0)
-#define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1)
-#define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2)
-#define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3)
-#define VERT_BIT_GENERIC4 (1 << VERT_ATTRIB_GENERIC4)
-#define VERT_BIT_GENERIC5 (1 << VERT_ATTRIB_GENERIC5)
-#define VERT_BIT_GENERIC6 (1 << VERT_ATTRIB_GENERIC6)
-#define VERT_BIT_GENERIC7 (1 << VERT_ATTRIB_GENERIC7)
-#define VERT_BIT_GENERIC8 (1 << VERT_ATTRIB_GENERIC8)
-#define VERT_BIT_GENERIC9 (1 << VERT_ATTRIB_GENERIC9)
-#define VERT_BIT_GENERIC10 (1 << VERT_ATTRIB_GENERIC10)
-#define VERT_BIT_GENERIC11 (1 << VERT_ATTRIB_GENERIC11)
-#define VERT_BIT_GENERIC12 (1 << VERT_ATTRIB_GENERIC12)
-#define VERT_BIT_GENERIC13 (1 << VERT_ATTRIB_GENERIC13)
-#define VERT_BIT_GENERIC14 (1 << VERT_ATTRIB_GENERIC14)
-#define VERT_BIT_GENERIC15 (1 << VERT_ATTRIB_GENERIC15)
+#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_COLOR_INDEX (1 << VERT_ATTRIB_COLOR_INDEX)
+#define VERT_BIT_EDGEFLAG    (1 << VERT_ATTRIB_EDGEFLAG)
+#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_GENERIC0    (1 << VERT_ATTRIB_GENERIC0)
+#define VERT_BIT_GENERIC1    (1 << VERT_ATTRIB_GENERIC1)
+#define VERT_BIT_GENERIC2    (1 << VERT_ATTRIB_GENERIC2)
+#define VERT_BIT_GENERIC3    (1 << VERT_ATTRIB_GENERIC3)
+#define VERT_BIT_GENERIC4    (1 << VERT_ATTRIB_GENERIC4)
+#define VERT_BIT_GENERIC5    (1 << VERT_ATTRIB_GENERIC5)
+#define VERT_BIT_GENERIC6    (1 << VERT_ATTRIB_GENERIC6)
+#define VERT_BIT_GENERIC7    (1 << VERT_ATTRIB_GENERIC7)
+#define VERT_BIT_GENERIC8    (1 << VERT_ATTRIB_GENERIC8)
+#define VERT_BIT_GENERIC9    (1 << VERT_ATTRIB_GENERIC9)
+#define VERT_BIT_GENERIC10   (1 << VERT_ATTRIB_GENERIC10)
+#define VERT_BIT_GENERIC11   (1 << VERT_ATTRIB_GENERIC11)
+#define VERT_BIT_GENERIC12   (1 << VERT_ATTRIB_GENERIC12)
+#define VERT_BIT_GENERIC13   (1 << VERT_ATTRIB_GENERIC13)
+#define VERT_BIT_GENERIC14   (1 << VERT_ATTRIB_GENERIC14)
+#define VERT_BIT_GENERIC15   (1 << VERT_ATTRIB_GENERIC15)
 
 #define VERT_BIT_TEX(u)  (1 << (VERT_ATTRIB_TEX0 + (u)))
 #define VERT_BIT_GENERIC(g)  (1 << (VERT_ATTRIB_GENERIC0 + (g)))
 /*@}*/
 
-/**
- * GLSL allows shader writers to allocate vertex result attributes (varyings) in
- * single float component granularity. This is in contrast to vertex / fragment
- * programs, where result attributes (actually texcoords) were allocated
- * in 4-component vectors of floats granularity.
- * For performance reasons, it would be optimal to stick with this scheme on a scalar
- * processor. Varyings will likely be allocated as 3-component vectors, so statistically
- * we win 2 floats.
- * The constant VARYINGS_PER_VECTOR tells us how much of float components we pack into
- * one result vector. For scalar processor it would be 1, for vector processor - 4.
- * 
- * NOTE: Currently we pack varyings into vertex attributes.
- */
-#define VARYINGS_PER_VECTOR 2
-#define VARYING_EMIT_STYLE  EMIT_2F
-#define MAX_VARYING_VECTORS ((MAX_VARYING_FLOATS + VARYINGS_PER_VECTOR - 1) / VARYINGS_PER_VECTOR)
 
 /**
  * Indexes for vertex program result attributes
@@ -249,7 +239,9 @@ enum
 #define VERT_RESULT_PSIZ 12
 #define VERT_RESULT_BFC0 13
 #define VERT_RESULT_BFC1 14
-#define VERT_RESULT_MAX  15
+#define VERT_RESULT_EDGE 15
+#define VERT_RESULT_VAR0 16  /**< shader varying */
+#define VERT_RESULT_MAX  (VERT_RESULT_VAR0 + MAX_VARYING)
 /*@}*/
 
 
@@ -270,7 +262,8 @@ enum
    FRAG_ATTRIB_TEX5 = 9,
    FRAG_ATTRIB_TEX6 = 10,
    FRAG_ATTRIB_TEX7 = 11,
-   FRAG_ATTRIB_MAX = 12
+   FRAG_ATTRIB_VAR0 = 12,  /**< shader varying */
+   FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
 };
 
 /**
@@ -289,6 +282,10 @@ enum
 #define FRAG_BIT_TEX5  (1 << FRAG_ATTRIB_TEX5)
 #define FRAG_BIT_TEX6  (1 << FRAG_ATTRIB_TEX6)
 #define FRAG_BIT_TEX7  (1 << FRAG_ATTRIB_TEX7)
+#define FRAG_BIT_VAR0  (1 << FRAG_ATTRIB_VAR0)
+
+#define FRAG_BIT_TEX(U)  (FRAG_BIT_TEX0 << (U))
+#define FRAG_BIT_VAR(V)  (FRAG_BIT_VAR0 << (V))
 
 #define FRAG_BITS_TEX_ANY (FRAG_BIT_TEX0|      \
                           FRAG_BIT_TEX1|       \
@@ -304,12 +301,14 @@ enum
 /**
  * Fragment program results
  */
-/*@{*/
-#define FRAG_RESULT_COLR  0
-#define FRAG_RESULT_COLH  1
-#define FRAG_RESULT_DEPR  2
-#define FRAG_RESULT_MAX   3
-/*@}*/
+enum
+{
+   FRAG_RESULT_COLR = 0,
+   FRAG_RESULT_COLH = 1,
+   FRAG_RESULT_DEPR = 2,
+   FRAG_RESULT_DATA0 = 3,
+   FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
+};
 
 
 /**
@@ -382,6 +381,13 @@ enum {
                             BUFFER_BIT_COLOR7)
 
 
+/** The pixel transfer path has three color tables: */
+/*@{*/
+#define COLORTABLE_PRECONVOLUTION  0
+#define COLORTABLE_POSTCONVOLUTION 1
+#define COLORTABLE_POSTCOLORMATRIX 2
+#define COLORTABLE_MAX 3
+/*@}*/
 
 
 /**
@@ -391,9 +397,9 @@ struct gl_color_table
 {
    GLenum InternalFormat;      /**< The user-specified format */
    GLenum _BaseFormat;         /**< GL_ALPHA, GL_RGBA, GL_RGB, etc */
-   GLuint Size;           /**< number of entries (rows) in table */
-   GLvoid *Table;         /**< points to data of <Type> */
-   GLenum Type;           /**< GL_UNSIGNED_BYTE or GL_FLOAT */
+   GLuint Size;                /**< number of entries in table */
+   GLfloat *TableF;            /**< Color table, floating point values */
+   GLubyte *TableUB;           /**< Color table, ubyte values */
    GLubyte RedSize;
    GLubyte GreenSize;
    GLubyte BlueSize;
@@ -613,29 +619,27 @@ struct gl_colorbuffer_attrib
 struct gl_current_attrib
 {
    /**
-    * \name Values valid only when FLUSH_VERTICES has been called.
+    * \name Current vertex attributes.
+    * \note Values are valid only after FLUSH_VERTICES has been called.
+    * \note Index and Edgeflag current values are stored as floats in the 
+    * SIX and SEVEN attribute slots.
     */
    /*@{*/
-   GLfloat Attrib[VERT_ATTRIB_MAX][4];         /**< Current vertex attributes
-                                                 *  indexed by VERT_ATTRIB_* */
-   GLfloat Index;                              /**< Current color index */
-   GLboolean EdgeFlag;                         /**< Current edge flag */
+   GLfloat Attrib[VERT_ATTRIB_MAX][4]; /**< Position, color, texcoords, etc */
    /*@}*/
 
    /**
-    * \name Values are always valid.  
-    * 
-    * \note BTW, note how similar this set of attributes is to the SWvertex
-    * data type in the software rasterizer...
+    * \name Current raster position attributes (always valid).
+    * \note This set of attributes is very similar to the SWvertex struct.
     */
    /*@{*/
-   GLfloat RasterPos[4];                       /**< Current raster position */
-   GLfloat RasterDistance;                     /**< Current raster distance */
-   GLfloat RasterColor[4];                     /**< Current raster color */
-   GLfloat RasterSecondaryColor[4];             /**< Current raster secondary color */
-   GLfloat RasterIndex;                                /**< Current raster index */
-   GLfloat RasterTexCoords[MAX_TEXTURE_UNITS][4];/**< Current raster texcoords */
-   GLboolean RasterPosValid;                   /**< Raster pos valid flag */
+   GLfloat RasterPos[4];
+   GLfloat RasterDistance;
+   GLfloat RasterColor[4];
+   GLfloat RasterSecondaryColor[4];
+   GLfloat RasterIndex;
+   GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
+   GLboolean RasterPosValid;
    /*@}*/
 };
 
@@ -664,9 +668,7 @@ struct gl_enable_attrib
    GLboolean Blend;
    GLbitfield ClipPlanes;
    GLboolean ColorMaterial;
-   GLboolean ColorTable;                /* SGI_color_table */
-   GLboolean PostColorMatrixColorTable; /* SGI_color_table */
-   GLboolean PostConvolutionColorTable; /* SGI_color_table */
+   GLboolean ColorTable[COLORTABLE_MAX];
    GLboolean Convolution1D;
    GLboolean Convolution2D;
    GLboolean Separable2D;
@@ -889,6 +891,7 @@ struct gl_light_attrib
    GLenum ColorMaterialMode;           /**< GL_AMBIENT, GL_DIFFUSE, etc */
    GLbitfield ColorMaterialBitmask;    /**< bitmask formed from Face and Mode */
    GLboolean ColorMaterialEnabled;
+   GLenum ClampVertexColor;
 
    struct gl_light EnabledList;         /**< List sentinel */
 
@@ -964,75 +967,92 @@ struct gl_multisample_attrib
 };
 
 
+/**
+ * A pixelmap (see glPixelMap)
+ */
+struct gl_pixelmap
+{
+   GLint Size;
+   GLfloat Map[MAX_PIXEL_MAP_TABLE];
+   GLubyte Map8[MAX_PIXEL_MAP_TABLE];  /**< converted to 8-bit color */
+};
+
+
+/**
+ * Collection of all pixelmaps
+ */
+struct gl_pixelmaps
+{
+   struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
+   struct gl_pixelmap GtoG;
+   struct gl_pixelmap BtoB;
+   struct gl_pixelmap AtoA;
+   struct gl_pixelmap ItoR;
+   struct gl_pixelmap ItoG;
+   struct gl_pixelmap ItoB;
+   struct gl_pixelmap ItoA;
+   struct gl_pixelmap ItoI;
+   struct gl_pixelmap StoS;
+};
+
+
 /**
  * Pixel attribute group (GL_PIXEL_MODE_BIT).
  */
 struct gl_pixel_attrib
 {
    GLenum ReadBuffer;          /**< source buffer for glRead/CopyPixels() */
+
+   /*--- Begin Pixel Transfer State ---*/
+   /* Fields are in the order in which they're applied... */
+
+   /* Scale & Bias (index shift, offset) */
    GLfloat RedBias, RedScale;
    GLfloat GreenBias, GreenScale;
    GLfloat BlueBias, BlueScale;
    GLfloat AlphaBias, AlphaScale;
    GLfloat DepthBias, DepthScale;
    GLint IndexShift, IndexOffset;
+
+   /* Pixel Maps */
+   /* Note: actual pixel maps are not part of this attrib group */
    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;
-   GLint MapItoGsize;
-   GLint MapItoBsize;
-   GLint MapItoAsize;
-   GLint MapRtoRsize;
-   GLint MapGtoGsize;
-   GLint MapBtoBsize;
-   GLint MapAtoAsize;
-   GLint MapStoS[MAX_PIXEL_MAP_TABLE]; /**< Pixel map tables */
-   GLfloat MapItoI[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapItoR[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapItoG[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapItoB[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapItoA[MAX_PIXEL_MAP_TABLE];
-   GLubyte MapItoR8[MAX_PIXEL_MAP_TABLE];  /**< converted to 8-bit color */
-   GLubyte MapItoG8[MAX_PIXEL_MAP_TABLE];
-   GLubyte MapItoB8[MAX_PIXEL_MAP_TABLE];
-   GLubyte MapItoA8[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapRtoR[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapGtoG[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapBtoB[MAX_PIXEL_MAP_TABLE];
-   GLfloat MapAtoA[MAX_PIXEL_MAP_TABLE];
-   /** GL_EXT_histogram */
-   GLboolean HistogramEnabled;
-   GLboolean MinMaxEnabled;
-   /** GL_SGI_color_matrix */
-   GLfloat PostColorMatrixScale[4];  /**< RGBA */
-   GLfloat PostColorMatrixBias[4];   /**< RGBA */
-   /** GL_SGI_color_table */
-   GLfloat ColorTableScale[4];
-   GLfloat ColorTableBias[4];
-   GLboolean ColorTableEnabled;
-   GLfloat PCCTscale[4];
-   GLfloat PCCTbias[4];
-   GLboolean PostConvolutionColorTableEnabled;
-   GLfloat PCMCTscale[4];
-   GLfloat PCMCTbias[4];
-   GLboolean PostColorMatrixColorTableEnabled;
-   /** GL_SGI_texture_color_table */
-   GLfloat TextureColorTableScale[4];
-   GLfloat TextureColorTableBias[4];
-   /** Convolution */
+
+   /* There are multiple color table stages: */
+   GLboolean ColorTableEnabled[COLORTABLE_MAX];
+   GLfloat ColorTableScale[COLORTABLE_MAX][4];  /**< RGBA */
+   GLfloat ColorTableBias[COLORTABLE_MAX][4];   /**< RGBA */
+
+   /* Convolution (GL_EXT_convolution) */
    GLboolean Convolution1DEnabled;
    GLboolean Convolution2DEnabled;
    GLboolean Separable2DEnabled;
    GLfloat ConvolutionBorderColor[3][4];
    GLenum ConvolutionBorderMode[3];
-   GLfloat ConvolutionFilterScale[3][4];
-   GLfloat ConvolutionFilterBias[3][4];
+   GLfloat ConvolutionFilterScale[3][4];  /**< RGBA */
+   GLfloat ConvolutionFilterBias[3][4];   /**< RGBA */
    GLfloat PostConvolutionScale[4];  /**< RGBA */
    GLfloat PostConvolutionBias[4];   /**< RGBA */
+
+   /* Color matrix (GL_SGI_color_matrix) */
+   /* Note: the color matrix is not part of this attrib group */
+   GLfloat PostColorMatrixScale[4];  /**< RGBA */
+   GLfloat PostColorMatrixBias[4];   /**< RGBA */
+
+   /* Histogram & minmax (GL_EXT_histogram) */
+   /* Note: histogram and minmax data are not part of this attrib group */
+   GLboolean HistogramEnabled;
+   GLboolean MinMaxEnabled;
+
+   /*--- End Pixel Transfer State ---*/
+
+   /* Pixel Zoom */
+   GLfloat ZoomX, ZoomY;
+
+   /** GL_SGI_texture_color_table */
+   GLfloat TextureColorTableScale[4];
+   GLfloat TextureColorTableBias[4];
 };
 
 
@@ -1048,8 +1068,8 @@ struct gl_point_attrib
    GLfloat MinSize, MaxSize;   /**< GL_EXT_point_parameters */
    GLfloat Threshold;          /**< GL_EXT_point_parameters */
    GLboolean _Attenuated;      /**< True if Params != [1, 0, 0] */
-   GLboolean PointSprite;      /**< GL_NV_point_sprite / GL_NV_point_sprite */
-   GLboolean CoordReplace[MAX_TEXTURE_UNITS]; /**< GL_NV/ARB_point_sprite */
+   GLboolean PointSprite;      /**< GL_NV/ARB_point_sprite */
+   GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite */
    GLenum SpriteRMode;         /**< GL_NV_point_sprite (only!) */
    GLenum SpriteOrigin;                /**< GL_ARB_point_sprite */
 };
@@ -1107,7 +1127,7 @@ struct gl_stencil_attrib
 };
 
 
-#define NUM_TEXTURE_TARGETS 5   /* 1D, 2D, 3D, CUBE and RECT */
+#define NUM_TEXTURE_TARGETS 7   /* 1D, 2D, 3D, CUBE, RECT, 1D_STACK, and 2D_STACK */
 
 /**
  * An index for each type of texture object
@@ -1118,6 +1138,8 @@ struct gl_stencil_attrib
 #define TEXTURE_3D_INDEX    2
 #define TEXTURE_CUBE_INDEX  3
 #define TEXTURE_RECT_INDEX  4
+#define TEXTURE_1D_ARRAY_INDEX    5
+#define TEXTURE_2D_ARRAY_INDEX    6
 /*@}*/
 
 /**
@@ -1130,6 +1152,8 @@ struct gl_stencil_attrib
 #define TEXTURE_3D_BIT   (1 << TEXTURE_3D_INDEX)
 #define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX)
 #define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX)
+#define TEXTURE_1D_ARRAY_BIT   (1 << TEXTURE_1D_ARRAY_INDEX)
+#define TEXTURE_2D_ARRAY_BIT   (1 << TEXTURE_2D_ARRAY_INDEX)
 /*@}*/
 
 
@@ -1217,24 +1241,42 @@ typedef void (*StoreTexelFunc)(struct gl_texture_image *texImage,
                                GLint col, GLint row, GLint img,
                                const void *texel);
 
+
 /**
- * TexImage store function.  This is called by the glTex[Sub]Image
- * functions and is responsible for converting the user-specified texture
- * image into a specific (hardware) image format.
+ * This macro defines the (many) parameters to the texstore functions.
+ * \param dims  either 1 or 2 or 3
+ * \param baseInternalFormat  user-specified base internal format
+ * \param dstFormat  destination Mesa texture format
+ * \param dstAddr  destination image address
+ * \param dstX/Y/Zoffset  destination x/y/z offset (ala TexSubImage), in texels
+ * \param dstRowStride  destination image row stride, in bytes
+ * \param dstImageOffsets  offset of each 2D slice within 3D texture, in texels
+ * \param srcWidth/Height/Depth  source image size, in pixels
+ * \param srcFormat  incoming image format
+ * \param srcType  incoming image data type
+ * \param srcAddr  source image address
+ * \param srcPacking  source image packing parameters
  */
-typedef GLboolean (*StoreTexImageFunc)(GLcontext *ctx, GLuint dims,
-                          GLenum baseInternalFormat,
-                          const struct gl_texture_format *dstFormat,
-                          GLvoid *dstAddr,
-                          GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
-                          GLint dstRowStride, GLint dstImageStride,
-                          GLint srcWidth, GLint srcHeight, GLint srcDepth,
-                          GLenum srcFormat, GLenum srcType,
-                          const GLvoid *srcAddr,
-                          const struct gl_pixelstore_attrib *srcPacking);
+#define TEXSTORE_PARAMS \
+       GLcontext *ctx, GLuint dims, \
+       GLenum baseInternalFormat, \
+       const struct gl_texture_format *dstFormat, \
+       GLvoid *dstAddr, \
+       GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
+       GLint dstRowStride, const GLuint *dstImageOffsets, \
+       GLint srcWidth, GLint srcHeight, GLint srcDepth, \
+       GLenum srcFormat, GLenum srcType, \
+       const GLvoid *srcAddr, \
+       const struct gl_pixelstore_attrib *srcPacking
 
 
 
+/**
+ * Texture image storage function.
+ */
+typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
+
+
 /**
  * Texture format record 
  */
@@ -1248,15 +1290,22 @@ struct gl_texture_format
                                 *   GL_DEPTH_COMPONENT.
                                 */
    GLenum DataType;            /**< GL_FLOAT or GL_UNSIGNED_NORMALIZED_ARB */
-   GLubyte RedBits;            /**< Bits per texel component */
-   GLubyte GreenBits;          /**< These are just rough approximations for */
-   GLubyte BlueBits;           /**< compressed texture formats. */
+
+   /**
+    * Bits per texel component.  These are just rough approximations
+    * for compressed texture formats.
+    */
+   /*@{*/
+   GLubyte RedBits;
+   GLubyte GreenBits;
+   GLubyte BlueBits;
    GLubyte AlphaBits;
    GLubyte LuminanceBits;
    GLubyte IntensityBits;
    GLubyte IndexBits;
    GLubyte DepthBits;
    GLubyte StencilBits;        /**< GL_EXT_packed_depth_stencil */
+   /*@}*/
 
    GLuint TexelBytes;          /**< Bytes per texel, 0 if compressed format */
 
@@ -1278,6 +1327,8 @@ struct gl_texture_format
 };
 
 
+#define MAX_3D_TEXTURE_SIZE (1 << (MAX_3D_TEXTURE_LEVELS - 1))
+
 /**
  * Texture image state.  Describes the dimensions of a texture image,
  * the texel format and pointers to Texel Fetch functions.
@@ -1295,8 +1346,6 @@ struct gl_texture_image
    GLuint Width;               /**< = 2^WidthLog2 + 2*Border */
    GLuint Height;              /**< = 2^HeightLog2 + 2*Border */
    GLuint Depth;               /**< = 2^DepthLog2 + 2*Border */
-   GLuint RowStride;           /**< == Width unless IsClientData and padded */
-   GLuint ImageStride;          /**< Stride between images, in texels */
    GLuint Width2;              /**< = Width - 2*Border */
    GLuint Height2;             /**< = Height - 2*Border */
    GLuint Depth2;              /**< = Depth - 2*Border */
@@ -1307,7 +1356,6 @@ struct gl_texture_image
    GLfloat WidthScale;         /**< used for mipmap LOD computation */
    GLfloat HeightScale;                /**< used for mipmap LOD computation */
    GLfloat DepthScale;         /**< used for mipmap LOD computation */
-   GLvoid *Data;               /**< Image data, accessed via FetchTexel() */
    GLboolean IsClientData;     /**< Data owned by client? */
    GLboolean _IsPowerOfTwo;    /**< Are all dimensions powers of two? */
 
@@ -1321,6 +1369,11 @@ struct gl_texture_image
    GLboolean IsCompressed;     /**< GL_ARB_texture_compression */
    GLuint CompressedSize;      /**< GL_ARB_texture_compression */
 
+   GLuint RowStride;           /**< == Width unless IsClientData and padded */
+   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
+                                     each 2D slice in 'Data', in texels */
+   GLvoid *Data;               /**< Image data, accessed via FetchTexel() */
+
    /**
     * \name For device driver:
     */
@@ -1351,7 +1404,6 @@ struct gl_texture_image
  */
 struct gl_texture_object
 {
-   _glthread_Mutex Mutex;      /**< for thread safety */
    GLint RefCount;             /**< reference count */
    GLuint Name;                        /**< the user-visible texture object ID */
    GLenum Target;               /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
@@ -1374,11 +1426,15 @@ struct gl_texture_object
    GLfloat ShadowAmbient;       /**< GL_ARB_shadow_ambient */
    GLenum CompareMode;         /**< GL_ARB_shadow */
    GLenum CompareFunc;         /**< GL_ARB_shadow */
+   GLenum _Function;           /**< Comparison function derived from 
+                                * \c CompareOperator, \c CompareMode, and
+                                * \c CompareFunc.
+                                */
    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 */
-   GLboolean Complete;         /**< Is texture object complete? */
+   GLboolean _Complete;                /**< Is texture object complete? */
 
    /** Actual texture images, indexed by [cube face] and [mipmap level] */
    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
@@ -1445,7 +1501,7 @@ struct gl_texture_unit
    GLbitfield _GenBitT;
    GLbitfield _GenBitR;
    GLbitfield _GenBitQ;
-   GLbitfield _GenFlags;       /**< bitwise or of GenBit[STRQ] */
+   GLbitfield _GenFlags;       /**< bitwise or of _GenBit[STRQ] */
    GLfloat ObjectPlaneS[4];
    GLfloat ObjectPlaneT[4];
    GLfloat ObjectPlaneR[4];
@@ -1478,26 +1534,41 @@ struct gl_texture_unit
    struct gl_texture_object *Current3D;
    struct gl_texture_object *CurrentCubeMap; /**< GL_ARB_texture_cube_map */
    struct gl_texture_object *CurrentRect;    /**< GL_NV_texture_rectangle */
+   struct gl_texture_object *Current1DArray; /**< GL_MESA_texture_array */
+   struct gl_texture_object *Current2DArray; /**< GL_MESA_texture_array */
 
    struct gl_texture_object *_Current; /**< Points to really enabled tex obj */
 
-   struct gl_texture_object Saved1D;  /**< only used by glPush/PopAttrib */
+   /** These are used for glPush/PopAttrib */
+   /*@{*/
+   struct gl_texture_object Saved1D;
    struct gl_texture_object Saved2D;
    struct gl_texture_object Saved3D;
    struct gl_texture_object SavedCubeMap;
    struct gl_texture_object SavedRect;
+   struct gl_texture_object Saved1DArray;
+   struct gl_texture_object Saved2DArray;
+   /*@}*/
 
-   /* GL_SGI_texture_color_table */
+   /** GL_SGI_texture_color_table */
+   /*@{*/
    struct gl_color_table ColorTable;
    struct gl_color_table ProxyColorTable;
    GLboolean ColorTableEnabled;
+   /*@}*/
 };
 
-struct texenvprog_cache {
+struct texenvprog_cache_item {
    GLuint hash;
    void *key;
-   void *data;
-   struct texenvprog_cache *next;
+   struct gl_fragment_program *data;
+   struct texenvprog_cache_item *next;
+};
+
+struct texenvprog_cache {
+   struct texenvprog_cache_item **items;
+   GLuint size, n_items;
+   GLcontext *ctx;
 };
 
 /**
@@ -1524,13 +1595,15 @@ struct gl_texture_attrib
    struct gl_texture_object *Proxy3D;
    struct gl_texture_object *ProxyCubeMap;
    struct gl_texture_object *ProxyRect;
+   struct gl_texture_object *Proxy1DArray;
+   struct gl_texture_object *Proxy2DArray;
 
    /** GL_EXT_shared_texture_palette */
    GLboolean SharedPalette;
    struct gl_color_table Palette;
    
    /** Cached texenv fragment programs */
-   struct texenvprog_cache *env_fp_cache;
+   struct texenvprog_cache env_fp_cache;
 };
 
 
@@ -1612,8 +1685,6 @@ struct gl_pixelstore_attrib
 };
 
 
-#define CA_CLIENT_DATA     0x1 /**< Data not allocated by mesa */
-
 
 /**
  * Client vertex array attributes
@@ -1625,39 +1696,57 @@ struct gl_client_array
    GLsizei Stride;             /**< user-specified stride */
    GLsizei StrideB;            /**< actual stride in bytes */
    const GLubyte *Ptr;          /**< Points to array data */
-   GLbitfield Enabled;         /**< one of the _NEW_ARRAY_ bits */
+   GLboolean Enabled;          /**< Enabled flag is a boolean */
    GLboolean Normalized;        /**< GL_ARB_vertex_program */
 
    /**< GL_ARB_vertex_buffer_object */
    struct gl_buffer_object *BufferObj;
    GLuint _MaxElement;
-
-   GLbitfield Flags;
 };
 
 
 /**
- * Vertex array state
+ * Collection of vertex arrays.  Defined by the GL_APPLE_vertex_array_object
+ * extension, but a nice encapsulation in any case.
  */
-struct gl_array_attrib
+struct gl_array_object
 {
-   struct gl_client_array Vertex;           /**< client data descriptors */
+   /** Name of the array object as received from glGenVertexArrayAPPLE. */
+   GLuint Name;
+
+   /** Conventional vertex arrays */
+   /*@{*/
+   struct gl_client_array Vertex;
    struct gl_client_array Normal;
    struct gl_client_array Color;
    struct gl_client_array SecondaryColor;
    struct gl_client_array FogCoord;
    struct gl_client_array Index;
-   struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
    struct gl_client_array EdgeFlag;
+   struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
+   /*@}*/
+
+   /** Generic arrays for vertex programs/shaders */
+   struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];
+
+   /** Mask of _NEW_ARRAY_* values indicating which arrays are enabled */
+   GLbitfield _Enabled;
+};
+
 
-   struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];  /**< GL_NV_vertex_program */
+/**
+ * Vertex array state
+ */
+struct gl_array_attrib
+{
+   struct gl_array_object *ArrayObj;
+   struct gl_array_object *DefaultArrayObj;
 
    GLint ActiveTexture;                /**< Client Active Texture */
    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
 
-   GLbitfield _Enabled;                /**< _NEW_ARRAY_* - bit set if array enabled */
-   GLbitfield NewState;                /**< _NEW_ARRAY_* */
+   GLbitfield NewState;                /**< mask of _NEW_ARRAY_* values */
 
 #if FEATURE_ARB_vertex_buffer_object
    struct gl_buffer_object *NullBufferObj;
@@ -1761,66 +1850,71 @@ struct gl_evaluators
 };
 
 
-/**
- * State used during execution of fragment programs.
- */
-struct fp_machine
-{
-   GLfloat Temporaries[MAX_NV_FRAGMENT_PROGRAM_TEMPS][4];
-   GLfloat Inputs[MAX_NV_FRAGMENT_PROGRAM_INPUTS][4];
-   GLfloat Outputs[MAX_NV_FRAGMENT_PROGRAM_OUTPUTS][4];
-   GLuint CondCodes[4];
-};
-
-
 /**
  * Names of the various vertex/fragment program register files, etc.
+ *
  * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
  * All values should fit in a 4-bit field.
+ *
+ * NOTE: PROGRAM_ENV_PARAM, PROGRAM_STATE_VAR, PROGRAM_NAMED_PARAM,
+ * PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be considered to
+ * be "uniform" variables since they can only be set outside glBegin/End.
+ * They're also all stored in the same Parameters array.
  */
 enum register_file
 {
-   PROGRAM_TEMPORARY = 0,
-   PROGRAM_LOCAL_PARAM = 1,
-   PROGRAM_ENV_PARAM = 2,
-   PROGRAM_STATE_VAR = 3,
-   PROGRAM_INPUT = 4,
-   PROGRAM_OUTPUT = 5,
-   PROGRAM_NAMED_PARAM = 6,
-   PROGRAM_CONSTANT = 7,
-   PROGRAM_WRITE_ONLY = 8,
-   PROGRAM_ADDRESS = 9,
-   PROGRAM_UNDEFINED = 15  /* invalid value */
+   PROGRAM_TEMPORARY = 0,   /**< machine->Temporary[] */
+   PROGRAM_LOCAL_PARAM = 1, /**< gl_program->LocalParams[] */
+   PROGRAM_ENV_PARAM = 2,   /**< gl_program->Parameters[] */
+   PROGRAM_STATE_VAR = 3,   /**< gl_program->Parameters[] */
+   PROGRAM_INPUT = 4,       /**< machine->Inputs[] */
+   PROGRAM_OUTPUT = 5,      /**< machine->Outputs[] */
+   PROGRAM_NAMED_PARAM = 6, /**< gl_program->Parameters[] */
+   PROGRAM_CONSTANT = 7,    /**< gl_program->Parameters[] */
+   PROGRAM_UNIFORM = 8,     /**< gl_program->Parameters[] */
+   PROGRAM_VARYING = 9,     /**< machine->Inputs[]/Outputs[] */
+   PROGRAM_WRITE_ONLY = 10, /**< A dummy, write-only register */
+   PROGRAM_ADDRESS = 11,    /**< machine->AddressReg */
+   PROGRAM_SAMPLER = 12,    /**< for shader samplers, compile-time only */
+   PROGRAM_UNDEFINED = 13,  /**< Invalid value */
+   PROGRAM_FILE_MAX
 };
 
 
 /** Vertex and fragment instructions */
 struct prog_instruction;
-struct program_parameter_list;
+struct gl_program_parameter_list;
 
 
 /**
  * Base class for any kind of program object
  */
-struct program
+struct gl_program
 {
    GLuint Id;
-   GLubyte *String;          /**< Null-terminated program text */
+   GLubyte *String;  /**< Null-terminated program text */
    GLint RefCount;
-   GLenum Target;
-   GLenum Format;            /**< String encoding format */
+   GLenum Target;    /**< GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_FRAGMENT_PROGRAM_NV */
+   GLenum Format;    /**< String encoding format */
    GLboolean Resident;
 
    struct prog_instruction *Instructions;
 
-   GLbitfield InputsRead;     /* Bitmask of which input regs are read */
-   GLbitfield OutputsWritten; /* Bitmask of which output regs are written to */
+   GLbitfield InputsRead;     /**< Bitmask of which input regs are read */
+   GLbitfield OutputsWritten; /**< Bitmask of which output regs are written to */
+   GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
+   GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
 
    /** Named parameters, constants, etc. from program text */
-   struct program_parameter_list *Parameters;
+   struct gl_program_parameter_list *Parameters;
    /** Numbered local parameters */
    GLfloat LocalParams[MAX_PROGRAM_LOCAL_PARAMS][4];
 
+   /** Vertex/fragment shader varying vars */
+   struct gl_program_parameter_list *Varying;
+   /** Vertex program user-defined attributes */
+   struct gl_program_parameter_list *Attributes;
+
    /** Logical counts */
    /*@{*/
    GLuint NumInstructions;
@@ -1828,6 +1922,9 @@ struct program
    GLuint NumParameters;
    GLuint NumAttributes;
    GLuint NumAddressRegs;
+   GLuint NumAluInstructions;
+   GLuint NumTexInstructions;
+   GLuint NumTexIndirections;
    /*@}*/
    /** Native, actual h/w counts */
    /*@{*/
@@ -1836,31 +1933,27 @@ struct program
    GLuint NumNativeParameters;
    GLuint NumNativeAttributes;
    GLuint NumNativeAddressRegs;
+   GLuint NumNativeAluInstructions;
+   GLuint NumNativeTexInstructions;
+   GLuint NumNativeTexIndirections;
    /*@}*/
 };
 
 
 /** Vertex program object */
-struct vertex_program
+struct gl_vertex_program
 {
-   struct program Base;   /* base class */
-   GLboolean IsNVProgram; /* GL_NV_vertex_program ? */
-   GLboolean IsPositionInvariant;  /* GL_ARB_vertex_program / GL_NV_vertex_program1_1 */
-   void *TnlData;              /* should probably use Base.DriverData */
+   struct gl_program Base;   /**< base class */
+   GLboolean IsNVProgram;    /**< is this a GL_NV_vertex_program program? */
+   GLboolean IsPositionInvariant;
+   void *TnlData;              /**< should probably use Base.DriverData */
 };
 
 
 /** Fragment program object */
-struct fragment_program
+struct gl_fragment_program
 {
-   struct program Base;   /**< base class */
-   GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
-   GLuint NumAluInstructions; /**< GL_ARB_fragment_program */
-   GLuint NumTexInstructions;
-   GLuint NumTexIndirections;
-   GLuint NumNativeAluInstructions; /**< GL_ARB_fragment_program */
-   GLuint NumNativeTexInstructions;
-   GLuint NumNativeTexIndirections;
+   struct gl_program Base;   /**< base class */
    GLenum FogOption;
    GLboolean UsesKill;
 };
@@ -1877,29 +1970,32 @@ struct gl_program_state
 
 
 /**
- * State vars for GL_ARB/GL_NV_vertex_program
+ * Context state for vertex programs.
  */
 struct gl_vertex_program_state
 {
-   GLboolean Enabled;                  /**< GL_VERTEX_PROGRAM_ARB/NV */
-   GLboolean _Enabled;                 /**< Enabled and valid program? */
-   GLboolean PointSizeEnabled;         /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
-   GLboolean TwoSideEnabled;           /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
-   struct vertex_program *Current;     /**< ptr to currently bound program */
-   struct vertex_program *_Current;    /**< ptr to currently bound
-                                          program, including internal
-                                          (t_vp_build.c) programs */
-
-   GLenum TrackMatrix[MAX_NV_VERTEX_PROGRAM_PARAMS / 4];
-   GLenum TrackMatrixTransform[MAX_NV_VERTEX_PROGRAM_PARAMS / 4];
-
-   GLfloat Parameters[MAX_NV_VERTEX_PROGRAM_PARAMS][4]; /* Env params */
-   /* Only used during program execution (may be moved someday): */
-   GLfloat Temporaries[MAX_NV_VERTEX_PROGRAM_TEMPS][4];
-   GLfloat Inputs[MAX_NV_VERTEX_PROGRAM_INPUTS][4];
-   GLuint InputsSize[MAX_NV_VERTEX_PROGRAM_INPUTS];
-   GLfloat Outputs[MAX_NV_VERTEX_PROGRAM_OUTPUTS][4];
-   GLint AddressReg[4];
+   GLboolean Enabled;               /**< GL_VERTEX_PROGRAM_ARB/NV */
+   GLboolean _Enabled;              /**< Enabled and valid program? */
+   GLboolean PointSizeEnabled;      /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
+   GLboolean TwoSideEnabled;        /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
+   struct gl_vertex_program *Current;  /**< user-bound vertex program */
+
+   /** Currently enabled and valid program (including internal programs
+    * and compiled shader programs).
+    */
+   struct gl_vertex_program *_Current;
+
+   GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
+
+   /* For GL_NV_vertex_program only: */
+   GLenum TrackMatrix[MAX_PROGRAM_ENV_PARAMS / 4];
+   GLenum TrackMatrixTransform[MAX_PROGRAM_ENV_PARAMS / 4];
+
+   /** Should fixed-function T&L be implemented with a vertex prog? */
+   GLboolean _MaintainTnlProgram;
+
+   /** Program to emulate fixed-function T&L (see above) */
+   struct gl_vertex_program *_TnlProgram;
 
 #if FEATURE_MESA_program_debug
    GLprogramcallbackMESA Callback;
@@ -1911,18 +2007,28 @@ struct gl_vertex_program_state
 
 
 /**
- * Context state for GL_ARB/NV_fragment_program
+ * Context state for fragment programs.
  */
 struct gl_fragment_program_state
 {
-   GLboolean Enabled;                    /* GL_VERTEX_PROGRAM_NV */
-   GLboolean _Enabled;                   /* Enabled and valid program? */
+   GLboolean Enabled;     /**< User-set fragment program enable flag */
+   GLboolean _Enabled;    /**< Fragment program enabled and valid? */
    GLboolean _Active;
-   struct fragment_program *Current;     /* ptr to currently bound program */
-   struct fragment_program *_Current;    /* ptr to currently active program 
-                                           (including internal programs) */
-   struct fp_machine Machine;            /* machine state */
-   GLfloat Parameters[MAX_NV_FRAGMENT_PROGRAM_PARAMS][4]; /* Env params */
+   struct gl_fragment_program *Current;  /**< User-bound fragment program */
+
+   /** Currently enabled and valid program (including internal programs
+    * and compiled shader programs).
+    */
+   struct gl_fragment_program *_Current;
+
+   GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
+
+   /** Should fixed-function texturing be implemented with a fragment prog? */
+   GLboolean _MaintainTexEnvProgram;
+   GLboolean _UseTexEnvProgram;
+
+   /** Program to emulate fixed-function texture env/combine (see above) */
+   struct gl_fragment_program *_TexEnvProgram;
 
 #if FEATURE_MESA_program_debug
    GLprogramcallbackMESA Callback;
@@ -1942,17 +2048,6 @@ struct gl_fragment_program_state
 struct atifs_instruction;
 struct atifs_setupinst;
 
-/**
- * State for executing ATI fragment shader.
- */
-struct atifs_machine
-{
-   GLfloat Registers[6][4];         /** six temporary registers */
-   GLfloat PrevPassRegisters[6][4];
-   GLfloat Inputs[2][4];   /** Primary, secondary input colors */
-};
-
-
 /**
  * ATI fragment shader
  */
@@ -1983,7 +2078,6 @@ struct gl_ati_fragment_shader_state
    GLboolean _Enabled;                      /** enabled and valid shader? */
    GLboolean Compiling;
    GLfloat GlobalConstants[8][4];
-   struct atifs_machine Machine;            /* machine state */
    struct ati_fragment_shader *Current;
 };
 
@@ -2011,14 +2105,61 @@ struct gl_query_state
 };
 
 
+
 /**
- * Context state for vertex/fragment shaders.
+ * A GLSL shader object.
  */
-struct gl_shader_objects_state
+struct gl_shader
 {
-   struct gl2_program_intf **CurrentProgram;
-   GLboolean _VertexShaderPresent;
-   GLboolean _FragmentShaderPresent;
+   GLenum Type;  /**< GL_FRAGMENT_SHADER || GL_VERTEX_SHADER (first field!) */
+   GLuint Name;  /**< AKA the handle */
+   GLint RefCount;  /**< Reference count */
+   GLboolean DeletePending;
+
+   const GLchar *Source;  /**< Source code string */
+   GLboolean CompileStatus;
+   GLuint NumPrograms;  /**< size of Programs[] array */
+   struct gl_program **Programs;  /**< Post-compile assembly code */
+   GLchar *InfoLog;
+};
+
+
+/**
+ * A GLSL program object.  Basically a linked collection of "shaders".
+ */
+struct gl_shader_program
+{
+   GLenum Type;  /**< Always GL_SHADER_PROGRAM (internal token) */
+   GLuint Name;  /**< aka handle or ID */
+   GLint RefCount;  /**< Reference count */
+   GLboolean DeletePending;
+
+   GLuint NumShaders;          /**< number of attached shaders */
+   struct gl_shader **Shaders; /**< List of attached the shaders */
+
+   /* post-link info: */
+   struct gl_vertex_program *VertexProgram;     /**< Linked vertex program */
+   struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
+   struct gl_program_parameter_list *Uniforms; /**< Plus constants, etc */
+   struct gl_program_parameter_list *Varying;
+   struct gl_program_parameter_list *Attributes; /**< Vertex attributes */
+   GLboolean LinkStatus;   /**< GL_LINK_STATUS */
+   GLboolean Validated;
+   GLchar *InfoLog;
+};   
+
+
+/**
+ * Context state for GLSL vertex/fragment shaders.
+ */
+struct gl_shader_state
+{
+   struct gl_shader_program *CurrentProgram; /**< The user-bound program */
+   /** Driver-selectable options: */
+   GLboolean EmitHighLevelInstructions; /**< IF/ELSE/ENDIF vs. BRA, etc. */
+   GLboolean EmitCondCodes;             /**< Use condition codes? */
+   GLboolean EmitComments;              /**< Annotated instructions */
+   void *MemPool;
 };
 
 
@@ -2041,18 +2182,33 @@ struct gl_shared_state
    struct gl_texture_object *Default3D;
    struct gl_texture_object *DefaultCubeMap;
    struct gl_texture_object *DefaultRect;
+   struct gl_texture_object *Default1DArray;
+   struct gl_texture_object *Default2DArray;
+   /*@}*/
+
+   /**
+    * \name Thread safety and statechange notification for texture
+    * objects. 
+    *
+    * \todo Improve the granularity of locking.
+    */
+   /*@{*/
+   _glthread_Mutex TexMutex;              /**< texobj thread safety */
+   GLuint TextureStateStamp;              /**< state notification for shared tex  */
    /*@}*/
 
+
+
    /**
     * \name Vertex/fragment programs
     */
    /*@{*/
    struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
 #if FEATURE_ARB_vertex_program
-   struct program *DefaultVertexProgram;
+   struct gl_program *DefaultVertexProgram;
 #endif
 #if FEATURE_ARB_fragment_program
-   struct program *DefaultFragmentProgram;
+   struct gl_program *DefaultFragmentProgram;
 #endif
    /*@}*/
 
@@ -2065,13 +2221,19 @@ struct gl_shared_state
    struct _mesa_HashTable *BufferObjects;
 #endif
 
-   struct _mesa_HashTable *GL2Objects;
+#if FEATURE_ARB_shader_objects
+   /** Table of both gl_shader and gl_shader_program objects */
+   struct _mesa_HashTable *ShaderObjects;
+#endif
 
 #if FEATURE_EXT_framebuffer_object
    struct _mesa_HashTable *RenderBuffers;
    struct _mesa_HashTable *FrameBuffers;
 #endif
 
+   /** Objects associated with the GL_APPLE_vertex_array_object extension. */
+   struct _mesa_HashTable *ArrayObjects;
+
    void *DriverData;  /**< Device driver shared state */
 };
 
@@ -2089,6 +2251,8 @@ struct gl_shared_state
  */
 struct gl_renderbuffer
 {
+#define RB_MAGIC 0xaabbccdd
+   int Magic; /** XXX TEMPORARY DEBUG INFO */
    _glthread_Mutex Mutex;                 /**< for thread safety */
    GLuint ClassID;        /**< Useful for drivers */
    GLuint Name;
@@ -2106,7 +2270,7 @@ struct gl_renderbuffer
    GLubyte IndexBits;
    GLubyte DepthBits;
    GLubyte StencilBits;
-   GLvoid *Data;
+   GLvoid *Data;        /**< This may not be used by some kinds of RBs */
 
    /* Used to wrap one renderbuffer around another: */
    struct gl_renderbuffer *Wrapped;
@@ -2186,17 +2350,24 @@ struct gl_renderbuffer
  */
 struct gl_renderbuffer_attachment
 {
-   GLenum Type;  /* GL_NONE or GL_TEXTURE or GL_RENDERBUFFER_EXT */
+   GLenum Type;  /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
    GLboolean Complete;
 
-   /* IF Type == GL_RENDERBUFFER_EXT: */
+   /**
+    * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
+    * application supplied renderbuffer object.
+    */
    struct gl_renderbuffer *Renderbuffer;
 
-   /* IF Type == GL_TEXTURE: */
+   /**
+    * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
+    * supplied texture object.
+    */
    struct gl_texture_object *Texture;
-   GLuint TextureLevel;
-   GLuint CubeMapFace;  /* 0 .. 5, for cube map textures */
-   GLuint Zoffset;      /* for 3D textures */
+   GLuint TextureLevel; /**< Attached mipmap level. */
+   GLuint CubeMapFace;  /**< 0 .. 5, for cube map textures. */
+   GLuint Zoffset;      /**< Slice for 3D textures,  or layer for both 1D
+                         * and 2D array textures */
 };
 
 
@@ -2210,6 +2381,7 @@ struct gl_framebuffer
    _glthread_Mutex Mutex;                 /**< for thread safety */
    GLuint Name;      /* if zero, this is a window system framebuffer */
    GLint RefCount;
+   GLboolean DeletePending;
 
    GLvisual Visual;    /**< The framebuffer's visual.
                              Immutable if this is a window system buffer.
@@ -2287,6 +2459,8 @@ struct gl_program_constants
    GLuint MaxNativeTemps;
    GLuint MaxNativeAddressRegs; /* vertex program only, for now */
    GLuint MaxNativeParameters;
+   /* For shaders */
+   GLuint MaxUniformComponents;
 };
 
 
@@ -2299,10 +2473,11 @@ struct gl_constants
    GLint MaxTextureLevels;             /**< Maximum number of allowed mipmap levels. */ 
    GLint Max3DTextureLevels;           /**< Maximum number of allowed mipmap levels for 3D texture targets. */
    GLint MaxCubeTextureLevels;          /**< Maximum number of allowed mipmap levels for GL_ARB_texture_cube_map */
+   GLint MaxArrayTextureLayers;         /**< Maximum number of layers in an array texture. */
    GLint MaxTextureRectSize;            /* GL_NV_texture_rectangle */
    GLuint MaxTextureCoordUnits;
    GLuint MaxTextureImageUnits;
-   GLuint MaxTextureUnits;              /* = MAX(CoordUnits, ImageUnits) */
+   GLuint MaxTextureUnits;              /* = MIN(CoordUnits, ImageUnits) */
    GLfloat MaxTextureMaxAnisotropy;    /* GL_EXT_texture_filter_anisotropic */
    GLfloat MaxTextureLodBias;           /* GL_EXT_texture_lod_bias */
    GLuint MaxArrayLockSize;
@@ -2336,6 +2511,9 @@ struct gl_constants
    /* GL_EXT_framebuffer_object */
    GLuint MaxColorAttachments;
    GLuint MaxRenderbufferSize;
+   /* GL_ARB_vertex_shader */
+   GLuint MaxVertexTextureImageUnits;
+   GLuint MaxVarying;
 };
 
 
@@ -2355,6 +2533,7 @@ struct gl_extensions
    GLboolean ARB_depth_texture;
    GLboolean ARB_draw_buffers;
    GLboolean ARB_fragment_program;
+   GLboolean ARB_fragment_program_shadow;
    GLboolean ARB_fragment_shader;
    GLboolean ARB_half_float_pixel;
    GLboolean ARB_imaging;
@@ -2364,6 +2543,7 @@ struct gl_extensions
    GLboolean ARB_point_sprite;
    GLboolean ARB_shader_objects;
    GLboolean ARB_shading_language_100;
+   GLboolean ARB_shading_language_120;
    GLboolean ARB_shadow;
    GLboolean ARB_texture_border_clamp;
    GLboolean ARB_texture_compression;
@@ -2397,6 +2577,7 @@ struct gl_extensions
    GLboolean EXT_framebuffer_object;
    GLboolean EXT_fog_coord;
    GLboolean EXT_framebuffer_blit;
+   GLboolean EXT_gpu_program_parameters;
    GLboolean EXT_histogram;
    GLboolean EXT_multi_draw_arrays;
    GLboolean EXT_paletted_texture;
@@ -2423,15 +2604,18 @@ struct gl_extensions
    GLboolean EXT_texture_filter_anisotropic;
    GLboolean EXT_texture_lod_bias;
    GLboolean EXT_texture_mirror_clamp;
+   GLboolean EXT_texture_sRGB;
    GLboolean EXT_timer_query;
    GLboolean EXT_vertex_array;
    GLboolean EXT_vertex_array_set;
    /* vendor extensions */
    GLboolean APPLE_client_storage;
    GLboolean APPLE_packed_pixels;
+   GLboolean APPLE_vertex_array_object;
    GLboolean ATI_texture_mirror_once;
    GLboolean ATI_texture_env_combine3;
    GLboolean ATI_fragment_shader;
+   GLboolean ATI_separate_stencil;
    GLboolean IBM_rasterpos_clip;
    GLboolean IBM_multimode_draw_arrays;
    GLboolean MESA_pack_invert;
@@ -2439,6 +2623,7 @@ struct gl_extensions
    GLboolean MESA_program_debug;
    GLboolean MESA_resize_buffers;
    GLboolean MESA_ycbcr_texture;
+   GLboolean MESA_texture_array;
    GLboolean NV_blend_square;
    GLboolean NV_fragment_program;
    GLboolean NV_light_max_exponent;
@@ -2468,7 +2653,7 @@ struct gl_extensions
 /**
  * A stack of matrices (projection, modelview, color, texture, etc).
  */
-struct matrix_stack
+struct gl_matrix_stack
 {
    GLmatrix *Top;      /**< points into Stack */
    GLmatrix *Stack;    /**< array [MaxDepth] of GLmatrix */
@@ -2564,8 +2749,8 @@ struct matrix_stack
 #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_INDEX            VERT_BIT_COLOR_INDEX
+#define _NEW_ARRAY_EDGEFLAG         VERT_BIT_EDGEFLAG
 #define _NEW_ARRAY_TEXCOORD_0       VERT_BIT_TEX0
 #define _NEW_ARRAY_TEXCOORD_1       VERT_BIT_TEX1
 #define _NEW_ARRAY_TEXCOORD_2       VERT_BIT_TEX2
@@ -2574,7 +2759,7 @@ struct matrix_stack
 #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_ATTRIB_0         0x10000  /* start at bit 16 */
+#define _NEW_ARRAY_ATTRIB_0         VERT_BIT_GENERIC0  /* start at bit 16 */
 #define _NEW_ARRAY_ALL              0xffffffff
 
 
@@ -2631,6 +2816,7 @@ struct matrix_stack
 #define _MESA_NEW_NEED_EYE_COORDS         (_NEW_LIGHT |                \
                                            _NEW_TEXTURE |      \
                                            _NEW_POINT |                \
+                                           _NEW_PROGRAM |      \
                                            _NEW_MODELVIEW)
 
 #define _MESA_NEW_NEED_NORMALS            (_NEW_LIGHT |                \
@@ -2698,7 +2884,7 @@ struct mesa_display_list
 /**
  * State used during display list compilation and execution.
  */
-struct mesa_list_state
+struct gl_dlist_state
 {
    struct mesa_display_list *CallStack[MAX_LIST_NESTING];
    GLuint CallDepth;           /**< Current recursion calling depth */
@@ -2737,17 +2923,6 @@ struct mesa_list_state
  */
 struct __GLcontextRec
 {
-   /**
-    * \name OS related interfaces. 
-    *
-    * These \b must be the first members of this structure, because they are
-    * exposed to the outside world (i.e. GLX extension).
-    */
-   /*@{*/
-   __GLimports imports;
-   __GLexports exports;
-   /*@}*/
-
    /** State possibly shared with other contexts in the address space */
    struct gl_shared_state *Shared;
 
@@ -2770,26 +2945,25 @@ struct __GLcontextRec
    struct dd_function_table Driver;
 
    void *DriverCtx;    /**< Points to device driver context/state */
-   void *DriverMgrCtx; /**< Points to device driver manager (optional)*/
 
    /** Core/Driver constants */
    struct gl_constants Const;
 
    /** \name The various 4x4 matrix stacks */
    /*@{*/
-   struct matrix_stack ModelviewMatrixStack;
-   struct matrix_stack ProjectionMatrixStack;
-   struct matrix_stack ColorMatrixStack;
-   struct matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS];
-   struct matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
-   struct matrix_stack *CurrentStack; /**< Points to one of the above stacks */
+   struct gl_matrix_stack ModelviewMatrixStack;
+   struct gl_matrix_stack ProjectionMatrixStack;
+   struct gl_matrix_stack ColorMatrixStack;
+   struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS];
+   struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
+   struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
    /*@}*/
 
    /** Combined modelview and projection matrix */
    GLmatrix _ModelProjectMatrix;
 
    /** \name Display lists */
-   struct mesa_list_state ListState;
+   struct gl_dlist_state ListState;
 
    GLboolean ExecuteFlag;      /**< Execute GL commands? */
    GLboolean CompileFlag;      /**< Compile GL commands into display list? */
@@ -2847,6 +3021,7 @@ struct __GLcontextRec
 
    /** \name Other assorted state (not pushed/popped on attribute stack) */
    /*@{*/
+   struct gl_pixelmaps          PixelMaps;
    struct gl_histogram_attrib  Histogram;
    struct gl_minmax_attrib     MinMax;
    struct gl_convolution_attrib Convolution1D;
@@ -2857,28 +3032,23 @@ struct __GLcontextRec
    struct gl_feedback   Feedback;  /**< Feedback */
    struct gl_selection  Select;    /**< Selection */
 
-   struct gl_color_table ColorTable;       /**< Pre-convolution */
-   struct gl_color_table ProxyColorTable;  /**< Pre-convolution */
+   struct gl_color_table ColorTable[COLORTABLE_MAX];
+   struct gl_color_table ProxyColorTable[COLORTABLE_MAX];
+#if 0
    struct gl_color_table PostConvolutionColorTable;
    struct gl_color_table ProxyPostConvolutionColorTable;
    struct gl_color_table PostColorMatrixColorTable;
    struct gl_color_table ProxyPostColorMatrixColorTable;
+#endif
 
    struct gl_program_state Program;        /**< for vertex or fragment progs */
    struct gl_vertex_program_state VertexProgram;   /**< GL_ARB/NV_vertex_program */
    struct gl_fragment_program_state FragmentProgram;  /**< GL_ARB/NV_vertex_program */
    struct gl_ati_fragment_shader_state ATIFragmentShader;  /**< GL_ATI_fragment_shader */
 
-   struct fragment_program *_TexEnvProgram;     /**< Texture state as fragment program */
-   struct vertex_program *_TnlProgram;          /**< Fixed func TNL state as vertex program */
-
-   GLboolean _MaintainTnlProgram;
-   GLboolean _MaintainTexEnvProgram;
-   GLboolean _UseTexEnvProgram;
-
    struct gl_query_state Query;  /**< GL_ARB_occlusion_query */
 
-   struct gl_shader_objects_state ShaderObjects;       /* GL_ARB_shader_objects */
+   struct gl_shader_state Shader; /**< GLSL shader object state */
    /*@}*/
 
 #if FEATURE_EXT_framebuffer_object
@@ -2899,6 +3069,8 @@ struct __GLcontextRec
    GLboolean _ForceEyeCoords; 
    GLenum _CurrentProgram;    /* currently executing program */
 
+   GLuint TextureStateTimestamp; /* detect changes to shared state */
+
    struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
    struct gl_shine_tab *_ShineTabList;  /**< MRU list of inactive shine tables */
    /**@}*/