added _NEW_PROGRAM to check_state flags for pipeline stages (fixes vparray demo bug)
[mesa.git] / src / mesa / tnl / t_vb_texgen.c
index 0789670da6e2affe84835a21193e76f1ef6fbbd1..64d569a0192a5df8400b55869987cc0860ad52e9 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: t_vb_texgen.c,v 1.3 2001/03/03 20:33:31 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.0
  *
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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.
  *
  * Authors:
- *    Brian Paul <brian@valinux.com>
- *    Keith Whitwell <keithw@valinux.com>
+ *    Brian Paul
+ *    Keith Whitwell <keith@tungstengraphics.com>
  */
 
+/*
+ * Regarding GL_NV_texgen_reflection:
+ *
+ * Portions of this software may use or implement intellectual
+ * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
+ * any and all warranties with respect to such intellectual property,
+ * including any use thereof or modifications thereto.
+ */
 
 #include "glheader.h"
 #include "colormac.h"
 #include "context.h"
 #include "macros.h"
-#include "mmath.h"
-#include "mem.h"
+#include "imports.h"
 #include "mtypes.h"
 
 #include "math/m_xform.h"
@@ -59,9 +64,9 @@ struct texgen_stage_data {
 
    /* Per-texunit derived state.
     */
-   GLuint TexgenSize[MAX_TEXTURE_UNITS];
-   GLuint TexgenHoles[MAX_TEXTURE_UNITS];
-   texgen_func TexgenFunc[MAX_TEXTURE_UNITS];
+   GLuint TexgenSize[MAX_TEXTURE_COORD_UNITS];
+   GLuint TexgenHoles[MAX_TEXTURE_COORD_UNITS];
+   texgen_func TexgenFunc[MAX_TEXTURE_COORD_UNITS];
 
    /* Temporary values used in texgen.
     */
@@ -70,12 +75,11 @@ struct texgen_stage_data {
 
    /* Buffered outputs of the stage.
     */
-   GLvector4f texcoord[MAX_TEXTURE_UNITS];
+   GLvector4f texcoord[MAX_TEXTURE_COORD_UNITS];
 };
 
 
-#define TEXGEN_STAGE_DATA(stage) ((struct texgen_stage_data *)stage->private)
-
+#define TEXGEN_STAGE_DATA(stage) ((struct texgen_stage_data *)stage->privatePtr)
 
 
 
@@ -89,11 +93,15 @@ static GLuint all_bits[5] = {
 
 #define VEC_SIZE_FLAGS (VEC_SIZE_1|VEC_SIZE_2|VEC_SIZE_3|VEC_SIZE_4)
 
-/* 
- */
-static void build_m3(GLfloat f[][3], GLfloat m[],
-                    const GLvector3f *normal, 
-                    const GLvector4f *eye )
+#define TEXGEN_NEED_M            (TEXGEN_SPHERE_MAP)
+#define TEXGEN_NEED_F            (TEXGEN_SPHERE_MAP        | \
+                                 TEXGEN_REFLECTION_MAP_NV)
+
+
+
+static void build_m3( GLfloat f[][3], GLfloat m[],
+                     const GLvector4f *normal,
+                     const GLvector4f *eye )
 {
    GLuint stride = eye->stride;
    GLfloat *coord = (GLfloat *)eye->start;
@@ -101,14 +109,9 @@ static void build_m3(GLfloat f[][3], GLfloat m[],
    const GLfloat *norm = normal->start;
    GLuint i;
 
-
-   /* KW: Had to rearrange this loop to avoid a compiler bug with gcc
-    *     2.7.3.1 at -O3 optimization.  Using -fno-strength-reduce
-    *     also fixed the bug - is this generally necessary?  
-    */
-   for (i=0;i<count;i++,STRIDE_F(coord,stride)) {
+   for (i=0;i<count;i++,STRIDE_F(coord,stride),STRIDE_F(norm,normal->stride)) {
       GLfloat u[3], two_nu, fx, fy, fz;
-      COPY_3V( u, coord ); 
+      COPY_3V( u, coord );
       NORMALIZE_3FV( u );
       two_nu = 2.0F * DOT3(norm,u);
       fx = f[i][0] = u[0] - norm[0] * two_nu;
@@ -116,18 +119,16 @@ static void build_m3(GLfloat f[][3], GLfloat m[],
       fz = f[i][2] = u[2] - norm[2] * two_nu;
       m[i] = fx * fx + fy * fy + (fz + 1.0F) * (fz + 1.0F);
       if (m[i] != 0.0F) {
-        m[i] = 0.5F / (GLfloat) GL_SQRT(m[i]);
+        m[i] = 0.5F * _mesa_inv_sqrtf(m[i]);
       }
-
-      STRIDE_F(norm, normal->stride);
    }
 }
 
 
 
-static void build_m2(GLfloat f[][3], GLfloat m[],
-                    const GLvector3f *normal, 
-                    const GLvector4f *eye )
+static void build_m2( GLfloat f[][3], GLfloat m[],
+                     const GLvector4f *normal,
+                     const GLvector4f *eye )
 {
    GLuint stride = eye->stride;
    GLfloat *coord = eye->start;
@@ -136,10 +137,9 @@ static void build_m2(GLfloat f[][3], GLfloat m[],
    GLfloat *norm = normal->start;
    GLuint i;
 
-   for (i=0;i<count;i++,STRIDE_F(coord,stride)) {
-
+   for (i=0;i<count;i++,STRIDE_F(coord,stride),STRIDE_F(norm,normal->stride)) {
       GLfloat u[3], two_nu, fx, fy, fz;
-      COPY_2V( u, coord ); 
+      COPY_2V( u, coord );
       u[2] = 0;
       NORMALIZE_3FV( u );
       two_nu = 2.0F * DOT3(norm,u);
@@ -148,20 +148,17 @@ static void build_m2(GLfloat f[][3], GLfloat m[],
       fz = f[i][2] = u[2] - norm[2] * two_nu;
       m[i] = fx * fx + fy * fy + (fz + 1.0F) * (fz + 1.0F);
       if (m[i] != 0.0F) {
-        m[i] = 0.5F / (GLfloat) GL_SQRT(m[i]);
+        m[i] = 0.5F * _mesa_inv_sqrtf(m[i]);
       }
-
-      STRIDE_F(norm, normal->stride);
    }
 }
 
 
 
-typedef void (*build_m_func)(GLfloat f[][3],
-                            GLfloat m[],
-                            const GLvector3f *normal,
-                            const GLvector4f *eye );
-
+typedef void (*build_m_func)( GLfloat f[][3],
+                             GLfloat m[],
+                             const GLvector4f *normal,
+                             const GLvector4f *eye );
 
 
 static build_m_func build_m_tab[5] = {
@@ -175,11 +172,11 @@ static build_m_func build_m_tab[5] = {
 
 /* This is unusual in that we respect the stride of the output vector
  * (f).  This allows us to pass in either a texcoord vector4f, or a
- * temporary vector3f.  
+ * temporary vector3f.
  */
-static void build_f3( GLfloat *f, 
+static void build_f3( GLfloat *f,
                      GLuint fstride,
-                     const GLvector3f *normal,
+                     const GLvector4f *normal,
                      const GLvector4f *eye )
 {
    GLuint stride = eye->stride;
@@ -191,22 +188,22 @@ static void build_f3( GLfloat *f,
 
    for (i=0;i<count;i++) {
       GLfloat u[3], two_nu;
-      COPY_3V( u, coord ); 
+      COPY_3V( u, coord );
       NORMALIZE_3FV( u );
       two_nu = 2.0F * DOT3(norm,u);
       f[0] = u[0] - norm[0] * two_nu;
       f[1] = u[1] - norm[1] * two_nu;
       f[2] = u[2] - norm[2] * two_nu;
       STRIDE_F(coord,stride);
-      STRIDE_F(f,fstride); 
+      STRIDE_F(f,fstride);
       STRIDE_F(norm, normal->stride);
    }
 }
 
 
-static void build_f2( GLfloat *f, 
+static void build_f2( GLfloat *f,
                      GLuint fstride,
-                     const GLvector3f *normal,
+                     const GLvector4f *normal,
                      const GLvector4f *eye )
 {
    GLuint stride = eye->stride;
@@ -218,7 +215,7 @@ static void build_f2( GLfloat *f,
    for (i=0;i<count;i++) {
 
       GLfloat u[3], two_nu;
-      COPY_2V( u, coord ); 
+      COPY_2V( u, coord );
       u[2] = 0;
       NORMALIZE_3FV( u );
       two_nu = 2.0F * DOT3(norm,u);
@@ -234,19 +231,19 @@ static void build_f2( GLfloat *f,
 
 typedef void (*build_f_func)( GLfloat *f,
                              GLuint fstride,
-                             const GLvector3f *normal_vec,
+                             const GLvector4f *normal_vec,
                              const GLvector4f *eye );
 
 
 
-/* Just treat 4-vectors as 3-vectors. 
+/* Just treat 4-vectors as 3-vectors.
  */
 static build_f_func build_f_tab[5] = {
    0,
    0,
    build_f2,
    build_f3,
-   build_f3            
+   build_f3
 };
 
 
@@ -262,22 +259,22 @@ static void texgen_reflection_map_nv( GLcontext *ctx,
 
    build_f_tab[VB->EyePtr->size]( out->start,
                                  out->stride,
-                                 VB->NormalPtr, 
-                                 VB->EyePtr ); 
-   
+                                 VB->NormalPtr,
+                                 VB->EyePtr );
+
    if (in) {
       out->flags |= (in->flags & VEC_SIZE_FLAGS) | VEC_SIZE_3;
       out->count = in->count;
       out->size = MAX2(in->size, 3);
-      if (in->size == 4) 
-        _mesa_copy_tab[0][0x8](out, in, 0);
-   } 
+      if (in->size == 4)
+        _mesa_copy_tab[0x8]( out, in );
+   }
    else {
       out->flags |= VEC_SIZE_3;
       out->size = 3;
       out->count = in->count;
    }
-   
+
 }
 
 
@@ -289,7 +286,7 @@ static void texgen_normal_map_nv( GLcontext *ctx,
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
    GLvector4f *in = VB->TexCoordPtr[unit];
    GLvector4f *out = &store->texcoord[unit];
-   GLvector3f *normal = VB->NormalPtr;   
+   GLvector4f *normal = VB->NormalPtr;
    GLfloat (*texcoord)[4] = (GLfloat (*)[4])out->start;
    GLuint count = VB->Count;
    GLuint i;
@@ -306,9 +303,9 @@ static void texgen_normal_map_nv( GLcontext *ctx,
       out->flags |= (in->flags & VEC_SIZE_FLAGS) | VEC_SIZE_3;
       out->count = in->count;
       out->size = MAX2(in->size, 3);
-      if (in->size == 4) 
-        _mesa_copy_tab[0][0x8](out, in, 0);
-   } 
+      if (in->size == 4)
+        _mesa_copy_tab[0x8]( out, in );
+   }
    else {
       out->flags |= VEC_SIZE_3;
       out->size = 3;
@@ -330,10 +327,10 @@ static void texgen_sphere_map( GLcontext *ctx,
    GLfloat (*f)[3] = store->tmp_f;
    GLfloat *m = store->tmp_m;
 
-   (build_m_tab[VB->EyePtr->size])( store->tmp_f, 
-                                   store->tmp_m, 
-                                   VB->NormalPtr, 
-                                   VB->EyePtr ); 
+   (build_m_tab[VB->EyePtr->size])( store->tmp_f,
+                                   store->tmp_m,
+                                   VB->NormalPtr,
+                                   VB->EyePtr );
 
    for (i=0;i<count;i++) {
       texcoord[i][0] = f[i][0] * m[i] + 0.5F;
@@ -344,8 +341,8 @@ static void texgen_sphere_map( GLcontext *ctx,
       out->size = MAX2(in->size,2);
       out->count = in->count;
       out->flags |= (in->flags & VEC_SIZE_FLAGS) | VEC_SIZE_2;
-      if (in->size > 2) 
-        _mesa_copy_tab[0][all_bits[in->size] & ~0x3](out, in, 0);
+      if (in->size > 2)
+        _mesa_copy_tab[all_bits[in->size] & ~0x3]( out, in );
    } else {
       out->size = 2;
       out->flags |= VEC_SIZE_2;
@@ -355,7 +352,7 @@ static void texgen_sphere_map( GLcontext *ctx,
 
 
 
-static void texgen( GLcontext *ctx, 
+static void texgen( GLcontext *ctx,
                    struct texgen_stage_data *store,
                    GLuint unit )
 {
@@ -363,22 +360,20 @@ static void texgen( GLcontext *ctx,
    struct vertex_buffer *VB = &tnl->vb;
    GLvector4f *in = VB->TexCoordPtr[unit];
    GLvector4f *out = &store->texcoord[unit];
-   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
    const GLvector4f *obj = VB->ObjPtr;
    const GLvector4f *eye = VB->EyePtr;
-   const GLvector3f *normal = VB->NormalPtr;
+   const GLvector4f *normal = VB->NormalPtr;
+   const GLfloat *m = store->tmp_m;
+   const GLuint count = VB->Count;
    GLfloat (*texcoord)[4] = (GLfloat (*)[4])out->data;
-   GLfloat *indata;
-   GLuint count = VB->Count;
    GLfloat (*f)[3] = store->tmp_f;
-   GLfloat *m = store->tmp_m;
-        GLuint holes = 0;
-
+   GLuint holes = 0;
 
    if (texUnit->_GenFlags & TEXGEN_NEED_M) {
-      build_m_tab[in->size]( store->tmp_f, store->tmp_m, normal, eye ); 
+      build_m_tab[eye->size]( store->tmp_f, store->tmp_m, normal, eye );
    } else if (texUnit->_GenFlags & TEXGEN_NEED_F) {
-      build_f_tab[in->size]( (GLfloat *)store->tmp_f, 3, normal, eye ); 
+      build_f_tab[eye->size]( (GLfloat *)store->tmp_f, 3, normal, eye );
    }
 
    if (!in) {
@@ -394,16 +389,17 @@ static void texgen( GLcontext *ctx,
    else {
       GLuint copy = (all_bits[in->size] & ~texUnit->TexGenEnabled);
       if (copy)
-        _mesa_copy_tab[0][copy](out, in, 0);
+        _mesa_copy_tab[copy]( out, in );
 
       out->size = MAX2(in->size, store->TexgenSize[unit]);
       out->flags |= (in->flags & VEC_SIZE_FLAGS) | texUnit->TexGenEnabled;
       out->count = in->count;
-      
+
       holes = ~all_bits[in->size] & store->TexgenHoles[unit];
    }
 
    if (holes) {
+      if (holes & VEC_DIRTY_3) _mesa_vector4f_clean_elem(out, count, 3);
       if (holes & VEC_DIRTY_2) _mesa_vector4f_clean_elem(out, count, 2);
       if (holes & VEC_DIRTY_1) _mesa_vector4f_clean_elem(out, count, 1);
       if (holes & VEC_DIRTY_0) _mesa_vector4f_clean_elem(out, count, 0);
@@ -413,21 +409,21 @@ static void texgen( GLcontext *ctx,
       GLuint i;
       switch (texUnit->GenModeS) {
       case GL_OBJECT_LINEAR:
-        (gl_dotprod_tab[0][obj->size])((GLfloat *)out->data,
-                                       sizeof(out->data[0]), obj, 
-                                       texUnit->ObjectPlaneS, 0);
+        _mesa_dotprod_tab[obj->size]( (GLfloat *)out->data,
+                                      sizeof(out->data[0]), obj,
+                                      texUnit->ObjectPlaneS );
         break;
       case GL_EYE_LINEAR:
-        (gl_dotprod_tab[0][eye->size])((GLfloat *)out->data, 
-                                       sizeof(out->data[0]), eye,
-                                       texUnit->EyePlaneS, 0);
+        _mesa_dotprod_tab[eye->size]( (GLfloat *)out->data,
+                                      sizeof(out->data[0]), eye,
+                                      texUnit->EyePlaneS );
         break;
-      case GL_SPHERE_MAP: 
-        for (indata=in->start,i=0 ; i<count ;i++, STRIDE_F(indata,in->stride))
-           texcoord[i][0] = indata[0] * m[i] + 0.5F;
+      case GL_SPHERE_MAP:
+         for (i = 0; i < count; i++)
+            texcoord[i][0] = f[i][0] * m[i] + 0.5F;
         break;
-      case GL_REFLECTION_MAP_NV: 
-        for (i=0;i<count;i++) 
+      case GL_REFLECTION_MAP_NV:
+        for (i=0;i<count;i++)
             texcoord[i][0] = f[i][0];
         break;
       case GL_NORMAL_MAP_NV: {
@@ -440,28 +436,28 @@ static void texgen( GLcontext *ctx,
       default:
         _mesa_problem(ctx, "Bad S texgen");
       }
-   } 
+   }
 
    if (texUnit->TexGenEnabled & T_BIT) {
       GLuint i;
       switch (texUnit->GenModeT) {
       case GL_OBJECT_LINEAR:
-        (gl_dotprod_tab[0][obj->size])(&(out->data[0][1]), 
-                                       sizeof(out->data[0]), obj, 
-                                       texUnit->ObjectPlaneT, 0);
+        _mesa_dotprod_tab[obj->size]( &(out->data[0][1]),
+                                      sizeof(out->data[0]), obj,
+                                      texUnit->ObjectPlaneT );
         break;
       case GL_EYE_LINEAR:
-        (gl_dotprod_tab[0][eye->size])(&(out->data[0][1]), 
-                                       sizeof(out->data[0]), eye, 
-                                       texUnit->EyePlaneT, 0);
-        break; 
-      case GL_SPHERE_MAP: 
-        for (indata=in->start,i=0; i<count ;i++,STRIDE_F(indata,in->stride)) 
-            texcoord[i][1] = indata[1] * m[i] + 0.5F;
-        break;      
-      case GL_REFLECTION_MAP_NV: 
-        for (i=0;i<count;i++) 
-            texcoord[i][0] = f[i][0];
+        _mesa_dotprod_tab[eye->size]( &(out->data[0][1]),
+                                      sizeof(out->data[0]), eye,
+                                      texUnit->EyePlaneT );
+        break;
+      case GL_SPHERE_MAP:
+         for (i = 0; i < count; i++)
+            texcoord[i][1] = f[i][1] * m[i] + 0.5F;
+        break;
+      case GL_REFLECTION_MAP_NV:
+        for (i=0;i<count;i++)
+            texcoord[i][1] = f[i][1];
         break;
       case GL_NORMAL_MAP_NV: {
         const GLfloat *norm = normal->start;
@@ -479,17 +475,17 @@ static void texgen( GLcontext *ctx,
       GLuint i;
       switch (texUnit->GenModeR) {
       case GL_OBJECT_LINEAR:
-        (gl_dotprod_tab[0][obj->size])(&(out->data[0][2]), 
-                                       sizeof(out->data[0]), obj, 
-                                       texUnit->ObjectPlaneR, 0);
+        _mesa_dotprod_tab[obj->size]( &(out->data[0][2]),
+                                      sizeof(out->data[0]), obj,
+                                      texUnit->ObjectPlaneR );
         break;
       case GL_EYE_LINEAR:
-        (gl_dotprod_tab[0][eye->size])(&(out->data[0][2]), 
-                                       sizeof(out->data[0]), eye,
-                                       texUnit->EyePlaneR, 0);
+        _mesa_dotprod_tab[eye->size]( &(out->data[0][2]),
+                                      sizeof(out->data[0]), eye,
+                                      texUnit->EyePlaneR );
         break;
-      case GL_REFLECTION_MAP_NV: 
-        for (i=0;i<count;i++) 
+      case GL_REFLECTION_MAP_NV:
+        for (i=0;i<count;i++)
             texcoord[i][2] = f[i][2];
         break;
       case GL_NORMAL_MAP_NV: {
@@ -507,14 +503,14 @@ static void texgen( GLcontext *ctx,
    if (texUnit->TexGenEnabled & Q_BIT) {
       switch (texUnit->GenModeQ) {
       case GL_OBJECT_LINEAR:
-        (gl_dotprod_tab[0][obj->size])(&(out->data[0][3]), 
-                                       sizeof(out->data[0]), obj, 
-                                       texUnit->ObjectPlaneQ, 0);
+        _mesa_dotprod_tab[obj->size]( &(out->data[0][3]),
+                                      sizeof(out->data[0]), obj,
+                                      texUnit->ObjectPlaneQ );
         break;
       case GL_EYE_LINEAR:
-        (gl_dotprod_tab[0][eye->size])(&(out->data[0][3]), 
-                                       sizeof(out->data[0]), eye,
-                                       texUnit->EyePlaneQ, 0);
+        _mesa_dotprod_tab[eye->size]( &(out->data[0][3]),
+                                      sizeof(out->data[0]), eye,
+                                      texUnit->EyePlaneQ );
         break;
       default:
         _mesa_problem(ctx, "Bad Q texgen");
@@ -524,19 +520,20 @@ static void texgen( GLcontext *ctx,
 
 
 
-static GLboolean run_texgen_stage( GLcontext *ctx, 
-                                  struct gl_pipeline_stage *stage )
+static GLboolean run_texgen_stage( GLcontext *ctx,
+                                  struct tnl_pipeline_stage *stage )
 {
-   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 
+   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
    struct texgen_stage_data *store = TEXGEN_STAGE_DATA( stage );
    GLuint i;
 
-   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) 
-      if (ctx->_Enabled & ENABLE_TEXGEN(i)) {
-        if (stage->changed_inputs & (VERT_EYE | VERT_NORM | VERT_TEX(i)))
+   for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
+      if (ctx->Texture._TexGenEnabled & ENABLE_TEXGEN(i)) {
+        if (stage->changed_inputs & (_TNL_BIT_POS | _TNL_BIT_NORMAL | _TNL_BIT_TEX(i)))
            store->TexgenFunc[i]( ctx, store, i );
 
-        VB->TexCoordPtr[i] = &store->texcoord[i];
+        VB->AttribPtr[VERT_ATTRIB_TEX0+i] = 
+           VB->TexCoordPtr[i] = &store->texcoord[i];
       }
 
    return GL_TRUE;
@@ -545,31 +542,32 @@ static GLboolean run_texgen_stage( GLcontext *ctx,
 
 
 
-static GLboolean run_validate_texgen_stage( GLcontext *ctx, 
-                                           struct gl_pipeline_stage *stage )
+static GLboolean run_validate_texgen_stage( GLcontext *ctx,
+                                           struct tnl_pipeline_stage *stage )
 {
    struct texgen_stage_data *store = TEXGEN_STAGE_DATA(stage);
    GLuint i;
 
-   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
+   for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) {
       struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
 
       if (texUnit->TexGenEnabled) {
         GLuint sz;
 
-        if (texUnit->TexGenEnabled & R_BIT)
+        if (texUnit->TexGenEnabled & Q_BIT)
            sz = 4;
-        else if (texUnit->TexGenEnabled & Q_BIT)
+        else if (texUnit->TexGenEnabled & R_BIT)
            sz = 3;
         else if (texUnit->TexGenEnabled & T_BIT)
            sz = 2;
         else
            sz = 1;
-       
+
         store->TexgenSize[i] = sz;
         store->TexgenHoles[i] = (all_bits[sz] & ~texUnit->TexGenEnabled);
-        store->TexgenFunc[i] = texgen;
-       
+        store->TexgenFunc[i] = texgen; /* general solution */
+
+         /* look for special texgen cases */
         if (texUnit->TexGenEnabled == (S_BIT|T_BIT|R_BIT)) {
            if (texUnit->_GenFlags == TEXGEN_REFLECTION_MAP_NV) {
               store->TexgenFunc[i] = texgen_reflection_map_nv;
@@ -590,62 +588,60 @@ static GLboolean run_validate_texgen_stage( GLcontext *ctx,
 }
 
 
-static void check_texgen( GLcontext *ctx, struct gl_pipeline_stage *stage )
+static void check_texgen( GLcontext *ctx, struct tnl_pipeline_stage *stage )
 {
    GLuint i;
    stage->active = 0;
 
-   if (ctx->_Enabled & ENABLE_TEXGEN_ANY) {
+   if (ctx->Texture._TexGenEnabled && !ctx->VertexProgram.Enabled) {
       GLuint inputs = 0;
       GLuint outputs = 0;
 
-      if (ctx->Texture._GenFlags & TEXGEN_NEED_VERTICES)
-        inputs |= VERT_EYE;
+      if (ctx->Texture._GenFlags & (TEXGEN_OBJ_LINEAR | TEXGEN_NEED_EYE_COORD))
+        inputs |= _TNL_BIT_POS;
 
       if (ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS)
-        inputs |= VERT_NORM;
+        inputs |= _TNL_BIT_NORMAL;
 
-      for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) 
-        if (ctx->_Enabled & ENABLE_TEXGEN(i)) 
+      for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
+        if (ctx->Texture._TexGenEnabled & ENABLE_TEXGEN(i))
         {
-           outputs |= VERT_TEX(i);
+           outputs |= _TNL_BIT_TEX(i);
 
            /* Need the original input in case it contains a Q coord:
             * (sigh)
             */
-/*         if ((ctx->Texture.Unit[i]._ReallyEnabled|Q_BIT) & */
-/*             ~ctx->Texture.Unit[i].TexGenEnabled) */
-              inputs |= VERT_TEX(i);
+           inputs |= _TNL_BIT_TEX(i);
 
            /* Something for Feedback? */
         }
 
-      if (stage->private)
+      if (stage->privatePtr)
         stage->run = run_validate_texgen_stage;
       stage->active = 1;
       stage->inputs = inputs;
       stage->outputs = outputs;
    }
 }
+
 
 
 
 /* Called the first time stage->run() is invoked.
  */
-static GLboolean alloc_texgen_data( GLcontext *ctx, 
-                                   struct gl_pipeline_stage *stage )
+static GLboolean alloc_texgen_data( GLcontext *ctx,
+                                   struct tnl_pipeline_stage *stage )
 {
-   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 
+   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
    struct texgen_stage_data *store;
    GLuint i;
 
-   stage->private = CALLOC(sizeof(*store));
+   stage->privatePtr = CALLOC(sizeof(*store));
    store = TEXGEN_STAGE_DATA(stage);
    if (!store)
       return GL_FALSE;
 
-   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
+   for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
       _mesa_vector4f_alloc( &store->texcoord[i], 0, VB->Size, 32 );
 
    store->tmp_f = (GLfloat (*)[3]) MALLOC(VB->Size * sizeof(GLfloat) * 3);
@@ -658,37 +654,38 @@ static GLboolean alloc_texgen_data( GLcontext *ctx,
 }
 
 
-static void free_texgen_data( struct gl_pipeline_stage *stage )
+static void free_texgen_data( struct tnl_pipeline_stage *stage )
 
 {
    struct texgen_stage_data *store = TEXGEN_STAGE_DATA(stage);
    GLuint i;
 
    if (store) {
-      for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
-        if (store->texcoord[i].data) 
+      for (i = 0 ; i < MAX_TEXTURE_COORD_UNITS ; i++)
+        if (store->texcoord[i].data)
            _mesa_vector4f_free( &store->texcoord[i] );
 
-      
+
       if (store->tmp_f) FREE( store->tmp_f );
       if (store->tmp_m) FREE( store->tmp_m );
       FREE( store );
-      stage->private = 0;
+      stage->privatePtr = NULL;
    }
 }
 
 
-   
-const struct gl_pipeline_stage _tnl_texgen_stage = 
-{ 
-   "texgen",
-   _NEW_TEXTURE,               /* when to call check() */
+
+const struct tnl_pipeline_stage _tnl_texgen_stage =
+{
+   "texgen",                   /* name */
+   _NEW_TEXTURE|_NEW_PROGRAM,  /* when to call check() */
    _NEW_TEXTURE,               /* when to invalidate stored data */
-   0,0,0,                      /* active, inputs, outputs */
-   0,0,                                /* changed_inputs, private */
+   GL_FALSE,                   /* active? */
+   0,                          /* inputs */
+   0,                          /* outputs */
+   0,                          /* changed_inputs */
+   NULL,                       /* private data */
    free_texgen_data,           /* destructor */
    check_texgen,               /* check */
    alloc_texgen_data           /* run -- initially set to alloc data */
 };
-
-