Rename the various function types in t_context.h to include a tnl_ prefix.
[mesa.git] / src / mesa / drivers / glide / fxvb.c
index 2d9f73d6a8f5af6e6fa97bf897ff0198e009c66b..46a4278d0759acfc6808f43695ffc20c11ff7391 100644 (file)
@@ -24,7 +24,8 @@
  */
 
 /* Authors:
- *   Keith Whitwell
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Daniel Borca <dborca@users.sourceforge.net>
  */
 
 #ifdef HAVE_CONFIG_H
@@ -57,51 +58,28 @@ static void copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
    *(GLuint *)&dst->pargb = *(GLuint *)&src->pargb;
 }
 
+static void copy_pv2( GLcontext *ctx, GLuint edst, GLuint esrc )
+{
+   fxMesaContext fxMesa = FX_CONTEXT( ctx );
+   GrVertex *dst = fxMesa->verts + edst;
+   GrVertex *src = fxMesa->verts + esrc;
+
+   *(GLuint *)&dst->pargb = *(GLuint *)&src->pargb;
+   *(GLuint *)&dst->pspec = *(GLuint *)&src->pspec;
+}
+
 typedef void (*emit_func)( GLcontext *, GLuint, GLuint, void * );
 
 static struct {
    emit_func           emit;
-   interp_func         interp;
+   tnl_copy_pv_func            copy_pv;
+   tnl_interp_func             interp;
    GLboolean           (*check_tex_sizes)( GLcontext *ctx );
    GLuint               vertex_format;
 } setup_tab[MAX_SETUP];
 
 
-static void import_float_colors( GLcontext *ctx )
-{
-   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
-   struct gl_client_array *from = VB->ColorPtr[0];
-   struct gl_client_array *to = &FX_CONTEXT(ctx)->UbyteColor;
-   GLuint count = VB->Count;
-
-   if (!to->Ptr) {
-      to->Ptr = ALIGN_MALLOC( VB->Size * 4 * sizeof(GLubyte), 32 );
-      to->Type = GL_UNSIGNED_BYTE;
-   }
-
-   /* No need to transform the same value 3000 times.
-    */
-   if (!from->StrideB) {
-      to->StrideB = 0;
-      count = 1;
-   }
-   else
-      to->StrideB = 4 * sizeof(GLubyte);
-   
-   _math_trans_4ub( (GLubyte (*)[4]) to->Ptr,
-                   from->Ptr,
-                   from->StrideB,
-                   from->Type,
-                   from->Size,
-                   0,
-                   count);
-
-   VB->ColorPtr[0] = to;
-}
-
-
-/* Hack alert: assume chan is 8 bits */
-#define GET_COLOR(ptr, idx) (((GLchan (*)[4])((ptr)->Ptr))[idx])
+#define GET_COLOR(ptr, idx) ((ptr)->data[idx])
 
 
 static void interp_extras( GLcontext *ctx,
@@ -112,18 +90,19 @@ static void interp_extras( GLcontext *ctx,
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
 
    if (VB->ColorPtr[1]) {
-      INTERP_4CHAN( t,
+      assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
+
+      INTERP_4F( t,
                 GET_COLOR(VB->ColorPtr[1], dst),
                 GET_COLOR(VB->ColorPtr[1], out),
                 GET_COLOR(VB->ColorPtr[1], in) );
-#if 1 /* [dBorca] GL_EXT_separate_specular_color */
+
       if (VB->SecondaryColorPtr[1]) {
-        INTERP_3CHAN( t,
+        INTERP_3F( t,
                    GET_COLOR(VB->SecondaryColorPtr[1], dst),
                    GET_COLOR(VB->SecondaryColorPtr[1], out),
                    GET_COLOR(VB->SecondaryColorPtr[1], in) );
       }
-#endif
    }
 
    if (VB->EdgeFlag) {
@@ -139,17 +118,16 @@ static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
 
    if (VB->ColorPtr[1]) {
-        COPY_CHAN4( GET_COLOR(VB->ColorPtr[1], dst),
+        COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst),
                   GET_COLOR(VB->ColorPtr[1], src) );
-#if 1 /* [dBorca] GL_EXT_separate_specular_color */
+
         if (VB->SecondaryColorPtr[1]) {
-           COPY_CHAN4( GET_COLOR(VB->SecondaryColorPtr[1], dst),
+           COPY_3FV( GET_COLOR(VB->SecondaryColorPtr[1], dst),
                      GET_COLOR(VB->SecondaryColorPtr[1], src) );
         }
-#endif
    }
 
-   copy_pv(ctx, dst, src);
+   setup_tab[FX_CONTEXT(ctx)->SetupIndex].copy_pv(ctx, dst, src);
 }
 
 
@@ -174,6 +152,70 @@ static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
 #define TAG(x) x##_wgpt0t1
 #include "fxvbtmp.h"
 
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_PSIZ)
+#define TAG(x) x##_wga
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ)
+#define TAG(x) x##_wgt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ)
+#define TAG(x) x##_wgt0t1a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_wgpt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_TMU0|SETUP_TMU1|\
+             SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_wgpt0t1a
+#include "fxvbtmp.h"
+
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC)
+#define TAG(x) x##_2wg
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
+#define TAG(x) x##_2wgt0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1)
+#define TAG(x) x##_2wgt0t1
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX)
+#define TAG(x) x##_2wgpt0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
+             SETUP_PTEX)
+#define TAG(x) x##_2wgpt0t1
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ)
+#define TAG(x) x##_2wga
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ)
+#define TAG(x) x##_2wgt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|SETUP_PSIZ)
+#define TAG(x) x##_2wgt0t1a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_2wgpt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1|\
+             SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_2wgpt0t1a
+#include "fxvbtmp.h"
+
 
 /* Snapping for voodoo-1
  */
