mesa: don't assign numbers to vertex attrib enums manually
[mesa.git] / src / mesa / tnl / t_context.h
index 1293db3bf3f24be6162dcddcafbf3da130a81917..67a87f26af552061441e00375b171365504a0c35 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * mesa 3-D graphics library
- * Version:  5.1
  *
- * Copyright (C) 1999-2003  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"),
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * 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.
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
  */
 
 /**
  * stages to the vertex_buffer TNLcontext::vb, where the vertex data
  * is stored. The last stage in the pipeline is the rasterizer.
  *
- * The initial vertex_buffer data may either come from an ::immediate
- * structure or client vertex_arrays or display lists:
- *
- *
- * - The ::immediate structure records all the GL commands issued between
- * glBegin and glEnd.  \n
- * The structure accumulates data, until it is either full or it is
- * flushed (usually by a state change). Before starting then the pipeline,
- * the collected vertex data in ::immediate has to be pushed into
- * TNLcontext::vb.
- * This happens in ::_tnl_vb_bind_immediate. The pipeline is then run by
- * calling tnl_device_driver::RunPipeline = ::_tnl_run_pipeline, which
- * is stored in TNLcontext::Driver.   \n
- * An ::immediate does (for performance reasons) usually not finish with a
- * glEnd, and hence it also does not need to start with a glBegin.
- * This means that the last vertices of one ::immediate may need to be
- * saved for the next one.
- *
- *
- * - NOT SURE ABOUT THIS: The vertex_arrays structure is used to handle
- * glDrawArrays etc.  \n
- * Here, the data of the vertex_arrays is copied by ::_tnl_vb_bind_arrays
- * into TNLcontext::vb, so that the pipeline can be started.
  */
 
 
 #ifndef _T_CONTEXT_H
 #define _T_CONTEXT_H
 
-#include "glheader.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
 
-#include "math/m_matrix.h"
 #include "math/m_vector.h"
-#include "math/m_xform.h"
 
+#include "vbo/vbo.h"
 
 #define MAX_PIPELINE_STAGES     30
 
-
 /*
  * 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.
  */
