Allow different max texture sizes for 1/2D, 3D and cube maps.
[mesa.git] / src / mesa / tnl / t_context.h
index 720db4b7f9d7fcf224213a412ce801cdc79bb3d1..226b877d8525d705b6edf6fd996ce05478ab2375 100644 (file)
@@ -1,11 +1,10 @@
-
-/* $Id: t_context.h,v 1.5 2000/11/24 15:22:00 keithw Exp $ */
+/* $Id: t_context.h,v 1.28 2001/06/04 16:09:28 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.5
  *
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2001  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"),
@@ -23,6 +22,9 @@
  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Author:
+ *    Keith Whitwell <keithw@valinux.com>
  */
 
 #ifndef _T_CONTEXT_H
 #include "math/m_vector.h"
 #include "math/m_xform.h"
 
-#include "t_trans_elt.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.
+/* Numbers for sizing immediate structs.
  */
-#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 IMM_MAX_COPIED_VERTS  3
+#define IMM_MAXDATA          (216 + IMM_MAX_COPIED_VERTS)
+#define IMM_SIZE             (IMM_MAXDATA + MAX_CLIPPED_VERTICES)
 
 
-#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.
+/* Values for IM->BeginState
  */
-#define CULL_MASK_ACTIVE  0x1
-#define COMPACTED_NORMALS 0x2
-#define CLIP_MASK_ACTIVE  0x4
+#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 */
 
-/* Flags for selecting a shading function.  The first two bits are
- * shared with the cull mode (ie. cull_mask_active and
- * compacted_normals.)
+
+/* Flags to be added to the primitive enum in VB->Primitive.
  */
-#define SHADE_TWOSIDE           0x4
+#define PRIM_MODE_MASK  0xff    /* Extract the actual primitive */
+#define PRIM_BEGIN      0x100  /* The prim starts here (not wrapped) */
+#define PRIM_END        0x200  /* The prim ends in this VB (does not wrap) */
+#define PRIM_PARITY     0x400  /* The prim wrapped on an odd number of verts */
+#define PRIM_LAST       0x800   /* No more prims in the VB */
 
 
-/* KW: Flags that describe the current vertex state, and the contents
- * of a vertex in a vertex-cassette.
+/* Flags that describe the inputs and outputs of pipeline stages, and
+ * the contents of 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[]).
+ * 5 spare flags, rearrangement of eval flags can secure at least 3
+ * more.
+ */
+#define VERT_OBJ             _NEW_ARRAY_VERTEX
+#define VERT_RGBA            _NEW_ARRAY_COLOR
+#define VERT_NORM            _NEW_ARRAY_NORMAL
+#define VERT_INDEX           _NEW_ARRAY_INDEX
+#define VERT_EDGE            _NEW_ARRAY_EDGEFLAG
+#define VERT_SPEC_RGB        _NEW_ARRAY_SECONDARYCOLOR
+#define VERT_FOG_COORD       _NEW_ARRAY_FOGCOORD
+#define VERT_TEX0            _NEW_ARRAY_TEXCOORD_0
+#define VERT_TEX1            _NEW_ARRAY_TEXCOORD_1
+#define VERT_TEX2            _NEW_ARRAY_TEXCOORD_2
+#define VERT_TEX3            _NEW_ARRAY_TEXCOORD_3
+#define VERT_TEX4            _NEW_ARRAY_TEXCOORD_4
+#define VERT_TEX5            _NEW_ARRAY_TEXCOORD_5
+#define VERT_TEX6            _NEW_ARRAY_TEXCOORD_6
+#define VERT_TEX7            _NEW_ARRAY_TEXCOORD_7
+#define VERT_EVAL_C1         0x8000     /* imm only */
+#define VERT_EVAL_C2         0x10000    /* imm only */
+#define VERT_EVAL_P1         0x20000    /* imm only */
+#define VERT_EVAL_P2         0x40000    /* imm only */
+#define VERT_OBJ_3           0x80000    /* imm only */
+#define VERT_OBJ_4           0x100000   /* imm only */
+#define VERT_MATERIAL        0x200000   /* imm only, but tested in vb code */
+#define VERT_ELT             0x400000   /* imm only */
+#define VERT_BEGIN           0x800000   /* imm only, but tested in vb code */
+#define VERT_END             0x1000000  /* imm only, but tested in vb code */
+#define VERT_END_VB          0x2000000  /* imm only, but tested in vb code */
+#define VERT_POINT_SIZE      0x4000000  /* vb only, could reuse a bit */
+#define VERT_EYE             VERT_BEGIN /* vb only, reuse imm bit */
+#define VERT_CLIP            VERT_END   /* vb only, reuse imm bit*/
+
+
+/* Flags for IM->TexCoordSize.  Enough flags for 16 units.
  */
