Merge branch 'mesa_7_6_branch' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / mesa / tnl / t_context.h
index fb036b9f3d94dfe01cf3b63e4c460c20f8c60022..ca4edcfcb9b940974719456b1b1a89e6256c2dc4 100644 (file)
@@ -1,11 +1,8 @@
-
-/* $Id: t_context.h,v 1.6 2000/12/08 00:18:39 brianp Exp $ */
-
 /*
- * Mesa 3-D graphics library
- * Version:  3.5
+ * mesa 3-D graphics library
+ * Version:  6.5
  *
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/**
+ * \file t_context.h
+ * \brief TnL module datatypes and definitions.
+ * \author Keith Whitwell
+ */
+
+
+/**
+ * \mainpage The TNL-module
+ *
+ * TNL stands for "transform and lighting", i.e. this module implements
+ * a pipeline that receives as input a buffer of vertices and does all
+ * necessary transformations (rotations, clipping, vertex shader etc.)
+ * and passes then the output to the rasterizer.
+ *
+ * The tnl_pipeline contains the array of all stages, which should be
+ * applied. Each stage is a black-box, which is described by an
+ * tnl_pipeline_stage. The function ::_tnl_run_pipeline applies all the
+ * stages to the vertex_buffer TNLcontext::vb, where the vertex data
+ * is stored. The last stage in the pipeline is the rasterizer.
+ *
+ */
+
+
 #ifndef _T_CONTEXT_H
 #define _T_CONTEXT_H
 
-#include "glheader.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/bitset.h"
+#include "main/mtypes.h"
 
 #include "math/m_matrix.h"
 #include "math/m_vector.h"
 #include "math/m_xform.h"
 
-#include "t_trans_elt.h"
-
+#include "vbo/vbo.h"
 
+#define MAX_PIPELINE_STAGES     30
 
 /*
- * Bits to indicate which faces a vertex participates in,
- * what facing the primitive provoked by that vertex has,
- * and some misc. flags.
+ * Note: The first attributes match the VERT_ATTRIB_* definitions
+ * in mtypes.h.  However, the tnl module has additional attributes
+ * for materials, color indexes, edge flags, etc.
  */
-#define VERT_FACE_FRONT       0x1      /* is in a front-color primitive */
-#define VERT_FACE_REAR        0x2      /* is in a rear-color primitive */
-#define PRIM_FACE_FRONT       0x4      /* use front color */
-#define PRIM_FACE_REAR        0x8      /* use rear color */
-#define PRIM_CLIPPED          0x10     /* needs clipping */
-#define PRIM_USER_CLIPPED     CLIP_USER_BIT    /* 0x40 */
-
-
-#define PRIM_FLAG_SHIFT  2
-#define PRIM_FACE_FLAGS  (PRIM_FACE_FRONT|PRIM_FACE_REAR)
-#define VERT_FACE_FLAGS  (VERT_FACE_FRONT|VERT_FACE_REAR)
-
-#define PRIM_ANY_CLIP    (PRIM_CLIPPED|PRIM_USER_CLIPPED)
-#define PRIM_NOT_CULLED  (PRIM_ANY_CLIP|PRIM_FACE_FLAGS)
-
-/* Flags for VB->CullMode.
+/* Although it's nice to use these as bit indexes in a DWORD flag, we
+ * could manage without if necessary.  Another limit currently is the
+ * number of bits allocated for these numbers in places like vertex
+ * program instruction formats and register layouts.
+ */
+/* The bit space exhaustion is a fact now, done by _TNL_ATTRIB_ATTRIBUTE* for
+ * GLSL vertex shader which cannot be aliased with conventional vertex attribs.
+ * Compacting _TNL_ATTRIB_MAT_* attribs would not work, they would not give
+ * as many free bits (11 plus already 1 free bit) as _TNL_ATTRIB_ATTRIBUTE*
+ * attribs want (16).
  */