-/* Note: These are currently being used to define both inputs and
- * outputs from the tnl pipeline.  A better solution (which would also
- * releive the congestion to slightly prolong the life of the bitmask
- * below) is to have the fixed function pipeline populate a set of
- * arrays named after those produced by the vertex program stage, and
- * have the rest the mesa backend work on those.
- */
-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_SIX = 6,
-       _TNL_ATTRIB_SEVEN = 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_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, 
-       _TNL_ATTRIB_INDEX = 28,        
-       _TNL_ATTRIB_EDGEFLAG = 29,     
-       _TNL_ATTRIB_POINTSIZE = 30,
-       _TNL_ATTRIB_MAX = 31
-} ;
-
-/* Will probably have to revise this scheme fairly shortly, eg. by
- * compacting all the MAT flags down to one bit, or by using two
- * dwords to store the flags.
- */
-#define _TNL_BIT_POS                 (1<<0)
-#define _TNL_BIT_WEIGHT              (1<<1)
-#define _TNL_BIT_NORMAL              (1<<2)
-#define _TNL_BIT_COLOR0              (1<<3)
-#define _TNL_BIT_COLOR1              (1<<4)
-#define _TNL_BIT_FOG                 (1<<5)
-#define _TNL_BIT_SIX                 (1<<6)
-#define _TNL_BIT_SEVEN               (1<<7)
-#define _TNL_BIT_TEX0                (1<<8)
-#define _TNL_BIT_TEX1                (1<<9)
-#define _TNL_BIT_TEX2                (1<<10)
-#define _TNL_BIT_TEX3                (1<<11)
-#define _TNL_BIT_TEX4                (1<<12)
-#define _TNL_BIT_TEX5                (1<<13)
-#define _TNL_BIT_TEX6                (1<<14)
-#define _TNL_BIT_TEX7                (1<<15)
-#define _TNL_BIT_MAT_FRONT_AMBIENT   (1<<16)
-#define _TNL_BIT_MAT_BACK_AMBIENT    (1<<17)
-#define _TNL_BIT_MAT_FRONT_DIFFUSE   (1<<18)
-#define _TNL_BIT_MAT_BACK_DIFFUSE    (1<<19)
-#define _TNL_BIT_MAT_FRONT_SPECULAR  (1<<20)
-#define _TNL_BIT_MAT_BACK_SPECULAR   (1<<21)
-#define _TNL_BIT_MAT_FRONT_EMISSION  (1<<22)
-#define _TNL_BIT_MAT_BACK_EMISSION   (1<<23)
-#define _TNL_BIT_MAT_FRONT_SHININESS (1<<24)
-#define _TNL_BIT_MAT_BACK_SHININESS  (1<<25)
-#define _TNL_BIT_MAT_FRONT_INDEXES   (1<<26)
-#define _TNL_BIT_MAT_BACK_INDEXES    (1<<27)
-#define _TNL_BIT_INDEX               (1<<28)
-#define _TNL_BIT_EDGEFLAG            (1<<29)
-#define _TNL_BIT_POINTSIZE           (1<<30)
-
-#define _TNL_BIT_TEX(u)  (1 << (_TNL_ATTRIB_TEX0 + (u)))
-
-
-
-#define _TNL_BITS_MAT_ANY  (_TNL_BIT_MAT_FRONT_AMBIENT   |     \
-                           _TNL_BIT_MAT_BACK_AMBIENT    |      \
-                           _TNL_BIT_MAT_FRONT_DIFFUSE   |      \
-                           _TNL_BIT_MAT_BACK_DIFFUSE    |      \
-                           _TNL_BIT_MAT_FRONT_SPECULAR  |      \
-                           _TNL_BIT_MAT_BACK_SPECULAR   |      \
-                           _TNL_BIT_MAT_FRONT_EMISSION  |      \
-                           _TNL_BIT_MAT_BACK_EMISSION   |      \
-                           _TNL_BIT_MAT_FRONT_SHININESS |      \
-                           _TNL_BIT_MAT_BACK_SHININESS  |      \
-                           _TNL_BIT_MAT_FRONT_INDEXES   |      \
-                           _TNL_BIT_MAT_BACK_INDEXES)
-
-
-#define _TNL_BITS_TEX_ANY  (_TNL_BIT_TEX0 |    \
-                            _TNL_BIT_TEX1 |    \
-                            _TNL_BIT_TEX2 |    \
-                            _TNL_BIT_TEX3 |    \
-                            _TNL_BIT_TEX4 |    \
-                            _TNL_BIT_TEX5 |    \
-                            _TNL_BIT_TEX6 |    \
-                            _TNL_BIT_TEX7)
-
-
-#define _TNL_BITS_PROG_ANY   (_TNL_BIT_POS    |                \
-                             _TNL_BIT_WEIGHT |         \
-                             _TNL_BIT_NORMAL |         \
-                             _TNL_BIT_COLOR0 |         \
-                             _TNL_BIT_COLOR1 |         \
-                             _TNL_BIT_FOG    |         \
-                             _TNL_BIT_SIX    |         \
-                             _TNL_BIT_SEVEN  |         \
-                             _TNL_BITS_TEX_ANY)
-
-
-
-#define PRIM_BEGIN     0x10
-#define PRIM_END       0x20
-#define PRIM_WEAK      0x40
-#define PRIM_MODE_MASK 0x0f
-
-/* 
+/* 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.
  */
-struct tnl_prim {
-   GLuint mode;
-   GLuint start;
-   GLuint count;
-};
-
-
-
-struct tnl_eval1_map {
-   struct gl_1d_map *map;
-   GLuint sz;
-};
-
-struct tnl_eval2_map {
-   struct gl_2d_map *map;
-   GLuint sz;
-};
-
-struct tnl_eval {
-   GLuint new_state;
-   struct tnl_eval1_map map1[_TNL_ATTRIB_INDEX + 1];
-   struct tnl_eval2_map map2[_TNL_ATTRIB_INDEX + 1];
-};
-
-
-#define TNL_MAX_PRIM 16
-#define TNL_MAX_COPIED_VERTS 3
-
-struct tnl_copied_vtx {
-   GLfloat buffer[_TNL_ATTRIB_MAX * 4 * TNL_MAX_COPIED_VERTS];
-   GLuint nr;
-};
-
-#define VERT_BUFFER_SIZE 2048  /* 8kbytes */
-
-#define ERROR_ATTRIB _TNL_ATTRIB_MAX /* error path for t_vtx_api.c */
-
-typedef void (*attrfv_func)( const GLfloat * );
-
-/* The assembly of vertices in immediate mode is separated from
- * display list compilation.  This allows a simpler immediate mode
- * treatment and a display list compiler better suited to
- * hardware-acceleration.
+/* 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).
  */