+#define TEX_0_SIZE_3          0x1
+#define TEX_0_SIZE_4          0x1001
+#define TEX_SIZE_3(unit)      (TEX_0_SIZE_3<<unit)
+#define TEX_SIZE_4(unit)      (TEX_0_SIZE_4<<unit)
 
-#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_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 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_23       (VERT_OBJ_3|VERT_OBJ)
 #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_TEX4 |                \
                             VERT_TEX5 |                \
                             VERT_TEX6 |                \
-                            VERT_TEX7 |                \
-                            VERT_TEX8 |                \
-                            VERT_TEX9 |                \
-                            VERT_TEX10 |       \
-                            VERT_TEX11)
+                            VERT_TEX7)
+
+#define VERT_FIXUP        (VERT_TEX_ANY |      \
+                           VERT_RGBA |         \
+                           VERT_SPEC_RGB |     \
+                           VERT_FOG_COORD |    \
+                          VERT_INDEX |         \
+                           VERT_EDGE |         \
+                           VERT_NORM)
 
-#define VERT_FIXUP         (VERT_TEX_ANY |     \
+#define VERT_CURRENT_DATA  (VERT_FIXUP |       \
+                           VERT_MATERIAL)
+
+#define VERT_DATA          (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;
-
-/**
- ** Vertex buffer/array structures
- **/
-
-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;
-};
-
-struct vertex_array_pointers
-{
-   GLvector4f  *Obj;
-   GLvector3f  *Normal;
-   GLvector4ub *Color;
-   GLvector1ui *Index;
-   GLvector1ub *EdgeFlag;
-   GLvector4f  *TexCoord[MAX_TEXTURE_UNITS];
-   GLvector1ui *Elt;
-   GLvector4ub *SecondaryColor;
-   GLvector1f *FogCoord;
-};
-
-/* Values for VB->Type */
-enum {
-   VB_IMMEDIATE,
-   VB_CVA_PRECALC
-};
-
+                            VERT_NORM |                \
+                           VERT_OBJ |  \
+                            VERT_MATERIAL |    \
+                            VERT_ELT |         \
+                           VERT_EVAL_ANY)
 