-#define CULL_MASK_ACTIVE  0x1
-#define COMPACTED_NORMALS 0x2
-#define CLIP_MASK_ACTIVE  0x4
+enum {
+       _TNL_ATTRIB_POS = 0,
+       _TNL_ATTRIB_WEIGHT = 1,
+       _TNL_ATTRIB_NORMAL = 2,
+       _TNL_ATTRIB_COLOR0 = 3,
+       _TNL_ATTRIB_COLOR1 = 4,
+       _TNL_ATTRIB_FOG = 5,
+       _TNL_ATTRIB_COLOR_INDEX = 6,
+       _TNL_ATTRIB_EDGEFLAG = 7,
+       _TNL_ATTRIB_TEX0 = 8,
+       _TNL_ATTRIB_TEX1 = 9,
+       _TNL_ATTRIB_TEX2 = 10,
+       _TNL_ATTRIB_TEX3 = 11,
+       _TNL_ATTRIB_TEX4 = 12,
+       _TNL_ATTRIB_TEX5 = 13,
+       _TNL_ATTRIB_TEX6 = 14,
+       _TNL_ATTRIB_TEX7 = 15,
+
+       _TNL_ATTRIB_GENERIC0 = 16, /* doesn't really exist! */
+       _TNL_ATTRIB_GENERIC1 = 17,
+       _TNL_ATTRIB_GENERIC2 = 18,
+       _TNL_ATTRIB_GENERIC3 = 19,
+       _TNL_ATTRIB_GENERIC4 = 20,
+       _TNL_ATTRIB_GENERIC5 = 21,
+       _TNL_ATTRIB_GENERIC6 = 22,
+       _TNL_ATTRIB_GENERIC7 = 23,
+       _TNL_ATTRIB_GENERIC8 = 24,
+       _TNL_ATTRIB_GENERIC9 = 25,
+       _TNL_ATTRIB_GENERIC10 = 26,
+       _TNL_ATTRIB_GENERIC11 = 27,
+       _TNL_ATTRIB_GENERIC12 = 28,
+       _TNL_ATTRIB_GENERIC13 = 29,
+       _TNL_ATTRIB_GENERIC14 = 30,
+       _TNL_ATTRIB_GENERIC15 = 31,
+
+       /* These alias with the generics, but they are not active
+        * concurrently, so it's not a problem.  The TNL module
+        * doesn't have to do anything about this as this is how they
+        * are passed into the _draw_prims callback.
+        *
+        * When we generate fixed-function replacement programs (in
+        * t_vp_build.c currently), they refer to the appropriate
+        * generic attribute in order to pick up per-vertex material
+        * data.
+        */
+       _TNL_ATTRIB_MAT_FRONT_AMBIENT = 16,
+       _TNL_ATTRIB_MAT_BACK_AMBIENT = 17,
+       _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 18,
+       _TNL_ATTRIB_MAT_BACK_DIFFUSE = 19,
+       _TNL_ATTRIB_MAT_FRONT_SPECULAR = 20,
+       _TNL_ATTRIB_MAT_BACK_SPECULAR = 21,
+       _TNL_ATTRIB_MAT_FRONT_EMISSION = 22,
+       _TNL_ATTRIB_MAT_BACK_EMISSION = 23,
+       _TNL_ATTRIB_MAT_FRONT_SHININESS = 24,
+       _TNL_ATTRIB_MAT_BACK_SHININESS = 25,
+       _TNL_ATTRIB_MAT_FRONT_INDEXES = 26,
+       _TNL_ATTRIB_MAT_BACK_INDEXES = 27,
+
+       /* This is really a VERT_RESULT, not an attrib.  Need to fix
+        * tnl to understand the difference.
+        */
+       _TNL_ATTRIB_POINTSIZE = 16,
+
+       _TNL_ATTRIB_MAX = 32
+} ;
+
+#define _TNL_ATTRIB_TEX(u)       (_TNL_ATTRIB_TEX0 + (u))
+#define _TNL_ATTRIB_GENERIC(n) (_TNL_ATTRIB_GENERIC0 + (n))
+
+/* special index used for handing invalid glVertexAttribute() indices */
+#define _TNL_ATTRIB_ERROR    (_TNL_ATTRIB_GENERIC15 + 1)
 
-/* Flags for selecting a shading function.  The first two bits are
- * shared with the cull mode (ie. cull_mask_active and
- * compacted_normals.)
+/**
+ * Handy attribute ranges:
  */
-#define SHADE_TWOSIDE           0x4
+#define _TNL_FIRST_PROG      _TNL_ATTRIB_WEIGHT
+#define _TNL_LAST_PROG       _TNL_ATTRIB_TEX7
 
+#define _TNL_FIRST_TEX       _TNL_ATTRIB_TEX0
+#define _TNL_LAST_TEX        _TNL_ATTRIB_TEX7
 
-/* KW: Flags that describe the current vertex state, and the contents
- * of a vertex in a vertex-cassette.
- *
- * For really major expansion, consider a 'VERT_ADDITIONAL_FLAGS' flag,
- * which means there is data in another flags array (eg, extra_flags[]).
- */
+#define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0
+#define _TNL_LAST_GENERIC  _TNL_ATTRIB_GENERIC15
 
-#define VERT_OBJ_2           0x1       /* glVertex2 */
-#define VERT_OBJ_3           0x2        /* glVertex3 */
-#define VERT_OBJ_4           0x4        /* glVertex4 */
-#define VERT_BEGIN           0x8       /* glBegin */
-#define VERT_END             0x10      /* glEnd */
-#define VERT_ELT             0x20      /* glArrayElement */
-#define VERT_RGBA            0x40      /* glColor */
-#define VERT_NORM            0x80      /* glNormal */
-#define VERT_INDEX           0x100     /* glIndex */
-#define VERT_EDGE            0x200     /* glEdgeFlag */
-#define VERT_MATERIAL        0x400     /* glMaterial */
-#define VERT_END_VB          0x800     /* end vb marker */
-#define VERT_TEX0            0x1000    
-#define VERT_TEX1            0x2000
-#define VERT_TEX2            0x3000
-#define VERT_TEX3            0x4000
-#define VERT_TEX4            0x10000   
-#define VERT_TEX5            0x20000
-#define VERT_TEX6            0x30000
-#define VERT_TEX7            0x40000
-#define VERT_TEX8            0x100000  
-#define VERT_TEX9            0x200000
-#define VERT_TEX10           0x300000
-#define VERT_TEX11           0x400000
-#define VERT_EVAL_C1         0x1000000  /* could reuse OBJ bits for this? */
-#define VERT_EVAL_C2         0x2000000  /*    - or just use 3 bits */
-#define VERT_EVAL_P1         0x4000000  /*  */
-#define VERT_EVAL_P2         0x8000000  /*  */
-#define VERT_SPEC_RGB        0x10000000        
-#define VERT_FOG_COORD       0x20000000        
-#define VERT_POINT_SIZE      0x40000000
-
-#define VERT_EYE             VERT_BEGIN /* reuse */
-#define VERT_WIN             VERT_END   /* reuse */
-#define VERT_SETUP_FULL      VERT_EVAL_P1 /* Rastersetup has been done */
-#define VERT_PRECALC_DATA    VERT_END_VB /* reuse */
-
-/* Shorthands.
- */
+#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC0 */
+#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC11 */
 