-struct tnl_vtx {
-   GLfloat buffer[VERT_BUFFER_SIZE];
-   GLubyte attrsz[_TNL_ATTRIB_MAX];
-   GLuint vertex_size;
-   struct tnl_prim prim[TNL_MAX_PRIM];
-   GLuint prim_count;
-   GLfloat *vbptr;                   /* cursor, points into buffer */
-   GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current vertex */
-   GLfloat *attrptr[_TNL_ATTRIB_MAX]; /* points into vertex */
-   GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->Current, etc */
-   GLuint counter, initial_counter;
-   struct tnl_copied_vtx copied;
-   attrfv_func tabfv[_TNL_ATTRIB_MAX+1][4]; /* +1 for ERROR_ATTRIB */
-   struct tnl_eval eval;
-   GLboolean *edgeflag_tmp;
-   GLboolean have_materials;
+enum {
+       _TNL_ATTRIB_POS,
+       _TNL_ATTRIB_WEIGHT,
+       _TNL_ATTRIB_NORMAL,
+       _TNL_ATTRIB_COLOR0,
+       _TNL_ATTRIB_COLOR1,
+       _TNL_ATTRIB_FOG,
+       _TNL_ATTRIB_COLOR_INDEX,
+       _TNL_ATTRIB_EDGEFLAG,
+       _TNL_ATTRIB_TEX0,
+       _TNL_ATTRIB_TEX1,
+       _TNL_ATTRIB_TEX2,
+       _TNL_ATTRIB_TEX3,
+       _TNL_ATTRIB_TEX4,
+       _TNL_ATTRIB_TEX5,
+       _TNL_ATTRIB_TEX6,
+       _TNL_ATTRIB_TEX7,
+
+       /* This is really a VARYING_SLOT, not an attrib.  Need to fix
+        * tnl to understand the difference.
+        */
+       _TNL_ATTRIB_POINTSIZE,
+
+       _TNL_ATTRIB_GENERIC0, /* doesn't really exist! */
+       _TNL_ATTRIB_GENERIC1,
+       _TNL_ATTRIB_GENERIC2,
+       _TNL_ATTRIB_GENERIC3,
+       _TNL_ATTRIB_GENERIC4,
+       _TNL_ATTRIB_GENERIC5,
+       _TNL_ATTRIB_GENERIC6,
+       _TNL_ATTRIB_GENERIC7,
+       _TNL_ATTRIB_GENERIC8,
+       _TNL_ATTRIB_GENERIC9,
+       _TNL_ATTRIB_GENERIC10,
+       _TNL_ATTRIB_GENERIC11,
+       _TNL_ATTRIB_GENERIC12,
+       _TNL_ATTRIB_GENERIC13,
+       _TNL_ATTRIB_GENERIC14,
+       _TNL_ATTRIB_GENERIC15,
+
+       _TNL_ATTRIB_MAX,
+
+       /* 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 = _TNL_ATTRIB_GENERIC0,
+       _TNL_ATTRIB_MAT_BACK_AMBIENT,
+       _TNL_ATTRIB_MAT_FRONT_DIFFUSE,
+       _TNL_ATTRIB_MAT_BACK_DIFFUSE,
+       _TNL_ATTRIB_MAT_FRONT_SPECULAR,
+       _TNL_ATTRIB_MAT_BACK_SPECULAR,
+       _TNL_ATTRIB_MAT_FRONT_EMISSION,
+       _TNL_ATTRIB_MAT_BACK_EMISSION,
+       _TNL_ATTRIB_MAT_FRONT_SHININESS,
+       _TNL_ATTRIB_MAT_BACK_SHININESS,
+       _TNL_ATTRIB_MAT_FRONT_INDEXES,
+       _TNL_ATTRIB_MAT_BACK_INDEXES,
 };
 
+#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)
 
-
-/* For display lists, this structure holds a run of vertices of the
- * same format, and a strictly well-formed set of begin/end pairs,
- * starting on the first vertex and ending at the last.  Vertex
- * copying on buffer breaks is precomputed according to these
- * primitives, though there are situations where the copying will need
- * correction at execute-time, perhaps by replaying the list as
- * immediate mode commands.
- *
- * On executing this list, the 'current' values may be updated with
- * the values of the final vertex, and often no fixup of the start of
- * the vertex list is required.
- *
- * Eval and other commands that don't fit into these vertex lists are
- * compiled using the fallback opcode mechanism provided by dlist.c.
- */
-struct tnl_vertex_list {
-   GLubyte attrsz[_TNL_ATTRIB_MAX];
-   GLuint vertex_size;
-
-   GLfloat *buffer;
-   GLuint count;
-   GLuint wrap_count;          /* number of copied vertices at start */
-   GLboolean have_materials;   /* bit of a hack - quick check for materials */
-   GLboolean dangling_attr_ref;        /* current attr implicitly referenced 
-                                  outside the list */
-
-   GLfloat *normal_lengths;
-   struct tnl_prim *prim;
-   GLuint prim_count;
-
-   struct tnl_vertex_store *vertex_store;
-   struct tnl_primitive_store *prim_store;
-};
-
-/* These buffers should be a reasonable size to support upload to
- * hardware?  Maybe drivers should stitch them back together, or
- * specify a desired size?
- */
-#define SAVE_BUFFER_SIZE (16*1024)
-#define SAVE_PRIM_SIZE   128
-
-/* Storage to be shared among several vertex_lists.
+/**
+ * Handy attribute ranges:
  */
-struct tnl_vertex_store {
-   GLfloat buffer[SAVE_BUFFER_SIZE];
-   GLuint used;
-   GLuint refcount;
-};
+#define _TNL_FIRST_PROG      _TNL_ATTRIB_WEIGHT
+#define _TNL_LAST_PROG       _TNL_ATTRIB_TEX7
 
-struct tnl_primitive_store {
-   struct tnl_prim buffer[SAVE_PRIM_SIZE];
-   GLuint used;
-   GLuint refcount;
-};
+#define _TNL_FIRST_TEX       _TNL_ATTRIB_TEX0
+#define _TNL_LAST_TEX        _TNL_ATTRIB_TEX7
 
+#define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0
+#define _TNL_LAST_GENERIC  _TNL_ATTRIB_GENERIC15
 
-struct tnl_save {
-   GLubyte attrsz[_TNL_ATTRIB_MAX];
-   GLuint vertex_size;
+#define _TNL_FIRST_MAT       _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC0 */
+#define _TNL_LAST_MAT        _TNL_ATTRIB_MAT_BACK_INDEXES  /* GENERIC11 */
 
-   GLfloat *buffer;
-   GLuint count;
-   GLuint wrap_count;
+/* Number of available texture attributes */
+#define _TNL_NUM_TEX 8
 
-   struct tnl_prim *prim;
-   GLuint prim_count, prim_max;
+/* Number of available generic attributes */
+#define _TNL_NUM_GENERIC 16
 
-   struct tnl_vertex_store *vertex_store;
-   struct tnl_primitive_store *prim_store;
+/* Number of attributes used for evaluators */
+#define _TNL_NUM_EVAL 16
 
-   GLfloat *vbptr;                /* cursor, points into buffer */
-   GLfloat vertex[_TNL_ATTRIB_MAX*4];     /* current values */
-   GLfloat *attrptr[_TNL_ATTRIB_MAX];
-   GLuint counter, initial_counter;
-   GLboolean dangling_attr_ref;
-   GLboolean have_materials;
 
-   GLuint opcode_vertex_list;
+#define PRIM_BEGIN     0x10
+#define PRIM_END       0x20
+#define PRIM_MODE_MASK 0x0f
 
-   struct tnl_copied_vtx copied;
+static inline GLuint _tnl_translate_prim( const struct _mesa_prim *prim )
+{
+   GLuint flag;
+   flag = prim->mode;
+   if (prim->begin) flag |= PRIM_BEGIN;
+   if (prim->end) flag |= PRIM_END;
+   return flag;
+}
 
-   GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->ListState */
-   GLubyte *currentsz[_TNL_ATTRIB_MAX];
 
-   void (*tabfv[_TNL_ATTRIB_MAX][4])( const GLfloat * );
-};
-
-
-struct tnl_vertex_arrays
-{
-   /* Conventional vertex attribute arrays */
-   GLvector4f  Obj;
-   GLvector4f  Normal;
-   GLvector4f  Color;
-   GLvector4f  SecondaryColor;
-   GLvector4f  FogCoord;
-   GLvector4f  TexCoord[MAX_TEXTURE_COORD_UNITS];
-   GLvector4f  Index;
-
-   GLubyte     *EdgeFlag;
-   GLuint      *Elt;
-
-   /* These attributes don't alias with the conventional attributes.
-    * The GL_NV_vertex_program extension defines 16 extra sets of vertex
-    * arrays which have precedent over the conventional arrays when enabled.
-    */
-   GLvector4f  Attribs[_TNL_ATTRIB_MAX];
-};
 
 
 /**
@@ -393,88 +193,61 @@ struct tnl_vertex_arrays
  */
 struct vertex_buffer
 {
-   /* Constant over life of the vertex_buffer.
-    */
-   GLuint      Size;
+   GLuint Size;  /**< Max vertices per vertex buffer, constant */
 
    /* Constant over the pipeline.
     */
-   GLuint      Count;                        /* for everything except Elts */
+   GLuint Count;  /**< Number of vertices currently in buffer */
 
-   /* Pointers to current data.
+   /* Pointers to current data.  Most of the data is in AttribPtr -- all of
+    * it that is one of VERT_ATTRIB_X.  For things only produced by TNL,
+    * such as backface color or eye-space coordinates, they are stored
+    * here.
     */
    GLuint      *Elts;                          
-   GLvector4f  *ObjPtr;                                /* _TNL_BIT_POS */
    GLvector4f  *EyePtr;                                /* _TNL_BIT_POS */
    GLvector4f  *ClipPtr;                       /* _TNL_BIT_POS */
    GLvector4f  *NdcPtr;                         /* _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  *PointSizePtr;                  /* _TNL_BIT_POS */
-   GLvector4f  *FogCoordPtr;                   /* _TNL_BIT_FOG */
-
-   struct tnl_prim  *Primitive;                      
+   GLvector4f  *BackfaceIndexPtr;
+   GLvector4f  *BackfaceColorPtr;
+   GLvector4f  *BackfaceSecondaryColorPtr;
+
+   const struct _mesa_prim  *Primitive;                      
    GLuint      PrimitiveCount;       
 
    /* Inputs to the vertex program stage */
-   GLvector4f *AttribPtr[_TNL_ATTRIB_MAX];      /* GL_NV_vertex_program */
-
-   GLuint LastClipped;
-   /* Private data from _tnl_render_stage that has no business being
-    * in this struct.
-    */
+   GLvector4f *AttribPtr[_TNL_ATTRIB_MAX];
 };
 
 
-/** Describes an individual operation on the pipeline.
+/**
+ * Describes an individual operation on the pipeline.
  */
 struct tnl_pipeline_stage
 {
    const char *name;
-   GLuint check_state;         /* All state referenced in check() --
-                                * When is the pipeline_stage struct
-                                * itself invalidated?  Must be
-                                * constant.
-                                */
-
-   /* Usually constant or set by the 'check' callback:
-    */
-   GLuint run_state;           /* All state referenced in run() --
-                                * When is the cached output of the
-                                * stage invalidated?
-                                */
-
-   GLboolean active;           /* True if runnable in current state */
-   GLuint inputs;              /* VERT_* inputs to the stage */
-   GLuint outputs;             /* VERT_* outputs of the stage */
-
-   /* Set in _tnl_run_pipeline():
-    */
-   GLuint changed_inputs;      /* Generated value -- inputs to the
-                                * stage that have changed since last
-                                * call to 'run'.
-                                */
-
 
    /* Private data for the pipeline stage:
     */
    void *privatePtr;
 
-   /* Free private data.  May not be null.
+   /* Allocate private data
+    */
+   GLboolean (*create)( struct gl_context *ctx, struct tnl_pipeline_stage * );
+
+   /* Free private data.
     */
    void (*destroy)( struct tnl_pipeline_stage * );
 
-   /* Called from _tnl_validate_pipeline().  Must update all fields in
-    * the pipeline_stage struct for the current state.
+   /* Called on any statechange or input array size change or
+    * input array change to/from zero stride.
     */
-   void (*check)( GLcontext *ctx, struct tnl_pipeline_stage * );
+   void (*validate)( struct gl_context *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
@@ -484,29 +257,39 @@ struct tnl_pipeline_stage
     * Return value: GL_TRUE - keep going
     *               GL_FALSE - finished pipeline
     */
-   GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * );
+   GLboolean (*run)( struct gl_context *ctx, struct tnl_pipeline_stage * );
 };
 
+
+
 /** Contains the array of all pipeline stages.
- * The default values are defined at the end of t_pipeline.c */
+ * The default values are defined at the end of t_pipeline.c 
+ */
 struct tnl_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 */
-   /** This array has to end with a NULL-pointer. */
+   
+   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;
 };
 
+struct tnl_clipspace;
 struct tnl_clipspace_attr;
 
-typedef void (*extract_func)( const struct tnl_clipspace_attr *a, GLfloat *out, 
-                             const GLubyte *v );
+typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a, 
+                                 GLfloat *out, 
+                                 const GLubyte *v );
+
+typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a, 
+                                GLubyte *v, 
+                                const GLfloat *in );
 