-/* 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.
+ * end, and can represent multiple begin/end pairs.  Can be used to
+ * losslessly encode this information in display lists.
  */
 struct immediate
 {
-   struct immediate *next;     /* for cache of free IM's */
+   struct __GLcontextRec *backref;
    GLuint id, ref_count;
 
    /* This must be saved when immediates are shared in display lists.
     */
-   GLuint Start, Count;
+   GLuint CopyStart, Start, Count;
    GLuint LastData;            /* count or count+1 */
    GLuint AndFlag, OrFlag;
-   GLuint Tex3Flag, Tex4Flag;  /* keep track of texcoord sizes */
+   GLuint TexSize;             /* keep track of texcoord sizes */
    GLuint BeginState, SavedBeginState;
-   GLuint LastPrimitive;       
+   GLuint LastPrimitive;
 
-   GLuint ArrayAndFlags;       /* precalc'ed for glArrayElt */
-   GLuint ArrayIncr;
+   GLuint ArrayEltFlags;       /* precalc'ed for glArrayElt */
+   GLuint ArrayEltIncr;
    GLuint ArrayEltFlush;
+
+#define FLUSH_ELT_EAGER 0x1
+#define FLUSH_ELT_LAZY 0x2
    GLuint FlushElt;
 
-   GLuint  Primitive[VB_SIZE]; /* GLubyte would do... */
-   GLuint  NextPrimitive[VB_SIZE];
+   GLuint MaxTextureUnits;     /* precalc'ed for glMultiTexCoordARB */
 
-   /* allocate storage for these on demand:
+   /* Temporary values created when vertices are copied into the
+    * first 3 slots of the struct:
     */
-   struct  gl_material (*Material)[2];
-   GLuint  *MaterialMask;
+   GLuint CopyOrFlag;
+   GLuint CopyAndFlag;
+   GLuint CopyTexSize;
 
-   GLfloat (*TexCoordPtr[MAX_TEXTURE_UNITS])[4];
 
-   struct vertex_arrays v;
+   /* allocate storage for these on demand:
+    */
+   struct gl_material (*Material)[2];
+   GLuint *MaterialMask;
+   GLuint LastMaterial;
+   GLuint MaterialOrMask;
+   GLuint MaterialAndMask;
 
-   struct __GLcontextRec *backref;             
+   GLfloat (*TexCoord[MAX_TEXTURE_UNITS])[4];
 
-   /* Normal lengths, zero if not available.
-    */
-   GLfloat   *NormalLengths;
-   GLuint     LastCalcedLength;
+   GLuint  Primitive[IMM_SIZE];            /* BEGIN/END */
+   GLuint  PrimitiveLength[IMM_SIZE]; /* BEGIN/END */
+   GLuint  Flag[IMM_SIZE];         /* VERT_* flags */
+   GLfloat Color[IMM_SIZE][4];
+   GLfloat Obj[IMM_SIZE][4];
+   GLfloat Normal[IMM_SIZE][3];
+   GLfloat TexCoord0[IMM_SIZE][4];  /* just VERT_TEX0 */
+   GLuint  Elt[IMM_SIZE];
+   GLubyte EdgeFlag[IMM_SIZE];
+   GLuint  Index[IMM_SIZE];
+   GLfloat SecondaryColor[IMM_SIZE][4];
+   GLfloat FogCoord[IMM_SIZE];
+};
 
-   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];
+
+struct vertex_arrays
+{
+   GLvector4f  Obj;
+   GLvector3f  Normal;
+   struct gl_client_array Color;
+   struct gl_client_array SecondaryColor;
+   GLvector1ui Index;
+   GLvector1ub EdgeFlag;
+   GLvector4f  TexCoord[MAX_TEXTURE_UNITS];
+   GLvector1ui Elt;
+   GLvector1f  FogCoord;
 };
 
 
-/* Not so big on storage these days, although still has pointers to
- * arrays used for temporary results.
+typedef struct gl_material GLmaterial;
+
+/* Contains the current state of a running pipeline.
  */
 typedef struct vertex_buffer
 {
-   /* Backpointers.
-    */
-   struct __GLcontextRec *ctx;
-   struct tnl_context *tnlctx;
-
-   /* Driver_data is allocated in Driver.RegisterVB(), if required.
+   /* Constant over life of the vertex_buffer.
     */
-   void *driver_data;
+   GLuint Size;
 
-   /* List of operations to process vertices in current state.
+   /* Constant over the pipeline.
     */
-   struct gl_pipeline *pipeline;
+   GLuint     Count;                           /* for everything except Elts */
+   GLuint     FirstClipped;                    /* temp verts for clipping */
+   GLuint     FirstPrimitive;                  /* usually zero */
 
-   /* Temporary storage used by immediate mode functions and various
-    * operations in the pipeline.
+   /* Pointers to current data.
     */
-   struct immediate *IM;       
-   struct vertex_array_pointers store; 
-
-   /* Where to find outstanding untransformed vertices.
+   GLuint      *Elts;                          /* VERT_ELT */
+   GLvector4f  *ObjPtr;                                /* VERT_OBJ */
+   GLvector4f  *EyePtr;                                /* VERT_EYE */
+   GLvector4f  *ClipPtr;                       /* VERT_CLIP */
+   GLvector4f  *ProjectedClipPtr;               /* VERT_CLIP (2) */
+   GLubyte     ClipOrMask;                     /* VERT_CLIP (3) */
+   GLubyte     *ClipMask;                      /* VERT_CLIP (4) */
+   GLvector3f  *NormalPtr;                     /* VERT_NORM */
+   GLboolean   *EdgeFlag;                      /* VERT_EDGE */
+   GLvector4f  *TexCoordPtr[MAX_TEXTURE_UNITS];        /* VERT_TEX_0..n */
+   GLvector1ui *IndexPtr[2];                   /* VERT_INDEX */
+   struct gl_client_array *ColorPtr[2];                        /* VERT_RGBA */
+   struct gl_client_array *SecondaryColorPtr[2];         /* VERT_SPEC_RGB */
+   GLvector1f  *FogCoordPtr;                   /* VERT_FOG_COORD */
+   GLvector1f  *PointSizePtr;                  /* VERT_POINT_SIZE */
+   GLmaterial (*Material)[2];                   /* VERT_MATERIAL, optional */
+   GLuint      *MaterialMask;                  /* VERT_MATERIAL, optional */
+   GLuint      *Flag;                          /* VERT_* flags, optional */
+   GLuint      *Primitive;                     /* GL_(mode)|PRIM_* flags */
+   GLuint      *PrimitiveLength;               /* integers */
+
+
+   GLuint importable_data;
+   void *import_source;
+   void (*import_data)( GLcontext *ctx, GLuint flags, GLuint vecflags );
+   /* Callback to the provider of the untransformed input for the
+    * render stage (or other stages) to call if they need to write into
+    * write-protected arrays, or fixup the stride on input arrays.
+    *
+    * This is currently only necessary for client arrays that make it
+    * as far down the pipeline as the render stage.
     */
-   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.
+   GLuint LastClipped;
+   /* Private data from _tnl_render_stage that has no business being
+    * in this struct.
     */
-   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;
+} TNLvertexbuffer;
 