-#define VERT_EVAL_ANY      (VERT_EVAL_C1|VERT_EVAL_P1| \
-                            VERT_EVAL_C2|VERT_EVAL_P2)
-
-#define VERT_OBJ_23       (VERT_OBJ_3|VERT_OBJ_2)
-#define VERT_OBJ_234      (VERT_OBJ_4|VERT_OBJ_23)
-#define VERT_OBJ_ANY      VERT_OBJ_2
-
-#define VERT_TEX0_SHIFT 11
-#define VERT_TEX(i)        (VERT_TEX0 << i)
-#define VERT_TEX_ANY       (VERT_TEX0 |                \
-                            VERT_TEX1 |                \
-                            VERT_TEX2 |                \
-                            VERT_TEX3 |                \
-                            VERT_TEX4 |                \
-                            VERT_TEX5 |                \
-                            VERT_TEX6 |                \
-                            VERT_TEX7 |                \
-                            VERT_TEX8 |                \
-                            VERT_TEX9 |                \
-                            VERT_TEX10 |       \
-                            VERT_TEX11)
-
-#define VERT_FIXUP         (VERT_TEX_ANY |     \
-                           VERT_RGBA |         \
-                           VERT_SPEC_RGB |     \
-                           VERT_FOG_COORD |    \
-                            VERT_INDEX |       \
-                            VERT_EDGE |                \
-                            VERT_NORM)
-
-#define VERT_DATA          (VERT_TEX_ANY | \
-                           VERT_RGBA | \
-                           VERT_SPEC_RGB | \
-                           VERT_FOG_COORD | \
-                            VERT_INDEX | \
-                            VERT_EDGE | \
-                            VERT_NORM | \
-                           VERT_OBJ_ANY | \
-                            VERT_MATERIAL | \
-                            VERT_ELT | \
-                           VERT_EVAL_ANY | \
-                            VERT_FOG_COORD)
-
-
-
-
-struct gl_pipeline;
-struct tnl_context;
+/* Number of available generic attributes */
+#define _TNL_NUM_GENERIC 16
 
-/**
- ** Vertex buffer/array structures
- **/
+/* Number of attributes used for evaluators */
+#define _TNL_NUM_EVAL 16
 
-struct vertex_data
-{
-   GLfloat (*Obj)[4];
-   GLfloat (*Normal)[3];
-   GLchan  (*Color)[4];
-   GLuint   *Index;
-   GLubyte  *EdgeFlag;
-   GLfloat (*TexCoord[MAX_TEXTURE_UNITS])[4];
-   GLuint   *Elt;
-   GLfloat  *FogCoord;
-   GLubyte  (*SecondaryColor)[4];
-};
 
-struct vertex_arrays
-{
-   GLvector4f  Obj;
-   GLvector3f  Normal;
-   GLvector4ub Color;
-   GLvector1ui Index;
-   GLvector1ub EdgeFlag;
-   GLvector4f  TexCoord[MAX_TEXTURE_UNITS];
-   GLvector1ui Elt;
-   GLvector4ub SecondaryColor;
-   GLvector1f  FogCoord;
-};
+#define PRIM_BEGIN     0x10
+#define PRIM_END       0x20
+#define PRIM_MODE_MASK 0x0f
 
-struct vertex_array_pointers
+static INLINE GLuint _tnl_translate_prim( const struct _mesa_prim *prim )
 {
-   GLvector4f  *Obj;
-   GLvector3f  *Normal;
-   GLvector4ub *Color;
-   GLvector1ui *Index;
-   GLvector1ub *EdgeFlag;
-   GLvector4f  *TexCoord[MAX_TEXTURE_UNITS];
-   GLvector1ui *Elt;
-   GLvector4ub *SecondaryColor;
-   GLvector1f *FogCoord;
-};
+   GLuint flag;
+   flag = prim->mode;
+   if (prim->begin) flag |= PRIM_BEGIN;
+   if (prim->end) flag |= PRIM_END;
+   return flag;
+}
 
-/* Values for VB->Type */
-enum {
-   VB_IMMEDIATE,
-   VB_CVA_PRECALC
-};
 
 
-/* Values for immediate->BeginState */
-#define VERT_BEGIN_0    0x1       /* glBegin (if initially inside beg/end) */
-#define VERT_BEGIN_1    0x2       /* glBegin (if initially outside beg/end) */
-#define VERT_ERROR_0    0x4       /* invalid_operation in initial state 0 */
-#define VERT_ERROR_1    0x8        /* invalid_operation in initial state 1 */
 
-/* KW: Represents everything that can take place between a begin and
- * end, and can represent multiple begin/end pairs.  This plus *any*
- * state variable (GLcontext) should be all you need to replay the
- * represented begin/end pairs as if they took place in that state.
- *
- * Thus this is sufficient for both immediate and compiled modes, but
- * we could/should throw some elements away for compiled mode if we
- * know they were empty.
+/**
+ * Contains the current state of a running pipeline.
  */