-typedef void (*insert_func)( const struct tnl_clipspace_attr *a, GLubyte *v, 
-                            const GLfloat *in );
+typedef void (*tnl_emit_func)( struct gl_context *ctx, 
+                              GLuint count, 
+                              GLubyte *dest );
 
 
 /**
@@ -516,34 +299,55 @@ typedef void (*insert_func)( const struct tnl_clipspace_attr *a, GLubyte *v,
 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;
-   insert_func *insert;
-   insert_func emit;
-   extract_func extract;
+   GLuint inputsize;
+   const tnl_insert_func *insert;
+   tnl_insert_func emit;
+   tnl_extract_func extract;
    const GLfloat *vp;   /* NDC->Viewport mapping matrix */
 };
 
 
 
-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 );
-typedef void (*setup_func)( GLcontext *ctx,
-                           GLuint start, GLuint end,
-                           GLuint new_inputs);
 
+typedef void (*tnl_points_func)( struct gl_context *ctx, GLuint first, GLuint last );
+typedef void (*tnl_line_func)( struct gl_context *ctx, GLuint v1, GLuint v2 );
+typedef void (*tnl_triangle_func)( struct gl_context *ctx,
+                                  GLuint v1, GLuint v2, GLuint v3 );
+typedef void (*tnl_quad_func)( struct gl_context *ctx, GLuint v1, GLuint v2,
+                              GLuint v3, GLuint v4 );
+typedef void (*tnl_render_func)( struct gl_context *ctx, GLuint start, GLuint count,
+                                GLuint flags );
+typedef void (*tnl_interp_func)( struct gl_context *ctx,
+                                GLfloat t, GLuint dst, GLuint out, GLuint in,
+                                GLboolean force_boundary );
+typedef void (*tnl_copy_pv_func)( struct gl_context *ctx, GLuint dst, GLuint src );
+typedef void (*tnl_setup_func)( struct gl_context *ctx,
+                               GLuint start, GLuint end,
+                               GLuint new_inputs);
+
+
+struct tnl_attr_type {
+   GLuint format;
+   GLuint size;
+   GLuint stride;
+   GLuint offset;
+};
+
+struct tnl_clipspace_fastpath {
+   GLuint vertex_size;
+   GLuint attr_count;
+   GLboolean match_strides;
+
+   struct tnl_attr_type *attr;
+
+   tnl_emit_func func;
+   struct tnl_clipspace_fastpath *next;
+};
 
 /**
  * Used to describe conversion of vertex arrays to vertex structures.
@@ -562,9 +366,35 @@ struct tnl_clipspace
    struct tnl_clipspace_attr attr[_TNL_ATTRIB_MAX];
    GLuint attr_count;
 
-   void (*emit)( GLcontext *ctx, GLuint start, GLuint end, void *dest );
-   interp_func interp;
-   copy_pv_func copy_pv;
+   tnl_emit_func emit;
+   tnl_interp_func interp;
+   tnl_copy_pv_func copy_pv;
+
+   /* 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)( struct gl_context *ctx );
+};
+
+
+#define SHINE_TABLE_SIZE 256   /**< Material shininess lookup table sizes */
+
+/**
+ * Material shininess lookup table.
+ */
+struct tnl_shine_tab
+{
+   struct tnl_shine_tab *next, *prev;
+   GLfloat tab[SHINE_TABLE_SIZE+1];
+   GLfloat shininess;
+   GLuint refcount;
 };
 
 