-   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.
-    */
-   GLvector4f Eye;
-   GLvector4f Clip;
-   GLvector4f Win;
-   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;
+/* Describes an individual operation on the pipeline.
+ */
+struct gl_pipeline_stage {
+   const char *name;
+   GLuint check_state;         /* All state referenced in check() --
+                                * When is the pipeline_stage struct
+                                * itself invalidated?  Must be
+                                * constant.
+                                */
 
-   /* Internal values.  Where these point depends on whether
-    * there were any identity matrices defined as transformations
-    * in the pipeline.
+   /* Usually constant or set by the 'check' callback:
     */
-   GLvector4f *EyePtr;
-   GLvector4f *ClipPtr;
-   GLvector4f *Unprojected;
-   GLvector4f *Projected;
-   GLvector4f *CurrentTexCoord;
-   GLuint     *Indirect;           /* For eval rescue and cva render */
+   GLuint run_state;           /* All state referenced in run() --
+                                * When is the cached output of the
+                                * stage invalidated?
+                                */
 
-   /* Currently active colors
-    */
-   GLvector4ub *Color[2];
-   GLvector1ui *Index[2];
-   GLvector4ub *SecondaryColor[2];
+   GLboolean active;           /* True if runnable in current state */
+   GLuint inputs;              /* VERT_* inputs to the stage */
+   GLuint outputs;             /* VERT_* outputs of the stage */
 
-   /* Storage for colors which have been lit but not yet fogged.
-    * Required for CVA, just point into store for normal VB's.
+   /* Set in _tnl_run_pipeline():
     */
-   GLvector4ub *LitColor[2];
-   GLvector1ui *LitIndex[2];
-   GLvector4ub *LitSecondary[2];
+   GLuint changed_inputs;      /* Generated value -- inputs to the
+                                * stage that have changed since last
+                                * call to 'run'.
+                                */
 
-   /* Temporary values used in texgen.
+   /* Private data for the pipeline stage:
     */
-   GLfloat (*tmp_f)[3];
-   GLfloat *tmp_m;
+   void *privatePtr;
 
-   /* Temporary values used in eval.
+   /* Free private data.  May not be null.
     */
-   GLuint *EvaluatedFlags;
+   void (*destroy)( struct gl_pipeline_stage * );
 
-   /* Not used for cva:
+   /* Called from _tnl_validate_pipeline().  Must update all fields in
+    * the pipeline_stage struct for the current state.
     */
-   GLubyte *NormCullStart;
-   GLubyte *CullMask;          /* Results of vertex culling */
-   GLubyte *NormCullMask;       /* Compressed onto shared normals */
-
-   GLubyte ClipOrMask;         /* bitwise-OR of all ClipMask[] values */
-   GLubyte ClipAndMask;                /* bitwise-AND of all ClipMask[] values */
-   GLubyte CullFlag[2];
-   GLubyte CullMode;           /* see flags below */
-
-   GLuint CopyCount;           /* max 3 vertices to copy after transform */
-   GLuint Copy[3];
-   GLfloat CopyProj[3][4];     /* temporary store for projected clip coords */
+   void (*check)( GLcontext *ctx, struct gl_pipeline_stage * );
 
-   /* Hooks for module private data
+   /* 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
     */
-   void *swsetup_vb;
+   GLboolean (*run)( GLcontext *ctx, struct gl_pipeline_stage * );
+};
 