-struct immediate
+struct vertex_buffer
 {
-   struct immediate *next;     /* for cache of free IM's */
-   GLuint id, ref_count;
+   GLuint Size;  /**< Max vertices per vertex buffer, constant */
 
-   /* This must be saved when immediates are shared in display lists.
+   /* Constant over the pipeline.
     */
-   GLuint Start, Count;
-   GLuint LastData;            /* count or count+1 */
-   GLuint AndFlag, OrFlag;
-   GLuint Tex3Flag, Tex4Flag;  /* keep track of texcoord sizes */
-   GLuint BeginState, SavedBeginState;
-   GLuint LastPrimitive;       
-
-   GLuint ArrayAndFlags;       /* precalc'ed for glArrayElt */
-   GLuint ArrayIncr;
-   GLuint ArrayEltFlush;
-   GLuint FlushElt;
-
-   GLuint  Primitive[VB_SIZE]; /* GLubyte would do... */
-   GLuint  NextPrimitive[VB_SIZE];
-
-   /* allocate storage for these on demand:
-    */
-   struct  gl_material (*Material)[2];
-   GLuint  *MaterialMask;
-
-   GLfloat (*TexCoordPtr[MAX_TEXTURE_UNITS])[4];
-
-   struct vertex_arrays v;
+   GLuint Count;  /**< Number of vertices currently in buffer */
 
-   struct __GLcontextRec *backref;             
-
-   /* Normal lengths, zero if not available.
+   /* Pointers to current data.
+    * XXX some of these fields alias AttribPtr below and should be removed
+    * such as NormalPtr, TexCoordPtr, FogCoordPtr, etc.
     */
-   GLfloat   *NormalLengths;
-   GLuint     LastCalcedLength;
-
-   GLuint  Flag[VB_SIZE];    /* bitwise-OR of VERT_ flags */
-   GLchan  Color[VB_SIZE][4];
-   GLfloat Obj[VB_SIZE][4];
-   GLfloat Normal[VB_SIZE][3];
-   GLfloat TexCoord[MAX_TEXTURE_UNITS][VB_SIZE][4];
-   GLuint  Elt[VB_SIZE];
-   GLubyte EdgeFlag[VB_SIZE];
-   GLuint  Index[VB_SIZE];
-   GLubyte SecondaryColor[VB_SIZE][4];
-   GLfloat FogCoord[VB_SIZE];
+   GLuint      *Elts;                          
+   GLvector4f  *ObjPtr;                                /* _TNL_BIT_POS */
+   GLvector4f  *EyePtr;                                /* _TNL_BIT_POS */
+   GLvector4f  *ClipPtr;                       /* _TNL_BIT_POS */
+   GLvector4f  *NdcPtr;                         /* _TNL_BIT_POS */
+   GLfloat     *ClipDistancePtr[MAX_CLIP_PLANES]; /* _TNL_BIT_POS */
+   GLubyte     ClipOrMask;                     /* _TNL_BIT_POS */
+   GLubyte     ClipAndMask;                    /* _TNL_BIT_POS */
+   GLubyte     *ClipMask;                      /* _TNL_BIT_POS */
+   GLvector4f  *NormalPtr;                     /* _TNL_BIT_NORMAL */
+   GLfloat     *NormalLengthPtr;               /* _TNL_BIT_NORMAL */
+   GLboolean   *EdgeFlag;                      /* _TNL_BIT_EDGEFLAG */
+   GLvector4f  *TexCoordPtr[MAX_TEXTURE_COORD_UNITS]; /* VERT_TEX_0..n */
+   GLvector4f  *IndexPtr[2];                   /* _TNL_BIT_INDEX */
+   GLvector4f  *ColorPtr[2];                   /* _TNL_BIT_COLOR0 */
+   GLvector4f  *SecondaryColorPtr[2];           /* _TNL_BIT_COLOR1 */
+   GLvector4f  *FogCoordPtr;                   /* _TNL_BIT_FOG */
+
+   const struct _mesa_prim  *Primitive;                      
+   GLuint      PrimitiveCount;       
+
+   /* Inputs to the vertex program stage */
+   GLvector4f *AttribPtr[_TNL_ATTRIB_MAX];      /* GL_NV_vertex_program */
 };
 
 
-/* Not so big on storage these days, although still has pointers to
- * arrays used for temporary results.
+/**
+ * Describes an individual operation on the pipeline.
  */