@@ -200,6 +242,76 @@ static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
 #define TAG(x) x##_wsgpt0t1
 #include "fxvbtmp.h"
 
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_PSIZ)
+#define TAG(x) x##_wsga
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|SETUP_PSIZ)
+#define TAG(x) x##_wsgt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
+             SETUP_TMU1|SETUP_PSIZ)
+#define TAG(x) x##_wsgt0t1a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
+             SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_wsgpt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_TMU0|\
+            SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_wsgpt0t1a
+#include "fxvbtmp.h"
+
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC)
+#define TAG(x) x##_2wsg
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
+#define TAG(x) x##_2wsgt0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+             SETUP_TMU1)
+#define TAG(x) x##_2wsgt0t1
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+             SETUP_PTEX)
+#define TAG(x) x##_2wsgpt0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+            SETUP_TMU1|SETUP_PTEX)
+#define TAG(x) x##_2wsgpt0t1
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_PSIZ)
+#define TAG(x) x##_2wsga
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_PSIZ)
+#define TAG(x) x##_2wsgt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+             SETUP_TMU1|SETUP_PSIZ)
+#define TAG(x) x##_2wsgt0t1a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+             SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_2wsgpt0a
+#include "fxvbtmp.h"
+
+#define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|\
+            SETUP_TMU1|SETUP_PTEX|SETUP_PSIZ)
+#define TAG(x) x##_2wsgpt0t1a
+#include "fxvbtmp.h"
+
 
 /* Vertex repair (multipass rendering)
  */
@@ -224,6 +336,27 @@ static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
 #include "fxvbtmp.h"
 
 