@@ -574,70 +404,64 @@ struct tnl_device_driver
     *** TNL Pipeline
     ***/
 
-   void (*RunPipeline)(GLcontext *ctx);
+   void (*RunPipeline)(struct gl_context *ctx);
    /* Replaces PipelineStart/PipelineFinish -- intended to allow
     * drivers to wrap _tnl_run_pipeline() with code to validate state
     * and grab/release hardware locks.  
     */
 
-   void (*NotifyMaterialChange)(GLcontext *ctx);
+   void (*NotifyMaterialChange)(struct gl_context *ctx);
    /* Alert tnl-aware drivers of changes to material.
     */
 
-   GLboolean (*NotifyBegin)(GLcontext *ctx, GLenum p);
-   /* Allow drivers to hook in optimized begin/end engines.
-    * Return value:  GL_TRUE - driver handled the begin
-    *                GL_FALSE - driver didn't handle the begin
-    */
-
    /***
     *** Rendering -- These functions called only from t_vb_render.c
     ***/
    struct
    {
-      void (*Start)(GLcontext *ctx);
-      void (*Finish)(GLcontext *ctx);
+      void (*Start)(struct gl_context *ctx);
+      void (*Finish)(struct gl_context *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);
+      void (*PrimitiveNotify)(struct gl_context *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().
        */
 
-      interp_func Interp;
+      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.
        */
 
-      copy_pv_func CopyPV;
+      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 );
+      void (*ClippedPolygon)( struct gl_context *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 );
+      void (*ClippedLine)( struct gl_context *ctx, GLuint v0, GLuint v1 );
       /* Render a line between the two vertices given by indexes v0 and v1. */
 
-      points_func           Points; /* must now respect vb->elts */
-      line_func             Line;
-      triangle_func         Triangle;
-      quad_func             Quad;
+      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.
        */
 
-      render_func          *PrimTabVerts;
-      render_func          *PrimTabElts;
+      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
@@ -645,11 +469,11 @@ struct tnl_device_driver
        * vertices.
        */
 
-      void (*ResetLineStipple)( GLcontext *ctx );
+      void (*ResetLineStipple)( struct gl_context *ctx );
       /* Reset the hardware's line stipple counter.
        */
 
-      setup_func BuildVertices;
+      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
@@ -660,7 +484,7 @@ struct tnl_device_driver
        */
       
 
-      GLboolean (*Multipass)( GLcontext *ctx, GLuint passno );
+      GLboolean (*Multipass)( struct gl_context *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
@@ -671,7 +495,7 @@ struct tnl_device_driver
        */
    } Render;
 };