-typedef struct vertex_buffer
+struct tnl_pipeline_stage
 {
-   /* Backpointers.
-    */
-   struct __GLcontextRec *ctx;
-   struct tnl_context *tnlctx;
+   const char *name;
 
-   /* Driver_data is allocated in Driver.RegisterVB(), if required.
+   /* Private data for the pipeline stage:
     */
-   void *driver_data;
+   void *privatePtr;
 
-   /* List of operations to process vertices in current state.
+   /* Allocate private data
     */
-   struct gl_pipeline *pipeline;
+   GLboolean (*create)( GLcontext *ctx, struct tnl_pipeline_stage * );
 
-   /* Temporary storage used by immediate mode functions and various
-    * operations in the pipeline.
+   /* Free private data.
     */
-   struct immediate *IM;       
-   struct vertex_array_pointers store; 
+   void (*destroy)( struct tnl_pipeline_stage * );
 
-   /* Where to find outstanding untransformed vertices.
-    */
-   struct immediate *prev_buffer;
-
-   GLuint     Type;            /* Either VB_IMMEDIATE or VB_CVA_PRECALC */
-
-   GLuint     Size, Start, Count;
-   GLuint     Free, FirstFree;
-   GLuint     CopyStart;
-   GLuint     Parity, Ovf;
-   GLuint     PurgeFlags;
-   GLuint     IndirectCount;   /* defaults to count */
-   GLuint     OrFlag, SavedOrFlag;
-   GLuint     Tex3Flag, Tex4Flag;
-   GLuint     SavedTex3Flag, SavedTex4Flag;
-   GLuint     EarlyCull;
-   GLuint     Culled, CullDone;
-
-   /* Pointers to input data - default to buffers in 'im' above.
-    */
-   GLvector4f  *ObjPtr;
-   GLvector3f  *NormalPtr;
-   GLvector4ub *ColorPtr;
-   GLvector1ui *IndexPtr;
-   GLvector1ub *EdgeFlagPtr;
-   GLvector4f  *TexCoordPtr[MAX_TEXTURE_UNITS];
-   GLvector1ui *EltPtr;
-   GLvector4ub *SecondaryColorPtr;
-   GLvector1f  *FogCoordPtr;
-   GLuint      *Flag, FlagMax;
-   struct      gl_material (*Material)[2];
-   GLuint      *MaterialMask;
-
-   GLuint      *NextPrimitive;
-   GLuint      *Primitive;
-   GLuint      LastPrimitive;
-
-   GLfloat (*BoundsPtr)[3];    /* Bounds for cull check */
-   GLfloat  *NormalLengthPtr;  /* Array of precomputed inv. normal lengths */
-
-   /* Holds malloced storage for pipeline data not supplied by
-    * the immediate struct.
+   /* Called on any statechange or input array size change or
+    * input array change to/from zero stride.
     */
-   GLvector4f Eye;
-   GLvector4f Clip;
-   GLvector4f Win;
-   GLvector1f PointSize;
-   GLvector4ub BColor;         /* not used in cva vb's */
-   GLvector1ui BIndex;         /* not used in cva vb's */
-   GLvector4ub BSecondary;     /* not used in cva vb's */
-
-   /* Temporary storage - may point into IM, or be dynamically
-    * allocated (for cva).
-    */
-   GLubyte *ClipMask;
-   GLubyte *UserClipMask;
-
-   /* Internal values.  Where these point depends on whether
-    * there were any identity matrices defined as transformations
-    * in the pipeline.
+   void (*validate)( GLcontext *ctx, struct tnl_pipeline_stage * );
+
+   /* Called from _tnl_run_pipeline().  The stage.changed_inputs value
+    * encodes all inputs to thee struct which have changed.  If
+    * non-zero, recompute all affected outputs of the stage, otherwise
+    * execute any 'sideeffects' of the stage.
+    *
+    * Return value: GL_TRUE - keep going
+    *               GL_FALSE - finished pipeline
     */
-   GLvector4f *EyePtr;
-   GLvector4f *ClipPtr;
-   GLvector4f *Unprojected;
-   GLvector4f *Projected;
-   GLvector4f *CurrentTexCoord;
-   GLuint     *Indirect;           /* For eval rescue and cva render */
-
-   /* Currently active colors
-    */
-   GLvector4ub *Color[2];
-   GLvector1ui *Index[2];
-   GLvector4ub *SecondaryColor[2];
-
-   /* Storage for colors which have been lit but not yet fogged.
-    * Required for CVA, just point into store for normal VB's.
-    */
-   GLvector4ub *LitColor[2];
-   GLvector1ui *LitIndex[2];
-   GLvector4ub *LitSecondary[2];
+   GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * );
+};
 
-   /* Temporary values used in texgen.
-    */
-   GLfloat (*tmp_f)[3];
-   GLfloat *tmp_m;
 
-   /* Temporary values used in eval.
-    */
-   GLuint *EvaluatedFlags;
 
-   /* Not used for cva:
-    */
-   GLubyte *NormCullStart;
-   GLubyte *CullMask;          /* Results of vertex culling */
-   GLubyte *NormCullMask;       /* Compressed onto shared normals */
+/** Contains the array of all pipeline stages.
+ * The default values are defined at the end of t_pipeline.c 
+ */
+struct tnl_pipeline {
+   
+   GLuint last_attrib_stride[_TNL_ATTRIB_MAX];
+   GLuint last_attrib_size[_TNL_ATTRIB_MAX];
+   GLuint input_changes;
+   GLuint new_state;
+
+   struct tnl_pipeline_stage stages[MAX_PIPELINE_STAGES+1];
+   GLuint nr_stages;
+};
 
-   GLubyte ClipOrMask;         /* bitwise-OR of all ClipMask[] values */
-   GLubyte ClipAndMask;                /* bitwise-AND of all ClipMask[] values */
-   GLubyte CullFlag[2];
-   GLubyte CullMode;           /* see flags below */
+struct tnl_clipspace;
+struct tnl_clipspace_attr;
 
-   GLuint CopyCount;           /* max 3 vertices to copy after transform */
-   GLuint Copy[3];
-   GLfloat CopyProj[3][4];     /* temporary store for projected clip coords */
+typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a, 
+                                 GLfloat *out, 
+                                 const GLubyte *v );
 
-   /* Hooks for module private data
-    */
-   void *swsetup_vb;
+typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a, 
+                                GLubyte *v, 
+                                const GLfloat *in );
 