+#define IND (SETUP_RGBA|SETUP_SPEC)
+#define TAG(x) x##_2g
+#include "fxvbtmp.h"
+
+#define IND (SETUP_TMU0|SETUP_SPEC)
+#define TAG(x) x##_2t0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_TMU0|SETUP_SPEC|SETUP_TMU1)
+#define TAG(x) x##_2t0t1
+#include "fxvbtmp.h"
+
+#define IND (SETUP_RGBA|SETUP_SPEC|SETUP_TMU0)
+#define TAG(x) x##_2gt0
+#include "fxvbtmp.h"
+
+#define IND (SETUP_RGBA|SETUP_SPEC|SETUP_TMU0|SETUP_TMU1)
+#define TAG(x) x##_2gt0t1
+#include "fxvbtmp.h"
+
+
 
 static void init_setup_tab( void )
 {
@@ -232,31 +365,68 @@ static void init_setup_tab( void )
    init_wgt0t1();
    init_wgpt0();
    init_wgpt0t1();
+   init_wga();
+   init_wgt0a();
+   init_wgt0t1a();
+   init_wgpt0a();
+   init_wgpt0t1a();
+    init_2wg();
+    init_2wgt0();
+    init_2wgt0t1();
+    init_2wgpt0();
+    init_2wgpt0t1();
+    init_2wga();
+    init_2wgt0a();
+    init_2wgt0t1a();
+    init_2wgpt0a();
+    init_2wgpt0t1a();
 
    init_wsg();
    init_wsgt0();
    init_wsgt0t1();
    init_wsgpt0();
    init_wsgpt0t1();
+   init_wsga();
+   init_wsgt0a();
+   init_wsgt0t1a();
+   init_wsgpt0a();
+   init_wsgpt0t1a();
+    init_2wsg();
+    init_2wsgt0();
+    init_2wsgt0t1();
+    init_2wsgpt0();
+    init_2wsgpt0t1();
+    init_2wsga();
+    init_2wsgt0a();
+    init_2wsgt0t1a();
+    init_2wsgpt0a();
+    init_2wsgpt0t1a();
 
    init_g();
    init_t0();
    init_t0t1();
    init_gt0();
    init_gt0t1();
+    init_2g();
+    init_2t0();
+    init_2t0t1();
+    init_2gt0();
+    init_2gt0t1();
 }
 
 
 void fxPrintSetupFlags(char *msg, GLuint flags )
 {
-   fprintf(stderr, "%s(%x): %s%s%s%s%s\n",
+   fprintf(stderr, "%s(%x): %s%s%s%s%s%s%s\n",
           msg,
           (int)flags,
           (flags & SETUP_XYZW)     ? " xyzw," : "", 
           (flags & SETUP_SNAP)     ? " snap," : "", 
           (flags & SETUP_RGBA)     ? " rgba," : "",
           (flags & SETUP_TMU0)     ? " tex-0," : "",
-          (flags & SETUP_TMU1)     ? " tex-1," : "");
+          (flags & SETUP_TMU1)     ? " tex-1," : "",
+          (flags & SETUP_PSIZ)     ? " psiz," : "",
+          (flags & SETUP_SPEC)     ? " spec," : "");
 }
 
 
@@ -299,14 +469,21 @@ void fxBuildVertices( GLcontext *ctx, GLuint start, GLuint count,
    if (!newinputs)
       return;
 
-   if (newinputs & VERT_BIT_CLIP) {
+   if (newinputs & VERT_BIT_POS) {
       setup_tab[fxMesa->SetupIndex].emit( ctx, start, count, v );   
    } else {
       GLuint ind = 0;
 
+      /* [dBorca] masked by VERT_BIT_POS ?!?
+      if (newinputs & VERT_BIT_POINT_SIZE)
+        ind |= SETUP_PSIZ;*/
+
       if (newinputs & VERT_BIT_COLOR0)
         ind |= SETUP_RGBA;
       
+      if (newinputs & VERT_BIT_COLOR1)
+        ind |= SETUP_SPEC;
+
       if (newinputs & VERT_BIT_TEX0) 
         ind |= SETUP_TMU0;
 
@@ -339,18 +516,24 @@ void fxChooseVertexState( GLcontext *ctx )
 
    if (ctx->Texture._EnabledUnits & 0x2) {
       if (ctx->Texture._EnabledUnits & 0x1) {
-        ind |= SETUP_TMU1|SETUP_TMU0;
-      }
-      else {
-        fxMesa->tmu_source[0] = 1;
-        fxMesa->tmu_source[1] = 0;
-        ind |= SETUP_TMU0;
+        ind |= SETUP_TMU1;
       }
+      ind |= SETUP_TMU0;
+      fxMesa->tmu_source[0] = 1;
+      fxMesa->tmu_source[1] = 0;
    }
    else if (ctx->Texture._EnabledUnits & 0x1) {
       ind |= SETUP_TMU0;
    }
-   
+
+   if (ctx->_TriangleCaps & DD_POINT_ATTEN) {
+      ind |= SETUP_PSIZ;
+   }
+
+   if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) {
+      ind |= SETUP_SPEC;
+   }
+
    fxMesa->SetupIndex = ind;
 
    if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
@@ -358,7 +541,7 @@ void fxChooseVertexState( GLcontext *ctx )
       tnl->Driver.Render.CopyPV = copy_pv_extras;
    } else {
       tnl->Driver.Render.Interp = setup_tab[ind].interp;
-      tnl->Driver.Render.CopyPV = copy_pv;
+      tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
    }
 
    if (setup_tab[ind].vertex_format != fxMesa->stw_hint_state) {
@@ -391,11 +574,6 @@ void fxFreeVB( GLcontext *ctx )
       ALIGN_FREE(fxMesa->verts);
       fxMesa->verts = 0;
    }
-
-   if (fxMesa->UbyteColor.Ptr) {
-      ALIGN_FREE((void *)fxMesa->UbyteColor.Ptr);
-      fxMesa->UbyteColor.Ptr = 0;
-   }
 }
 #else