-} TNLvertexbuffer;
 
+struct gl_pipeline {
+   GLuint build_state_trigger;   /* state changes which require build */
+   GLuint build_state_changes;    /* state changes since last build */
+   GLuint run_state_changes;     /* state changes since last run */
+   GLuint run_input_changes;     /* VERT_* changes since last run */
+   GLuint inputs;                /* VERT_* inputs to pipeline */
+   struct gl_pipeline_stage stages[MAX_PIPELINE_STAGES+1];
+   GLuint nr_stages;
+};
 
-typedef void (*shade_func)( struct vertex_buffer *VB );
 
-typedef void (*clip_interp_func)( struct vertex_buffer *VB, GLuint dst,
-                                  GLfloat t, GLuint in, GLuint out );
+struct tnl_eval_store {
+   GLuint EvalMap1Flags;
+   GLuint EvalMap2Flags;
+   GLuint EvalNewState;
+   struct immediate *im;       /* used for temporary data */
+};
 
-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 (*points_func)( GLcontext *ctx, GLuint first, GLuint last );
+typedef void (*line_func)( GLcontext *ctx, GLuint v1, GLuint v2 );
+typedef void (*triangle_func)( GLcontext *ctx,
+                               GLuint v1, GLuint v2, GLuint v3 );
+typedef void (*quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
+                           GLuint v3, GLuint v4 );
+typedef void (*render_func)( GLcontext *ctx, GLuint start, GLuint count,
+                            GLuint flags );
+typedef void (*interp_func)( GLcontext *ctx,
+                            GLfloat t, GLuint dst, GLuint out, GLuint in,
+                            GLboolean force_boundary );
+typedef void (*copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src );
+
+
+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.  
+    */
 
+   /***
+    *** Rendering
+    ***/
 
-#define MAX_PIPELINE_STAGES     30
+   void (*RenderStart)(GLcontext *ctx);
+   void (*RenderFinish)(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.
+    */
 
-#define PIPE_IMMEDIATE          0x1
-#define PIPE_PRECALC            0x2
+   void (*RenderPrimitive)(GLcontext *ctx, GLenum mode);
+   /* Called between RednerStart() and RenderFinish() to indicate the
+    * type of primitive we're about to draw.  Mode will be one of the
+    * modes accepted by glBegin().
+    */
 
-#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
+   interp_func RenderInterp;
+   /* 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.
+    */
 
+   copy_pv_func RenderCopyPV;
+   /* The copy function is used to make a copy of a vertex.  All pertinant
+    * vertex attributes should be copied.
+    */
 
+   void (*RenderClippedPolygon)( GLcontext *ctx, const GLuint *elts, GLuint n );
+   /* Render a polygon with <n> vertices whose indexes are in the <elts>
+    * array.
+    */
 
-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 );
-};
+   void (*RenderClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 );
+   /* Render a line between the two vertices given by indexes v0 and v1. */
 
+   points_func           PointsFunc; /* must now respect vb->elts */
+   line_func             LineFunc;
+   triangle_func         TriangleFunc;
+   quad_func             QuadFunc;
+   /* These functions are called in order to render points, lines,
+    * triangles and quads.  These are only called via the T&L module.
+    */
 
-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;
-   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];
-};
+   render_func          *RenderTabVerts;
+   render_func          *RenderTabElts;
+   /* 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.
+    */
 
+   void (*BuildProjectedVertices)( GLcontext *ctx,
+                                  GLuint start, GLuint end,
+                                  GLuint new_inputs);
+   /* 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.
+    */
 