-} TNLvertexbuffer;
+typedef void (*tnl_emit_func)( GLcontext *ctx, 
+                              GLuint count, 
+                              GLubyte *dest );
 
 
-typedef void (*shade_func)( struct vertex_buffer *VB );
+/**
+ * Describes how to convert/move a vertex attribute from a vertex array
+ * to a vertex structure.
+ */
+struct tnl_clipspace_attr
+{
+   GLuint attrib;          /* which vertex attrib (0=position, etc) */
+   GLuint format;
+   GLuint vertoffset;      /* position of the attrib in the vertex struct */
+   GLuint vertattrsize;    /* size of the attribute in bytes */
+   GLubyte *inputptr;
+   GLuint inputstride;
+   GLuint inputsize;
+   const tnl_insert_func *insert;
+   tnl_insert_func emit;
+   tnl_extract_func extract;
+   const GLfloat *vp;   /* NDC->Viewport mapping matrix */
+};
 
-typedef void (*clip_interp_func)( struct vertex_buffer *VB, GLuint dst,
-                                  GLfloat t, GLuint in, GLuint out );
 
-typedef GLuint (*clip_line_func)( struct vertex_buffer *VB,
-                                 GLuint *i, GLuint *j,
-                                 GLubyte mask);
 
-typedef GLuint (*clip_poly_func)( struct vertex_buffer *VB,
-                                 GLuint n, GLuint vlist[],
-                                 GLubyte mask );
 
+typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last );
+typedef void (*tnl_line_func)( GLcontext *ctx, GLuint v1, GLuint v2 );
+typedef void (*tnl_triangle_func)( GLcontext *ctx,
+                                  GLuint v1, GLuint v2, GLuint v3 );
+typedef void (*tnl_quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
+                              GLuint v3, GLuint v4 );
+typedef void (*tnl_render_func)( GLcontext *ctx, GLuint start, GLuint count,
+                                GLuint flags );
+typedef void (*tnl_interp_func)( GLcontext *ctx,
+                                GLfloat t, GLuint dst, GLuint out, GLuint in,
+                                GLboolean force_boundary );
+typedef void (*tnl_copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src );
+typedef void (*tnl_setup_func)( GLcontext *ctx,
+                               GLuint start, GLuint end,
+                               GLuint new_inputs);
 
-#define MAX_PIPELINE_STAGES     30
 
-#define PIPE_IMMEDIATE          0x1
-#define PIPE_PRECALC            0x2
+struct tnl_attr_type {
+   GLuint format;
+   GLuint size;
+   GLuint stride;
+   GLuint offset;
+};
 