-   
+
 
 /**
  * Context state for T&L context.
@@ -682,61 +506,50 @@ typedef struct
     */
    struct tnl_device_driver Driver;
 
-   /* Execute:
-    */
-   struct tnl_vtx vtx;
-   
-   /* Compile:
-    */
-   struct tnl_save save;
-
    /* Pipeline
     */
    struct tnl_pipeline pipeline;
    struct vertex_buffer vb;
 
-   /* GLvectors for binding to vb:
-    */
-   struct tnl_vertex_arrays vtx_inputs;
-   struct tnl_vertex_arrays save_inputs;
-   struct tnl_vertex_arrays current;
-   struct tnl_vertex_arrays array_inputs;
-
    /* Clipspace/ndc/window vertex managment:
     */
    struct tnl_clipspace clipspace;
+   GLmatrix _WindowMap;
 
    /* Probably need a better configuration mechanism:
     */
    GLboolean NeedNdcCoords;
-   GLboolean LoopbackDListCassettes;
-   GLboolean CalcDListNormalLengths;
-   GLboolean IsolateMaterials;
    GLboolean AllowVertexFog;
    GLboolean AllowPixelFog;
-
    GLboolean _DoVertexFog;  /* eval fog function at each vertex? */
 
-   GLuint render_inputs;
+   GLbitfield64 render_inputs_bitset;
 
-   GLvertexformat exec_vtxfmt;
-   GLvertexformat save_vtxfmt;
+   GLvector4f tmp_inputs[VERT_ATTRIB_MAX];
 
+   /* Temp storage for t_draw.c: 
+    */
+   GLubyte *block[VERT_ATTRIB_MAX];
+   GLuint nr_blocks;
+
+   GLuint CurInstance;
+
+   struct tnl_shine_tab *_ShineTable[2]; /**< Active shine tables */
+   struct tnl_shine_tab *_ShineTabList;  /**< MRU list of inactive shine tables */
+   /**@}*/
 } TNLcontext;
 
 
 
-#define TNL_CONTEXT(ctx) ((TNLcontext *)(ctx->swtnl_context))
+#define TNL_CONTEXT(ctx) ((TNLcontext *)((ctx)->swtnl_context))
 
 
 #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_clip_prepare(struct gl_context *ctx);
 
 
 #endif