-/* 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;
-};
 
-/* 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;
+   GLboolean (*MultipassFunc)( 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.
+    */
 };
 
 
+typedef struct {
 
-typedef void (*texgen_func)( struct vertex_buffer *VB,
-                            GLuint textureSet);
-
-
-
-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;
-
-
-   /* Pipeline stages - shared between the two pipelines,
-    * which live in CVA.
+   /* Driver interface.
     */
-   struct gl_pipeline_stage PipelineStage[MAX_PIPELINE_STAGES];
-   GLuint NrPipelineStages;
+   struct tnl_device_driver Driver;
 
-   /* Per-texunit derived state.
+   /* Track whether the module is active.
     */
-   GLuint _TexgenSize[MAX_TEXTURE_UNITS];
-   GLuint _TexgenHoles[MAX_TEXTURE_UNITS];
-   texgen_func *_TexgenFunc[MAX_TEXTURE_UNITS];
-
+   GLboolean bound_exec;
 
    /* Display list extensions
     */
    GLuint opcode_vertex_cassette;
 
-   /* Cva
+   /* Pipeline
     */
-   struct gl_cva CVA;
-   GLboolean CompileCVAFlag;
+   struct gl_pipeline pipeline;
+   struct vertex_buffer vb;
 
-   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 */
+   /* GLvectors for binding to vb:
+    */
+   struct vertex_arrays imm_inputs;
+   struct vertex_arrays array_inputs;
+   GLuint *tmp_primitive;
+   GLuint *tmp_primitive_length;
+
+   /* Set when executing an internally generated begin/end object.  If
+    * such an object is encountered in a display list, it will be
+    * replayed only if the list is outside any existing begin/end
+    * objects.  
+    */
+   GLboolean ReplayHardBeginEnd;
 
-   GLenum _CurrentPrimitive;         /* Prim or GL_POLYGON+1 */
-   GLuint _CurrentTex3Flag;
-   GLuint _CurrentTex4Flag;
+   /* Note which vertices need copying over succesive immediates.
+    * Will add save versions to precompute vertex copying where
+    * possible.
+    */
+   struct immediate *ExecCopySource;
+   GLuint ExecCopyCount;
+   GLuint ExecCopyElts[IMM_MAX_COPIED_VERTS];
+   GLuint ExecCopyTexSize;
+   GLuint ExecParity;
 
-   GLboolean _ReplayHardBeginEnd; /* Display list execution of rect, etc */
+   GLuint DlistPrimitive;
+   GLuint DlistPrimitiveLength;
+   GLuint DlistLastPrimitive;
 
-   GLuint _RenderFlags;              /* Active inputs to render stage */
+   /* Cache a single free immediate (refcount == 0)
+    */
+   struct immediate *freed_immediate;   
 
-   /* Cache of unused immediate structs */
-   struct immediate *freed_im_queue;
-   GLuint nr_im_queued;
+   /* Probably need a better configuration mechanism:
+    */
+   GLboolean NeedProjCoords;
+   GLboolean LoopbackDListCassettes;
 
-   struct gl_fallback_arrays Fallback; 
+   /* Derived state and storage for _tnl_eval_vb:
+    */
+   struct tnl_eval_store eval;
 
+   /* Functions to be plugged into dispatch when tnl is active.
+    */
    GLvertexformat vtxfmt;
 
 } TNLcontext;
@@ -596,20 +540,16 @@ typedef struct tnl_context {
 
 #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))
 
-extern GLboolean _tnl_flush_vertices( GLcontext *ctx, GLuint flush_flags );
 
+#define TYPE_IDX(t) ((t) & 0xf)
+#define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1      /* 0xa + 1 */
 
-extern void
-_tnl_MakeCurrent( GLcontext *ctx,
-                 GLframebuffer *drawBuffer,
-                 GLframebuffer *readBuffer );
+extern void _tnl_MakeCurrent( GLcontext *ctx,
+                             GLframebuffer *drawBuffer,
+                             GLframebuffer *readBuffer );
 
 
-extern void
-_tnl_LightingSpaceChange( GLcontext *ctx );
-
 /*
  * Macros for fetching current input buffer.
  */
@@ -626,4 +566,5 @@ do {                                                \
 } while (0)
 #endif
 
+
 #endif