-#define PIPE_OP_VERT_XFORM        0x1
-#define PIPE_OP_NORM_XFORM        0x2
-#define PIPE_OP_LIGHT             0x4
-#define PIPE_OP_FOG               0x8
-#define PIPE_OP_TEX              0x10
-#define PIPE_OP_RAST_SETUP_0    0x100
-#define PIPE_OP_RAST_SETUP_1    0x200
-#define PIPE_OP_RENDER          0x400
-#define PIPE_OP_CVA_PREPARE     0x800
-#define PIPE_OP_POINT_SIZE     0x1000
+struct tnl_clipspace_fastpath {
+   GLuint vertex_size;
+   GLuint attr_count;
+   GLboolean match_strides;
 
+   struct tnl_attr_type *attr;
 
-struct gl_pipeline_stage {
-   const char *name;
-   GLuint ops;                 /* PIPE_OP flags */
-   GLuint type;                        /* VERT flags */
-   GLuint special;             /* VERT flags - force update_inputs() */
-   GLuint state_change;                /* state flags - trigger update_inputs() */
-   GLuint cva_state_change;          /* state flags - recalc cva buffer */
-   GLuint elt_forbidden_inputs;      /* VERT flags - force a pipeline recalc */
-   GLuint pre_forbidden_inputs;             /* VERT flags - force a pipeline recalc */
-   GLuint active;                   /* VERT flags */
-   GLuint inputs;                   /* VERT flags */
-   GLuint outputs;                  /* VERT flags */
-   void (*check)( GLcontext *ctx, struct gl_pipeline_stage * );
-   void (*run)( struct vertex_buffer *VB );
+   tnl_emit_func func;
+   struct tnl_clipspace_fastpath *next;
 };
 
-
-struct gl_pipeline {
-   GLuint state_change;                /* state changes which require recalc */
-   GLuint cva_state_change;    /* ... which require re-run */
-   GLuint forbidden_inputs;    /* inputs which require recalc */
-   GLuint ops;                 /* what gets done in this pipe */
-   GLuint changed_ops;
-   GLuint inputs;
-   GLuint outputs;
+/**
+ * Used to describe conversion of vertex arrays to vertex structures.
+ * I.e. Structure of arrays to arrays of structs.
+ */
+struct tnl_clipspace
+{
+   GLboolean need_extras;
+   
    GLuint new_inputs;
-   GLuint new_outputs;
-   GLuint fallback;
-   GLuint type;
-   GLuint pipeline_valid:1;
-   GLuint data_valid:1;
-   GLuint copy_transformed_data:1;
-   GLuint replay_copied_vertices:1;
-   GLuint new_state;           /* state changes since last recalc */
-   struct gl_pipeline_stage *stages[MAX_PIPELINE_STAGES];
-};
 
+   GLubyte *vertex_buf;
+   GLuint vertex_size;
+   GLuint max_vertex_size;
 
+   struct tnl_clipspace_attr attr[_TNL_ATTRIB_MAX];
+   GLuint attr_count;
 
-/* All fields are derived.
- */
-struct gl_cva {
-   struct gl_pipeline pre;
-   struct gl_pipeline elt;
-       
-   struct gl_client_array Elt;
-   trans_1ui_func EltFunc;
-
-   struct vertex_buffer *VB;
-   struct vertex_arrays v;
-   struct vertex_data store;
-
-   GLuint elt_count;
-   GLenum elt_mode;
-   GLuint elt_size;
-
-   GLuint forbidden_inputs;
-   GLuint orflag;
-   GLuint merge;
-
-   GLuint locked;
-   GLuint lock_changed;
-   GLuint last_orflag;
-   GLuint last_array_flags;
-   GLuint last_array_new_state;
-};
+   tnl_emit_func emit;
+   tnl_interp_func interp;
+   tnl_copy_pv_func copy_pv;
 
-/* These are used to make the ctx->Current values look like
- * arrays (with zero StrideB).
- */
-struct gl_fallback_arrays {
-   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_UNITS];
-   struct gl_client_array EdgeFlag;
+   /* Parameters and constants for codegen:
+    */
+   GLboolean need_viewport;
+   GLfloat vp_scale[4];                
+   GLfloat vp_xlate[4];
+   GLfloat chan_scale[4];
+   GLfloat identity[4];
+
+   struct tnl_clipspace_fastpath *fastpath;
+   
+   void (*codegen_emit)( GLcontext *ctx );
 };
 
 
+struct tnl_device_driver
+{
+   /***
+    *** TNL Pipeline
+    ***/
+
+   void (*RunPipeline)(GLcontext *ctx);
+   /* Replaces PipelineStart/PipelineFinish -- intended to allow
+    * drivers to wrap _tnl_run_pipeline() with code to validate state
+    * and grab/release hardware locks.  
+    */
 
-typedef void (*texgen_func)( struct vertex_buffer *VB,
-                            GLuint textureSet);
+   void (*NotifyMaterialChange)(GLcontext *ctx);
+   /* Alert tnl-aware drivers of changes to material.
+    */
 
+   void (*NotifyInputChanges)(GLcontext *ctx, GLuint bitmask);
+   /* Alert tnl-aware drivers of changes to size and stride of input
+    * arrays.
+    */
 
+   /***
+    *** Rendering -- These functions called only from t_vb_render.c
+    ***/
+   struct
+   {
+      void (*Start)(GLcontext *ctx);
+      void (*Finish)(GLcontext *ctx);
+      /* Called before and after all rendering operations, including DrawPixels,
+       * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
+       * These are a suitable place for grabbing/releasing hardware locks.
+       */
+
+      void (*PrimitiveNotify)(GLcontext *ctx, GLenum mode);
+      /* Called between RenderStart() and RenderFinish() to indicate the
+       * type of primitive we're about to draw.  Mode will be one of the
+       * modes accepted by glBegin().
+       */
+
+      tnl_interp_func Interp;
+      /* The interp function is called by the clipping routines when we need
+       * to generate an interpolated vertex.  All pertinant vertex ancilliary
+       * data should be computed by interpolating between the 'in' and 'out'
+       * vertices.
+       */
+
+      tnl_copy_pv_func CopyPV;
+      /* The copy function is used to make a copy of a vertex.  All pertinant
+       * vertex attributes should be copied.
+       */
+
+      void (*ClippedPolygon)( GLcontext *ctx, const GLuint *elts, GLuint n );
+      /* Render a polygon with <n> vertices whose indexes are in the <elts>
+       * array.
+       */
+
+      void (*ClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 );
+      /* Render a line between the two vertices given by indexes v0 and v1. */
+
+      tnl_points_func           Points; /* must now respect vb->elts */
+      tnl_line_func             Line;
+      tnl_triangle_func         Triangle;
+      tnl_quad_func             Quad;
+      /* These functions are called in order to render points, lines,
+       * triangles and quads.  These are only called via the T&L module.
+       */
+
+      tnl_render_func          *PrimTabVerts;
+      tnl_render_func          *PrimTabElts;
+      /* Render whole unclipped primitives (points, lines, linestrips,
+       * lineloops, etc).  The tables are indexed by the GL enum of the
+       * primitive to be rendered.  RenderTabVerts is used for non-indexed
+       * arrays of vertices.  RenderTabElts is used for indexed arrays of
+       * vertices.
+       */
+
+      void (*ResetLineStipple)( GLcontext *ctx );
+      /* Reset the hardware's line stipple counter.
+       */
+
+      tnl_setup_func BuildVertices;
+      /* This function is called whenever new vertices are required for
+       * rendering.  The vertices in question are those n such that start
+       * <= n < end.  The new_inputs parameter indicates those fields of
+       * the vertex which need to be updated, if only a partial repair of
+       * the vertex is required.
+       *
+       * This function is called only from _tnl_render_stage in tnl/t_render.c.
+       */
+      
+
+      GLboolean (*Multipass)( GLcontext *ctx, GLuint passno );
+      /* Driver may request additional render passes by returning GL_TRUE
+       * when this function is called.  This function will be called
+       * after the first pass, and passes will be made until the function
+       * returns GL_FALSE.  If no function is registered, only one pass
+       * is made.
+       *
+       * This function will be first invoked with passno == 1.
+       */
+   } Render;
+};
 
-typedef struct tnl_context {   
 
-   GLuint _ArrayFlag[VB_SIZE]; /* crock */
-   GLuint _ArrayFlags;
-   GLuint _ArraySummary;       /* Like flags, but no size information */
-   GLuint _ArrayNewState;      /* Tracks which arrays have been changed. */
-   GLuint _ArrayTex3Flag;
-   GLuint _ArrayTex4Flag;
+#define DECLARE_RENDERINPUTS(name) BITSET64_DECLARE(name, _TNL_ATTRIB_MAX)
+#define RENDERINPUTS_COPY BITSET64_COPY
+#define RENDERINPUTS_EQUAL BITSET64_EQUAL
+#define RENDERINPUTS_ZERO BITSET64_ZERO
+#define RENDERINPUTS_ONES BITSET64_ONES
+#define RENDERINPUTS_TEST BITSET64_TEST
+#define RENDERINPUTS_SET BITSET64_SET
+#define RENDERINPUTS_CLEAR BITSET64_CLEAR
+#define RENDERINPUTS_TEST_RANGE BITSET64_TEST_RANGE
+#define RENDERINPUTS_SET_RANGE BITSET64_SET_RANGE
+#define RENDERINPUTS_CLEAR_RANGE BITSET64_CLEAR_RANGE
 
 
-   /* Pipeline stages - shared between the two pipelines,
-    * which live in CVA.
+/**
+ * Context state for T&L context.
+ */
+typedef struct
+{
+   /* Driver interface.
     */
-   struct gl_pipeline_stage PipelineStage[MAX_PIPELINE_STAGES];
-   GLuint NrPipelineStages;
+   struct tnl_device_driver Driver;
 
-   /* Per-texunit derived state.
+   /* Pipeline
     */
-   GLuint _TexgenSize[MAX_TEXTURE_UNITS];
-   GLuint _TexgenHoles[MAX_TEXTURE_UNITS];
-   texgen_func *_TexgenFunc[MAX_TEXTURE_UNITS];
+   struct tnl_pipeline pipeline;
+   struct vertex_buffer vb;
 
-
-   /* Display list extensions
+   /* Clipspace/ndc/window vertex managment:
     */
-   GLuint opcode_vertex_cassette;
+   struct tnl_clipspace clipspace;
 
-   /* Cva
+   /* Probably need a better configuration mechanism:
     */
-   struct gl_cva CVA;
-   GLboolean CompileCVAFlag;
-
-   clip_poly_func *_poly_clip_tab;
-   clip_line_func *_line_clip_tab;
-   clip_interp_func _ClipInterpFunc; /* Clip interpolation function */
-   normal_func *_NormalTransform; 
-   shade_func *_shade_func_tab;   /* Current shading function table */
-
-   GLenum _CurrentPrimitive;         /* Prim or GL_POLYGON+1 */
-   GLuint _CurrentTex3Flag;
-   GLuint _CurrentTex4Flag;
+   GLboolean NeedNdcCoords;
+   GLboolean AllowVertexFog;
+   GLboolean AllowPixelFog;
+   GLboolean _DoVertexFog;  /* eval fog function at each vertex? */
 
-   GLboolean _ReplayHardBeginEnd; /* Display list execution of rect, etc */
+   DECLARE_RENDERINPUTS(render_inputs_bitset);
 
-   GLuint _RenderFlags;              /* Active inputs to render stage */
+   GLvector4f tmp_inputs[VERT_ATTRIB_MAX];
 
-   /* Cache of unused immediate structs */
-   struct immediate *freed_im_queue;
-   GLuint nr_im_queued;
-
-   struct gl_fallback_arrays Fallback; 
-
-   GLvertexformat vtxfmt;
+   /* Temp storage for t_draw.c: 
+    */
+   GLubyte *block[VERT_ATTRIB_MAX];
+   GLuint nr_blocks;
 
 } TNLcontext;
 
 
 
-#define TNL_CONTEXT(ctx) ((TNLcontext *)(ctx->swtnl_context))
-#define TNL_CURRENT_IM(ctx) ((struct immediate *)(ctx->swtnl_im))
-#define TNL_VB(ctx) ((struct vertex_buffer *)(ctx->swtnl_vb))
+#define TNL_CONTEXT(ctx) ((TNLcontext *)((ctx)->swtnl_context))
 
-extern GLboolean _tnl_flush_vertices( GLcontext *ctx, GLuint flush_flags );
 
-
-extern void
-_tnl_MakeCurrent( GLcontext *ctx,
-                 GLframebuffer *drawBuffer,
-                 GLframebuffer *readBuffer );
+#define TYPE_IDX(t) ((t) & 0xf)
+#define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1      /* 0xa + 1 */
 
 
 extern void
-_tnl_LightingSpaceChange( GLcontext *ctx );
+tnl_clip_prepare(GLcontext *ctx);
 
-/*
- * Macros for fetching current input buffer.
- */
-#ifdef THREADS
-#define GET_IMMEDIATE  struct immediate *IM = TNL_CURRENT_IM(((GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())))
-#define SET_IMMEDIATE(ctx, im)  ctx->swtnl_im = (void *)im
-#else
-extern struct immediate *_tnl_CurrentInput;
-#define GET_IMMEDIATE struct immediate *IM = _tnl_CurrentInput
-#define SET_IMMEDIATE(ctx, im)                 \
-do {                                           \
-   ctx->swtnl_im = (void *)im;                 \
-   _tnl_CurrentInput = im;                     \
-} while (0)
-#endif
 
 #endif